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.messageboards.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.messageboards.NoSuchMessageException;
0039: import com.liferay.portlet.messageboards.model.MBMessage;
0040: import com.liferay.portlet.messageboards.model.impl.MBMessageImpl;
0041: import com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl;
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="MBMessagePersistenceImpl.java.html"><b><i>View Source</i></b></a>
0057: *
0058: * @author Brian Wing Shun Chan
0059: *
0060: */
0061: public class MBMessagePersistenceImpl extends BasePersistence implements
0062: MBMessagePersistence {
0063: public MBMessage create(long messageId) {
0064: MBMessage mbMessage = new MBMessageImpl();
0065:
0066: mbMessage.setNew(true);
0067: mbMessage.setPrimaryKey(messageId);
0068:
0069: String uuid = PortalUUIDUtil.generate();
0070:
0071: mbMessage.setUuid(uuid);
0072:
0073: return mbMessage;
0074: }
0075:
0076: public MBMessage remove(long messageId)
0077: throws NoSuchMessageException, SystemException {
0078: Session session = null;
0079:
0080: try {
0081: session = openSession();
0082:
0083: MBMessage mbMessage = (MBMessage) session.get(
0084: MBMessageImpl.class, new Long(messageId));
0085:
0086: if (mbMessage == null) {
0087: if (_log.isWarnEnabled()) {
0088: _log
0089: .warn("No MBMessage exists with the primary key "
0090: + messageId);
0091: }
0092:
0093: throw new NoSuchMessageException(
0094: "No MBMessage exists with the primary key "
0095: + messageId);
0096: }
0097:
0098: return remove(mbMessage);
0099: } catch (NoSuchMessageException nsee) {
0100: throw nsee;
0101: } catch (Exception e) {
0102: throw HibernateUtil.processException(e);
0103: } finally {
0104: closeSession(session);
0105: }
0106: }
0107:
0108: public MBMessage remove(MBMessage mbMessage) throws SystemException {
0109: ModelListener listener = _getListener();
0110:
0111: if (listener != null) {
0112: listener.onBeforeRemove(mbMessage);
0113: }
0114:
0115: mbMessage = removeImpl(mbMessage);
0116:
0117: if (listener != null) {
0118: listener.onAfterRemove(mbMessage);
0119: }
0120:
0121: return mbMessage;
0122: }
0123:
0124: protected MBMessage removeImpl(MBMessage mbMessage)
0125: throws SystemException {
0126: Session session = null;
0127:
0128: try {
0129: session = openSession();
0130:
0131: session.delete(mbMessage);
0132:
0133: session.flush();
0134:
0135: return mbMessage;
0136: } catch (Exception e) {
0137: throw HibernateUtil.processException(e);
0138: } finally {
0139: closeSession(session);
0140:
0141: FinderCache.clearCache(MBMessage.class.getName());
0142: }
0143: }
0144:
0145: public MBMessage update(MBMessage mbMessage) throws SystemException {
0146: return update(mbMessage, false);
0147: }
0148:
0149: public MBMessage update(MBMessage mbMessage, boolean merge)
0150: throws SystemException {
0151: ModelListener listener = _getListener();
0152:
0153: boolean isNew = mbMessage.isNew();
0154:
0155: if (listener != null) {
0156: if (isNew) {
0157: listener.onBeforeCreate(mbMessage);
0158: } else {
0159: listener.onBeforeUpdate(mbMessage);
0160: }
0161: }
0162:
0163: mbMessage = updateImpl(mbMessage, merge);
0164:
0165: if (listener != null) {
0166: if (isNew) {
0167: listener.onAfterCreate(mbMessage);
0168: } else {
0169: listener.onAfterUpdate(mbMessage);
0170: }
0171: }
0172:
0173: return mbMessage;
0174: }
0175:
0176: public MBMessage updateImpl(
0177: com.liferay.portlet.messageboards.model.MBMessage mbMessage,
0178: boolean merge) throws SystemException {
0179: if (Validator.isNull(mbMessage.getUuid())) {
0180: String uuid = PortalUUIDUtil.generate();
0181:
0182: mbMessage.setUuid(uuid);
0183: }
0184:
0185: Session session = null;
0186:
0187: try {
0188: session = openSession();
0189:
0190: if (merge) {
0191: session.merge(mbMessage);
0192: } else {
0193: if (mbMessage.isNew()) {
0194: session.save(mbMessage);
0195: }
0196: }
0197:
0198: session.flush();
0199:
0200: mbMessage.setNew(false);
0201:
0202: return mbMessage;
0203: } catch (Exception e) {
0204: throw HibernateUtil.processException(e);
0205: } finally {
0206: closeSession(session);
0207:
0208: FinderCache.clearCache(MBMessage.class.getName());
0209: }
0210: }
0211:
0212: public MBMessage findByPrimaryKey(long messageId)
0213: throws NoSuchMessageException, SystemException {
0214: MBMessage mbMessage = fetchByPrimaryKey(messageId);
0215:
0216: if (mbMessage == null) {
0217: if (_log.isWarnEnabled()) {
0218: _log.warn("No MBMessage exists with the primary key "
0219: + messageId);
0220: }
0221:
0222: throw new NoSuchMessageException(
0223: "No MBMessage exists with the primary key "
0224: + messageId);
0225: }
0226:
0227: return mbMessage;
0228: }
0229:
0230: public MBMessage fetchByPrimaryKey(long messageId)
0231: throws SystemException {
0232: Session session = null;
0233:
0234: try {
0235: session = openSession();
0236:
0237: return (MBMessage) session.get(MBMessageImpl.class,
0238: new Long(messageId));
0239: } catch (Exception e) {
0240: throw HibernateUtil.processException(e);
0241: } finally {
0242: closeSession(session);
0243: }
0244: }
0245:
0246: public List findByUuid(String uuid) throws SystemException {
0247: boolean finderClassNameCacheEnabled = MBMessageModelImpl.CACHE_ENABLED;
0248: String finderClassName = MBMessage.class.getName();
0249: String finderMethodName = "findByUuid";
0250: String[] finderParams = new String[] { String.class.getName() };
0251: Object[] finderArgs = new Object[] { uuid };
0252:
0253: Object result = null;
0254:
0255: if (finderClassNameCacheEnabled) {
0256: result = FinderCache.getResult(finderClassName,
0257: finderMethodName, finderParams, finderArgs,
0258: getSessionFactory());
0259: }
0260:
0261: if (result == null) {
0262: Session session = null;
0263:
0264: try {
0265: session = openSession();
0266:
0267: StringMaker query = new StringMaker();
0268:
0269: query
0270: .append("FROM com.liferay.portlet.messageboards.model.MBMessage WHERE ");
0271:
0272: if (uuid == null) {
0273: query.append("uuid_ IS NULL");
0274: } else {
0275: query.append("uuid_ = ?");
0276: }
0277:
0278: query.append(" ");
0279:
0280: query.append("ORDER BY ");
0281:
0282: query.append("createDate ASC, ");
0283: query.append("messageId ASC");
0284:
0285: Query q = session.createQuery(query.toString());
0286:
0287: int queryPos = 0;
0288:
0289: if (uuid != null) {
0290: q.setString(queryPos++, uuid);
0291: }
0292:
0293: List list = q.list();
0294:
0295: FinderCache.putResult(finderClassNameCacheEnabled,
0296: finderClassName, finderMethodName,
0297: finderParams, finderArgs, list);
0298:
0299: return list;
0300: } catch (Exception e) {
0301: throw HibernateUtil.processException(e);
0302: } finally {
0303: closeSession(session);
0304: }
0305: } else {
0306: return (List) result;
0307: }
0308: }
0309:
0310: public List findByUuid(String uuid, int begin, int end)
0311: throws SystemException {
0312: return findByUuid(uuid, begin, end, null);
0313: }
0314:
0315: public List findByUuid(String uuid, int begin, int end,
0316: OrderByComparator obc) throws SystemException {
0317: boolean finderClassNameCacheEnabled = MBMessageModelImpl.CACHE_ENABLED;
0318: String finderClassName = MBMessage.class.getName();
0319: String finderMethodName = "findByUuid";
0320: String[] finderParams = new String[] { String.class.getName(),
0321:
0322: "java.lang.Integer", "java.lang.Integer",
0323: "com.liferay.portal.kernel.util.OrderByComparator" };
0324: Object[] finderArgs = new Object[] { uuid,
0325:
0326: String.valueOf(begin), String.valueOf(end), String.valueOf(obc) };
0327:
0328: Object result = null;
0329:
0330: if (finderClassNameCacheEnabled) {
0331: result = FinderCache.getResult(finderClassName,
0332: finderMethodName, finderParams, finderArgs,
0333: getSessionFactory());
0334: }
0335:
0336: if (result == null) {
0337: Session session = null;
0338:
0339: try {
0340: session = openSession();
0341:
0342: StringMaker query = new StringMaker();
0343:
0344: query
0345: .append("FROM com.liferay.portlet.messageboards.model.MBMessage WHERE ");
0346:
0347: if (uuid == null) {
0348: query.append("uuid_ IS NULL");
0349: } else {
0350: query.append("uuid_ = ?");
0351: }
0352:
0353: query.append(" ");
0354:
0355: if (obc != null) {
0356: query.append("ORDER BY ");
0357: query.append(obc.getOrderBy());
0358: }
0359:
0360: else {
0361: query.append("ORDER BY ");
0362:
0363: query.append("createDate ASC, ");
0364: query.append("messageId ASC");
0365: }
0366:
0367: Query q = session.createQuery(query.toString());
0368:
0369: int queryPos = 0;
0370:
0371: if (uuid != null) {
0372: q.setString(queryPos++, uuid);
0373: }
0374:
0375: List list = QueryUtil.list(q, getDialect(), begin, end);
0376:
0377: FinderCache.putResult(finderClassNameCacheEnabled,
0378: finderClassName, finderMethodName,
0379: finderParams, finderArgs, list);
0380:
0381: return list;
0382: } catch (Exception e) {
0383: throw HibernateUtil.processException(e);
0384: } finally {
0385: closeSession(session);
0386: }
0387: } else {
0388: return (List) result;
0389: }
0390: }
0391:
0392: public MBMessage findByUuid_First(String uuid, OrderByComparator obc)
0393: throws NoSuchMessageException, SystemException {
0394: List list = findByUuid(uuid, 0, 1, obc);
0395:
0396: if (list.size() == 0) {
0397: StringMaker msg = new StringMaker();
0398:
0399: msg.append("No MBMessage exists with the key {");
0400:
0401: msg.append("uuid=" + uuid);
0402:
0403: msg.append(StringPool.CLOSE_CURLY_BRACE);
0404:
0405: throw new NoSuchMessageException(msg.toString());
0406: } else {
0407: return (MBMessage) list.get(0);
0408: }
0409: }
0410:
0411: public MBMessage findByUuid_Last(String uuid, OrderByComparator obc)
0412: throws NoSuchMessageException, SystemException {
0413: int count = countByUuid(uuid);
0414:
0415: List list = findByUuid(uuid, count - 1, count, obc);
0416:
0417: if (list.size() == 0) {
0418: StringMaker msg = new StringMaker();
0419:
0420: msg.append("No MBMessage exists with the key {");
0421:
0422: msg.append("uuid=" + uuid);
0423:
0424: msg.append(StringPool.CLOSE_CURLY_BRACE);
0425:
0426: throw new NoSuchMessageException(msg.toString());
0427: } else {
0428: return (MBMessage) list.get(0);
0429: }
0430: }
0431:
0432: public MBMessage[] findByUuid_PrevAndNext(long messageId,
0433: String uuid, OrderByComparator obc)
0434: throws NoSuchMessageException, SystemException {
0435: MBMessage mbMessage = findByPrimaryKey(messageId);
0436:
0437: int count = countByUuid(uuid);
0438:
0439: Session session = null;
0440:
0441: try {
0442: session = openSession();
0443:
0444: StringMaker query = new StringMaker();
0445:
0446: query
0447: .append("FROM com.liferay.portlet.messageboards.model.MBMessage WHERE ");
0448:
0449: if (uuid == null) {
0450: query.append("uuid_ IS NULL");
0451: } else {
0452: query.append("uuid_ = ?");
0453: }
0454:
0455: query.append(" ");
0456:
0457: if (obc != null) {
0458: query.append("ORDER BY ");
0459: query.append(obc.getOrderBy());
0460: }
0461:
0462: else {
0463: query.append("ORDER BY ");
0464:
0465: query.append("createDate ASC, ");
0466: query.append("messageId ASC");
0467: }
0468:
0469: Query q = session.createQuery(query.toString());
0470:
0471: int queryPos = 0;
0472:
0473: if (uuid != null) {
0474: q.setString(queryPos++, uuid);
0475: }
0476:
0477: Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
0478: mbMessage);
0479:
0480: MBMessage[] array = new MBMessageImpl[3];
0481:
0482: array[0] = (MBMessage) objArray[0];
0483: array[1] = (MBMessage) objArray[1];
0484: array[2] = (MBMessage) objArray[2];
0485:
0486: return array;
0487: } catch (Exception e) {
0488: throw HibernateUtil.processException(e);
0489: } finally {
0490: closeSession(session);
0491: }
0492: }
0493:
0494: public List findByCompanyId(long companyId) throws SystemException {
0495: boolean finderClassNameCacheEnabled = MBMessageModelImpl.CACHE_ENABLED;
0496: String finderClassName = MBMessage.class.getName();
0497: String finderMethodName = "findByCompanyId";
0498: String[] finderParams = new String[] { Long.class.getName() };
0499: Object[] finderArgs = new Object[] { new Long(companyId) };
0500:
0501: Object result = null;
0502:
0503: if (finderClassNameCacheEnabled) {
0504: result = FinderCache.getResult(finderClassName,
0505: finderMethodName, finderParams, finderArgs,
0506: getSessionFactory());
0507: }
0508:
0509: if (result == null) {
0510: Session session = null;
0511:
0512: try {
0513: session = openSession();
0514:
0515: StringMaker query = new StringMaker();
0516:
0517: query
0518: .append("FROM com.liferay.portlet.messageboards.model.MBMessage WHERE ");
0519:
0520: query.append("companyId = ?");
0521:
0522: query.append(" ");
0523:
0524: query.append("ORDER BY ");
0525:
0526: query.append("createDate ASC, ");
0527: query.append("messageId ASC");
0528:
0529: Query q = session.createQuery(query.toString());
0530:
0531: int queryPos = 0;
0532:
0533: q.setLong(queryPos++, companyId);
0534:
0535: List list = q.list();
0536:
0537: FinderCache.putResult(finderClassNameCacheEnabled,
0538: finderClassName, finderMethodName,
0539: finderParams, finderArgs, list);
0540:
0541: return list;
0542: } catch (Exception e) {
0543: throw HibernateUtil.processException(e);
0544: } finally {
0545: closeSession(session);
0546: }
0547: } else {
0548: return (List) result;
0549: }
0550: }
0551:
0552: public List findByCompanyId(long companyId, int begin, int end)
0553: throws SystemException {
0554: return findByCompanyId(companyId, begin, end, null);
0555: }
0556:
0557: public List findByCompanyId(long companyId, int begin, int end,
0558: OrderByComparator obc) throws SystemException {
0559: boolean finderClassNameCacheEnabled = MBMessageModelImpl.CACHE_ENABLED;
0560: String finderClassName = MBMessage.class.getName();
0561: String finderMethodName = "findByCompanyId";
0562: String[] finderParams = new String[] { Long.class.getName(),
0563:
0564: "java.lang.Integer", "java.lang.Integer",
0565: "com.liferay.portal.kernel.util.OrderByComparator" };
0566: Object[] finderArgs = new Object[] { new Long(companyId),
0567:
0568: String.valueOf(begin), String.valueOf(end), String.valueOf(obc) };
0569:
0570: Object result = null;
0571:
0572: if (finderClassNameCacheEnabled) {
0573: result = FinderCache.getResult(finderClassName,
0574: finderMethodName, finderParams, finderArgs,
0575: getSessionFactory());
0576: }
0577:
0578: if (result == null) {
0579: Session session = null;
0580:
0581: try {
0582: session = openSession();
0583:
0584: StringMaker query = new StringMaker();
0585:
0586: query
0587: .append("FROM com.liferay.portlet.messageboards.model.MBMessage WHERE ");
0588:
0589: query.append("companyId = ?");
0590:
0591: query.append(" ");
0592:
0593: if (obc != null) {
0594: query.append("ORDER BY ");
0595: query.append(obc.getOrderBy());
0596: }
0597:
0598: else {
0599: query.append("ORDER BY ");
0600:
0601: query.append("createDate ASC, ");
0602: query.append("messageId ASC");
0603: }
0604:
0605: Query q = session.createQuery(query.toString());
0606:
0607: int queryPos = 0;
0608:
0609: q.setLong(queryPos++, companyId);
0610:
0611: List list = QueryUtil.list(q, getDialect(), begin, end);
0612:
0613: FinderCache.putResult(finderClassNameCacheEnabled,
0614: finderClassName, finderMethodName,
0615: finderParams, finderArgs, list);
0616:
0617: return list;
0618: } catch (Exception e) {
0619: throw HibernateUtil.processException(e);
0620: } finally {
0621: closeSession(session);
0622: }
0623: } else {
0624: return (List) result;
0625: }
0626: }
0627:
0628: public MBMessage findByCompanyId_First(long companyId,
0629: OrderByComparator obc) throws NoSuchMessageException,
0630: SystemException {
0631: List list = findByCompanyId(companyId, 0, 1, obc);
0632:
0633: if (list.size() == 0) {
0634: StringMaker msg = new StringMaker();
0635:
0636: msg.append("No MBMessage exists with the key {");
0637:
0638: msg.append("companyId=" + companyId);
0639:
0640: msg.append(StringPool.CLOSE_CURLY_BRACE);
0641:
0642: throw new NoSuchMessageException(msg.toString());
0643: } else {
0644: return (MBMessage) list.get(0);
0645: }
0646: }
0647:
0648: public MBMessage findByCompanyId_Last(long companyId,
0649: OrderByComparator obc) throws NoSuchMessageException,
0650: SystemException {
0651: int count = countByCompanyId(companyId);
0652:
0653: List list = findByCompanyId(companyId, count - 1, count, obc);
0654:
0655: if (list.size() == 0) {
0656: StringMaker msg = new StringMaker();
0657:
0658: msg.append("No MBMessage exists with the key {");
0659:
0660: msg.append("companyId=" + companyId);
0661:
0662: msg.append(StringPool.CLOSE_CURLY_BRACE);
0663:
0664: throw new NoSuchMessageException(msg.toString());
0665: } else {
0666: return (MBMessage) list.get(0);
0667: }
0668: }
0669:
0670: public MBMessage[] findByCompanyId_PrevAndNext(long messageId,
0671: long companyId, OrderByComparator obc)
0672: throws NoSuchMessageException, SystemException {
0673: MBMessage mbMessage = findByPrimaryKey(messageId);
0674:
0675: int count = countByCompanyId(companyId);
0676:
0677: Session session = null;
0678:
0679: try {
0680: session = openSession();
0681:
0682: StringMaker query = new StringMaker();
0683:
0684: query
0685: .append("FROM com.liferay.portlet.messageboards.model.MBMessage WHERE ");
0686:
0687: query.append("companyId = ?");
0688:
0689: query.append(" ");
0690:
0691: if (obc != null) {
0692: query.append("ORDER BY ");
0693: query.append(obc.getOrderBy());
0694: }
0695:
0696: else {
0697: query.append("ORDER BY ");
0698:
0699: query.append("createDate ASC, ");
0700: query.append("messageId ASC");
0701: }
0702:
0703: Query q = session.createQuery(query.toString());
0704:
0705: int queryPos = 0;
0706:
0707: q.setLong(queryPos++, companyId);
0708:
0709: Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
0710: mbMessage);
0711:
0712: MBMessage[] array = new MBMessageImpl[3];
0713:
0714: array[0] = (MBMessage) objArray[0];
0715: array[1] = (MBMessage) objArray[1];
0716: array[2] = (MBMessage) objArray[2];
0717:
0718: return array;
0719: } catch (Exception e) {
0720: throw HibernateUtil.processException(e);
0721: } finally {
0722: closeSession(session);
0723: }
0724: }
0725:
0726: public List findByCategoryId(long categoryId)
0727: throws SystemException {
0728: boolean finderClassNameCacheEnabled = MBMessageModelImpl.CACHE_ENABLED;
0729: String finderClassName = MBMessage.class.getName();
0730: String finderMethodName = "findByCategoryId";
0731: String[] finderParams = new String[] { Long.class.getName() };
0732: Object[] finderArgs = new Object[] { new Long(categoryId) };
0733:
0734: Object result = null;
0735:
0736: if (finderClassNameCacheEnabled) {
0737: result = FinderCache.getResult(finderClassName,
0738: finderMethodName, finderParams, finderArgs,
0739: getSessionFactory());
0740: }
0741:
0742: if (result == null) {
0743: Session session = null;
0744:
0745: try {
0746: session = openSession();
0747:
0748: StringMaker query = new StringMaker();
0749:
0750: query
0751: .append("FROM com.liferay.portlet.messageboards.model.MBMessage WHERE ");
0752:
0753: query.append("categoryId = ?");
0754:
0755: query.append(" ");
0756:
0757: query.append("ORDER BY ");
0758:
0759: query.append("createDate ASC, ");
0760: query.append("messageId ASC");
0761:
0762: Query q = session.createQuery(query.toString());
0763:
0764: int queryPos = 0;
0765:
0766: q.setLong(queryPos++, categoryId);
0767:
0768: List list = q.list();
0769:
0770: FinderCache.putResult(finderClassNameCacheEnabled,
0771: finderClassName, finderMethodName,
0772: finderParams, finderArgs, list);
0773:
0774: return list;
0775: } catch (Exception e) {
0776: throw HibernateUtil.processException(e);
0777: } finally {
0778: closeSession(session);
0779: }
0780: } else {
0781: return (List) result;
0782: }
0783: }
0784:
0785: public List findByCategoryId(long categoryId, int begin, int end)
0786: throws SystemException {
0787: return findByCategoryId(categoryId, begin, end, null);
0788: }
0789:
0790: public List findByCategoryId(long categoryId, int begin, int end,
0791: OrderByComparator obc) throws SystemException {
0792: boolean finderClassNameCacheEnabled = MBMessageModelImpl.CACHE_ENABLED;
0793: String finderClassName = MBMessage.class.getName();
0794: String finderMethodName = "findByCategoryId";
0795: String[] finderParams = new String[] { Long.class.getName(),
0796:
0797: "java.lang.Integer", "java.lang.Integer",
0798: "com.liferay.portal.kernel.util.OrderByComparator" };
0799: Object[] finderArgs = new Object[] { new Long(categoryId),
0800:
0801: String.valueOf(begin), String.valueOf(end), String.valueOf(obc) };
0802:
0803: Object result = null;
0804:
0805: if (finderClassNameCacheEnabled) {
0806: result = FinderCache.getResult(finderClassName,
0807: finderMethodName, finderParams, finderArgs,
0808: getSessionFactory());
0809: }
0810:
0811: if (result == null) {
0812: Session session = null;
0813:
0814: try {
0815: session = openSession();
0816:
0817: StringMaker query = new StringMaker();
0818:
0819: query
0820: .append("FROM com.liferay.portlet.messageboards.model.MBMessage WHERE ");
0821:
0822: query.append("categoryId = ?");
0823:
0824: query.append(" ");
0825:
0826: if (obc != null) {
0827: query.append("ORDER BY ");
0828: query.append(obc.getOrderBy());
0829: }
0830:
0831: else {
0832: query.append("ORDER BY ");
0833:
0834: query.append("createDate ASC, ");
0835: query.append("messageId ASC");
0836: }
0837:
0838: Query q = session.createQuery(query.toString());
0839:
0840: int queryPos = 0;
0841:
0842: q.setLong(queryPos++, categoryId);
0843:
0844: List list = QueryUtil.list(q, getDialect(), begin, end);
0845:
0846: FinderCache.putResult(finderClassNameCacheEnabled,
0847: finderClassName, finderMethodName,
0848: finderParams, finderArgs, list);
0849:
0850: return list;
0851: } catch (Exception e) {
0852: throw HibernateUtil.processException(e);
0853: } finally {
0854: closeSession(session);
0855: }
0856: } else {
0857: return (List) result;
0858: }
0859: }
0860:
0861: public MBMessage findByCategoryId_First(long categoryId,
0862: OrderByComparator obc) throws NoSuchMessageException,
0863: SystemException {
0864: List list = findByCategoryId(categoryId, 0, 1, obc);
0865:
0866: if (list.size() == 0) {
0867: StringMaker msg = new StringMaker();
0868:
0869: msg.append("No MBMessage exists with the key {");
0870:
0871: msg.append("categoryId=" + categoryId);
0872:
0873: msg.append(StringPool.CLOSE_CURLY_BRACE);
0874:
0875: throw new NoSuchMessageException(msg.toString());
0876: } else {
0877: return (MBMessage) list.get(0);
0878: }
0879: }
0880:
0881: public MBMessage findByCategoryId_Last(long categoryId,
0882: OrderByComparator obc) throws NoSuchMessageException,
0883: SystemException {
0884: int count = countByCategoryId(categoryId);
0885:
0886: List list = findByCategoryId(categoryId, count - 1, count, obc);
0887:
0888: if (list.size() == 0) {
0889: StringMaker msg = new StringMaker();
0890:
0891: msg.append("No MBMessage exists with the key {");
0892:
0893: msg.append("categoryId=" + categoryId);
0894:
0895: msg.append(StringPool.CLOSE_CURLY_BRACE);
0896:
0897: throw new NoSuchMessageException(msg.toString());
0898: } else {
0899: return (MBMessage) list.get(0);
0900: }
0901: }
0902:
0903: public MBMessage[] findByCategoryId_PrevAndNext(long messageId,
0904: long categoryId, OrderByComparator obc)
0905: throws NoSuchMessageException, SystemException {
0906: MBMessage mbMessage = findByPrimaryKey(messageId);
0907:
0908: int count = countByCategoryId(categoryId);
0909:
0910: Session session = null;
0911:
0912: try {
0913: session = openSession();
0914:
0915: StringMaker query = new StringMaker();
0916:
0917: query
0918: .append("FROM com.liferay.portlet.messageboards.model.MBMessage WHERE ");
0919:
0920: query.append("categoryId = ?");
0921:
0922: query.append(" ");
0923:
0924: if (obc != null) {
0925: query.append("ORDER BY ");
0926: query.append(obc.getOrderBy());
0927: }
0928:
0929: else {
0930: query.append("ORDER BY ");
0931:
0932: query.append("createDate ASC, ");
0933: query.append("messageId ASC");
0934: }
0935:
0936: Query q = session.createQuery(query.toString());
0937:
0938: int queryPos = 0;
0939:
0940: q.setLong(queryPos++, categoryId);
0941:
0942: Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
0943: mbMessage);
0944:
0945: MBMessage[] array = new MBMessageImpl[3];
0946:
0947: array[0] = (MBMessage) objArray[0];
0948: array[1] = (MBMessage) objArray[1];
0949: array[2] = (MBMessage) objArray[2];
0950:
0951: return array;
0952: } catch (Exception e) {
0953: throw HibernateUtil.processException(e);
0954: } finally {
0955: closeSession(session);
0956: }
0957: }
0958:
0959: public List findByThreadId(long threadId) throws SystemException {
0960: boolean finderClassNameCacheEnabled = MBMessageModelImpl.CACHE_ENABLED;
0961: String finderClassName = MBMessage.class.getName();
0962: String finderMethodName = "findByThreadId";
0963: String[] finderParams = new String[] { Long.class.getName() };
0964: Object[] finderArgs = new Object[] { new Long(threadId) };
0965:
0966: Object result = null;
0967:
0968: if (finderClassNameCacheEnabled) {
0969: result = FinderCache.getResult(finderClassName,
0970: finderMethodName, finderParams, finderArgs,
0971: getSessionFactory());
0972: }
0973:
0974: if (result == null) {
0975: Session session = null;
0976:
0977: try {
0978: session = openSession();
0979:
0980: StringMaker query = new StringMaker();
0981:
0982: query
0983: .append("FROM com.liferay.portlet.messageboards.model.MBMessage WHERE ");
0984:
0985: query.append("threadId = ?");
0986:
0987: query.append(" ");
0988:
0989: query.append("ORDER BY ");
0990:
0991: query.append("createDate ASC, ");
0992: query.append("messageId ASC");
0993:
0994: Query q = session.createQuery(query.toString());
0995:
0996: int queryPos = 0;
0997:
0998: q.setLong(queryPos++, threadId);
0999:
1000: List list = q.list();
1001:
1002: FinderCache.putResult(finderClassNameCacheEnabled,
1003: finderClassName, finderMethodName,
1004: finderParams, finderArgs, list);
1005:
1006: return list;
1007: } catch (Exception e) {
1008: throw HibernateUtil.processException(e);
1009: } finally {
1010: closeSession(session);
1011: }
1012: } else {
1013: return (List) result;
1014: }
1015: }
1016:
1017: public List findByThreadId(long threadId, int begin, int end)
1018: throws SystemException {
1019: return findByThreadId(threadId, begin, end, null);
1020: }
1021:
1022: public List findByThreadId(long threadId, int begin, int end,
1023: OrderByComparator obc) throws SystemException {
1024: boolean finderClassNameCacheEnabled = MBMessageModelImpl.CACHE_ENABLED;
1025: String finderClassName = MBMessage.class.getName();
1026: String finderMethodName = "findByThreadId";
1027: String[] finderParams = new String[] { Long.class.getName(),
1028:
1029: "java.lang.Integer", "java.lang.Integer",
1030: "com.liferay.portal.kernel.util.OrderByComparator" };
1031: Object[] finderArgs = new Object[] { new Long(threadId),
1032:
1033: String.valueOf(begin), String.valueOf(end), String.valueOf(obc) };
1034:
1035: Object result = null;
1036:
1037: if (finderClassNameCacheEnabled) {
1038: result = FinderCache.getResult(finderClassName,
1039: finderMethodName, finderParams, finderArgs,
1040: getSessionFactory());
1041: }
1042:
1043: if (result == null) {
1044: Session session = null;
1045:
1046: try {
1047: session = openSession();
1048:
1049: StringMaker query = new StringMaker();
1050:
1051: query
1052: .append("FROM com.liferay.portlet.messageboards.model.MBMessage WHERE ");
1053:
1054: query.append("threadId = ?");
1055:
1056: query.append(" ");
1057:
1058: if (obc != null) {
1059: query.append("ORDER BY ");
1060: query.append(obc.getOrderBy());
1061: }
1062:
1063: else {
1064: query.append("ORDER BY ");
1065:
1066: query.append("createDate ASC, ");
1067: query.append("messageId ASC");
1068: }
1069:
1070: Query q = session.createQuery(query.toString());
1071:
1072: int queryPos = 0;
1073:
1074: q.setLong(queryPos++, threadId);
1075:
1076: List list = QueryUtil.list(q, getDialect(), begin, end);
1077:
1078: FinderCache.putResult(finderClassNameCacheEnabled,
1079: finderClassName, finderMethodName,
1080: finderParams, finderArgs, list);
1081:
1082: return list;
1083: } catch (Exception e) {
1084: throw HibernateUtil.processException(e);
1085: } finally {
1086: closeSession(session);
1087: }
1088: } else {
1089: return (List) result;
1090: }
1091: }
1092:
1093: public MBMessage findByThreadId_First(long threadId,
1094: OrderByComparator obc) throws NoSuchMessageException,
1095: SystemException {
1096: List list = findByThreadId(threadId, 0, 1, obc);
1097:
1098: if (list.size() == 0) {
1099: StringMaker msg = new StringMaker();
1100:
1101: msg.append("No MBMessage exists with the key {");
1102:
1103: msg.append("threadId=" + threadId);
1104:
1105: msg.append(StringPool.CLOSE_CURLY_BRACE);
1106:
1107: throw new NoSuchMessageException(msg.toString());
1108: } else {
1109: return (MBMessage) list.get(0);
1110: }
1111: }
1112:
1113: public MBMessage findByThreadId_Last(long threadId,
1114: OrderByComparator obc) throws NoSuchMessageException,
1115: SystemException {
1116: int count = countByThreadId(threadId);
1117:
1118: List list = findByThreadId(threadId, count - 1, count, obc);
1119:
1120: if (list.size() == 0) {
1121: StringMaker msg = new StringMaker();
1122:
1123: msg.append("No MBMessage exists with the key {");
1124:
1125: msg.append("threadId=" + threadId);
1126:
1127: msg.append(StringPool.CLOSE_CURLY_BRACE);
1128:
1129: throw new NoSuchMessageException(msg.toString());
1130: } else {
1131: return (MBMessage) list.get(0);
1132: }
1133: }
1134:
1135: public MBMessage[] findByThreadId_PrevAndNext(long messageId,
1136: long threadId, OrderByComparator obc)
1137: throws NoSuchMessageException, SystemException {
1138: MBMessage mbMessage = findByPrimaryKey(messageId);
1139:
1140: int count = countByThreadId(threadId);
1141:
1142: Session session = null;
1143:
1144: try {
1145: session = openSession();
1146:
1147: StringMaker query = new StringMaker();
1148:
1149: query
1150: .append("FROM com.liferay.portlet.messageboards.model.MBMessage WHERE ");
1151:
1152: query.append("threadId = ?");
1153:
1154: query.append(" ");
1155:
1156: if (obc != null) {
1157: query.append("ORDER BY ");
1158: query.append(obc.getOrderBy());
1159: }
1160:
1161: else {
1162: query.append("ORDER BY ");
1163:
1164: query.append("createDate ASC, ");
1165: query.append("messageId ASC");
1166: }
1167:
1168: Query q = session.createQuery(query.toString());
1169:
1170: int queryPos = 0;
1171:
1172: q.setLong(queryPos++, threadId);
1173:
1174: Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1175: mbMessage);
1176:
1177: MBMessage[] array = new MBMessageImpl[3];
1178:
1179: array[0] = (MBMessage) objArray[0];
1180: array[1] = (MBMessage) objArray[1];
1181: array[2] = (MBMessage) objArray[2];
1182:
1183: return array;
1184: } catch (Exception e) {
1185: throw HibernateUtil.processException(e);
1186: } finally {
1187: closeSession(session);
1188: }
1189: }
1190:
1191: public List findByC_T(long categoryId, long threadId)
1192: throws SystemException {
1193: boolean finderClassNameCacheEnabled = MBMessageModelImpl.CACHE_ENABLED;
1194: String finderClassName = MBMessage.class.getName();
1195: String finderMethodName = "findByC_T";
1196: String[] finderParams = new String[] { Long.class.getName(),
1197: Long.class.getName() };
1198: Object[] finderArgs = new Object[] { new Long(categoryId),
1199: new Long(threadId) };
1200:
1201: Object result = null;
1202:
1203: if (finderClassNameCacheEnabled) {
1204: result = FinderCache.getResult(finderClassName,
1205: finderMethodName, finderParams, finderArgs,
1206: getSessionFactory());
1207: }
1208:
1209: if (result == null) {
1210: Session session = null;
1211:
1212: try {
1213: session = openSession();
1214:
1215: StringMaker query = new StringMaker();
1216:
1217: query
1218: .append("FROM com.liferay.portlet.messageboards.model.MBMessage WHERE ");
1219:
1220: query.append("categoryId = ?");
1221:
1222: query.append(" AND ");
1223:
1224: query.append("threadId = ?");
1225:
1226: query.append(" ");
1227:
1228: query.append("ORDER BY ");
1229:
1230: query.append("createDate ASC, ");
1231: query.append("messageId ASC");
1232:
1233: Query q = session.createQuery(query.toString());
1234:
1235: int queryPos = 0;
1236:
1237: q.setLong(queryPos++, categoryId);
1238:
1239: q.setLong(queryPos++, threadId);
1240:
1241: List list = q.list();
1242:
1243: FinderCache.putResult(finderClassNameCacheEnabled,
1244: finderClassName, finderMethodName,
1245: finderParams, finderArgs, list);
1246:
1247: return list;
1248: } catch (Exception e) {
1249: throw HibernateUtil.processException(e);
1250: } finally {
1251: closeSession(session);
1252: }
1253: } else {
1254: return (List) result;
1255: }
1256: }
1257:
1258: public List findByC_T(long categoryId, long threadId, int begin,
1259: int end) throws SystemException {
1260: return findByC_T(categoryId, threadId, begin, end, null);
1261: }
1262:
1263: public List findByC_T(long categoryId, long threadId, int begin,
1264: int end, OrderByComparator obc) throws SystemException {
1265: boolean finderClassNameCacheEnabled = MBMessageModelImpl.CACHE_ENABLED;
1266: String finderClassName = MBMessage.class.getName();
1267: String finderMethodName = "findByC_T";
1268: String[] finderParams = new String[] { Long.class.getName(),
1269: Long.class.getName(),
1270:
1271: "java.lang.Integer", "java.lang.Integer",
1272: "com.liferay.portal.kernel.util.OrderByComparator" };
1273: Object[] finderArgs = new Object[] { new Long(categoryId),
1274: new Long(threadId),
1275:
1276: String.valueOf(begin), String.valueOf(end),
1277: String.valueOf(obc) };
1278:
1279: Object result = null;
1280:
1281: if (finderClassNameCacheEnabled) {
1282: result = FinderCache.getResult(finderClassName,
1283: finderMethodName, finderParams, finderArgs,
1284: getSessionFactory());
1285: }
1286:
1287: if (result == null) {
1288: Session session = null;
1289:
1290: try {
1291: session = openSession();
1292:
1293: StringMaker query = new StringMaker();
1294:
1295: query
1296: .append("FROM com.liferay.portlet.messageboards.model.MBMessage WHERE ");
1297:
1298: query.append("categoryId = ?");
1299:
1300: query.append(" AND ");
1301:
1302: query.append("threadId = ?");
1303:
1304: query.append(" ");
1305:
1306: if (obc != null) {
1307: query.append("ORDER BY ");
1308: query.append(obc.getOrderBy());
1309: }
1310:
1311: else {
1312: query.append("ORDER BY ");
1313:
1314: query.append("createDate ASC, ");
1315: query.append("messageId ASC");
1316: }
1317:
1318: Query q = session.createQuery(query.toString());
1319:
1320: int queryPos = 0;
1321:
1322: q.setLong(queryPos++, categoryId);
1323:
1324: q.setLong(queryPos++, threadId);
1325:
1326: List list = QueryUtil.list(q, getDialect(), begin, end);
1327:
1328: FinderCache.putResult(finderClassNameCacheEnabled,
1329: finderClassName, finderMethodName,
1330: finderParams, finderArgs, list);
1331:
1332: return list;
1333: } catch (Exception e) {
1334: throw HibernateUtil.processException(e);
1335: } finally {
1336: closeSession(session);
1337: }
1338: } else {
1339: return (List) result;
1340: }
1341: }
1342:
1343: public MBMessage findByC_T_First(long categoryId, long threadId,
1344: OrderByComparator obc) throws NoSuchMessageException,
1345: SystemException {
1346: List list = findByC_T(categoryId, threadId, 0, 1, obc);
1347:
1348: if (list.size() == 0) {
1349: StringMaker msg = new StringMaker();
1350:
1351: msg.append("No MBMessage exists with the key {");
1352:
1353: msg.append("categoryId=" + categoryId);
1354:
1355: msg.append(", ");
1356: msg.append("threadId=" + threadId);
1357:
1358: msg.append(StringPool.CLOSE_CURLY_BRACE);
1359:
1360: throw new NoSuchMessageException(msg.toString());
1361: } else {
1362: return (MBMessage) list.get(0);
1363: }
1364: }
1365:
1366: public MBMessage findByC_T_Last(long categoryId, long threadId,
1367: OrderByComparator obc) throws NoSuchMessageException,
1368: SystemException {
1369: int count = countByC_T(categoryId, threadId);
1370:
1371: List list = findByC_T(categoryId, threadId, count - 1, count,
1372: obc);
1373:
1374: if (list.size() == 0) {
1375: StringMaker msg = new StringMaker();
1376:
1377: msg.append("No MBMessage exists with the key {");
1378:
1379: msg.append("categoryId=" + categoryId);
1380:
1381: msg.append(", ");
1382: msg.append("threadId=" + threadId);
1383:
1384: msg.append(StringPool.CLOSE_CURLY_BRACE);
1385:
1386: throw new NoSuchMessageException(msg.toString());
1387: } else {
1388: return (MBMessage) list.get(0);
1389: }
1390: }
1391:
1392: public MBMessage[] findByC_T_PrevAndNext(long messageId,
1393: long categoryId, long threadId, OrderByComparator obc)
1394: throws NoSuchMessageException, SystemException {
1395: MBMessage mbMessage = findByPrimaryKey(messageId);
1396:
1397: int count = countByC_T(categoryId, threadId);
1398:
1399: Session session = null;
1400:
1401: try {
1402: session = openSession();
1403:
1404: StringMaker query = new StringMaker();
1405:
1406: query
1407: .append("FROM com.liferay.portlet.messageboards.model.MBMessage WHERE ");
1408:
1409: query.append("categoryId = ?");
1410:
1411: query.append(" AND ");
1412:
1413: query.append("threadId = ?");
1414:
1415: query.append(" ");
1416:
1417: if (obc != null) {
1418: query.append("ORDER BY ");
1419: query.append(obc.getOrderBy());
1420: }
1421:
1422: else {
1423: query.append("ORDER BY ");
1424:
1425: query.append("createDate ASC, ");
1426: query.append("messageId ASC");
1427: }
1428:
1429: Query q = session.createQuery(query.toString());
1430:
1431: int queryPos = 0;
1432:
1433: q.setLong(queryPos++, categoryId);
1434:
1435: q.setLong(queryPos++, threadId);
1436:
1437: Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1438: mbMessage);
1439:
1440: MBMessage[] array = new MBMessageImpl[3];
1441:
1442: array[0] = (MBMessage) objArray[0];
1443: array[1] = (MBMessage) objArray[1];
1444: array[2] = (MBMessage) objArray[2];
1445:
1446: return array;
1447: } catch (Exception e) {
1448: throw HibernateUtil.processException(e);
1449: } finally {
1450: closeSession(session);
1451: }
1452: }
1453:
1454: public List findByT_P(long threadId, long parentMessageId)
1455: throws SystemException {
1456: boolean finderClassNameCacheEnabled = MBMessageModelImpl.CACHE_ENABLED;
1457: String finderClassName = MBMessage.class.getName();
1458: String finderMethodName = "findByT_P";
1459: String[] finderParams = new String[] { Long.class.getName(),
1460: Long.class.getName() };
1461: Object[] finderArgs = new Object[] { new Long(threadId),
1462: new Long(parentMessageId) };
1463:
1464: Object result = null;
1465:
1466: if (finderClassNameCacheEnabled) {
1467: result = FinderCache.getResult(finderClassName,
1468: finderMethodName, finderParams, finderArgs,
1469: getSessionFactory());
1470: }
1471:
1472: if (result == null) {
1473: Session session = null;
1474:
1475: try {
1476: session = openSession();
1477:
1478: StringMaker query = new StringMaker();
1479:
1480: query
1481: .append("FROM com.liferay.portlet.messageboards.model.MBMessage WHERE ");
1482:
1483: query.append("threadId = ?");
1484:
1485: query.append(" AND ");
1486:
1487: query.append("parentMessageId = ?");
1488:
1489: query.append(" ");
1490:
1491: query.append("ORDER BY ");
1492:
1493: query.append("createDate ASC, ");
1494: query.append("messageId ASC");
1495:
1496: Query q = session.createQuery(query.toString());
1497:
1498: int queryPos = 0;
1499:
1500: q.setLong(queryPos++, threadId);
1501:
1502: q.setLong(queryPos++, parentMessageId);
1503:
1504: List list = q.list();
1505:
1506: FinderCache.putResult(finderClassNameCacheEnabled,
1507: finderClassName, finderMethodName,
1508: finderParams, finderArgs, list);
1509:
1510: return list;
1511: } catch (Exception e) {
1512: throw HibernateUtil.processException(e);
1513: } finally {
1514: closeSession(session);
1515: }
1516: } else {
1517: return (List) result;
1518: }
1519: }
1520:
1521: public List findByT_P(long threadId, long parentMessageId,
1522: int begin, int end) throws SystemException {
1523: return findByT_P(threadId, parentMessageId, begin, end, null);
1524: }
1525:
1526: public List findByT_P(long threadId, long parentMessageId,
1527: int begin, int end, OrderByComparator obc)
1528: throws SystemException {
1529: boolean finderClassNameCacheEnabled = MBMessageModelImpl.CACHE_ENABLED;
1530: String finderClassName = MBMessage.class.getName();
1531: String finderMethodName = "findByT_P";
1532: String[] finderParams = new String[] { Long.class.getName(),
1533: Long.class.getName(),
1534:
1535: "java.lang.Integer", "java.lang.Integer",
1536: "com.liferay.portal.kernel.util.OrderByComparator" };
1537: Object[] finderArgs = new Object[] { new Long(threadId),
1538: new Long(parentMessageId),
1539:
1540: String.valueOf(begin), String.valueOf(end),
1541: String.valueOf(obc) };
1542:
1543: Object result = null;
1544:
1545: if (finderClassNameCacheEnabled) {
1546: result = FinderCache.getResult(finderClassName,
1547: finderMethodName, finderParams, finderArgs,
1548: getSessionFactory());
1549: }
1550:
1551: if (result == null) {
1552: Session session = null;
1553:
1554: try {
1555: session = openSession();
1556:
1557: StringMaker query = new StringMaker();
1558:
1559: query
1560: .append("FROM com.liferay.portlet.messageboards.model.MBMessage WHERE ");
1561:
1562: query.append("threadId = ?");
1563:
1564: query.append(" AND ");
1565:
1566: query.append("parentMessageId = ?");
1567:
1568: query.append(" ");
1569:
1570: if (obc != null) {
1571: query.append("ORDER BY ");
1572: query.append(obc.getOrderBy());
1573: }
1574:
1575: else {
1576: query.append("ORDER BY ");
1577:
1578: query.append("createDate ASC, ");
1579: query.append("messageId ASC");
1580: }
1581:
1582: Query q = session.createQuery(query.toString());
1583:
1584: int queryPos = 0;
1585:
1586: q.setLong(queryPos++, threadId);
1587:
1588: q.setLong(queryPos++, parentMessageId);
1589:
1590: List list = QueryUtil.list(q, getDialect(), begin, end);
1591:
1592: FinderCache.putResult(finderClassNameCacheEnabled,
1593: finderClassName, finderMethodName,
1594: finderParams, finderArgs, list);
1595:
1596: return list;
1597: } catch (Exception e) {
1598: throw HibernateUtil.processException(e);
1599: } finally {
1600: closeSession(session);
1601: }
1602: } else {
1603: return (List) result;
1604: }
1605: }
1606:
1607: public MBMessage findByT_P_First(long threadId,
1608: long parentMessageId, OrderByComparator obc)
1609: throws NoSuchMessageException, SystemException {
1610: List list = findByT_P(threadId, parentMessageId, 0, 1, obc);
1611:
1612: if (list.size() == 0) {
1613: StringMaker msg = new StringMaker();
1614:
1615: msg.append("No MBMessage exists with the key {");
1616:
1617: msg.append("threadId=" + threadId);
1618:
1619: msg.append(", ");
1620: msg.append("parentMessageId=" + parentMessageId);
1621:
1622: msg.append(StringPool.CLOSE_CURLY_BRACE);
1623:
1624: throw new NoSuchMessageException(msg.toString());
1625: } else {
1626: return (MBMessage) list.get(0);
1627: }
1628: }
1629:
1630: public MBMessage findByT_P_Last(long threadId,
1631: long parentMessageId, OrderByComparator obc)
1632: throws NoSuchMessageException, SystemException {
1633: int count = countByT_P(threadId, parentMessageId);
1634:
1635: List list = findByT_P(threadId, parentMessageId, count - 1,
1636: count, obc);
1637:
1638: if (list.size() == 0) {
1639: StringMaker msg = new StringMaker();
1640:
1641: msg.append("No MBMessage exists with the key {");
1642:
1643: msg.append("threadId=" + threadId);
1644:
1645: msg.append(", ");
1646: msg.append("parentMessageId=" + parentMessageId);
1647:
1648: msg.append(StringPool.CLOSE_CURLY_BRACE);
1649:
1650: throw new NoSuchMessageException(msg.toString());
1651: } else {
1652: return (MBMessage) list.get(0);
1653: }
1654: }
1655:
1656: public MBMessage[] findByT_P_PrevAndNext(long messageId,
1657: long threadId, long parentMessageId, OrderByComparator obc)
1658: throws NoSuchMessageException, SystemException {
1659: MBMessage mbMessage = findByPrimaryKey(messageId);
1660:
1661: int count = countByT_P(threadId, parentMessageId);
1662:
1663: Session session = null;
1664:
1665: try {
1666: session = openSession();
1667:
1668: StringMaker query = new StringMaker();
1669:
1670: query
1671: .append("FROM com.liferay.portlet.messageboards.model.MBMessage WHERE ");
1672:
1673: query.append("threadId = ?");
1674:
1675: query.append(" AND ");
1676:
1677: query.append("parentMessageId = ?");
1678:
1679: query.append(" ");
1680:
1681: if (obc != null) {
1682: query.append("ORDER BY ");
1683: query.append(obc.getOrderBy());
1684: }
1685:
1686: else {
1687: query.append("ORDER BY ");
1688:
1689: query.append("createDate ASC, ");
1690: query.append("messageId ASC");
1691: }
1692:
1693: Query q = session.createQuery(query.toString());
1694:
1695: int queryPos = 0;
1696:
1697: q.setLong(queryPos++, threadId);
1698:
1699: q.setLong(queryPos++, parentMessageId);
1700:
1701: Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1702: mbMessage);
1703:
1704: MBMessage[] array = new MBMessageImpl[3];
1705:
1706: array[0] = (MBMessage) objArray[0];
1707: array[1] = (MBMessage) objArray[1];
1708: array[2] = (MBMessage) objArray[2];
1709:
1710: return array;
1711: } catch (Exception e) {
1712: throw HibernateUtil.processException(e);
1713: } finally {
1714: closeSession(session);
1715: }
1716: }
1717:
1718: public List findWithDynamicQuery(
1719: DynamicQueryInitializer queryInitializer)
1720: throws SystemException {
1721: Session session = null;
1722:
1723: try {
1724: session = openSession();
1725:
1726: DynamicQuery query = queryInitializer.initialize(session);
1727:
1728: return query.list();
1729: } catch (Exception e) {
1730: throw HibernateUtil.processException(e);
1731: } finally {
1732: closeSession(session);
1733: }
1734: }
1735:
1736: public List findWithDynamicQuery(
1737: DynamicQueryInitializer queryInitializer, int begin, int end)
1738: throws SystemException {
1739: Session session = null;
1740:
1741: try {
1742: session = openSession();
1743:
1744: DynamicQuery query = queryInitializer.initialize(session);
1745:
1746: query.setLimit(begin, end);
1747:
1748: return query.list();
1749: } catch (Exception e) {
1750: throw HibernateUtil.processException(e);
1751: } finally {
1752: closeSession(session);
1753: }
1754: }
1755:
1756: public List findAll() throws SystemException {
1757: return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1758: }
1759:
1760: public List findAll(int begin, int end) throws SystemException {
1761: return findAll(begin, end, null);
1762: }
1763:
1764: public List findAll(int begin, int end, OrderByComparator obc)
1765: throws SystemException {
1766: boolean finderClassNameCacheEnabled = MBMessageModelImpl.CACHE_ENABLED;
1767: String finderClassName = MBMessage.class.getName();
1768: String finderMethodName = "findAll";
1769: String[] finderParams = new String[] { "java.lang.Integer",
1770: "java.lang.Integer",
1771: "com.liferay.portal.kernel.util.OrderByComparator" };
1772: Object[] finderArgs = new Object[] { String.valueOf(begin),
1773: String.valueOf(end), String.valueOf(obc) };
1774:
1775: Object result = null;
1776:
1777: if (finderClassNameCacheEnabled) {
1778: result = FinderCache.getResult(finderClassName,
1779: finderMethodName, finderParams, finderArgs,
1780: getSessionFactory());
1781: }
1782:
1783: if (result == null) {
1784: Session session = null;
1785:
1786: try {
1787: session = openSession();
1788:
1789: StringMaker query = new StringMaker();
1790:
1791: query
1792: .append("FROM com.liferay.portlet.messageboards.model.MBMessage ");
1793:
1794: if (obc != null) {
1795: query.append("ORDER BY ");
1796: query.append(obc.getOrderBy());
1797: }
1798:
1799: else {
1800: query.append("ORDER BY ");
1801:
1802: query.append("createDate ASC, ");
1803: query.append("messageId ASC");
1804: }
1805:
1806: Query q = session.createQuery(query.toString());
1807:
1808: List list = QueryUtil.list(q, getDialect(), begin, end);
1809:
1810: if (obc == null) {
1811: Collections.sort(list);
1812: }
1813:
1814: FinderCache.putResult(finderClassNameCacheEnabled,
1815: finderClassName, finderMethodName,
1816: finderParams, finderArgs, list);
1817:
1818: return list;
1819: } catch (Exception e) {
1820: throw HibernateUtil.processException(e);
1821: } finally {
1822: closeSession(session);
1823: }
1824: } else {
1825: return (List) result;
1826: }
1827: }
1828:
1829: public void removeByUuid(String uuid) throws SystemException {
1830: Iterator itr = findByUuid(uuid).iterator();
1831:
1832: while (itr.hasNext()) {
1833: MBMessage mbMessage = (MBMessage) itr.next();
1834:
1835: remove(mbMessage);
1836: }
1837: }
1838:
1839: public void removeByCompanyId(long companyId)
1840: throws SystemException {
1841: Iterator itr = findByCompanyId(companyId).iterator();
1842:
1843: while (itr.hasNext()) {
1844: MBMessage mbMessage = (MBMessage) itr.next();
1845:
1846: remove(mbMessage);
1847: }
1848: }
1849:
1850: public void removeByCategoryId(long categoryId)
1851: throws SystemException {
1852: Iterator itr = findByCategoryId(categoryId).iterator();
1853:
1854: while (itr.hasNext()) {
1855: MBMessage mbMessage = (MBMessage) itr.next();
1856:
1857: remove(mbMessage);
1858: }
1859: }
1860:
1861: public void removeByThreadId(long threadId) throws SystemException {
1862: Iterator itr = findByThreadId(threadId).iterator();
1863:
1864: while (itr.hasNext()) {
1865: MBMessage mbMessage = (MBMessage) itr.next();
1866:
1867: remove(mbMessage);
1868: }
1869: }
1870:
1871: public void removeByC_T(long categoryId, long threadId)
1872: throws SystemException {
1873: Iterator itr = findByC_T(categoryId, threadId).iterator();
1874:
1875: while (itr.hasNext()) {
1876: MBMessage mbMessage = (MBMessage) itr.next();
1877:
1878: remove(mbMessage);
1879: }
1880: }
1881:
1882: public void removeByT_P(long threadId, long parentMessageId)
1883: throws SystemException {
1884: Iterator itr = findByT_P(threadId, parentMessageId).iterator();
1885:
1886: while (itr.hasNext()) {
1887: MBMessage mbMessage = (MBMessage) itr.next();
1888:
1889: remove(mbMessage);
1890: }
1891: }
1892:
1893: public void removeAll() throws SystemException {
1894: Iterator itr = findAll().iterator();
1895:
1896: while (itr.hasNext()) {
1897: remove((MBMessage) itr.next());
1898: }
1899: }
1900:
1901: public int countByUuid(String uuid) throws SystemException {
1902: boolean finderClassNameCacheEnabled = MBMessageModelImpl.CACHE_ENABLED;
1903: String finderClassName = MBMessage.class.getName();
1904: String finderMethodName = "countByUuid";
1905: String[] finderParams = new String[] { String.class.getName() };
1906: Object[] finderArgs = new Object[] { uuid };
1907:
1908: Object result = null;
1909:
1910: if (finderClassNameCacheEnabled) {
1911: result = FinderCache.getResult(finderClassName,
1912: finderMethodName, finderParams, finderArgs,
1913: getSessionFactory());
1914: }
1915:
1916: if (result == null) {
1917: Session session = null;
1918:
1919: try {
1920: session = openSession();
1921:
1922: StringMaker query = new StringMaker();
1923:
1924: query.append("SELECT COUNT(*) ");
1925: query
1926: .append("FROM com.liferay.portlet.messageboards.model.MBMessage WHERE ");
1927:
1928: if (uuid == null) {
1929: query.append("uuid_ IS NULL");
1930: } else {
1931: query.append("uuid_ = ?");
1932: }
1933:
1934: query.append(" ");
1935:
1936: Query q = session.createQuery(query.toString());
1937:
1938: int queryPos = 0;
1939:
1940: if (uuid != null) {
1941: q.setString(queryPos++, uuid);
1942: }
1943:
1944: Long count = null;
1945:
1946: Iterator itr = q.list().iterator();
1947:
1948: if (itr.hasNext()) {
1949: count = (Long) itr.next();
1950: }
1951:
1952: if (count == null) {
1953: count = new Long(0);
1954: }
1955:
1956: FinderCache.putResult(finderClassNameCacheEnabled,
1957: finderClassName, finderMethodName,
1958: finderParams, finderArgs, count);
1959:
1960: return count.intValue();
1961: } catch (Exception e) {
1962: throw HibernateUtil.processException(e);
1963: } finally {
1964: closeSession(session);
1965: }
1966: } else {
1967: return ((Long) result).intValue();
1968: }
1969: }
1970:
1971: public int countByCompanyId(long companyId) throws SystemException {
1972: boolean finderClassNameCacheEnabled = MBMessageModelImpl.CACHE_ENABLED;
1973: String finderClassName = MBMessage.class.getName();
1974: String finderMethodName = "countByCompanyId";
1975: String[] finderParams = new String[] { Long.class.getName() };
1976: Object[] finderArgs = new Object[] { new Long(companyId) };
1977:
1978: Object result = null;
1979:
1980: if (finderClassNameCacheEnabled) {
1981: result = FinderCache.getResult(finderClassName,
1982: finderMethodName, finderParams, finderArgs,
1983: getSessionFactory());
1984: }
1985:
1986: if (result == null) {
1987: Session session = null;
1988:
1989: try {
1990: session = openSession();
1991:
1992: StringMaker query = new StringMaker();
1993:
1994: query.append("SELECT COUNT(*) ");
1995: query
1996: .append("FROM com.liferay.portlet.messageboards.model.MBMessage WHERE ");
1997:
1998: query.append("companyId = ?");
1999:
2000: query.append(" ");
2001:
2002: Query q = session.createQuery(query.toString());
2003:
2004: int queryPos = 0;
2005:
2006: q.setLong(queryPos++, companyId);
2007:
2008: Long count = null;
2009:
2010: Iterator itr = q.list().iterator();
2011:
2012: if (itr.hasNext()) {
2013: count = (Long) itr.next();
2014: }
2015:
2016: if (count == null) {
2017: count = new Long(0);
2018: }
2019:
2020: FinderCache.putResult(finderClassNameCacheEnabled,
2021: finderClassName, finderMethodName,
2022: finderParams, finderArgs, count);
2023:
2024: return count.intValue();
2025: } catch (Exception e) {
2026: throw HibernateUtil.processException(e);
2027: } finally {
2028: closeSession(session);
2029: }
2030: } else {
2031: return ((Long) result).intValue();
2032: }
2033: }
2034:
2035: public int countByCategoryId(long categoryId)
2036: throws SystemException {
2037: boolean finderClassNameCacheEnabled = MBMessageModelImpl.CACHE_ENABLED;
2038: String finderClassName = MBMessage.class.getName();
2039: String finderMethodName = "countByCategoryId";
2040: String[] finderParams = new String[] { Long.class.getName() };
2041: Object[] finderArgs = new Object[] { new Long(categoryId) };
2042:
2043: Object result = null;
2044:
2045: if (finderClassNameCacheEnabled) {
2046: result = FinderCache.getResult(finderClassName,
2047: finderMethodName, finderParams, finderArgs,
2048: getSessionFactory());
2049: }
2050:
2051: if (result == null) {
2052: Session session = null;
2053:
2054: try {
2055: session = openSession();
2056:
2057: StringMaker query = new StringMaker();
2058:
2059: query.append("SELECT COUNT(*) ");
2060: query
2061: .append("FROM com.liferay.portlet.messageboards.model.MBMessage WHERE ");
2062:
2063: query.append("categoryId = ?");
2064:
2065: query.append(" ");
2066:
2067: Query q = session.createQuery(query.toString());
2068:
2069: int queryPos = 0;
2070:
2071: q.setLong(queryPos++, categoryId);
2072:
2073: Long count = null;
2074:
2075: Iterator itr = q.list().iterator();
2076:
2077: if (itr.hasNext()) {
2078: count = (Long) itr.next();
2079: }
2080:
2081: if (count == null) {
2082: count = new Long(0);
2083: }
2084:
2085: FinderCache.putResult(finderClassNameCacheEnabled,
2086: finderClassName, finderMethodName,
2087: finderParams, finderArgs, count);
2088:
2089: return count.intValue();
2090: } catch (Exception e) {
2091: throw HibernateUtil.processException(e);
2092: } finally {
2093: closeSession(session);
2094: }
2095: } else {
2096: return ((Long) result).intValue();
2097: }
2098: }
2099:
2100: public int countByThreadId(long threadId) throws SystemException {
2101: boolean finderClassNameCacheEnabled = MBMessageModelImpl.CACHE_ENABLED;
2102: String finderClassName = MBMessage.class.getName();
2103: String finderMethodName = "countByThreadId";
2104: String[] finderParams = new String[] { Long.class.getName() };
2105: Object[] finderArgs = new Object[] { new Long(threadId) };
2106:
2107: Object result = null;
2108:
2109: if (finderClassNameCacheEnabled) {
2110: result = FinderCache.getResult(finderClassName,
2111: finderMethodName, finderParams, finderArgs,
2112: getSessionFactory());
2113: }
2114:
2115: if (result == null) {
2116: Session session = null;
2117:
2118: try {
2119: session = openSession();
2120:
2121: StringMaker query = new StringMaker();
2122:
2123: query.append("SELECT COUNT(*) ");
2124: query
2125: .append("FROM com.liferay.portlet.messageboards.model.MBMessage WHERE ");
2126:
2127: query.append("threadId = ?");
2128:
2129: query.append(" ");
2130:
2131: Query q = session.createQuery(query.toString());
2132:
2133: int queryPos = 0;
2134:
2135: q.setLong(queryPos++, threadId);
2136:
2137: Long count = null;
2138:
2139: Iterator itr = q.list().iterator();
2140:
2141: if (itr.hasNext()) {
2142: count = (Long) itr.next();
2143: }
2144:
2145: if (count == null) {
2146: count = new Long(0);
2147: }
2148:
2149: FinderCache.putResult(finderClassNameCacheEnabled,
2150: finderClassName, finderMethodName,
2151: finderParams, finderArgs, count);
2152:
2153: return count.intValue();
2154: } catch (Exception e) {
2155: throw HibernateUtil.processException(e);
2156: } finally {
2157: closeSession(session);
2158: }
2159: } else {
2160: return ((Long) result).intValue();
2161: }
2162: }
2163:
2164: public int countByC_T(long categoryId, long threadId)
2165: throws SystemException {
2166: boolean finderClassNameCacheEnabled = MBMessageModelImpl.CACHE_ENABLED;
2167: String finderClassName = MBMessage.class.getName();
2168: String finderMethodName = "countByC_T";
2169: String[] finderParams = new String[] { Long.class.getName(),
2170: Long.class.getName() };
2171: Object[] finderArgs = new Object[] { new Long(categoryId),
2172: new Long(threadId) };
2173:
2174: Object result = null;
2175:
2176: if (finderClassNameCacheEnabled) {
2177: result = FinderCache.getResult(finderClassName,
2178: finderMethodName, finderParams, finderArgs,
2179: getSessionFactory());
2180: }
2181:
2182: if (result == null) {
2183: Session session = null;
2184:
2185: try {
2186: session = openSession();
2187:
2188: StringMaker query = new StringMaker();
2189:
2190: query.append("SELECT COUNT(*) ");
2191: query
2192: .append("FROM com.liferay.portlet.messageboards.model.MBMessage WHERE ");
2193:
2194: query.append("categoryId = ?");
2195:
2196: query.append(" AND ");
2197:
2198: query.append("threadId = ?");
2199:
2200: query.append(" ");
2201:
2202: Query q = session.createQuery(query.toString());
2203:
2204: int queryPos = 0;
2205:
2206: q.setLong(queryPos++, categoryId);
2207:
2208: q.setLong(queryPos++, threadId);
2209:
2210: Long count = null;
2211:
2212: Iterator itr = q.list().iterator();
2213:
2214: if (itr.hasNext()) {
2215: count = (Long) itr.next();
2216: }
2217:
2218: if (count == null) {
2219: count = new Long(0);
2220: }
2221:
2222: FinderCache.putResult(finderClassNameCacheEnabled,
2223: finderClassName, finderMethodName,
2224: finderParams, finderArgs, count);
2225:
2226: return count.intValue();
2227: } catch (Exception e) {
2228: throw HibernateUtil.processException(e);
2229: } finally {
2230: closeSession(session);
2231: }
2232: } else {
2233: return ((Long) result).intValue();
2234: }
2235: }
2236:
2237: public int countByT_P(long threadId, long parentMessageId)
2238: throws SystemException {
2239: boolean finderClassNameCacheEnabled = MBMessageModelImpl.CACHE_ENABLED;
2240: String finderClassName = MBMessage.class.getName();
2241: String finderMethodName = "countByT_P";
2242: String[] finderParams = new String[] { Long.class.getName(),
2243: Long.class.getName() };
2244: Object[] finderArgs = new Object[] { new Long(threadId),
2245: new Long(parentMessageId) };
2246:
2247: Object result = null;
2248:
2249: if (finderClassNameCacheEnabled) {
2250: result = FinderCache.getResult(finderClassName,
2251: finderMethodName, finderParams, finderArgs,
2252: getSessionFactory());
2253: }
2254:
2255: if (result == null) {
2256: Session session = null;
2257:
2258: try {
2259: session = openSession();
2260:
2261: StringMaker query = new StringMaker();
2262:
2263: query.append("SELECT COUNT(*) ");
2264: query
2265: .append("FROM com.liferay.portlet.messageboards.model.MBMessage WHERE ");
2266:
2267: query.append("threadId = ?");
2268:
2269: query.append(" AND ");
2270:
2271: query.append("parentMessageId = ?");
2272:
2273: query.append(" ");
2274:
2275: Query q = session.createQuery(query.toString());
2276:
2277: int queryPos = 0;
2278:
2279: q.setLong(queryPos++, threadId);
2280:
2281: q.setLong(queryPos++, parentMessageId);
2282:
2283: Long count = null;
2284:
2285: Iterator itr = q.list().iterator();
2286:
2287: if (itr.hasNext()) {
2288: count = (Long) itr.next();
2289: }
2290:
2291: if (count == null) {
2292: count = new Long(0);
2293: }
2294:
2295: FinderCache.putResult(finderClassNameCacheEnabled,
2296: finderClassName, finderMethodName,
2297: finderParams, finderArgs, count);
2298:
2299: return count.intValue();
2300: } catch (Exception e) {
2301: throw HibernateUtil.processException(e);
2302: } finally {
2303: closeSession(session);
2304: }
2305: } else {
2306: return ((Long) result).intValue();
2307: }
2308: }
2309:
2310: public int countAll() throws SystemException {
2311: boolean finderClassNameCacheEnabled = MBMessageModelImpl.CACHE_ENABLED;
2312: String finderClassName = MBMessage.class.getName();
2313: String finderMethodName = "countAll";
2314: String[] finderParams = new String[] {};
2315: Object[] finderArgs = new Object[] {};
2316:
2317: Object result = null;
2318:
2319: if (finderClassNameCacheEnabled) {
2320: result = FinderCache.getResult(finderClassName,
2321: finderMethodName, finderParams, finderArgs,
2322: getSessionFactory());
2323: }
2324:
2325: if (result == null) {
2326: Session session = null;
2327:
2328: try {
2329: session = openSession();
2330:
2331: Query q = session
2332: .createQuery("SELECT COUNT(*) FROM com.liferay.portlet.messageboards.model.MBMessage");
2333:
2334: Long count = null;
2335:
2336: Iterator itr = q.list().iterator();
2337:
2338: if (itr.hasNext()) {
2339: count = (Long) itr.next();
2340: }
2341:
2342: if (count == null) {
2343: count = new Long(0);
2344: }
2345:
2346: FinderCache.putResult(finderClassNameCacheEnabled,
2347: finderClassName, finderMethodName,
2348: finderParams, finderArgs, count);
2349:
2350: return count.intValue();
2351: } catch (Exception e) {
2352: throw HibernateUtil.processException(e);
2353: } finally {
2354: closeSession(session);
2355: }
2356: } else {
2357: return ((Long) result).intValue();
2358: }
2359: }
2360:
2361: protected void initDao() {
2362: }
2363:
2364: private static ModelListener _getListener() {
2365: if (Validator.isNotNull(_LISTENER)) {
2366: try {
2367: return (ModelListener) Class.forName(_LISTENER)
2368: .newInstance();
2369: } catch (Exception e) {
2370: _log.error(e);
2371: }
2372: }
2373:
2374: return null;
2375: }
2376:
2377: private static final String _LISTENER = GetterUtil
2378: .getString(PropsUtil
2379: .get("value.object.listener.com.liferay.portlet.messageboards.model.MBMessage"));
2380: private static Log _log = LogFactory
2381: .getLog(MBMessagePersistenceImpl.class);
2382: }
|