0001: /**
0002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
0003: *
0004: * Permission is hereby granted, free of charge, to any person obtaining a copy
0005: * of this software and associated documentation files (the "Software"), to deal
0006: * in the Software without restriction, including without limitation the rights
0007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0008: * copies of the Software, and to permit persons to whom the Software is
0009: * furnished to do so, subject to the following conditions:
0010: *
0011: * The above copyright notice and this permission notice shall be included in
0012: * all copies or substantial portions of the Software.
0013: *
0014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0020: * SOFTWARE.
0021: */package com.liferay.portal.service.persistence;
0022:
0023: import com.liferay.portal.NoSuchMembershipRequestException;
0024: import com.liferay.portal.SystemException;
0025: import com.liferay.portal.kernel.dao.DynamicQuery;
0026: import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
0027: import com.liferay.portal.kernel.util.GetterUtil;
0028: import com.liferay.portal.kernel.util.OrderByComparator;
0029: import com.liferay.portal.kernel.util.StringMaker;
0030: import com.liferay.portal.kernel.util.StringPool;
0031: import com.liferay.portal.kernel.util.Validator;
0032: import com.liferay.portal.model.MembershipRequest;
0033: import com.liferay.portal.model.ModelListener;
0034: import com.liferay.portal.model.impl.MembershipRequestImpl;
0035: import com.liferay.portal.model.impl.MembershipRequestModelImpl;
0036: import com.liferay.portal.spring.hibernate.FinderCache;
0037: import com.liferay.portal.spring.hibernate.HibernateUtil;
0038: import com.liferay.portal.util.PropsUtil;
0039:
0040: import com.liferay.util.dao.hibernate.QueryUtil;
0041:
0042: import org.apache.commons.logging.Log;
0043: import org.apache.commons.logging.LogFactory;
0044:
0045: import org.hibernate.Query;
0046: import org.hibernate.Session;
0047:
0048: import java.util.Collections;
0049: import java.util.Iterator;
0050: import java.util.List;
0051:
0052: /**
0053: * <a href="MembershipRequestPersistenceImpl.java.html"><b><i>View Source</i></b></a>
0054: *
0055: * @author Brian Wing Shun Chan
0056: *
0057: */
0058: public class MembershipRequestPersistenceImpl extends BasePersistence
0059: implements MembershipRequestPersistence {
0060: public MembershipRequest create(long membershipRequestId) {
0061: MembershipRequest membershipRequest = new MembershipRequestImpl();
0062:
0063: membershipRequest.setNew(true);
0064: membershipRequest.setPrimaryKey(membershipRequestId);
0065:
0066: return membershipRequest;
0067: }
0068:
0069: public MembershipRequest remove(long membershipRequestId)
0070: throws NoSuchMembershipRequestException, SystemException {
0071: Session session = null;
0072:
0073: try {
0074: session = openSession();
0075:
0076: MembershipRequest membershipRequest = (MembershipRequest) session
0077: .get(MembershipRequestImpl.class, new Long(
0078: membershipRequestId));
0079:
0080: if (membershipRequest == null) {
0081: if (_log.isWarnEnabled()) {
0082: _log
0083: .warn("No MembershipRequest exists with the primary key "
0084: + membershipRequestId);
0085: }
0086:
0087: throw new NoSuchMembershipRequestException(
0088: "No MembershipRequest exists with the primary key "
0089: + membershipRequestId);
0090: }
0091:
0092: return remove(membershipRequest);
0093: } catch (NoSuchMembershipRequestException nsee) {
0094: throw nsee;
0095: } catch (Exception e) {
0096: throw HibernateUtil.processException(e);
0097: } finally {
0098: closeSession(session);
0099: }
0100: }
0101:
0102: public MembershipRequest remove(MembershipRequest membershipRequest)
0103: throws SystemException {
0104: ModelListener listener = _getListener();
0105:
0106: if (listener != null) {
0107: listener.onBeforeRemove(membershipRequest);
0108: }
0109:
0110: membershipRequest = removeImpl(membershipRequest);
0111:
0112: if (listener != null) {
0113: listener.onAfterRemove(membershipRequest);
0114: }
0115:
0116: return membershipRequest;
0117: }
0118:
0119: protected MembershipRequest removeImpl(
0120: MembershipRequest membershipRequest) throws SystemException {
0121: Session session = null;
0122:
0123: try {
0124: session = openSession();
0125:
0126: session.delete(membershipRequest);
0127:
0128: session.flush();
0129:
0130: return membershipRequest;
0131: } catch (Exception e) {
0132: throw HibernateUtil.processException(e);
0133: } finally {
0134: closeSession(session);
0135:
0136: FinderCache.clearCache(MembershipRequest.class.getName());
0137: }
0138: }
0139:
0140: public MembershipRequest update(MembershipRequest membershipRequest)
0141: throws SystemException {
0142: return update(membershipRequest, false);
0143: }
0144:
0145: public MembershipRequest update(
0146: MembershipRequest membershipRequest, boolean merge)
0147: throws SystemException {
0148: ModelListener listener = _getListener();
0149:
0150: boolean isNew = membershipRequest.isNew();
0151:
0152: if (listener != null) {
0153: if (isNew) {
0154: listener.onBeforeCreate(membershipRequest);
0155: } else {
0156: listener.onBeforeUpdate(membershipRequest);
0157: }
0158: }
0159:
0160: membershipRequest = updateImpl(membershipRequest, merge);
0161:
0162: if (listener != null) {
0163: if (isNew) {
0164: listener.onAfterCreate(membershipRequest);
0165: } else {
0166: listener.onAfterUpdate(membershipRequest);
0167: }
0168: }
0169:
0170: return membershipRequest;
0171: }
0172:
0173: public MembershipRequest updateImpl(
0174: com.liferay.portal.model.MembershipRequest membershipRequest,
0175: boolean merge) throws SystemException {
0176: Session session = null;
0177:
0178: try {
0179: session = openSession();
0180:
0181: if (merge) {
0182: session.merge(membershipRequest);
0183: } else {
0184: if (membershipRequest.isNew()) {
0185: session.save(membershipRequest);
0186: }
0187: }
0188:
0189: session.flush();
0190:
0191: membershipRequest.setNew(false);
0192:
0193: return membershipRequest;
0194: } catch (Exception e) {
0195: throw HibernateUtil.processException(e);
0196: } finally {
0197: closeSession(session);
0198:
0199: FinderCache.clearCache(MembershipRequest.class.getName());
0200: }
0201: }
0202:
0203: public MembershipRequest findByPrimaryKey(long membershipRequestId)
0204: throws NoSuchMembershipRequestException, SystemException {
0205: MembershipRequest membershipRequest = fetchByPrimaryKey(membershipRequestId);
0206:
0207: if (membershipRequest == null) {
0208: if (_log.isWarnEnabled()) {
0209: _log
0210: .warn("No MembershipRequest exists with the primary key "
0211: + membershipRequestId);
0212: }
0213:
0214: throw new NoSuchMembershipRequestException(
0215: "No MembershipRequest exists with the primary key "
0216: + membershipRequestId);
0217: }
0218:
0219: return membershipRequest;
0220: }
0221:
0222: public MembershipRequest fetchByPrimaryKey(long membershipRequestId)
0223: throws SystemException {
0224: Session session = null;
0225:
0226: try {
0227: session = openSession();
0228:
0229: return (MembershipRequest) session.get(
0230: MembershipRequestImpl.class, new Long(
0231: membershipRequestId));
0232: } catch (Exception e) {
0233: throw HibernateUtil.processException(e);
0234: } finally {
0235: closeSession(session);
0236: }
0237: }
0238:
0239: public List findByGroupId(long groupId) throws SystemException {
0240: boolean finderClassNameCacheEnabled = MembershipRequestModelImpl.CACHE_ENABLED;
0241: String finderClassName = MembershipRequest.class.getName();
0242: String finderMethodName = "findByGroupId";
0243: String[] finderParams = new String[] { Long.class.getName() };
0244: Object[] finderArgs = new Object[] { new Long(groupId) };
0245:
0246: Object result = null;
0247:
0248: if (finderClassNameCacheEnabled) {
0249: result = FinderCache.getResult(finderClassName,
0250: finderMethodName, finderParams, finderArgs,
0251: getSessionFactory());
0252: }
0253:
0254: if (result == null) {
0255: Session session = null;
0256:
0257: try {
0258: session = openSession();
0259:
0260: StringMaker query = new StringMaker();
0261:
0262: query
0263: .append("FROM com.liferay.portal.model.MembershipRequest WHERE ");
0264:
0265: query.append("groupId = ?");
0266:
0267: query.append(" ");
0268:
0269: query.append("ORDER BY ");
0270:
0271: query.append("createDate DESC");
0272:
0273: Query q = session.createQuery(query.toString());
0274:
0275: int queryPos = 0;
0276:
0277: q.setLong(queryPos++, groupId);
0278:
0279: List list = q.list();
0280:
0281: FinderCache.putResult(finderClassNameCacheEnabled,
0282: finderClassName, finderMethodName,
0283: finderParams, finderArgs, list);
0284:
0285: return list;
0286: } catch (Exception e) {
0287: throw HibernateUtil.processException(e);
0288: } finally {
0289: closeSession(session);
0290: }
0291: } else {
0292: return (List) result;
0293: }
0294: }
0295:
0296: public List findByGroupId(long groupId, int begin, int end)
0297: throws SystemException {
0298: return findByGroupId(groupId, begin, end, null);
0299: }
0300:
0301: public List findByGroupId(long groupId, int begin, int end,
0302: OrderByComparator obc) throws SystemException {
0303: boolean finderClassNameCacheEnabled = MembershipRequestModelImpl.CACHE_ENABLED;
0304: String finderClassName = MembershipRequest.class.getName();
0305: String finderMethodName = "findByGroupId";
0306: String[] finderParams = new String[] { Long.class.getName(),
0307:
0308: "java.lang.Integer", "java.lang.Integer",
0309: "com.liferay.portal.kernel.util.OrderByComparator" };
0310: Object[] finderArgs = new Object[] { new Long(groupId),
0311:
0312: String.valueOf(begin), String.valueOf(end), String.valueOf(obc) };
0313:
0314: Object result = null;
0315:
0316: if (finderClassNameCacheEnabled) {
0317: result = FinderCache.getResult(finderClassName,
0318: finderMethodName, finderParams, finderArgs,
0319: getSessionFactory());
0320: }
0321:
0322: if (result == null) {
0323: Session session = null;
0324:
0325: try {
0326: session = openSession();
0327:
0328: StringMaker query = new StringMaker();
0329:
0330: query
0331: .append("FROM com.liferay.portal.model.MembershipRequest WHERE ");
0332:
0333: query.append("groupId = ?");
0334:
0335: query.append(" ");
0336:
0337: if (obc != null) {
0338: query.append("ORDER BY ");
0339: query.append(obc.getOrderBy());
0340: }
0341:
0342: else {
0343: query.append("ORDER BY ");
0344:
0345: query.append("createDate DESC");
0346: }
0347:
0348: Query q = session.createQuery(query.toString());
0349:
0350: int queryPos = 0;
0351:
0352: q.setLong(queryPos++, groupId);
0353:
0354: List list = QueryUtil.list(q, getDialect(), begin, end);
0355:
0356: FinderCache.putResult(finderClassNameCacheEnabled,
0357: finderClassName, finderMethodName,
0358: finderParams, finderArgs, list);
0359:
0360: return list;
0361: } catch (Exception e) {
0362: throw HibernateUtil.processException(e);
0363: } finally {
0364: closeSession(session);
0365: }
0366: } else {
0367: return (List) result;
0368: }
0369: }
0370:
0371: public MembershipRequest findByGroupId_First(long groupId,
0372: OrderByComparator obc)
0373: throws NoSuchMembershipRequestException, SystemException {
0374: List list = findByGroupId(groupId, 0, 1, obc);
0375:
0376: if (list.size() == 0) {
0377: StringMaker msg = new StringMaker();
0378:
0379: msg.append("No MembershipRequest exists with the key {");
0380:
0381: msg.append("groupId=" + groupId);
0382:
0383: msg.append(StringPool.CLOSE_CURLY_BRACE);
0384:
0385: throw new NoSuchMembershipRequestException(msg.toString());
0386: } else {
0387: return (MembershipRequest) list.get(0);
0388: }
0389: }
0390:
0391: public MembershipRequest findByGroupId_Last(long groupId,
0392: OrderByComparator obc)
0393: throws NoSuchMembershipRequestException, SystemException {
0394: int count = countByGroupId(groupId);
0395:
0396: List list = findByGroupId(groupId, count - 1, count, obc);
0397:
0398: if (list.size() == 0) {
0399: StringMaker msg = new StringMaker();
0400:
0401: msg.append("No MembershipRequest exists with the key {");
0402:
0403: msg.append("groupId=" + groupId);
0404:
0405: msg.append(StringPool.CLOSE_CURLY_BRACE);
0406:
0407: throw new NoSuchMembershipRequestException(msg.toString());
0408: } else {
0409: return (MembershipRequest) list.get(0);
0410: }
0411: }
0412:
0413: public MembershipRequest[] findByGroupId_PrevAndNext(
0414: long membershipRequestId, long groupId,
0415: OrderByComparator obc)
0416: throws NoSuchMembershipRequestException, SystemException {
0417: MembershipRequest membershipRequest = findByPrimaryKey(membershipRequestId);
0418:
0419: int count = countByGroupId(groupId);
0420:
0421: Session session = null;
0422:
0423: try {
0424: session = openSession();
0425:
0426: StringMaker query = new StringMaker();
0427:
0428: query
0429: .append("FROM com.liferay.portal.model.MembershipRequest WHERE ");
0430:
0431: query.append("groupId = ?");
0432:
0433: query.append(" ");
0434:
0435: if (obc != null) {
0436: query.append("ORDER BY ");
0437: query.append(obc.getOrderBy());
0438: }
0439:
0440: else {
0441: query.append("ORDER BY ");
0442:
0443: query.append("createDate DESC");
0444: }
0445:
0446: Query q = session.createQuery(query.toString());
0447:
0448: int queryPos = 0;
0449:
0450: q.setLong(queryPos++, groupId);
0451:
0452: Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
0453: membershipRequest);
0454:
0455: MembershipRequest[] array = new MembershipRequestImpl[3];
0456:
0457: array[0] = (MembershipRequest) objArray[0];
0458: array[1] = (MembershipRequest) objArray[1];
0459: array[2] = (MembershipRequest) objArray[2];
0460:
0461: return array;
0462: } catch (Exception e) {
0463: throw HibernateUtil.processException(e);
0464: } finally {
0465: closeSession(session);
0466: }
0467: }
0468:
0469: public List findByUserId(long userId) throws SystemException {
0470: boolean finderClassNameCacheEnabled = MembershipRequestModelImpl.CACHE_ENABLED;
0471: String finderClassName = MembershipRequest.class.getName();
0472: String finderMethodName = "findByUserId";
0473: String[] finderParams = new String[] { Long.class.getName() };
0474: Object[] finderArgs = new Object[] { new Long(userId) };
0475:
0476: Object result = null;
0477:
0478: if (finderClassNameCacheEnabled) {
0479: result = FinderCache.getResult(finderClassName,
0480: finderMethodName, finderParams, finderArgs,
0481: getSessionFactory());
0482: }
0483:
0484: if (result == null) {
0485: Session session = null;
0486:
0487: try {
0488: session = openSession();
0489:
0490: StringMaker query = new StringMaker();
0491:
0492: query
0493: .append("FROM com.liferay.portal.model.MembershipRequest WHERE ");
0494:
0495: query.append("userId = ?");
0496:
0497: query.append(" ");
0498:
0499: query.append("ORDER BY ");
0500:
0501: query.append("createDate DESC");
0502:
0503: Query q = session.createQuery(query.toString());
0504:
0505: int queryPos = 0;
0506:
0507: q.setLong(queryPos++, userId);
0508:
0509: List list = q.list();
0510:
0511: FinderCache.putResult(finderClassNameCacheEnabled,
0512: finderClassName, finderMethodName,
0513: finderParams, finderArgs, list);
0514:
0515: return list;
0516: } catch (Exception e) {
0517: throw HibernateUtil.processException(e);
0518: } finally {
0519: closeSession(session);
0520: }
0521: } else {
0522: return (List) result;
0523: }
0524: }
0525:
0526: public List findByUserId(long userId, int begin, int end)
0527: throws SystemException {
0528: return findByUserId(userId, begin, end, null);
0529: }
0530:
0531: public List findByUserId(long userId, int begin, int end,
0532: OrderByComparator obc) throws SystemException {
0533: boolean finderClassNameCacheEnabled = MembershipRequestModelImpl.CACHE_ENABLED;
0534: String finderClassName = MembershipRequest.class.getName();
0535: String finderMethodName = "findByUserId";
0536: String[] finderParams = new String[] { Long.class.getName(),
0537:
0538: "java.lang.Integer", "java.lang.Integer",
0539: "com.liferay.portal.kernel.util.OrderByComparator" };
0540: Object[] finderArgs = new Object[] { new Long(userId),
0541:
0542: String.valueOf(begin), String.valueOf(end), String.valueOf(obc) };
0543:
0544: Object result = null;
0545:
0546: if (finderClassNameCacheEnabled) {
0547: result = FinderCache.getResult(finderClassName,
0548: finderMethodName, finderParams, finderArgs,
0549: getSessionFactory());
0550: }
0551:
0552: if (result == null) {
0553: Session session = null;
0554:
0555: try {
0556: session = openSession();
0557:
0558: StringMaker query = new StringMaker();
0559:
0560: query
0561: .append("FROM com.liferay.portal.model.MembershipRequest WHERE ");
0562:
0563: query.append("userId = ?");
0564:
0565: query.append(" ");
0566:
0567: if (obc != null) {
0568: query.append("ORDER BY ");
0569: query.append(obc.getOrderBy());
0570: }
0571:
0572: else {
0573: query.append("ORDER BY ");
0574:
0575: query.append("createDate DESC");
0576: }
0577:
0578: Query q = session.createQuery(query.toString());
0579:
0580: int queryPos = 0;
0581:
0582: q.setLong(queryPos++, userId);
0583:
0584: List list = QueryUtil.list(q, getDialect(), begin, end);
0585:
0586: FinderCache.putResult(finderClassNameCacheEnabled,
0587: finderClassName, finderMethodName,
0588: finderParams, finderArgs, list);
0589:
0590: return list;
0591: } catch (Exception e) {
0592: throw HibernateUtil.processException(e);
0593: } finally {
0594: closeSession(session);
0595: }
0596: } else {
0597: return (List) result;
0598: }
0599: }
0600:
0601: public MembershipRequest findByUserId_First(long userId,
0602: OrderByComparator obc)
0603: throws NoSuchMembershipRequestException, SystemException {
0604: List list = findByUserId(userId, 0, 1, obc);
0605:
0606: if (list.size() == 0) {
0607: StringMaker msg = new StringMaker();
0608:
0609: msg.append("No MembershipRequest exists with the key {");
0610:
0611: msg.append("userId=" + userId);
0612:
0613: msg.append(StringPool.CLOSE_CURLY_BRACE);
0614:
0615: throw new NoSuchMembershipRequestException(msg.toString());
0616: } else {
0617: return (MembershipRequest) list.get(0);
0618: }
0619: }
0620:
0621: public MembershipRequest findByUserId_Last(long userId,
0622: OrderByComparator obc)
0623: throws NoSuchMembershipRequestException, SystemException {
0624: int count = countByUserId(userId);
0625:
0626: List list = findByUserId(userId, count - 1, count, obc);
0627:
0628: if (list.size() == 0) {
0629: StringMaker msg = new StringMaker();
0630:
0631: msg.append("No MembershipRequest exists with the key {");
0632:
0633: msg.append("userId=" + userId);
0634:
0635: msg.append(StringPool.CLOSE_CURLY_BRACE);
0636:
0637: throw new NoSuchMembershipRequestException(msg.toString());
0638: } else {
0639: return (MembershipRequest) list.get(0);
0640: }
0641: }
0642:
0643: public MembershipRequest[] findByUserId_PrevAndNext(
0644: long membershipRequestId, long userId, OrderByComparator obc)
0645: throws NoSuchMembershipRequestException, SystemException {
0646: MembershipRequest membershipRequest = findByPrimaryKey(membershipRequestId);
0647:
0648: int count = countByUserId(userId);
0649:
0650: Session session = null;
0651:
0652: try {
0653: session = openSession();
0654:
0655: StringMaker query = new StringMaker();
0656:
0657: query
0658: .append("FROM com.liferay.portal.model.MembershipRequest WHERE ");
0659:
0660: query.append("userId = ?");
0661:
0662: query.append(" ");
0663:
0664: if (obc != null) {
0665: query.append("ORDER BY ");
0666: query.append(obc.getOrderBy());
0667: }
0668:
0669: else {
0670: query.append("ORDER BY ");
0671:
0672: query.append("createDate DESC");
0673: }
0674:
0675: Query q = session.createQuery(query.toString());
0676:
0677: int queryPos = 0;
0678:
0679: q.setLong(queryPos++, userId);
0680:
0681: Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
0682: membershipRequest);
0683:
0684: MembershipRequest[] array = new MembershipRequestImpl[3];
0685:
0686: array[0] = (MembershipRequest) objArray[0];
0687: array[1] = (MembershipRequest) objArray[1];
0688: array[2] = (MembershipRequest) objArray[2];
0689:
0690: return array;
0691: } catch (Exception e) {
0692: throw HibernateUtil.processException(e);
0693: } finally {
0694: closeSession(session);
0695: }
0696: }
0697:
0698: public List findByG_S(long groupId, int statusId)
0699: throws SystemException {
0700: boolean finderClassNameCacheEnabled = MembershipRequestModelImpl.CACHE_ENABLED;
0701: String finderClassName = MembershipRequest.class.getName();
0702: String finderMethodName = "findByG_S";
0703: String[] finderParams = new String[] { Long.class.getName(),
0704: Integer.class.getName() };
0705: Object[] finderArgs = new Object[] { new Long(groupId),
0706: new Integer(statusId) };
0707:
0708: Object result = null;
0709:
0710: if (finderClassNameCacheEnabled) {
0711: result = FinderCache.getResult(finderClassName,
0712: finderMethodName, finderParams, finderArgs,
0713: getSessionFactory());
0714: }
0715:
0716: if (result == null) {
0717: Session session = null;
0718:
0719: try {
0720: session = openSession();
0721:
0722: StringMaker query = new StringMaker();
0723:
0724: query
0725: .append("FROM com.liferay.portal.model.MembershipRequest WHERE ");
0726:
0727: query.append("groupId = ?");
0728:
0729: query.append(" AND ");
0730:
0731: query.append("statusId = ?");
0732:
0733: query.append(" ");
0734:
0735: query.append("ORDER BY ");
0736:
0737: query.append("createDate DESC");
0738:
0739: Query q = session.createQuery(query.toString());
0740:
0741: int queryPos = 0;
0742:
0743: q.setLong(queryPos++, groupId);
0744:
0745: q.setInteger(queryPos++, statusId);
0746:
0747: List list = q.list();
0748:
0749: FinderCache.putResult(finderClassNameCacheEnabled,
0750: finderClassName, finderMethodName,
0751: finderParams, finderArgs, list);
0752:
0753: return list;
0754: } catch (Exception e) {
0755: throw HibernateUtil.processException(e);
0756: } finally {
0757: closeSession(session);
0758: }
0759: } else {
0760: return (List) result;
0761: }
0762: }
0763:
0764: public List findByG_S(long groupId, int statusId, int begin, int end)
0765: throws SystemException {
0766: return findByG_S(groupId, statusId, begin, end, null);
0767: }
0768:
0769: public List findByG_S(long groupId, int statusId, int begin,
0770: int end, OrderByComparator obc) throws SystemException {
0771: boolean finderClassNameCacheEnabled = MembershipRequestModelImpl.CACHE_ENABLED;
0772: String finderClassName = MembershipRequest.class.getName();
0773: String finderMethodName = "findByG_S";
0774: String[] finderParams = new String[] { Long.class.getName(),
0775: Integer.class.getName(),
0776:
0777: "java.lang.Integer", "java.lang.Integer",
0778: "com.liferay.portal.kernel.util.OrderByComparator" };
0779: Object[] finderArgs = new Object[] { new Long(groupId),
0780: new Integer(statusId),
0781:
0782: String.valueOf(begin), String.valueOf(end),
0783: String.valueOf(obc) };
0784:
0785: Object result = null;
0786:
0787: if (finderClassNameCacheEnabled) {
0788: result = FinderCache.getResult(finderClassName,
0789: finderMethodName, finderParams, finderArgs,
0790: getSessionFactory());
0791: }
0792:
0793: if (result == null) {
0794: Session session = null;
0795:
0796: try {
0797: session = openSession();
0798:
0799: StringMaker query = new StringMaker();
0800:
0801: query
0802: .append("FROM com.liferay.portal.model.MembershipRequest WHERE ");
0803:
0804: query.append("groupId = ?");
0805:
0806: query.append(" AND ");
0807:
0808: query.append("statusId = ?");
0809:
0810: query.append(" ");
0811:
0812: if (obc != null) {
0813: query.append("ORDER BY ");
0814: query.append(obc.getOrderBy());
0815: }
0816:
0817: else {
0818: query.append("ORDER BY ");
0819:
0820: query.append("createDate DESC");
0821: }
0822:
0823: Query q = session.createQuery(query.toString());
0824:
0825: int queryPos = 0;
0826:
0827: q.setLong(queryPos++, groupId);
0828:
0829: q.setInteger(queryPos++, statusId);
0830:
0831: List list = QueryUtil.list(q, getDialect(), begin, end);
0832:
0833: FinderCache.putResult(finderClassNameCacheEnabled,
0834: finderClassName, finderMethodName,
0835: finderParams, finderArgs, list);
0836:
0837: return list;
0838: } catch (Exception e) {
0839: throw HibernateUtil.processException(e);
0840: } finally {
0841: closeSession(session);
0842: }
0843: } else {
0844: return (List) result;
0845: }
0846: }
0847:
0848: public MembershipRequest findByG_S_First(long groupId,
0849: int statusId, OrderByComparator obc)
0850: throws NoSuchMembershipRequestException, SystemException {
0851: List list = findByG_S(groupId, statusId, 0, 1, obc);
0852:
0853: if (list.size() == 0) {
0854: StringMaker msg = new StringMaker();
0855:
0856: msg.append("No MembershipRequest exists with the key {");
0857:
0858: msg.append("groupId=" + groupId);
0859:
0860: msg.append(", ");
0861: msg.append("statusId=" + statusId);
0862:
0863: msg.append(StringPool.CLOSE_CURLY_BRACE);
0864:
0865: throw new NoSuchMembershipRequestException(msg.toString());
0866: } else {
0867: return (MembershipRequest) list.get(0);
0868: }
0869: }
0870:
0871: public MembershipRequest findByG_S_Last(long groupId, int statusId,
0872: OrderByComparator obc)
0873: throws NoSuchMembershipRequestException, SystemException {
0874: int count = countByG_S(groupId, statusId);
0875:
0876: List list = findByG_S(groupId, statusId, count - 1, count, obc);
0877:
0878: if (list.size() == 0) {
0879: StringMaker msg = new StringMaker();
0880:
0881: msg.append("No MembershipRequest exists with the key {");
0882:
0883: msg.append("groupId=" + groupId);
0884:
0885: msg.append(", ");
0886: msg.append("statusId=" + statusId);
0887:
0888: msg.append(StringPool.CLOSE_CURLY_BRACE);
0889:
0890: throw new NoSuchMembershipRequestException(msg.toString());
0891: } else {
0892: return (MembershipRequest) list.get(0);
0893: }
0894: }
0895:
0896: public MembershipRequest[] findByG_S_PrevAndNext(
0897: long membershipRequestId, long groupId, int statusId,
0898: OrderByComparator obc)
0899: throws NoSuchMembershipRequestException, SystemException {
0900: MembershipRequest membershipRequest = findByPrimaryKey(membershipRequestId);
0901:
0902: int count = countByG_S(groupId, statusId);
0903:
0904: Session session = null;
0905:
0906: try {
0907: session = openSession();
0908:
0909: StringMaker query = new StringMaker();
0910:
0911: query
0912: .append("FROM com.liferay.portal.model.MembershipRequest WHERE ");
0913:
0914: query.append("groupId = ?");
0915:
0916: query.append(" AND ");
0917:
0918: query.append("statusId = ?");
0919:
0920: query.append(" ");
0921:
0922: if (obc != null) {
0923: query.append("ORDER BY ");
0924: query.append(obc.getOrderBy());
0925: }
0926:
0927: else {
0928: query.append("ORDER BY ");
0929:
0930: query.append("createDate DESC");
0931: }
0932:
0933: Query q = session.createQuery(query.toString());
0934:
0935: int queryPos = 0;
0936:
0937: q.setLong(queryPos++, groupId);
0938:
0939: q.setInteger(queryPos++, statusId);
0940:
0941: Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
0942: membershipRequest);
0943:
0944: MembershipRequest[] array = new MembershipRequestImpl[3];
0945:
0946: array[0] = (MembershipRequest) objArray[0];
0947: array[1] = (MembershipRequest) objArray[1];
0948: array[2] = (MembershipRequest) objArray[2];
0949:
0950: return array;
0951: } catch (Exception e) {
0952: throw HibernateUtil.processException(e);
0953: } finally {
0954: closeSession(session);
0955: }
0956: }
0957:
0958: public List findWithDynamicQuery(
0959: DynamicQueryInitializer queryInitializer)
0960: throws SystemException {
0961: Session session = null;
0962:
0963: try {
0964: session = openSession();
0965:
0966: DynamicQuery query = queryInitializer.initialize(session);
0967:
0968: return query.list();
0969: } catch (Exception e) {
0970: throw HibernateUtil.processException(e);
0971: } finally {
0972: closeSession(session);
0973: }
0974: }
0975:
0976: public List findWithDynamicQuery(
0977: DynamicQueryInitializer queryInitializer, int begin, int end)
0978: throws SystemException {
0979: Session session = null;
0980:
0981: try {
0982: session = openSession();
0983:
0984: DynamicQuery query = queryInitializer.initialize(session);
0985:
0986: query.setLimit(begin, end);
0987:
0988: return query.list();
0989: } catch (Exception e) {
0990: throw HibernateUtil.processException(e);
0991: } finally {
0992: closeSession(session);
0993: }
0994: }
0995:
0996: public List findAll() throws SystemException {
0997: return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
0998: }
0999:
1000: public List findAll(int begin, int end) throws SystemException {
1001: return findAll(begin, end, null);
1002: }
1003:
1004: public List findAll(int begin, int end, OrderByComparator obc)
1005: throws SystemException {
1006: boolean finderClassNameCacheEnabled = MembershipRequestModelImpl.CACHE_ENABLED;
1007: String finderClassName = MembershipRequest.class.getName();
1008: String finderMethodName = "findAll";
1009: String[] finderParams = new String[] { "java.lang.Integer",
1010: "java.lang.Integer",
1011: "com.liferay.portal.kernel.util.OrderByComparator" };
1012: Object[] finderArgs = new Object[] { String.valueOf(begin),
1013: String.valueOf(end), String.valueOf(obc) };
1014:
1015: Object result = null;
1016:
1017: if (finderClassNameCacheEnabled) {
1018: result = FinderCache.getResult(finderClassName,
1019: finderMethodName, finderParams, finderArgs,
1020: getSessionFactory());
1021: }
1022:
1023: if (result == null) {
1024: Session session = null;
1025:
1026: try {
1027: session = openSession();
1028:
1029: StringMaker query = new StringMaker();
1030:
1031: query
1032: .append("FROM com.liferay.portal.model.MembershipRequest ");
1033:
1034: if (obc != null) {
1035: query.append("ORDER BY ");
1036: query.append(obc.getOrderBy());
1037: }
1038:
1039: else {
1040: query.append("ORDER BY ");
1041:
1042: query.append("createDate DESC");
1043: }
1044:
1045: Query q = session.createQuery(query.toString());
1046:
1047: List list = QueryUtil.list(q, getDialect(), begin, end);
1048:
1049: if (obc == null) {
1050: Collections.sort(list);
1051: }
1052:
1053: FinderCache.putResult(finderClassNameCacheEnabled,
1054: finderClassName, finderMethodName,
1055: finderParams, finderArgs, list);
1056:
1057: return list;
1058: } catch (Exception e) {
1059: throw HibernateUtil.processException(e);
1060: } finally {
1061: closeSession(session);
1062: }
1063: } else {
1064: return (List) result;
1065: }
1066: }
1067:
1068: public void removeByGroupId(long groupId) throws SystemException {
1069: Iterator itr = findByGroupId(groupId).iterator();
1070:
1071: while (itr.hasNext()) {
1072: MembershipRequest membershipRequest = (MembershipRequest) itr
1073: .next();
1074:
1075: remove(membershipRequest);
1076: }
1077: }
1078:
1079: public void removeByUserId(long userId) throws SystemException {
1080: Iterator itr = findByUserId(userId).iterator();
1081:
1082: while (itr.hasNext()) {
1083: MembershipRequest membershipRequest = (MembershipRequest) itr
1084: .next();
1085:
1086: remove(membershipRequest);
1087: }
1088: }
1089:
1090: public void removeByG_S(long groupId, int statusId)
1091: throws SystemException {
1092: Iterator itr = findByG_S(groupId, statusId).iterator();
1093:
1094: while (itr.hasNext()) {
1095: MembershipRequest membershipRequest = (MembershipRequest) itr
1096: .next();
1097:
1098: remove(membershipRequest);
1099: }
1100: }
1101:
1102: public void removeAll() throws SystemException {
1103: Iterator itr = findAll().iterator();
1104:
1105: while (itr.hasNext()) {
1106: remove((MembershipRequest) itr.next());
1107: }
1108: }
1109:
1110: public int countByGroupId(long groupId) throws SystemException {
1111: boolean finderClassNameCacheEnabled = MembershipRequestModelImpl.CACHE_ENABLED;
1112: String finderClassName = MembershipRequest.class.getName();
1113: String finderMethodName = "countByGroupId";
1114: String[] finderParams = new String[] { Long.class.getName() };
1115: Object[] finderArgs = new Object[] { new Long(groupId) };
1116:
1117: Object result = null;
1118:
1119: if (finderClassNameCacheEnabled) {
1120: result = FinderCache.getResult(finderClassName,
1121: finderMethodName, finderParams, finderArgs,
1122: getSessionFactory());
1123: }
1124:
1125: if (result == null) {
1126: Session session = null;
1127:
1128: try {
1129: session = openSession();
1130:
1131: StringMaker query = new StringMaker();
1132:
1133: query.append("SELECT COUNT(*) ");
1134: query
1135: .append("FROM com.liferay.portal.model.MembershipRequest WHERE ");
1136:
1137: query.append("groupId = ?");
1138:
1139: query.append(" ");
1140:
1141: Query q = session.createQuery(query.toString());
1142:
1143: int queryPos = 0;
1144:
1145: q.setLong(queryPos++, groupId);
1146:
1147: Long count = null;
1148:
1149: Iterator itr = q.list().iterator();
1150:
1151: if (itr.hasNext()) {
1152: count = (Long) itr.next();
1153: }
1154:
1155: if (count == null) {
1156: count = new Long(0);
1157: }
1158:
1159: FinderCache.putResult(finderClassNameCacheEnabled,
1160: finderClassName, finderMethodName,
1161: finderParams, finderArgs, count);
1162:
1163: return count.intValue();
1164: } catch (Exception e) {
1165: throw HibernateUtil.processException(e);
1166: } finally {
1167: closeSession(session);
1168: }
1169: } else {
1170: return ((Long) result).intValue();
1171: }
1172: }
1173:
1174: public int countByUserId(long userId) throws SystemException {
1175: boolean finderClassNameCacheEnabled = MembershipRequestModelImpl.CACHE_ENABLED;
1176: String finderClassName = MembershipRequest.class.getName();
1177: String finderMethodName = "countByUserId";
1178: String[] finderParams = new String[] { Long.class.getName() };
1179: Object[] finderArgs = new Object[] { new Long(userId) };
1180:
1181: Object result = null;
1182:
1183: if (finderClassNameCacheEnabled) {
1184: result = FinderCache.getResult(finderClassName,
1185: finderMethodName, finderParams, finderArgs,
1186: getSessionFactory());
1187: }
1188:
1189: if (result == null) {
1190: Session session = null;
1191:
1192: try {
1193: session = openSession();
1194:
1195: StringMaker query = new StringMaker();
1196:
1197: query.append("SELECT COUNT(*) ");
1198: query
1199: .append("FROM com.liferay.portal.model.MembershipRequest WHERE ");
1200:
1201: query.append("userId = ?");
1202:
1203: query.append(" ");
1204:
1205: Query q = session.createQuery(query.toString());
1206:
1207: int queryPos = 0;
1208:
1209: q.setLong(queryPos++, userId);
1210:
1211: Long count = null;
1212:
1213: Iterator itr = q.list().iterator();
1214:
1215: if (itr.hasNext()) {
1216: count = (Long) itr.next();
1217: }
1218:
1219: if (count == null) {
1220: count = new Long(0);
1221: }
1222:
1223: FinderCache.putResult(finderClassNameCacheEnabled,
1224: finderClassName, finderMethodName,
1225: finderParams, finderArgs, count);
1226:
1227: return count.intValue();
1228: } catch (Exception e) {
1229: throw HibernateUtil.processException(e);
1230: } finally {
1231: closeSession(session);
1232: }
1233: } else {
1234: return ((Long) result).intValue();
1235: }
1236: }
1237:
1238: public int countByG_S(long groupId, int statusId)
1239: throws SystemException {
1240: boolean finderClassNameCacheEnabled = MembershipRequestModelImpl.CACHE_ENABLED;
1241: String finderClassName = MembershipRequest.class.getName();
1242: String finderMethodName = "countByG_S";
1243: String[] finderParams = new String[] { Long.class.getName(),
1244: Integer.class.getName() };
1245: Object[] finderArgs = new Object[] { new Long(groupId),
1246: new Integer(statusId) };
1247:
1248: Object result = null;
1249:
1250: if (finderClassNameCacheEnabled) {
1251: result = FinderCache.getResult(finderClassName,
1252: finderMethodName, finderParams, finderArgs,
1253: getSessionFactory());
1254: }
1255:
1256: if (result == null) {
1257: Session session = null;
1258:
1259: try {
1260: session = openSession();
1261:
1262: StringMaker query = new StringMaker();
1263:
1264: query.append("SELECT COUNT(*) ");
1265: query
1266: .append("FROM com.liferay.portal.model.MembershipRequest WHERE ");
1267:
1268: query.append("groupId = ?");
1269:
1270: query.append(" AND ");
1271:
1272: query.append("statusId = ?");
1273:
1274: query.append(" ");
1275:
1276: Query q = session.createQuery(query.toString());
1277:
1278: int queryPos = 0;
1279:
1280: q.setLong(queryPos++, groupId);
1281:
1282: q.setInteger(queryPos++, statusId);
1283:
1284: Long count = null;
1285:
1286: Iterator itr = q.list().iterator();
1287:
1288: if (itr.hasNext()) {
1289: count = (Long) itr.next();
1290: }
1291:
1292: if (count == null) {
1293: count = new Long(0);
1294: }
1295:
1296: FinderCache.putResult(finderClassNameCacheEnabled,
1297: finderClassName, finderMethodName,
1298: finderParams, finderArgs, count);
1299:
1300: return count.intValue();
1301: } catch (Exception e) {
1302: throw HibernateUtil.processException(e);
1303: } finally {
1304: closeSession(session);
1305: }
1306: } else {
1307: return ((Long) result).intValue();
1308: }
1309: }
1310:
1311: public int countAll() throws SystemException {
1312: boolean finderClassNameCacheEnabled = MembershipRequestModelImpl.CACHE_ENABLED;
1313: String finderClassName = MembershipRequest.class.getName();
1314: String finderMethodName = "countAll";
1315: String[] finderParams = new String[] {};
1316: Object[] finderArgs = new Object[] {};
1317:
1318: Object result = null;
1319:
1320: if (finderClassNameCacheEnabled) {
1321: result = FinderCache.getResult(finderClassName,
1322: finderMethodName, finderParams, finderArgs,
1323: getSessionFactory());
1324: }
1325:
1326: if (result == null) {
1327: Session session = null;
1328:
1329: try {
1330: session = openSession();
1331:
1332: Query q = session
1333: .createQuery("SELECT COUNT(*) FROM com.liferay.portal.model.MembershipRequest");
1334:
1335: Long count = null;
1336:
1337: Iterator itr = q.list().iterator();
1338:
1339: if (itr.hasNext()) {
1340: count = (Long) itr.next();
1341: }
1342:
1343: if (count == null) {
1344: count = new Long(0);
1345: }
1346:
1347: FinderCache.putResult(finderClassNameCacheEnabled,
1348: finderClassName, finderMethodName,
1349: finderParams, finderArgs, count);
1350:
1351: return count.intValue();
1352: } catch (Exception e) {
1353: throw HibernateUtil.processException(e);
1354: } finally {
1355: closeSession(session);
1356: }
1357: } else {
1358: return ((Long) result).intValue();
1359: }
1360: }
1361:
1362: protected void initDao() {
1363: }
1364:
1365: private static ModelListener _getListener() {
1366: if (Validator.isNotNull(_LISTENER)) {
1367: try {
1368: return (ModelListener) Class.forName(_LISTENER)
1369: .newInstance();
1370: } catch (Exception e) {
1371: _log.error(e);
1372: }
1373: }
1374:
1375: return null;
1376: }
1377:
1378: private static final String _LISTENER = GetterUtil
1379: .getString(PropsUtil
1380: .get("value.object.listener.com.liferay.portal.model.MembershipRequest"));
1381: private static Log _log = LogFactory
1382: .getLog(MembershipRequestPersistenceImpl.class);
1383: }
|