1
22
23 package com.liferay.portal.service.persistence;
24
25 import com.liferay.portal.NoSuchClassNameException;
26 import com.liferay.portal.SystemException;
27 import com.liferay.portal.kernel.annotation.BeanReference;
28 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
29 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
30 import com.liferay.portal.kernel.dao.orm.Query;
31 import com.liferay.portal.kernel.dao.orm.QueryPos;
32 import com.liferay.portal.kernel.dao.orm.QueryUtil;
33 import com.liferay.portal.kernel.dao.orm.Session;
34 import com.liferay.portal.kernel.log.Log;
35 import com.liferay.portal.kernel.log.LogFactoryUtil;
36 import com.liferay.portal.kernel.util.GetterUtil;
37 import com.liferay.portal.kernel.util.OrderByComparator;
38 import com.liferay.portal.kernel.util.StringPool;
39 import com.liferay.portal.kernel.util.StringUtil;
40 import com.liferay.portal.model.ClassName;
41 import com.liferay.portal.model.ModelListener;
42 import com.liferay.portal.model.impl.ClassNameImpl;
43 import com.liferay.portal.model.impl.ClassNameModelImpl;
44 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
45
46 import java.util.ArrayList;
47 import java.util.Collections;
48 import java.util.Iterator;
49 import java.util.List;
50
51
57 public class ClassNamePersistenceImpl extends BasePersistenceImpl
58 implements ClassNamePersistence {
59 public ClassName create(long classNameId) {
60 ClassName className = new ClassNameImpl();
61
62 className.setNew(true);
63 className.setPrimaryKey(classNameId);
64
65 return className;
66 }
67
68 public ClassName remove(long classNameId)
69 throws NoSuchClassNameException, SystemException {
70 Session session = null;
71
72 try {
73 session = openSession();
74
75 ClassName className = (ClassName)session.get(ClassNameImpl.class,
76 new Long(classNameId));
77
78 if (className == null) {
79 if (_log.isWarnEnabled()) {
80 _log.warn("No ClassName exists with the primary key " +
81 classNameId);
82 }
83
84 throw new NoSuchClassNameException(
85 "No ClassName exists with the primary key " + classNameId);
86 }
87
88 return remove(className);
89 }
90 catch (NoSuchClassNameException nsee) {
91 throw nsee;
92 }
93 catch (Exception e) {
94 throw processException(e);
95 }
96 finally {
97 closeSession(session);
98 }
99 }
100
101 public ClassName remove(ClassName className) throws SystemException {
102 for (ModelListener listener : listeners) {
103 listener.onBeforeRemove(className);
104 }
105
106 className = removeImpl(className);
107
108 for (ModelListener listener : listeners) {
109 listener.onAfterRemove(className);
110 }
111
112 return className;
113 }
114
115 protected ClassName removeImpl(ClassName className)
116 throws SystemException {
117 Session session = null;
118
119 try {
120 session = openSession();
121
122 if (BatchSessionUtil.isEnabled()) {
123 Object staleObject = session.get(ClassNameImpl.class,
124 className.getPrimaryKeyObj());
125
126 if (staleObject != null) {
127 session.evict(staleObject);
128 }
129 }
130
131 session.delete(className);
132
133 session.flush();
134
135 return className;
136 }
137 catch (Exception e) {
138 throw processException(e);
139 }
140 finally {
141 closeSession(session);
142
143 FinderCacheUtil.clearCache(ClassName.class.getName());
144 }
145 }
146
147
150 public ClassName update(ClassName className) throws SystemException {
151 if (_log.isWarnEnabled()) {
152 _log.warn(
153 "Using the deprecated update(ClassName className) method. Use update(ClassName className, boolean merge) instead.");
154 }
155
156 return update(className, false);
157 }
158
159
172 public ClassName update(ClassName className, boolean merge)
173 throws SystemException {
174 boolean isNew = className.isNew();
175
176 for (ModelListener listener : listeners) {
177 if (isNew) {
178 listener.onBeforeCreate(className);
179 }
180 else {
181 listener.onBeforeUpdate(className);
182 }
183 }
184
185 className = updateImpl(className, merge);
186
187 for (ModelListener listener : listeners) {
188 if (isNew) {
189 listener.onAfterCreate(className);
190 }
191 else {
192 listener.onAfterUpdate(className);
193 }
194 }
195
196 return className;
197 }
198
199 public ClassName updateImpl(com.liferay.portal.model.ClassName className,
200 boolean merge) throws SystemException {
201 Session session = null;
202
203 try {
204 session = openSession();
205
206 BatchSessionUtil.update(session, className, merge);
207
208 className.setNew(false);
209
210 return className;
211 }
212 catch (Exception e) {
213 throw processException(e);
214 }
215 finally {
216 closeSession(session);
217
218 FinderCacheUtil.clearCache(ClassName.class.getName());
219 }
220 }
221
222 public ClassName findByPrimaryKey(long classNameId)
223 throws NoSuchClassNameException, SystemException {
224 ClassName className = fetchByPrimaryKey(classNameId);
225
226 if (className == null) {
227 if (_log.isWarnEnabled()) {
228 _log.warn("No ClassName exists with the primary key " +
229 classNameId);
230 }
231
232 throw new NoSuchClassNameException(
233 "No ClassName exists with the primary key " + classNameId);
234 }
235
236 return className;
237 }
238
239 public ClassName fetchByPrimaryKey(long classNameId)
240 throws SystemException {
241 Session session = null;
242
243 try {
244 session = openSession();
245
246 return (ClassName)session.get(ClassNameImpl.class,
247 new Long(classNameId));
248 }
249 catch (Exception e) {
250 throw processException(e);
251 }
252 finally {
253 closeSession(session);
254 }
255 }
256
257 public ClassName findByValue(String value)
258 throws NoSuchClassNameException, SystemException {
259 ClassName className = fetchByValue(value);
260
261 if (className == null) {
262 StringBuilder msg = new StringBuilder();
263
264 msg.append("No ClassName exists with the key {");
265
266 msg.append("value=" + value);
267
268 msg.append(StringPool.CLOSE_CURLY_BRACE);
269
270 if (_log.isWarnEnabled()) {
271 _log.warn(msg.toString());
272 }
273
274 throw new NoSuchClassNameException(msg.toString());
275 }
276
277 return className;
278 }
279
280 public ClassName fetchByValue(String value) throws SystemException {
281 boolean finderClassNameCacheEnabled = ClassNameModelImpl.CACHE_ENABLED;
282 String finderClassName = ClassName.class.getName();
283 String finderMethodName = "fetchByValue";
284 String[] finderParams = new String[] { String.class.getName() };
285 Object[] finderArgs = new Object[] { value };
286
287 Object result = null;
288
289 if (finderClassNameCacheEnabled) {
290 result = FinderCacheUtil.getResult(finderClassName,
291 finderMethodName, finderParams, finderArgs, this);
292 }
293
294 if (result == null) {
295 Session session = null;
296
297 try {
298 session = openSession();
299
300 StringBuilder query = new StringBuilder();
301
302 query.append("FROM com.liferay.portal.model.ClassName WHERE ");
303
304 if (value == null) {
305 query.append("value IS NULL");
306 }
307 else {
308 query.append("value = ?");
309 }
310
311 query.append(" ");
312
313 Query q = session.createQuery(query.toString());
314
315 QueryPos qPos = QueryPos.getInstance(q);
316
317 if (value != null) {
318 qPos.add(value);
319 }
320
321 List<ClassName> list = q.list();
322
323 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
324 finderClassName, finderMethodName, finderParams,
325 finderArgs, list);
326
327 if (list.size() == 0) {
328 return null;
329 }
330 else {
331 return list.get(0);
332 }
333 }
334 catch (Exception e) {
335 throw processException(e);
336 }
337 finally {
338 closeSession(session);
339 }
340 }
341 else {
342 List<ClassName> list = (List<ClassName>)result;
343
344 if (list.size() == 0) {
345 return null;
346 }
347 else {
348 return list.get(0);
349 }
350 }
351 }
352
353 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
354 throws SystemException {
355 Session session = null;
356
357 try {
358 session = openSession();
359
360 dynamicQuery.compile(session);
361
362 return dynamicQuery.list();
363 }
364 catch (Exception e) {
365 throw processException(e);
366 }
367 finally {
368 closeSession(session);
369 }
370 }
371
372 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
373 int start, int end) throws SystemException {
374 Session session = null;
375
376 try {
377 session = openSession();
378
379 dynamicQuery.setLimit(start, end);
380
381 dynamicQuery.compile(session);
382
383 return dynamicQuery.list();
384 }
385 catch (Exception e) {
386 throw processException(e);
387 }
388 finally {
389 closeSession(session);
390 }
391 }
392
393 public List<ClassName> findAll() throws SystemException {
394 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
395 }
396
397 public List<ClassName> findAll(int start, int end)
398 throws SystemException {
399 return findAll(start, end, null);
400 }
401
402 public List<ClassName> findAll(int start, int end, OrderByComparator obc)
403 throws SystemException {
404 boolean finderClassNameCacheEnabled = ClassNameModelImpl.CACHE_ENABLED;
405 String finderClassName = ClassName.class.getName();
406 String finderMethodName = "findAll";
407 String[] finderParams = new String[] {
408 "java.lang.Integer", "java.lang.Integer",
409 "com.liferay.portal.kernel.util.OrderByComparator"
410 };
411 Object[] finderArgs = new Object[] {
412 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
413 };
414
415 Object result = null;
416
417 if (finderClassNameCacheEnabled) {
418 result = FinderCacheUtil.getResult(finderClassName,
419 finderMethodName, finderParams, finderArgs, this);
420 }
421
422 if (result == null) {
423 Session session = null;
424
425 try {
426 session = openSession();
427
428 StringBuilder query = new StringBuilder();
429
430 query.append("FROM com.liferay.portal.model.ClassName ");
431
432 if (obc != null) {
433 query.append("ORDER BY ");
434 query.append(obc.getOrderBy());
435 }
436
437 Query q = session.createQuery(query.toString());
438
439 List<ClassName> list = null;
440
441 if (obc == null) {
442 list = (List<ClassName>)QueryUtil.list(q, getDialect(),
443 start, end, false);
444
445 Collections.sort(list);
446 }
447 else {
448 list = (List<ClassName>)QueryUtil.list(q, getDialect(),
449 start, end);
450 }
451
452 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
453 finderClassName, finderMethodName, finderParams,
454 finderArgs, list);
455
456 return list;
457 }
458 catch (Exception e) {
459 throw processException(e);
460 }
461 finally {
462 closeSession(session);
463 }
464 }
465 else {
466 return (List<ClassName>)result;
467 }
468 }
469
470 public void removeByValue(String value)
471 throws NoSuchClassNameException, SystemException {
472 ClassName className = findByValue(value);
473
474 remove(className);
475 }
476
477 public void removeAll() throws SystemException {
478 for (ClassName className : findAll()) {
479 remove(className);
480 }
481 }
482
483 public int countByValue(String value) throws SystemException {
484 boolean finderClassNameCacheEnabled = ClassNameModelImpl.CACHE_ENABLED;
485 String finderClassName = ClassName.class.getName();
486 String finderMethodName = "countByValue";
487 String[] finderParams = new String[] { String.class.getName() };
488 Object[] finderArgs = new Object[] { value };
489
490 Object result = null;
491
492 if (finderClassNameCacheEnabled) {
493 result = FinderCacheUtil.getResult(finderClassName,
494 finderMethodName, finderParams, finderArgs, this);
495 }
496
497 if (result == null) {
498 Session session = null;
499
500 try {
501 session = openSession();
502
503 StringBuilder query = new StringBuilder();
504
505 query.append("SELECT COUNT(*) ");
506 query.append("FROM com.liferay.portal.model.ClassName WHERE ");
507
508 if (value == null) {
509 query.append("value IS NULL");
510 }
511 else {
512 query.append("value = ?");
513 }
514
515 query.append(" ");
516
517 Query q = session.createQuery(query.toString());
518
519 QueryPos qPos = QueryPos.getInstance(q);
520
521 if (value != null) {
522 qPos.add(value);
523 }
524
525 Long count = null;
526
527 Iterator<Long> itr = q.list().iterator();
528
529 if (itr.hasNext()) {
530 count = itr.next();
531 }
532
533 if (count == null) {
534 count = new Long(0);
535 }
536
537 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
538 finderClassName, finderMethodName, finderParams,
539 finderArgs, count);
540
541 return count.intValue();
542 }
543 catch (Exception e) {
544 throw processException(e);
545 }
546 finally {
547 closeSession(session);
548 }
549 }
550 else {
551 return ((Long)result).intValue();
552 }
553 }
554
555 public int countAll() throws SystemException {
556 boolean finderClassNameCacheEnabled = ClassNameModelImpl.CACHE_ENABLED;
557 String finderClassName = ClassName.class.getName();
558 String finderMethodName = "countAll";
559 String[] finderParams = new String[] { };
560 Object[] finderArgs = new Object[] { };
561
562 Object result = null;
563
564 if (finderClassNameCacheEnabled) {
565 result = FinderCacheUtil.getResult(finderClassName,
566 finderMethodName, finderParams, finderArgs, this);
567 }
568
569 if (result == null) {
570 Session session = null;
571
572 try {
573 session = openSession();
574
575 Query q = session.createQuery(
576 "SELECT COUNT(*) FROM com.liferay.portal.model.ClassName");
577
578 Long count = null;
579
580 Iterator<Long> itr = q.list().iterator();
581
582 if (itr.hasNext()) {
583 count = itr.next();
584 }
585
586 if (count == null) {
587 count = new Long(0);
588 }
589
590 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
591 finderClassName, finderMethodName, finderParams,
592 finderArgs, count);
593
594 return count.intValue();
595 }
596 catch (Exception e) {
597 throw processException(e);
598 }
599 finally {
600 closeSession(session);
601 }
602 }
603 else {
604 return ((Long)result).intValue();
605 }
606 }
607
608 public void afterPropertiesSet() {
609 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
610 com.liferay.portal.util.PropsUtil.get(
611 "value.object.listener.com.liferay.portal.model.ClassName")));
612
613 if (listenerClassNames.length > 0) {
614 try {
615 List<ModelListener> listenersList = new ArrayList<ModelListener>();
616
617 for (String listenerClassName : listenerClassNames) {
618 listenersList.add((ModelListener)Class.forName(
619 listenerClassName).newInstance());
620 }
621
622 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
623 }
624 catch (Exception e) {
625 _log.error(e);
626 }
627 }
628 }
629
630 @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
631 protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
632 @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
633 protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
634 @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
635 protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
636 @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
637 protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
638 @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
639 protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
640 @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
641 protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
642 @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
643 protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
644 @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
645 protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
646 @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
647 protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
648 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
649 protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
650 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
651 protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
652 @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
653 protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
654 @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
655 protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
656 @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
657 protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
658 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
659 protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
660 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
661 protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
662 @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
663 protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
664 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
665 protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
666 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
667 protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
668 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
669 protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
670 @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
671 protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
672 @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
673 protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
674 @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
675 protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
676 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
677 protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
678 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
679 protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
680 @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
681 protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
682 @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
683 protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
684 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
685 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
686 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
687 protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
688 @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
689 protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
690 @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
691 protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
692 @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
693 protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
694 @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
695 protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
696 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
697 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
698 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
699 protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
700 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
701 protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
702 @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
703 protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
704 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
705 protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
706 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
707 protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
708 @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
709 protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
710 @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
711 protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
712 private static Log _log = LogFactoryUtil.getLog(ClassNamePersistenceImpl.class);
713 }