1
22
23 package com.liferay.portal.service.persistence;
24
25 import com.liferay.portal.NoSuchAccountException;
26 import com.liferay.portal.SystemException;
27 import com.liferay.portal.kernel.annotation.BeanReference;
28 import com.liferay.portal.kernel.cache.CacheRegistry;
29 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
30 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
31 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
32 import com.liferay.portal.kernel.dao.orm.FinderPath;
33 import com.liferay.portal.kernel.dao.orm.Query;
34 import com.liferay.portal.kernel.dao.orm.QueryUtil;
35 import com.liferay.portal.kernel.dao.orm.Session;
36 import com.liferay.portal.kernel.log.Log;
37 import com.liferay.portal.kernel.log.LogFactoryUtil;
38 import com.liferay.portal.kernel.util.GetterUtil;
39 import com.liferay.portal.kernel.util.OrderByComparator;
40 import com.liferay.portal.kernel.util.StringUtil;
41 import com.liferay.portal.model.Account;
42 import com.liferay.portal.model.ModelListener;
43 import com.liferay.portal.model.impl.AccountImpl;
44 import com.liferay.portal.model.impl.AccountModelImpl;
45 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
46
47 import java.util.ArrayList;
48 import java.util.Collections;
49 import java.util.List;
50
51
64 public class AccountPersistenceImpl extends BasePersistenceImpl
65 implements AccountPersistence {
66 public static final String FINDER_CLASS_NAME_ENTITY = AccountImpl.class.getName();
67 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
68 ".List";
69 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(AccountModelImpl.ENTITY_CACHE_ENABLED,
70 AccountModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
71 "findAll", new String[0]);
72 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AccountModelImpl.ENTITY_CACHE_ENABLED,
73 AccountModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
74 "countAll", new String[0]);
75
76 public void cacheResult(Account account) {
77 EntityCacheUtil.putResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
78 AccountImpl.class, account.getPrimaryKey(), account);
79 }
80
81 public void cacheResult(List<Account> accounts) {
82 for (Account account : accounts) {
83 if (EntityCacheUtil.getResult(
84 AccountModelImpl.ENTITY_CACHE_ENABLED,
85 AccountImpl.class, account.getPrimaryKey(), this) == null) {
86 cacheResult(account);
87 }
88 }
89 }
90
91 public void clearCache() {
92 CacheRegistry.clear(AccountImpl.class.getName());
93 EntityCacheUtil.clearCache(AccountImpl.class.getName());
94 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
95 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
96 }
97
98 public Account create(long accountId) {
99 Account account = new AccountImpl();
100
101 account.setNew(true);
102 account.setPrimaryKey(accountId);
103
104 return account;
105 }
106
107 public Account remove(long accountId)
108 throws NoSuchAccountException, SystemException {
109 Session session = null;
110
111 try {
112 session = openSession();
113
114 Account account = (Account)session.get(AccountImpl.class,
115 new Long(accountId));
116
117 if (account == null) {
118 if (_log.isWarnEnabled()) {
119 _log.warn("No Account exists with the primary key " +
120 accountId);
121 }
122
123 throw new NoSuchAccountException(
124 "No Account exists with the primary key " + accountId);
125 }
126
127 return remove(account);
128 }
129 catch (NoSuchAccountException nsee) {
130 throw nsee;
131 }
132 catch (Exception e) {
133 throw processException(e);
134 }
135 finally {
136 closeSession(session);
137 }
138 }
139
140 public Account remove(Account account) throws SystemException {
141 for (ModelListener<Account> listener : listeners) {
142 listener.onBeforeRemove(account);
143 }
144
145 account = removeImpl(account);
146
147 for (ModelListener<Account> listener : listeners) {
148 listener.onAfterRemove(account);
149 }
150
151 return account;
152 }
153
154 protected Account removeImpl(Account account) throws SystemException {
155 account = toUnwrappedModel(account);
156
157 Session session = null;
158
159 try {
160 session = openSession();
161
162 if (account.isCachedModel() || BatchSessionUtil.isEnabled()) {
163 Object staleObject = session.get(AccountImpl.class,
164 account.getPrimaryKeyObj());
165
166 if (staleObject != null) {
167 session.evict(staleObject);
168 }
169 }
170
171 session.delete(account);
172
173 session.flush();
174 }
175 catch (Exception e) {
176 throw processException(e);
177 }
178 finally {
179 closeSession(session);
180 }
181
182 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
183
184 EntityCacheUtil.removeResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
185 AccountImpl.class, account.getPrimaryKey());
186
187 return account;
188 }
189
190
193 public Account update(Account account) throws SystemException {
194 if (_log.isWarnEnabled()) {
195 _log.warn(
196 "Using the deprecated update(Account account) method. Use update(Account account, boolean merge) instead.");
197 }
198
199 return update(account, false);
200 }
201
202
214 public Account update(Account account, boolean merge)
215 throws SystemException {
216 boolean isNew = account.isNew();
217
218 for (ModelListener<Account> listener : listeners) {
219 if (isNew) {
220 listener.onBeforeCreate(account);
221 }
222 else {
223 listener.onBeforeUpdate(account);
224 }
225 }
226
227 account = updateImpl(account, merge);
228
229 for (ModelListener<Account> listener : listeners) {
230 if (isNew) {
231 listener.onAfterCreate(account);
232 }
233 else {
234 listener.onAfterUpdate(account);
235 }
236 }
237
238 return account;
239 }
240
241 public Account updateImpl(com.liferay.portal.model.Account account,
242 boolean merge) throws SystemException {
243 account = toUnwrappedModel(account);
244
245 Session session = null;
246
247 try {
248 session = openSession();
249
250 BatchSessionUtil.update(session, account, merge);
251
252 account.setNew(false);
253 }
254 catch (Exception e) {
255 throw processException(e);
256 }
257 finally {
258 closeSession(session);
259 }
260
261 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
262
263 EntityCacheUtil.putResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
264 AccountImpl.class, account.getPrimaryKey(), account);
265
266 return account;
267 }
268
269 protected Account toUnwrappedModel(Account account) {
270 if (account instanceof AccountImpl) {
271 return account;
272 }
273
274 AccountImpl accountImpl = new AccountImpl();
275
276 accountImpl.setNew(account.isNew());
277 accountImpl.setPrimaryKey(account.getPrimaryKey());
278
279 accountImpl.setAccountId(account.getAccountId());
280 accountImpl.setCompanyId(account.getCompanyId());
281 accountImpl.setUserId(account.getUserId());
282 accountImpl.setUserName(account.getUserName());
283 accountImpl.setCreateDate(account.getCreateDate());
284 accountImpl.setModifiedDate(account.getModifiedDate());
285 accountImpl.setParentAccountId(account.getParentAccountId());
286 accountImpl.setName(account.getName());
287 accountImpl.setLegalName(account.getLegalName());
288 accountImpl.setLegalId(account.getLegalId());
289 accountImpl.setLegalType(account.getLegalType());
290 accountImpl.setSicCode(account.getSicCode());
291 accountImpl.setTickerSymbol(account.getTickerSymbol());
292 accountImpl.setIndustry(account.getIndustry());
293 accountImpl.setType(account.getType());
294 accountImpl.setSize(account.getSize());
295
296 return accountImpl;
297 }
298
299 public Account findByPrimaryKey(long accountId)
300 throws NoSuchAccountException, SystemException {
301 Account account = fetchByPrimaryKey(accountId);
302
303 if (account == null) {
304 if (_log.isWarnEnabled()) {
305 _log.warn("No Account exists with the primary key " +
306 accountId);
307 }
308
309 throw new NoSuchAccountException(
310 "No Account exists with the primary key " + accountId);
311 }
312
313 return account;
314 }
315
316 public Account fetchByPrimaryKey(long accountId) throws SystemException {
317 Account account = (Account)EntityCacheUtil.getResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
318 AccountImpl.class, accountId, this);
319
320 if (account == null) {
321 Session session = null;
322
323 try {
324 session = openSession();
325
326 account = (Account)session.get(AccountImpl.class,
327 new Long(accountId));
328 }
329 catch (Exception e) {
330 throw processException(e);
331 }
332 finally {
333 if (account != null) {
334 cacheResult(account);
335 }
336
337 closeSession(session);
338 }
339 }
340
341 return account;
342 }
343
344 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
345 throws SystemException {
346 Session session = null;
347
348 try {
349 session = openSession();
350
351 dynamicQuery.compile(session);
352
353 return dynamicQuery.list();
354 }
355 catch (Exception e) {
356 throw processException(e);
357 }
358 finally {
359 closeSession(session);
360 }
361 }
362
363 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
364 int start, int end) throws SystemException {
365 Session session = null;
366
367 try {
368 session = openSession();
369
370 dynamicQuery.setLimit(start, end);
371
372 dynamicQuery.compile(session);
373
374 return dynamicQuery.list();
375 }
376 catch (Exception e) {
377 throw processException(e);
378 }
379 finally {
380 closeSession(session);
381 }
382 }
383
384 public List<Account> findAll() throws SystemException {
385 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
386 }
387
388 public List<Account> findAll(int start, int end) throws SystemException {
389 return findAll(start, end, null);
390 }
391
392 public List<Account> findAll(int start, int end, OrderByComparator obc)
393 throws SystemException {
394 Object[] finderArgs = new Object[] {
395 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
396 };
397
398 List<Account> list = (List<Account>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
399 finderArgs, this);
400
401 if (list == null) {
402 Session session = null;
403
404 try {
405 session = openSession();
406
407 StringBuilder query = new StringBuilder();
408
409 query.append("SELECT account FROM Account account ");
410
411 if (obc != null) {
412 query.append("ORDER BY ");
413
414 String[] orderByFields = obc.getOrderByFields();
415
416 for (int i = 0; i < orderByFields.length; i++) {
417 query.append("account.");
418 query.append(orderByFields[i]);
419
420 if (obc.isAscending()) {
421 query.append(" ASC");
422 }
423 else {
424 query.append(" DESC");
425 }
426
427 if ((i + 1) < orderByFields.length) {
428 query.append(", ");
429 }
430 }
431 }
432
433 Query q = session.createQuery(query.toString());
434
435 if (obc == null) {
436 list = (List<Account>)QueryUtil.list(q, getDialect(),
437 start, end, false);
438
439 Collections.sort(list);
440 }
441 else {
442 list = (List<Account>)QueryUtil.list(q, getDialect(),
443 start, end);
444 }
445 }
446 catch (Exception e) {
447 throw processException(e);
448 }
449 finally {
450 if (list == null) {
451 list = new ArrayList<Account>();
452 }
453
454 cacheResult(list);
455
456 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
457
458 closeSession(session);
459 }
460 }
461
462 return list;
463 }
464
465 public void removeAll() throws SystemException {
466 for (Account account : findAll()) {
467 remove(account);
468 }
469 }
470
471 public int countAll() throws SystemException {
472 Object[] finderArgs = new Object[0];
473
474 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
475 finderArgs, this);
476
477 if (count == null) {
478 Session session = null;
479
480 try {
481 session = openSession();
482
483 Query q = session.createQuery(
484 "SELECT COUNT(account) FROM Account account");
485
486 count = (Long)q.uniqueResult();
487 }
488 catch (Exception e) {
489 throw processException(e);
490 }
491 finally {
492 if (count == null) {
493 count = Long.valueOf(0);
494 }
495
496 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
497 count);
498
499 closeSession(session);
500 }
501 }
502
503 return count.intValue();
504 }
505
506 public void afterPropertiesSet() {
507 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
508 com.liferay.portal.util.PropsUtil.get(
509 "value.object.listener.com.liferay.portal.model.Account")));
510
511 if (listenerClassNames.length > 0) {
512 try {
513 List<ModelListener<Account>> listenersList = new ArrayList<ModelListener<Account>>();
514
515 for (String listenerClassName : listenerClassNames) {
516 listenersList.add((ModelListener<Account>)Class.forName(
517 listenerClassName).newInstance());
518 }
519
520 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
521 }
522 catch (Exception e) {
523 _log.error(e);
524 }
525 }
526 }
527
528 @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
529 protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
530 @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
531 protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
532 @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence.impl")
533 protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
534 @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
535 protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
536 @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
537 protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
538 @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
539 protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
540 @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
541 protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
542 @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
543 protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
544 @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
545 protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
546 @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
547 protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
548 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
549 protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
550 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
551 protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
552 @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
553 protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
554 @BeanReference(name = "com.liferay.portal.service.persistence.LockPersistence.impl")
555 protected com.liferay.portal.service.persistence.LockPersistence lockPersistence;
556 @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
557 protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
558 @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
559 protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
560 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
561 protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
562 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
563 protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
564 @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
565 protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
566 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
567 protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
568 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
569 protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
570 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
571 protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
572 @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
573 protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
574 @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
575 protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
576 @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
577 protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
578 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
579 protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
580 @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
581 protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
582 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
583 protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
584 @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
585 protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
586 @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
587 protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
588 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
589 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
590 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence.impl")
591 protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
592 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
593 protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
594 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence.impl")
595 protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
596 @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
597 protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
598 @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
599 protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
600 @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence.impl")
601 protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
602 @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
603 protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
604 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
605 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
606 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
607 protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
608 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupGroupRolePersistence.impl")
609 protected com.liferay.portal.service.persistence.UserGroupGroupRolePersistence userGroupGroupRolePersistence;
610 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
611 protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
612 @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
613 protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
614 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
615 protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
616 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
617 protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
618 @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
619 protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
620 @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
621 protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
622 private static Log _log = LogFactoryUtil.getLog(AccountPersistenceImpl.class);
623 }