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_WITH_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_WITHOUT_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 if (account.isCachedModel()) {
237 account = (Account)session.get(AccountImpl.class,
238 account.getPrimaryKeyObj());
239 }
240
241 session.delete(account);
242 }
243 catch (Exception e) {
244 throw processException(e);
245 }
246 finally {
247 closeSession(session);
248 }
249
250 clearCache(account);
251
252 return account;
253 }
254
255 @Override
256 public Account updateImpl(com.liferay.portal.model.Account account)
257 throws SystemException {
258 account = toUnwrappedModel(account);
259
260 boolean isNew = account.isNew();
261
262 Session session = null;
263
264 try {
265 session = openSession();
266
267 if (account.isNew()) {
268 session.save(account);
269
270 account.setNew(false);
271 }
272 else {
273 session.merge(account);
274 }
275 }
276 catch (Exception e) {
277 throw processException(e);
278 }
279 finally {
280 closeSession(session);
281 }
282
283 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
284
285 if (isNew) {
286 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
287 }
288
289 EntityCacheUtil.putResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
290 AccountImpl.class, account.getPrimaryKey(), account);
291
292 return account;
293 }
294
295 protected Account toUnwrappedModel(Account account) {
296 if (account instanceof AccountImpl) {
297 return account;
298 }
299
300 AccountImpl accountImpl = new AccountImpl();
301
302 accountImpl.setNew(account.isNew());
303 accountImpl.setPrimaryKey(account.getPrimaryKey());
304
305 accountImpl.setAccountId(account.getAccountId());
306 accountImpl.setCompanyId(account.getCompanyId());
307 accountImpl.setUserId(account.getUserId());
308 accountImpl.setUserName(account.getUserName());
309 accountImpl.setCreateDate(account.getCreateDate());
310 accountImpl.setModifiedDate(account.getModifiedDate());
311 accountImpl.setParentAccountId(account.getParentAccountId());
312 accountImpl.setName(account.getName());
313 accountImpl.setLegalName(account.getLegalName());
314 accountImpl.setLegalId(account.getLegalId());
315 accountImpl.setLegalType(account.getLegalType());
316 accountImpl.setSicCode(account.getSicCode());
317 accountImpl.setTickerSymbol(account.getTickerSymbol());
318 accountImpl.setIndustry(account.getIndustry());
319 accountImpl.setType(account.getType());
320 accountImpl.setSize(account.getSize());
321
322 return accountImpl;
323 }
324
325
333 @Override
334 public Account findByPrimaryKey(Serializable primaryKey)
335 throws NoSuchModelException, SystemException {
336 return findByPrimaryKey(((Long)primaryKey).longValue());
337 }
338
339
347 public Account findByPrimaryKey(long accountId)
348 throws NoSuchAccountException, SystemException {
349 Account account = fetchByPrimaryKey(accountId);
350
351 if (account == null) {
352 if (_log.isWarnEnabled()) {
353 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + accountId);
354 }
355
356 throw new NoSuchAccountException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
357 accountId);
358 }
359
360 return account;
361 }
362
363
370 @Override
371 public Account fetchByPrimaryKey(Serializable primaryKey)
372 throws SystemException {
373 return fetchByPrimaryKey(((Long)primaryKey).longValue());
374 }
375
376
383 public Account fetchByPrimaryKey(long accountId) throws SystemException {
384 Account account = (Account)EntityCacheUtil.getResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
385 AccountImpl.class, accountId);
386
387 if (account == _nullAccount) {
388 return null;
389 }
390
391 if (account == null) {
392 Session session = null;
393
394 boolean hasException = false;
395
396 try {
397 session = openSession();
398
399 account = (Account)session.get(AccountImpl.class,
400 Long.valueOf(accountId));
401 }
402 catch (Exception e) {
403 hasException = true;
404
405 throw processException(e);
406 }
407 finally {
408 if (account != null) {
409 cacheResult(account);
410 }
411 else if (!hasException) {
412 EntityCacheUtil.putResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
413 AccountImpl.class, accountId, _nullAccount);
414 }
415
416 closeSession(session);
417 }
418 }
419
420 return account;
421 }
422
423
429 public List<Account> findAll() throws SystemException {
430 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
431 }
432
433
445 public List<Account> findAll(int start, int end) throws SystemException {
446 return findAll(start, end, null);
447 }
448
449
462 public List<Account> findAll(int start, int end,
463 OrderByComparator orderByComparator) throws SystemException {
464 FinderPath finderPath = null;
465 Object[] finderArgs = new Object[] { start, end, orderByComparator };
466
467 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
468 (orderByComparator == null)) {
469 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
470 finderArgs = FINDER_ARGS_EMPTY;
471 }
472 else {
473 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
474 finderArgs = new Object[] { start, end, orderByComparator };
475 }
476
477 List<Account> list = (List<Account>)FinderCacheUtil.getResult(finderPath,
478 finderArgs, this);
479
480 if (list == null) {
481 StringBundler query = null;
482 String sql = null;
483
484 if (orderByComparator != null) {
485 query = new StringBundler(2 +
486 (orderByComparator.getOrderByFields().length * 3));
487
488 query.append(_SQL_SELECT_ACCOUNT);
489
490 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
491 orderByComparator);
492
493 sql = query.toString();
494 }
495 else {
496 sql = _SQL_SELECT_ACCOUNT;
497 }
498
499 Session session = null;
500
501 try {
502 session = openSession();
503
504 Query q = session.createQuery(sql);
505
506 if (orderByComparator == null) {
507 list = (List<Account>)QueryUtil.list(q, getDialect(),
508 start, end, false);
509
510 Collections.sort(list);
511 }
512 else {
513 list = (List<Account>)QueryUtil.list(q, getDialect(),
514 start, end);
515 }
516 }
517 catch (Exception e) {
518 throw processException(e);
519 }
520 finally {
521 if (list == null) {
522 FinderCacheUtil.removeResult(finderPath, finderArgs);
523 }
524 else {
525 cacheResult(list);
526
527 FinderCacheUtil.putResult(finderPath, finderArgs, list);
528 }
529
530 closeSession(session);
531 }
532 }
533
534 return list;
535 }
536
537
542 public void removeAll() throws SystemException {
543 for (Account account : findAll()) {
544 remove(account);
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_ACCOUNT);
565
566 count = (Long)q.uniqueResult();
567 }
568 catch (Exception e) {
569 throw processException(e);
570 }
571 finally {
572 if (count == null) {
573 count = Long.valueOf(0);
574 }
575
576 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
577 FINDER_ARGS_EMPTY, count);
578
579 closeSession(session);
580 }
581 }
582
583 return count.intValue();
584 }
585
586
589 public void afterPropertiesSet() {
590 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
591 com.liferay.portal.util.PropsUtil.get(
592 "value.object.listener.com.liferay.portal.model.Account")));
593
594 if (listenerClassNames.length > 0) {
595 try {
596 List<ModelListener<Account>> listenersList = new ArrayList<ModelListener<Account>>();
597
598 for (String listenerClassName : listenerClassNames) {
599 listenersList.add((ModelListener<Account>)InstanceFactory.newInstance(
600 listenerClassName));
601 }
602
603 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
604 }
605 catch (Exception e) {
606 _log.error(e);
607 }
608 }
609 }
610
611 public void destroy() {
612 EntityCacheUtil.removeCache(AccountImpl.class.getName());
613 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
614 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
615 }
616
617 @BeanReference(type = AccountPersistence.class)
618 protected AccountPersistence accountPersistence;
619 @BeanReference(type = AddressPersistence.class)
620 protected AddressPersistence addressPersistence;
621 @BeanReference(type = BrowserTrackerPersistence.class)
622 protected BrowserTrackerPersistence browserTrackerPersistence;
623 @BeanReference(type = ClassNamePersistence.class)
624 protected ClassNamePersistence classNamePersistence;
625 @BeanReference(type = ClusterGroupPersistence.class)
626 protected ClusterGroupPersistence clusterGroupPersistence;
627 @BeanReference(type = CompanyPersistence.class)
628 protected CompanyPersistence companyPersistence;
629 @BeanReference(type = ContactPersistence.class)
630 protected ContactPersistence contactPersistence;
631 @BeanReference(type = CountryPersistence.class)
632 protected CountryPersistence countryPersistence;
633 @BeanReference(type = EmailAddressPersistence.class)
634 protected EmailAddressPersistence emailAddressPersistence;
635 @BeanReference(type = GroupPersistence.class)
636 protected GroupPersistence groupPersistence;
637 @BeanReference(type = ImagePersistence.class)
638 protected ImagePersistence imagePersistence;
639 @BeanReference(type = LayoutPersistence.class)
640 protected LayoutPersistence layoutPersistence;
641 @BeanReference(type = LayoutBranchPersistence.class)
642 protected LayoutBranchPersistence layoutBranchPersistence;
643 @BeanReference(type = LayoutPrototypePersistence.class)
644 protected LayoutPrototypePersistence layoutPrototypePersistence;
645 @BeanReference(type = LayoutRevisionPersistence.class)
646 protected LayoutRevisionPersistence layoutRevisionPersistence;
647 @BeanReference(type = LayoutSetPersistence.class)
648 protected LayoutSetPersistence layoutSetPersistence;
649 @BeanReference(type = LayoutSetBranchPersistence.class)
650 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
651 @BeanReference(type = LayoutSetPrototypePersistence.class)
652 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
653 @BeanReference(type = ListTypePersistence.class)
654 protected ListTypePersistence listTypePersistence;
655 @BeanReference(type = LockPersistence.class)
656 protected LockPersistence lockPersistence;
657 @BeanReference(type = MembershipRequestPersistence.class)
658 protected MembershipRequestPersistence membershipRequestPersistence;
659 @BeanReference(type = OrganizationPersistence.class)
660 protected OrganizationPersistence organizationPersistence;
661 @BeanReference(type = OrgGroupRolePersistence.class)
662 protected OrgGroupRolePersistence orgGroupRolePersistence;
663 @BeanReference(type = OrgLaborPersistence.class)
664 protected OrgLaborPersistence orgLaborPersistence;
665 @BeanReference(type = PasswordPolicyPersistence.class)
666 protected PasswordPolicyPersistence passwordPolicyPersistence;
667 @BeanReference(type = PasswordPolicyRelPersistence.class)
668 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
669 @BeanReference(type = PasswordTrackerPersistence.class)
670 protected PasswordTrackerPersistence passwordTrackerPersistence;
671 @BeanReference(type = PhonePersistence.class)
672 protected PhonePersistence phonePersistence;
673 @BeanReference(type = PluginSettingPersistence.class)
674 protected PluginSettingPersistence pluginSettingPersistence;
675 @BeanReference(type = PortalPreferencesPersistence.class)
676 protected PortalPreferencesPersistence portalPreferencesPersistence;
677 @BeanReference(type = PortletPersistence.class)
678 protected PortletPersistence portletPersistence;
679 @BeanReference(type = PortletItemPersistence.class)
680 protected PortletItemPersistence portletItemPersistence;
681 @BeanReference(type = PortletPreferencesPersistence.class)
682 protected PortletPreferencesPersistence portletPreferencesPersistence;
683 @BeanReference(type = RegionPersistence.class)
684 protected RegionPersistence regionPersistence;
685 @BeanReference(type = ReleasePersistence.class)
686 protected ReleasePersistence releasePersistence;
687 @BeanReference(type = RepositoryPersistence.class)
688 protected RepositoryPersistence repositoryPersistence;
689 @BeanReference(type = RepositoryEntryPersistence.class)
690 protected RepositoryEntryPersistence repositoryEntryPersistence;
691 @BeanReference(type = ResourceActionPersistence.class)
692 protected ResourceActionPersistence resourceActionPersistence;
693 @BeanReference(type = ResourceBlockPersistence.class)
694 protected ResourceBlockPersistence resourceBlockPersistence;
695 @BeanReference(type = ResourceBlockPermissionPersistence.class)
696 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
697 @BeanReference(type = ResourcePermissionPersistence.class)
698 protected ResourcePermissionPersistence resourcePermissionPersistence;
699 @BeanReference(type = ResourceTypePermissionPersistence.class)
700 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
701 @BeanReference(type = RolePersistence.class)
702 protected RolePersistence rolePersistence;
703 @BeanReference(type = ServiceComponentPersistence.class)
704 protected ServiceComponentPersistence serviceComponentPersistence;
705 @BeanReference(type = ShardPersistence.class)
706 protected ShardPersistence shardPersistence;
707 @BeanReference(type = SubscriptionPersistence.class)
708 protected SubscriptionPersistence subscriptionPersistence;
709 @BeanReference(type = TeamPersistence.class)
710 protected TeamPersistence teamPersistence;
711 @BeanReference(type = TicketPersistence.class)
712 protected TicketPersistence ticketPersistence;
713 @BeanReference(type = UserPersistence.class)
714 protected UserPersistence userPersistence;
715 @BeanReference(type = UserGroupPersistence.class)
716 protected UserGroupPersistence userGroupPersistence;
717 @BeanReference(type = UserGroupGroupRolePersistence.class)
718 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
719 @BeanReference(type = UserGroupRolePersistence.class)
720 protected UserGroupRolePersistence userGroupRolePersistence;
721 @BeanReference(type = UserIdMapperPersistence.class)
722 protected UserIdMapperPersistence userIdMapperPersistence;
723 @BeanReference(type = UserNotificationEventPersistence.class)
724 protected UserNotificationEventPersistence userNotificationEventPersistence;
725 @BeanReference(type = UserTrackerPersistence.class)
726 protected UserTrackerPersistence userTrackerPersistence;
727 @BeanReference(type = UserTrackerPathPersistence.class)
728 protected UserTrackerPathPersistence userTrackerPathPersistence;
729 @BeanReference(type = VirtualHostPersistence.class)
730 protected VirtualHostPersistence virtualHostPersistence;
731 @BeanReference(type = WebDAVPropsPersistence.class)
732 protected WebDAVPropsPersistence webDAVPropsPersistence;
733 @BeanReference(type = WebsitePersistence.class)
734 protected WebsitePersistence websitePersistence;
735 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
736 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
737 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
738 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
739 private static final String _SQL_SELECT_ACCOUNT = "SELECT account FROM Account account";
740 private static final String _SQL_COUNT_ACCOUNT = "SELECT COUNT(account) FROM Account account";
741 private static final String _ORDER_BY_ENTITY_ALIAS = "account.";
742 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Account exists with the primary key ";
743 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
744 private static Log _log = LogFactoryUtil.getLog(AccountPersistenceImpl.class);
745 private static Account _nullAccount = new AccountImpl() {
746 @Override
747 public Object clone() {
748 return this;
749 }
750
751 @Override
752 public CacheModel<Account> toCacheModel() {
753 return _nullAccountCacheModel;
754 }
755 };
756
757 private static CacheModel<Account> _nullAccountCacheModel = new CacheModel<Account>() {
758 public Account toEntityModel() {
759 return _nullAccount;
760 }
761 };
762 }