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