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.dao.orm.DynamicQueryFactoryUtil;
028    import com.liferay.portal.kernel.exception.PortalException;
029    import com.liferay.portal.kernel.exception.SystemException;
030    import com.liferay.portal.kernel.search.Indexable;
031    import com.liferay.portal.kernel.search.IndexableType;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.model.PersistedModel;
034    import com.liferay.portal.service.BaseLocalServiceImpl;
035    import com.liferay.portal.service.PersistedModelLocalServiceRegistry;
036    import com.liferay.portal.service.ResourceLocalService;
037    import com.liferay.portal.service.UserLocalService;
038    import com.liferay.portal.service.UserService;
039    import com.liferay.portal.service.persistence.UserFinder;
040    import com.liferay.portal.service.persistence.UserPersistence;
041    
042    import java.io.Serializable;
043    
044    import java.util.List;
045    
046    import javax.sql.DataSource;
047    
048    /**
049     * The base implementation of the counter local service.
050     *
051     * <p>
052     * 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}.
053     * </p>
054     *
055     * @author Brian Wing Shun Chan
056     * @see com.liferay.counter.service.impl.CounterLocalServiceImpl
057     * @see com.liferay.counter.service.CounterLocalServiceUtil
058     * @generated
059     */
060    public abstract class CounterLocalServiceBaseImpl extends BaseLocalServiceImpl
061            implements CounterLocalService, IdentifiableBean {
062            /*
063             * NOTE FOR DEVELOPERS:
064             *
065             * Never modify or reference this class directly. Always use {@link com.liferay.counter.service.CounterLocalServiceUtil} to access the counter local service.
066             */
067    
068            /**
069             * Adds the counter to the database. Also notifies the appropriate model listeners.
070             *
071             * @param counter the counter
072             * @return the counter that was added
073             * @throws SystemException if a system exception occurred
074             */
075            @Indexable(type = IndexableType.REINDEX)
076            public Counter addCounter(Counter counter) throws SystemException {
077                    counter.setNew(true);
078    
079                    return counterPersistence.update(counter);
080            }
081    
082            /**
083             * Creates a new counter with the primary key. Does not add the counter to the database.
084             *
085             * @param name the primary key for the new counter
086             * @return the new counter
087             */
088            public Counter createCounter(String name) {
089                    return counterPersistence.create(name);
090            }
091    
092            /**
093             * Deletes the counter with the primary key from the database. Also notifies the appropriate model listeners.
094             *
095             * @param name the primary key of the counter
096             * @return the counter that was removed
097             * @throws PortalException if a counter with the primary key could not be found
098             * @throws SystemException if a system exception occurred
099             */
100            @Indexable(type = IndexableType.DELETE)
101            public Counter deleteCounter(String name)
102                    throws PortalException, SystemException {
103                    return counterPersistence.remove(name);
104            }
105    
106            /**
107             * Deletes the counter from the database. Also notifies the appropriate model listeners.
108             *
109             * @param counter the counter
110             * @return the counter that was removed
111             * @throws SystemException if a system exception occurred
112             */
113            @Indexable(type = IndexableType.DELETE)
114            public Counter deleteCounter(Counter counter) throws SystemException {
115                    return counterPersistence.remove(counter);
116            }
117    
118            public DynamicQuery dynamicQuery() {
119                    Class<?> clazz = getClass();
120    
121                    return DynamicQueryFactoryUtil.forClass(Counter.class,
122                            clazz.getClassLoader());
123            }
124    
125            /**
126             * Performs a dynamic query on the database and returns the matching rows.
127             *
128             * @param dynamicQuery the dynamic query
129             * @return the matching rows
130             * @throws SystemException if a system exception occurred
131             */
132            @SuppressWarnings("rawtypes")
133            public List dynamicQuery(DynamicQuery dynamicQuery)
134                    throws SystemException {
135                    return counterPersistence.findWithDynamicQuery(dynamicQuery);
136            }
137    
138            /**
139             * Performs a dynamic query on the database and returns a range of the matching rows.
140             *
141             * <p>
142             * 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.
143             * </p>
144             *
145             * @param dynamicQuery the dynamic query
146             * @param start the lower bound of the range of model instances
147             * @param end the upper bound of the range of model instances (not inclusive)
148             * @return the range of matching rows
149             * @throws SystemException if a system exception occurred
150             */
151            @SuppressWarnings("rawtypes")
152            public List dynamicQuery(DynamicQuery dynamicQuery, int start, int end)
153                    throws SystemException {
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.
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             * @throws SystemException if a system exception occurred
170             */
171            @SuppressWarnings("rawtypes")
172            public List dynamicQuery(DynamicQuery dynamicQuery, int start, int end,
173                    OrderByComparator orderByComparator) throws SystemException {
174                    return counterPersistence.findWithDynamicQuery(dynamicQuery, start,
175                            end, orderByComparator);
176            }
177    
178            /**
179             * Returns the number of rows that match the dynamic query.
180             *
181             * @param dynamicQuery the dynamic query
182             * @return the number of rows that match the dynamic query
183             * @throws SystemException if a system exception occurred
184             */
185            public long dynamicQueryCount(DynamicQuery dynamicQuery)
186                    throws SystemException {
187                    return counterPersistence.countWithDynamicQuery(dynamicQuery);
188            }
189    
190            public Counter fetchCounter(String name) throws SystemException {
191                    return counterPersistence.fetchByPrimaryKey(name);
192            }
193    
194            /**
195             * Returns the counter with the primary key.
196             *
197             * @param name the primary key of the counter
198             * @return the counter
199             * @throws PortalException if a counter with the primary key could not be found
200             * @throws SystemException if a system exception occurred
201             */
202            public Counter getCounter(String name)
203                    throws PortalException, SystemException {
204                    return counterPersistence.findByPrimaryKey(name);
205            }
206    
207            public PersistedModel getPersistedModel(Serializable primaryKeyObj)
208                    throws PortalException, SystemException {
209                    return counterPersistence.findByPrimaryKey(primaryKeyObj);
210            }
211    
212            /**
213             * Returns a range of all the counters.
214             *
215             * <p>
216             * 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.
217             * </p>
218             *
219             * @param start the lower bound of the range of counters
220             * @param end the upper bound of the range of counters (not inclusive)
221             * @return the range of counters
222             * @throws SystemException if a system exception occurred
223             */
224            public List<Counter> getCounters(int start, int end)
225                    throws SystemException {
226                    return counterPersistence.findAll(start, end);
227            }
228    
229            /**
230             * Returns the number of counters.
231             *
232             * @return the number of counters
233             * @throws SystemException if a system exception occurred
234             */
235            public int getCountersCount() throws SystemException {
236                    return counterPersistence.countAll();
237            }
238    
239            /**
240             * Updates the counter in the database or adds it if it does not yet exist. Also notifies the appropriate model listeners.
241             *
242             * @param counter the counter
243             * @return the counter that was updated
244             * @throws SystemException if a system exception occurred
245             */
246            @Indexable(type = IndexableType.REINDEX)
247            public Counter updateCounter(Counter counter) throws SystemException {
248                    return counterPersistence.update(counter);
249            }
250    
251            /**
252             * Returns the counter local service.
253             *
254             * @return the counter local service
255             */
256            public CounterLocalService getCounterLocalService() {
257                    return counterLocalService;
258            }
259    
260            /**
261             * Sets the counter local service.
262             *
263             * @param counterLocalService the counter local service
264             */
265            public void setCounterLocalService(CounterLocalService counterLocalService) {
266                    this.counterLocalService = counterLocalService;
267            }
268    
269            /**
270             * Returns the counter persistence.
271             *
272             * @return the counter persistence
273             */
274            public CounterPersistence getCounterPersistence() {
275                    return counterPersistence;
276            }
277    
278            /**
279             * Sets the counter persistence.
280             *
281             * @param counterPersistence the counter persistence
282             */
283            public void setCounterPersistence(CounterPersistence counterPersistence) {
284                    this.counterPersistence = counterPersistence;
285            }
286    
287            /**
288             * Returns the counter finder.
289             *
290             * @return the counter finder
291             */
292            public CounterFinder getCounterFinder() {
293                    return counterFinder;
294            }
295    
296            /**
297             * Sets the counter finder.
298             *
299             * @param counterFinder the counter finder
300             */
301            public void setCounterFinder(CounterFinder counterFinder) {
302                    this.counterFinder = counterFinder;
303            }
304    
305            /**
306             * Returns the resource local service.
307             *
308             * @return the resource local service
309             */
310            public ResourceLocalService getResourceLocalService() {
311                    return resourceLocalService;
312            }
313    
314            /**
315             * Sets the resource local service.
316             *
317             * @param resourceLocalService the resource local service
318             */
319            public void setResourceLocalService(
320                    ResourceLocalService resourceLocalService) {
321                    this.resourceLocalService = resourceLocalService;
322            }
323    
324            /**
325             * Returns the user local service.
326             *
327             * @return the user local service
328             */
329            public UserLocalService getUserLocalService() {
330                    return userLocalService;
331            }
332    
333            /**
334             * Sets the user local service.
335             *
336             * @param userLocalService the user local service
337             */
338            public void setUserLocalService(UserLocalService userLocalService) {
339                    this.userLocalService = userLocalService;
340            }
341    
342            /**
343             * Returns the user remote service.
344             *
345             * @return the user remote service
346             */
347            public UserService getUserService() {
348                    return userService;
349            }
350    
351            /**
352             * Sets the user remote service.
353             *
354             * @param userService the user remote service
355             */
356            public void setUserService(UserService userService) {
357                    this.userService = userService;
358            }
359    
360            /**
361             * Returns the user persistence.
362             *
363             * @return the user persistence
364             */
365            public UserPersistence getUserPersistence() {
366                    return userPersistence;
367            }
368    
369            /**
370             * Sets the user persistence.
371             *
372             * @param userPersistence the user persistence
373             */
374            public void setUserPersistence(UserPersistence userPersistence) {
375                    this.userPersistence = userPersistence;
376            }
377    
378            /**
379             * Returns the user finder.
380             *
381             * @return the user finder
382             */
383            public UserFinder getUserFinder() {
384                    return userFinder;
385            }
386    
387            /**
388             * Sets the user finder.
389             *
390             * @param userFinder the user finder
391             */
392            public void setUserFinder(UserFinder userFinder) {
393                    this.userFinder = userFinder;
394            }
395    
396            public void afterPropertiesSet() {
397                    persistedModelLocalServiceRegistry.register("com.liferay.counter.model.Counter",
398                            counterLocalService);
399            }
400    
401            public void destroy() {
402                    persistedModelLocalServiceRegistry.unregister(
403                            "com.liferay.counter.model.Counter");
404            }
405    
406            /**
407             * Returns the Spring bean ID for this bean.
408             *
409             * @return the Spring bean ID for this bean
410             */
411            public String getBeanIdentifier() {
412                    return _beanIdentifier;
413            }
414    
415            /**
416             * Sets the Spring bean ID for this bean.
417             *
418             * @param beanIdentifier the Spring bean ID for this bean
419             */
420            public void setBeanIdentifier(String beanIdentifier) {
421                    _beanIdentifier = beanIdentifier;
422            }
423    
424            protected Class<?> getModelClass() {
425                    return Counter.class;
426            }
427    
428            protected String getModelClassName() {
429                    return Counter.class.getName();
430            }
431    
432            /**
433             * Performs an SQL query.
434             *
435             * @param sql the sql query
436             */
437            protected void runSQL(String sql) throws SystemException {
438                    try {
439                            DataSource dataSource = counterPersistence.getDataSource();
440    
441                            SqlUpdate sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(dataSource,
442                                            sql, new int[0]);
443    
444                            sqlUpdate.update();
445                    }
446                    catch (Exception e) {
447                            throw new SystemException(e);
448                    }
449            }
450    
451            @BeanReference(type = CounterLocalService.class)
452            protected CounterLocalService counterLocalService;
453            @BeanReference(type = CounterPersistence.class)
454            protected CounterPersistence counterPersistence;
455            @BeanReference(type = CounterFinder.class)
456            protected CounterFinder counterFinder;
457            @BeanReference(type = ResourceLocalService.class)
458            protected ResourceLocalService resourceLocalService;
459            @BeanReference(type = UserLocalService.class)
460            protected UserLocalService userLocalService;
461            @BeanReference(type = UserService.class)
462            protected UserService userService;
463            @BeanReference(type = UserPersistence.class)
464            protected UserPersistence userPersistence;
465            @BeanReference(type = UserFinder.class)
466            protected UserFinder userFinder;
467            @BeanReference(type = PersistedModelLocalServiceRegistry.class)
468            protected PersistedModelLocalServiceRegistry persistedModelLocalServiceRegistry;
469            private String _beanIdentifier;
470    }