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