001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchClusterGroupException;
018 import com.liferay.portal.NoSuchModelException;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
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.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringUtil;
034 import com.liferay.portal.kernel.util.UnmodifiableList;
035 import com.liferay.portal.model.CacheModel;
036 import com.liferay.portal.model.ClusterGroup;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.model.impl.ClusterGroupImpl;
039 import com.liferay.portal.model.impl.ClusterGroupModelImpl;
040 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041
042 import java.io.Serializable;
043
044 import java.util.ArrayList;
045 import java.util.Collections;
046 import java.util.List;
047
048
060 public class ClusterGroupPersistenceImpl extends BasePersistenceImpl<ClusterGroup>
061 implements ClusterGroupPersistence {
062
067 public static final String FINDER_CLASS_NAME_ENTITY = ClusterGroupImpl.class.getName();
068 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
069 ".List1";
070 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071 ".List2";
072 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
073 ClusterGroupModelImpl.FINDER_CACHE_ENABLED, ClusterGroupImpl.class,
074 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
075 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
076 ClusterGroupModelImpl.FINDER_CACHE_ENABLED, ClusterGroupImpl.class,
077 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
078 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
079 ClusterGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
080 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
081
082
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 public void cacheResult(List<ClusterGroup> clusterGroups) {
100 for (ClusterGroup clusterGroup : clusterGroups) {
101 if (EntityCacheUtil.getResult(
102 ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
103 ClusterGroupImpl.class, clusterGroup.getPrimaryKey()) == null) {
104 cacheResult(clusterGroup);
105 }
106 else {
107 clusterGroup.resetOriginalValues();
108 }
109 }
110 }
111
112
119 @Override
120 public void clearCache() {
121 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
122 CacheRegistryUtil.clear(ClusterGroupImpl.class.getName());
123 }
124
125 EntityCacheUtil.clearCache(ClusterGroupImpl.class.getName());
126
127 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
128 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
129 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
130 }
131
132
139 @Override
140 public void clearCache(ClusterGroup clusterGroup) {
141 EntityCacheUtil.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
142 ClusterGroupImpl.class, clusterGroup.getPrimaryKey());
143
144 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
145 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
146 }
147
148 @Override
149 public void clearCache(List<ClusterGroup> clusterGroups) {
150 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
151 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
152
153 for (ClusterGroup clusterGroup : clusterGroups) {
154 EntityCacheUtil.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
155 ClusterGroupImpl.class, clusterGroup.getPrimaryKey());
156 }
157 }
158
159
165 public ClusterGroup create(long clusterGroupId) {
166 ClusterGroup clusterGroup = new ClusterGroupImpl();
167
168 clusterGroup.setNew(true);
169 clusterGroup.setPrimaryKey(clusterGroupId);
170
171 return clusterGroup;
172 }
173
174
182 public ClusterGroup remove(long clusterGroupId)
183 throws NoSuchClusterGroupException, SystemException {
184 return remove(Long.valueOf(clusterGroupId));
185 }
186
187
195 @Override
196 public ClusterGroup remove(Serializable primaryKey)
197 throws NoSuchClusterGroupException, SystemException {
198 Session session = null;
199
200 try {
201 session = openSession();
202
203 ClusterGroup clusterGroup = (ClusterGroup)session.get(ClusterGroupImpl.class,
204 primaryKey);
205
206 if (clusterGroup == null) {
207 if (_log.isWarnEnabled()) {
208 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
209 }
210
211 throw new NoSuchClusterGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
212 primaryKey);
213 }
214
215 return remove(clusterGroup);
216 }
217 catch (NoSuchClusterGroupException nsee) {
218 throw nsee;
219 }
220 catch (Exception e) {
221 throw processException(e);
222 }
223 finally {
224 closeSession(session);
225 }
226 }
227
228 @Override
229 protected ClusterGroup removeImpl(ClusterGroup clusterGroup)
230 throws SystemException {
231 clusterGroup = toUnwrappedModel(clusterGroup);
232
233 Session session = null;
234
235 try {
236 session = openSession();
237
238 if (!session.contains(clusterGroup)) {
239 clusterGroup = (ClusterGroup)session.get(ClusterGroupImpl.class,
240 clusterGroup.getPrimaryKeyObj());
241 }
242
243 if (clusterGroup != null) {
244 session.delete(clusterGroup);
245 }
246 }
247 catch (Exception e) {
248 throw processException(e);
249 }
250 finally {
251 closeSession(session);
252 }
253
254 if (clusterGroup != null) {
255 clearCache(clusterGroup);
256 }
257
258 return clusterGroup;
259 }
260
261 @Override
262 public ClusterGroup updateImpl(
263 com.liferay.portal.model.ClusterGroup clusterGroup)
264 throws SystemException {
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
299 return clusterGroup;
300 }
301
302 protected ClusterGroup toUnwrappedModel(ClusterGroup clusterGroup) {
303 if (clusterGroup instanceof ClusterGroupImpl) {
304 return clusterGroup;
305 }
306
307 ClusterGroupImpl clusterGroupImpl = new ClusterGroupImpl();
308
309 clusterGroupImpl.setNew(clusterGroup.isNew());
310 clusterGroupImpl.setPrimaryKey(clusterGroup.getPrimaryKey());
311
312 clusterGroupImpl.setClusterGroupId(clusterGroup.getClusterGroupId());
313 clusterGroupImpl.setName(clusterGroup.getName());
314 clusterGroupImpl.setClusterNodeIds(clusterGroup.getClusterNodeIds());
315 clusterGroupImpl.setWholeCluster(clusterGroup.isWholeCluster());
316
317 return clusterGroupImpl;
318 }
319
320
328 @Override
329 public ClusterGroup findByPrimaryKey(Serializable primaryKey)
330 throws NoSuchModelException, SystemException {
331 return findByPrimaryKey(((Long)primaryKey).longValue());
332 }
333
334
342 public ClusterGroup findByPrimaryKey(long clusterGroupId)
343 throws NoSuchClusterGroupException, SystemException {
344 ClusterGroup clusterGroup = fetchByPrimaryKey(clusterGroupId);
345
346 if (clusterGroup == null) {
347 if (_log.isWarnEnabled()) {
348 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + clusterGroupId);
349 }
350
351 throw new NoSuchClusterGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
352 clusterGroupId);
353 }
354
355 return clusterGroup;
356 }
357
358
365 @Override
366 public ClusterGroup fetchByPrimaryKey(Serializable primaryKey)
367 throws SystemException {
368 return fetchByPrimaryKey(((Long)primaryKey).longValue());
369 }
370
371
378 public ClusterGroup fetchByPrimaryKey(long clusterGroupId)
379 throws SystemException {
380 ClusterGroup clusterGroup = (ClusterGroup)EntityCacheUtil.getResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
381 ClusterGroupImpl.class, clusterGroupId);
382
383 if (clusterGroup == _nullClusterGroup) {
384 return null;
385 }
386
387 if (clusterGroup == null) {
388 Session session = null;
389
390 try {
391 session = openSession();
392
393 clusterGroup = (ClusterGroup)session.get(ClusterGroupImpl.class,
394 Long.valueOf(clusterGroupId));
395
396 if (clusterGroup != null) {
397 cacheResult(clusterGroup);
398 }
399 else {
400 EntityCacheUtil.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
401 ClusterGroupImpl.class, clusterGroupId,
402 _nullClusterGroup);
403 }
404 }
405 catch (Exception e) {
406 EntityCacheUtil.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
407 ClusterGroupImpl.class, clusterGroupId);
408
409 throw processException(e);
410 }
411 finally {
412 closeSession(session);
413 }
414 }
415
416 return clusterGroup;
417 }
418
419
425 public List<ClusterGroup> findAll() throws SystemException {
426 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
427 }
428
429
441 public List<ClusterGroup> findAll(int start, int end)
442 throws SystemException {
443 return findAll(start, end, null);
444 }
445
446
459 public List<ClusterGroup> findAll(int start, int end,
460 OrderByComparator orderByComparator) throws SystemException {
461 boolean pagination = true;
462 FinderPath finderPath = null;
463 Object[] finderArgs = null;
464
465 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
466 (orderByComparator == null)) {
467 pagination = false;
468 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
469 finderArgs = FINDER_ARGS_EMPTY;
470 }
471 else {
472 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
473 finderArgs = new Object[] { start, end, orderByComparator };
474 }
475
476 List<ClusterGroup> list = (List<ClusterGroup>)FinderCacheUtil.getResult(finderPath,
477 finderArgs, this);
478
479 if (list == null) {
480 StringBundler query = null;
481 String sql = null;
482
483 if (orderByComparator != null) {
484 query = new StringBundler(2 +
485 (orderByComparator.getOrderByFields().length * 3));
486
487 query.append(_SQL_SELECT_CLUSTERGROUP);
488
489 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
490 orderByComparator);
491
492 sql = query.toString();
493 }
494 else {
495 sql = _SQL_SELECT_CLUSTERGROUP;
496
497 if (pagination) {
498 sql = sql.concat(ClusterGroupModelImpl.ORDER_BY_JPQL);
499 }
500 }
501
502 Session session = null;
503
504 try {
505 session = openSession();
506
507 Query q = session.createQuery(sql);
508
509 if (!pagination) {
510 list = (List<ClusterGroup>)QueryUtil.list(q, getDialect(),
511 start, end, false);
512
513 Collections.sort(list);
514
515 list = new UnmodifiableList<ClusterGroup>(list);
516 }
517 else {
518 list = (List<ClusterGroup>)QueryUtil.list(q, getDialect(),
519 start, end);
520 }
521
522 cacheResult(list);
523
524 FinderCacheUtil.putResult(finderPath, finderArgs, list);
525 }
526 catch (Exception e) {
527 FinderCacheUtil.removeResult(finderPath, finderArgs);
528
529 throw processException(e);
530 }
531 finally {
532 closeSession(session);
533 }
534 }
535
536 return list;
537 }
538
539
544 public void removeAll() throws SystemException {
545 for (ClusterGroup clusterGroup : findAll()) {
546 remove(clusterGroup);
547 }
548 }
549
550
556 public int countAll() throws SystemException {
557 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
558 FINDER_ARGS_EMPTY, this);
559
560 if (count == null) {
561 Session session = null;
562
563 try {
564 session = openSession();
565
566 Query q = session.createQuery(_SQL_COUNT_CLUSTERGROUP);
567
568 count = (Long)q.uniqueResult();
569
570 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
571 FINDER_ARGS_EMPTY, count);
572 }
573 catch (Exception e) {
574 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
575 FINDER_ARGS_EMPTY);
576
577 throw processException(e);
578 }
579 finally {
580 closeSession(session);
581 }
582 }
583
584 return count.intValue();
585 }
586
587
590 public void afterPropertiesSet() {
591 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
592 com.liferay.portal.util.PropsUtil.get(
593 "value.object.listener.com.liferay.portal.model.ClusterGroup")));
594
595 if (listenerClassNames.length > 0) {
596 try {
597 List<ModelListener<ClusterGroup>> listenersList = new ArrayList<ModelListener<ClusterGroup>>();
598
599 for (String listenerClassName : listenerClassNames) {
600 listenersList.add((ModelListener<ClusterGroup>)InstanceFactory.newInstance(
601 listenerClassName));
602 }
603
604 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
605 }
606 catch (Exception e) {
607 _log.error(e);
608 }
609 }
610 }
611
612 public void destroy() {
613 EntityCacheUtil.removeCache(ClusterGroupImpl.class.getName());
614 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
615 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
616 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
617 }
618
619 private static final String _SQL_SELECT_CLUSTERGROUP = "SELECT clusterGroup FROM ClusterGroup clusterGroup";
620 private static final String _SQL_COUNT_CLUSTERGROUP = "SELECT COUNT(clusterGroup) FROM ClusterGroup clusterGroup";
621 private static final String _ORDER_BY_ENTITY_ALIAS = "clusterGroup.";
622 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ClusterGroup exists with the primary key ";
623 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
624 private static Log _log = LogFactoryUtil.getLog(ClusterGroupPersistenceImpl.class);
625 private static ClusterGroup _nullClusterGroup = new ClusterGroupImpl() {
626 @Override
627 public Object clone() {
628 return this;
629 }
630
631 @Override
632 public CacheModel<ClusterGroup> toCacheModel() {
633 return _nullClusterGroupCacheModel;
634 }
635 };
636
637 private static CacheModel<ClusterGroup> _nullClusterGroupCacheModel = new CacheModel<ClusterGroup>() {
638 public ClusterGroup toEntityModel() {
639 return _nullClusterGroup;
640 }
641 };
642 }