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