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.service.persistence.ClassNamePersistence;
042    import com.liferay.portal.service.persistence.UserFinder;
043    import com.liferay.portal.service.persistence.UserPersistence;
044    import com.liferay.portal.util.PortalUtil;
045    
046    import java.io.Serializable;
047    
048    import java.util.List;
049    
050    import javax.sql.DataSource;
051    
052    /**
053     * Provides the base implementation for the counter local service.
054     *
055     * <p>
056     * 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}.
057     * </p>
058     *
059     * @author Brian Wing Shun Chan
060     * @see com.liferay.counter.service.impl.CounterLocalServiceImpl
061     * @see com.liferay.counter.service.CounterLocalServiceUtil
062     * @generated
063     */
064    @ProviderType
065    public abstract class CounterLocalServiceBaseImpl extends BaseLocalServiceImpl
066            implements CounterLocalService, IdentifiableBean {
067            /*
068             * NOTE FOR DEVELOPERS:
069             *
070             * Never modify or reference this class directly. Always use {@link com.liferay.counter.service.CounterLocalServiceUtil} to access the counter local service.
071             */
072    
073            /**
074             * Adds the counter to the database. Also notifies the appropriate model listeners.
075             *
076             * @param counter the counter
077             * @return the counter that was added
078             */
079            @Indexable(type = IndexableType.REINDEX)
080            @Override
081            public Counter addCounter(Counter counter) {
082                    counter.setNew(true);
083    
084                    return counterPersistence.update(counter);
085            }
086    
087            /**
088             * Creates a new counter with the primary key. Does not add the counter to the database.
089             *
090             * @param name the primary key for the new counter
091             * @return the new counter
092             */
093            @Override
094            public Counter createCounter(String name) {
095                    return counterPersistence.create(name);
096            }
097    
098            /**
099             * Deletes the counter with the primary key from the database. Also notifies the appropriate model listeners.
100             *
101             * @param name the primary key of the counter
102             * @return the counter that was removed
103             * @throws PortalException if a counter with the primary key could not be found
104             */
105            @Indexable(type = IndexableType.DELETE)
106            @Override
107            public Counter deleteCounter(String name) throws PortalException {
108                    return counterPersistence.remove(name);
109            }
110    
111            /**
112             * Deletes the counter from the database. Also notifies the appropriate model listeners.
113             *
114             * @param counter the counter
115             * @return the counter that was removed
116             */
117            @Indexable(type = IndexableType.DELETE)
118            @Override
119            public Counter deleteCounter(Counter counter) {
120                    return counterPersistence.remove(counter);
121            }
122    
123            @Override
124            public DynamicQuery dynamicQuery() {
125                    Class<?> clazz = getClass();
126    
127                    return DynamicQueryFactoryUtil.forClass(Counter.class,
128                            clazz.getClassLoader());
129            }
130    
131            /**
132             * Performs a dynamic query on the database and returns the matching rows.
133             *
134             * @param dynamicQuery the dynamic query
135             * @return the matching rows
136             */
137            @Override
138            public <T> List<T> dynamicQuery(DynamicQuery dynamicQuery) {
139                    return counterPersistence.findWithDynamicQuery(dynamicQuery);
140            }
141    
142            /**
143             * Performs a dynamic query on the database and returns a range of the matching rows.
144             *
145             * <p>
146             * 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.
147             * </p>
148             *
149             * @param dynamicQuery the dynamic query
150             * @param start the lower bound of the range of model instances
151             * @param end the upper bound of the range of model instances (not inclusive)
152             * @return the range of matching rows
153             */
154            @Override
155            public <T> List<T> dynamicQuery(DynamicQuery dynamicQuery, int start,
156                    int end) {
157                    return counterPersistence.findWithDynamicQuery(dynamicQuery, start, end);
158            }
159    
160            /**
161             * Performs a dynamic query on the database and returns an ordered range of the matching rows.
162             *
163             * <p>
164             * 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.
165             * </p>
166             *
167             * @param dynamicQuery the dynamic query
168             * @param start the lower bound of the range of model instances
169             * @param end the upper bound of the range of model instances (not inclusive)
170             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
171             * @return the ordered range of matching rows
172             */
173            @Override
174            public <T> List<T> dynamicQuery(DynamicQuery dynamicQuery, int start,
175                    int end, OrderByComparator<T> orderByComparator) {
176                    return counterPersistence.findWithDynamicQuery(dynamicQuery, start,
177                            end, orderByComparator);
178            }
179    
180            /**
181             * Returns the number of rows that match the dynamic query.
182             *
183             * @param dynamicQuery the dynamic query
184             * @return the number of rows that match the dynamic query
185             */
186            @Override
187            public long dynamicQueryCount(DynamicQuery dynamicQuery) {
188                    return counterPersistence.countWithDynamicQuery(dynamicQuery);
189            }
190    
191            /**
192             * Returns the number of rows that match the dynamic query.
193             *
194             * @param dynamicQuery the dynamic query
195             * @param projection the projection to apply to the query
196             * @return the number of rows that match the dynamic query
197             */
198            @Override
199            public long dynamicQueryCount(DynamicQuery dynamicQuery,
200                    Projection projection) {
201                    return counterPersistence.countWithDynamicQuery(dynamicQuery, projection);
202            }
203    
204            @Override
205            public Counter fetchCounter(String name) {
206                    return counterPersistence.fetchByPrimaryKey(name);
207            }
208    
209            /**
210             * Returns the counter with the primary key.
211             *
212             * @param name the primary key of the counter
213             * @return the counter
214             * @throws PortalException if a counter with the primary key could not be found
215             */
216            @Override
217            public Counter getCounter(String name) throws PortalException {
218                    return counterPersistence.findByPrimaryKey(name);
219            }
220    
221            /**
222             * @throws PortalException
223             */
224            @Override
225            public PersistedModel deletePersistedModel(PersistedModel persistedModel)
226                    throws PortalException {
227                    return counterLocalService.deleteCounter((Counter)persistedModel);
228            }
229    
230            @Override
231            public PersistedModel getPersistedModel(Serializable primaryKeyObj)
232                    throws PortalException {
233                    return counterPersistence.findByPrimaryKey(primaryKeyObj);
234            }
235    
236            /**
237             * Returns a range of all the counters.
238             *
239             * <p>
240             * 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.
241             * </p>
242             *
243             * @param start the lower bound of the range of counters
244             * @param end the upper bound of the range of counters (not inclusive)
245             * @return the range of counters
246             */
247            @Override
248            public List<Counter> getCounters(int start, int end) {
249                    return counterPersistence.findAll(start, end);
250            }
251    
252            /**
253             * Returns the number of counters.
254             *
255             * @return the number of counters
256             */
257            @Override
258            public int getCountersCount() {
259                    return counterPersistence.countAll();
260            }
261    
262            /**
263             * Updates the counter in the database or adds it if it does not yet exist. Also notifies the appropriate model listeners.
264             *
265             * @param counter the counter
266             * @return the counter that was updated
267             */
268            @Indexable(type = IndexableType.REINDEX)
269            @Override
270            public Counter updateCounter(Counter counter) {
271                    return counterPersistence.update(counter);
272            }
273    
274            /**
275             * Returns the counter local service.
276             *
277             * @return the counter local service
278             */
279            public com.liferay.counter.service.CounterLocalService getCounterLocalService() {
280                    return counterLocalService;
281            }
282    
283            /**
284             * Sets the counter local service.
285             *
286             * @param counterLocalService the counter local service
287             */
288            public void setCounterLocalService(
289                    com.liferay.counter.service.CounterLocalService counterLocalService) {
290                    this.counterLocalService = counterLocalService;
291            }
292    
293            /**
294             * Returns the counter persistence.
295             *
296             * @return the counter persistence
297             */
298            public CounterPersistence getCounterPersistence() {
299                    return counterPersistence;
300            }
301    
302            /**
303             * Sets the counter persistence.
304             *
305             * @param counterPersistence the counter persistence
306             */
307            public void setCounterPersistence(CounterPersistence counterPersistence) {
308                    this.counterPersistence = counterPersistence;
309            }
310    
311            /**
312             * Returns the counter finder.
313             *
314             * @return the counter finder
315             */
316            public CounterFinder getCounterFinder() {
317                    return counterFinder;
318            }
319    
320            /**
321             * Sets the counter finder.
322             *
323             * @param counterFinder the counter finder
324             */
325            public void setCounterFinder(CounterFinder counterFinder) {
326                    this.counterFinder = counterFinder;
327            }
328    
329            /**
330             * Returns the class name local service.
331             *
332             * @return the class name local service
333             */
334            public com.liferay.portal.service.ClassNameLocalService getClassNameLocalService() {
335                    return classNameLocalService;
336            }
337    
338            /**
339             * Sets the class name local service.
340             *
341             * @param classNameLocalService the class name local service
342             */
343            public void setClassNameLocalService(
344                    com.liferay.portal.service.ClassNameLocalService classNameLocalService) {
345                    this.classNameLocalService = classNameLocalService;
346            }
347    
348            /**
349             * Returns the class name remote service.
350             *
351             * @return the class name remote service
352             */
353            public com.liferay.portal.service.ClassNameService getClassNameService() {
354                    return classNameService;
355            }
356    
357            /**
358             * Sets the class name remote service.
359             *
360             * @param classNameService the class name remote service
361             */
362            public void setClassNameService(
363                    com.liferay.portal.service.ClassNameService classNameService) {
364                    this.classNameService = classNameService;
365            }
366    
367            /**
368             * Returns the class name persistence.
369             *
370             * @return the class name persistence
371             */
372            public ClassNamePersistence getClassNamePersistence() {
373                    return classNamePersistence;
374            }
375    
376            /**
377             * Sets the class name persistence.
378             *
379             * @param classNamePersistence the class name persistence
380             */
381            public void setClassNamePersistence(
382                    ClassNamePersistence classNamePersistence) {
383                    this.classNamePersistence = classNamePersistence;
384            }
385    
386            /**
387             * Returns the resource local service.
388             *
389             * @return the resource local service
390             */
391            public com.liferay.portal.service.ResourceLocalService getResourceLocalService() {
392                    return resourceLocalService;
393            }
394    
395            /**
396             * Sets the resource local service.
397             *
398             * @param resourceLocalService the resource local service
399             */
400            public void setResourceLocalService(
401                    com.liferay.portal.service.ResourceLocalService resourceLocalService) {
402                    this.resourceLocalService = resourceLocalService;
403            }
404    
405            /**
406             * Returns the user local service.
407             *
408             * @return the user local service
409             */
410            public com.liferay.portal.service.UserLocalService getUserLocalService() {
411                    return userLocalService;
412            }
413    
414            /**
415             * Sets the user local service.
416             *
417             * @param userLocalService the user local service
418             */
419            public void setUserLocalService(
420                    com.liferay.portal.service.UserLocalService userLocalService) {
421                    this.userLocalService = userLocalService;
422            }
423    
424            /**
425             * Returns the user remote service.
426             *
427             * @return the user remote service
428             */
429            public com.liferay.portal.service.UserService getUserService() {
430                    return userService;
431            }
432    
433            /**
434             * Sets the user remote service.
435             *
436             * @param userService the user remote service
437             */
438            public void setUserService(
439                    com.liferay.portal.service.UserService userService) {
440                    this.userService = userService;
441            }
442    
443            /**
444             * Returns the user persistence.
445             *
446             * @return the user persistence
447             */
448            public UserPersistence getUserPersistence() {
449                    return userPersistence;
450            }
451    
452            /**
453             * Sets the user persistence.
454             *
455             * @param userPersistence the user persistence
456             */
457            public void setUserPersistence(UserPersistence userPersistence) {
458                    this.userPersistence = userPersistence;
459            }
460    
461            /**
462             * Returns the user finder.
463             *
464             * @return the user finder
465             */
466            public UserFinder getUserFinder() {
467                    return userFinder;
468            }
469    
470            /**
471             * Sets the user finder.
472             *
473             * @param userFinder the user finder
474             */
475            public void setUserFinder(UserFinder userFinder) {
476                    this.userFinder = userFinder;
477            }
478    
479            public void afterPropertiesSet() {
480                    persistedModelLocalServiceRegistry.register("com.liferay.counter.model.Counter",
481                            counterLocalService);
482            }
483    
484            public void destroy() {
485                    persistedModelLocalServiceRegistry.unregister(
486                            "com.liferay.counter.model.Counter");
487            }
488    
489            /**
490             * Returns the Spring bean ID for this bean.
491             *
492             * @return the Spring bean ID for this bean
493             */
494            @Override
495            public String getBeanIdentifier() {
496                    return _beanIdentifier;
497            }
498    
499            /**
500             * Sets the Spring bean ID for this bean.
501             *
502             * @param beanIdentifier the Spring bean ID for this bean
503             */
504            @Override
505            public void setBeanIdentifier(String beanIdentifier) {
506                    _beanIdentifier = beanIdentifier;
507            }
508    
509            protected Class<?> getModelClass() {
510                    return Counter.class;
511            }
512    
513            protected String getModelClassName() {
514                    return Counter.class.getName();
515            }
516    
517            /**
518             * Performs a SQL query.
519             *
520             * @param sql the sql query
521             */
522            protected void runSQL(String sql) {
523                    try {
524                            DataSource dataSource = counterPersistence.getDataSource();
525    
526                            DB db = DBFactoryUtil.getDB();
527    
528                            sql = db.buildSQL(sql);
529                            sql = PortalUtil.transformSQL(sql);
530    
531                            SqlUpdate sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(dataSource,
532                                            sql, new int[0]);
533    
534                            sqlUpdate.update();
535                    }
536                    catch (Exception e) {
537                            throw new SystemException(e);
538                    }
539            }
540    
541            @BeanReference(type = com.liferay.counter.service.CounterLocalService.class)
542            protected com.liferay.counter.service.CounterLocalService counterLocalService;
543            @BeanReference(type = CounterPersistence.class)
544            protected CounterPersistence counterPersistence;
545            @BeanReference(type = CounterFinder.class)
546            protected CounterFinder counterFinder;
547            @BeanReference(type = com.liferay.portal.service.ClassNameLocalService.class)
548            protected com.liferay.portal.service.ClassNameLocalService classNameLocalService;
549            @BeanReference(type = com.liferay.portal.service.ClassNameService.class)
550            protected com.liferay.portal.service.ClassNameService classNameService;
551            @BeanReference(type = ClassNamePersistence.class)
552            protected ClassNamePersistence classNamePersistence;
553            @BeanReference(type = com.liferay.portal.service.ResourceLocalService.class)
554            protected com.liferay.portal.service.ResourceLocalService resourceLocalService;
555            @BeanReference(type = com.liferay.portal.service.UserLocalService.class)
556            protected com.liferay.portal.service.UserLocalService userLocalService;
557            @BeanReference(type = com.liferay.portal.service.UserService.class)
558            protected com.liferay.portal.service.UserService userService;
559            @BeanReference(type = UserPersistence.class)
560            protected UserPersistence userPersistence;
561            @BeanReference(type = UserFinder.class)
562            protected UserFinder userFinder;
563            @BeanReference(type = PersistedModelLocalServiceRegistry.class)
564            protected PersistedModelLocalServiceRegistry persistedModelLocalServiceRegistry;
565            private String _beanIdentifier;
566    }