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