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