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