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.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.log.Log;
027 import com.liferay.portal.kernel.log.LogFactoryUtil;
028 import com.liferay.portal.kernel.util.OrderByComparator;
029 import com.liferay.portal.kernel.util.StringBundler;
030 import com.liferay.portal.kernel.util.StringPool;
031 import com.liferay.portal.model.CacheModel;
032 import com.liferay.portal.model.ClusterGroup;
033 import com.liferay.portal.model.MVCCModel;
034 import com.liferay.portal.model.impl.ClusterGroupImpl;
035 import com.liferay.portal.model.impl.ClusterGroupModelImpl;
036 import com.liferay.portal.service.persistence.ClusterGroupPersistence;
037
038 import java.io.Serializable;
039
040 import java.util.Collections;
041 import java.util.HashMap;
042 import java.util.HashSet;
043 import java.util.Iterator;
044 import java.util.List;
045 import java.util.Map;
046 import java.util.Set;
047
048
060 @ProviderType
061 public class ClusterGroupPersistenceImpl extends BasePersistenceImpl<ClusterGroup>
062 implements ClusterGroupPersistence {
063
068 public static final String FINDER_CLASS_NAME_ENTITY = ClusterGroupImpl.class.getName();
069 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
070 ".List1";
071 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072 ".List2";
073 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
074 ClusterGroupModelImpl.FINDER_CACHE_ENABLED, ClusterGroupImpl.class,
075 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
076 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
077 ClusterGroupModelImpl.FINDER_CACHE_ENABLED, ClusterGroupImpl.class,
078 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
079 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
080 ClusterGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
081 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
082
083 public ClusterGroupPersistenceImpl() {
084 setModelClass(ClusterGroup.class);
085 }
086
087
092 @Override
093 public void cacheResult(ClusterGroup clusterGroup) {
094 EntityCacheUtil.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
095 ClusterGroupImpl.class, clusterGroup.getPrimaryKey(), clusterGroup);
096
097 clusterGroup.resetOriginalValues();
098 }
099
100
105 @Override
106 public void cacheResult(List<ClusterGroup> clusterGroups) {
107 for (ClusterGroup clusterGroup : clusterGroups) {
108 if (EntityCacheUtil.getResult(
109 ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
110 ClusterGroupImpl.class, clusterGroup.getPrimaryKey()) == null) {
111 cacheResult(clusterGroup);
112 }
113 else {
114 clusterGroup.resetOriginalValues();
115 }
116 }
117 }
118
119
126 @Override
127 public void clearCache() {
128 EntityCacheUtil.clearCache(ClusterGroupImpl.class);
129
130 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
131 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
132 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
133 }
134
135
142 @Override
143 public void clearCache(ClusterGroup clusterGroup) {
144 EntityCacheUtil.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
145 ClusterGroupImpl.class, clusterGroup.getPrimaryKey());
146
147 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
148 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
149 }
150
151 @Override
152 public void clearCache(List<ClusterGroup> clusterGroups) {
153 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
154 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
155
156 for (ClusterGroup clusterGroup : clusterGroups) {
157 EntityCacheUtil.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
158 ClusterGroupImpl.class, clusterGroup.getPrimaryKey());
159 }
160 }
161
162
168 @Override
169 public ClusterGroup create(long clusterGroupId) {
170 ClusterGroup clusterGroup = new ClusterGroupImpl();
171
172 clusterGroup.setNew(true);
173 clusterGroup.setPrimaryKey(clusterGroupId);
174
175 return clusterGroup;
176 }
177
178
185 @Override
186 public ClusterGroup remove(long clusterGroupId)
187 throws NoSuchClusterGroupException {
188 return remove((Serializable)clusterGroupId);
189 }
190
191
198 @Override
199 public ClusterGroup remove(Serializable primaryKey)
200 throws NoSuchClusterGroupException {
201 Session session = null;
202
203 try {
204 session = openSession();
205
206 ClusterGroup clusterGroup = (ClusterGroup)session.get(ClusterGroupImpl.class,
207 primaryKey);
208
209 if (clusterGroup == null) {
210 if (_log.isWarnEnabled()) {
211 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
212 }
213
214 throw new NoSuchClusterGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
215 primaryKey);
216 }
217
218 return remove(clusterGroup);
219 }
220 catch (NoSuchClusterGroupException nsee) {
221 throw nsee;
222 }
223 catch (Exception e) {
224 throw processException(e);
225 }
226 finally {
227 closeSession(session);
228 }
229 }
230
231 @Override
232 protected ClusterGroup removeImpl(ClusterGroup clusterGroup) {
233 clusterGroup = toUnwrappedModel(clusterGroup);
234
235 Session session = null;
236
237 try {
238 session = openSession();
239
240 if (!session.contains(clusterGroup)) {
241 clusterGroup = (ClusterGroup)session.get(ClusterGroupImpl.class,
242 clusterGroup.getPrimaryKeyObj());
243 }
244
245 if (clusterGroup != null) {
246 session.delete(clusterGroup);
247 }
248 }
249 catch (Exception e) {
250 throw processException(e);
251 }
252 finally {
253 closeSession(session);
254 }
255
256 if (clusterGroup != null) {
257 clearCache(clusterGroup);
258 }
259
260 return clusterGroup;
261 }
262
263 @Override
264 public ClusterGroup updateImpl(ClusterGroup clusterGroup) {
265 clusterGroup = toUnwrappedModel(clusterGroup);
266
267 boolean isNew = clusterGroup.isNew();
268
269 Session session = null;
270
271 try {
272 session = openSession();
273
274 if (clusterGroup.isNew()) {
275 session.save(clusterGroup);
276
277 clusterGroup.setNew(false);
278 }
279 else {
280 session.merge(clusterGroup);
281 }
282 }
283 catch (Exception e) {
284 throw processException(e);
285 }
286 finally {
287 closeSession(session);
288 }
289
290 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
291
292 if (isNew) {
293 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
294 }
295
296 EntityCacheUtil.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
297 ClusterGroupImpl.class, clusterGroup.getPrimaryKey(), clusterGroup,
298 false);
299
300 clusterGroup.resetOriginalValues();
301
302 return clusterGroup;
303 }
304
305 protected ClusterGroup toUnwrappedModel(ClusterGroup clusterGroup) {
306 if (clusterGroup instanceof ClusterGroupImpl) {
307 return clusterGroup;
308 }
309
310 ClusterGroupImpl clusterGroupImpl = new ClusterGroupImpl();
311
312 clusterGroupImpl.setNew(clusterGroup.isNew());
313 clusterGroupImpl.setPrimaryKey(clusterGroup.getPrimaryKey());
314
315 clusterGroupImpl.setMvccVersion(clusterGroup.getMvccVersion());
316 clusterGroupImpl.setClusterGroupId(clusterGroup.getClusterGroupId());
317 clusterGroupImpl.setName(clusterGroup.getName());
318 clusterGroupImpl.setClusterNodeIds(clusterGroup.getClusterNodeIds());
319 clusterGroupImpl.setWholeCluster(clusterGroup.isWholeCluster());
320
321 return clusterGroupImpl;
322 }
323
324
331 @Override
332 public ClusterGroup findByPrimaryKey(Serializable primaryKey)
333 throws NoSuchClusterGroupException {
334 ClusterGroup clusterGroup = fetchByPrimaryKey(primaryKey);
335
336 if (clusterGroup == null) {
337 if (_log.isWarnEnabled()) {
338 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
339 }
340
341 throw new NoSuchClusterGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
342 primaryKey);
343 }
344
345 return clusterGroup;
346 }
347
348
355 @Override
356 public ClusterGroup findByPrimaryKey(long clusterGroupId)
357 throws NoSuchClusterGroupException {
358 return findByPrimaryKey((Serializable)clusterGroupId);
359 }
360
361
367 @Override
368 public ClusterGroup fetchByPrimaryKey(Serializable primaryKey) {
369 ClusterGroup clusterGroup = (ClusterGroup)EntityCacheUtil.getResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
370 ClusterGroupImpl.class, primaryKey);
371
372 if (clusterGroup == _nullClusterGroup) {
373 return null;
374 }
375
376 if (clusterGroup == null) {
377 Session session = null;
378
379 try {
380 session = openSession();
381
382 clusterGroup = (ClusterGroup)session.get(ClusterGroupImpl.class,
383 primaryKey);
384
385 if (clusterGroup != null) {
386 cacheResult(clusterGroup);
387 }
388 else {
389 EntityCacheUtil.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
390 ClusterGroupImpl.class, primaryKey, _nullClusterGroup);
391 }
392 }
393 catch (Exception e) {
394 EntityCacheUtil.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
395 ClusterGroupImpl.class, primaryKey);
396
397 throw processException(e);
398 }
399 finally {
400 closeSession(session);
401 }
402 }
403
404 return clusterGroup;
405 }
406
407
413 @Override
414 public ClusterGroup fetchByPrimaryKey(long clusterGroupId) {
415 return fetchByPrimaryKey((Serializable)clusterGroupId);
416 }
417
418 @Override
419 public Map<Serializable, ClusterGroup> fetchByPrimaryKeys(
420 Set<Serializable> primaryKeys) {
421 if (primaryKeys.isEmpty()) {
422 return Collections.emptyMap();
423 }
424
425 Map<Serializable, ClusterGroup> map = new HashMap<Serializable, ClusterGroup>();
426
427 if (primaryKeys.size() == 1) {
428 Iterator<Serializable> iterator = primaryKeys.iterator();
429
430 Serializable primaryKey = iterator.next();
431
432 ClusterGroup clusterGroup = fetchByPrimaryKey(primaryKey);
433
434 if (clusterGroup != null) {
435 map.put(primaryKey, clusterGroup);
436 }
437
438 return map;
439 }
440
441 Set<Serializable> uncachedPrimaryKeys = null;
442
443 for (Serializable primaryKey : primaryKeys) {
444 ClusterGroup clusterGroup = (ClusterGroup)EntityCacheUtil.getResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
445 ClusterGroupImpl.class, primaryKey);
446
447 if (clusterGroup == null) {
448 if (uncachedPrimaryKeys == null) {
449 uncachedPrimaryKeys = new HashSet<Serializable>();
450 }
451
452 uncachedPrimaryKeys.add(primaryKey);
453 }
454 else {
455 map.put(primaryKey, clusterGroup);
456 }
457 }
458
459 if (uncachedPrimaryKeys == null) {
460 return map;
461 }
462
463 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
464 1);
465
466 query.append(_SQL_SELECT_CLUSTERGROUP_WHERE_PKS_IN);
467
468 for (Serializable primaryKey : uncachedPrimaryKeys) {
469 query.append(String.valueOf(primaryKey));
470
471 query.append(StringPool.COMMA);
472 }
473
474 query.setIndex(query.index() - 1);
475
476 query.append(StringPool.CLOSE_PARENTHESIS);
477
478 String sql = query.toString();
479
480 Session session = null;
481
482 try {
483 session = openSession();
484
485 Query q = session.createQuery(sql);
486
487 for (ClusterGroup clusterGroup : (List<ClusterGroup>)q.list()) {
488 map.put(clusterGroup.getPrimaryKeyObj(), clusterGroup);
489
490 cacheResult(clusterGroup);
491
492 uncachedPrimaryKeys.remove(clusterGroup.getPrimaryKeyObj());
493 }
494
495 for (Serializable primaryKey : uncachedPrimaryKeys) {
496 EntityCacheUtil.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
497 ClusterGroupImpl.class, primaryKey, _nullClusterGroup);
498 }
499 }
500 catch (Exception e) {
501 throw processException(e);
502 }
503 finally {
504 closeSession(session);
505 }
506
507 return map;
508 }
509
510
515 @Override
516 public List<ClusterGroup> findAll() {
517 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
518 }
519
520
531 @Override
532 public List<ClusterGroup> findAll(int start, int end) {
533 return findAll(start, end, null);
534 }
535
536
548 @Override
549 public List<ClusterGroup> findAll(int start, int end,
550 OrderByComparator<ClusterGroup> orderByComparator) {
551 boolean pagination = true;
552 FinderPath finderPath = null;
553 Object[] finderArgs = null;
554
555 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
556 (orderByComparator == null)) {
557 pagination = false;
558 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
559 finderArgs = FINDER_ARGS_EMPTY;
560 }
561 else {
562 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
563 finderArgs = new Object[] { start, end, orderByComparator };
564 }
565
566 List<ClusterGroup> list = (List<ClusterGroup>)FinderCacheUtil.getResult(finderPath,
567 finderArgs, this);
568
569 if (list == null) {
570 StringBundler query = null;
571 String sql = null;
572
573 if (orderByComparator != null) {
574 query = new StringBundler(2 +
575 (orderByComparator.getOrderByFields().length * 3));
576
577 query.append(_SQL_SELECT_CLUSTERGROUP);
578
579 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
580 orderByComparator);
581
582 sql = query.toString();
583 }
584 else {
585 sql = _SQL_SELECT_CLUSTERGROUP;
586
587 if (pagination) {
588 sql = sql.concat(ClusterGroupModelImpl.ORDER_BY_JPQL);
589 }
590 }
591
592 Session session = null;
593
594 try {
595 session = openSession();
596
597 Query q = session.createQuery(sql);
598
599 if (!pagination) {
600 list = (List<ClusterGroup>)QueryUtil.list(q, getDialect(),
601 start, end, false);
602
603 Collections.sort(list);
604
605 list = Collections.unmodifiableList(list);
606 }
607 else {
608 list = (List<ClusterGroup>)QueryUtil.list(q, getDialect(),
609 start, end);
610 }
611
612 cacheResult(list);
613
614 FinderCacheUtil.putResult(finderPath, finderArgs, list);
615 }
616 catch (Exception e) {
617 FinderCacheUtil.removeResult(finderPath, finderArgs);
618
619 throw processException(e);
620 }
621 finally {
622 closeSession(session);
623 }
624 }
625
626 return list;
627 }
628
629
633 @Override
634 public void removeAll() {
635 for (ClusterGroup clusterGroup : findAll()) {
636 remove(clusterGroup);
637 }
638 }
639
640
645 @Override
646 public int countAll() {
647 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
648 FINDER_ARGS_EMPTY, this);
649
650 if (count == null) {
651 Session session = null;
652
653 try {
654 session = openSession();
655
656 Query q = session.createQuery(_SQL_COUNT_CLUSTERGROUP);
657
658 count = (Long)q.uniqueResult();
659
660 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
661 FINDER_ARGS_EMPTY, count);
662 }
663 catch (Exception e) {
664 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
665 FINDER_ARGS_EMPTY);
666
667 throw processException(e);
668 }
669 finally {
670 closeSession(session);
671 }
672 }
673
674 return count.intValue();
675 }
676
677
680 public void afterPropertiesSet() {
681 }
682
683 public void destroy() {
684 EntityCacheUtil.removeCache(ClusterGroupImpl.class.getName());
685 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
686 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
687 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
688 }
689
690 private static final String _SQL_SELECT_CLUSTERGROUP = "SELECT clusterGroup FROM ClusterGroup clusterGroup";
691 private static final String _SQL_SELECT_CLUSTERGROUP_WHERE_PKS_IN = "SELECT clusterGroup FROM ClusterGroup clusterGroup WHERE clusterGroupId IN (";
692 private static final String _SQL_COUNT_CLUSTERGROUP = "SELECT COUNT(clusterGroup) FROM ClusterGroup clusterGroup";
693 private static final String _ORDER_BY_ENTITY_ALIAS = "clusterGroup.";
694 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ClusterGroup exists with the primary key ";
695 private static final Log _log = LogFactoryUtil.getLog(ClusterGroupPersistenceImpl.class);
696 private static final ClusterGroup _nullClusterGroup = new ClusterGroupImpl() {
697 @Override
698 public Object clone() {
699 return this;
700 }
701
702 @Override
703 public CacheModel<ClusterGroup> toCacheModel() {
704 return _nullClusterGroupCacheModel;
705 }
706 };
707
708 private static final CacheModel<ClusterGroup> _nullClusterGroupCacheModel = new NullCacheModel();
709
710 private static class NullCacheModel implements CacheModel<ClusterGroup>,
711 MVCCModel {
712 @Override
713 public long getMvccVersion() {
714 return -1;
715 }
716
717 @Override
718 public void setMvccVersion(long mvccVersion) {
719 }
720
721 @Override
722 public ClusterGroup toEntityModel() {
723 return _nullClusterGroup;
724 }
725 }
726 }