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.portlet.polls.service.persistence;
0022:
0023: import com.liferay.portal.SystemException;
0024: import com.liferay.portal.kernel.dao.DynamicQuery;
0025: import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
0026: import com.liferay.portal.kernel.util.GetterUtil;
0027: import com.liferay.portal.kernel.util.OrderByComparator;
0028: import com.liferay.portal.kernel.util.StringMaker;
0029: import com.liferay.portal.kernel.util.StringPool;
0030: import com.liferay.portal.kernel.util.Validator;
0031: import com.liferay.portal.model.ModelListener;
0032: import com.liferay.portal.service.persistence.BasePersistence;
0033: import com.liferay.portal.spring.hibernate.FinderCache;
0034: import com.liferay.portal.spring.hibernate.HibernateUtil;
0035: import com.liferay.portal.util.PropsUtil;
0036:
0037: import com.liferay.portlet.polls.NoSuchVoteException;
0038: import com.liferay.portlet.polls.model.PollsVote;
0039: import com.liferay.portlet.polls.model.impl.PollsVoteImpl;
0040: import com.liferay.portlet.polls.model.impl.PollsVoteModelImpl;
0041:
0042: import com.liferay.util.dao.hibernate.QueryUtil;
0043:
0044: import org.apache.commons.logging.Log;
0045: import org.apache.commons.logging.LogFactory;
0046:
0047: import org.hibernate.Query;
0048: import org.hibernate.Session;
0049:
0050: import java.util.Collections;
0051: import java.util.Iterator;
0052: import java.util.List;
0053:
0054: /**
0055: * <a href="PollsVotePersistenceImpl.java.html"><b><i>View Source</i></b></a>
0056: *
0057: * @author Brian Wing Shun Chan
0058: *
0059: */
0060: public class PollsVotePersistenceImpl extends BasePersistence implements
0061: PollsVotePersistence {
0062: public PollsVote create(long voteId) {
0063: PollsVote pollsVote = new PollsVoteImpl();
0064:
0065: pollsVote.setNew(true);
0066: pollsVote.setPrimaryKey(voteId);
0067:
0068: return pollsVote;
0069: }
0070:
0071: public PollsVote remove(long voteId) throws NoSuchVoteException,
0072: SystemException {
0073: Session session = null;
0074:
0075: try {
0076: session = openSession();
0077:
0078: PollsVote pollsVote = (PollsVote) session.get(
0079: PollsVoteImpl.class, new Long(voteId));
0080:
0081: if (pollsVote == null) {
0082: if (_log.isWarnEnabled()) {
0083: _log
0084: .warn("No PollsVote exists with the primary key "
0085: + voteId);
0086: }
0087:
0088: throw new NoSuchVoteException(
0089: "No PollsVote exists with the primary key "
0090: + voteId);
0091: }
0092:
0093: return remove(pollsVote);
0094: } catch (NoSuchVoteException nsee) {
0095: throw nsee;
0096: } catch (Exception e) {
0097: throw HibernateUtil.processException(e);
0098: } finally {
0099: closeSession(session);
0100: }
0101: }
0102:
0103: public PollsVote remove(PollsVote pollsVote) throws SystemException {
0104: ModelListener listener = _getListener();
0105:
0106: if (listener != null) {
0107: listener.onBeforeRemove(pollsVote);
0108: }
0109:
0110: pollsVote = removeImpl(pollsVote);
0111:
0112: if (listener != null) {
0113: listener.onAfterRemove(pollsVote);
0114: }
0115:
0116: return pollsVote;
0117: }
0118:
0119: protected PollsVote removeImpl(PollsVote pollsVote)
0120: throws SystemException {
0121: Session session = null;
0122:
0123: try {
0124: session = openSession();
0125:
0126: session.delete(pollsVote);
0127:
0128: session.flush();
0129:
0130: return pollsVote;
0131: } catch (Exception e) {
0132: throw HibernateUtil.processException(e);
0133: } finally {
0134: closeSession(session);
0135:
0136: FinderCache.clearCache(PollsVote.class.getName());
0137: }
0138: }
0139:
0140: public PollsVote update(PollsVote pollsVote) throws SystemException {
0141: return update(pollsVote, false);
0142: }
0143:
0144: public PollsVote update(PollsVote pollsVote, boolean merge)
0145: throws SystemException {
0146: ModelListener listener = _getListener();
0147:
0148: boolean isNew = pollsVote.isNew();
0149:
0150: if (listener != null) {
0151: if (isNew) {
0152: listener.onBeforeCreate(pollsVote);
0153: } else {
0154: listener.onBeforeUpdate(pollsVote);
0155: }
0156: }
0157:
0158: pollsVote = updateImpl(pollsVote, merge);
0159:
0160: if (listener != null) {
0161: if (isNew) {
0162: listener.onAfterCreate(pollsVote);
0163: } else {
0164: listener.onAfterUpdate(pollsVote);
0165: }
0166: }
0167:
0168: return pollsVote;
0169: }
0170:
0171: public PollsVote updateImpl(
0172: com.liferay.portlet.polls.model.PollsVote pollsVote,
0173: boolean merge) throws SystemException {
0174: Session session = null;
0175:
0176: try {
0177: session = openSession();
0178:
0179: if (merge) {
0180: session.merge(pollsVote);
0181: } else {
0182: if (pollsVote.isNew()) {
0183: session.save(pollsVote);
0184: }
0185: }
0186:
0187: session.flush();
0188:
0189: pollsVote.setNew(false);
0190:
0191: return pollsVote;
0192: } catch (Exception e) {
0193: throw HibernateUtil.processException(e);
0194: } finally {
0195: closeSession(session);
0196:
0197: FinderCache.clearCache(PollsVote.class.getName());
0198: }
0199: }
0200:
0201: public PollsVote findByPrimaryKey(long voteId)
0202: throws NoSuchVoteException, SystemException {
0203: PollsVote pollsVote = fetchByPrimaryKey(voteId);
0204:
0205: if (pollsVote == null) {
0206: if (_log.isWarnEnabled()) {
0207: _log.warn("No PollsVote exists with the primary key "
0208: + voteId);
0209: }
0210:
0211: throw new NoSuchVoteException(
0212: "No PollsVote exists with the primary key "
0213: + voteId);
0214: }
0215:
0216: return pollsVote;
0217: }
0218:
0219: public PollsVote fetchByPrimaryKey(long voteId)
0220: throws SystemException {
0221: Session session = null;
0222:
0223: try {
0224: session = openSession();
0225:
0226: return (PollsVote) session.get(PollsVoteImpl.class,
0227: new Long(voteId));
0228: } catch (Exception e) {
0229: throw HibernateUtil.processException(e);
0230: } finally {
0231: closeSession(session);
0232: }
0233: }
0234:
0235: public List findByQuestionId(long questionId)
0236: throws SystemException {
0237: boolean finderClassNameCacheEnabled = PollsVoteModelImpl.CACHE_ENABLED;
0238: String finderClassName = PollsVote.class.getName();
0239: String finderMethodName = "findByQuestionId";
0240: String[] finderParams = new String[] { Long.class.getName() };
0241: Object[] finderArgs = new Object[] { new Long(questionId) };
0242:
0243: Object result = null;
0244:
0245: if (finderClassNameCacheEnabled) {
0246: result = FinderCache.getResult(finderClassName,
0247: finderMethodName, finderParams, finderArgs,
0248: getSessionFactory());
0249: }
0250:
0251: if (result == null) {
0252: Session session = null;
0253:
0254: try {
0255: session = openSession();
0256:
0257: StringMaker query = new StringMaker();
0258:
0259: query
0260: .append("FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
0261:
0262: query.append("questionId = ?");
0263:
0264: query.append(" ");
0265:
0266: Query q = session.createQuery(query.toString());
0267:
0268: int queryPos = 0;
0269:
0270: q.setLong(queryPos++, questionId);
0271:
0272: List list = q.list();
0273:
0274: FinderCache.putResult(finderClassNameCacheEnabled,
0275: finderClassName, finderMethodName,
0276: finderParams, finderArgs, list);
0277:
0278: return list;
0279: } catch (Exception e) {
0280: throw HibernateUtil.processException(e);
0281: } finally {
0282: closeSession(session);
0283: }
0284: } else {
0285: return (List) result;
0286: }
0287: }
0288:
0289: public List findByQuestionId(long questionId, int begin, int end)
0290: throws SystemException {
0291: return findByQuestionId(questionId, begin, end, null);
0292: }
0293:
0294: public List findByQuestionId(long questionId, int begin, int end,
0295: OrderByComparator obc) throws SystemException {
0296: boolean finderClassNameCacheEnabled = PollsVoteModelImpl.CACHE_ENABLED;
0297: String finderClassName = PollsVote.class.getName();
0298: String finderMethodName = "findByQuestionId";
0299: String[] finderParams = new String[] { Long.class.getName(),
0300:
0301: "java.lang.Integer", "java.lang.Integer",
0302: "com.liferay.portal.kernel.util.OrderByComparator" };
0303: Object[] finderArgs = new Object[] { new Long(questionId),
0304:
0305: String.valueOf(begin), String.valueOf(end), String.valueOf(obc) };
0306:
0307: Object result = null;
0308:
0309: if (finderClassNameCacheEnabled) {
0310: result = FinderCache.getResult(finderClassName,
0311: finderMethodName, finderParams, finderArgs,
0312: getSessionFactory());
0313: }
0314:
0315: if (result == null) {
0316: Session session = null;
0317:
0318: try {
0319: session = openSession();
0320:
0321: StringMaker query = new StringMaker();
0322:
0323: query
0324: .append("FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
0325:
0326: query.append("questionId = ?");
0327:
0328: query.append(" ");
0329:
0330: if (obc != null) {
0331: query.append("ORDER BY ");
0332: query.append(obc.getOrderBy());
0333: }
0334:
0335: Query q = session.createQuery(query.toString());
0336:
0337: int queryPos = 0;
0338:
0339: q.setLong(queryPos++, questionId);
0340:
0341: List list = QueryUtil.list(q, getDialect(), begin, end);
0342:
0343: FinderCache.putResult(finderClassNameCacheEnabled,
0344: finderClassName, finderMethodName,
0345: finderParams, finderArgs, list);
0346:
0347: return list;
0348: } catch (Exception e) {
0349: throw HibernateUtil.processException(e);
0350: } finally {
0351: closeSession(session);
0352: }
0353: } else {
0354: return (List) result;
0355: }
0356: }
0357:
0358: public PollsVote findByQuestionId_First(long questionId,
0359: OrderByComparator obc) throws NoSuchVoteException,
0360: SystemException {
0361: List list = findByQuestionId(questionId, 0, 1, obc);
0362:
0363: if (list.size() == 0) {
0364: StringMaker msg = new StringMaker();
0365:
0366: msg.append("No PollsVote exists with the key {");
0367:
0368: msg.append("questionId=" + questionId);
0369:
0370: msg.append(StringPool.CLOSE_CURLY_BRACE);
0371:
0372: throw new NoSuchVoteException(msg.toString());
0373: } else {
0374: return (PollsVote) list.get(0);
0375: }
0376: }
0377:
0378: public PollsVote findByQuestionId_Last(long questionId,
0379: OrderByComparator obc) throws NoSuchVoteException,
0380: SystemException {
0381: int count = countByQuestionId(questionId);
0382:
0383: List list = findByQuestionId(questionId, count - 1, count, obc);
0384:
0385: if (list.size() == 0) {
0386: StringMaker msg = new StringMaker();
0387:
0388: msg.append("No PollsVote exists with the key {");
0389:
0390: msg.append("questionId=" + questionId);
0391:
0392: msg.append(StringPool.CLOSE_CURLY_BRACE);
0393:
0394: throw new NoSuchVoteException(msg.toString());
0395: } else {
0396: return (PollsVote) list.get(0);
0397: }
0398: }
0399:
0400: public PollsVote[] findByQuestionId_PrevAndNext(long voteId,
0401: long questionId, OrderByComparator obc)
0402: throws NoSuchVoteException, SystemException {
0403: PollsVote pollsVote = findByPrimaryKey(voteId);
0404:
0405: int count = countByQuestionId(questionId);
0406:
0407: Session session = null;
0408:
0409: try {
0410: session = openSession();
0411:
0412: StringMaker query = new StringMaker();
0413:
0414: query
0415: .append("FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
0416:
0417: query.append("questionId = ?");
0418:
0419: query.append(" ");
0420:
0421: if (obc != null) {
0422: query.append("ORDER BY ");
0423: query.append(obc.getOrderBy());
0424: }
0425:
0426: Query q = session.createQuery(query.toString());
0427:
0428: int queryPos = 0;
0429:
0430: q.setLong(queryPos++, questionId);
0431:
0432: Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
0433: pollsVote);
0434:
0435: PollsVote[] array = new PollsVoteImpl[3];
0436:
0437: array[0] = (PollsVote) objArray[0];
0438: array[1] = (PollsVote) objArray[1];
0439: array[2] = (PollsVote) objArray[2];
0440:
0441: return array;
0442: } catch (Exception e) {
0443: throw HibernateUtil.processException(e);
0444: } finally {
0445: closeSession(session);
0446: }
0447: }
0448:
0449: public List findByChoiceId(long choiceId) throws SystemException {
0450: boolean finderClassNameCacheEnabled = PollsVoteModelImpl.CACHE_ENABLED;
0451: String finderClassName = PollsVote.class.getName();
0452: String finderMethodName = "findByChoiceId";
0453: String[] finderParams = new String[] { Long.class.getName() };
0454: Object[] finderArgs = new Object[] { new Long(choiceId) };
0455:
0456: Object result = null;
0457:
0458: if (finderClassNameCacheEnabled) {
0459: result = FinderCache.getResult(finderClassName,
0460: finderMethodName, finderParams, finderArgs,
0461: getSessionFactory());
0462: }
0463:
0464: if (result == null) {
0465: Session session = null;
0466:
0467: try {
0468: session = openSession();
0469:
0470: StringMaker query = new StringMaker();
0471:
0472: query
0473: .append("FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
0474:
0475: query.append("choiceId = ?");
0476:
0477: query.append(" ");
0478:
0479: Query q = session.createQuery(query.toString());
0480:
0481: int queryPos = 0;
0482:
0483: q.setLong(queryPos++, choiceId);
0484:
0485: List list = q.list();
0486:
0487: FinderCache.putResult(finderClassNameCacheEnabled,
0488: finderClassName, finderMethodName,
0489: finderParams, finderArgs, list);
0490:
0491: return list;
0492: } catch (Exception e) {
0493: throw HibernateUtil.processException(e);
0494: } finally {
0495: closeSession(session);
0496: }
0497: } else {
0498: return (List) result;
0499: }
0500: }
0501:
0502: public List findByChoiceId(long choiceId, int begin, int end)
0503: throws SystemException {
0504: return findByChoiceId(choiceId, begin, end, null);
0505: }
0506:
0507: public List findByChoiceId(long choiceId, int begin, int end,
0508: OrderByComparator obc) throws SystemException {
0509: boolean finderClassNameCacheEnabled = PollsVoteModelImpl.CACHE_ENABLED;
0510: String finderClassName = PollsVote.class.getName();
0511: String finderMethodName = "findByChoiceId";
0512: String[] finderParams = new String[] { Long.class.getName(),
0513:
0514: "java.lang.Integer", "java.lang.Integer",
0515: "com.liferay.portal.kernel.util.OrderByComparator" };
0516: Object[] finderArgs = new Object[] { new Long(choiceId),
0517:
0518: String.valueOf(begin), String.valueOf(end), String.valueOf(obc) };
0519:
0520: Object result = null;
0521:
0522: if (finderClassNameCacheEnabled) {
0523: result = FinderCache.getResult(finderClassName,
0524: finderMethodName, finderParams, finderArgs,
0525: getSessionFactory());
0526: }
0527:
0528: if (result == null) {
0529: Session session = null;
0530:
0531: try {
0532: session = openSession();
0533:
0534: StringMaker query = new StringMaker();
0535:
0536: query
0537: .append("FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
0538:
0539: query.append("choiceId = ?");
0540:
0541: query.append(" ");
0542:
0543: if (obc != null) {
0544: query.append("ORDER BY ");
0545: query.append(obc.getOrderBy());
0546: }
0547:
0548: Query q = session.createQuery(query.toString());
0549:
0550: int queryPos = 0;
0551:
0552: q.setLong(queryPos++, choiceId);
0553:
0554: List list = QueryUtil.list(q, getDialect(), begin, end);
0555:
0556: FinderCache.putResult(finderClassNameCacheEnabled,
0557: finderClassName, finderMethodName,
0558: finderParams, finderArgs, list);
0559:
0560: return list;
0561: } catch (Exception e) {
0562: throw HibernateUtil.processException(e);
0563: } finally {
0564: closeSession(session);
0565: }
0566: } else {
0567: return (List) result;
0568: }
0569: }
0570:
0571: public PollsVote findByChoiceId_First(long choiceId,
0572: OrderByComparator obc) throws NoSuchVoteException,
0573: SystemException {
0574: List list = findByChoiceId(choiceId, 0, 1, obc);
0575:
0576: if (list.size() == 0) {
0577: StringMaker msg = new StringMaker();
0578:
0579: msg.append("No PollsVote exists with the key {");
0580:
0581: msg.append("choiceId=" + choiceId);
0582:
0583: msg.append(StringPool.CLOSE_CURLY_BRACE);
0584:
0585: throw new NoSuchVoteException(msg.toString());
0586: } else {
0587: return (PollsVote) list.get(0);
0588: }
0589: }
0590:
0591: public PollsVote findByChoiceId_Last(long choiceId,
0592: OrderByComparator obc) throws NoSuchVoteException,
0593: SystemException {
0594: int count = countByChoiceId(choiceId);
0595:
0596: List list = findByChoiceId(choiceId, count - 1, count, obc);
0597:
0598: if (list.size() == 0) {
0599: StringMaker msg = new StringMaker();
0600:
0601: msg.append("No PollsVote exists with the key {");
0602:
0603: msg.append("choiceId=" + choiceId);
0604:
0605: msg.append(StringPool.CLOSE_CURLY_BRACE);
0606:
0607: throw new NoSuchVoteException(msg.toString());
0608: } else {
0609: return (PollsVote) list.get(0);
0610: }
0611: }
0612:
0613: public PollsVote[] findByChoiceId_PrevAndNext(long voteId,
0614: long choiceId, OrderByComparator obc)
0615: throws NoSuchVoteException, SystemException {
0616: PollsVote pollsVote = findByPrimaryKey(voteId);
0617:
0618: int count = countByChoiceId(choiceId);
0619:
0620: Session session = null;
0621:
0622: try {
0623: session = openSession();
0624:
0625: StringMaker query = new StringMaker();
0626:
0627: query
0628: .append("FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
0629:
0630: query.append("choiceId = ?");
0631:
0632: query.append(" ");
0633:
0634: if (obc != null) {
0635: query.append("ORDER BY ");
0636: query.append(obc.getOrderBy());
0637: }
0638:
0639: Query q = session.createQuery(query.toString());
0640:
0641: int queryPos = 0;
0642:
0643: q.setLong(queryPos++, choiceId);
0644:
0645: Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
0646: pollsVote);
0647:
0648: PollsVote[] array = new PollsVoteImpl[3];
0649:
0650: array[0] = (PollsVote) objArray[0];
0651: array[1] = (PollsVote) objArray[1];
0652: array[2] = (PollsVote) objArray[2];
0653:
0654: return array;
0655: } catch (Exception e) {
0656: throw HibernateUtil.processException(e);
0657: } finally {
0658: closeSession(session);
0659: }
0660: }
0661:
0662: public PollsVote findByQ_U(long questionId, long userId)
0663: throws NoSuchVoteException, SystemException {
0664: PollsVote pollsVote = fetchByQ_U(questionId, userId);
0665:
0666: if (pollsVote == null) {
0667: StringMaker msg = new StringMaker();
0668:
0669: msg.append("No PollsVote exists with the key {");
0670:
0671: msg.append("questionId=" + questionId);
0672:
0673: msg.append(", ");
0674: msg.append("userId=" + userId);
0675:
0676: msg.append(StringPool.CLOSE_CURLY_BRACE);
0677:
0678: if (_log.isWarnEnabled()) {
0679: _log.warn(msg.toString());
0680: }
0681:
0682: throw new NoSuchVoteException(msg.toString());
0683: }
0684:
0685: return pollsVote;
0686: }
0687:
0688: public PollsVote fetchByQ_U(long questionId, long userId)
0689: throws SystemException {
0690: boolean finderClassNameCacheEnabled = PollsVoteModelImpl.CACHE_ENABLED;
0691: String finderClassName = PollsVote.class.getName();
0692: String finderMethodName = "fetchByQ_U";
0693: String[] finderParams = new String[] { Long.class.getName(),
0694: Long.class.getName() };
0695: Object[] finderArgs = new Object[] { new Long(questionId),
0696: new Long(userId) };
0697:
0698: Object result = null;
0699:
0700: if (finderClassNameCacheEnabled) {
0701: result = FinderCache.getResult(finderClassName,
0702: finderMethodName, finderParams, finderArgs,
0703: getSessionFactory());
0704: }
0705:
0706: if (result == null) {
0707: Session session = null;
0708:
0709: try {
0710: session = openSession();
0711:
0712: StringMaker query = new StringMaker();
0713:
0714: query
0715: .append("FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
0716:
0717: query.append("questionId = ?");
0718:
0719: query.append(" AND ");
0720:
0721: query.append("userId = ?");
0722:
0723: query.append(" ");
0724:
0725: Query q = session.createQuery(query.toString());
0726:
0727: int queryPos = 0;
0728:
0729: q.setLong(queryPos++, questionId);
0730:
0731: q.setLong(queryPos++, userId);
0732:
0733: List list = q.list();
0734:
0735: FinderCache.putResult(finderClassNameCacheEnabled,
0736: finderClassName, finderMethodName,
0737: finderParams, finderArgs, list);
0738:
0739: if (list.size() == 0) {
0740: return null;
0741: } else {
0742: return (PollsVote) list.get(0);
0743: }
0744: } catch (Exception e) {
0745: throw HibernateUtil.processException(e);
0746: } finally {
0747: closeSession(session);
0748: }
0749: } else {
0750: List list = (List) result;
0751:
0752: if (list.size() == 0) {
0753: return null;
0754: } else {
0755: return (PollsVote) list.get(0);
0756: }
0757: }
0758: }
0759:
0760: public List findWithDynamicQuery(
0761: DynamicQueryInitializer queryInitializer)
0762: throws SystemException {
0763: Session session = null;
0764:
0765: try {
0766: session = openSession();
0767:
0768: DynamicQuery query = queryInitializer.initialize(session);
0769:
0770: return query.list();
0771: } catch (Exception e) {
0772: throw HibernateUtil.processException(e);
0773: } finally {
0774: closeSession(session);
0775: }
0776: }
0777:
0778: public List findWithDynamicQuery(
0779: DynamicQueryInitializer queryInitializer, int begin, int end)
0780: throws SystemException {
0781: Session session = null;
0782:
0783: try {
0784: session = openSession();
0785:
0786: DynamicQuery query = queryInitializer.initialize(session);
0787:
0788: query.setLimit(begin, end);
0789:
0790: return query.list();
0791: } catch (Exception e) {
0792: throw HibernateUtil.processException(e);
0793: } finally {
0794: closeSession(session);
0795: }
0796: }
0797:
0798: public List findAll() throws SystemException {
0799: return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
0800: }
0801:
0802: public List findAll(int begin, int end) throws SystemException {
0803: return findAll(begin, end, null);
0804: }
0805:
0806: public List findAll(int begin, int end, OrderByComparator obc)
0807: throws SystemException {
0808: boolean finderClassNameCacheEnabled = PollsVoteModelImpl.CACHE_ENABLED;
0809: String finderClassName = PollsVote.class.getName();
0810: String finderMethodName = "findAll";
0811: String[] finderParams = new String[] { "java.lang.Integer",
0812: "java.lang.Integer",
0813: "com.liferay.portal.kernel.util.OrderByComparator" };
0814: Object[] finderArgs = new Object[] { String.valueOf(begin),
0815: String.valueOf(end), String.valueOf(obc) };
0816:
0817: Object result = null;
0818:
0819: if (finderClassNameCacheEnabled) {
0820: result = FinderCache.getResult(finderClassName,
0821: finderMethodName, finderParams, finderArgs,
0822: getSessionFactory());
0823: }
0824:
0825: if (result == null) {
0826: Session session = null;
0827:
0828: try {
0829: session = openSession();
0830:
0831: StringMaker query = new StringMaker();
0832:
0833: query
0834: .append("FROM com.liferay.portlet.polls.model.PollsVote ");
0835:
0836: if (obc != null) {
0837: query.append("ORDER BY ");
0838: query.append(obc.getOrderBy());
0839: }
0840:
0841: Query q = session.createQuery(query.toString());
0842:
0843: List list = QueryUtil.list(q, getDialect(), begin, end);
0844:
0845: if (obc == null) {
0846: Collections.sort(list);
0847: }
0848:
0849: FinderCache.putResult(finderClassNameCacheEnabled,
0850: finderClassName, finderMethodName,
0851: finderParams, finderArgs, list);
0852:
0853: return list;
0854: } catch (Exception e) {
0855: throw HibernateUtil.processException(e);
0856: } finally {
0857: closeSession(session);
0858: }
0859: } else {
0860: return (List) result;
0861: }
0862: }
0863:
0864: public void removeByQuestionId(long questionId)
0865: throws SystemException {
0866: Iterator itr = findByQuestionId(questionId).iterator();
0867:
0868: while (itr.hasNext()) {
0869: PollsVote pollsVote = (PollsVote) itr.next();
0870:
0871: remove(pollsVote);
0872: }
0873: }
0874:
0875: public void removeByChoiceId(long choiceId) throws SystemException {
0876: Iterator itr = findByChoiceId(choiceId).iterator();
0877:
0878: while (itr.hasNext()) {
0879: PollsVote pollsVote = (PollsVote) itr.next();
0880:
0881: remove(pollsVote);
0882: }
0883: }
0884:
0885: public void removeByQ_U(long questionId, long userId)
0886: throws NoSuchVoteException, SystemException {
0887: PollsVote pollsVote = findByQ_U(questionId, userId);
0888:
0889: remove(pollsVote);
0890: }
0891:
0892: public void removeAll() throws SystemException {
0893: Iterator itr = findAll().iterator();
0894:
0895: while (itr.hasNext()) {
0896: remove((PollsVote) itr.next());
0897: }
0898: }
0899:
0900: public int countByQuestionId(long questionId)
0901: throws SystemException {
0902: boolean finderClassNameCacheEnabled = PollsVoteModelImpl.CACHE_ENABLED;
0903: String finderClassName = PollsVote.class.getName();
0904: String finderMethodName = "countByQuestionId";
0905: String[] finderParams = new String[] { Long.class.getName() };
0906: Object[] finderArgs = new Object[] { new Long(questionId) };
0907:
0908: Object result = null;
0909:
0910: if (finderClassNameCacheEnabled) {
0911: result = FinderCache.getResult(finderClassName,
0912: finderMethodName, finderParams, finderArgs,
0913: getSessionFactory());
0914: }
0915:
0916: if (result == null) {
0917: Session session = null;
0918:
0919: try {
0920: session = openSession();
0921:
0922: StringMaker query = new StringMaker();
0923:
0924: query.append("SELECT COUNT(*) ");
0925: query
0926: .append("FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
0927:
0928: query.append("questionId = ?");
0929:
0930: query.append(" ");
0931:
0932: Query q = session.createQuery(query.toString());
0933:
0934: int queryPos = 0;
0935:
0936: q.setLong(queryPos++, questionId);
0937:
0938: Long count = null;
0939:
0940: Iterator itr = q.list().iterator();
0941:
0942: if (itr.hasNext()) {
0943: count = (Long) itr.next();
0944: }
0945:
0946: if (count == null) {
0947: count = new Long(0);
0948: }
0949:
0950: FinderCache.putResult(finderClassNameCacheEnabled,
0951: finderClassName, finderMethodName,
0952: finderParams, finderArgs, count);
0953:
0954: return count.intValue();
0955: } catch (Exception e) {
0956: throw HibernateUtil.processException(e);
0957: } finally {
0958: closeSession(session);
0959: }
0960: } else {
0961: return ((Long) result).intValue();
0962: }
0963: }
0964:
0965: public int countByChoiceId(long choiceId) throws SystemException {
0966: boolean finderClassNameCacheEnabled = PollsVoteModelImpl.CACHE_ENABLED;
0967: String finderClassName = PollsVote.class.getName();
0968: String finderMethodName = "countByChoiceId";
0969: String[] finderParams = new String[] { Long.class.getName() };
0970: Object[] finderArgs = new Object[] { new Long(choiceId) };
0971:
0972: Object result = null;
0973:
0974: if (finderClassNameCacheEnabled) {
0975: result = FinderCache.getResult(finderClassName,
0976: finderMethodName, finderParams, finderArgs,
0977: getSessionFactory());
0978: }
0979:
0980: if (result == null) {
0981: Session session = null;
0982:
0983: try {
0984: session = openSession();
0985:
0986: StringMaker query = new StringMaker();
0987:
0988: query.append("SELECT COUNT(*) ");
0989: query
0990: .append("FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
0991:
0992: query.append("choiceId = ?");
0993:
0994: query.append(" ");
0995:
0996: Query q = session.createQuery(query.toString());
0997:
0998: int queryPos = 0;
0999:
1000: q.setLong(queryPos++, choiceId);
1001:
1002: Long count = null;
1003:
1004: Iterator itr = q.list().iterator();
1005:
1006: if (itr.hasNext()) {
1007: count = (Long) itr.next();
1008: }
1009:
1010: if (count == null) {
1011: count = new Long(0);
1012: }
1013:
1014: FinderCache.putResult(finderClassNameCacheEnabled,
1015: finderClassName, finderMethodName,
1016: finderParams, finderArgs, count);
1017:
1018: return count.intValue();
1019: } catch (Exception e) {
1020: throw HibernateUtil.processException(e);
1021: } finally {
1022: closeSession(session);
1023: }
1024: } else {
1025: return ((Long) result).intValue();
1026: }
1027: }
1028:
1029: public int countByQ_U(long questionId, long userId)
1030: throws SystemException {
1031: boolean finderClassNameCacheEnabled = PollsVoteModelImpl.CACHE_ENABLED;
1032: String finderClassName = PollsVote.class.getName();
1033: String finderMethodName = "countByQ_U";
1034: String[] finderParams = new String[] { Long.class.getName(),
1035: Long.class.getName() };
1036: Object[] finderArgs = new Object[] { new Long(questionId),
1037: new Long(userId) };
1038:
1039: Object result = null;
1040:
1041: if (finderClassNameCacheEnabled) {
1042: result = FinderCache.getResult(finderClassName,
1043: finderMethodName, finderParams, finderArgs,
1044: getSessionFactory());
1045: }
1046:
1047: if (result == null) {
1048: Session session = null;
1049:
1050: try {
1051: session = openSession();
1052:
1053: StringMaker query = new StringMaker();
1054:
1055: query.append("SELECT COUNT(*) ");
1056: query
1057: .append("FROM com.liferay.portlet.polls.model.PollsVote WHERE ");
1058:
1059: query.append("questionId = ?");
1060:
1061: query.append(" AND ");
1062:
1063: query.append("userId = ?");
1064:
1065: query.append(" ");
1066:
1067: Query q = session.createQuery(query.toString());
1068:
1069: int queryPos = 0;
1070:
1071: q.setLong(queryPos++, questionId);
1072:
1073: q.setLong(queryPos++, userId);
1074:
1075: Long count = null;
1076:
1077: Iterator itr = q.list().iterator();
1078:
1079: if (itr.hasNext()) {
1080: count = (Long) itr.next();
1081: }
1082:
1083: if (count == null) {
1084: count = new Long(0);
1085: }
1086:
1087: FinderCache.putResult(finderClassNameCacheEnabled,
1088: finderClassName, finderMethodName,
1089: finderParams, finderArgs, count);
1090:
1091: return count.intValue();
1092: } catch (Exception e) {
1093: throw HibernateUtil.processException(e);
1094: } finally {
1095: closeSession(session);
1096: }
1097: } else {
1098: return ((Long) result).intValue();
1099: }
1100: }
1101:
1102: public int countAll() throws SystemException {
1103: boolean finderClassNameCacheEnabled = PollsVoteModelImpl.CACHE_ENABLED;
1104: String finderClassName = PollsVote.class.getName();
1105: String finderMethodName = "countAll";
1106: String[] finderParams = new String[] {};
1107: Object[] finderArgs = new Object[] {};
1108:
1109: Object result = null;
1110:
1111: if (finderClassNameCacheEnabled) {
1112: result = FinderCache.getResult(finderClassName,
1113: finderMethodName, finderParams, finderArgs,
1114: getSessionFactory());
1115: }
1116:
1117: if (result == null) {
1118: Session session = null;
1119:
1120: try {
1121: session = openSession();
1122:
1123: Query q = session
1124: .createQuery("SELECT COUNT(*) FROM com.liferay.portlet.polls.model.PollsVote");
1125:
1126: Long count = null;
1127:
1128: Iterator itr = q.list().iterator();
1129:
1130: if (itr.hasNext()) {
1131: count = (Long) itr.next();
1132: }
1133:
1134: if (count == null) {
1135: count = new Long(0);
1136: }
1137:
1138: FinderCache.putResult(finderClassNameCacheEnabled,
1139: finderClassName, finderMethodName,
1140: finderParams, finderArgs, count);
1141:
1142: return count.intValue();
1143: } catch (Exception e) {
1144: throw HibernateUtil.processException(e);
1145: } finally {
1146: closeSession(session);
1147: }
1148: } else {
1149: return ((Long) result).intValue();
1150: }
1151: }
1152:
1153: protected void initDao() {
1154: }
1155:
1156: private static ModelListener _getListener() {
1157: if (Validator.isNotNull(_LISTENER)) {
1158: try {
1159: return (ModelListener) Class.forName(_LISTENER)
1160: .newInstance();
1161: } catch (Exception e) {
1162: _log.error(e);
1163: }
1164: }
1165:
1166: return null;
1167: }
1168:
1169: private static final String _LISTENER = GetterUtil
1170: .getString(PropsUtil
1171: .get("value.object.listener.com.liferay.portlet.polls.model.PollsVote"));
1172: private static Log _log = LogFactory
1173: .getLog(PollsVotePersistenceImpl.class);
1174: }
|