001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.service.persistence;
022:
023: import com.liferay.portal.NoSuchPluginSettingException;
024: import com.liferay.portal.SystemException;
025: import com.liferay.portal.kernel.dao.DynamicQuery;
026: import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
027: import com.liferay.portal.kernel.util.GetterUtil;
028: import com.liferay.portal.kernel.util.OrderByComparator;
029: import com.liferay.portal.kernel.util.StringMaker;
030: import com.liferay.portal.kernel.util.StringPool;
031: import com.liferay.portal.kernel.util.Validator;
032: import com.liferay.portal.model.ModelListener;
033: import com.liferay.portal.model.PluginSetting;
034: import com.liferay.portal.model.impl.PluginSettingImpl;
035: import com.liferay.portal.model.impl.PluginSettingModelImpl;
036: import com.liferay.portal.spring.hibernate.FinderCache;
037: import com.liferay.portal.spring.hibernate.HibernateUtil;
038: import com.liferay.portal.util.PropsUtil;
039:
040: import com.liferay.util.dao.hibernate.QueryUtil;
041:
042: import org.apache.commons.logging.Log;
043: import org.apache.commons.logging.LogFactory;
044:
045: import org.hibernate.Query;
046: import org.hibernate.Session;
047:
048: import java.util.Collections;
049: import java.util.Iterator;
050: import java.util.List;
051:
052: /**
053: * <a href="PluginSettingPersistenceImpl.java.html"><b><i>View Source</i></b></a>
054: *
055: * @author Brian Wing Shun Chan
056: *
057: */
058: public class PluginSettingPersistenceImpl extends BasePersistence
059: implements PluginSettingPersistence {
060: public PluginSetting create(long pluginSettingId) {
061: PluginSetting pluginSetting = new PluginSettingImpl();
062:
063: pluginSetting.setNew(true);
064: pluginSetting.setPrimaryKey(pluginSettingId);
065:
066: return pluginSetting;
067: }
068:
069: public PluginSetting remove(long pluginSettingId)
070: throws NoSuchPluginSettingException, SystemException {
071: Session session = null;
072:
073: try {
074: session = openSession();
075:
076: PluginSetting pluginSetting = (PluginSetting) session.get(
077: PluginSettingImpl.class, new Long(pluginSettingId));
078:
079: if (pluginSetting == null) {
080: if (_log.isWarnEnabled()) {
081: _log
082: .warn("No PluginSetting exists with the primary key "
083: + pluginSettingId);
084: }
085:
086: throw new NoSuchPluginSettingException(
087: "No PluginSetting exists with the primary key "
088: + pluginSettingId);
089: }
090:
091: return remove(pluginSetting);
092: } catch (NoSuchPluginSettingException nsee) {
093: throw nsee;
094: } catch (Exception e) {
095: throw HibernateUtil.processException(e);
096: } finally {
097: closeSession(session);
098: }
099: }
100:
101: public PluginSetting remove(PluginSetting pluginSetting)
102: throws SystemException {
103: ModelListener listener = _getListener();
104:
105: if (listener != null) {
106: listener.onBeforeRemove(pluginSetting);
107: }
108:
109: pluginSetting = removeImpl(pluginSetting);
110:
111: if (listener != null) {
112: listener.onAfterRemove(pluginSetting);
113: }
114:
115: return pluginSetting;
116: }
117:
118: protected PluginSetting removeImpl(PluginSetting pluginSetting)
119: throws SystemException {
120: Session session = null;
121:
122: try {
123: session = openSession();
124:
125: session.delete(pluginSetting);
126:
127: session.flush();
128:
129: return pluginSetting;
130: } catch (Exception e) {
131: throw HibernateUtil.processException(e);
132: } finally {
133: closeSession(session);
134:
135: FinderCache.clearCache(PluginSetting.class.getName());
136: }
137: }
138:
139: public PluginSetting update(PluginSetting pluginSetting)
140: throws SystemException {
141: return update(pluginSetting, false);
142: }
143:
144: public PluginSetting update(PluginSetting pluginSetting,
145: boolean merge) throws SystemException {
146: ModelListener listener = _getListener();
147:
148: boolean isNew = pluginSetting.isNew();
149:
150: if (listener != null) {
151: if (isNew) {
152: listener.onBeforeCreate(pluginSetting);
153: } else {
154: listener.onBeforeUpdate(pluginSetting);
155: }
156: }
157:
158: pluginSetting = updateImpl(pluginSetting, merge);
159:
160: if (listener != null) {
161: if (isNew) {
162: listener.onAfterCreate(pluginSetting);
163: } else {
164: listener.onAfterUpdate(pluginSetting);
165: }
166: }
167:
168: return pluginSetting;
169: }
170:
171: public PluginSetting updateImpl(
172: com.liferay.portal.model.PluginSetting pluginSetting,
173: boolean merge) throws SystemException {
174: Session session = null;
175:
176: try {
177: session = openSession();
178:
179: if (merge) {
180: session.merge(pluginSetting);
181: } else {
182: if (pluginSetting.isNew()) {
183: session.save(pluginSetting);
184: }
185: }
186:
187: session.flush();
188:
189: pluginSetting.setNew(false);
190:
191: return pluginSetting;
192: } catch (Exception e) {
193: throw HibernateUtil.processException(e);
194: } finally {
195: closeSession(session);
196:
197: FinderCache.clearCache(PluginSetting.class.getName());
198: }
199: }
200:
201: public PluginSetting findByPrimaryKey(long pluginSettingId)
202: throws NoSuchPluginSettingException, SystemException {
203: PluginSetting pluginSetting = fetchByPrimaryKey(pluginSettingId);
204:
205: if (pluginSetting == null) {
206: if (_log.isWarnEnabled()) {
207: _log
208: .warn("No PluginSetting exists with the primary key "
209: + pluginSettingId);
210: }
211:
212: throw new NoSuchPluginSettingException(
213: "No PluginSetting exists with the primary key "
214: + pluginSettingId);
215: }
216:
217: return pluginSetting;
218: }
219:
220: public PluginSetting fetchByPrimaryKey(long pluginSettingId)
221: throws SystemException {
222: Session session = null;
223:
224: try {
225: session = openSession();
226:
227: return (PluginSetting) session.get(PluginSettingImpl.class,
228: new Long(pluginSettingId));
229: } catch (Exception e) {
230: throw HibernateUtil.processException(e);
231: } finally {
232: closeSession(session);
233: }
234: }
235:
236: public List findByCompanyId(long companyId) throws SystemException {
237: boolean finderClassNameCacheEnabled = PluginSettingModelImpl.CACHE_ENABLED;
238: String finderClassName = PluginSetting.class.getName();
239: String finderMethodName = "findByCompanyId";
240: String[] finderParams = new String[] { Long.class.getName() };
241: Object[] finderArgs = new Object[] { new Long(companyId) };
242:
243: Object result = null;
244:
245: if (finderClassNameCacheEnabled) {
246: result = FinderCache.getResult(finderClassName,
247: finderMethodName, finderParams, finderArgs,
248: getSessionFactory());
249: }
250:
251: if (result == null) {
252: Session session = null;
253:
254: try {
255: session = openSession();
256:
257: StringMaker query = new StringMaker();
258:
259: query
260: .append("FROM com.liferay.portal.model.PluginSetting WHERE ");
261:
262: query.append("companyId = ?");
263:
264: query.append(" ");
265:
266: Query q = session.createQuery(query.toString());
267:
268: int queryPos = 0;
269:
270: q.setLong(queryPos++, companyId);
271:
272: List list = q.list();
273:
274: FinderCache.putResult(finderClassNameCacheEnabled,
275: finderClassName, finderMethodName,
276: finderParams, finderArgs, list);
277:
278: return list;
279: } catch (Exception e) {
280: throw HibernateUtil.processException(e);
281: } finally {
282: closeSession(session);
283: }
284: } else {
285: return (List) result;
286: }
287: }
288:
289: public List findByCompanyId(long companyId, int begin, int end)
290: throws SystemException {
291: return findByCompanyId(companyId, begin, end, null);
292: }
293:
294: public List findByCompanyId(long companyId, int begin, int end,
295: OrderByComparator obc) throws SystemException {
296: boolean finderClassNameCacheEnabled = PluginSettingModelImpl.CACHE_ENABLED;
297: String finderClassName = PluginSetting.class.getName();
298: String finderMethodName = "findByCompanyId";
299: String[] finderParams = new String[] { Long.class.getName(),
300:
301: "java.lang.Integer", "java.lang.Integer",
302: "com.liferay.portal.kernel.util.OrderByComparator" };
303: Object[] finderArgs = new Object[] { new Long(companyId),
304:
305: String.valueOf(begin), String.valueOf(end), String.valueOf(obc) };
306:
307: Object result = null;
308:
309: if (finderClassNameCacheEnabled) {
310: result = FinderCache.getResult(finderClassName,
311: finderMethodName, finderParams, finderArgs,
312: getSessionFactory());
313: }
314:
315: if (result == null) {
316: Session session = null;
317:
318: try {
319: session = openSession();
320:
321: StringMaker query = new StringMaker();
322:
323: query
324: .append("FROM com.liferay.portal.model.PluginSetting WHERE ");
325:
326: query.append("companyId = ?");
327:
328: query.append(" ");
329:
330: if (obc != null) {
331: query.append("ORDER BY ");
332: query.append(obc.getOrderBy());
333: }
334:
335: Query q = session.createQuery(query.toString());
336:
337: int queryPos = 0;
338:
339: q.setLong(queryPos++, companyId);
340:
341: List list = QueryUtil.list(q, getDialect(), begin, end);
342:
343: FinderCache.putResult(finderClassNameCacheEnabled,
344: finderClassName, finderMethodName,
345: finderParams, finderArgs, list);
346:
347: return list;
348: } catch (Exception e) {
349: throw HibernateUtil.processException(e);
350: } finally {
351: closeSession(session);
352: }
353: } else {
354: return (List) result;
355: }
356: }
357:
358: public PluginSetting findByCompanyId_First(long companyId,
359: OrderByComparator obc) throws NoSuchPluginSettingException,
360: SystemException {
361: List list = findByCompanyId(companyId, 0, 1, obc);
362:
363: if (list.size() == 0) {
364: StringMaker msg = new StringMaker();
365:
366: msg.append("No PluginSetting exists with the key {");
367:
368: msg.append("companyId=" + companyId);
369:
370: msg.append(StringPool.CLOSE_CURLY_BRACE);
371:
372: throw new NoSuchPluginSettingException(msg.toString());
373: } else {
374: return (PluginSetting) list.get(0);
375: }
376: }
377:
378: public PluginSetting findByCompanyId_Last(long companyId,
379: OrderByComparator obc) throws NoSuchPluginSettingException,
380: SystemException {
381: int count = countByCompanyId(companyId);
382:
383: List list = findByCompanyId(companyId, count - 1, count, obc);
384:
385: if (list.size() == 0) {
386: StringMaker msg = new StringMaker();
387:
388: msg.append("No PluginSetting exists with the key {");
389:
390: msg.append("companyId=" + companyId);
391:
392: msg.append(StringPool.CLOSE_CURLY_BRACE);
393:
394: throw new NoSuchPluginSettingException(msg.toString());
395: } else {
396: return (PluginSetting) list.get(0);
397: }
398: }
399:
400: public PluginSetting[] findByCompanyId_PrevAndNext(
401: long pluginSettingId, long companyId, OrderByComparator obc)
402: throws NoSuchPluginSettingException, SystemException {
403: PluginSetting pluginSetting = findByPrimaryKey(pluginSettingId);
404:
405: int count = countByCompanyId(companyId);
406:
407: Session session = null;
408:
409: try {
410: session = openSession();
411:
412: StringMaker query = new StringMaker();
413:
414: query
415: .append("FROM com.liferay.portal.model.PluginSetting WHERE ");
416:
417: query.append("companyId = ?");
418:
419: query.append(" ");
420:
421: if (obc != null) {
422: query.append("ORDER BY ");
423: query.append(obc.getOrderBy());
424: }
425:
426: Query q = session.createQuery(query.toString());
427:
428: int queryPos = 0;
429:
430: q.setLong(queryPos++, companyId);
431:
432: Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
433: pluginSetting);
434:
435: PluginSetting[] array = new PluginSettingImpl[3];
436:
437: array[0] = (PluginSetting) objArray[0];
438: array[1] = (PluginSetting) objArray[1];
439: array[2] = (PluginSetting) objArray[2];
440:
441: return array;
442: } catch (Exception e) {
443: throw HibernateUtil.processException(e);
444: } finally {
445: closeSession(session);
446: }
447: }
448:
449: public PluginSetting findByC_I_T(long companyId, String pluginId,
450: String pluginType) throws NoSuchPluginSettingException,
451: SystemException {
452: PluginSetting pluginSetting = fetchByC_I_T(companyId, pluginId,
453: pluginType);
454:
455: if (pluginSetting == null) {
456: StringMaker msg = new StringMaker();
457:
458: msg.append("No PluginSetting exists with the key {");
459:
460: msg.append("companyId=" + companyId);
461:
462: msg.append(", ");
463: msg.append("pluginId=" + pluginId);
464:
465: msg.append(", ");
466: msg.append("pluginType=" + pluginType);
467:
468: msg.append(StringPool.CLOSE_CURLY_BRACE);
469:
470: if (_log.isWarnEnabled()) {
471: _log.warn(msg.toString());
472: }
473:
474: throw new NoSuchPluginSettingException(msg.toString());
475: }
476:
477: return pluginSetting;
478: }
479:
480: public PluginSetting fetchByC_I_T(long companyId, String pluginId,
481: String pluginType) throws SystemException {
482: boolean finderClassNameCacheEnabled = PluginSettingModelImpl.CACHE_ENABLED;
483: String finderClassName = PluginSetting.class.getName();
484: String finderMethodName = "fetchByC_I_T";
485: String[] finderParams = new String[] { Long.class.getName(),
486: String.class.getName(), String.class.getName() };
487: Object[] finderArgs = new Object[] { new Long(companyId),
488:
489: pluginId,
490:
491: pluginType };
492:
493: Object result = null;
494:
495: if (finderClassNameCacheEnabled) {
496: result = FinderCache.getResult(finderClassName,
497: finderMethodName, finderParams, finderArgs,
498: getSessionFactory());
499: }
500:
501: if (result == null) {
502: Session session = null;
503:
504: try {
505: session = openSession();
506:
507: StringMaker query = new StringMaker();
508:
509: query
510: .append("FROM com.liferay.portal.model.PluginSetting WHERE ");
511:
512: query.append("companyId = ?");
513:
514: query.append(" AND ");
515:
516: if (pluginId == null) {
517: query.append("pluginId IS NULL");
518: } else {
519: query.append("pluginId = ?");
520: }
521:
522: query.append(" AND ");
523:
524: if (pluginType == null) {
525: query.append("pluginType IS NULL");
526: } else {
527: query.append("pluginType = ?");
528: }
529:
530: query.append(" ");
531:
532: Query q = session.createQuery(query.toString());
533:
534: int queryPos = 0;
535:
536: q.setLong(queryPos++, companyId);
537:
538: if (pluginId != null) {
539: q.setString(queryPos++, pluginId);
540: }
541:
542: if (pluginType != null) {
543: q.setString(queryPos++, pluginType);
544: }
545:
546: List list = q.list();
547:
548: FinderCache.putResult(finderClassNameCacheEnabled,
549: finderClassName, finderMethodName,
550: finderParams, finderArgs, list);
551:
552: if (list.size() == 0) {
553: return null;
554: } else {
555: return (PluginSetting) list.get(0);
556: }
557: } catch (Exception e) {
558: throw HibernateUtil.processException(e);
559: } finally {
560: closeSession(session);
561: }
562: } else {
563: List list = (List) result;
564:
565: if (list.size() == 0) {
566: return null;
567: } else {
568: return (PluginSetting) list.get(0);
569: }
570: }
571: }
572:
573: public List findWithDynamicQuery(
574: DynamicQueryInitializer queryInitializer)
575: throws SystemException {
576: Session session = null;
577:
578: try {
579: session = openSession();
580:
581: DynamicQuery query = queryInitializer.initialize(session);
582:
583: return query.list();
584: } catch (Exception e) {
585: throw HibernateUtil.processException(e);
586: } finally {
587: closeSession(session);
588: }
589: }
590:
591: public List findWithDynamicQuery(
592: DynamicQueryInitializer queryInitializer, int begin, int end)
593: throws SystemException {
594: Session session = null;
595:
596: try {
597: session = openSession();
598:
599: DynamicQuery query = queryInitializer.initialize(session);
600:
601: query.setLimit(begin, end);
602:
603: return query.list();
604: } catch (Exception e) {
605: throw HibernateUtil.processException(e);
606: } finally {
607: closeSession(session);
608: }
609: }
610:
611: public List findAll() throws SystemException {
612: return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
613: }
614:
615: public List findAll(int begin, int end) throws SystemException {
616: return findAll(begin, end, null);
617: }
618:
619: public List findAll(int begin, int end, OrderByComparator obc)
620: throws SystemException {
621: boolean finderClassNameCacheEnabled = PluginSettingModelImpl.CACHE_ENABLED;
622: String finderClassName = PluginSetting.class.getName();
623: String finderMethodName = "findAll";
624: String[] finderParams = new String[] { "java.lang.Integer",
625: "java.lang.Integer",
626: "com.liferay.portal.kernel.util.OrderByComparator" };
627: Object[] finderArgs = new Object[] { String.valueOf(begin),
628: String.valueOf(end), String.valueOf(obc) };
629:
630: Object result = null;
631:
632: if (finderClassNameCacheEnabled) {
633: result = FinderCache.getResult(finderClassName,
634: finderMethodName, finderParams, finderArgs,
635: getSessionFactory());
636: }
637:
638: if (result == null) {
639: Session session = null;
640:
641: try {
642: session = openSession();
643:
644: StringMaker query = new StringMaker();
645:
646: query
647: .append("FROM com.liferay.portal.model.PluginSetting ");
648:
649: if (obc != null) {
650: query.append("ORDER BY ");
651: query.append(obc.getOrderBy());
652: }
653:
654: Query q = session.createQuery(query.toString());
655:
656: List list = QueryUtil.list(q, getDialect(), begin, end);
657:
658: if (obc == null) {
659: Collections.sort(list);
660: }
661:
662: FinderCache.putResult(finderClassNameCacheEnabled,
663: finderClassName, finderMethodName,
664: finderParams, finderArgs, list);
665:
666: return list;
667: } catch (Exception e) {
668: throw HibernateUtil.processException(e);
669: } finally {
670: closeSession(session);
671: }
672: } else {
673: return (List) result;
674: }
675: }
676:
677: public void removeByCompanyId(long companyId)
678: throws SystemException {
679: Iterator itr = findByCompanyId(companyId).iterator();
680:
681: while (itr.hasNext()) {
682: PluginSetting pluginSetting = (PluginSetting) itr.next();
683:
684: remove(pluginSetting);
685: }
686: }
687:
688: public void removeByC_I_T(long companyId, String pluginId,
689: String pluginType) throws NoSuchPluginSettingException,
690: SystemException {
691: PluginSetting pluginSetting = findByC_I_T(companyId, pluginId,
692: pluginType);
693:
694: remove(pluginSetting);
695: }
696:
697: public void removeAll() throws SystemException {
698: Iterator itr = findAll().iterator();
699:
700: while (itr.hasNext()) {
701: remove((PluginSetting) itr.next());
702: }
703: }
704:
705: public int countByCompanyId(long companyId) throws SystemException {
706: boolean finderClassNameCacheEnabled = PluginSettingModelImpl.CACHE_ENABLED;
707: String finderClassName = PluginSetting.class.getName();
708: String finderMethodName = "countByCompanyId";
709: String[] finderParams = new String[] { Long.class.getName() };
710: Object[] finderArgs = new Object[] { new Long(companyId) };
711:
712: Object result = null;
713:
714: if (finderClassNameCacheEnabled) {
715: result = FinderCache.getResult(finderClassName,
716: finderMethodName, finderParams, finderArgs,
717: getSessionFactory());
718: }
719:
720: if (result == null) {
721: Session session = null;
722:
723: try {
724: session = openSession();
725:
726: StringMaker query = new StringMaker();
727:
728: query.append("SELECT COUNT(*) ");
729: query
730: .append("FROM com.liferay.portal.model.PluginSetting WHERE ");
731:
732: query.append("companyId = ?");
733:
734: query.append(" ");
735:
736: Query q = session.createQuery(query.toString());
737:
738: int queryPos = 0;
739:
740: q.setLong(queryPos++, companyId);
741:
742: Long count = null;
743:
744: Iterator itr = q.list().iterator();
745:
746: if (itr.hasNext()) {
747: count = (Long) itr.next();
748: }
749:
750: if (count == null) {
751: count = new Long(0);
752: }
753:
754: FinderCache.putResult(finderClassNameCacheEnabled,
755: finderClassName, finderMethodName,
756: finderParams, finderArgs, count);
757:
758: return count.intValue();
759: } catch (Exception e) {
760: throw HibernateUtil.processException(e);
761: } finally {
762: closeSession(session);
763: }
764: } else {
765: return ((Long) result).intValue();
766: }
767: }
768:
769: public int countByC_I_T(long companyId, String pluginId,
770: String pluginType) throws SystemException {
771: boolean finderClassNameCacheEnabled = PluginSettingModelImpl.CACHE_ENABLED;
772: String finderClassName = PluginSetting.class.getName();
773: String finderMethodName = "countByC_I_T";
774: String[] finderParams = new String[] { Long.class.getName(),
775: String.class.getName(), String.class.getName() };
776: Object[] finderArgs = new Object[] { new Long(companyId),
777:
778: pluginId,
779:
780: pluginType };
781:
782: Object result = null;
783:
784: if (finderClassNameCacheEnabled) {
785: result = FinderCache.getResult(finderClassName,
786: finderMethodName, finderParams, finderArgs,
787: getSessionFactory());
788: }
789:
790: if (result == null) {
791: Session session = null;
792:
793: try {
794: session = openSession();
795:
796: StringMaker query = new StringMaker();
797:
798: query.append("SELECT COUNT(*) ");
799: query
800: .append("FROM com.liferay.portal.model.PluginSetting WHERE ");
801:
802: query.append("companyId = ?");
803:
804: query.append(" AND ");
805:
806: if (pluginId == null) {
807: query.append("pluginId IS NULL");
808: } else {
809: query.append("pluginId = ?");
810: }
811:
812: query.append(" AND ");
813:
814: if (pluginType == null) {
815: query.append("pluginType IS NULL");
816: } else {
817: query.append("pluginType = ?");
818: }
819:
820: query.append(" ");
821:
822: Query q = session.createQuery(query.toString());
823:
824: int queryPos = 0;
825:
826: q.setLong(queryPos++, companyId);
827:
828: if (pluginId != null) {
829: q.setString(queryPos++, pluginId);
830: }
831:
832: if (pluginType != null) {
833: q.setString(queryPos++, pluginType);
834: }
835:
836: Long count = null;
837:
838: Iterator itr = q.list().iterator();
839:
840: if (itr.hasNext()) {
841: count = (Long) itr.next();
842: }
843:
844: if (count == null) {
845: count = new Long(0);
846: }
847:
848: FinderCache.putResult(finderClassNameCacheEnabled,
849: finderClassName, finderMethodName,
850: finderParams, finderArgs, count);
851:
852: return count.intValue();
853: } catch (Exception e) {
854: throw HibernateUtil.processException(e);
855: } finally {
856: closeSession(session);
857: }
858: } else {
859: return ((Long) result).intValue();
860: }
861: }
862:
863: public int countAll() throws SystemException {
864: boolean finderClassNameCacheEnabled = PluginSettingModelImpl.CACHE_ENABLED;
865: String finderClassName = PluginSetting.class.getName();
866: String finderMethodName = "countAll";
867: String[] finderParams = new String[] {};
868: Object[] finderArgs = new Object[] {};
869:
870: Object result = null;
871:
872: if (finderClassNameCacheEnabled) {
873: result = FinderCache.getResult(finderClassName,
874: finderMethodName, finderParams, finderArgs,
875: getSessionFactory());
876: }
877:
878: if (result == null) {
879: Session session = null;
880:
881: try {
882: session = openSession();
883:
884: Query q = session
885: .createQuery("SELECT COUNT(*) FROM com.liferay.portal.model.PluginSetting");
886:
887: Long count = null;
888:
889: Iterator itr = q.list().iterator();
890:
891: if (itr.hasNext()) {
892: count = (Long) itr.next();
893: }
894:
895: if (count == null) {
896: count = new Long(0);
897: }
898:
899: FinderCache.putResult(finderClassNameCacheEnabled,
900: finderClassName, finderMethodName,
901: finderParams, finderArgs, count);
902:
903: return count.intValue();
904: } catch (Exception e) {
905: throw HibernateUtil.processException(e);
906: } finally {
907: closeSession(session);
908: }
909: } else {
910: return ((Long) result).intValue();
911: }
912: }
913:
914: protected void initDao() {
915: }
916:
917: private static ModelListener _getListener() {
918: if (Validator.isNotNull(_LISTENER)) {
919: try {
920: return (ModelListener) Class.forName(_LISTENER)
921: .newInstance();
922: } catch (Exception e) {
923: _log.error(e);
924: }
925: }
926:
927: return null;
928: }
929:
930: private static final String _LISTENER = GetterUtil
931: .getString(PropsUtil
932: .get("value.object.listener.com.liferay.portal.model.PluginSetting"));
933: private static Log _log = LogFactory
934: .getLog(PluginSettingPersistenceImpl.class);
935: }
|