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