001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.NoSuchClusterGroupException;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderPath;
024 import com.liferay.portal.kernel.dao.orm.Query;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.OrderByComparator;
030 import com.liferay.portal.kernel.util.StringBundler;
031 import com.liferay.portal.kernel.util.StringPool;
032 import com.liferay.portal.model.CacheModel;
033 import com.liferay.portal.model.ClusterGroup;
034 import com.liferay.portal.model.MVCCModel;
035 import com.liferay.portal.model.impl.ClusterGroupImpl;
036 import com.liferay.portal.model.impl.ClusterGroupModelImpl;
037 import com.liferay.portal.service.persistence.ClusterGroupPersistence;
038
039 import java.io.Serializable;
040
041 import java.util.Collections;
042 import java.util.HashMap;
043 import java.util.HashSet;
044 import java.util.Iterator;
045 import java.util.List;
046 import java.util.Map;
047 import java.util.Set;
048
049
061 @ProviderType
062 public class ClusterGroupPersistenceImpl extends BasePersistenceImpl<ClusterGroup>
063 implements ClusterGroupPersistence {
064
069 public static final String FINDER_CLASS_NAME_ENTITY = ClusterGroupImpl.class.getName();
070 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071 ".List1";
072 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List2";
074 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
075 ClusterGroupModelImpl.FINDER_CACHE_ENABLED, ClusterGroupImpl.class,
076 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
077 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
078 ClusterGroupModelImpl.FINDER_CACHE_ENABLED, ClusterGroupImpl.class,
079 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
080 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
081 ClusterGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
083
084 public ClusterGroupPersistenceImpl() {
085 setModelClass(ClusterGroup.class);
086 }
087
088
093 @Override
094 public void cacheResult(ClusterGroup clusterGroup) {
095 EntityCacheUtil.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
096 ClusterGroupImpl.class, clusterGroup.getPrimaryKey(), clusterGroup);
097
098 clusterGroup.resetOriginalValues();
099 }
100
101
106 @Override
107 public void cacheResult(List<ClusterGroup> clusterGroups) {
108 for (ClusterGroup clusterGroup : clusterGroups) {
109 if (EntityCacheUtil.getResult(
110 ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
111 ClusterGroupImpl.class, clusterGroup.getPrimaryKey()) == null) {
112 cacheResult(clusterGroup);
113 }
114 else {
115 clusterGroup.resetOriginalValues();
116 }
117 }
118 }
119
120
127 @Override
128 public void clearCache() {
129 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
130 CacheRegistryUtil.clear(ClusterGroupImpl.class.getName());
131 }
132
133 EntityCacheUtil.clearCache(ClusterGroupImpl.class);
134
135 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
136 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
137 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
138 }
139
140
147 @Override
148 public void clearCache(ClusterGroup clusterGroup) {
149 EntityCacheUtil.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
150 ClusterGroupImpl.class, clusterGroup.getPrimaryKey());
151
152 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
153 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
154 }
155
156 @Override
157 public void clearCache(List<ClusterGroup> clusterGroups) {
158 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
159 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
160
161 for (ClusterGroup clusterGroup : clusterGroups) {
162 EntityCacheUtil.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
163 ClusterGroupImpl.class, clusterGroup.getPrimaryKey());
164 }
165 }
166
167
173 @Override
174 public ClusterGroup create(long clusterGroupId) {
175 ClusterGroup clusterGroup = new ClusterGroupImpl();
176
177 clusterGroup.setNew(true);
178 clusterGroup.setPrimaryKey(clusterGroupId);
179
180 return clusterGroup;
181 }
182
183
190 @Override
191 public ClusterGroup remove(long clusterGroupId)
192 throws NoSuchClusterGroupException {
193 return remove((Serializable)clusterGroupId);
194 }
195
196
203 @Override
204 public ClusterGroup remove(Serializable primaryKey)
205 throws NoSuchClusterGroupException {
206 Session session = null;
207
208 try {
209 session = openSession();
210
211 ClusterGroup clusterGroup = (ClusterGroup)session.get(ClusterGroupImpl.class,
212 primaryKey);
213
214 if (clusterGroup == null) {
215 if (_log.isWarnEnabled()) {
216 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
217 }
218
219 throw new NoSuchClusterGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
220 primaryKey);
221 }
222
223 return remove(clusterGroup);
224 }
225 catch (NoSuchClusterGroupException nsee) {
226 throw nsee;
227 }
228 catch (Exception e) {
229 throw processException(e);
230 }
231 finally {
232 closeSession(session);
233 }
234 }
235
236 @Override
237 protected ClusterGroup removeImpl(ClusterGroup clusterGroup) {
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 clusterGroup = toUnwrappedModel(clusterGroup);
272
273 boolean isNew = clusterGroup.isNew();
274
275 Session session = null;
276
277 try {
278 session = openSession();
279
280 if (clusterGroup.isNew()) {
281 session.save(clusterGroup);
282
283 clusterGroup.setNew(false);
284 }
285 else {
286 session.merge(clusterGroup);
287 }
288 }
289 catch (Exception e) {
290 throw processException(e);
291 }
292 finally {
293 closeSession(session);
294 }
295
296 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
297
298 if (isNew) {
299 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
300 }
301
302 EntityCacheUtil.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
303 ClusterGroupImpl.class, clusterGroup.getPrimaryKey(), clusterGroup,
304 false);
305
306 clusterGroup.resetOriginalValues();
307
308 return clusterGroup;
309 }
310
311 protected ClusterGroup toUnwrappedModel(ClusterGroup clusterGroup) {
312 if (clusterGroup instanceof ClusterGroupImpl) {
313 return clusterGroup;
314 }
315
316 ClusterGroupImpl clusterGroupImpl = new ClusterGroupImpl();
317
318 clusterGroupImpl.setNew(clusterGroup.isNew());
319 clusterGroupImpl.setPrimaryKey(clusterGroup.getPrimaryKey());
320
321 clusterGroupImpl.setMvccVersion(clusterGroup.getMvccVersion());
322 clusterGroupImpl.setClusterGroupId(clusterGroup.getClusterGroupId());
323 clusterGroupImpl.setName(clusterGroup.getName());
324 clusterGroupImpl.setClusterNodeIds(clusterGroup.getClusterNodeIds());
325 clusterGroupImpl.setWholeCluster(clusterGroup.isWholeCluster());
326
327 return clusterGroupImpl;
328 }
329
330
337 @Override
338 public ClusterGroup findByPrimaryKey(Serializable primaryKey)
339 throws NoSuchClusterGroupException {
340 ClusterGroup clusterGroup = fetchByPrimaryKey(primaryKey);
341
342 if (clusterGroup == null) {
343 if (_log.isWarnEnabled()) {
344 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
345 }
346
347 throw new NoSuchClusterGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
348 primaryKey);
349 }
350
351 return clusterGroup;
352 }
353
354
361 @Override
362 public ClusterGroup findByPrimaryKey(long clusterGroupId)
363 throws NoSuchClusterGroupException {
364 return findByPrimaryKey((Serializable)clusterGroupId);
365 }
366
367
373 @Override
374 public ClusterGroup fetchByPrimaryKey(Serializable primaryKey) {
375 ClusterGroup clusterGroup = (ClusterGroup)EntityCacheUtil.getResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
376 ClusterGroupImpl.class, primaryKey);
377
378 if (clusterGroup == _nullClusterGroup) {
379 return null;
380 }
381
382 if (clusterGroup == null) {
383 Session session = null;
384
385 try {
386 session = openSession();
387
388 clusterGroup = (ClusterGroup)session.get(ClusterGroupImpl.class,
389 primaryKey);
390
391 if (clusterGroup != null) {
392 cacheResult(clusterGroup);
393 }
394 else {
395 EntityCacheUtil.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
396 ClusterGroupImpl.class, primaryKey, _nullClusterGroup);
397 }
398 }
399 catch (Exception e) {
400 EntityCacheUtil.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
401 ClusterGroupImpl.class, primaryKey);
402
403 throw processException(e);
404 }
405 finally {
406 closeSession(session);
407 }
408 }
409
410 return clusterGroup;
411 }
412
413
419 @Override
420 public ClusterGroup fetchByPrimaryKey(long clusterGroupId) {
421 return fetchByPrimaryKey((Serializable)clusterGroupId);
422 }
423
424 @Override
425 public Map<Serializable, ClusterGroup> fetchByPrimaryKeys(
426 Set<Serializable> primaryKeys) {
427 if (primaryKeys.isEmpty()) {
428 return Collections.emptyMap();
429 }
430
431 Map<Serializable, ClusterGroup> map = new HashMap<Serializable, ClusterGroup>();
432
433 if (primaryKeys.size() == 1) {
434 Iterator<Serializable> iterator = primaryKeys.iterator();
435
436 Serializable primaryKey = iterator.next();
437
438 ClusterGroup clusterGroup = fetchByPrimaryKey(primaryKey);
439
440 if (clusterGroup != null) {
441 map.put(primaryKey, clusterGroup);
442 }
443
444 return map;
445 }
446
447 Set<Serializable> uncachedPrimaryKeys = null;
448
449 for (Serializable primaryKey : primaryKeys) {
450 ClusterGroup clusterGroup = (ClusterGroup)EntityCacheUtil.getResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
451 ClusterGroupImpl.class, primaryKey);
452
453 if (clusterGroup == null) {
454 if (uncachedPrimaryKeys == null) {
455 uncachedPrimaryKeys = new HashSet<Serializable>();
456 }
457
458 uncachedPrimaryKeys.add(primaryKey);
459 }
460 else {
461 map.put(primaryKey, clusterGroup);
462 }
463 }
464
465 if (uncachedPrimaryKeys == null) {
466 return map;
467 }
468
469 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
470 1);
471
472 query.append(_SQL_SELECT_CLUSTERGROUP_WHERE_PKS_IN);
473
474 for (Serializable primaryKey : uncachedPrimaryKeys) {
475 query.append(String.valueOf(primaryKey));
476
477 query.append(StringPool.COMMA);
478 }
479
480 query.setIndex(query.index() - 1);
481
482 query.append(StringPool.CLOSE_PARENTHESIS);
483
484 String sql = query.toString();
485
486 Session session = null;
487
488 try {
489 session = openSession();
490
491 Query q = session.createQuery(sql);
492
493 for (ClusterGroup clusterGroup : (List<ClusterGroup>)q.list()) {
494 map.put(clusterGroup.getPrimaryKeyObj(), clusterGroup);
495
496 cacheResult(clusterGroup);
497
498 uncachedPrimaryKeys.remove(clusterGroup.getPrimaryKeyObj());
499 }
500
501 for (Serializable primaryKey : uncachedPrimaryKeys) {
502 EntityCacheUtil.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
503 ClusterGroupImpl.class, primaryKey, _nullClusterGroup);
504 }
505 }
506 catch (Exception e) {
507 throw processException(e);
508 }
509 finally {
510 closeSession(session);
511 }
512
513 return map;
514 }
515
516
521 @Override
522 public List<ClusterGroup> findAll() {
523 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
524 }
525
526
537 @Override
538 public List<ClusterGroup> findAll(int start, int end) {
539 return findAll(start, end, null);
540 }
541
542
554 @Override
555 public List<ClusterGroup> findAll(int start, int end,
556 OrderByComparator<ClusterGroup> orderByComparator) {
557 boolean pagination = true;
558 FinderPath finderPath = null;
559 Object[] finderArgs = null;
560
561 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
562 (orderByComparator == null)) {
563 pagination = false;
564 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
565 finderArgs = FINDER_ARGS_EMPTY;
566 }
567 else {
568 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
569 finderArgs = new Object[] { start, end, orderByComparator };
570 }
571
572 List<ClusterGroup> list = (List<ClusterGroup>)FinderCacheUtil.getResult(finderPath,
573 finderArgs, this);
574
575 if (list == null) {
576 StringBundler query = null;
577 String sql = null;
578
579 if (orderByComparator != null) {
580 query = new StringBundler(2 +
581 (orderByComparator.getOrderByFields().length * 3));
582
583 query.append(_SQL_SELECT_CLUSTERGROUP);
584
585 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
586 orderByComparator);
587
588 sql = query.toString();
589 }
590 else {
591 sql = _SQL_SELECT_CLUSTERGROUP;
592
593 if (pagination) {
594 sql = sql.concat(ClusterGroupModelImpl.ORDER_BY_JPQL);
595 }
596 }
597
598 Session session = null;
599
600 try {
601 session = openSession();
602
603 Query q = session.createQuery(sql);
604
605 if (!pagination) {
606 list = (List<ClusterGroup>)QueryUtil.list(q, getDialect(),
607 start, end, false);
608
609 Collections.sort(list);
610
611 list = Collections.unmodifiableList(list);
612 }
613 else {
614 list = (List<ClusterGroup>)QueryUtil.list(q, getDialect(),
615 start, end);
616 }
617
618 cacheResult(list);
619
620 FinderCacheUtil.putResult(finderPath, finderArgs, list);
621 }
622 catch (Exception e) {
623 FinderCacheUtil.removeResult(finderPath, finderArgs);
624
625 throw processException(e);
626 }
627 finally {
628 closeSession(session);
629 }
630 }
631
632 return list;
633 }
634
635
639 @Override
640 public void removeAll() {
641 for (ClusterGroup clusterGroup : findAll()) {
642 remove(clusterGroup);
643 }
644 }
645
646
651 @Override
652 public int countAll() {
653 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
654 FINDER_ARGS_EMPTY, this);
655
656 if (count == null) {
657 Session session = null;
658
659 try {
660 session = openSession();
661
662 Query q = session.createQuery(_SQL_COUNT_CLUSTERGROUP);
663
664 count = (Long)q.uniqueResult();
665
666 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
667 FINDER_ARGS_EMPTY, count);
668 }
669 catch (Exception e) {
670 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
671 FINDER_ARGS_EMPTY);
672
673 throw processException(e);
674 }
675 finally {
676 closeSession(session);
677 }
678 }
679
680 return count.intValue();
681 }
682
683
686 public void afterPropertiesSet() {
687 }
688
689 public void destroy() {
690 EntityCacheUtil.removeCache(ClusterGroupImpl.class.getName());
691 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
692 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
693 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
694 }
695
696 private static final String _SQL_SELECT_CLUSTERGROUP = "SELECT clusterGroup FROM ClusterGroup clusterGroup";
697 private static final String _SQL_SELECT_CLUSTERGROUP_WHERE_PKS_IN = "SELECT clusterGroup FROM ClusterGroup clusterGroup WHERE clusterGroupId IN (";
698 private static final String _SQL_COUNT_CLUSTERGROUP = "SELECT COUNT(clusterGroup) FROM ClusterGroup clusterGroup";
699 private static final String _ORDER_BY_ENTITY_ALIAS = "clusterGroup.";
700 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ClusterGroup exists with the primary key ";
701 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
702 private static final Log _log = LogFactoryUtil.getLog(ClusterGroupPersistenceImpl.class);
703 private static final ClusterGroup _nullClusterGroup = new ClusterGroupImpl() {
704 @Override
705 public Object clone() {
706 return this;
707 }
708
709 @Override
710 public CacheModel<ClusterGroup> toCacheModel() {
711 return _nullClusterGroupCacheModel;
712 }
713 };
714
715 private static final CacheModel<ClusterGroup> _nullClusterGroupCacheModel = new NullCacheModel();
716
717 private static class NullCacheModel implements CacheModel<ClusterGroup>,
718 MVCCModel {
719 @Override
720 public long getMvccVersion() {
721 return -1;
722 }
723
724 @Override
725 public void setMvccVersion(long mvccVersion) {
726 }
727
728 @Override
729 public ClusterGroup toEntityModel() {
730 return _nullClusterGroup;
731 }
732 }
733 }