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
086 @Override
087 public void cacheResult(ClusterGroup clusterGroup) {
088 EntityCacheUtil.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
089 ClusterGroupImpl.class, clusterGroup.getPrimaryKey(), clusterGroup);
090
091 clusterGroup.resetOriginalValues();
092 }
093
094
099 @Override
100 public void cacheResult(List<ClusterGroup> clusterGroups) {
101 for (ClusterGroup clusterGroup : clusterGroups) {
102 if (EntityCacheUtil.getResult(
103 ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
104 ClusterGroupImpl.class, clusterGroup.getPrimaryKey()) == null) {
105 cacheResult(clusterGroup);
106 }
107 else {
108 clusterGroup.resetOriginalValues();
109 }
110 }
111 }
112
113
120 @Override
121 public void clearCache() {
122 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
123 CacheRegistryUtil.clear(ClusterGroupImpl.class.getName());
124 }
125
126 EntityCacheUtil.clearCache(ClusterGroupImpl.class.getName());
127
128 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
129 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
130 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
131 }
132
133
140 @Override
141 public void clearCache(ClusterGroup clusterGroup) {
142 EntityCacheUtil.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
143 ClusterGroupImpl.class, clusterGroup.getPrimaryKey());
144
145 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
146 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
147 }
148
149 @Override
150 public void clearCache(List<ClusterGroup> clusterGroups) {
151 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
152 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
153
154 for (ClusterGroup clusterGroup : clusterGroups) {
155 EntityCacheUtil.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
156 ClusterGroupImpl.class, clusterGroup.getPrimaryKey());
157 }
158 }
159
160
166 @Override
167 public ClusterGroup create(long clusterGroupId) {
168 ClusterGroup clusterGroup = new ClusterGroupImpl();
169
170 clusterGroup.setNew(true);
171 clusterGroup.setPrimaryKey(clusterGroupId);
172
173 return clusterGroup;
174 }
175
176
184 @Override
185 public ClusterGroup remove(long clusterGroupId)
186 throws NoSuchClusterGroupException, SystemException {
187 return remove((Serializable)clusterGroupId);
188 }
189
190
198 @Override
199 public ClusterGroup remove(Serializable primaryKey)
200 throws NoSuchClusterGroupException, SystemException {
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 throws SystemException {
234 clusterGroup = toUnwrappedModel(clusterGroup);
235
236 Session session = null;
237
238 try {
239 session = openSession();
240
241 if (!session.contains(clusterGroup)) {
242 clusterGroup = (ClusterGroup)session.get(ClusterGroupImpl.class,
243 clusterGroup.getPrimaryKeyObj());
244 }
245
246 if (clusterGroup != null) {
247 session.delete(clusterGroup);
248 }
249 }
250 catch (Exception e) {
251 throw processException(e);
252 }
253 finally {
254 closeSession(session);
255 }
256
257 if (clusterGroup != null) {
258 clearCache(clusterGroup);
259 }
260
261 return clusterGroup;
262 }
263
264 @Override
265 public ClusterGroup updateImpl(
266 com.liferay.portal.model.ClusterGroup clusterGroup)
267 throws SystemException {
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 session.merge(clusterGroup);
284 }
285 }
286 catch (Exception e) {
287 throw processException(e);
288 }
289 finally {
290 closeSession(session);
291 }
292
293 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
294
295 if (isNew) {
296 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
297 }
298
299 EntityCacheUtil.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
300 ClusterGroupImpl.class, clusterGroup.getPrimaryKey(), clusterGroup);
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.setClusterGroupId(clusterGroup.getClusterGroupId());
316 clusterGroupImpl.setName(clusterGroup.getName());
317 clusterGroupImpl.setClusterNodeIds(clusterGroup.getClusterNodeIds());
318 clusterGroupImpl.setWholeCluster(clusterGroup.isWholeCluster());
319
320 return clusterGroupImpl;
321 }
322
323
331 @Override
332 public ClusterGroup findByPrimaryKey(Serializable primaryKey)
333 throws NoSuchClusterGroupException, SystemException {
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
356 @Override
357 public ClusterGroup findByPrimaryKey(long clusterGroupId)
358 throws NoSuchClusterGroupException, SystemException {
359 return findByPrimaryKey((Serializable)clusterGroupId);
360 }
361
362
369 @Override
370 public ClusterGroup fetchByPrimaryKey(Serializable primaryKey)
371 throws SystemException {
372 ClusterGroup clusterGroup = (ClusterGroup)EntityCacheUtil.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 EntityCacheUtil.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
393 ClusterGroupImpl.class, primaryKey, _nullClusterGroup);
394 }
395 }
396 catch (Exception e) {
397 EntityCacheUtil.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
417 @Override
418 public ClusterGroup fetchByPrimaryKey(long clusterGroupId)
419 throws SystemException {
420 return fetchByPrimaryKey((Serializable)clusterGroupId);
421 }
422
423
429 @Override
430 public List<ClusterGroup> findAll() throws SystemException {
431 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
432 }
433
434
446 @Override
447 public List<ClusterGroup> findAll(int start, int end)
448 throws SystemException {
449 return findAll(start, end, null);
450 }
451
452
465 @Override
466 public List<ClusterGroup> findAll(int start, int end,
467 OrderByComparator orderByComparator) throws SystemException {
468 boolean pagination = true;
469 FinderPath finderPath = null;
470 Object[] finderArgs = null;
471
472 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
473 (orderByComparator == null)) {
474 pagination = false;
475 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
476 finderArgs = FINDER_ARGS_EMPTY;
477 }
478 else {
479 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
480 finderArgs = new Object[] { start, end, orderByComparator };
481 }
482
483 List<ClusterGroup> list = (List<ClusterGroup>)FinderCacheUtil.getResult(finderPath,
484 finderArgs, this);
485
486 if (list == null) {
487 StringBundler query = null;
488 String sql = null;
489
490 if (orderByComparator != null) {
491 query = new StringBundler(2 +
492 (orderByComparator.getOrderByFields().length * 3));
493
494 query.append(_SQL_SELECT_CLUSTERGROUP);
495
496 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
497 orderByComparator);
498
499 sql = query.toString();
500 }
501 else {
502 sql = _SQL_SELECT_CLUSTERGROUP;
503
504 if (pagination) {
505 sql = sql.concat(ClusterGroupModelImpl.ORDER_BY_JPQL);
506 }
507 }
508
509 Session session = null;
510
511 try {
512 session = openSession();
513
514 Query q = session.createQuery(sql);
515
516 if (!pagination) {
517 list = (List<ClusterGroup>)QueryUtil.list(q, getDialect(),
518 start, end, false);
519
520 Collections.sort(list);
521
522 list = new UnmodifiableList<ClusterGroup>(list);
523 }
524 else {
525 list = (List<ClusterGroup>)QueryUtil.list(q, getDialect(),
526 start, end);
527 }
528
529 cacheResult(list);
530
531 FinderCacheUtil.putResult(finderPath, finderArgs, list);
532 }
533 catch (Exception e) {
534 FinderCacheUtil.removeResult(finderPath, finderArgs);
535
536 throw processException(e);
537 }
538 finally {
539 closeSession(session);
540 }
541 }
542
543 return list;
544 }
545
546
551 @Override
552 public void removeAll() throws SystemException {
553 for (ClusterGroup clusterGroup : findAll()) {
554 remove(clusterGroup);
555 }
556 }
557
558
564 @Override
565 public int countAll() throws SystemException {
566 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
567 FINDER_ARGS_EMPTY, this);
568
569 if (count == null) {
570 Session session = null;
571
572 try {
573 session = openSession();
574
575 Query q = session.createQuery(_SQL_COUNT_CLUSTERGROUP);
576
577 count = (Long)q.uniqueResult();
578
579 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
580 FINDER_ARGS_EMPTY, count);
581 }
582 catch (Exception e) {
583 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
584 FINDER_ARGS_EMPTY);
585
586 throw processException(e);
587 }
588 finally {
589 closeSession(session);
590 }
591 }
592
593 return count.intValue();
594 }
595
596
599 public void afterPropertiesSet() {
600 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
601 com.liferay.portal.util.PropsUtil.get(
602 "value.object.listener.com.liferay.portal.model.ClusterGroup")));
603
604 if (listenerClassNames.length > 0) {
605 try {
606 List<ModelListener<ClusterGroup>> listenersList = new ArrayList<ModelListener<ClusterGroup>>();
607
608 for (String listenerClassName : listenerClassNames) {
609 listenersList.add((ModelListener<ClusterGroup>)InstanceFactory.newInstance(
610 getClassLoader(), listenerClassName));
611 }
612
613 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
614 }
615 catch (Exception e) {
616 _log.error(e);
617 }
618 }
619 }
620
621 public void destroy() {
622 EntityCacheUtil.removeCache(ClusterGroupImpl.class.getName());
623 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
624 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
625 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
626 }
627
628 private static final String _SQL_SELECT_CLUSTERGROUP = "SELECT clusterGroup FROM ClusterGroup clusterGroup";
629 private static final String _SQL_COUNT_CLUSTERGROUP = "SELECT COUNT(clusterGroup) FROM ClusterGroup clusterGroup";
630 private static final String _ORDER_BY_ENTITY_ALIAS = "clusterGroup.";
631 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ClusterGroup exists with the primary key ";
632 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
633 private static Log _log = LogFactoryUtil.getLog(ClusterGroupPersistenceImpl.class);
634 private static ClusterGroup _nullClusterGroup = new ClusterGroupImpl() {
635 @Override
636 public Object clone() {
637 return this;
638 }
639
640 @Override
641 public CacheModel<ClusterGroup> toCacheModel() {
642 return _nullClusterGroupCacheModel;
643 }
644 };
645
646 private static CacheModel<ClusterGroup> _nullClusterGroupCacheModel = new CacheModel<ClusterGroup>() {
647 @Override
648 public ClusterGroup toEntityModel() {
649 return _nullClusterGroup;
650 }
651 };
652 }