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