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.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.Account;
036 import com.liferay.portal.model.ModelListener;
037 import com.liferay.portal.model.impl.AccountImpl;
038 import com.liferay.portal.model.impl.AccountModelImpl;
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 AccountPersistenceImpl extends BasePersistenceImpl<Account>
064 implements AccountPersistence {
065 public static final String FINDER_CLASS_NAME_ENTITY = AccountImpl.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(AccountModelImpl.ENTITY_CACHE_ENABLED,
069 AccountModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
070 "findAll", new String[0]);
071 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AccountModelImpl.ENTITY_CACHE_ENABLED,
072 AccountModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
073 "countAll", new String[0]);
074
075
080 public void cacheResult(Account account) {
081 EntityCacheUtil.putResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
082 AccountImpl.class, account.getPrimaryKey(), account);
083 }
084
085
090 public void cacheResult(List<Account> accounts) {
091 for (Account account : accounts) {
092 if (EntityCacheUtil.getResult(
093 AccountModelImpl.ENTITY_CACHE_ENABLED,
094 AccountImpl.class, account.getPrimaryKey(), this) == null) {
095 cacheResult(account);
096 }
097 }
098 }
099
100
107 public void clearCache() {
108 CacheRegistryUtil.clear(AccountImpl.class.getName());
109 EntityCacheUtil.clearCache(AccountImpl.class.getName());
110 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
111 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
112 }
113
114
121 public void clearCache(Account account) {
122 EntityCacheUtil.removeResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
123 AccountImpl.class, account.getPrimaryKey());
124 }
125
126
132 public Account create(long accountId) {
133 Account account = new AccountImpl();
134
135 account.setNew(true);
136 account.setPrimaryKey(accountId);
137
138 return account;
139 }
140
141
149 public Account remove(Serializable primaryKey)
150 throws NoSuchModelException, SystemException {
151 return remove(((Long)primaryKey).longValue());
152 }
153
154
162 public Account remove(long accountId)
163 throws NoSuchAccountException, SystemException {
164 Session session = null;
165
166 try {
167 session = openSession();
168
169 Account account = (Account)session.get(AccountImpl.class,
170 new Long(accountId));
171
172 if (account == null) {
173 if (_log.isWarnEnabled()) {
174 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + accountId);
175 }
176
177 throw new NoSuchAccountException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
178 accountId);
179 }
180
181 return remove(account);
182 }
183 catch (NoSuchAccountException nsee) {
184 throw nsee;
185 }
186 catch (Exception e) {
187 throw processException(e);
188 }
189 finally {
190 closeSession(session);
191 }
192 }
193
194 protected Account removeImpl(Account account) throws SystemException {
195 account = toUnwrappedModel(account);
196
197 Session session = null;
198
199 try {
200 session = openSession();
201
202 BatchSessionUtil.delete(session, account);
203 }
204 catch (Exception e) {
205 throw processException(e);
206 }
207 finally {
208 closeSession(session);
209 }
210
211 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
212
213 EntityCacheUtil.removeResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
214 AccountImpl.class, account.getPrimaryKey());
215
216 return account;
217 }
218
219 public Account updateImpl(com.liferay.portal.model.Account account,
220 boolean merge) throws SystemException {
221 account = toUnwrappedModel(account);
222
223 Session session = null;
224
225 try {
226 session = openSession();
227
228 BatchSessionUtil.update(session, account, merge);
229
230 account.setNew(false);
231 }
232 catch (Exception e) {
233 throw processException(e);
234 }
235 finally {
236 closeSession(session);
237 }
238
239 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
240
241 EntityCacheUtil.putResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
242 AccountImpl.class, account.getPrimaryKey(), account);
243
244 return account;
245 }
246
247 protected Account toUnwrappedModel(Account account) {
248 if (account instanceof AccountImpl) {
249 return account;
250 }
251
252 AccountImpl accountImpl = new AccountImpl();
253
254 accountImpl.setNew(account.isNew());
255 accountImpl.setPrimaryKey(account.getPrimaryKey());
256
257 accountImpl.setAccountId(account.getAccountId());
258 accountImpl.setCompanyId(account.getCompanyId());
259 accountImpl.setUserId(account.getUserId());
260 accountImpl.setUserName(account.getUserName());
261 accountImpl.setCreateDate(account.getCreateDate());
262 accountImpl.setModifiedDate(account.getModifiedDate());
263 accountImpl.setParentAccountId(account.getParentAccountId());
264 accountImpl.setName(account.getName());
265 accountImpl.setLegalName(account.getLegalName());
266 accountImpl.setLegalId(account.getLegalId());
267 accountImpl.setLegalType(account.getLegalType());
268 accountImpl.setSicCode(account.getSicCode());
269 accountImpl.setTickerSymbol(account.getTickerSymbol());
270 accountImpl.setIndustry(account.getIndustry());
271 accountImpl.setType(account.getType());
272 accountImpl.setSize(account.getSize());
273
274 return accountImpl;
275 }
276
277
285 public Account findByPrimaryKey(Serializable primaryKey)
286 throws NoSuchModelException, SystemException {
287 return findByPrimaryKey(((Long)primaryKey).longValue());
288 }
289
290
298 public Account findByPrimaryKey(long accountId)
299 throws NoSuchAccountException, SystemException {
300 Account account = fetchByPrimaryKey(accountId);
301
302 if (account == null) {
303 if (_log.isWarnEnabled()) {
304 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + accountId);
305 }
306
307 throw new NoSuchAccountException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
308 accountId);
309 }
310
311 return account;
312 }
313
314
321 public Account fetchByPrimaryKey(Serializable primaryKey)
322 throws SystemException {
323 return fetchByPrimaryKey(((Long)primaryKey).longValue());
324 }
325
326
333 public Account fetchByPrimaryKey(long accountId) throws SystemException {
334 Account account = (Account)EntityCacheUtil.getResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
335 AccountImpl.class, accountId, this);
336
337 if (account == null) {
338 Session session = null;
339
340 try {
341 session = openSession();
342
343 account = (Account)session.get(AccountImpl.class,
344 new Long(accountId));
345 }
346 catch (Exception e) {
347 throw processException(e);
348 }
349 finally {
350 if (account != null) {
351 cacheResult(account);
352 }
353
354 closeSession(session);
355 }
356 }
357
358 return account;
359 }
360
361
367 public List<Account> findAll() throws SystemException {
368 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
369 }
370
371
383 public List<Account> findAll(int start, int end) throws SystemException {
384 return findAll(start, end, null);
385 }
386
387
400 public List<Account> findAll(int start, int end,
401 OrderByComparator orderByComparator) throws SystemException {
402 Object[] finderArgs = new Object[] {
403 String.valueOf(start), String.valueOf(end),
404 String.valueOf(orderByComparator)
405 };
406
407 List<Account> list = (List<Account>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
408 finderArgs, this);
409
410 if (list == null) {
411 StringBundler query = null;
412 String sql = null;
413
414 if (orderByComparator != null) {
415 query = new StringBundler(2 +
416 (orderByComparator.getOrderByFields().length * 3));
417
418 query.append(_SQL_SELECT_ACCOUNT);
419
420 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
421 orderByComparator);
422
423 sql = query.toString();
424 }
425 else {
426 sql = _SQL_SELECT_ACCOUNT;
427 }
428
429 Session session = null;
430
431 try {
432 session = openSession();
433
434 Query q = session.createQuery(sql);
435
436 if (orderByComparator == null) {
437 list = (List<Account>)QueryUtil.list(q, getDialect(),
438 start, end, false);
439
440 Collections.sort(list);
441 }
442 else {
443 list = (List<Account>)QueryUtil.list(q, getDialect(),
444 start, end);
445 }
446 }
447 catch (Exception e) {
448 throw processException(e);
449 }
450 finally {
451 if (list == null) {
452 FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
453 finderArgs);
454 }
455 else {
456 cacheResult(list);
457
458 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
459 list);
460 }
461
462 closeSession(session);
463 }
464 }
465
466 return list;
467 }
468
469
474 public void removeAll() throws SystemException {
475 for (Account account : findAll()) {
476 remove(account);
477 }
478 }
479
480
486 public int countAll() throws SystemException {
487 Object[] finderArgs = new Object[0];
488
489 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
490 finderArgs, this);
491
492 if (count == null) {
493 Session session = null;
494
495 try {
496 session = openSession();
497
498 Query q = session.createQuery(_SQL_COUNT_ACCOUNT);
499
500 count = (Long)q.uniqueResult();
501 }
502 catch (Exception e) {
503 throw processException(e);
504 }
505 finally {
506 if (count == null) {
507 count = Long.valueOf(0);
508 }
509
510 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
511 count);
512
513 closeSession(session);
514 }
515 }
516
517 return count.intValue();
518 }
519
520
523 public void afterPropertiesSet() {
524 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
525 com.liferay.portal.util.PropsUtil.get(
526 "value.object.listener.com.liferay.portal.model.Account")));
527
528 if (listenerClassNames.length > 0) {
529 try {
530 List<ModelListener<Account>> listenersList = new ArrayList<ModelListener<Account>>();
531
532 for (String listenerClassName : listenerClassNames) {
533 listenersList.add((ModelListener<Account>)InstanceFactory.newInstance(
534 listenerClassName));
535 }
536
537 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
538 }
539 catch (Exception e) {
540 _log.error(e);
541 }
542 }
543 }
544
545 public void destroy() {
546 EntityCacheUtil.removeCache(AccountImpl.class.getName());
547 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
548 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
549 }
550
551 @BeanReference(type = AccountPersistence.class)
552 protected AccountPersistence accountPersistence;
553 @BeanReference(type = AddressPersistence.class)
554 protected AddressPersistence addressPersistence;
555 @BeanReference(type = BrowserTrackerPersistence.class)
556 protected BrowserTrackerPersistence browserTrackerPersistence;
557 @BeanReference(type = ClassNamePersistence.class)
558 protected ClassNamePersistence classNamePersistence;
559 @BeanReference(type = ClusterGroupPersistence.class)
560 protected ClusterGroupPersistence clusterGroupPersistence;
561 @BeanReference(type = CompanyPersistence.class)
562 protected CompanyPersistence companyPersistence;
563 @BeanReference(type = ContactPersistence.class)
564 protected ContactPersistence contactPersistence;
565 @BeanReference(type = CountryPersistence.class)
566 protected CountryPersistence countryPersistence;
567 @BeanReference(type = EmailAddressPersistence.class)
568 protected EmailAddressPersistence emailAddressPersistence;
569 @BeanReference(type = GroupPersistence.class)
570 protected GroupPersistence groupPersistence;
571 @BeanReference(type = ImagePersistence.class)
572 protected ImagePersistence imagePersistence;
573 @BeanReference(type = LayoutPersistence.class)
574 protected LayoutPersistence layoutPersistence;
575 @BeanReference(type = LayoutPrototypePersistence.class)
576 protected LayoutPrototypePersistence layoutPrototypePersistence;
577 @BeanReference(type = LayoutSetPersistence.class)
578 protected LayoutSetPersistence layoutSetPersistence;
579 @BeanReference(type = LayoutSetPrototypePersistence.class)
580 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
581 @BeanReference(type = ListTypePersistence.class)
582 protected ListTypePersistence listTypePersistence;
583 @BeanReference(type = LockPersistence.class)
584 protected LockPersistence lockPersistence;
585 @BeanReference(type = MembershipRequestPersistence.class)
586 protected MembershipRequestPersistence membershipRequestPersistence;
587 @BeanReference(type = OrganizationPersistence.class)
588 protected OrganizationPersistence organizationPersistence;
589 @BeanReference(type = OrgGroupPermissionPersistence.class)
590 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
591 @BeanReference(type = OrgGroupRolePersistence.class)
592 protected OrgGroupRolePersistence orgGroupRolePersistence;
593 @BeanReference(type = OrgLaborPersistence.class)
594 protected OrgLaborPersistence orgLaborPersistence;
595 @BeanReference(type = PasswordPolicyPersistence.class)
596 protected PasswordPolicyPersistence passwordPolicyPersistence;
597 @BeanReference(type = PasswordPolicyRelPersistence.class)
598 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
599 @BeanReference(type = PasswordTrackerPersistence.class)
600 protected PasswordTrackerPersistence passwordTrackerPersistence;
601 @BeanReference(type = PermissionPersistence.class)
602 protected PermissionPersistence permissionPersistence;
603 @BeanReference(type = PhonePersistence.class)
604 protected PhonePersistence phonePersistence;
605 @BeanReference(type = PluginSettingPersistence.class)
606 protected PluginSettingPersistence pluginSettingPersistence;
607 @BeanReference(type = PortletPersistence.class)
608 protected PortletPersistence portletPersistence;
609 @BeanReference(type = PortletItemPersistence.class)
610 protected PortletItemPersistence portletItemPersistence;
611 @BeanReference(type = PortletPreferencesPersistence.class)
612 protected PortletPreferencesPersistence portletPreferencesPersistence;
613 @BeanReference(type = RegionPersistence.class)
614 protected RegionPersistence regionPersistence;
615 @BeanReference(type = ReleasePersistence.class)
616 protected ReleasePersistence releasePersistence;
617 @BeanReference(type = ResourcePersistence.class)
618 protected ResourcePersistence resourcePersistence;
619 @BeanReference(type = ResourceActionPersistence.class)
620 protected ResourceActionPersistence resourceActionPersistence;
621 @BeanReference(type = ResourceCodePersistence.class)
622 protected ResourceCodePersistence resourceCodePersistence;
623 @BeanReference(type = ResourcePermissionPersistence.class)
624 protected ResourcePermissionPersistence resourcePermissionPersistence;
625 @BeanReference(type = RolePersistence.class)
626 protected RolePersistence rolePersistence;
627 @BeanReference(type = ServiceComponentPersistence.class)
628 protected ServiceComponentPersistence serviceComponentPersistence;
629 @BeanReference(type = ShardPersistence.class)
630 protected ShardPersistence shardPersistence;
631 @BeanReference(type = SubscriptionPersistence.class)
632 protected SubscriptionPersistence subscriptionPersistence;
633 @BeanReference(type = TicketPersistence.class)
634 protected TicketPersistence ticketPersistence;
635 @BeanReference(type = TeamPersistence.class)
636 protected TeamPersistence teamPersistence;
637 @BeanReference(type = UserPersistence.class)
638 protected UserPersistence userPersistence;
639 @BeanReference(type = UserGroupPersistence.class)
640 protected UserGroupPersistence userGroupPersistence;
641 @BeanReference(type = UserGroupGroupRolePersistence.class)
642 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
643 @BeanReference(type = UserGroupRolePersistence.class)
644 protected UserGroupRolePersistence userGroupRolePersistence;
645 @BeanReference(type = UserIdMapperPersistence.class)
646 protected UserIdMapperPersistence userIdMapperPersistence;
647 @BeanReference(type = UserTrackerPersistence.class)
648 protected UserTrackerPersistence userTrackerPersistence;
649 @BeanReference(type = UserTrackerPathPersistence.class)
650 protected UserTrackerPathPersistence userTrackerPathPersistence;
651 @BeanReference(type = WebDAVPropsPersistence.class)
652 protected WebDAVPropsPersistence webDAVPropsPersistence;
653 @BeanReference(type = WebsitePersistence.class)
654 protected WebsitePersistence websitePersistence;
655 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
656 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
657 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
658 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
659 private static final String _SQL_SELECT_ACCOUNT = "SELECT account FROM Account account";
660 private static final String _SQL_COUNT_ACCOUNT = "SELECT COUNT(account) FROM Account account";
661 private static final String _ORDER_BY_ENTITY_ALIAS = "account.";
662 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Account exists with the primary key ";
663 private static Log _log = LogFactoryUtil.getLog(AccountPersistenceImpl.class);
664 }