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