001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchAccountException;
018 import com.liferay.portal.NoSuchModelException;
019 import com.liferay.portal.kernel.annotation.BeanReference;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderPath;
024 import com.liferay.portal.kernel.dao.orm.Query;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.model.Account;
036 import com.liferay.portal.model.ModelListener;
037 import com.liferay.portal.model.impl.AccountImpl;
038 import com.liferay.portal.model.impl.AccountModelImpl;
039 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
040
041 import java.io.Serializable;
042
043 import java.util.ArrayList;
044 import java.util.Collections;
045 import java.util.List;
046
047
053 public class AccountPersistenceImpl extends BasePersistenceImpl<Account>
054 implements AccountPersistence {
055 public static final String FINDER_CLASS_NAME_ENTITY = AccountImpl.class.getName();
056 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
057 ".List";
058 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(AccountModelImpl.ENTITY_CACHE_ENABLED,
059 AccountModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
060 "findAll", new String[0]);
061 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AccountModelImpl.ENTITY_CACHE_ENABLED,
062 AccountModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
063 "countAll", new String[0]);
064
065 public void cacheResult(Account account) {
066 EntityCacheUtil.putResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
067 AccountImpl.class, account.getPrimaryKey(), account);
068 }
069
070 public void cacheResult(List<Account> accounts) {
071 for (Account account : accounts) {
072 if (EntityCacheUtil.getResult(
073 AccountModelImpl.ENTITY_CACHE_ENABLED,
074 AccountImpl.class, account.getPrimaryKey(), this) == null) {
075 cacheResult(account);
076 }
077 }
078 }
079
080 public void clearCache() {
081 CacheRegistryUtil.clear(AccountImpl.class.getName());
082 EntityCacheUtil.clearCache(AccountImpl.class.getName());
083 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
084 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
085 }
086
087 public void clearCache(Account account) {
088 EntityCacheUtil.removeResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
089 AccountImpl.class, account.getPrimaryKey());
090 }
091
092 public Account create(long accountId) {
093 Account account = new AccountImpl();
094
095 account.setNew(true);
096 account.setPrimaryKey(accountId);
097
098 return account;
099 }
100
101 public Account remove(Serializable primaryKey)
102 throws NoSuchModelException, SystemException {
103 return remove(((Long)primaryKey).longValue());
104 }
105
106 public Account remove(long accountId)
107 throws NoSuchAccountException, SystemException {
108 Session session = null;
109
110 try {
111 session = openSession();
112
113 Account account = (Account)session.get(AccountImpl.class,
114 new Long(accountId));
115
116 if (account == null) {
117 if (_log.isWarnEnabled()) {
118 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + accountId);
119 }
120
121 throw new NoSuchAccountException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
122 accountId);
123 }
124
125 return remove(account);
126 }
127 catch (NoSuchAccountException nsee) {
128 throw nsee;
129 }
130 catch (Exception e) {
131 throw processException(e);
132 }
133 finally {
134 closeSession(session);
135 }
136 }
137
138 protected Account removeImpl(Account account) throws SystemException {
139 account = toUnwrappedModel(account);
140
141 Session session = null;
142
143 try {
144 session = openSession();
145
146 if (account.isCachedModel() || BatchSessionUtil.isEnabled()) {
147 Object staleObject = session.get(AccountImpl.class,
148 account.getPrimaryKeyObj());
149
150 if (staleObject != null) {
151 session.evict(staleObject);
152 }
153 }
154
155 session.delete(account);
156
157 session.flush();
158 }
159 catch (Exception e) {
160 throw processException(e);
161 }
162 finally {
163 closeSession(session);
164 }
165
166 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
167
168 EntityCacheUtil.removeResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
169 AccountImpl.class, account.getPrimaryKey());
170
171 return account;
172 }
173
174 public Account updateImpl(com.liferay.portal.model.Account account,
175 boolean merge) throws SystemException {
176 account = toUnwrappedModel(account);
177
178 Session session = null;
179
180 try {
181 session = openSession();
182
183 BatchSessionUtil.update(session, account, merge);
184
185 account.setNew(false);
186 }
187 catch (Exception e) {
188 throw processException(e);
189 }
190 finally {
191 closeSession(session);
192 }
193
194 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
195
196 EntityCacheUtil.putResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
197 AccountImpl.class, account.getPrimaryKey(), account);
198
199 return account;
200 }
201
202 protected Account toUnwrappedModel(Account account) {
203 if (account instanceof AccountImpl) {
204 return account;
205 }
206
207 AccountImpl accountImpl = new AccountImpl();
208
209 accountImpl.setNew(account.isNew());
210 accountImpl.setPrimaryKey(account.getPrimaryKey());
211
212 accountImpl.setAccountId(account.getAccountId());
213 accountImpl.setCompanyId(account.getCompanyId());
214 accountImpl.setUserId(account.getUserId());
215 accountImpl.setUserName(account.getUserName());
216 accountImpl.setCreateDate(account.getCreateDate());
217 accountImpl.setModifiedDate(account.getModifiedDate());
218 accountImpl.setParentAccountId(account.getParentAccountId());
219 accountImpl.setName(account.getName());
220 accountImpl.setLegalName(account.getLegalName());
221 accountImpl.setLegalId(account.getLegalId());
222 accountImpl.setLegalType(account.getLegalType());
223 accountImpl.setSicCode(account.getSicCode());
224 accountImpl.setTickerSymbol(account.getTickerSymbol());
225 accountImpl.setIndustry(account.getIndustry());
226 accountImpl.setType(account.getType());
227 accountImpl.setSize(account.getSize());
228
229 return accountImpl;
230 }
231
232 public Account findByPrimaryKey(Serializable primaryKey)
233 throws NoSuchModelException, SystemException {
234 return findByPrimaryKey(((Long)primaryKey).longValue());
235 }
236
237 public Account findByPrimaryKey(long accountId)
238 throws NoSuchAccountException, SystemException {
239 Account account = fetchByPrimaryKey(accountId);
240
241 if (account == null) {
242 if (_log.isWarnEnabled()) {
243 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + accountId);
244 }
245
246 throw new NoSuchAccountException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
247 accountId);
248 }
249
250 return account;
251 }
252
253 public Account fetchByPrimaryKey(Serializable primaryKey)
254 throws SystemException {
255 return fetchByPrimaryKey(((Long)primaryKey).longValue());
256 }
257
258 public Account fetchByPrimaryKey(long accountId) throws SystemException {
259 Account account = (Account)EntityCacheUtil.getResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
260 AccountImpl.class, accountId, this);
261
262 if (account == null) {
263 Session session = null;
264
265 try {
266 session = openSession();
267
268 account = (Account)session.get(AccountImpl.class,
269 new Long(accountId));
270 }
271 catch (Exception e) {
272 throw processException(e);
273 }
274 finally {
275 if (account != null) {
276 cacheResult(account);
277 }
278
279 closeSession(session);
280 }
281 }
282
283 return account;
284 }
285
286 public List<Account> findAll() throws SystemException {
287 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
288 }
289
290 public List<Account> findAll(int start, int end) throws SystemException {
291 return findAll(start, end, null);
292 }
293
294 public List<Account> findAll(int start, int end,
295 OrderByComparator orderByComparator) throws SystemException {
296 Object[] finderArgs = new Object[] {
297 String.valueOf(start), String.valueOf(end),
298 String.valueOf(orderByComparator)
299 };
300
301 List<Account> list = (List<Account>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
302 finderArgs, this);
303
304 if (list == null) {
305 Session session = null;
306
307 try {
308 session = openSession();
309
310 StringBundler query = null;
311 String sql = null;
312
313 if (orderByComparator != null) {
314 query = new StringBundler(2 +
315 (orderByComparator.getOrderByFields().length * 3));
316
317 query.append(_SQL_SELECT_ACCOUNT);
318
319 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
320 orderByComparator);
321
322 sql = query.toString();
323 }
324 else {
325 sql = _SQL_SELECT_ACCOUNT;
326 }
327
328 Query q = session.createQuery(sql);
329
330 if (orderByComparator == null) {
331 list = (List<Account>)QueryUtil.list(q, getDialect(),
332 start, end, false);
333
334 Collections.sort(list);
335 }
336 else {
337 list = (List<Account>)QueryUtil.list(q, getDialect(),
338 start, end);
339 }
340 }
341 catch (Exception e) {
342 throw processException(e);
343 }
344 finally {
345 if (list == null) {
346 list = new ArrayList<Account>();
347 }
348
349 cacheResult(list);
350
351 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
352
353 closeSession(session);
354 }
355 }
356
357 return list;
358 }
359
360 public void removeAll() throws SystemException {
361 for (Account account : findAll()) {
362 remove(account);
363 }
364 }
365
366 public int countAll() throws SystemException {
367 Object[] finderArgs = new Object[0];
368
369 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
370 finderArgs, this);
371
372 if (count == null) {
373 Session session = null;
374
375 try {
376 session = openSession();
377
378 Query q = session.createQuery(_SQL_COUNT_ACCOUNT);
379
380 count = (Long)q.uniqueResult();
381 }
382 catch (Exception e) {
383 throw processException(e);
384 }
385 finally {
386 if (count == null) {
387 count = Long.valueOf(0);
388 }
389
390 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
391 count);
392
393 closeSession(session);
394 }
395 }
396
397 return count.intValue();
398 }
399
400 public void afterPropertiesSet() {
401 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
402 com.liferay.portal.util.PropsUtil.get(
403 "value.object.listener.com.liferay.portal.model.Account")));
404
405 if (listenerClassNames.length > 0) {
406 try {
407 List<ModelListener<Account>> listenersList = new ArrayList<ModelListener<Account>>();
408
409 for (String listenerClassName : listenerClassNames) {
410 listenersList.add((ModelListener<Account>)InstanceFactory.newInstance(
411 listenerClassName));
412 }
413
414 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
415 }
416 catch (Exception e) {
417 _log.error(e);
418 }
419 }
420 }
421
422 @BeanReference(type = AccountPersistence.class)
423 protected AccountPersistence accountPersistence;
424 @BeanReference(type = AddressPersistence.class)
425 protected AddressPersistence addressPersistence;
426 @BeanReference(type = BrowserTrackerPersistence.class)
427 protected BrowserTrackerPersistence browserTrackerPersistence;
428 @BeanReference(type = ClassNamePersistence.class)
429 protected ClassNamePersistence classNamePersistence;
430 @BeanReference(type = CompanyPersistence.class)
431 protected CompanyPersistence companyPersistence;
432 @BeanReference(type = ContactPersistence.class)
433 protected ContactPersistence contactPersistence;
434 @BeanReference(type = CountryPersistence.class)
435 protected CountryPersistence countryPersistence;
436 @BeanReference(type = EmailAddressPersistence.class)
437 protected EmailAddressPersistence emailAddressPersistence;
438 @BeanReference(type = GroupPersistence.class)
439 protected GroupPersistence groupPersistence;
440 @BeanReference(type = ImagePersistence.class)
441 protected ImagePersistence imagePersistence;
442 @BeanReference(type = LayoutPersistence.class)
443 protected LayoutPersistence layoutPersistence;
444 @BeanReference(type = LayoutPrototypePersistence.class)
445 protected LayoutPrototypePersistence layoutPrototypePersistence;
446 @BeanReference(type = LayoutSetPersistence.class)
447 protected LayoutSetPersistence layoutSetPersistence;
448 @BeanReference(type = LayoutSetPrototypePersistence.class)
449 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
450 @BeanReference(type = ListTypePersistence.class)
451 protected ListTypePersistence listTypePersistence;
452 @BeanReference(type = LockPersistence.class)
453 protected LockPersistence lockPersistence;
454 @BeanReference(type = MembershipRequestPersistence.class)
455 protected MembershipRequestPersistence membershipRequestPersistence;
456 @BeanReference(type = OrganizationPersistence.class)
457 protected OrganizationPersistence organizationPersistence;
458 @BeanReference(type = OrgGroupPermissionPersistence.class)
459 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
460 @BeanReference(type = OrgGroupRolePersistence.class)
461 protected OrgGroupRolePersistence orgGroupRolePersistence;
462 @BeanReference(type = OrgLaborPersistence.class)
463 protected OrgLaborPersistence orgLaborPersistence;
464 @BeanReference(type = PasswordPolicyPersistence.class)
465 protected PasswordPolicyPersistence passwordPolicyPersistence;
466 @BeanReference(type = PasswordPolicyRelPersistence.class)
467 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
468 @BeanReference(type = PasswordTrackerPersistence.class)
469 protected PasswordTrackerPersistence passwordTrackerPersistence;
470 @BeanReference(type = PermissionPersistence.class)
471 protected PermissionPersistence permissionPersistence;
472 @BeanReference(type = PhonePersistence.class)
473 protected PhonePersistence phonePersistence;
474 @BeanReference(type = PluginSettingPersistence.class)
475 protected PluginSettingPersistence pluginSettingPersistence;
476 @BeanReference(type = PortletPersistence.class)
477 protected PortletPersistence portletPersistence;
478 @BeanReference(type = PortletItemPersistence.class)
479 protected PortletItemPersistence portletItemPersistence;
480 @BeanReference(type = PortletPreferencesPersistence.class)
481 protected PortletPreferencesPersistence portletPreferencesPersistence;
482 @BeanReference(type = RegionPersistence.class)
483 protected RegionPersistence regionPersistence;
484 @BeanReference(type = ReleasePersistence.class)
485 protected ReleasePersistence releasePersistence;
486 @BeanReference(type = ResourcePersistence.class)
487 protected ResourcePersistence resourcePersistence;
488 @BeanReference(type = ResourceActionPersistence.class)
489 protected ResourceActionPersistence resourceActionPersistence;
490 @BeanReference(type = ResourceCodePersistence.class)
491 protected ResourceCodePersistence resourceCodePersistence;
492 @BeanReference(type = ResourcePermissionPersistence.class)
493 protected ResourcePermissionPersistence resourcePermissionPersistence;
494 @BeanReference(type = RolePersistence.class)
495 protected RolePersistence rolePersistence;
496 @BeanReference(type = ServiceComponentPersistence.class)
497 protected ServiceComponentPersistence serviceComponentPersistence;
498 @BeanReference(type = ShardPersistence.class)
499 protected ShardPersistence shardPersistence;
500 @BeanReference(type = SubscriptionPersistence.class)
501 protected SubscriptionPersistence subscriptionPersistence;
502 @BeanReference(type = TicketPersistence.class)
503 protected TicketPersistence ticketPersistence;
504 @BeanReference(type = TeamPersistence.class)
505 protected TeamPersistence teamPersistence;
506 @BeanReference(type = UserPersistence.class)
507 protected UserPersistence userPersistence;
508 @BeanReference(type = UserGroupPersistence.class)
509 protected UserGroupPersistence userGroupPersistence;
510 @BeanReference(type = UserGroupGroupRolePersistence.class)
511 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
512 @BeanReference(type = UserGroupRolePersistence.class)
513 protected UserGroupRolePersistence userGroupRolePersistence;
514 @BeanReference(type = UserIdMapperPersistence.class)
515 protected UserIdMapperPersistence userIdMapperPersistence;
516 @BeanReference(type = UserTrackerPersistence.class)
517 protected UserTrackerPersistence userTrackerPersistence;
518 @BeanReference(type = UserTrackerPathPersistence.class)
519 protected UserTrackerPathPersistence userTrackerPathPersistence;
520 @BeanReference(type = WebDAVPropsPersistence.class)
521 protected WebDAVPropsPersistence webDAVPropsPersistence;
522 @BeanReference(type = WebsitePersistence.class)
523 protected WebsitePersistence websitePersistence;
524 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
525 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
526 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
527 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
528 private static final String _SQL_SELECT_ACCOUNT = "SELECT account FROM Account account";
529 private static final String _SQL_COUNT_ACCOUNT = "SELECT COUNT(account) FROM Account account";
530 private static final String _ORDER_BY_ENTITY_ALIAS = "account.";
531 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Account exists with the primary key ";
532 private static Log _log = LogFactoryUtil.getLog(AccountPersistenceImpl.class);
533 }