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