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