001
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
064 public abstract class CounterLocalServiceBaseImpl implements CounterLocalService,
065 IdentifiableBean {
066
071
072
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
106 public Counter createCounter(String name) {
107 return counterPersistence.create(name);
108 }
109
110
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
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
165 @SuppressWarnings("rawtypes")
166 public List dynamicQuery(DynamicQuery dynamicQuery)
167 throws SystemException {
168 return counterPersistence.findWithDynamicQuery(dynamicQuery);
169 }
170
171
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
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
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
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
257 public List<Counter> getCounters(int start, int end)
258 throws SystemException {
259 return counterPersistence.findAll(start, end);
260 }
261
262
268 public int getCountersCount() throws SystemException {
269 return counterPersistence.countAll();
270 }
271
272
279 public Counter updateCounter(Counter counter) throws SystemException {
280 return updateCounter(counter, true);
281 }
282
283
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
318 public CounterLocalService getCounterLocalService() {
319 return counterLocalService;
320 }
321
322
327 public void setCounterLocalService(CounterLocalService counterLocalService) {
328 this.counterLocalService = counterLocalService;
329 }
330
331
336 public CounterPersistence getCounterPersistence() {
337 return counterPersistence;
338 }
339
340
345 public void setCounterPersistence(CounterPersistence counterPersistence) {
346 this.counterPersistence = counterPersistence;
347 }
348
349
354 public CounterFinder getCounterFinder() {
355 return counterFinder;
356 }
357
358
363 public void setCounterFinder(CounterFinder counterFinder) {
364 this.counterFinder = counterFinder;
365 }
366
367
372 public ResourceLocalService getResourceLocalService() {
373 return resourceLocalService;
374 }
375
376
381 public void setResourceLocalService(
382 ResourceLocalService resourceLocalService) {
383 this.resourceLocalService = resourceLocalService;
384 }
385
386
391 public ResourceService getResourceService() {
392 return resourceService;
393 }
394
395
400 public void setResourceService(ResourceService resourceService) {
401 this.resourceService = resourceService;
402 }
403
404
409 public ResourcePersistence getResourcePersistence() {
410 return resourcePersistence;
411 }
412
413
418 public void setResourcePersistence(ResourcePersistence resourcePersistence) {
419 this.resourcePersistence = resourcePersistence;
420 }
421
422
427 public ResourceFinder getResourceFinder() {
428 return resourceFinder;
429 }
430
431
436 public void setResourceFinder(ResourceFinder resourceFinder) {
437 this.resourceFinder = resourceFinder;
438 }
439
440
445 public UserLocalService getUserLocalService() {
446 return userLocalService;
447 }
448
449
454 public void setUserLocalService(UserLocalService userLocalService) {
455 this.userLocalService = userLocalService;
456 }
457
458
463 public UserService getUserService() {
464 return userService;
465 }
466
467
472 public void setUserService(UserService userService) {
473 this.userService = userService;
474 }
475
476
481 public UserPersistence getUserPersistence() {
482 return userPersistence;
483 }
484
485
490 public void setUserPersistence(UserPersistence userPersistence) {
491 this.userPersistence = userPersistence;
492 }
493
494
499 public UserFinder getUserFinder() {
500 return userFinder;
501 }
502
503
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
527 public String getBeanIdentifier() {
528 return _beanIdentifier;
529 }
530
531
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
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 }