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