001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchAccountException;
018 import com.liferay.portal.NoSuchModelException;
019 import com.liferay.portal.kernel.bean.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.Account;
036 import com.liferay.portal.model.CacheModel;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.model.impl.AccountImpl;
039 import com.liferay.portal.model.impl.AccountModelImpl;
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 AccountPersistenceImpl extends BasePersistenceImpl<Account>
061 implements AccountPersistence {
062
067 public static final String FINDER_CLASS_NAME_ENTITY = AccountImpl.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(AccountModelImpl.ENTITY_CACHE_ENABLED,
073 AccountModelImpl.FINDER_CACHE_ENABLED, AccountImpl.class,
074 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
075 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(AccountModelImpl.ENTITY_CACHE_ENABLED,
076 AccountModelImpl.FINDER_CACHE_ENABLED, AccountImpl.class,
077 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
078 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AccountModelImpl.ENTITY_CACHE_ENABLED,
079 AccountModelImpl.FINDER_CACHE_ENABLED, Long.class,
080 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
081
082
087 public void cacheResult(Account account) {
088 EntityCacheUtil.putResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
089 AccountImpl.class, account.getPrimaryKey(), account);
090
091 account.resetOriginalValues();
092 }
093
094
099 public void cacheResult(List<Account> accounts) {
100 for (Account account : accounts) {
101 if (EntityCacheUtil.getResult(
102 AccountModelImpl.ENTITY_CACHE_ENABLED,
103 AccountImpl.class, account.getPrimaryKey()) == null) {
104 cacheResult(account);
105 }
106 else {
107 account.resetOriginalValues();
108 }
109 }
110 }
111
112
119 @Override
120 public void clearCache() {
121 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
122 CacheRegistryUtil.clear(AccountImpl.class.getName());
123 }
124
125 EntityCacheUtil.clearCache(AccountImpl.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(Account account) {
141 EntityCacheUtil.removeResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
142 AccountImpl.class, account.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<Account> accounts) {
150 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
151 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
152
153 for (Account account : accounts) {
154 EntityCacheUtil.removeResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
155 AccountImpl.class, account.getPrimaryKey());
156 }
157 }
158
159
165 public Account create(long accountId) {
166 Account account = new AccountImpl();
167
168 account.setNew(true);
169 account.setPrimaryKey(accountId);
170
171 return account;
172 }
173
174
182 public Account remove(long accountId)
183 throws NoSuchAccountException, SystemException {
184 return remove(Long.valueOf(accountId));
185 }
186
187
195 @Override
196 public Account remove(Serializable primaryKey)
197 throws NoSuchAccountException, SystemException {
198 Session session = null;
199
200 try {
201 session = openSession();
202
203 Account account = (Account)session.get(AccountImpl.class, primaryKey);
204
205 if (account == null) {
206 if (_log.isWarnEnabled()) {
207 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
208 }
209
210 throw new NoSuchAccountException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
211 primaryKey);
212 }
213
214 return remove(account);
215 }
216 catch (NoSuchAccountException 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 Account removeImpl(Account account) throws SystemException {
229 account = toUnwrappedModel(account);
230
231 Session session = null;
232
233 try {
234 session = openSession();
235
236 BatchSessionUtil.delete(session, account);
237 }
238 catch (Exception e) {
239 throw processException(e);
240 }
241 finally {
242 closeSession(session);
243 }
244
245 clearCache(account);
246
247 return account;
248 }
249
250 @Override
251 public Account updateImpl(com.liferay.portal.model.Account account,
252 boolean merge) throws SystemException {
253 account = toUnwrappedModel(account);
254
255 Session session = null;
256
257 try {
258 session = openSession();
259
260 BatchSessionUtil.update(session, account, merge);
261
262 account.setNew(false);
263 }
264 catch (Exception e) {
265 throw processException(e);
266 }
267 finally {
268 closeSession(session);
269 }
270
271 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
272
273 EntityCacheUtil.putResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
274 AccountImpl.class, account.getPrimaryKey(), account);
275
276 return account;
277 }
278
279 protected Account toUnwrappedModel(Account account) {
280 if (account instanceof AccountImpl) {
281 return account;
282 }
283
284 AccountImpl accountImpl = new AccountImpl();
285
286 accountImpl.setNew(account.isNew());
287 accountImpl.setPrimaryKey(account.getPrimaryKey());
288
289 accountImpl.setAccountId(account.getAccountId());
290 accountImpl.setCompanyId(account.getCompanyId());
291 accountImpl.setUserId(account.getUserId());
292 accountImpl.setUserName(account.getUserName());
293 accountImpl.setCreateDate(account.getCreateDate());
294 accountImpl.setModifiedDate(account.getModifiedDate());
295 accountImpl.setParentAccountId(account.getParentAccountId());
296 accountImpl.setName(account.getName());
297 accountImpl.setLegalName(account.getLegalName());
298 accountImpl.setLegalId(account.getLegalId());
299 accountImpl.setLegalType(account.getLegalType());
300 accountImpl.setSicCode(account.getSicCode());
301 accountImpl.setTickerSymbol(account.getTickerSymbol());
302 accountImpl.setIndustry(account.getIndustry());
303 accountImpl.setType(account.getType());
304 accountImpl.setSize(account.getSize());
305
306 return accountImpl;
307 }
308
309
317 @Override
318 public Account findByPrimaryKey(Serializable primaryKey)
319 throws NoSuchModelException, SystemException {
320 return findByPrimaryKey(((Long)primaryKey).longValue());
321 }
322
323
331 public Account findByPrimaryKey(long accountId)
332 throws NoSuchAccountException, SystemException {
333 Account account = fetchByPrimaryKey(accountId);
334
335 if (account == null) {
336 if (_log.isWarnEnabled()) {
337 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + accountId);
338 }
339
340 throw new NoSuchAccountException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
341 accountId);
342 }
343
344 return account;
345 }
346
347
354 @Override
355 public Account fetchByPrimaryKey(Serializable primaryKey)
356 throws SystemException {
357 return fetchByPrimaryKey(((Long)primaryKey).longValue());
358 }
359
360
367 public Account fetchByPrimaryKey(long accountId) throws SystemException {
368 Account account = (Account)EntityCacheUtil.getResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
369 AccountImpl.class, accountId);
370
371 if (account == _nullAccount) {
372 return null;
373 }
374
375 if (account == null) {
376 Session session = null;
377
378 boolean hasException = false;
379
380 try {
381 session = openSession();
382
383 account = (Account)session.get(AccountImpl.class,
384 Long.valueOf(accountId));
385 }
386 catch (Exception e) {
387 hasException = true;
388
389 throw processException(e);
390 }
391 finally {
392 if (account != null) {
393 cacheResult(account);
394 }
395 else if (!hasException) {
396 EntityCacheUtil.putResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
397 AccountImpl.class, accountId, _nullAccount);
398 }
399
400 closeSession(session);
401 }
402 }
403
404 return account;
405 }
406
407
413 public List<Account> findAll() throws SystemException {
414 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
415 }
416
417
429 public List<Account> findAll(int start, int end) throws SystemException {
430 return findAll(start, end, null);
431 }
432
433
446 public List<Account> findAll(int start, int end,
447 OrderByComparator orderByComparator) throws SystemException {
448 FinderPath finderPath = null;
449 Object[] finderArgs = new Object[] { start, end, orderByComparator };
450
451 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
452 (orderByComparator == null)) {
453 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
454 finderArgs = FINDER_ARGS_EMPTY;
455 }
456 else {
457 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
458 finderArgs = new Object[] { start, end, orderByComparator };
459 }
460
461 List<Account> list = (List<Account>)FinderCacheUtil.getResult(finderPath,
462 finderArgs, this);
463
464 if (list == null) {
465 StringBundler query = null;
466 String sql = null;
467
468 if (orderByComparator != null) {
469 query = new StringBundler(2 +
470 (orderByComparator.getOrderByFields().length * 3));
471
472 query.append(_SQL_SELECT_ACCOUNT);
473
474 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
475 orderByComparator);
476
477 sql = query.toString();
478 }
479 else {
480 sql = _SQL_SELECT_ACCOUNT;
481 }
482
483 Session session = null;
484
485 try {
486 session = openSession();
487
488 Query q = session.createQuery(sql);
489
490 if (orderByComparator == null) {
491 list = (List<Account>)QueryUtil.list(q, getDialect(),
492 start, end, false);
493
494 Collections.sort(list);
495 }
496 else {
497 list = (List<Account>)QueryUtil.list(q, getDialect(),
498 start, end);
499 }
500 }
501 catch (Exception e) {
502 throw processException(e);
503 }
504 finally {
505 if (list == null) {
506 FinderCacheUtil.removeResult(finderPath, finderArgs);
507 }
508 else {
509 cacheResult(list);
510
511 FinderCacheUtil.putResult(finderPath, finderArgs, list);
512 }
513
514 closeSession(session);
515 }
516 }
517
518 return list;
519 }
520
521
526 public void removeAll() throws SystemException {
527 for (Account account : findAll()) {
528 remove(account);
529 }
530 }
531
532
538 public int countAll() throws SystemException {
539 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
540 FINDER_ARGS_EMPTY, this);
541
542 if (count == null) {
543 Session session = null;
544
545 try {
546 session = openSession();
547
548 Query q = session.createQuery(_SQL_COUNT_ACCOUNT);
549
550 count = (Long)q.uniqueResult();
551 }
552 catch (Exception e) {
553 throw processException(e);
554 }
555 finally {
556 if (count == null) {
557 count = Long.valueOf(0);
558 }
559
560 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
561 FINDER_ARGS_EMPTY, count);
562
563 closeSession(session);
564 }
565 }
566
567 return count.intValue();
568 }
569
570
573 public void afterPropertiesSet() {
574 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
575 com.liferay.portal.util.PropsUtil.get(
576 "value.object.listener.com.liferay.portal.model.Account")));
577
578 if (listenerClassNames.length > 0) {
579 try {
580 List<ModelListener<Account>> listenersList = new ArrayList<ModelListener<Account>>();
581
582 for (String listenerClassName : listenerClassNames) {
583 listenersList.add((ModelListener<Account>)InstanceFactory.newInstance(
584 listenerClassName));
585 }
586
587 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
588 }
589 catch (Exception e) {
590 _log.error(e);
591 }
592 }
593 }
594
595 public void destroy() {
596 EntityCacheUtil.removeCache(AccountImpl.class.getName());
597 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
598 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
599 }
600
601 @BeanReference(type = AccountPersistence.class)
602 protected AccountPersistence accountPersistence;
603 @BeanReference(type = AddressPersistence.class)
604 protected AddressPersistence addressPersistence;
605 @BeanReference(type = BrowserTrackerPersistence.class)
606 protected BrowserTrackerPersistence browserTrackerPersistence;
607 @BeanReference(type = ClassNamePersistence.class)
608 protected ClassNamePersistence classNamePersistence;
609 @BeanReference(type = ClusterGroupPersistence.class)
610 protected ClusterGroupPersistence clusterGroupPersistence;
611 @BeanReference(type = CompanyPersistence.class)
612 protected CompanyPersistence companyPersistence;
613 @BeanReference(type = ContactPersistence.class)
614 protected ContactPersistence contactPersistence;
615 @BeanReference(type = CountryPersistence.class)
616 protected CountryPersistence countryPersistence;
617 @BeanReference(type = EmailAddressPersistence.class)
618 protected EmailAddressPersistence emailAddressPersistence;
619 @BeanReference(type = GroupPersistence.class)
620 protected GroupPersistence groupPersistence;
621 @BeanReference(type = ImagePersistence.class)
622 protected ImagePersistence imagePersistence;
623 @BeanReference(type = LayoutPersistence.class)
624 protected LayoutPersistence layoutPersistence;
625 @BeanReference(type = LayoutBranchPersistence.class)
626 protected LayoutBranchPersistence layoutBranchPersistence;
627 @BeanReference(type = LayoutPrototypePersistence.class)
628 protected LayoutPrototypePersistence layoutPrototypePersistence;
629 @BeanReference(type = LayoutRevisionPersistence.class)
630 protected LayoutRevisionPersistence layoutRevisionPersistence;
631 @BeanReference(type = LayoutSetPersistence.class)
632 protected LayoutSetPersistence layoutSetPersistence;
633 @BeanReference(type = LayoutSetBranchPersistence.class)
634 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
635 @BeanReference(type = LayoutSetPrototypePersistence.class)
636 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
637 @BeanReference(type = ListTypePersistence.class)
638 protected ListTypePersistence listTypePersistence;
639 @BeanReference(type = LockPersistence.class)
640 protected LockPersistence lockPersistence;
641 @BeanReference(type = MembershipRequestPersistence.class)
642 protected MembershipRequestPersistence membershipRequestPersistence;
643 @BeanReference(type = OrganizationPersistence.class)
644 protected OrganizationPersistence organizationPersistence;
645 @BeanReference(type = OrgGroupPermissionPersistence.class)
646 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
647 @BeanReference(type = OrgGroupRolePersistence.class)
648 protected OrgGroupRolePersistence orgGroupRolePersistence;
649 @BeanReference(type = OrgLaborPersistence.class)
650 protected OrgLaborPersistence orgLaborPersistence;
651 @BeanReference(type = PasswordPolicyPersistence.class)
652 protected PasswordPolicyPersistence passwordPolicyPersistence;
653 @BeanReference(type = PasswordPolicyRelPersistence.class)
654 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
655 @BeanReference(type = PasswordTrackerPersistence.class)
656 protected PasswordTrackerPersistence passwordTrackerPersistence;
657 @BeanReference(type = PermissionPersistence.class)
658 protected PermissionPersistence permissionPersistence;
659 @BeanReference(type = PhonePersistence.class)
660 protected PhonePersistence phonePersistence;
661 @BeanReference(type = PluginSettingPersistence.class)
662 protected PluginSettingPersistence pluginSettingPersistence;
663 @BeanReference(type = PortalPreferencesPersistence.class)
664 protected PortalPreferencesPersistence portalPreferencesPersistence;
665 @BeanReference(type = PortletPersistence.class)
666 protected PortletPersistence portletPersistence;
667 @BeanReference(type = PortletItemPersistence.class)
668 protected PortletItemPersistence portletItemPersistence;
669 @BeanReference(type = PortletPreferencesPersistence.class)
670 protected PortletPreferencesPersistence portletPreferencesPersistence;
671 @BeanReference(type = RegionPersistence.class)
672 protected RegionPersistence regionPersistence;
673 @BeanReference(type = ReleasePersistence.class)
674 protected ReleasePersistence releasePersistence;
675 @BeanReference(type = RepositoryPersistence.class)
676 protected RepositoryPersistence repositoryPersistence;
677 @BeanReference(type = RepositoryEntryPersistence.class)
678 protected RepositoryEntryPersistence repositoryEntryPersistence;
679 @BeanReference(type = ResourcePersistence.class)
680 protected ResourcePersistence resourcePersistence;
681 @BeanReference(type = ResourceActionPersistence.class)
682 protected ResourceActionPersistence resourceActionPersistence;
683 @BeanReference(type = ResourceBlockPersistence.class)
684 protected ResourceBlockPersistence resourceBlockPersistence;
685 @BeanReference(type = ResourceBlockPermissionPersistence.class)
686 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
687 @BeanReference(type = ResourceCodePersistence.class)
688 protected ResourceCodePersistence resourceCodePersistence;
689 @BeanReference(type = ResourcePermissionPersistence.class)
690 protected ResourcePermissionPersistence resourcePermissionPersistence;
691 @BeanReference(type = ResourceTypePermissionPersistence.class)
692 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
693 @BeanReference(type = RolePersistence.class)
694 protected RolePersistence rolePersistence;
695 @BeanReference(type = ServiceComponentPersistence.class)
696 protected ServiceComponentPersistence serviceComponentPersistence;
697 @BeanReference(type = ShardPersistence.class)
698 protected ShardPersistence shardPersistence;
699 @BeanReference(type = SubscriptionPersistence.class)
700 protected SubscriptionPersistence subscriptionPersistence;
701 @BeanReference(type = TeamPersistence.class)
702 protected TeamPersistence teamPersistence;
703 @BeanReference(type = TicketPersistence.class)
704 protected TicketPersistence ticketPersistence;
705 @BeanReference(type = UserPersistence.class)
706 protected UserPersistence userPersistence;
707 @BeanReference(type = UserGroupPersistence.class)
708 protected UserGroupPersistence userGroupPersistence;
709 @BeanReference(type = UserGroupGroupRolePersistence.class)
710 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
711 @BeanReference(type = UserGroupRolePersistence.class)
712 protected UserGroupRolePersistence userGroupRolePersistence;
713 @BeanReference(type = UserIdMapperPersistence.class)
714 protected UserIdMapperPersistence userIdMapperPersistence;
715 @BeanReference(type = UserNotificationEventPersistence.class)
716 protected UserNotificationEventPersistence userNotificationEventPersistence;
717 @BeanReference(type = UserTrackerPersistence.class)
718 protected UserTrackerPersistence userTrackerPersistence;
719 @BeanReference(type = UserTrackerPathPersistence.class)
720 protected UserTrackerPathPersistence userTrackerPathPersistence;
721 @BeanReference(type = VirtualHostPersistence.class)
722 protected VirtualHostPersistence virtualHostPersistence;
723 @BeanReference(type = WebDAVPropsPersistence.class)
724 protected WebDAVPropsPersistence webDAVPropsPersistence;
725 @BeanReference(type = WebsitePersistence.class)
726 protected WebsitePersistence websitePersistence;
727 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
728 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
729 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
730 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
731 private static final String _SQL_SELECT_ACCOUNT = "SELECT account FROM Account account";
732 private static final String _SQL_COUNT_ACCOUNT = "SELECT COUNT(account) FROM Account account";
733 private static final String _ORDER_BY_ENTITY_ALIAS = "account.";
734 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Account exists with the primary key ";
735 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
736 private static Log _log = LogFactoryUtil.getLog(AccountPersistenceImpl.class);
737 private static Account _nullAccount = new AccountImpl() {
738 @Override
739 public Object clone() {
740 return this;
741 }
742
743 @Override
744 public CacheModel<Account> toCacheModel() {
745 return _nullAccountCacheModel;
746 }
747 };
748
749 private static CacheModel<Account> _nullAccountCacheModel = new CacheModel<Account>() {
750 public Account toEntityModel() {
751 return _nullAccount;
752 }
753 };
754 }