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