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.annotation.BeanReference;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
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.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringUtil;
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
063 public class ClusterGroupPersistenceImpl extends BasePersistenceImpl<ClusterGroup>
064 implements ClusterGroupPersistence {
065 public static final String FINDER_CLASS_NAME_ENTITY = ClusterGroupImpl.class.getName();
066 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
067 ".List";
068 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
069 ClusterGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
070 "findAll", new String[0]);
071 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
072 ClusterGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
073 "countAll", new String[0]);
074
075
080 public void cacheResult(ClusterGroup clusterGroup) {
081 EntityCacheUtil.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
082 ClusterGroupImpl.class, clusterGroup.getPrimaryKey(), clusterGroup);
083 }
084
085
090 public void cacheResult(List<ClusterGroup> clusterGroups) {
091 for (ClusterGroup clusterGroup : clusterGroups) {
092 if (EntityCacheUtil.getResult(
093 ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
094 ClusterGroupImpl.class, clusterGroup.getPrimaryKey(),
095 this) == null) {
096 cacheResult(clusterGroup);
097 }
098 }
099 }
100
101
108 public void clearCache() {
109 CacheRegistryUtil.clear(ClusterGroupImpl.class.getName());
110 EntityCacheUtil.clearCache(ClusterGroupImpl.class.getName());
111 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
112 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
113 }
114
115
122 public void clearCache(ClusterGroup clusterGroup) {
123 EntityCacheUtil.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
124 ClusterGroupImpl.class, clusterGroup.getPrimaryKey());
125 }
126
127
133 public ClusterGroup create(long clusterGroupId) {
134 ClusterGroup clusterGroup = new ClusterGroupImpl();
135
136 clusterGroup.setNew(true);
137 clusterGroup.setPrimaryKey(clusterGroupId);
138
139 return clusterGroup;
140 }
141
142
150 public ClusterGroup remove(Serializable primaryKey)
151 throws NoSuchModelException, SystemException {
152 return remove(((Long)primaryKey).longValue());
153 }
154
155
163 public ClusterGroup remove(long clusterGroupId)
164 throws NoSuchClusterGroupException, SystemException {
165 Session session = null;
166
167 try {
168 session = openSession();
169
170 ClusterGroup clusterGroup = (ClusterGroup)session.get(ClusterGroupImpl.class,
171 new Long(clusterGroupId));
172
173 if (clusterGroup == null) {
174 if (_log.isWarnEnabled()) {
175 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
176 clusterGroupId);
177 }
178
179 throw new NoSuchClusterGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
180 clusterGroupId);
181 }
182
183 return remove(clusterGroup);
184 }
185 catch (NoSuchClusterGroupException nsee) {
186 throw nsee;
187 }
188 catch (Exception e) {
189 throw processException(e);
190 }
191 finally {
192 closeSession(session);
193 }
194 }
195
196 protected ClusterGroup removeImpl(ClusterGroup clusterGroup)
197 throws SystemException {
198 clusterGroup = toUnwrappedModel(clusterGroup);
199
200 Session session = null;
201
202 try {
203 session = openSession();
204
205 BatchSessionUtil.delete(session, clusterGroup);
206 }
207 catch (Exception e) {
208 throw processException(e);
209 }
210 finally {
211 closeSession(session);
212 }
213
214 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
215
216 EntityCacheUtil.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
217 ClusterGroupImpl.class, clusterGroup.getPrimaryKey());
218
219 return clusterGroup;
220 }
221
222 public ClusterGroup updateImpl(
223 com.liferay.portal.model.ClusterGroup clusterGroup, boolean merge)
224 throws SystemException {
225 clusterGroup = toUnwrappedModel(clusterGroup);
226
227 Session session = null;
228
229 try {
230 session = openSession();
231
232 BatchSessionUtil.update(session, clusterGroup, merge);
233
234 clusterGroup.setNew(false);
235 }
236 catch (Exception e) {
237 throw processException(e);
238 }
239 finally {
240 closeSession(session);
241 }
242
243 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
244
245 EntityCacheUtil.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
246 ClusterGroupImpl.class, clusterGroup.getPrimaryKey(), clusterGroup);
247
248 return clusterGroup;
249 }
250
251 protected ClusterGroup toUnwrappedModel(ClusterGroup clusterGroup) {
252 if (clusterGroup instanceof ClusterGroupImpl) {
253 return clusterGroup;
254 }
255
256 ClusterGroupImpl clusterGroupImpl = new ClusterGroupImpl();
257
258 clusterGroupImpl.setNew(clusterGroup.isNew());
259 clusterGroupImpl.setPrimaryKey(clusterGroup.getPrimaryKey());
260
261 clusterGroupImpl.setClusterGroupId(clusterGroup.getClusterGroupId());
262 clusterGroupImpl.setName(clusterGroup.getName());
263 clusterGroupImpl.setClusterNodeIds(clusterGroup.getClusterNodeIds());
264 clusterGroupImpl.setWholeCluster(clusterGroup.isWholeCluster());
265
266 return clusterGroupImpl;
267 }
268
269
277 public ClusterGroup findByPrimaryKey(Serializable primaryKey)
278 throws NoSuchModelException, SystemException {
279 return findByPrimaryKey(((Long)primaryKey).longValue());
280 }
281
282
290 public ClusterGroup findByPrimaryKey(long clusterGroupId)
291 throws NoSuchClusterGroupException, SystemException {
292 ClusterGroup clusterGroup = fetchByPrimaryKey(clusterGroupId);
293
294 if (clusterGroup == null) {
295 if (_log.isWarnEnabled()) {
296 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + clusterGroupId);
297 }
298
299 throw new NoSuchClusterGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
300 clusterGroupId);
301 }
302
303 return clusterGroup;
304 }
305
306
313 public ClusterGroup fetchByPrimaryKey(Serializable primaryKey)
314 throws SystemException {
315 return fetchByPrimaryKey(((Long)primaryKey).longValue());
316 }
317
318
325 public ClusterGroup fetchByPrimaryKey(long clusterGroupId)
326 throws SystemException {
327 ClusterGroup clusterGroup = (ClusterGroup)EntityCacheUtil.getResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
328 ClusterGroupImpl.class, clusterGroupId, this);
329
330 if (clusterGroup == null) {
331 Session session = null;
332
333 try {
334 session = openSession();
335
336 clusterGroup = (ClusterGroup)session.get(ClusterGroupImpl.class,
337 new Long(clusterGroupId));
338 }
339 catch (Exception e) {
340 throw processException(e);
341 }
342 finally {
343 if (clusterGroup != null) {
344 cacheResult(clusterGroup);
345 }
346
347 closeSession(session);
348 }
349 }
350
351 return clusterGroup;
352 }
353
354
360 public List<ClusterGroup> findAll() throws SystemException {
361 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
362 }
363
364
376 public List<ClusterGroup> findAll(int start, int end)
377 throws SystemException {
378 return findAll(start, end, null);
379 }
380
381
394 public List<ClusterGroup> findAll(int start, int end,
395 OrderByComparator orderByComparator) throws SystemException {
396 Object[] finderArgs = new Object[] {
397 String.valueOf(start), String.valueOf(end),
398 String.valueOf(orderByComparator)
399 };
400
401 List<ClusterGroup> list = (List<ClusterGroup>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
402 finderArgs, this);
403
404 if (list == null) {
405 Session session = null;
406
407 try {
408 session = openSession();
409
410 StringBundler query = null;
411 String sql = null;
412
413 if (orderByComparator != null) {
414 query = new StringBundler(2 +
415 (orderByComparator.getOrderByFields().length * 3));
416
417 query.append(_SQL_SELECT_CLUSTERGROUP);
418
419 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
420 orderByComparator);
421
422 sql = query.toString();
423 }
424 else {
425 sql = _SQL_SELECT_CLUSTERGROUP;
426 }
427
428 Query q = session.createQuery(sql);
429
430 if (orderByComparator == null) {
431 list = (List<ClusterGroup>)QueryUtil.list(q, getDialect(),
432 start, end, false);
433
434 Collections.sort(list);
435 }
436 else {
437 list = (List<ClusterGroup>)QueryUtil.list(q, getDialect(),
438 start, end);
439 }
440 }
441 catch (Exception e) {
442 throw processException(e);
443 }
444 finally {
445 if (list == null) {
446 list = new ArrayList<ClusterGroup>();
447 }
448
449 cacheResult(list);
450
451 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
452
453 closeSession(session);
454 }
455 }
456
457 return list;
458 }
459
460
465 public void removeAll() throws SystemException {
466 for (ClusterGroup clusterGroup : findAll()) {
467 remove(clusterGroup);
468 }
469 }
470
471
477 public int countAll() throws SystemException {
478 Object[] finderArgs = new Object[0];
479
480 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
481 finderArgs, this);
482
483 if (count == null) {
484 Session session = null;
485
486 try {
487 session = openSession();
488
489 Query q = session.createQuery(_SQL_COUNT_CLUSTERGROUP);
490
491 count = (Long)q.uniqueResult();
492 }
493 catch (Exception e) {
494 throw processException(e);
495 }
496 finally {
497 if (count == null) {
498 count = Long.valueOf(0);
499 }
500
501 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
502 count);
503
504 closeSession(session);
505 }
506 }
507
508 return count.intValue();
509 }
510
511
514 public void afterPropertiesSet() {
515 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
516 com.liferay.portal.util.PropsUtil.get(
517 "value.object.listener.com.liferay.portal.model.ClusterGroup")));
518
519 if (listenerClassNames.length > 0) {
520 try {
521 List<ModelListener<ClusterGroup>> listenersList = new ArrayList<ModelListener<ClusterGroup>>();
522
523 for (String listenerClassName : listenerClassNames) {
524 listenersList.add((ModelListener<ClusterGroup>)InstanceFactory.newInstance(
525 listenerClassName));
526 }
527
528 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
529 }
530 catch (Exception e) {
531 _log.error(e);
532 }
533 }
534 }
535
536 public void destroy() {
537 EntityCacheUtil.removeCache(ClusterGroupImpl.class.getName());
538 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
539 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
540 }
541
542 @BeanReference(type = AccountPersistence.class)
543 protected AccountPersistence accountPersistence;
544 @BeanReference(type = AddressPersistence.class)
545 protected AddressPersistence addressPersistence;
546 @BeanReference(type = BrowserTrackerPersistence.class)
547 protected BrowserTrackerPersistence browserTrackerPersistence;
548 @BeanReference(type = ClassNamePersistence.class)
549 protected ClassNamePersistence classNamePersistence;
550 @BeanReference(type = ClusterGroupPersistence.class)
551 protected ClusterGroupPersistence clusterGroupPersistence;
552 @BeanReference(type = CompanyPersistence.class)
553 protected CompanyPersistence companyPersistence;
554 @BeanReference(type = ContactPersistence.class)
555 protected ContactPersistence contactPersistence;
556 @BeanReference(type = CountryPersistence.class)
557 protected CountryPersistence countryPersistence;
558 @BeanReference(type = EmailAddressPersistence.class)
559 protected EmailAddressPersistence emailAddressPersistence;
560 @BeanReference(type = GroupPersistence.class)
561 protected GroupPersistence groupPersistence;
562 @BeanReference(type = ImagePersistence.class)
563 protected ImagePersistence imagePersistence;
564 @BeanReference(type = LayoutPersistence.class)
565 protected LayoutPersistence layoutPersistence;
566 @BeanReference(type = LayoutPrototypePersistence.class)
567 protected LayoutPrototypePersistence layoutPrototypePersistence;
568 @BeanReference(type = LayoutSetPersistence.class)
569 protected LayoutSetPersistence layoutSetPersistence;
570 @BeanReference(type = LayoutSetPrototypePersistence.class)
571 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
572 @BeanReference(type = ListTypePersistence.class)
573 protected ListTypePersistence listTypePersistence;
574 @BeanReference(type = LockPersistence.class)
575 protected LockPersistence lockPersistence;
576 @BeanReference(type = MembershipRequestPersistence.class)
577 protected MembershipRequestPersistence membershipRequestPersistence;
578 @BeanReference(type = OrganizationPersistence.class)
579 protected OrganizationPersistence organizationPersistence;
580 @BeanReference(type = OrgGroupPermissionPersistence.class)
581 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
582 @BeanReference(type = OrgGroupRolePersistence.class)
583 protected OrgGroupRolePersistence orgGroupRolePersistence;
584 @BeanReference(type = OrgLaborPersistence.class)
585 protected OrgLaborPersistence orgLaborPersistence;
586 @BeanReference(type = PasswordPolicyPersistence.class)
587 protected PasswordPolicyPersistence passwordPolicyPersistence;
588 @BeanReference(type = PasswordPolicyRelPersistence.class)
589 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
590 @BeanReference(type = PasswordTrackerPersistence.class)
591 protected PasswordTrackerPersistence passwordTrackerPersistence;
592 @BeanReference(type = PermissionPersistence.class)
593 protected PermissionPersistence permissionPersistence;
594 @BeanReference(type = PhonePersistence.class)
595 protected PhonePersistence phonePersistence;
596 @BeanReference(type = PluginSettingPersistence.class)
597 protected PluginSettingPersistence pluginSettingPersistence;
598 @BeanReference(type = PortletPersistence.class)
599 protected PortletPersistence portletPersistence;
600 @BeanReference(type = PortletItemPersistence.class)
601 protected PortletItemPersistence portletItemPersistence;
602 @BeanReference(type = PortletPreferencesPersistence.class)
603 protected PortletPreferencesPersistence portletPreferencesPersistence;
604 @BeanReference(type = RegionPersistence.class)
605 protected RegionPersistence regionPersistence;
606 @BeanReference(type = ReleasePersistence.class)
607 protected ReleasePersistence releasePersistence;
608 @BeanReference(type = ResourcePersistence.class)
609 protected ResourcePersistence resourcePersistence;
610 @BeanReference(type = ResourceActionPersistence.class)
611 protected ResourceActionPersistence resourceActionPersistence;
612 @BeanReference(type = ResourceCodePersistence.class)
613 protected ResourceCodePersistence resourceCodePersistence;
614 @BeanReference(type = ResourcePermissionPersistence.class)
615 protected ResourcePermissionPersistence resourcePermissionPersistence;
616 @BeanReference(type = RolePersistence.class)
617 protected RolePersistence rolePersistence;
618 @BeanReference(type = ServiceComponentPersistence.class)
619 protected ServiceComponentPersistence serviceComponentPersistence;
620 @BeanReference(type = ShardPersistence.class)
621 protected ShardPersistence shardPersistence;
622 @BeanReference(type = SubscriptionPersistence.class)
623 protected SubscriptionPersistence subscriptionPersistence;
624 @BeanReference(type = TicketPersistence.class)
625 protected TicketPersistence ticketPersistence;
626 @BeanReference(type = TeamPersistence.class)
627 protected TeamPersistence teamPersistence;
628 @BeanReference(type = UserPersistence.class)
629 protected UserPersistence userPersistence;
630 @BeanReference(type = UserGroupPersistence.class)
631 protected UserGroupPersistence userGroupPersistence;
632 @BeanReference(type = UserGroupGroupRolePersistence.class)
633 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
634 @BeanReference(type = UserGroupRolePersistence.class)
635 protected UserGroupRolePersistence userGroupRolePersistence;
636 @BeanReference(type = UserIdMapperPersistence.class)
637 protected UserIdMapperPersistence userIdMapperPersistence;
638 @BeanReference(type = UserTrackerPersistence.class)
639 protected UserTrackerPersistence userTrackerPersistence;
640 @BeanReference(type = UserTrackerPathPersistence.class)
641 protected UserTrackerPathPersistence userTrackerPathPersistence;
642 @BeanReference(type = WebDAVPropsPersistence.class)
643 protected WebDAVPropsPersistence webDAVPropsPersistence;
644 @BeanReference(type = WebsitePersistence.class)
645 protected WebsitePersistence websitePersistence;
646 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
647 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
648 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
649 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
650 private static final String _SQL_SELECT_CLUSTERGROUP = "SELECT clusterGroup FROM ClusterGroup clusterGroup";
651 private static final String _SQL_COUNT_CLUSTERGROUP = "SELECT COUNT(clusterGroup) FROM ClusterGroup clusterGroup";
652 private static final String _ORDER_BY_ENTITY_ALIAS = "clusterGroup.";
653 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ClusterGroup exists with the primary key ";
654 private static Log _log = LogFactoryUtil.getLog(ClusterGroupPersistenceImpl.class);
655 }