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 if (clusterGroup.isCachedModel() || BatchSessionUtil.isEnabled()) {
206 Object staleObject = session.get(ClusterGroupImpl.class,
207 clusterGroup.getPrimaryKeyObj());
208
209 if (staleObject != null) {
210 session.evict(staleObject);
211 }
212 }
213
214 session.delete(clusterGroup);
215
216 session.flush();
217 }
218 catch (Exception e) {
219 throw processException(e);
220 }
221 finally {
222 closeSession(session);
223 }
224
225 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
226
227 EntityCacheUtil.removeResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
228 ClusterGroupImpl.class, clusterGroup.getPrimaryKey());
229
230 return clusterGroup;
231 }
232
233 public ClusterGroup updateImpl(
234 com.liferay.portal.model.ClusterGroup clusterGroup, boolean merge)
235 throws SystemException {
236 clusterGroup = toUnwrappedModel(clusterGroup);
237
238 Session session = null;
239
240 try {
241 session = openSession();
242
243 BatchSessionUtil.update(session, clusterGroup, merge);
244
245 clusterGroup.setNew(false);
246 }
247 catch (Exception e) {
248 throw processException(e);
249 }
250 finally {
251 closeSession(session);
252 }
253
254 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
255
256 EntityCacheUtil.putResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
257 ClusterGroupImpl.class, clusterGroup.getPrimaryKey(), clusterGroup);
258
259 return clusterGroup;
260 }
261
262 protected ClusterGroup toUnwrappedModel(ClusterGroup clusterGroup) {
263 if (clusterGroup instanceof ClusterGroupImpl) {
264 return clusterGroup;
265 }
266
267 ClusterGroupImpl clusterGroupImpl = new ClusterGroupImpl();
268
269 clusterGroupImpl.setNew(clusterGroup.isNew());
270 clusterGroupImpl.setPrimaryKey(clusterGroup.getPrimaryKey());
271
272 clusterGroupImpl.setClusterGroupId(clusterGroup.getClusterGroupId());
273 clusterGroupImpl.setName(clusterGroup.getName());
274 clusterGroupImpl.setClusterNodeIds(clusterGroup.getClusterNodeIds());
275 clusterGroupImpl.setWholeCluster(clusterGroup.isWholeCluster());
276
277 return clusterGroupImpl;
278 }
279
280
288 public ClusterGroup findByPrimaryKey(Serializable primaryKey)
289 throws NoSuchModelException, SystemException {
290 return findByPrimaryKey(((Long)primaryKey).longValue());
291 }
292
293
301 public ClusterGroup findByPrimaryKey(long clusterGroupId)
302 throws NoSuchClusterGroupException, SystemException {
303 ClusterGroup clusterGroup = fetchByPrimaryKey(clusterGroupId);
304
305 if (clusterGroup == null) {
306 if (_log.isWarnEnabled()) {
307 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + clusterGroupId);
308 }
309
310 throw new NoSuchClusterGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
311 clusterGroupId);
312 }
313
314 return clusterGroup;
315 }
316
317
324 public ClusterGroup fetchByPrimaryKey(Serializable primaryKey)
325 throws SystemException {
326 return fetchByPrimaryKey(((Long)primaryKey).longValue());
327 }
328
329
336 public ClusterGroup fetchByPrimaryKey(long clusterGroupId)
337 throws SystemException {
338 ClusterGroup clusterGroup = (ClusterGroup)EntityCacheUtil.getResult(ClusterGroupModelImpl.ENTITY_CACHE_ENABLED,
339 ClusterGroupImpl.class, clusterGroupId, this);
340
341 if (clusterGroup == null) {
342 Session session = null;
343
344 try {
345 session = openSession();
346
347 clusterGroup = (ClusterGroup)session.get(ClusterGroupImpl.class,
348 new Long(clusterGroupId));
349 }
350 catch (Exception e) {
351 throw processException(e);
352 }
353 finally {
354 if (clusterGroup != null) {
355 cacheResult(clusterGroup);
356 }
357
358 closeSession(session);
359 }
360 }
361
362 return clusterGroup;
363 }
364
365
371 public List<ClusterGroup> findAll() throws SystemException {
372 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
373 }
374
375
387 public List<ClusterGroup> findAll(int start, int end)
388 throws SystemException {
389 return findAll(start, end, null);
390 }
391
392
405 public List<ClusterGroup> findAll(int start, int end,
406 OrderByComparator orderByComparator) throws SystemException {
407 Object[] finderArgs = new Object[] {
408 String.valueOf(start), String.valueOf(end),
409 String.valueOf(orderByComparator)
410 };
411
412 List<ClusterGroup> list = (List<ClusterGroup>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
413 finderArgs, this);
414
415 if (list == null) {
416 Session session = null;
417
418 try {
419 session = openSession();
420
421 StringBundler query = null;
422 String sql = null;
423
424 if (orderByComparator != null) {
425 query = new StringBundler(2 +
426 (orderByComparator.getOrderByFields().length * 3));
427
428 query.append(_SQL_SELECT_CLUSTERGROUP);
429
430 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
431 orderByComparator);
432
433 sql = query.toString();
434 }
435 else {
436 sql = _SQL_SELECT_CLUSTERGROUP;
437 }
438
439 Query q = session.createQuery(sql);
440
441 if (orderByComparator == null) {
442 list = (List<ClusterGroup>)QueryUtil.list(q, getDialect(),
443 start, end, false);
444
445 Collections.sort(list);
446 }
447 else {
448 list = (List<ClusterGroup>)QueryUtil.list(q, getDialect(),
449 start, end);
450 }
451 }
452 catch (Exception e) {
453 throw processException(e);
454 }
455 finally {
456 if (list == null) {
457 list = new ArrayList<ClusterGroup>();
458 }
459
460 cacheResult(list);
461
462 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
463
464 closeSession(session);
465 }
466 }
467
468 return list;
469 }
470
471
476 public void removeAll() throws SystemException {
477 for (ClusterGroup clusterGroup : findAll()) {
478 remove(clusterGroup);
479 }
480 }
481
482
488 public int countAll() throws SystemException {
489 Object[] finderArgs = new Object[0];
490
491 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
492 finderArgs, this);
493
494 if (count == null) {
495 Session session = null;
496
497 try {
498 session = openSession();
499
500 Query q = session.createQuery(_SQL_COUNT_CLUSTERGROUP);
501
502 count = (Long)q.uniqueResult();
503 }
504 catch (Exception e) {
505 throw processException(e);
506 }
507 finally {
508 if (count == null) {
509 count = Long.valueOf(0);
510 }
511
512 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
513 count);
514
515 closeSession(session);
516 }
517 }
518
519 return count.intValue();
520 }
521
522
525 public void afterPropertiesSet() {
526 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
527 com.liferay.portal.util.PropsUtil.get(
528 "value.object.listener.com.liferay.portal.model.ClusterGroup")));
529
530 if (listenerClassNames.length > 0) {
531 try {
532 List<ModelListener<ClusterGroup>> listenersList = new ArrayList<ModelListener<ClusterGroup>>();
533
534 for (String listenerClassName : listenerClassNames) {
535 listenersList.add((ModelListener<ClusterGroup>)InstanceFactory.newInstance(
536 listenerClassName));
537 }
538
539 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
540 }
541 catch (Exception e) {
542 _log.error(e);
543 }
544 }
545 }
546
547 @BeanReference(type = AccountPersistence.class)
548 protected AccountPersistence accountPersistence;
549 @BeanReference(type = AddressPersistence.class)
550 protected AddressPersistence addressPersistence;
551 @BeanReference(type = BrowserTrackerPersistence.class)
552 protected BrowserTrackerPersistence browserTrackerPersistence;
553 @BeanReference(type = ClassNamePersistence.class)
554 protected ClassNamePersistence classNamePersistence;
555 @BeanReference(type = ClusterGroupPersistence.class)
556 protected ClusterGroupPersistence clusterGroupPersistence;
557 @BeanReference(type = CompanyPersistence.class)
558 protected CompanyPersistence companyPersistence;
559 @BeanReference(type = ContactPersistence.class)
560 protected ContactPersistence contactPersistence;
561 @BeanReference(type = CountryPersistence.class)
562 protected CountryPersistence countryPersistence;
563 @BeanReference(type = EmailAddressPersistence.class)
564 protected EmailAddressPersistence emailAddressPersistence;
565 @BeanReference(type = GroupPersistence.class)
566 protected GroupPersistence groupPersistence;
567 @BeanReference(type = ImagePersistence.class)
568 protected ImagePersistence imagePersistence;
569 @BeanReference(type = LayoutPersistence.class)
570 protected LayoutPersistence layoutPersistence;
571 @BeanReference(type = LayoutPrototypePersistence.class)
572 protected LayoutPrototypePersistence layoutPrototypePersistence;
573 @BeanReference(type = LayoutSetPersistence.class)
574 protected LayoutSetPersistence layoutSetPersistence;
575 @BeanReference(type = LayoutSetPrototypePersistence.class)
576 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
577 @BeanReference(type = ListTypePersistence.class)
578 protected ListTypePersistence listTypePersistence;
579 @BeanReference(type = LockPersistence.class)
580 protected LockPersistence lockPersistence;
581 @BeanReference(type = MembershipRequestPersistence.class)
582 protected MembershipRequestPersistence membershipRequestPersistence;
583 @BeanReference(type = OrganizationPersistence.class)
584 protected OrganizationPersistence organizationPersistence;
585 @BeanReference(type = OrgGroupPermissionPersistence.class)
586 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
587 @BeanReference(type = OrgGroupRolePersistence.class)
588 protected OrgGroupRolePersistence orgGroupRolePersistence;
589 @BeanReference(type = OrgLaborPersistence.class)
590 protected OrgLaborPersistence orgLaborPersistence;
591 @BeanReference(type = PasswordPolicyPersistence.class)
592 protected PasswordPolicyPersistence passwordPolicyPersistence;
593 @BeanReference(type = PasswordPolicyRelPersistence.class)
594 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
595 @BeanReference(type = PasswordTrackerPersistence.class)
596 protected PasswordTrackerPersistence passwordTrackerPersistence;
597 @BeanReference(type = PermissionPersistence.class)
598 protected PermissionPersistence permissionPersistence;
599 @BeanReference(type = PhonePersistence.class)
600 protected PhonePersistence phonePersistence;
601 @BeanReference(type = PluginSettingPersistence.class)
602 protected PluginSettingPersistence pluginSettingPersistence;
603 @BeanReference(type = PortletPersistence.class)
604 protected PortletPersistence portletPersistence;
605 @BeanReference(type = PortletItemPersistence.class)
606 protected PortletItemPersistence portletItemPersistence;
607 @BeanReference(type = PortletPreferencesPersistence.class)
608 protected PortletPreferencesPersistence portletPreferencesPersistence;
609 @BeanReference(type = RegionPersistence.class)
610 protected RegionPersistence regionPersistence;
611 @BeanReference(type = ReleasePersistence.class)
612 protected ReleasePersistence releasePersistence;
613 @BeanReference(type = ResourcePersistence.class)
614 protected ResourcePersistence resourcePersistence;
615 @BeanReference(type = ResourceActionPersistence.class)
616 protected ResourceActionPersistence resourceActionPersistence;
617 @BeanReference(type = ResourceCodePersistence.class)
618 protected ResourceCodePersistence resourceCodePersistence;
619 @BeanReference(type = ResourcePermissionPersistence.class)
620 protected ResourcePermissionPersistence resourcePermissionPersistence;
621 @BeanReference(type = RolePersistence.class)
622 protected RolePersistence rolePersistence;
623 @BeanReference(type = ServiceComponentPersistence.class)
624 protected ServiceComponentPersistence serviceComponentPersistence;
625 @BeanReference(type = ShardPersistence.class)
626 protected ShardPersistence shardPersistence;
627 @BeanReference(type = SubscriptionPersistence.class)
628 protected SubscriptionPersistence subscriptionPersistence;
629 @BeanReference(type = TicketPersistence.class)
630 protected TicketPersistence ticketPersistence;
631 @BeanReference(type = TeamPersistence.class)
632 protected TeamPersistence teamPersistence;
633 @BeanReference(type = UserPersistence.class)
634 protected UserPersistence userPersistence;
635 @BeanReference(type = UserGroupPersistence.class)
636 protected UserGroupPersistence userGroupPersistence;
637 @BeanReference(type = UserGroupGroupRolePersistence.class)
638 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
639 @BeanReference(type = UserGroupRolePersistence.class)
640 protected UserGroupRolePersistence userGroupRolePersistence;
641 @BeanReference(type = UserIdMapperPersistence.class)
642 protected UserIdMapperPersistence userIdMapperPersistence;
643 @BeanReference(type = UserTrackerPersistence.class)
644 protected UserTrackerPersistence userTrackerPersistence;
645 @BeanReference(type = UserTrackerPathPersistence.class)
646 protected UserTrackerPathPersistence userTrackerPathPersistence;
647 @BeanReference(type = WebDAVPropsPersistence.class)
648 protected WebDAVPropsPersistence webDAVPropsPersistence;
649 @BeanReference(type = WebsitePersistence.class)
650 protected WebsitePersistence websitePersistence;
651 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
652 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
653 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
654 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
655 private static final String _SQL_SELECT_CLUSTERGROUP = "SELECT clusterGroup FROM ClusterGroup clusterGroup";
656 private static final String _SQL_COUNT_CLUSTERGROUP = "SELECT COUNT(clusterGroup) FROM ClusterGroup clusterGroup";
657 private static final String _ORDER_BY_ENTITY_ALIAS = "clusterGroup.";
658 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ClusterGroup exists with the primary key ";
659 private static Log _log = LogFactoryUtil.getLog(ClusterGroupPersistenceImpl.class);
660 }