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 StringBundler query = null;
406 String sql = null;
407
408 if (orderByComparator != null) {
409 query = new StringBundler(2 +
410 (orderByComparator.getOrderByFields().length * 3));
411
412 query.append(_SQL_SELECT_CLUSTERGROUP);
413
414 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
415 orderByComparator);
416
417 sql = query.toString();
418 }
419 else {
420 sql = _SQL_SELECT_CLUSTERGROUP;
421 }
422
423 Session session = null;
424
425 try {
426 session = openSession();
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 FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
447 finderArgs);
448 }
449 else {
450 cacheResult(list);
451
452 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
453 list);
454 }
455
456 closeSession(session);
457 }
458 }
459
460 return list;
461 }
462
463
468 public void removeAll() throws SystemException {
469 for (ClusterGroup clusterGroup : findAll()) {
470 remove(clusterGroup);
471 }
472 }
473
474
480 public int countAll() throws SystemException {
481 Object[] finderArgs = new Object[0];
482
483 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
484 finderArgs, this);
485
486 if (count == null) {
487 Session session = null;
488
489 try {
490 session = openSession();
491
492 Query q = session.createQuery(_SQL_COUNT_CLUSTERGROUP);
493
494 count = (Long)q.uniqueResult();
495 }
496 catch (Exception e) {
497 throw processException(e);
498 }
499 finally {
500 if (count == null) {
501 count = Long.valueOf(0);
502 }
503
504 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
505 count);
506
507 closeSession(session);
508 }
509 }
510
511 return count.intValue();
512 }
513
514
517 public void afterPropertiesSet() {
518 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
519 com.liferay.portal.util.PropsUtil.get(
520 "value.object.listener.com.liferay.portal.model.ClusterGroup")));
521
522 if (listenerClassNames.length > 0) {
523 try {
524 List<ModelListener<ClusterGroup>> listenersList = new ArrayList<ModelListener<ClusterGroup>>();
525
526 for (String listenerClassName : listenerClassNames) {
527 listenersList.add((ModelListener<ClusterGroup>)InstanceFactory.newInstance(
528 listenerClassName));
529 }
530
531 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
532 }
533 catch (Exception e) {
534 _log.error(e);
535 }
536 }
537 }
538
539 public void destroy() {
540 EntityCacheUtil.removeCache(ClusterGroupImpl.class.getName());
541 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
542 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
543 }
544
545 @BeanReference(type = AccountPersistence.class)
546 protected AccountPersistence accountPersistence;
547 @BeanReference(type = AddressPersistence.class)
548 protected AddressPersistence addressPersistence;
549 @BeanReference(type = BrowserTrackerPersistence.class)
550 protected BrowserTrackerPersistence browserTrackerPersistence;
551 @BeanReference(type = ClassNamePersistence.class)
552 protected ClassNamePersistence classNamePersistence;
553 @BeanReference(type = ClusterGroupPersistence.class)
554 protected ClusterGroupPersistence clusterGroupPersistence;
555 @BeanReference(type = CompanyPersistence.class)
556 protected CompanyPersistence companyPersistence;
557 @BeanReference(type = ContactPersistence.class)
558 protected ContactPersistence contactPersistence;
559 @BeanReference(type = CountryPersistence.class)
560 protected CountryPersistence countryPersistence;
561 @BeanReference(type = EmailAddressPersistence.class)
562 protected EmailAddressPersistence emailAddressPersistence;
563 @BeanReference(type = GroupPersistence.class)
564 protected GroupPersistence groupPersistence;
565 @BeanReference(type = ImagePersistence.class)
566 protected ImagePersistence imagePersistence;
567 @BeanReference(type = LayoutPersistence.class)
568 protected LayoutPersistence layoutPersistence;
569 @BeanReference(type = LayoutPrototypePersistence.class)
570 protected LayoutPrototypePersistence layoutPrototypePersistence;
571 @BeanReference(type = LayoutSetPersistence.class)
572 protected LayoutSetPersistence layoutSetPersistence;
573 @BeanReference(type = LayoutSetPrototypePersistence.class)
574 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
575 @BeanReference(type = ListTypePersistence.class)
576 protected ListTypePersistence listTypePersistence;
577 @BeanReference(type = LockPersistence.class)
578 protected LockPersistence lockPersistence;
579 @BeanReference(type = MembershipRequestPersistence.class)
580 protected MembershipRequestPersistence membershipRequestPersistence;
581 @BeanReference(type = OrganizationPersistence.class)
582 protected OrganizationPersistence organizationPersistence;
583 @BeanReference(type = OrgGroupPermissionPersistence.class)
584 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
585 @BeanReference(type = OrgGroupRolePersistence.class)
586 protected OrgGroupRolePersistence orgGroupRolePersistence;
587 @BeanReference(type = OrgLaborPersistence.class)
588 protected OrgLaborPersistence orgLaborPersistence;
589 @BeanReference(type = PasswordPolicyPersistence.class)
590 protected PasswordPolicyPersistence passwordPolicyPersistence;
591 @BeanReference(type = PasswordPolicyRelPersistence.class)
592 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
593 @BeanReference(type = PasswordTrackerPersistence.class)
594 protected PasswordTrackerPersistence passwordTrackerPersistence;
595 @BeanReference(type = PermissionPersistence.class)
596 protected PermissionPersistence permissionPersistence;
597 @BeanReference(type = PhonePersistence.class)
598 protected PhonePersistence phonePersistence;
599 @BeanReference(type = PluginSettingPersistence.class)
600 protected PluginSettingPersistence pluginSettingPersistence;
601 @BeanReference(type = PortletPersistence.class)
602 protected PortletPersistence portletPersistence;
603 @BeanReference(type = PortletItemPersistence.class)
604 protected PortletItemPersistence portletItemPersistence;
605 @BeanReference(type = PortletPreferencesPersistence.class)
606 protected PortletPreferencesPersistence portletPreferencesPersistence;
607 @BeanReference(type = RegionPersistence.class)
608 protected RegionPersistence regionPersistence;
609 @BeanReference(type = ReleasePersistence.class)
610 protected ReleasePersistence releasePersistence;
611 @BeanReference(type = ResourcePersistence.class)
612 protected ResourcePersistence resourcePersistence;
613 @BeanReference(type = ResourceActionPersistence.class)
614 protected ResourceActionPersistence resourceActionPersistence;
615 @BeanReference(type = ResourceCodePersistence.class)
616 protected ResourceCodePersistence resourceCodePersistence;
617 @BeanReference(type = ResourcePermissionPersistence.class)
618 protected ResourcePermissionPersistence resourcePermissionPersistence;
619 @BeanReference(type = RolePersistence.class)
620 protected RolePersistence rolePersistence;
621 @BeanReference(type = ServiceComponentPersistence.class)
622 protected ServiceComponentPersistence serviceComponentPersistence;
623 @BeanReference(type = ShardPersistence.class)
624 protected ShardPersistence shardPersistence;
625 @BeanReference(type = SubscriptionPersistence.class)
626 protected SubscriptionPersistence subscriptionPersistence;
627 @BeanReference(type = TicketPersistence.class)
628 protected TicketPersistence ticketPersistence;
629 @BeanReference(type = TeamPersistence.class)
630 protected TeamPersistence teamPersistence;
631 @BeanReference(type = UserPersistence.class)
632 protected UserPersistence userPersistence;
633 @BeanReference(type = UserGroupPersistence.class)
634 protected UserGroupPersistence userGroupPersistence;
635 @BeanReference(type = UserGroupGroupRolePersistence.class)
636 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
637 @BeanReference(type = UserGroupRolePersistence.class)
638 protected UserGroupRolePersistence userGroupRolePersistence;
639 @BeanReference(type = UserIdMapperPersistence.class)
640 protected UserIdMapperPersistence userIdMapperPersistence;
641 @BeanReference(type = UserTrackerPersistence.class)
642 protected UserTrackerPersistence userTrackerPersistence;
643 @BeanReference(type = UserTrackerPathPersistence.class)
644 protected UserTrackerPathPersistence userTrackerPathPersistence;
645 @BeanReference(type = WebDAVPropsPersistence.class)
646 protected WebDAVPropsPersistence webDAVPropsPersistence;
647 @BeanReference(type = WebsitePersistence.class)
648 protected WebsitePersistence websitePersistence;
649 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
650 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
651 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
652 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
653 private static final String _SQL_SELECT_CLUSTERGROUP = "SELECT clusterGroup FROM ClusterGroup clusterGroup";
654 private static final String _SQL_COUNT_CLUSTERGROUP = "SELECT COUNT(clusterGroup) FROM ClusterGroup clusterGroup";
655 private static final String _ORDER_BY_ENTITY_ALIAS = "clusterGroup.";
656 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ClusterGroup exists with the primary key ";
657 private static Log _log = LogFactoryUtil.getLog(ClusterGroupPersistenceImpl.class);
658 }