1
14
15 package com.liferay.portal.service.persistence;
16
17 import com.liferay.portal.NoSuchAccountException;
18 import com.liferay.portal.NoSuchModelException;
19 import com.liferay.portal.SystemException;
20 import com.liferay.portal.kernel.annotation.BeanReference;
21 import com.liferay.portal.kernel.cache.CacheRegistry;
22 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
23 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
24 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
25 import com.liferay.portal.kernel.dao.orm.FinderPath;
26 import com.liferay.portal.kernel.dao.orm.Query;
27 import com.liferay.portal.kernel.dao.orm.QueryUtil;
28 import com.liferay.portal.kernel.dao.orm.Session;
29 import com.liferay.portal.kernel.log.Log;
30 import com.liferay.portal.kernel.log.LogFactoryUtil;
31 import com.liferay.portal.kernel.util.GetterUtil;
32 import com.liferay.portal.kernel.util.OrderByComparator;
33 import com.liferay.portal.kernel.util.StringBundler;
34 import com.liferay.portal.kernel.util.StringUtil;
35 import com.liferay.portal.model.Account;
36 import com.liferay.portal.model.ModelListener;
37 import com.liferay.portal.model.impl.AccountImpl;
38 import com.liferay.portal.model.impl.AccountModelImpl;
39 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
40
41 import java.io.Serializable;
42
43 import java.util.ArrayList;
44 import java.util.Collections;
45 import java.util.List;
46
47
60 public class AccountPersistenceImpl extends BasePersistenceImpl<Account>
61 implements AccountPersistence {
62 public static final String FINDER_CLASS_NAME_ENTITY = AccountImpl.class.getName();
63 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
64 ".List";
65 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(AccountModelImpl.ENTITY_CACHE_ENABLED,
66 AccountModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
67 "findAll", new String[0]);
68 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AccountModelImpl.ENTITY_CACHE_ENABLED,
69 AccountModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
70 "countAll", new String[0]);
71
72 public void cacheResult(Account account) {
73 EntityCacheUtil.putResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
74 AccountImpl.class, account.getPrimaryKey(), account);
75 }
76
77 public void cacheResult(List<Account> accounts) {
78 for (Account account : accounts) {
79 if (EntityCacheUtil.getResult(
80 AccountModelImpl.ENTITY_CACHE_ENABLED,
81 AccountImpl.class, account.getPrimaryKey(), this) == null) {
82 cacheResult(account);
83 }
84 }
85 }
86
87 public void clearCache() {
88 CacheRegistry.clear(AccountImpl.class.getName());
89 EntityCacheUtil.clearCache(AccountImpl.class.getName());
90 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
91 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
92 }
93
94 public Account create(long accountId) {
95 Account account = new AccountImpl();
96
97 account.setNew(true);
98 account.setPrimaryKey(accountId);
99
100 return account;
101 }
102
103 public Account remove(Serializable primaryKey)
104 throws NoSuchModelException, SystemException {
105 return remove(((Long)primaryKey).longValue());
106 }
107
108 public Account remove(long accountId)
109 throws NoSuchAccountException, SystemException {
110 Session session = null;
111
112 try {
113 session = openSession();
114
115 Account account = (Account)session.get(AccountImpl.class,
116 new Long(accountId));
117
118 if (account == null) {
119 if (_log.isWarnEnabled()) {
120 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + accountId);
121 }
122
123 throw new NoSuchAccountException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
124 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 public Account updateImpl(com.liferay.portal.model.Account account,
203 boolean merge) throws SystemException {
204 account = toUnwrappedModel(account);
205
206 Session session = null;
207
208 try {
209 session = openSession();
210
211 BatchSessionUtil.update(session, account, merge);
212
213 account.setNew(false);
214 }
215 catch (Exception e) {
216 throw processException(e);
217 }
218 finally {
219 closeSession(session);
220 }
221
222 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
223
224 EntityCacheUtil.putResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
225 AccountImpl.class, account.getPrimaryKey(), account);
226
227 return account;
228 }
229
230 protected Account toUnwrappedModel(Account account) {
231 if (account instanceof AccountImpl) {
232 return account;
233 }
234
235 AccountImpl accountImpl = new AccountImpl();
236
237 accountImpl.setNew(account.isNew());
238 accountImpl.setPrimaryKey(account.getPrimaryKey());
239
240 accountImpl.setAccountId(account.getAccountId());
241 accountImpl.setCompanyId(account.getCompanyId());
242 accountImpl.setUserId(account.getUserId());
243 accountImpl.setUserName(account.getUserName());
244 accountImpl.setCreateDate(account.getCreateDate());
245 accountImpl.setModifiedDate(account.getModifiedDate());
246 accountImpl.setParentAccountId(account.getParentAccountId());
247 accountImpl.setName(account.getName());
248 accountImpl.setLegalName(account.getLegalName());
249 accountImpl.setLegalId(account.getLegalId());
250 accountImpl.setLegalType(account.getLegalType());
251 accountImpl.setSicCode(account.getSicCode());
252 accountImpl.setTickerSymbol(account.getTickerSymbol());
253 accountImpl.setIndustry(account.getIndustry());
254 accountImpl.setType(account.getType());
255 accountImpl.setSize(account.getSize());
256
257 return accountImpl;
258 }
259
260 public Account findByPrimaryKey(Serializable primaryKey)
261 throws NoSuchModelException, SystemException {
262 return findByPrimaryKey(((Long)primaryKey).longValue());
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_SUCH_ENTITY_WITH_PRIMARY_KEY + accountId);
272 }
273
274 throw new NoSuchAccountException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
275 accountId);
276 }
277
278 return account;
279 }
280
281 public Account fetchByPrimaryKey(Serializable primaryKey)
282 throws SystemException {
283 return fetchByPrimaryKey(((Long)primaryKey).longValue());
284 }
285
286 public Account fetchByPrimaryKey(long accountId) throws SystemException {
287 Account account = (Account)EntityCacheUtil.getResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
288 AccountImpl.class, accountId, this);
289
290 if (account == null) {
291 Session session = null;
292
293 try {
294 session = openSession();
295
296 account = (Account)session.get(AccountImpl.class,
297 new Long(accountId));
298 }
299 catch (Exception e) {
300 throw processException(e);
301 }
302 finally {
303 if (account != null) {
304 cacheResult(account);
305 }
306
307 closeSession(session);
308 }
309 }
310
311 return account;
312 }
313
314 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
315 throws SystemException {
316 Session session = null;
317
318 try {
319 session = openSession();
320
321 dynamicQuery.compile(session);
322
323 return dynamicQuery.list();
324 }
325 catch (Exception e) {
326 throw processException(e);
327 }
328 finally {
329 closeSession(session);
330 }
331 }
332
333 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
334 int start, int end) throws SystemException {
335 Session session = null;
336
337 try {
338 session = openSession();
339
340 dynamicQuery.setLimit(start, end);
341
342 dynamicQuery.compile(session);
343
344 return dynamicQuery.list();
345 }
346 catch (Exception e) {
347 throw processException(e);
348 }
349 finally {
350 closeSession(session);
351 }
352 }
353
354 public List<Account> findAll() throws SystemException {
355 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
356 }
357
358 public List<Account> findAll(int start, int end) throws SystemException {
359 return findAll(start, end, null);
360 }
361
362 public List<Account> findAll(int start, int end, OrderByComparator obc)
363 throws SystemException {
364 Object[] finderArgs = new Object[] {
365 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
366 };
367
368 List<Account> list = (List<Account>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
369 finderArgs, this);
370
371 if (list == null) {
372 Session session = null;
373
374 try {
375 session = openSession();
376
377 StringBundler query = null;
378 String sql = null;
379
380 if (obc != null) {
381 query = new StringBundler(2 +
382 (obc.getOrderByFields().length * 3));
383
384 query.append(_SQL_SELECT_ACCOUNT);
385
386 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
387
388 sql = query.toString();
389 }
390
391 sql = _SQL_SELECT_ACCOUNT;
392
393 Query q = session.createQuery(sql);
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(_SQL_COUNT_ACCOUNT);
444
445 count = (Long)q.uniqueResult();
446 }
447 catch (Exception e) {
448 throw processException(e);
449 }
450 finally {
451 if (count == null) {
452 count = Long.valueOf(0);
453 }
454
455 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
456 count);
457
458 closeSession(session);
459 }
460 }
461
462 return count.intValue();
463 }
464
465 public void afterPropertiesSet() {
466 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
467 com.liferay.portal.util.PropsUtil.get(
468 "value.object.listener.com.liferay.portal.model.Account")));
469
470 if (listenerClassNames.length > 0) {
471 try {
472 List<ModelListener<Account>> listenersList = new ArrayList<ModelListener<Account>>();
473
474 for (String listenerClassName : listenerClassNames) {
475 listenersList.add((ModelListener<Account>)Class.forName(
476 listenerClassName).newInstance());
477 }
478
479 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
480 }
481 catch (Exception e) {
482 _log.error(e);
483 }
484 }
485 }
486
487 @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence")
488 protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
489 @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence")
490 protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
491 @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence")
492 protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
493 @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence")
494 protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
495 @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence")
496 protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
497 @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence")
498 protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
499 @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence")
500 protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
501 @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence")
502 protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
503 @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence")
504 protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
505 @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence")
506 protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
507 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence")
508 protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
509 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence")
510 protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
511 @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence")
512 protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
513 @BeanReference(name = "com.liferay.portal.service.persistence.LockPersistence")
514 protected com.liferay.portal.service.persistence.LockPersistence lockPersistence;
515 @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence")
516 protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
517 @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence")
518 protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
519 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence")
520 protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
521 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence")
522 protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
523 @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence")
524 protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
525 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence")
526 protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
527 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence")
528 protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
529 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence")
530 protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
531 @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence")
532 protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
533 @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence")
534 protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
535 @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence")
536 protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
537 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence")
538 protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
539 @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence")
540 protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
541 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence")
542 protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
543 @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence")
544 protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
545 @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence")
546 protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
547 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence")
548 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
549 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence")
550 protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
551 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence")
552 protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
553 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence")
554 protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
555 @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence")
556 protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
557 @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence")
558 protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
559 @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence")
560 protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
561 @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence")
562 protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
563 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence")
564 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
565 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence")
566 protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
567 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence")
568 protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
569 @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence")
570 protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
571 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence")
572 protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
573 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence")
574 protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
575 @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence")
576 protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
577 @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence")
578 protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
579 private static final String _SQL_SELECT_ACCOUNT = "SELECT account FROM Account account";
580 private static final String _SQL_COUNT_ACCOUNT = "SELECT COUNT(account) FROM Account account";
581 private static final String _ORDER_BY_ENTITY_ALIAS = "account.";
582 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Account exists with the primary key ";
583 private static Log _log = LogFactoryUtil.getLog(AccountPersistenceImpl.class);
584 }