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