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 public void cacheResult(ClusterGroup clusterGroup) {
087 EntityCacheUtil.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
088 ClusterGroupImpl.class, clusterGroup.getPrimaryKey(), clusterGroup);
089
090 clusterGroup.resetOriginalValues();
091 }
092
093
098 public void cacheResult(List<ClusterGroup> clusterGroups) {
099 for (ClusterGroup clusterGroup : clusterGroups) {
100 if (EntityCacheUtil.getResult(
101 ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
102 ClusterGroupImpl.class, clusterGroup.getPrimaryKey()) == null) {
103 cacheResult(clusterGroup);
104 }
105 else {
106 clusterGroup.resetOriginalValues();
107 }
108 }
109 }
110
111
118 @Override
119 public void clearCache() {
120 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
121 CacheRegistryUtil.clear(ClusterGroupImpl.class.getName());
122 }
123
124 EntityCacheUtil.clearCache(ClusterGroupImpl.class.getName());
125
126 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
127 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
128 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
129 }
130
131
138 @Override
139 public void clearCache(ClusterGroup clusterGroup) {
140 EntityCacheUtil.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
141 ClusterGroupImpl.class, clusterGroup.getPrimaryKey());
142
143 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
144 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
145 }
146
147 @Override
148 public void clearCache(List<ClusterGroup> clusterGroups) {
149 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
150 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
151
152 for (ClusterGroup clusterGroup : clusterGroups) {
153 EntityCacheUtil.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
154 ClusterGroupImpl.class, clusterGroup.getPrimaryKey());
155 }
156 }
157
158
164 public ClusterGroup create(long clusterGroupId) {
165 ClusterGroup clusterGroup = new ClusterGroupImpl();
166
167 clusterGroup.setNew(true);
168 clusterGroup.setPrimaryKey(clusterGroupId);
169
170 return clusterGroup;
171 }
172
173
181 public ClusterGroup remove(long clusterGroupId)
182 throws NoSuchClusterGroupException, SystemException {
183 return remove((Serializable)clusterGroupId);
184 }
185
186
194 @Override
195 public ClusterGroup remove(Serializable primaryKey)
196 throws NoSuchClusterGroupException, SystemException {
197 Session session = null;
198
199 try {
200 session = openSession();
201
202 ClusterGroup clusterGroup = (ClusterGroup)session.get(ClusterGroupImpl.class,
203 primaryKey);
204
205 if (clusterGroup == null) {
206 if (_log.isWarnEnabled()) {
207 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
208 }
209
210 throw new NoSuchClusterGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
211 primaryKey);
212 }
213
214 return remove(clusterGroup);
215 }
216 catch (NoSuchClusterGroupException nsee) {
217 throw nsee;
218 }
219 catch (Exception e) {
220 throw processException(e);
221 }
222 finally {
223 closeSession(session);
224 }
225 }
226
227 @Override
228 protected ClusterGroup removeImpl(ClusterGroup clusterGroup)
229 throws SystemException {
230 clusterGroup = toUnwrappedModel(clusterGroup);
231
232 Session session = null;
233
234 try {
235 session = openSession();
236
237 if (!session.contains(clusterGroup)) {
238 clusterGroup = (ClusterGroup)session.get(ClusterGroupImpl.class,
239 clusterGroup.getPrimaryKeyObj());
240 }
241
242 if (clusterGroup != null) {
243 session.delete(clusterGroup);
244 }
245 }
246 catch (Exception e) {
247 throw processException(e);
248 }
249 finally {
250 closeSession(session);
251 }
252
253 if (clusterGroup != null) {
254 clearCache(clusterGroup);
255 }
256
257 return clusterGroup;
258 }
259
260 @Override
261 public ClusterGroup updateImpl(
262 com.liferay.portal.model.ClusterGroup clusterGroup)
263 throws SystemException {
264 clusterGroup = toUnwrappedModel(clusterGroup);
265
266 boolean isNew = clusterGroup.isNew();
267
268 Session session = null;
269
270 try {
271 session = openSession();
272
273 if (clusterGroup.isNew()) {
274 session.save(clusterGroup);
275
276 clusterGroup.setNew(false);
277 }
278 else {
279 session.merge(clusterGroup);
280 }
281 }
282 catch (Exception e) {
283 throw processException(e);
284 }
285 finally {
286 closeSession(session);
287 }
288
289 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
290
291 if (isNew) {
292 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
293 }
294
295 EntityCacheUtil.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
296 ClusterGroupImpl.class, clusterGroup.getPrimaryKey(), clusterGroup);
297
298 return clusterGroup;
299 }
300
301 protected ClusterGroup toUnwrappedModel(ClusterGroup clusterGroup) {
302 if (clusterGroup instanceof ClusterGroupImpl) {
303 return clusterGroup;
304 }
305
306 ClusterGroupImpl clusterGroupImpl = new ClusterGroupImpl();
307
308 clusterGroupImpl.setNew(clusterGroup.isNew());
309 clusterGroupImpl.setPrimaryKey(clusterGroup.getPrimaryKey());
310
311 clusterGroupImpl.setClusterGroupId(clusterGroup.getClusterGroupId());
312 clusterGroupImpl.setName(clusterGroup.getName());
313 clusterGroupImpl.setClusterNodeIds(clusterGroup.getClusterNodeIds());
314 clusterGroupImpl.setWholeCluster(clusterGroup.isWholeCluster());
315
316 return clusterGroupImpl;
317 }
318
319
327 @Override
328 public ClusterGroup findByPrimaryKey(Serializable primaryKey)
329 throws NoSuchClusterGroupException, SystemException {
330 ClusterGroup clusterGroup = fetchByPrimaryKey(primaryKey);
331
332 if (clusterGroup == null) {
333 if (_log.isWarnEnabled()) {
334 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
335 }
336
337 throw new NoSuchClusterGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
338 primaryKey);
339 }
340
341 return clusterGroup;
342 }
343
344
352 public ClusterGroup findByPrimaryKey(long clusterGroupId)
353 throws NoSuchClusterGroupException, SystemException {
354 return findByPrimaryKey((Serializable)clusterGroupId);
355 }
356
357
364 @Override
365 public ClusterGroup fetchByPrimaryKey(Serializable primaryKey)
366 throws SystemException {
367 ClusterGroup clusterGroup = (ClusterGroup)EntityCacheUtil.getResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
368 ClusterGroupImpl.class, primaryKey);
369
370 if (clusterGroup == _nullClusterGroup) {
371 return null;
372 }
373
374 if (clusterGroup == null) {
375 Session session = null;
376
377 try {
378 session = openSession();
379
380 clusterGroup = (ClusterGroup)session.get(ClusterGroupImpl.class,
381 primaryKey);
382
383 if (clusterGroup != null) {
384 cacheResult(clusterGroup);
385 }
386 else {
387 EntityCacheUtil.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
388 ClusterGroupImpl.class, primaryKey, _nullClusterGroup);
389 }
390 }
391 catch (Exception e) {
392 EntityCacheUtil.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
393 ClusterGroupImpl.class, primaryKey);
394
395 throw processException(e);
396 }
397 finally {
398 closeSession(session);
399 }
400 }
401
402 return clusterGroup;
403 }
404
405
412 public ClusterGroup fetchByPrimaryKey(long clusterGroupId)
413 throws SystemException {
414 return fetchByPrimaryKey((Serializable)clusterGroupId);
415 }
416
417
423 public List<ClusterGroup> findAll() throws SystemException {
424 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
425 }
426
427
439 public List<ClusterGroup> findAll(int start, int end)
440 throws SystemException {
441 return findAll(start, end, null);
442 }
443
444
457 public List<ClusterGroup> findAll(int start, int end,
458 OrderByComparator orderByComparator) throws SystemException {
459 boolean pagination = true;
460 FinderPath finderPath = null;
461 Object[] finderArgs = null;
462
463 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
464 (orderByComparator == null)) {
465 pagination = false;
466 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
467 finderArgs = FINDER_ARGS_EMPTY;
468 }
469 else {
470 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
471 finderArgs = new Object[] { start, end, orderByComparator };
472 }
473
474 List<ClusterGroup> list = (List<ClusterGroup>)FinderCacheUtil.getResult(finderPath,
475 finderArgs, this);
476
477 if (list == null) {
478 StringBundler query = null;
479 String sql = null;
480
481 if (orderByComparator != null) {
482 query = new StringBundler(2 +
483 (orderByComparator.getOrderByFields().length * 3));
484
485 query.append(_SQL_SELECT_CLUSTERGROUP);
486
487 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
488 orderByComparator);
489
490 sql = query.toString();
491 }
492 else {
493 sql = _SQL_SELECT_CLUSTERGROUP;
494
495 if (pagination) {
496 sql = sql.concat(ClusterGroupModelImpl.ORDER_BY_JPQL);
497 }
498 }
499
500 Session session = null;
501
502 try {
503 session = openSession();
504
505 Query q = session.createQuery(sql);
506
507 if (!pagination) {
508 list = (List<ClusterGroup>)QueryUtil.list(q, getDialect(),
509 start, end, false);
510
511 Collections.sort(list);
512
513 list = new UnmodifiableList<ClusterGroup>(list);
514 }
515 else {
516 list = (List<ClusterGroup>)QueryUtil.list(q, getDialect(),
517 start, end);
518 }
519
520 cacheResult(list);
521
522 FinderCacheUtil.putResult(finderPath, finderArgs, list);
523 }
524 catch (Exception e) {
525 FinderCacheUtil.removeResult(finderPath, finderArgs);
526
527 throw processException(e);
528 }
529 finally {
530 closeSession(session);
531 }
532 }
533
534 return list;
535 }
536
537
542 public void removeAll() throws SystemException {
543 for (ClusterGroup clusterGroup : findAll()) {
544 remove(clusterGroup);
545 }
546 }
547
548
554 public int countAll() throws SystemException {
555 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
556 FINDER_ARGS_EMPTY, this);
557
558 if (count == null) {
559 Session session = null;
560
561 try {
562 session = openSession();
563
564 Query q = session.createQuery(_SQL_COUNT_CLUSTERGROUP);
565
566 count = (Long)q.uniqueResult();
567
568 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
569 FINDER_ARGS_EMPTY, count);
570 }
571 catch (Exception e) {
572 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
573 FINDER_ARGS_EMPTY);
574
575 throw processException(e);
576 }
577 finally {
578 closeSession(session);
579 }
580 }
581
582 return count.intValue();
583 }
584
585
588 public void afterPropertiesSet() {
589 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
590 com.liferay.portal.util.PropsUtil.get(
591 "value.object.listener.com.liferay.portal.model.ClusterGroup")));
592
593 if (listenerClassNames.length > 0) {
594 try {
595 List<ModelListener<ClusterGroup>> listenersList = new ArrayList<ModelListener<ClusterGroup>>();
596
597 for (String listenerClassName : listenerClassNames) {
598 listenersList.add((ModelListener<ClusterGroup>)InstanceFactory.newInstance(
599 listenerClassName));
600 }
601
602 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
603 }
604 catch (Exception e) {
605 _log.error(e);
606 }
607 }
608 }
609
610 public void destroy() {
611 EntityCacheUtil.removeCache(ClusterGroupImpl.class.getName());
612 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
613 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
614 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
615 }
616
617 private static final String _SQL_SELECT_CLUSTERGROUP = "SELECT clusterGroup FROM ClusterGroup clusterGroup";
618 private static final String _SQL_COUNT_CLUSTERGROUP = "SELECT COUNT(clusterGroup) FROM ClusterGroup clusterGroup";
619 private static final String _ORDER_BY_ENTITY_ALIAS = "clusterGroup.";
620 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ClusterGroup exists with the primary key ";
621 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
622 private static Log _log = LogFactoryUtil.getLog(ClusterGroupPersistenceImpl.class);
623 private static ClusterGroup _nullClusterGroup = new ClusterGroupImpl() {
624 @Override
625 public Object clone() {
626 return this;
627 }
628
629 @Override
630 public CacheModel<ClusterGroup> toCacheModel() {
631 return _nullClusterGroupCacheModel;
632 }
633 };
634
635 private static CacheModel<ClusterGroup> _nullClusterGroupCacheModel = new CacheModel<ClusterGroup>() {
636 public ClusterGroup toEntityModel() {
637 return _nullClusterGroup;
638 }
639 };
640 }