001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.counter.service.base;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.counter.model.Counter;
020    import com.liferay.counter.service.CounterLocalService;
021    import com.liferay.counter.service.persistence.CounterFinder;
022    import com.liferay.counter.service.persistence.CounterPersistence;
023    
024    import com.liferay.portal.kernel.bean.BeanReference;
025    import com.liferay.portal.kernel.bean.IdentifiableBean;
026    import com.liferay.portal.kernel.dao.db.DB;
027    import com.liferay.portal.kernel.dao.db.DBFactoryUtil;
028    import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
029    import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
030    import com.liferay.portal.kernel.dao.orm.DynamicQuery;
031    import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil;
032    import com.liferay.portal.kernel.dao.orm.Projection;
033    import com.liferay.portal.kernel.exception.PortalException;
034    import com.liferay.portal.kernel.exception.SystemException;
035    import com.liferay.portal.kernel.search.Indexable;
036    import com.liferay.portal.kernel.search.IndexableType;
037    import com.liferay.portal.kernel.util.OrderByComparator;
038    import com.liferay.portal.model.PersistedModel;
039    import com.liferay.portal.service.BaseLocalServiceImpl;
040    import com.liferay.portal.service.PersistedModelLocalServiceRegistry;
041    import com.liferay.portal.util.PortalUtil;
042    
043    import java.io.Serializable;
044    
045    import java.util.List;
046    
047    import javax.sql.DataSource;
048    
049    /**
050     * Provides the base implementation for the counter local service.
051     *
052     * <p>
053     * This implementation exists only as a container for the default service methods generated by ServiceBuilder. All custom service methods should be put in {@link com.liferay.counter.service.impl.CounterLocalServiceImpl}.
054     * </p>
055     *
056     * @author Brian Wing Shun Chan
057     * @see com.liferay.counter.service.impl.CounterLocalServiceImpl
058     * @see com.liferay.counter.service.CounterLocalServiceUtil
059     * @generated
060     */
061    @ProviderType
062    public abstract class CounterLocalServiceBaseImpl extends BaseLocalServiceImpl
063            implements CounterLocalService, IdentifiableBean {
064            /*
065             * NOTE FOR DEVELOPERS:
066             *
067             * Never modify or reference this class directly. Always use {@link com.liferay.counter.service.CounterLocalServiceUtil} to access the counter local service.
068             */
069    
070            /**
071             * Adds the counter to the database. Also notifies the appropriate model listeners.
072             *
073             * @param counter the counter
074             * @return the counter that was added
075             */
076            @Indexable(type = IndexableType.REINDEX)
077            @Override
078            public Counter addCounter(Counter counter) {
079                    counter.setNew(true);
080    
081                    return counterPersistence.update(counter);
082            }
083    
084            /**
085             * Creates a new counter with the primary key. Does not add the counter to the database.
086             *
087             * @param name the primary key for the new counter
088             * @return the new counter
089             */
090            @Override
091            public Counter createCounter(String name) {
092                    return counterPersistence.create(name);
093            }
094    
095            /**
096             * Deletes the counter with the primary key from the database. Also notifies the appropriate model listeners.
097             *
098             * @param name the primary key of the counter
099             * @return the counter that was removed
100             * @throws PortalException if a counter with the primary key could not be found
101             */
102            @Indexable(type = IndexableType.DELETE)
103            @Override
104            public Counter deleteCounter(String name) throws PortalException {
105                    return counterPersistence.remove(name);
106            }
107    
108            /**
109             * Deletes the counter from the database. Also notifies the appropriate model listeners.
110             *
111             * @param counter the counter
112             * @return the counter that was removed
113             */
114            @Indexable(type = IndexableType.DELETE)
115            @Override
116            public Counter deleteCounter(Counter counter) {
117                    return counterPersistence.remove(counter);
118            }
119    
120            @Override
121            public DynamicQuery dynamicQuery() {
122                    Class<?> clazz = getClass();
123    
124                    return DynamicQueryFactoryUtil.forClass(Counter.class,
125                            clazz.getClassLoader());
126            }
127    
128            /**
129             * Performs a dynamic query on the database and returns the matching rows.
130             *
131             * @param dynamicQuery the dynamic query
132             * @return the matching rows
133             */
134            @Override
135            public <T> List<T> dynamicQuery(DynamicQuery dynamicQuery) {
136                    return counterPersistence.findWithDynamicQuery(dynamicQuery);
137            }
138    
139            /**
140             * Performs a dynamic query on the database and returns a range of the matching rows.
141             *
142             * <p>
143             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.counter.model.impl.CounterModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
144             * </p>
145             *
146             * @param dynamicQuery the dynamic query
147             * @param start the lower bound of the range of model instances
148             * @param end the upper bound of the range of model instances (not inclusive)
149             * @return the range of matching rows
150             */
151            @Override
152            public <T> List<T> dynamicQuery(DynamicQuery dynamicQuery, int start,
153                    int end) {
154                    return counterPersistence.findWithDynamicQuery(dynamicQuery, start, end);
155            }
156    
157            /**
158             * Performs a dynamic query on the database and returns an ordered range of the matching rows.
159             *
160             * <p>
161             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.counter.model.impl.CounterModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
162             * </p>
163             *
164             * @param dynamicQuery the dynamic query
165             * @param start the lower bound of the range of model instances
166             * @param end the upper bound of the range of model instances (not inclusive)
167             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
168             * @return the ordered range of matching rows
169             */
170            @Override
171            public <T> List<T> dynamicQuery(DynamicQuery dynamicQuery, int start,
172                    int end, OrderByComparator<T> orderByComparator) {
173                    return counterPersistence.findWithDynamicQuery(dynamicQuery, start,
174                            end, orderByComparator);
175            }
176    
177            /**
178             * Returns the number of rows matching the dynamic query.
179             *
180             * @param dynamicQuery the dynamic query
181             * @return the number of rows matching the dynamic query
182             */
183            @Override
184            public long dynamicQueryCount(DynamicQuery dynamicQuery) {
185                    return counterPersistence.countWithDynamicQuery(dynamicQuery);
186            }
187    
188            /**
189             * Returns the number of rows matching the dynamic query.
190             *
191             * @param dynamicQuery the dynamic query
192             * @param projection the projection to apply to the query
193             * @return the number of rows matching the dynamic query
194             */
195            @Override
196            public long dynamicQueryCount(DynamicQuery dynamicQuery,
197                    Projection projection) {
198                    return counterPersistence.countWithDynamicQuery(dynamicQuery, projection);
199            }
200    
201            @Override
202            public Counter fetchCounter(String name) {
203                    return counterPersistence.fetchByPrimaryKey(name);
204            }
205    
206            /**
207             * Returns the counter with the primary key.
208             *
209             * @param name the primary key of the counter
210             * @return the counter
211             * @throws PortalException if a counter with the primary key could not be found
212             */
213            @Override
214            public Counter getCounter(String name) throws PortalException {
215                    return counterPersistence.findByPrimaryKey(name);
216            }
217    
218            /**
219             * @throws PortalException
220             */
221            @Override
222            public PersistedModel deletePersistedModel(PersistedModel persistedModel)
223                    throws PortalException {
224                    return counterLocalService.deleteCounter((Counter)persistedModel);
225            }
226    
227            @Override
228            public PersistedModel getPersistedModel(Serializable primaryKeyObj)
229                    throws PortalException {
230                    return counterPersistence.findByPrimaryKey(primaryKeyObj);
231            }
232    
233            /**
234             * Returns a range of all the counters.
235             *
236             * <p>
237             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.counter.model.impl.CounterModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
238             * </p>
239             *
240             * @param start the lower bound of the range of counters
241             * @param end the upper bound of the range of counters (not inclusive)
242             * @return the range of counters
243             */
244            @Override
245            public List<Counter> getCounters(int start, int end) {
246                    return counterPersistence.findAll(start, end);
247            }
248    
249            /**
250             * Returns the number of counters.
251             *
252             * @return the number of counters
253             */
254            @Override
255            public int getCountersCount() {
256                    return counterPersistence.countAll();
257            }
258    
259            /**
260             * Updates the counter in the database or adds it if it does not yet exist. Also notifies the appropriate model listeners.
261             *
262             * @param counter the counter
263             * @return the counter that was updated
264             */
265            @Indexable(type = IndexableType.REINDEX)
266            @Override
267            public Counter updateCounter(Counter counter) {
268                    return counterPersistence.update(counter);
269            }
270    
271            /**
272             * Returns the counter local service.
273             *
274             * @return the counter local service
275             */
276            public com.liferay.counter.service.CounterLocalService getCounterLocalService() {
277                    return counterLocalService;
278            }
279    
280            /**
281             * Sets the counter local service.
282             *
283             * @param counterLocalService the counter local service
284             */
285            public void setCounterLocalService(
286                    com.liferay.counter.service.CounterLocalService counterLocalService) {
287                    this.counterLocalService = counterLocalService;
288            }
289    
290            /**
291             * Returns the counter persistence.
292             *
293             * @return the counter persistence
294             */
295            public CounterPersistence getCounterPersistence() {
296                    return counterPersistence;
297            }
298    
299            /**
300             * Sets the counter persistence.
301             *
302             * @param counterPersistence the counter persistence
303             */
304            public void setCounterPersistence(CounterPersistence counterPersistence) {
305                    this.counterPersistence = counterPersistence;
306            }
307    
308            /**
309             * Returns the counter finder.
310             *
311             * @return the counter finder
312             */
313            public CounterFinder getCounterFinder() {
314                    return counterFinder;
315            }
316    
317            /**
318             * Sets the counter finder.
319             *
320             * @param counterFinder the counter finder
321             */
322            public void setCounterFinder(CounterFinder counterFinder) {
323                    this.counterFinder = counterFinder;
324            }
325    
326            public void afterPropertiesSet() {
327                    persistedModelLocalServiceRegistry.register("com.liferay.counter.model.Counter",
328                            counterLocalService);
329            }
330    
331            public void destroy() {
332                    persistedModelLocalServiceRegistry.unregister(
333                            "com.liferay.counter.model.Counter");
334            }
335    
336            /**
337             * Returns the Spring bean ID for this bean.
338             *
339             * @return the Spring bean ID for this bean
340             */
341            @Override
342            public String getBeanIdentifier() {
343                    return _beanIdentifier;
344            }
345    
346            /**
347             * Sets the Spring bean ID for this bean.
348             *
349             * @param beanIdentifier the Spring bean ID for this bean
350             */
351            @Override
352            public void setBeanIdentifier(String beanIdentifier) {
353                    _beanIdentifier = beanIdentifier;
354            }
355    
356            protected Class<?> getModelClass() {
357                    return Counter.class;
358            }
359    
360            protected String getModelClassName() {
361                    return Counter.class.getName();
362            }
363    
364            /**
365             * Performs a SQL query.
366             *
367             * @param sql the sql query
368             */
369            protected void runSQL(String sql) {
370                    try {
371                            DataSource dataSource = counterPersistence.getDataSource();
372    
373                            DB db = DBFactoryUtil.getDB();
374    
375                            sql = db.buildSQL(sql);
376                            sql = PortalUtil.transformSQL(sql);
377    
378                            SqlUpdate sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(dataSource,
379                                            sql, new int[0]);
380    
381                            sqlUpdate.update();
382                    }
383                    catch (Exception e) {
384                            throw new SystemException(e);
385                    }
386            }
387    
388            @BeanReference(type = com.liferay.counter.service.CounterLocalService.class)
389            protected com.liferay.counter.service.CounterLocalService counterLocalService;
390            @BeanReference(type = CounterPersistence.class)
391            protected CounterPersistence counterPersistence;
392            @BeanReference(type = CounterFinder.class)
393            protected CounterFinder counterFinder;
394            @BeanReference(type = PersistedModelLocalServiceRegistry.class)
395            protected PersistedModelLocalServiceRegistry persistedModelLocalServiceRegistry;
396            private String _beanIdentifier;
397    }