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 Session session = null;
156
157 try {
158 session = openSession();
159
160 if (account.isCachedModel() || BatchSessionUtil.isEnabled()) {
161 Object staleObject = session.get(AccountImpl.class,
162 account.getPrimaryKeyObj());
163
164 if (staleObject != null) {
165 session.evict(staleObject);
166 }
167 }
168
169 session.delete(account);
170
171 session.flush();
172 }
173 catch (Exception e) {
174 throw processException(e);
175 }
176 finally {
177 closeSession(session);
178 }
179
180 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
181
182 EntityCacheUtil.removeResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
183 AccountImpl.class, account.getPrimaryKey());
184
185 return account;
186 }
187
188
191 public Account update(Account account) throws SystemException {
192 if (_log.isWarnEnabled()) {
193 _log.warn(
194 "Using the deprecated update(Account account) method. Use update(Account account, boolean merge) instead.");
195 }
196
197 return update(account, false);
198 }
199
200
212 public Account update(Account account, boolean merge)
213 throws SystemException {
214 boolean isNew = account.isNew();
215
216 for (ModelListener<Account> listener : listeners) {
217 if (isNew) {
218 listener.onBeforeCreate(account);
219 }
220 else {
221 listener.onBeforeUpdate(account);
222 }
223 }
224
225 account = updateImpl(account, merge);
226
227 for (ModelListener<Account> listener : listeners) {
228 if (isNew) {
229 listener.onAfterCreate(account);
230 }
231 else {
232 listener.onAfterUpdate(account);
233 }
234 }
235
236 return account;
237 }
238
239 public Account updateImpl(com.liferay.portal.model.Account account,
240 boolean merge) throws SystemException {
241 Session session = null;
242
243 try {
244 session = openSession();
245
246 BatchSessionUtil.update(session, account, merge);
247
248 account.setNew(false);
249 }
250 catch (Exception e) {
251 throw processException(e);
252 }
253 finally {
254 closeSession(session);
255 }
256
257 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
258
259 EntityCacheUtil.putResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
260 AccountImpl.class, account.getPrimaryKey(), account);
261
262 return account;
263 }
264
265 public Account findByPrimaryKey(long accountId)
266 throws NoSuchAccountException, SystemException {
267 Account account = fetchByPrimaryKey(accountId);
268
269 if (account == null) {
270 if (_log.isWarnEnabled()) {
271 _log.warn("No Account exists with the primary key " +
272 accountId);
273 }
274
275 throw new NoSuchAccountException(
276 "No Account exists with the primary key " + accountId);
277 }
278
279 return account;
280 }
281
282 public Account fetchByPrimaryKey(long accountId) throws SystemException {
283 Account account = (Account)EntityCacheUtil.getResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
284 AccountImpl.class, accountId, this);
285
286 if (account == null) {
287 Session session = null;
288
289 try {
290 session = openSession();
291
292 account = (Account)session.get(AccountImpl.class,
293 new Long(accountId));
294 }
295 catch (Exception e) {
296 throw processException(e);
297 }
298 finally {
299 if (account != null) {
300 cacheResult(account);
301 }
302
303 closeSession(session);
304 }
305 }
306
307 return account;
308 }
309
310 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
311 throws SystemException {
312 Session session = null;
313
314 try {
315 session = openSession();
316
317 dynamicQuery.compile(session);
318
319 return dynamicQuery.list();
320 }
321 catch (Exception e) {
322 throw processException(e);
323 }
324 finally {
325 closeSession(session);
326 }
327 }
328
329 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
330 int start, int end) throws SystemException {
331 Session session = null;
332
333 try {
334 session = openSession();
335
336 dynamicQuery.setLimit(start, end);
337
338 dynamicQuery.compile(session);
339
340 return dynamicQuery.list();
341 }
342 catch (Exception e) {
343 throw processException(e);
344 }
345 finally {
346 closeSession(session);
347 }
348 }
349
350 public List<Account> findAll() throws SystemException {
351 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
352 }
353
354 public List<Account> findAll(int start, int end) throws SystemException {
355 return findAll(start, end, null);
356 }
357
358 public List<Account> findAll(int start, int end, OrderByComparator obc)
359 throws SystemException {
360 Object[] finderArgs = new Object[] {
361 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
362 };
363
364 List<Account> list = (List<Account>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
365 finderArgs, this);
366
367 if (list == null) {
368 Session session = null;
369
370 try {
371 session = openSession();
372
373 StringBuilder query = new StringBuilder();
374
375 query.append("SELECT account FROM Account account ");
376
377 if (obc != null) {
378 query.append("ORDER BY ");
379
380 String[] orderByFields = obc.getOrderByFields();
381
382 for (int i = 0; i < orderByFields.length; i++) {
383 query.append("account.");
384 query.append(orderByFields[i]);
385
386 if (obc.isAscending()) {
387 query.append(" ASC");
388 }
389 else {
390 query.append(" DESC");
391 }
392
393 if ((i + 1) < orderByFields.length) {
394 query.append(", ");
395 }
396 }
397 }
398
399 Query q = session.createQuery(query.toString());
400
401 if (obc == null) {
402 list = (List<Account>)QueryUtil.list(q, getDialect(),
403 start, end, false);
404
405 Collections.sort(list);
406 }
407 else {
408 list = (List<Account>)QueryUtil.list(q, getDialect(),
409 start, end);
410 }
411 }
412 catch (Exception e) {
413 throw processException(e);
414 }
415 finally {
416 if (list == null) {
417 list = new ArrayList<Account>();
418 }
419
420 cacheResult(list);
421
422 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
423
424 closeSession(session);
425 }
426 }
427
428 return list;
429 }
430
431 public void removeAll() throws SystemException {
432 for (Account account : findAll()) {
433 remove(account);
434 }
435 }
436
437 public int countAll() throws SystemException {
438 Object[] finderArgs = new Object[0];
439
440 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
441 finderArgs, this);
442
443 if (count == null) {
444 Session session = null;
445
446 try {
447 session = openSession();
448
449 Query q = session.createQuery(
450 "SELECT COUNT(account) FROM Account account");
451
452 count = (Long)q.uniqueResult();
453 }
454 catch (Exception e) {
455 throw processException(e);
456 }
457 finally {
458 if (count == null) {
459 count = Long.valueOf(0);
460 }
461
462 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
463 count);
464
465 closeSession(session);
466 }
467 }
468
469 return count.intValue();
470 }
471
472 public void afterPropertiesSet() {
473 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
474 com.liferay.portal.util.PropsUtil.get(
475 "value.object.listener.com.liferay.portal.model.Account")));
476
477 if (listenerClassNames.length > 0) {
478 try {
479 List<ModelListener<Account>> listenersList = new ArrayList<ModelListener<Account>>();
480
481 for (String listenerClassName : listenerClassNames) {
482 listenersList.add((ModelListener<Account>)Class.forName(
483 listenerClassName).newInstance());
484 }
485
486 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
487 }
488 catch (Exception e) {
489 _log.error(e);
490 }
491 }
492 }
493
494 @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
495 protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
496 @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
497 protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
498 @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence.impl")
499 protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
500 @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
501 protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
502 @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
503 protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
504 @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
505 protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
506 @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
507 protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
508 @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
509 protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
510 @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
511 protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
512 @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
513 protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
514 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
515 protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
516 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
517 protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
518 @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
519 protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
520 @BeanReference(name = "com.liferay.portal.service.persistence.LockPersistence.impl")
521 protected com.liferay.portal.service.persistence.LockPersistence lockPersistence;
522 @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
523 protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
524 @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
525 protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
526 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
527 protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
528 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
529 protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
530 @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
531 protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
532 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
533 protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
534 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
535 protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
536 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
537 protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
538 @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
539 protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
540 @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
541 protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
542 @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
543 protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
544 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
545 protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
546 @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
547 protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
548 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
549 protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
550 @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
551 protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
552 @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
553 protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
554 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
555 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
556 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence.impl")
557 protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
558 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
559 protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
560 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence.impl")
561 protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
562 @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
563 protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
564 @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
565 protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
566 @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence.impl")
567 protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
568 @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
569 protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
570 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
571 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
572 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
573 protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
574 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
575 protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
576 @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
577 protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
578 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
579 protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
580 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
581 protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
582 @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
583 protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
584 @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
585 protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
586 private static Log _log = LogFactoryUtil.getLog(AccountPersistenceImpl.class);
587 }