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 if (account.isCachedModel() || BatchSessionUtil.isEnabled()) {
203 Object staleObject = session.get(AccountImpl.class,
204 account.getPrimaryKeyObj());
205
206 if (staleObject != null) {
207 session.evict(staleObject);
208 }
209 }
210
211 session.delete(account);
212
213 session.flush();
214 }
215 catch (Exception e) {
216 throw processException(e);
217 }
218 finally {
219 closeSession(session);
220 }
221
222 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
223
224 EntityCacheUtil.removeResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
225 AccountImpl.class, account.getPrimaryKey());
226
227 return account;
228 }
229
230 public Account updateImpl(com.liferay.portal.model.Account account,
231 boolean merge) throws SystemException {
232 account = toUnwrappedModel(account);
233
234 Session session = null;
235
236 try {
237 session = openSession();
238
239 BatchSessionUtil.update(session, account, merge);
240
241 account.setNew(false);
242 }
243 catch (Exception e) {
244 throw processException(e);
245 }
246 finally {
247 closeSession(session);
248 }
249
250 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
251
252 EntityCacheUtil.putResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
253 AccountImpl.class, account.getPrimaryKey(), account);
254
255 return account;
256 }
257
258 protected Account toUnwrappedModel(Account account) {
259 if (account instanceof AccountImpl) {
260 return account;
261 }
262
263 AccountImpl accountImpl = new AccountImpl();
264
265 accountImpl.setNew(account.isNew());
266 accountImpl.setPrimaryKey(account.getPrimaryKey());
267
268 accountImpl.setAccountId(account.getAccountId());
269 accountImpl.setCompanyId(account.getCompanyId());
270 accountImpl.setUserId(account.getUserId());
271 accountImpl.setUserName(account.getUserName());
272 accountImpl.setCreateDate(account.getCreateDate());
273 accountImpl.setModifiedDate(account.getModifiedDate());
274 accountImpl.setParentAccountId(account.getParentAccountId());
275 accountImpl.setName(account.getName());
276 accountImpl.setLegalName(account.getLegalName());
277 accountImpl.setLegalId(account.getLegalId());
278 accountImpl.setLegalType(account.getLegalType());
279 accountImpl.setSicCode(account.getSicCode());
280 accountImpl.setTickerSymbol(account.getTickerSymbol());
281 accountImpl.setIndustry(account.getIndustry());
282 accountImpl.setType(account.getType());
283 accountImpl.setSize(account.getSize());
284
285 return accountImpl;
286 }
287
288
296 public Account findByPrimaryKey(Serializable primaryKey)
297 throws NoSuchModelException, SystemException {
298 return findByPrimaryKey(((Long)primaryKey).longValue());
299 }
300
301
309 public Account findByPrimaryKey(long accountId)
310 throws NoSuchAccountException, SystemException {
311 Account account = fetchByPrimaryKey(accountId);
312
313 if (account == null) {
314 if (_log.isWarnEnabled()) {
315 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + accountId);
316 }
317
318 throw new NoSuchAccountException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
319 accountId);
320 }
321
322 return account;
323 }
324
325
332 public Account fetchByPrimaryKey(Serializable primaryKey)
333 throws SystemException {
334 return fetchByPrimaryKey(((Long)primaryKey).longValue());
335 }
336
337
344 public Account fetchByPrimaryKey(long accountId) throws SystemException {
345 Account account = (Account)EntityCacheUtil.getResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
346 AccountImpl.class, accountId, this);
347
348 if (account == null) {
349 Session session = null;
350
351 try {
352 session = openSession();
353
354 account = (Account)session.get(AccountImpl.class,
355 new Long(accountId));
356 }
357 catch (Exception e) {
358 throw processException(e);
359 }
360 finally {
361 if (account != null) {
362 cacheResult(account);
363 }
364
365 closeSession(session);
366 }
367 }
368
369 return account;
370 }
371
372
378 public List<Account> findAll() throws SystemException {
379 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
380 }
381
382
394 public List<Account> findAll(int start, int end) throws SystemException {
395 return findAll(start, end, null);
396 }
397
398
411 public List<Account> findAll(int start, int end,
412 OrderByComparator orderByComparator) throws SystemException {
413 Object[] finderArgs = new Object[] {
414 String.valueOf(start), String.valueOf(end),
415 String.valueOf(orderByComparator)
416 };
417
418 List<Account> list = (List<Account>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
419 finderArgs, this);
420
421 if (list == null) {
422 Session session = null;
423
424 try {
425 session = openSession();
426
427 StringBundler query = null;
428 String sql = null;
429
430 if (orderByComparator != null) {
431 query = new StringBundler(2 +
432 (orderByComparator.getOrderByFields().length * 3));
433
434 query.append(_SQL_SELECT_ACCOUNT);
435
436 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
437 orderByComparator);
438
439 sql = query.toString();
440 }
441 else {
442 sql = _SQL_SELECT_ACCOUNT;
443 }
444
445 Query q = session.createQuery(sql);
446
447 if (orderByComparator == null) {
448 list = (List<Account>)QueryUtil.list(q, getDialect(),
449 start, end, false);
450
451 Collections.sort(list);
452 }
453 else {
454 list = (List<Account>)QueryUtil.list(q, getDialect(),
455 start, end);
456 }
457 }
458 catch (Exception e) {
459 throw processException(e);
460 }
461 finally {
462 if (list == null) {
463 list = new ArrayList<Account>();
464 }
465
466 cacheResult(list);
467
468 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
469
470 closeSession(session);
471 }
472 }
473
474 return list;
475 }
476
477
482 public void removeAll() throws SystemException {
483 for (Account account : findAll()) {
484 remove(account);
485 }
486 }
487
488
494 public int countAll() throws SystemException {
495 Object[] finderArgs = new Object[0];
496
497 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
498 finderArgs, this);
499
500 if (count == null) {
501 Session session = null;
502
503 try {
504 session = openSession();
505
506 Query q = session.createQuery(_SQL_COUNT_ACCOUNT);
507
508 count = (Long)q.uniqueResult();
509 }
510 catch (Exception e) {
511 throw processException(e);
512 }
513 finally {
514 if (count == null) {
515 count = Long.valueOf(0);
516 }
517
518 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
519 count);
520
521 closeSession(session);
522 }
523 }
524
525 return count.intValue();
526 }
527
528
531 public void afterPropertiesSet() {
532 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
533 com.liferay.portal.util.PropsUtil.get(
534 "value.object.listener.com.liferay.portal.model.Account")));
535
536 if (listenerClassNames.length > 0) {
537 try {
538 List<ModelListener<Account>> listenersList = new ArrayList<ModelListener<Account>>();
539
540 for (String listenerClassName : listenerClassNames) {
541 listenersList.add((ModelListener<Account>)InstanceFactory.newInstance(
542 listenerClassName));
543 }
544
545 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
546 }
547 catch (Exception e) {
548 _log.error(e);
549 }
550 }
551 }
552
553 @BeanReference(type = AccountPersistence.class)
554 protected AccountPersistence accountPersistence;
555 @BeanReference(type = AddressPersistence.class)
556 protected AddressPersistence addressPersistence;
557 @BeanReference(type = BrowserTrackerPersistence.class)
558 protected BrowserTrackerPersistence browserTrackerPersistence;
559 @BeanReference(type = ClassNamePersistence.class)
560 protected ClassNamePersistence classNamePersistence;
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 }