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