001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchClusterGroupException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryUtil;
024 import com.liferay.portal.kernel.dao.orm.Session;
025 import com.liferay.portal.kernel.exception.SystemException;
026 import com.liferay.portal.kernel.log.Log;
027 import com.liferay.portal.kernel.log.LogFactoryUtil;
028 import com.liferay.portal.kernel.util.GetterUtil;
029 import com.liferay.portal.kernel.util.InstanceFactory;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.StringBundler;
032 import com.liferay.portal.kernel.util.StringUtil;
033 import com.liferay.portal.kernel.util.UnmodifiableList;
034 import com.liferay.portal.model.CacheModel;
035 import com.liferay.portal.model.ClusterGroup;
036 import com.liferay.portal.model.ModelListener;
037 import com.liferay.portal.model.impl.ClusterGroupImpl;
038 import com.liferay.portal.model.impl.ClusterGroupModelImpl;
039 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
040
041 import java.io.Serializable;
042
043 import java.util.ArrayList;
044 import java.util.Collections;
045 import java.util.List;
046
047
059 public class ClusterGroupPersistenceImpl extends BasePersistenceImpl<ClusterGroup>
060 implements ClusterGroupPersistence {
061
066 public static final String FINDER_CLASS_NAME_ENTITY = ClusterGroupImpl.class.getName();
067 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
068 ".List1";
069 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
070 ".List2";
071 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
072 ClusterGroupModelImpl.FINDER_CACHE_ENABLED, ClusterGroupImpl.class,
073 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
074 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
075 ClusterGroupModelImpl.FINDER_CACHE_ENABLED, ClusterGroupImpl.class,
076 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
077 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
078 ClusterGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
079 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
080
081 public ClusterGroupPersistenceImpl() {
082 setModelClass(ClusterGroup.class);
083 }
084
085
090 @Override
091 public void cacheResult(ClusterGroup clusterGroup) {
092 EntityCacheUtil.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
093 ClusterGroupImpl.class, clusterGroup.getPrimaryKey(), clusterGroup);
094
095 clusterGroup.resetOriginalValues();
096 }
097
098
103 @Override
104 public void cacheResult(List<ClusterGroup> clusterGroups) {
105 for (ClusterGroup clusterGroup : clusterGroups) {
106 if (EntityCacheUtil.getResult(
107 ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
108 ClusterGroupImpl.class, clusterGroup.getPrimaryKey()) == null) {
109 cacheResult(clusterGroup);
110 }
111 else {
112 clusterGroup.resetOriginalValues();
113 }
114 }
115 }
116
117
124 @Override
125 public void clearCache() {
126 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
127 CacheRegistryUtil.clear(ClusterGroupImpl.class.getName());
128 }
129
130 EntityCacheUtil.clearCache(ClusterGroupImpl.class.getName());
131
132 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
133 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
134 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
135 }
136
137
144 @Override
145 public void clearCache(ClusterGroup clusterGroup) {
146 EntityCacheUtil.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
147 ClusterGroupImpl.class, clusterGroup.getPrimaryKey());
148
149 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
150 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
151 }
152
153 @Override
154 public void clearCache(List<ClusterGroup> clusterGroups) {
155 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
156 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
157
158 for (ClusterGroup clusterGroup : clusterGroups) {
159 EntityCacheUtil.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
160 ClusterGroupImpl.class, clusterGroup.getPrimaryKey());
161 }
162 }
163
164
170 @Override
171 public ClusterGroup create(long clusterGroupId) {
172 ClusterGroup clusterGroup = new ClusterGroupImpl();
173
174 clusterGroup.setNew(true);
175 clusterGroup.setPrimaryKey(clusterGroupId);
176
177 return clusterGroup;
178 }
179
180
188 @Override
189 public ClusterGroup remove(long clusterGroupId)
190 throws NoSuchClusterGroupException, SystemException {
191 return remove((Serializable)clusterGroupId);
192 }
193
194
202 @Override
203 public ClusterGroup remove(Serializable primaryKey)
204 throws NoSuchClusterGroupException, SystemException {
205 Session session = null;
206
207 try {
208 session = openSession();
209
210 ClusterGroup clusterGroup = (ClusterGroup)session.get(ClusterGroupImpl.class,
211 primaryKey);
212
213 if (clusterGroup == null) {
214 if (_log.isWarnEnabled()) {
215 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
216 }
217
218 throw new NoSuchClusterGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
219 primaryKey);
220 }
221
222 return remove(clusterGroup);
223 }
224 catch (NoSuchClusterGroupException nsee) {
225 throw nsee;
226 }
227 catch (Exception e) {
228 throw processException(e);
229 }
230 finally {
231 closeSession(session);
232 }
233 }
234
235 @Override
236 protected ClusterGroup removeImpl(ClusterGroup clusterGroup)
237 throws SystemException {
238 clusterGroup = toUnwrappedModel(clusterGroup);
239
240 Session session = null;
241
242 try {
243 session = openSession();
244
245 if (!session.contains(clusterGroup)) {
246 clusterGroup = (ClusterGroup)session.get(ClusterGroupImpl.class,
247 clusterGroup.getPrimaryKeyObj());
248 }
249
250 if (clusterGroup != null) {
251 session.delete(clusterGroup);
252 }
253 }
254 catch (Exception e) {
255 throw processException(e);
256 }
257 finally {
258 closeSession(session);
259 }
260
261 if (clusterGroup != null) {
262 clearCache(clusterGroup);
263 }
264
265 return clusterGroup;
266 }
267
268 @Override
269 public ClusterGroup updateImpl(
270 com.liferay.portal.model.ClusterGroup clusterGroup)
271 throws SystemException {
272 clusterGroup = toUnwrappedModel(clusterGroup);
273
274 boolean isNew = clusterGroup.isNew();
275
276 Session session = null;
277
278 try {
279 session = openSession();
280
281 if (clusterGroup.isNew()) {
282 session.save(clusterGroup);
283
284 clusterGroup.setNew(false);
285 }
286 else {
287 session.merge(clusterGroup);
288 }
289 }
290 catch (Exception e) {
291 throw processException(e);
292 }
293 finally {
294 closeSession(session);
295 }
296
297 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
298
299 if (isNew) {
300 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
301 }
302
303 EntityCacheUtil.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
304 ClusterGroupImpl.class, clusterGroup.getPrimaryKey(), clusterGroup);
305
306 return clusterGroup;
307 }
308
309 protected ClusterGroup toUnwrappedModel(ClusterGroup clusterGroup) {
310 if (clusterGroup instanceof ClusterGroupImpl) {
311 return clusterGroup;
312 }
313
314 ClusterGroupImpl clusterGroupImpl = new ClusterGroupImpl();
315
316 clusterGroupImpl.setNew(clusterGroup.isNew());
317 clusterGroupImpl.setPrimaryKey(clusterGroup.getPrimaryKey());
318
319 clusterGroupImpl.setClusterGroupId(clusterGroup.getClusterGroupId());
320 clusterGroupImpl.setName(clusterGroup.getName());
321 clusterGroupImpl.setClusterNodeIds(clusterGroup.getClusterNodeIds());
322 clusterGroupImpl.setWholeCluster(clusterGroup.isWholeCluster());
323
324 return clusterGroupImpl;
325 }
326
327
335 @Override
336 public ClusterGroup findByPrimaryKey(Serializable primaryKey)
337 throws NoSuchClusterGroupException, SystemException {
338 ClusterGroup clusterGroup = fetchByPrimaryKey(primaryKey);
339
340 if (clusterGroup == null) {
341 if (_log.isWarnEnabled()) {
342 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
343 }
344
345 throw new NoSuchClusterGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
346 primaryKey);
347 }
348
349 return clusterGroup;
350 }
351
352
360 @Override
361 public ClusterGroup findByPrimaryKey(long clusterGroupId)
362 throws NoSuchClusterGroupException, SystemException {
363 return findByPrimaryKey((Serializable)clusterGroupId);
364 }
365
366
373 @Override
374 public ClusterGroup fetchByPrimaryKey(Serializable primaryKey)
375 throws SystemException {
376 ClusterGroup clusterGroup = (ClusterGroup)EntityCacheUtil.getResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
377 ClusterGroupImpl.class, primaryKey);
378
379 if (clusterGroup == _nullClusterGroup) {
380 return null;
381 }
382
383 if (clusterGroup == null) {
384 Session session = null;
385
386 try {
387 session = openSession();
388
389 clusterGroup = (ClusterGroup)session.get(ClusterGroupImpl.class,
390 primaryKey);
391
392 if (clusterGroup != null) {
393 cacheResult(clusterGroup);
394 }
395 else {
396 EntityCacheUtil.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
397 ClusterGroupImpl.class, primaryKey, _nullClusterGroup);
398 }
399 }
400 catch (Exception e) {
401 EntityCacheUtil.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
402 ClusterGroupImpl.class, primaryKey);
403
404 throw processException(e);
405 }
406 finally {
407 closeSession(session);
408 }
409 }
410
411 return clusterGroup;
412 }
413
414
421 @Override
422 public ClusterGroup fetchByPrimaryKey(long clusterGroupId)
423 throws SystemException {
424 return fetchByPrimaryKey((Serializable)clusterGroupId);
425 }
426
427
433 @Override
434 public List<ClusterGroup> findAll() throws SystemException {
435 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
436 }
437
438
450 @Override
451 public List<ClusterGroup> findAll(int start, int end)
452 throws SystemException {
453 return findAll(start, end, null);
454 }
455
456
469 @Override
470 public List<ClusterGroup> findAll(int start, int end,
471 OrderByComparator orderByComparator) throws SystemException {
472 boolean pagination = true;
473 FinderPath finderPath = null;
474 Object[] finderArgs = null;
475
476 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
477 (orderByComparator == null)) {
478 pagination = false;
479 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
480 finderArgs = FINDER_ARGS_EMPTY;
481 }
482 else {
483 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
484 finderArgs = new Object[] { start, end, orderByComparator };
485 }
486
487 List<ClusterGroup> list = (List<ClusterGroup>)FinderCacheUtil.getResult(finderPath,
488 finderArgs, this);
489
490 if (list == null) {
491 StringBundler query = null;
492 String sql = null;
493
494 if (orderByComparator != null) {
495 query = new StringBundler(2 +
496 (orderByComparator.getOrderByFields().length * 3));
497
498 query.append(_SQL_SELECT_CLUSTERGROUP);
499
500 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
501 orderByComparator);
502
503 sql = query.toString();
504 }
505 else {
506 sql = _SQL_SELECT_CLUSTERGROUP;
507
508 if (pagination) {
509 sql = sql.concat(ClusterGroupModelImpl.ORDER_BY_JPQL);
510 }
511 }
512
513 Session session = null;
514
515 try {
516 session = openSession();
517
518 Query q = session.createQuery(sql);
519
520 if (!pagination) {
521 list = (List<ClusterGroup>)QueryUtil.list(q, getDialect(),
522 start, end, false);
523
524 Collections.sort(list);
525
526 list = new UnmodifiableList<ClusterGroup>(list);
527 }
528 else {
529 list = (List<ClusterGroup>)QueryUtil.list(q, getDialect(),
530 start, end);
531 }
532
533 cacheResult(list);
534
535 FinderCacheUtil.putResult(finderPath, finderArgs, list);
536 }
537 catch (Exception e) {
538 FinderCacheUtil.removeResult(finderPath, finderArgs);
539
540 throw processException(e);
541 }
542 finally {
543 closeSession(session);
544 }
545 }
546
547 return list;
548 }
549
550
555 @Override
556 public void removeAll() throws SystemException {
557 for (ClusterGroup clusterGroup : findAll()) {
558 remove(clusterGroup);
559 }
560 }
561
562
568 @Override
569 public int countAll() throws SystemException {
570 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
571 FINDER_ARGS_EMPTY, this);
572
573 if (count == null) {
574 Session session = null;
575
576 try {
577 session = openSession();
578
579 Query q = session.createQuery(_SQL_COUNT_CLUSTERGROUP);
580
581 count = (Long)q.uniqueResult();
582
583 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
584 FINDER_ARGS_EMPTY, count);
585 }
586 catch (Exception e) {
587 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
588 FINDER_ARGS_EMPTY);
589
590 throw processException(e);
591 }
592 finally {
593 closeSession(session);
594 }
595 }
596
597 return count.intValue();
598 }
599
600
603 public void afterPropertiesSet() {
604 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
605 com.liferay.portal.util.PropsUtil.get(
606 "value.object.listener.com.liferay.portal.model.ClusterGroup")));
607
608 if (listenerClassNames.length > 0) {
609 try {
610 List<ModelListener<ClusterGroup>> listenersList = new ArrayList<ModelListener<ClusterGroup>>();
611
612 for (String listenerClassName : listenerClassNames) {
613 listenersList.add((ModelListener<ClusterGroup>)InstanceFactory.newInstance(
614 getClassLoader(), listenerClassName));
615 }
616
617 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
618 }
619 catch (Exception e) {
620 _log.error(e);
621 }
622 }
623 }
624
625 public void destroy() {
626 EntityCacheUtil.removeCache(ClusterGroupImpl.class.getName());
627 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
628 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
629 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
630 }
631
632 private static final String _SQL_SELECT_CLUSTERGROUP = "SELECT clusterGroup FROM ClusterGroup clusterGroup";
633 private static final String _SQL_COUNT_CLUSTERGROUP = "SELECT COUNT(clusterGroup) FROM ClusterGroup clusterGroup";
634 private static final String _ORDER_BY_ENTITY_ALIAS = "clusterGroup.";
635 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ClusterGroup exists with the primary key ";
636 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
637 private static Log _log = LogFactoryUtil.getLog(ClusterGroupPersistenceImpl.class);
638 private static ClusterGroup _nullClusterGroup = new ClusterGroupImpl() {
639 @Override
640 public Object clone() {
641 return this;
642 }
643
644 @Override
645 public CacheModel<ClusterGroup> toCacheModel() {
646 return _nullClusterGroupCacheModel;
647 }
648 };
649
650 private static CacheModel<ClusterGroup> _nullClusterGroupCacheModel = new CacheModel<ClusterGroup>() {
651 @Override
652 public ClusterGroup toEntityModel() {
653 return _nullClusterGroup;
654 }
655 };
656 }