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 Session session = null;
156
157 try {
158 session = openSession();
159
160 if (release.isCachedModel() || BatchSessionUtil.isEnabled()) {
161 Object staleObject = session.get(ReleaseImpl.class,
162 release.getPrimaryKeyObj());
163
164 if (staleObject != null) {
165 session.evict(staleObject);
166 }
167 }
168
169 session.delete(release);
170
171 session.flush();
172 }
173 catch (Exception e) {
174 throw processException(e);
175 }
176 finally {
177 closeSession(session);
178 }
179
180 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
181
182 EntityCacheUtil.removeResult(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
183 ReleaseImpl.class, release.getPrimaryKey());
184
185 return release;
186 }
187
188
191 public Release update(Release release) throws SystemException {
192 if (_log.isWarnEnabled()) {
193 _log.warn(
194 "Using the deprecated update(Release release) method. Use update(Release release, boolean merge) instead.");
195 }
196
197 return update(release, false);
198 }
199
200
212 public Release update(Release release, boolean merge)
213 throws SystemException {
214 boolean isNew = release.isNew();
215
216 for (ModelListener<Release> listener : listeners) {
217 if (isNew) {
218 listener.onBeforeCreate(release);
219 }
220 else {
221 listener.onBeforeUpdate(release);
222 }
223 }
224
225 release = updateImpl(release, merge);
226
227 for (ModelListener<Release> listener : listeners) {
228 if (isNew) {
229 listener.onAfterCreate(release);
230 }
231 else {
232 listener.onAfterUpdate(release);
233 }
234 }
235
236 return release;
237 }
238
239 public Release updateImpl(com.liferay.portal.model.Release release,
240 boolean merge) throws SystemException {
241 Session session = null;
242
243 try {
244 session = openSession();
245
246 BatchSessionUtil.update(session, release, merge);
247
248 release.setNew(false);
249 }
250 catch (Exception e) {
251 throw processException(e);
252 }
253 finally {
254 closeSession(session);
255 }
256
257 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
258
259 EntityCacheUtil.putResult(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
260 ReleaseImpl.class, release.getPrimaryKey(), release);
261
262 return release;
263 }
264
265 public Release findByPrimaryKey(long releaseId)
266 throws NoSuchReleaseException, SystemException {
267 Release release = fetchByPrimaryKey(releaseId);
268
269 if (release == null) {
270 if (_log.isWarnEnabled()) {
271 _log.warn("No Release exists with the primary key " +
272 releaseId);
273 }
274
275 throw new NoSuchReleaseException(
276 "No Release exists with the primary key " + releaseId);
277 }
278
279 return release;
280 }
281
282 public Release fetchByPrimaryKey(long releaseId) throws SystemException {
283 Release release = (Release)EntityCacheUtil.getResult(ReleaseModelImpl.ENTITY_CACHE_ENABLED,
284 ReleaseImpl.class, releaseId, this);
285
286 if (release == null) {
287 Session session = null;
288
289 try {
290 session = openSession();
291
292 release = (Release)session.get(ReleaseImpl.class,
293 new Long(releaseId));
294 }
295 catch (Exception e) {
296 throw processException(e);
297 }
298 finally {
299 if (release != null) {
300 cacheResult(release);
301 }
302
303 closeSession(session);
304 }
305 }
306
307 return release;
308 }
309
310 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
311 throws SystemException {
312 Session session = null;
313
314 try {
315 session = openSession();
316
317 dynamicQuery.compile(session);
318
319 return dynamicQuery.list();
320 }
321 catch (Exception e) {
322 throw processException(e);
323 }
324 finally {
325 closeSession(session);
326 }
327 }
328
329 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
330 int start, int end) throws SystemException {
331 Session session = null;
332
333 try {
334 session = openSession();
335
336 dynamicQuery.setLimit(start, end);
337
338 dynamicQuery.compile(session);
339
340 return dynamicQuery.list();
341 }
342 catch (Exception e) {
343 throw processException(e);
344 }
345 finally {
346 closeSession(session);
347 }
348 }
349
350 public List<Release> findAll() throws SystemException {
351 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
352 }
353
354 public List<Release> findAll(int start, int end) throws SystemException {
355 return findAll(start, end, null);
356 }
357
358 public List<Release> findAll(int start, int end, OrderByComparator obc)
359 throws SystemException {
360 Object[] finderArgs = new Object[] {
361 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
362 };
363
364 List<Release> list = (List<Release>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
365 finderArgs, this);
366
367 if (list == null) {
368 Session session = null;
369
370 try {
371 session = openSession();
372
373 StringBuilder query = new StringBuilder();
374
375 query.append("SELECT release FROM Release release ");
376
377 if (obc != null) {
378 query.append("ORDER BY ");
379
380 String[] orderByFields = obc.getOrderByFields();
381
382 for (int i = 0; i < orderByFields.length; i++) {
383 query.append("release.");
384 query.append(orderByFields[i]);
385
386 if (obc.isAscending()) {
387 query.append(" ASC");
388 }
389 else {
390 query.append(" DESC");
391 }
392
393 if ((i + 1) < orderByFields.length) {
394 query.append(", ");
395 }
396 }
397 }
398
399 Query q = session.createQuery(query.toString());
400
401 if (obc == null) {
402 list = (List<Release>)QueryUtil.list(q, getDialect(),
403 start, end, false);
404
405 Collections.sort(list);
406 }
407 else {
408 list = (List<Release>)QueryUtil.list(q, getDialect(),
409 start, end);
410 }
411 }
412 catch (Exception e) {
413 throw processException(e);
414 }
415 finally {
416 if (list == null) {
417 list = new ArrayList<Release>();
418 }
419
420 cacheResult(list);
421
422 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
423
424 closeSession(session);
425 }
426 }
427
428 return list;
429 }
430
431 public void removeAll() throws SystemException {
432 for (Release release : findAll()) {
433 remove(release);
434 }
435 }
436
437 public int countAll() throws SystemException {
438 Object[] finderArgs = new Object[0];
439
440 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
441 finderArgs, this);
442
443 if (count == null) {
444 Session session = null;
445
446 try {
447 session = openSession();
448
449 Query q = session.createQuery(
450 "SELECT COUNT(release) FROM Release release");
451
452 count = (Long)q.uniqueResult();
453 }
454 catch (Exception e) {
455 throw processException(e);
456 }
457 finally {
458 if (count == null) {
459 count = Long.valueOf(0);
460 }
461
462 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
463 count);
464
465 closeSession(session);
466 }
467 }
468
469 return count.intValue();
470 }
471
472 public void afterPropertiesSet() {
473 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
474 com.liferay.portal.util.PropsUtil.get(
475 "value.object.listener.com.liferay.portal.model.Release")));
476
477 if (listenerClassNames.length > 0) {
478 try {
479 List<ModelListener<Release>> listenersList = new ArrayList<ModelListener<Release>>();
480
481 for (String listenerClassName : listenerClassNames) {
482 listenersList.add((ModelListener<Release>)Class.forName(
483 listenerClassName).newInstance());
484 }
485
486 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
487 }
488 catch (Exception e) {
489 _log.error(e);
490 }
491 }
492 }
493
494 @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
495 protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
496 @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
497 protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
498 @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence.impl")
499 protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
500 @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
501 protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
502 @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
503 protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
504 @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
505 protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
506 @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
507 protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
508 @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
509 protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
510 @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
511 protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
512 @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
513 protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
514 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
515 protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
516 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
517 protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
518 @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
519 protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
520 @BeanReference(name = "com.liferay.portal.service.persistence.LockPersistence.impl")
521 protected com.liferay.portal.service.persistence.LockPersistence lockPersistence;
522 @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
523 protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
524 @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
525 protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
526 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
527 protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
528 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
529 protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
530 @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
531 protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
532 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
533 protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
534 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
535 protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
536 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
537 protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
538 @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
539 protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
540 @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
541 protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
542 @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
543 protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
544 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
545 protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
546 @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
547 protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
548 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
549 protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
550 @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
551 protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
552 @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
553 protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
554 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
555 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
556 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence.impl")
557 protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
558 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
559 protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
560 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence.impl")
561 protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
562 @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
563 protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
564 @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
565 protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
566 @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence.impl")
567 protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
568 @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
569 protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
570 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
571 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
572 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
573 protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
574 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
575 protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
576 @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
577 protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
578 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
579 protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
580 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
581 protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
582 @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
583 protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
584 @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
585 protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
586 private static Log _log = LogFactoryUtil.getLog(ReleasePersistenceImpl.class);
587 }