001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.kernel.dao.orm.EntityCache;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCache;
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.exception.NoSuchClusterGroupException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.model.CacheModel;
031 import com.liferay.portal.kernel.model.ClusterGroup;
032 import com.liferay.portal.kernel.model.MVCCModel;
033 import com.liferay.portal.kernel.service.persistence.ClusterGroupPersistence;
034 import com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl;
035 import com.liferay.portal.kernel.util.OrderByComparator;
036 import com.liferay.portal.kernel.util.StringBundler;
037 import com.liferay.portal.kernel.util.StringPool;
038 import com.liferay.portal.model.impl.ClusterGroupImpl;
039 import com.liferay.portal.model.impl.ClusterGroupModelImpl;
040
041 import java.io.Serializable;
042
043 import java.util.Collections;
044 import java.util.HashMap;
045 import java.util.HashSet;
046 import java.util.Iterator;
047 import java.util.List;
048 import java.util.Map;
049 import java.util.Set;
050
051
063 @ProviderType
064 public class ClusterGroupPersistenceImpl extends BasePersistenceImpl<ClusterGroup>
065 implements ClusterGroupPersistence {
066
071 public static final String FINDER_CLASS_NAME_ENTITY = ClusterGroupImpl.class.getName();
072 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List1";
074 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List2";
076 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
077 ClusterGroupModelImpl.FINDER_CACHE_ENABLED, ClusterGroupImpl.class,
078 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
079 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
080 ClusterGroupModelImpl.FINDER_CACHE_ENABLED, ClusterGroupImpl.class,
081 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
082 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
083 ClusterGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
084 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
085
086 public ClusterGroupPersistenceImpl() {
087 setModelClass(ClusterGroup.class);
088 }
089
090
095 @Override
096 public void cacheResult(ClusterGroup clusterGroup) {
097 entityCache.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
098 ClusterGroupImpl.class, clusterGroup.getPrimaryKey(), clusterGroup);
099
100 clusterGroup.resetOriginalValues();
101 }
102
103
108 @Override
109 public void cacheResult(List<ClusterGroup> clusterGroups) {
110 for (ClusterGroup clusterGroup : clusterGroups) {
111 if (entityCache.getResult(
112 ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
113 ClusterGroupImpl.class, clusterGroup.getPrimaryKey()) == null) {
114 cacheResult(clusterGroup);
115 }
116 else {
117 clusterGroup.resetOriginalValues();
118 }
119 }
120 }
121
122
129 @Override
130 public void clearCache() {
131 entityCache.clearCache(ClusterGroupImpl.class);
132
133 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
134 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
135 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
136 }
137
138
145 @Override
146 public void clearCache(ClusterGroup clusterGroup) {
147 entityCache.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
148 ClusterGroupImpl.class, clusterGroup.getPrimaryKey());
149
150 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
151 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
152 }
153
154 @Override
155 public void clearCache(List<ClusterGroup> clusterGroups) {
156 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
157 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
158
159 for (ClusterGroup clusterGroup : clusterGroups) {
160 entityCache.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
161 ClusterGroupImpl.class, clusterGroup.getPrimaryKey());
162 }
163 }
164
165
171 @Override
172 public ClusterGroup create(long clusterGroupId) {
173 ClusterGroup clusterGroup = new ClusterGroupImpl();
174
175 clusterGroup.setNew(true);
176 clusterGroup.setPrimaryKey(clusterGroupId);
177
178 return clusterGroup;
179 }
180
181
188 @Override
189 public ClusterGroup remove(long clusterGroupId)
190 throws NoSuchClusterGroupException {
191 return remove((Serializable)clusterGroupId);
192 }
193
194
201 @Override
202 public ClusterGroup remove(Serializable primaryKey)
203 throws NoSuchClusterGroupException {
204 Session session = null;
205
206 try {
207 session = openSession();
208
209 ClusterGroup clusterGroup = (ClusterGroup)session.get(ClusterGroupImpl.class,
210 primaryKey);
211
212 if (clusterGroup == null) {
213 if (_log.isWarnEnabled()) {
214 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
215 }
216
217 throw new NoSuchClusterGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
218 primaryKey);
219 }
220
221 return remove(clusterGroup);
222 }
223 catch (NoSuchClusterGroupException nsee) {
224 throw nsee;
225 }
226 catch (Exception e) {
227 throw processException(e);
228 }
229 finally {
230 closeSession(session);
231 }
232 }
233
234 @Override
235 protected ClusterGroup removeImpl(ClusterGroup clusterGroup) {
236 clusterGroup = toUnwrappedModel(clusterGroup);
237
238 Session session = null;
239
240 try {
241 session = openSession();
242
243 if (!session.contains(clusterGroup)) {
244 clusterGroup = (ClusterGroup)session.get(ClusterGroupImpl.class,
245 clusterGroup.getPrimaryKeyObj());
246 }
247
248 if (clusterGroup != null) {
249 session.delete(clusterGroup);
250 }
251 }
252 catch (Exception e) {
253 throw processException(e);
254 }
255 finally {
256 closeSession(session);
257 }
258
259 if (clusterGroup != null) {
260 clearCache(clusterGroup);
261 }
262
263 return clusterGroup;
264 }
265
266 @Override
267 public ClusterGroup updateImpl(ClusterGroup clusterGroup) {
268 clusterGroup = toUnwrappedModel(clusterGroup);
269
270 boolean isNew = clusterGroup.isNew();
271
272 Session session = null;
273
274 try {
275 session = openSession();
276
277 if (clusterGroup.isNew()) {
278 session.save(clusterGroup);
279
280 clusterGroup.setNew(false);
281 }
282 else {
283 clusterGroup = (ClusterGroup)session.merge(clusterGroup);
284 }
285 }
286 catch (Exception e) {
287 throw processException(e);
288 }
289 finally {
290 closeSession(session);
291 }
292
293 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
294
295 if (isNew) {
296 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
297 }
298
299 entityCache.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
300 ClusterGroupImpl.class, clusterGroup.getPrimaryKey(), clusterGroup,
301 false);
302
303 clusterGroup.resetOriginalValues();
304
305 return clusterGroup;
306 }
307
308 protected ClusterGroup toUnwrappedModel(ClusterGroup clusterGroup) {
309 if (clusterGroup instanceof ClusterGroupImpl) {
310 return clusterGroup;
311 }
312
313 ClusterGroupImpl clusterGroupImpl = new ClusterGroupImpl();
314
315 clusterGroupImpl.setNew(clusterGroup.isNew());
316 clusterGroupImpl.setPrimaryKey(clusterGroup.getPrimaryKey());
317
318 clusterGroupImpl.setMvccVersion(clusterGroup.getMvccVersion());
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
334 @Override
335 public ClusterGroup findByPrimaryKey(Serializable primaryKey)
336 throws NoSuchClusterGroupException {
337 ClusterGroup clusterGroup = fetchByPrimaryKey(primaryKey);
338
339 if (clusterGroup == null) {
340 if (_log.isWarnEnabled()) {
341 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
342 }
343
344 throw new NoSuchClusterGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
345 primaryKey);
346 }
347
348 return clusterGroup;
349 }
350
351
358 @Override
359 public ClusterGroup findByPrimaryKey(long clusterGroupId)
360 throws NoSuchClusterGroupException {
361 return findByPrimaryKey((Serializable)clusterGroupId);
362 }
363
364
370 @Override
371 public ClusterGroup fetchByPrimaryKey(Serializable primaryKey) {
372 ClusterGroup clusterGroup = (ClusterGroup)entityCache.getResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
373 ClusterGroupImpl.class, primaryKey);
374
375 if (clusterGroup == _nullClusterGroup) {
376 return null;
377 }
378
379 if (clusterGroup == null) {
380 Session session = null;
381
382 try {
383 session = openSession();
384
385 clusterGroup = (ClusterGroup)session.get(ClusterGroupImpl.class,
386 primaryKey);
387
388 if (clusterGroup != null) {
389 cacheResult(clusterGroup);
390 }
391 else {
392 entityCache.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
393 ClusterGroupImpl.class, primaryKey, _nullClusterGroup);
394 }
395 }
396 catch (Exception e) {
397 entityCache.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
398 ClusterGroupImpl.class, primaryKey);
399
400 throw processException(e);
401 }
402 finally {
403 closeSession(session);
404 }
405 }
406
407 return clusterGroup;
408 }
409
410
416 @Override
417 public ClusterGroup fetchByPrimaryKey(long clusterGroupId) {
418 return fetchByPrimaryKey((Serializable)clusterGroupId);
419 }
420
421 @Override
422 public Map<Serializable, ClusterGroup> fetchByPrimaryKeys(
423 Set<Serializable> primaryKeys) {
424 if (primaryKeys.isEmpty()) {
425 return Collections.emptyMap();
426 }
427
428 Map<Serializable, ClusterGroup> map = new HashMap<Serializable, ClusterGroup>();
429
430 if (primaryKeys.size() == 1) {
431 Iterator<Serializable> iterator = primaryKeys.iterator();
432
433 Serializable primaryKey = iterator.next();
434
435 ClusterGroup clusterGroup = fetchByPrimaryKey(primaryKey);
436
437 if (clusterGroup != null) {
438 map.put(primaryKey, clusterGroup);
439 }
440
441 return map;
442 }
443
444 Set<Serializable> uncachedPrimaryKeys = null;
445
446 for (Serializable primaryKey : primaryKeys) {
447 ClusterGroup clusterGroup = (ClusterGroup)entityCache.getResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
448 ClusterGroupImpl.class, primaryKey);
449
450 if (clusterGroup == null) {
451 if (uncachedPrimaryKeys == null) {
452 uncachedPrimaryKeys = new HashSet<Serializable>();
453 }
454
455 uncachedPrimaryKeys.add(primaryKey);
456 }
457 else {
458 map.put(primaryKey, clusterGroup);
459 }
460 }
461
462 if (uncachedPrimaryKeys == null) {
463 return map;
464 }
465
466 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
467 1);
468
469 query.append(_SQL_SELECT_CLUSTERGROUP_WHERE_PKS_IN);
470
471 for (Serializable primaryKey : uncachedPrimaryKeys) {
472 query.append(String.valueOf(primaryKey));
473
474 query.append(StringPool.COMMA);
475 }
476
477 query.setIndex(query.index() - 1);
478
479 query.append(StringPool.CLOSE_PARENTHESIS);
480
481 String sql = query.toString();
482
483 Session session = null;
484
485 try {
486 session = openSession();
487
488 Query q = session.createQuery(sql);
489
490 for (ClusterGroup clusterGroup : (List<ClusterGroup>)q.list()) {
491 map.put(clusterGroup.getPrimaryKeyObj(), clusterGroup);
492
493 cacheResult(clusterGroup);
494
495 uncachedPrimaryKeys.remove(clusterGroup.getPrimaryKeyObj());
496 }
497
498 for (Serializable primaryKey : uncachedPrimaryKeys) {
499 entityCache.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
500 ClusterGroupImpl.class, primaryKey, _nullClusterGroup);
501 }
502 }
503 catch (Exception e) {
504 throw processException(e);
505 }
506 finally {
507 closeSession(session);
508 }
509
510 return map;
511 }
512
513
518 @Override
519 public List<ClusterGroup> findAll() {
520 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
521 }
522
523
534 @Override
535 public List<ClusterGroup> findAll(int start, int end) {
536 return findAll(start, end, null);
537 }
538
539
551 @Override
552 public List<ClusterGroup> findAll(int start, int end,
553 OrderByComparator<ClusterGroup> orderByComparator) {
554 return findAll(start, end, orderByComparator, true);
555 }
556
557
570 @Override
571 public List<ClusterGroup> findAll(int start, int end,
572 OrderByComparator<ClusterGroup> orderByComparator,
573 boolean retrieveFromCache) {
574 boolean pagination = true;
575 FinderPath finderPath = null;
576 Object[] finderArgs = null;
577
578 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
579 (orderByComparator == null)) {
580 pagination = false;
581 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
582 finderArgs = FINDER_ARGS_EMPTY;
583 }
584 else {
585 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
586 finderArgs = new Object[] { start, end, orderByComparator };
587 }
588
589 List<ClusterGroup> list = null;
590
591 if (retrieveFromCache) {
592 list = (List<ClusterGroup>)finderCache.getResult(finderPath,
593 finderArgs, this);
594 }
595
596 if (list == null) {
597 StringBundler query = null;
598 String sql = null;
599
600 if (orderByComparator != null) {
601 query = new StringBundler(2 +
602 (orderByComparator.getOrderByFields().length * 2));
603
604 query.append(_SQL_SELECT_CLUSTERGROUP);
605
606 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
607 orderByComparator);
608
609 sql = query.toString();
610 }
611 else {
612 sql = _SQL_SELECT_CLUSTERGROUP;
613
614 if (pagination) {
615 sql = sql.concat(ClusterGroupModelImpl.ORDER_BY_JPQL);
616 }
617 }
618
619 Session session = null;
620
621 try {
622 session = openSession();
623
624 Query q = session.createQuery(sql);
625
626 if (!pagination) {
627 list = (List<ClusterGroup>)QueryUtil.list(q, getDialect(),
628 start, end, false);
629
630 Collections.sort(list);
631
632 list = Collections.unmodifiableList(list);
633 }
634 else {
635 list = (List<ClusterGroup>)QueryUtil.list(q, getDialect(),
636 start, end);
637 }
638
639 cacheResult(list);
640
641 finderCache.putResult(finderPath, finderArgs, list);
642 }
643 catch (Exception e) {
644 finderCache.removeResult(finderPath, finderArgs);
645
646 throw processException(e);
647 }
648 finally {
649 closeSession(session);
650 }
651 }
652
653 return list;
654 }
655
656
660 @Override
661 public void removeAll() {
662 for (ClusterGroup clusterGroup : findAll()) {
663 remove(clusterGroup);
664 }
665 }
666
667
672 @Override
673 public int countAll() {
674 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
675 FINDER_ARGS_EMPTY, this);
676
677 if (count == null) {
678 Session session = null;
679
680 try {
681 session = openSession();
682
683 Query q = session.createQuery(_SQL_COUNT_CLUSTERGROUP);
684
685 count = (Long)q.uniqueResult();
686
687 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
688 count);
689 }
690 catch (Exception e) {
691 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
692 FINDER_ARGS_EMPTY);
693
694 throw processException(e);
695 }
696 finally {
697 closeSession(session);
698 }
699 }
700
701 return count.intValue();
702 }
703
704 @Override
705 protected Map<String, Integer> getTableColumnsMap() {
706 return ClusterGroupModelImpl.TABLE_COLUMNS_MAP;
707 }
708
709
712 public void afterPropertiesSet() {
713 }
714
715 public void destroy() {
716 entityCache.removeCache(ClusterGroupImpl.class.getName());
717 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
718 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
719 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
720 }
721
722 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
723 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
724 private static final String _SQL_SELECT_CLUSTERGROUP = "SELECT clusterGroup FROM ClusterGroup clusterGroup";
725 private static final String _SQL_SELECT_CLUSTERGROUP_WHERE_PKS_IN = "SELECT clusterGroup FROM ClusterGroup clusterGroup WHERE clusterGroupId IN (";
726 private static final String _SQL_COUNT_CLUSTERGROUP = "SELECT COUNT(clusterGroup) FROM ClusterGroup clusterGroup";
727 private static final String _ORDER_BY_ENTITY_ALIAS = "clusterGroup.";
728 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ClusterGroup exists with the primary key ";
729 private static final Log _log = LogFactoryUtil.getLog(ClusterGroupPersistenceImpl.class);
730 private static final ClusterGroup _nullClusterGroup = new ClusterGroupImpl() {
731 @Override
732 public Object clone() {
733 return this;
734 }
735
736 @Override
737 public CacheModel<ClusterGroup> toCacheModel() {
738 return _nullClusterGroupCacheModel;
739 }
740 };
741
742 private static final CacheModel<ClusterGroup> _nullClusterGroupCacheModel = new NullCacheModel();
743
744 private static class NullCacheModel implements CacheModel<ClusterGroup>,
745 MVCCModel {
746 @Override
747 public long getMvccVersion() {
748 return -1;
749 }
750
751 @Override
752 public void setMvccVersion(long mvccVersion) {
753 }
754
755 @Override
756 public ClusterGroup toEntityModel() {
757 return _nullClusterGroup;
758 }
759 }
760 }