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