0001: /**
0002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
0003: *
0004: * Permission is hereby granted, free of charge, to any person obtaining a copy
0005: * of this software and associated documentation files (the "Software"), to deal
0006: * in the Software without restriction, including without limitation the rights
0007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0008: * copies of the Software, and to permit persons to whom the Software is
0009: * furnished to do so, subject to the following conditions:
0010: *
0011: * The above copyright notice and this permission notice shall be included in
0012: * all copies or substantial portions of the Software.
0013: *
0014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0020: * SOFTWARE.
0021: */package com.liferay.portlet.messageboards.service.persistence;
0022:
0023: import com.liferay.portal.SystemException;
0024: import com.liferay.portal.kernel.dao.DynamicQuery;
0025: import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
0026: import com.liferay.portal.kernel.util.GetterUtil;
0027: import com.liferay.portal.kernel.util.OrderByComparator;
0028: import com.liferay.portal.kernel.util.StringMaker;
0029: import com.liferay.portal.kernel.util.StringPool;
0030: import com.liferay.portal.kernel.util.Validator;
0031: import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
0032: import com.liferay.portal.model.ModelListener;
0033: import com.liferay.portal.service.persistence.BasePersistence;
0034: import com.liferay.portal.spring.hibernate.FinderCache;
0035: import com.liferay.portal.spring.hibernate.HibernateUtil;
0036: import com.liferay.portal.util.PropsUtil;
0037:
0038: import com.liferay.portlet.messageboards.NoSuchCategoryException;
0039: import com.liferay.portlet.messageboards.model.MBCategory;
0040: import com.liferay.portlet.messageboards.model.impl.MBCategoryImpl;
0041: import com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl;
0042:
0043: import com.liferay.util.dao.hibernate.QueryUtil;
0044:
0045: import org.apache.commons.logging.Log;
0046: import org.apache.commons.logging.LogFactory;
0047:
0048: import org.hibernate.Query;
0049: import org.hibernate.Session;
0050:
0051: import java.util.Collections;
0052: import java.util.Iterator;
0053: import java.util.List;
0054:
0055: /**
0056: * <a href="MBCategoryPersistenceImpl.java.html"><b><i>View Source</i></b></a>
0057: *
0058: * @author Brian Wing Shun Chan
0059: *
0060: */
0061: public class MBCategoryPersistenceImpl extends BasePersistence
0062: implements MBCategoryPersistence {
0063: public MBCategory create(long categoryId) {
0064: MBCategory mbCategory = new MBCategoryImpl();
0065:
0066: mbCategory.setNew(true);
0067: mbCategory.setPrimaryKey(categoryId);
0068:
0069: String uuid = PortalUUIDUtil.generate();
0070:
0071: mbCategory.setUuid(uuid);
0072:
0073: return mbCategory;
0074: }
0075:
0076: public MBCategory remove(long categoryId)
0077: throws NoSuchCategoryException, SystemException {
0078: Session session = null;
0079:
0080: try {
0081: session = openSession();
0082:
0083: MBCategory mbCategory = (MBCategory) session.get(
0084: MBCategoryImpl.class, new Long(categoryId));
0085:
0086: if (mbCategory == null) {
0087: if (_log.isWarnEnabled()) {
0088: _log
0089: .warn("No MBCategory exists with the primary key "
0090: + categoryId);
0091: }
0092:
0093: throw new NoSuchCategoryException(
0094: "No MBCategory exists with the primary key "
0095: + categoryId);
0096: }
0097:
0098: return remove(mbCategory);
0099: } catch (NoSuchCategoryException nsee) {
0100: throw nsee;
0101: } catch (Exception e) {
0102: throw HibernateUtil.processException(e);
0103: } finally {
0104: closeSession(session);
0105: }
0106: }
0107:
0108: public MBCategory remove(MBCategory mbCategory)
0109: throws SystemException {
0110: ModelListener listener = _getListener();
0111:
0112: if (listener != null) {
0113: listener.onBeforeRemove(mbCategory);
0114: }
0115:
0116: mbCategory = removeImpl(mbCategory);
0117:
0118: if (listener != null) {
0119: listener.onAfterRemove(mbCategory);
0120: }
0121:
0122: return mbCategory;
0123: }
0124:
0125: protected MBCategory removeImpl(MBCategory mbCategory)
0126: throws SystemException {
0127: Session session = null;
0128:
0129: try {
0130: session = openSession();
0131:
0132: session.delete(mbCategory);
0133:
0134: session.flush();
0135:
0136: return mbCategory;
0137: } catch (Exception e) {
0138: throw HibernateUtil.processException(e);
0139: } finally {
0140: closeSession(session);
0141:
0142: FinderCache.clearCache(MBCategory.class.getName());
0143: }
0144: }
0145:
0146: public MBCategory update(MBCategory mbCategory)
0147: throws SystemException {
0148: return update(mbCategory, false);
0149: }
0150:
0151: public MBCategory update(MBCategory mbCategory, boolean merge)
0152: throws SystemException {
0153: ModelListener listener = _getListener();
0154:
0155: boolean isNew = mbCategory.isNew();
0156:
0157: if (listener != null) {
0158: if (isNew) {
0159: listener.onBeforeCreate(mbCategory);
0160: } else {
0161: listener.onBeforeUpdate(mbCategory);
0162: }
0163: }
0164:
0165: mbCategory = updateImpl(mbCategory, merge);
0166:
0167: if (listener != null) {
0168: if (isNew) {
0169: listener.onAfterCreate(mbCategory);
0170: } else {
0171: listener.onAfterUpdate(mbCategory);
0172: }
0173: }
0174:
0175: return mbCategory;
0176: }
0177:
0178: public MBCategory updateImpl(
0179: com.liferay.portlet.messageboards.model.MBCategory mbCategory,
0180: boolean merge) throws SystemException {
0181: if (Validator.isNull(mbCategory.getUuid())) {
0182: String uuid = PortalUUIDUtil.generate();
0183:
0184: mbCategory.setUuid(uuid);
0185: }
0186:
0187: Session session = null;
0188:
0189: try {
0190: session = openSession();
0191:
0192: if (merge) {
0193: session.merge(mbCategory);
0194: } else {
0195: if (mbCategory.isNew()) {
0196: session.save(mbCategory);
0197: }
0198: }
0199:
0200: session.flush();
0201:
0202: mbCategory.setNew(false);
0203:
0204: return mbCategory;
0205: } catch (Exception e) {
0206: throw HibernateUtil.processException(e);
0207: } finally {
0208: closeSession(session);
0209:
0210: FinderCache.clearCache(MBCategory.class.getName());
0211: }
0212: }
0213:
0214: public MBCategory findByPrimaryKey(long categoryId)
0215: throws NoSuchCategoryException, SystemException {
0216: MBCategory mbCategory = fetchByPrimaryKey(categoryId);
0217:
0218: if (mbCategory == null) {
0219: if (_log.isWarnEnabled()) {
0220: _log.warn("No MBCategory exists with the primary key "
0221: + categoryId);
0222: }
0223:
0224: throw new NoSuchCategoryException(
0225: "No MBCategory exists with the primary key "
0226: + categoryId);
0227: }
0228:
0229: return mbCategory;
0230: }
0231:
0232: public MBCategory fetchByPrimaryKey(long categoryId)
0233: throws SystemException {
0234: Session session = null;
0235:
0236: try {
0237: session = openSession();
0238:
0239: return (MBCategory) session.get(MBCategoryImpl.class,
0240: new Long(categoryId));
0241: } catch (Exception e) {
0242: throw HibernateUtil.processException(e);
0243: } finally {
0244: closeSession(session);
0245: }
0246: }
0247:
0248: public List findByUuid(String uuid) throws SystemException {
0249: boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
0250: String finderClassName = MBCategory.class.getName();
0251: String finderMethodName = "findByUuid";
0252: String[] finderParams = new String[] { String.class.getName() };
0253: Object[] finderArgs = new Object[] { uuid };
0254:
0255: Object result = null;
0256:
0257: if (finderClassNameCacheEnabled) {
0258: result = FinderCache.getResult(finderClassName,
0259: finderMethodName, finderParams, finderArgs,
0260: getSessionFactory());
0261: }
0262:
0263: if (result == null) {
0264: Session session = null;
0265:
0266: try {
0267: session = openSession();
0268:
0269: StringMaker query = new StringMaker();
0270:
0271: query
0272: .append("FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
0273:
0274: if (uuid == null) {
0275: query.append("uuid_ IS NULL");
0276: } else {
0277: query.append("uuid_ = ?");
0278: }
0279:
0280: query.append(" ");
0281:
0282: query.append("ORDER BY ");
0283:
0284: query.append("parentCategoryId ASC, ");
0285: query.append("name ASC");
0286:
0287: Query q = session.createQuery(query.toString());
0288:
0289: int queryPos = 0;
0290:
0291: if (uuid != null) {
0292: q.setString(queryPos++, uuid);
0293: }
0294:
0295: List list = q.list();
0296:
0297: FinderCache.putResult(finderClassNameCacheEnabled,
0298: finderClassName, finderMethodName,
0299: finderParams, finderArgs, list);
0300:
0301: return list;
0302: } catch (Exception e) {
0303: throw HibernateUtil.processException(e);
0304: } finally {
0305: closeSession(session);
0306: }
0307: } else {
0308: return (List) result;
0309: }
0310: }
0311:
0312: public List findByUuid(String uuid, int begin, int end)
0313: throws SystemException {
0314: return findByUuid(uuid, begin, end, null);
0315: }
0316:
0317: public List findByUuid(String uuid, int begin, int end,
0318: OrderByComparator obc) throws SystemException {
0319: boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
0320: String finderClassName = MBCategory.class.getName();
0321: String finderMethodName = "findByUuid";
0322: String[] finderParams = new String[] { String.class.getName(),
0323:
0324: "java.lang.Integer", "java.lang.Integer",
0325: "com.liferay.portal.kernel.util.OrderByComparator" };
0326: Object[] finderArgs = new Object[] { uuid,
0327:
0328: String.valueOf(begin), String.valueOf(end), String.valueOf(obc) };
0329:
0330: Object result = null;
0331:
0332: if (finderClassNameCacheEnabled) {
0333: result = FinderCache.getResult(finderClassName,
0334: finderMethodName, finderParams, finderArgs,
0335: getSessionFactory());
0336: }
0337:
0338: if (result == null) {
0339: Session session = null;
0340:
0341: try {
0342: session = openSession();
0343:
0344: StringMaker query = new StringMaker();
0345:
0346: query
0347: .append("FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
0348:
0349: if (uuid == null) {
0350: query.append("uuid_ IS NULL");
0351: } else {
0352: query.append("uuid_ = ?");
0353: }
0354:
0355: query.append(" ");
0356:
0357: if (obc != null) {
0358: query.append("ORDER BY ");
0359: query.append(obc.getOrderBy());
0360: }
0361:
0362: else {
0363: query.append("ORDER BY ");
0364:
0365: query.append("parentCategoryId ASC, ");
0366: query.append("name ASC");
0367: }
0368:
0369: Query q = session.createQuery(query.toString());
0370:
0371: int queryPos = 0;
0372:
0373: if (uuid != null) {
0374: q.setString(queryPos++, uuid);
0375: }
0376:
0377: List list = QueryUtil.list(q, getDialect(), begin, end);
0378:
0379: FinderCache.putResult(finderClassNameCacheEnabled,
0380: finderClassName, finderMethodName,
0381: finderParams, finderArgs, list);
0382:
0383: return list;
0384: } catch (Exception e) {
0385: throw HibernateUtil.processException(e);
0386: } finally {
0387: closeSession(session);
0388: }
0389: } else {
0390: return (List) result;
0391: }
0392: }
0393:
0394: public MBCategory findByUuid_First(String uuid,
0395: OrderByComparator obc) throws NoSuchCategoryException,
0396: SystemException {
0397: List list = findByUuid(uuid, 0, 1, obc);
0398:
0399: if (list.size() == 0) {
0400: StringMaker msg = new StringMaker();
0401:
0402: msg.append("No MBCategory exists with the key {");
0403:
0404: msg.append("uuid=" + uuid);
0405:
0406: msg.append(StringPool.CLOSE_CURLY_BRACE);
0407:
0408: throw new NoSuchCategoryException(msg.toString());
0409: } else {
0410: return (MBCategory) list.get(0);
0411: }
0412: }
0413:
0414: public MBCategory findByUuid_Last(String uuid, OrderByComparator obc)
0415: throws NoSuchCategoryException, SystemException {
0416: int count = countByUuid(uuid);
0417:
0418: List list = findByUuid(uuid, count - 1, count, obc);
0419:
0420: if (list.size() == 0) {
0421: StringMaker msg = new StringMaker();
0422:
0423: msg.append("No MBCategory exists with the key {");
0424:
0425: msg.append("uuid=" + uuid);
0426:
0427: msg.append(StringPool.CLOSE_CURLY_BRACE);
0428:
0429: throw new NoSuchCategoryException(msg.toString());
0430: } else {
0431: return (MBCategory) list.get(0);
0432: }
0433: }
0434:
0435: public MBCategory[] findByUuid_PrevAndNext(long categoryId,
0436: String uuid, OrderByComparator obc)
0437: throws NoSuchCategoryException, SystemException {
0438: MBCategory mbCategory = findByPrimaryKey(categoryId);
0439:
0440: int count = countByUuid(uuid);
0441:
0442: Session session = null;
0443:
0444: try {
0445: session = openSession();
0446:
0447: StringMaker query = new StringMaker();
0448:
0449: query
0450: .append("FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
0451:
0452: if (uuid == null) {
0453: query.append("uuid_ IS NULL");
0454: } else {
0455: query.append("uuid_ = ?");
0456: }
0457:
0458: query.append(" ");
0459:
0460: if (obc != null) {
0461: query.append("ORDER BY ");
0462: query.append(obc.getOrderBy());
0463: }
0464:
0465: else {
0466: query.append("ORDER BY ");
0467:
0468: query.append("parentCategoryId ASC, ");
0469: query.append("name ASC");
0470: }
0471:
0472: Query q = session.createQuery(query.toString());
0473:
0474: int queryPos = 0;
0475:
0476: if (uuid != null) {
0477: q.setString(queryPos++, uuid);
0478: }
0479:
0480: Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
0481: mbCategory);
0482:
0483: MBCategory[] array = new MBCategoryImpl[3];
0484:
0485: array[0] = (MBCategory) objArray[0];
0486: array[1] = (MBCategory) objArray[1];
0487: array[2] = (MBCategory) objArray[2];
0488:
0489: return array;
0490: } catch (Exception e) {
0491: throw HibernateUtil.processException(e);
0492: } finally {
0493: closeSession(session);
0494: }
0495: }
0496:
0497: public MBCategory findByUUID_G(String uuid, long groupId)
0498: throws NoSuchCategoryException, SystemException {
0499: MBCategory mbCategory = fetchByUUID_G(uuid, groupId);
0500:
0501: if (mbCategory == null) {
0502: StringMaker msg = new StringMaker();
0503:
0504: msg.append("No MBCategory exists with the key {");
0505:
0506: msg.append("uuid=" + uuid);
0507:
0508: msg.append(", ");
0509: msg.append("groupId=" + groupId);
0510:
0511: msg.append(StringPool.CLOSE_CURLY_BRACE);
0512:
0513: if (_log.isWarnEnabled()) {
0514: _log.warn(msg.toString());
0515: }
0516:
0517: throw new NoSuchCategoryException(msg.toString());
0518: }
0519:
0520: return mbCategory;
0521: }
0522:
0523: public MBCategory fetchByUUID_G(String uuid, long groupId)
0524: throws SystemException {
0525: boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
0526: String finderClassName = MBCategory.class.getName();
0527: String finderMethodName = "fetchByUUID_G";
0528: String[] finderParams = new String[] { String.class.getName(),
0529: Long.class.getName() };
0530: Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
0531:
0532: Object result = null;
0533:
0534: if (finderClassNameCacheEnabled) {
0535: result = FinderCache.getResult(finderClassName,
0536: finderMethodName, finderParams, finderArgs,
0537: getSessionFactory());
0538: }
0539:
0540: if (result == null) {
0541: Session session = null;
0542:
0543: try {
0544: session = openSession();
0545:
0546: StringMaker query = new StringMaker();
0547:
0548: query
0549: .append("FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
0550:
0551: if (uuid == null) {
0552: query.append("uuid_ IS NULL");
0553: } else {
0554: query.append("uuid_ = ?");
0555: }
0556:
0557: query.append(" AND ");
0558:
0559: query.append("groupId = ?");
0560:
0561: query.append(" ");
0562:
0563: query.append("ORDER BY ");
0564:
0565: query.append("parentCategoryId ASC, ");
0566: query.append("name ASC");
0567:
0568: Query q = session.createQuery(query.toString());
0569:
0570: int queryPos = 0;
0571:
0572: if (uuid != null) {
0573: q.setString(queryPos++, uuid);
0574: }
0575:
0576: q.setLong(queryPos++, groupId);
0577:
0578: List list = q.list();
0579:
0580: FinderCache.putResult(finderClassNameCacheEnabled,
0581: finderClassName, finderMethodName,
0582: finderParams, finderArgs, list);
0583:
0584: if (list.size() == 0) {
0585: return null;
0586: } else {
0587: return (MBCategory) list.get(0);
0588: }
0589: } catch (Exception e) {
0590: throw HibernateUtil.processException(e);
0591: } finally {
0592: closeSession(session);
0593: }
0594: } else {
0595: List list = (List) result;
0596:
0597: if (list.size() == 0) {
0598: return null;
0599: } else {
0600: return (MBCategory) list.get(0);
0601: }
0602: }
0603: }
0604:
0605: public List findByGroupId(long groupId) throws SystemException {
0606: boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
0607: String finderClassName = MBCategory.class.getName();
0608: String finderMethodName = "findByGroupId";
0609: String[] finderParams = new String[] { Long.class.getName() };
0610: Object[] finderArgs = new Object[] { new Long(groupId) };
0611:
0612: Object result = null;
0613:
0614: if (finderClassNameCacheEnabled) {
0615: result = FinderCache.getResult(finderClassName,
0616: finderMethodName, finderParams, finderArgs,
0617: getSessionFactory());
0618: }
0619:
0620: if (result == null) {
0621: Session session = null;
0622:
0623: try {
0624: session = openSession();
0625:
0626: StringMaker query = new StringMaker();
0627:
0628: query
0629: .append("FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
0630:
0631: query.append("groupId = ?");
0632:
0633: query.append(" ");
0634:
0635: query.append("ORDER BY ");
0636:
0637: query.append("parentCategoryId ASC, ");
0638: query.append("name ASC");
0639:
0640: Query q = session.createQuery(query.toString());
0641:
0642: int queryPos = 0;
0643:
0644: q.setLong(queryPos++, groupId);
0645:
0646: List list = q.list();
0647:
0648: FinderCache.putResult(finderClassNameCacheEnabled,
0649: finderClassName, finderMethodName,
0650: finderParams, finderArgs, list);
0651:
0652: return list;
0653: } catch (Exception e) {
0654: throw HibernateUtil.processException(e);
0655: } finally {
0656: closeSession(session);
0657: }
0658: } else {
0659: return (List) result;
0660: }
0661: }
0662:
0663: public List findByGroupId(long groupId, int begin, int end)
0664: throws SystemException {
0665: return findByGroupId(groupId, begin, end, null);
0666: }
0667:
0668: public List findByGroupId(long groupId, int begin, int end,
0669: OrderByComparator obc) throws SystemException {
0670: boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
0671: String finderClassName = MBCategory.class.getName();
0672: String finderMethodName = "findByGroupId";
0673: String[] finderParams = new String[] { Long.class.getName(),
0674:
0675: "java.lang.Integer", "java.lang.Integer",
0676: "com.liferay.portal.kernel.util.OrderByComparator" };
0677: Object[] finderArgs = new Object[] { new Long(groupId),
0678:
0679: String.valueOf(begin), String.valueOf(end), String.valueOf(obc) };
0680:
0681: Object result = null;
0682:
0683: if (finderClassNameCacheEnabled) {
0684: result = FinderCache.getResult(finderClassName,
0685: finderMethodName, finderParams, finderArgs,
0686: getSessionFactory());
0687: }
0688:
0689: if (result == null) {
0690: Session session = null;
0691:
0692: try {
0693: session = openSession();
0694:
0695: StringMaker query = new StringMaker();
0696:
0697: query
0698: .append("FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
0699:
0700: query.append("groupId = ?");
0701:
0702: query.append(" ");
0703:
0704: if (obc != null) {
0705: query.append("ORDER BY ");
0706: query.append(obc.getOrderBy());
0707: }
0708:
0709: else {
0710: query.append("ORDER BY ");
0711:
0712: query.append("parentCategoryId ASC, ");
0713: query.append("name ASC");
0714: }
0715:
0716: Query q = session.createQuery(query.toString());
0717:
0718: int queryPos = 0;
0719:
0720: q.setLong(queryPos++, groupId);
0721:
0722: List list = QueryUtil.list(q, getDialect(), begin, end);
0723:
0724: FinderCache.putResult(finderClassNameCacheEnabled,
0725: finderClassName, finderMethodName,
0726: finderParams, finderArgs, list);
0727:
0728: return list;
0729: } catch (Exception e) {
0730: throw HibernateUtil.processException(e);
0731: } finally {
0732: closeSession(session);
0733: }
0734: } else {
0735: return (List) result;
0736: }
0737: }
0738:
0739: public MBCategory findByGroupId_First(long groupId,
0740: OrderByComparator obc) throws NoSuchCategoryException,
0741: SystemException {
0742: List list = findByGroupId(groupId, 0, 1, obc);
0743:
0744: if (list.size() == 0) {
0745: StringMaker msg = new StringMaker();
0746:
0747: msg.append("No MBCategory exists with the key {");
0748:
0749: msg.append("groupId=" + groupId);
0750:
0751: msg.append(StringPool.CLOSE_CURLY_BRACE);
0752:
0753: throw new NoSuchCategoryException(msg.toString());
0754: } else {
0755: return (MBCategory) list.get(0);
0756: }
0757: }
0758:
0759: public MBCategory findByGroupId_Last(long groupId,
0760: OrderByComparator obc) throws NoSuchCategoryException,
0761: SystemException {
0762: int count = countByGroupId(groupId);
0763:
0764: List list = findByGroupId(groupId, count - 1, count, obc);
0765:
0766: if (list.size() == 0) {
0767: StringMaker msg = new StringMaker();
0768:
0769: msg.append("No MBCategory exists with the key {");
0770:
0771: msg.append("groupId=" + groupId);
0772:
0773: msg.append(StringPool.CLOSE_CURLY_BRACE);
0774:
0775: throw new NoSuchCategoryException(msg.toString());
0776: } else {
0777: return (MBCategory) list.get(0);
0778: }
0779: }
0780:
0781: public MBCategory[] findByGroupId_PrevAndNext(long categoryId,
0782: long groupId, OrderByComparator obc)
0783: throws NoSuchCategoryException, SystemException {
0784: MBCategory mbCategory = findByPrimaryKey(categoryId);
0785:
0786: int count = countByGroupId(groupId);
0787:
0788: Session session = null;
0789:
0790: try {
0791: session = openSession();
0792:
0793: StringMaker query = new StringMaker();
0794:
0795: query
0796: .append("FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
0797:
0798: query.append("groupId = ?");
0799:
0800: query.append(" ");
0801:
0802: if (obc != null) {
0803: query.append("ORDER BY ");
0804: query.append(obc.getOrderBy());
0805: }
0806:
0807: else {
0808: query.append("ORDER BY ");
0809:
0810: query.append("parentCategoryId ASC, ");
0811: query.append("name ASC");
0812: }
0813:
0814: Query q = session.createQuery(query.toString());
0815:
0816: int queryPos = 0;
0817:
0818: q.setLong(queryPos++, groupId);
0819:
0820: Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
0821: mbCategory);
0822:
0823: MBCategory[] array = new MBCategoryImpl[3];
0824:
0825: array[0] = (MBCategory) objArray[0];
0826: array[1] = (MBCategory) objArray[1];
0827: array[2] = (MBCategory) objArray[2];
0828:
0829: return array;
0830: } catch (Exception e) {
0831: throw HibernateUtil.processException(e);
0832: } finally {
0833: closeSession(session);
0834: }
0835: }
0836:
0837: public List findByCompanyId(long companyId) throws SystemException {
0838: boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
0839: String finderClassName = MBCategory.class.getName();
0840: String finderMethodName = "findByCompanyId";
0841: String[] finderParams = new String[] { Long.class.getName() };
0842: Object[] finderArgs = new Object[] { new Long(companyId) };
0843:
0844: Object result = null;
0845:
0846: if (finderClassNameCacheEnabled) {
0847: result = FinderCache.getResult(finderClassName,
0848: finderMethodName, finderParams, finderArgs,
0849: getSessionFactory());
0850: }
0851:
0852: if (result == null) {
0853: Session session = null;
0854:
0855: try {
0856: session = openSession();
0857:
0858: StringMaker query = new StringMaker();
0859:
0860: query
0861: .append("FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
0862:
0863: query.append("companyId = ?");
0864:
0865: query.append(" ");
0866:
0867: query.append("ORDER BY ");
0868:
0869: query.append("parentCategoryId ASC, ");
0870: query.append("name ASC");
0871:
0872: Query q = session.createQuery(query.toString());
0873:
0874: int queryPos = 0;
0875:
0876: q.setLong(queryPos++, companyId);
0877:
0878: List list = q.list();
0879:
0880: FinderCache.putResult(finderClassNameCacheEnabled,
0881: finderClassName, finderMethodName,
0882: finderParams, finderArgs, list);
0883:
0884: return list;
0885: } catch (Exception e) {
0886: throw HibernateUtil.processException(e);
0887: } finally {
0888: closeSession(session);
0889: }
0890: } else {
0891: return (List) result;
0892: }
0893: }
0894:
0895: public List findByCompanyId(long companyId, int begin, int end)
0896: throws SystemException {
0897: return findByCompanyId(companyId, begin, end, null);
0898: }
0899:
0900: public List findByCompanyId(long companyId, int begin, int end,
0901: OrderByComparator obc) throws SystemException {
0902: boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
0903: String finderClassName = MBCategory.class.getName();
0904: String finderMethodName = "findByCompanyId";
0905: String[] finderParams = new String[] { Long.class.getName(),
0906:
0907: "java.lang.Integer", "java.lang.Integer",
0908: "com.liferay.portal.kernel.util.OrderByComparator" };
0909: Object[] finderArgs = new Object[] { new Long(companyId),
0910:
0911: String.valueOf(begin), String.valueOf(end), String.valueOf(obc) };
0912:
0913: Object result = null;
0914:
0915: if (finderClassNameCacheEnabled) {
0916: result = FinderCache.getResult(finderClassName,
0917: finderMethodName, finderParams, finderArgs,
0918: getSessionFactory());
0919: }
0920:
0921: if (result == null) {
0922: Session session = null;
0923:
0924: try {
0925: session = openSession();
0926:
0927: StringMaker query = new StringMaker();
0928:
0929: query
0930: .append("FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
0931:
0932: query.append("companyId = ?");
0933:
0934: query.append(" ");
0935:
0936: if (obc != null) {
0937: query.append("ORDER BY ");
0938: query.append(obc.getOrderBy());
0939: }
0940:
0941: else {
0942: query.append("ORDER BY ");
0943:
0944: query.append("parentCategoryId ASC, ");
0945: query.append("name ASC");
0946: }
0947:
0948: Query q = session.createQuery(query.toString());
0949:
0950: int queryPos = 0;
0951:
0952: q.setLong(queryPos++, companyId);
0953:
0954: List list = QueryUtil.list(q, getDialect(), begin, end);
0955:
0956: FinderCache.putResult(finderClassNameCacheEnabled,
0957: finderClassName, finderMethodName,
0958: finderParams, finderArgs, list);
0959:
0960: return list;
0961: } catch (Exception e) {
0962: throw HibernateUtil.processException(e);
0963: } finally {
0964: closeSession(session);
0965: }
0966: } else {
0967: return (List) result;
0968: }
0969: }
0970:
0971: public MBCategory findByCompanyId_First(long companyId,
0972: OrderByComparator obc) throws NoSuchCategoryException,
0973: SystemException {
0974: List list = findByCompanyId(companyId, 0, 1, obc);
0975:
0976: if (list.size() == 0) {
0977: StringMaker msg = new StringMaker();
0978:
0979: msg.append("No MBCategory exists with the key {");
0980:
0981: msg.append("companyId=" + companyId);
0982:
0983: msg.append(StringPool.CLOSE_CURLY_BRACE);
0984:
0985: throw new NoSuchCategoryException(msg.toString());
0986: } else {
0987: return (MBCategory) list.get(0);
0988: }
0989: }
0990:
0991: public MBCategory findByCompanyId_Last(long companyId,
0992: OrderByComparator obc) throws NoSuchCategoryException,
0993: SystemException {
0994: int count = countByCompanyId(companyId);
0995:
0996: List list = findByCompanyId(companyId, count - 1, count, obc);
0997:
0998: if (list.size() == 0) {
0999: StringMaker msg = new StringMaker();
1000:
1001: msg.append("No MBCategory exists with the key {");
1002:
1003: msg.append("companyId=" + companyId);
1004:
1005: msg.append(StringPool.CLOSE_CURLY_BRACE);
1006:
1007: throw new NoSuchCategoryException(msg.toString());
1008: } else {
1009: return (MBCategory) list.get(0);
1010: }
1011: }
1012:
1013: public MBCategory[] findByCompanyId_PrevAndNext(long categoryId,
1014: long companyId, OrderByComparator obc)
1015: throws NoSuchCategoryException, SystemException {
1016: MBCategory mbCategory = findByPrimaryKey(categoryId);
1017:
1018: int count = countByCompanyId(companyId);
1019:
1020: Session session = null;
1021:
1022: try {
1023: session = openSession();
1024:
1025: StringMaker query = new StringMaker();
1026:
1027: query
1028: .append("FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
1029:
1030: query.append("companyId = ?");
1031:
1032: query.append(" ");
1033:
1034: if (obc != null) {
1035: query.append("ORDER BY ");
1036: query.append(obc.getOrderBy());
1037: }
1038:
1039: else {
1040: query.append("ORDER BY ");
1041:
1042: query.append("parentCategoryId ASC, ");
1043: query.append("name ASC");
1044: }
1045:
1046: Query q = session.createQuery(query.toString());
1047:
1048: int queryPos = 0;
1049:
1050: q.setLong(queryPos++, companyId);
1051:
1052: Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1053: mbCategory);
1054:
1055: MBCategory[] array = new MBCategoryImpl[3];
1056:
1057: array[0] = (MBCategory) objArray[0];
1058: array[1] = (MBCategory) objArray[1];
1059: array[2] = (MBCategory) objArray[2];
1060:
1061: return array;
1062: } catch (Exception e) {
1063: throw HibernateUtil.processException(e);
1064: } finally {
1065: closeSession(session);
1066: }
1067: }
1068:
1069: public List findByG_P(long groupId, long parentCategoryId)
1070: throws SystemException {
1071: boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
1072: String finderClassName = MBCategory.class.getName();
1073: String finderMethodName = "findByG_P";
1074: String[] finderParams = new String[] { Long.class.getName(),
1075: Long.class.getName() };
1076: Object[] finderArgs = new Object[] { new Long(groupId),
1077: new Long(parentCategoryId) };
1078:
1079: Object result = null;
1080:
1081: if (finderClassNameCacheEnabled) {
1082: result = FinderCache.getResult(finderClassName,
1083: finderMethodName, finderParams, finderArgs,
1084: getSessionFactory());
1085: }
1086:
1087: if (result == null) {
1088: Session session = null;
1089:
1090: try {
1091: session = openSession();
1092:
1093: StringMaker query = new StringMaker();
1094:
1095: query
1096: .append("FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
1097:
1098: query.append("groupId = ?");
1099:
1100: query.append(" AND ");
1101:
1102: query.append("parentCategoryId = ?");
1103:
1104: query.append(" ");
1105:
1106: query.append("ORDER BY ");
1107:
1108: query.append("parentCategoryId ASC, ");
1109: query.append("name ASC");
1110:
1111: Query q = session.createQuery(query.toString());
1112:
1113: int queryPos = 0;
1114:
1115: q.setLong(queryPos++, groupId);
1116:
1117: q.setLong(queryPos++, parentCategoryId);
1118:
1119: List list = q.list();
1120:
1121: FinderCache.putResult(finderClassNameCacheEnabled,
1122: finderClassName, finderMethodName,
1123: finderParams, finderArgs, list);
1124:
1125: return list;
1126: } catch (Exception e) {
1127: throw HibernateUtil.processException(e);
1128: } finally {
1129: closeSession(session);
1130: }
1131: } else {
1132: return (List) result;
1133: }
1134: }
1135:
1136: public List findByG_P(long groupId, long parentCategoryId,
1137: int begin, int end) throws SystemException {
1138: return findByG_P(groupId, parentCategoryId, begin, end, null);
1139: }
1140:
1141: public List findByG_P(long groupId, long parentCategoryId,
1142: int begin, int end, OrderByComparator obc)
1143: throws SystemException {
1144: boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
1145: String finderClassName = MBCategory.class.getName();
1146: String finderMethodName = "findByG_P";
1147: String[] finderParams = new String[] { Long.class.getName(),
1148: Long.class.getName(),
1149:
1150: "java.lang.Integer", "java.lang.Integer",
1151: "com.liferay.portal.kernel.util.OrderByComparator" };
1152: Object[] finderArgs = new Object[] { new Long(groupId),
1153: new Long(parentCategoryId),
1154:
1155: String.valueOf(begin), String.valueOf(end),
1156: String.valueOf(obc) };
1157:
1158: Object result = null;
1159:
1160: if (finderClassNameCacheEnabled) {
1161: result = FinderCache.getResult(finderClassName,
1162: finderMethodName, finderParams, finderArgs,
1163: getSessionFactory());
1164: }
1165:
1166: if (result == null) {
1167: Session session = null;
1168:
1169: try {
1170: session = openSession();
1171:
1172: StringMaker query = new StringMaker();
1173:
1174: query
1175: .append("FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
1176:
1177: query.append("groupId = ?");
1178:
1179: query.append(" AND ");
1180:
1181: query.append("parentCategoryId = ?");
1182:
1183: query.append(" ");
1184:
1185: if (obc != null) {
1186: query.append("ORDER BY ");
1187: query.append(obc.getOrderBy());
1188: }
1189:
1190: else {
1191: query.append("ORDER BY ");
1192:
1193: query.append("parentCategoryId ASC, ");
1194: query.append("name ASC");
1195: }
1196:
1197: Query q = session.createQuery(query.toString());
1198:
1199: int queryPos = 0;
1200:
1201: q.setLong(queryPos++, groupId);
1202:
1203: q.setLong(queryPos++, parentCategoryId);
1204:
1205: List list = QueryUtil.list(q, getDialect(), begin, end);
1206:
1207: FinderCache.putResult(finderClassNameCacheEnabled,
1208: finderClassName, finderMethodName,
1209: finderParams, finderArgs, list);
1210:
1211: return list;
1212: } catch (Exception e) {
1213: throw HibernateUtil.processException(e);
1214: } finally {
1215: closeSession(session);
1216: }
1217: } else {
1218: return (List) result;
1219: }
1220: }
1221:
1222: public MBCategory findByG_P_First(long groupId,
1223: long parentCategoryId, OrderByComparator obc)
1224: throws NoSuchCategoryException, SystemException {
1225: List list = findByG_P(groupId, parentCategoryId, 0, 1, obc);
1226:
1227: if (list.size() == 0) {
1228: StringMaker msg = new StringMaker();
1229:
1230: msg.append("No MBCategory exists with the key {");
1231:
1232: msg.append("groupId=" + groupId);
1233:
1234: msg.append(", ");
1235: msg.append("parentCategoryId=" + parentCategoryId);
1236:
1237: msg.append(StringPool.CLOSE_CURLY_BRACE);
1238:
1239: throw new NoSuchCategoryException(msg.toString());
1240: } else {
1241: return (MBCategory) list.get(0);
1242: }
1243: }
1244:
1245: public MBCategory findByG_P_Last(long groupId,
1246: long parentCategoryId, OrderByComparator obc)
1247: throws NoSuchCategoryException, SystemException {
1248: int count = countByG_P(groupId, parentCategoryId);
1249:
1250: List list = findByG_P(groupId, parentCategoryId, count - 1,
1251: count, obc);
1252:
1253: if (list.size() == 0) {
1254: StringMaker msg = new StringMaker();
1255:
1256: msg.append("No MBCategory exists with the key {");
1257:
1258: msg.append("groupId=" + groupId);
1259:
1260: msg.append(", ");
1261: msg.append("parentCategoryId=" + parentCategoryId);
1262:
1263: msg.append(StringPool.CLOSE_CURLY_BRACE);
1264:
1265: throw new NoSuchCategoryException(msg.toString());
1266: } else {
1267: return (MBCategory) list.get(0);
1268: }
1269: }
1270:
1271: public MBCategory[] findByG_P_PrevAndNext(long categoryId,
1272: long groupId, long parentCategoryId, OrderByComparator obc)
1273: throws NoSuchCategoryException, SystemException {
1274: MBCategory mbCategory = findByPrimaryKey(categoryId);
1275:
1276: int count = countByG_P(groupId, parentCategoryId);
1277:
1278: Session session = null;
1279:
1280: try {
1281: session = openSession();
1282:
1283: StringMaker query = new StringMaker();
1284:
1285: query
1286: .append("FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
1287:
1288: query.append("groupId = ?");
1289:
1290: query.append(" AND ");
1291:
1292: query.append("parentCategoryId = ?");
1293:
1294: query.append(" ");
1295:
1296: if (obc != null) {
1297: query.append("ORDER BY ");
1298: query.append(obc.getOrderBy());
1299: }
1300:
1301: else {
1302: query.append("ORDER BY ");
1303:
1304: query.append("parentCategoryId ASC, ");
1305: query.append("name ASC");
1306: }
1307:
1308: Query q = session.createQuery(query.toString());
1309:
1310: int queryPos = 0;
1311:
1312: q.setLong(queryPos++, groupId);
1313:
1314: q.setLong(queryPos++, parentCategoryId);
1315:
1316: Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1317: mbCategory);
1318:
1319: MBCategory[] array = new MBCategoryImpl[3];
1320:
1321: array[0] = (MBCategory) objArray[0];
1322: array[1] = (MBCategory) objArray[1];
1323: array[2] = (MBCategory) objArray[2];
1324:
1325: return array;
1326: } catch (Exception e) {
1327: throw HibernateUtil.processException(e);
1328: } finally {
1329: closeSession(session);
1330: }
1331: }
1332:
1333: public List findWithDynamicQuery(
1334: DynamicQueryInitializer queryInitializer)
1335: throws SystemException {
1336: Session session = null;
1337:
1338: try {
1339: session = openSession();
1340:
1341: DynamicQuery query = queryInitializer.initialize(session);
1342:
1343: return query.list();
1344: } catch (Exception e) {
1345: throw HibernateUtil.processException(e);
1346: } finally {
1347: closeSession(session);
1348: }
1349: }
1350:
1351: public List findWithDynamicQuery(
1352: DynamicQueryInitializer queryInitializer, int begin, int end)
1353: throws SystemException {
1354: Session session = null;
1355:
1356: try {
1357: session = openSession();
1358:
1359: DynamicQuery query = queryInitializer.initialize(session);
1360:
1361: query.setLimit(begin, end);
1362:
1363: return query.list();
1364: } catch (Exception e) {
1365: throw HibernateUtil.processException(e);
1366: } finally {
1367: closeSession(session);
1368: }
1369: }
1370:
1371: public List findAll() throws SystemException {
1372: return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1373: }
1374:
1375: public List findAll(int begin, int end) throws SystemException {
1376: return findAll(begin, end, null);
1377: }
1378:
1379: public List findAll(int begin, int end, OrderByComparator obc)
1380: throws SystemException {
1381: boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
1382: String finderClassName = MBCategory.class.getName();
1383: String finderMethodName = "findAll";
1384: String[] finderParams = new String[] { "java.lang.Integer",
1385: "java.lang.Integer",
1386: "com.liferay.portal.kernel.util.OrderByComparator" };
1387: Object[] finderArgs = new Object[] { String.valueOf(begin),
1388: String.valueOf(end), String.valueOf(obc) };
1389:
1390: Object result = null;
1391:
1392: if (finderClassNameCacheEnabled) {
1393: result = FinderCache.getResult(finderClassName,
1394: finderMethodName, finderParams, finderArgs,
1395: getSessionFactory());
1396: }
1397:
1398: if (result == null) {
1399: Session session = null;
1400:
1401: try {
1402: session = openSession();
1403:
1404: StringMaker query = new StringMaker();
1405:
1406: query
1407: .append("FROM com.liferay.portlet.messageboards.model.MBCategory ");
1408:
1409: if (obc != null) {
1410: query.append("ORDER BY ");
1411: query.append(obc.getOrderBy());
1412: }
1413:
1414: else {
1415: query.append("ORDER BY ");
1416:
1417: query.append("parentCategoryId ASC, ");
1418: query.append("name ASC");
1419: }
1420:
1421: Query q = session.createQuery(query.toString());
1422:
1423: List list = QueryUtil.list(q, getDialect(), begin, end);
1424:
1425: if (obc == null) {
1426: Collections.sort(list);
1427: }
1428:
1429: FinderCache.putResult(finderClassNameCacheEnabled,
1430: finderClassName, finderMethodName,
1431: finderParams, finderArgs, list);
1432:
1433: return list;
1434: } catch (Exception e) {
1435: throw HibernateUtil.processException(e);
1436: } finally {
1437: closeSession(session);
1438: }
1439: } else {
1440: return (List) result;
1441: }
1442: }
1443:
1444: public void removeByUuid(String uuid) throws SystemException {
1445: Iterator itr = findByUuid(uuid).iterator();
1446:
1447: while (itr.hasNext()) {
1448: MBCategory mbCategory = (MBCategory) itr.next();
1449:
1450: remove(mbCategory);
1451: }
1452: }
1453:
1454: public void removeByUUID_G(String uuid, long groupId)
1455: throws NoSuchCategoryException, SystemException {
1456: MBCategory mbCategory = findByUUID_G(uuid, groupId);
1457:
1458: remove(mbCategory);
1459: }
1460:
1461: public void removeByGroupId(long groupId) throws SystemException {
1462: Iterator itr = findByGroupId(groupId).iterator();
1463:
1464: while (itr.hasNext()) {
1465: MBCategory mbCategory = (MBCategory) itr.next();
1466:
1467: remove(mbCategory);
1468: }
1469: }
1470:
1471: public void removeByCompanyId(long companyId)
1472: throws SystemException {
1473: Iterator itr = findByCompanyId(companyId).iterator();
1474:
1475: while (itr.hasNext()) {
1476: MBCategory mbCategory = (MBCategory) itr.next();
1477:
1478: remove(mbCategory);
1479: }
1480: }
1481:
1482: public void removeByG_P(long groupId, long parentCategoryId)
1483: throws SystemException {
1484: Iterator itr = findByG_P(groupId, parentCategoryId).iterator();
1485:
1486: while (itr.hasNext()) {
1487: MBCategory mbCategory = (MBCategory) itr.next();
1488:
1489: remove(mbCategory);
1490: }
1491: }
1492:
1493: public void removeAll() throws SystemException {
1494: Iterator itr = findAll().iterator();
1495:
1496: while (itr.hasNext()) {
1497: remove((MBCategory) itr.next());
1498: }
1499: }
1500:
1501: public int countByUuid(String uuid) throws SystemException {
1502: boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
1503: String finderClassName = MBCategory.class.getName();
1504: String finderMethodName = "countByUuid";
1505: String[] finderParams = new String[] { String.class.getName() };
1506: Object[] finderArgs = new Object[] { uuid };
1507:
1508: Object result = null;
1509:
1510: if (finderClassNameCacheEnabled) {
1511: result = FinderCache.getResult(finderClassName,
1512: finderMethodName, finderParams, finderArgs,
1513: getSessionFactory());
1514: }
1515:
1516: if (result == null) {
1517: Session session = null;
1518:
1519: try {
1520: session = openSession();
1521:
1522: StringMaker query = new StringMaker();
1523:
1524: query.append("SELECT COUNT(*) ");
1525: query
1526: .append("FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
1527:
1528: if (uuid == null) {
1529: query.append("uuid_ IS NULL");
1530: } else {
1531: query.append("uuid_ = ?");
1532: }
1533:
1534: query.append(" ");
1535:
1536: Query q = session.createQuery(query.toString());
1537:
1538: int queryPos = 0;
1539:
1540: if (uuid != null) {
1541: q.setString(queryPos++, uuid);
1542: }
1543:
1544: Long count = null;
1545:
1546: Iterator itr = q.list().iterator();
1547:
1548: if (itr.hasNext()) {
1549: count = (Long) itr.next();
1550: }
1551:
1552: if (count == null) {
1553: count = new Long(0);
1554: }
1555:
1556: FinderCache.putResult(finderClassNameCacheEnabled,
1557: finderClassName, finderMethodName,
1558: finderParams, finderArgs, count);
1559:
1560: return count.intValue();
1561: } catch (Exception e) {
1562: throw HibernateUtil.processException(e);
1563: } finally {
1564: closeSession(session);
1565: }
1566: } else {
1567: return ((Long) result).intValue();
1568: }
1569: }
1570:
1571: public int countByUUID_G(String uuid, long groupId)
1572: throws SystemException {
1573: boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
1574: String finderClassName = MBCategory.class.getName();
1575: String finderMethodName = "countByUUID_G";
1576: String[] finderParams = new String[] { String.class.getName(),
1577: Long.class.getName() };
1578: Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
1579:
1580: Object result = null;
1581:
1582: if (finderClassNameCacheEnabled) {
1583: result = FinderCache.getResult(finderClassName,
1584: finderMethodName, finderParams, finderArgs,
1585: getSessionFactory());
1586: }
1587:
1588: if (result == null) {
1589: Session session = null;
1590:
1591: try {
1592: session = openSession();
1593:
1594: StringMaker query = new StringMaker();
1595:
1596: query.append("SELECT COUNT(*) ");
1597: query
1598: .append("FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
1599:
1600: if (uuid == null) {
1601: query.append("uuid_ IS NULL");
1602: } else {
1603: query.append("uuid_ = ?");
1604: }
1605:
1606: query.append(" AND ");
1607:
1608: query.append("groupId = ?");
1609:
1610: query.append(" ");
1611:
1612: Query q = session.createQuery(query.toString());
1613:
1614: int queryPos = 0;
1615:
1616: if (uuid != null) {
1617: q.setString(queryPos++, uuid);
1618: }
1619:
1620: q.setLong(queryPos++, groupId);
1621:
1622: Long count = null;
1623:
1624: Iterator itr = q.list().iterator();
1625:
1626: if (itr.hasNext()) {
1627: count = (Long) itr.next();
1628: }
1629:
1630: if (count == null) {
1631: count = new Long(0);
1632: }
1633:
1634: FinderCache.putResult(finderClassNameCacheEnabled,
1635: finderClassName, finderMethodName,
1636: finderParams, finderArgs, count);
1637:
1638: return count.intValue();
1639: } catch (Exception e) {
1640: throw HibernateUtil.processException(e);
1641: } finally {
1642: closeSession(session);
1643: }
1644: } else {
1645: return ((Long) result).intValue();
1646: }
1647: }
1648:
1649: public int countByGroupId(long groupId) throws SystemException {
1650: boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
1651: String finderClassName = MBCategory.class.getName();
1652: String finderMethodName = "countByGroupId";
1653: String[] finderParams = new String[] { Long.class.getName() };
1654: Object[] finderArgs = new Object[] { new Long(groupId) };
1655:
1656: Object result = null;
1657:
1658: if (finderClassNameCacheEnabled) {
1659: result = FinderCache.getResult(finderClassName,
1660: finderMethodName, finderParams, finderArgs,
1661: getSessionFactory());
1662: }
1663:
1664: if (result == null) {
1665: Session session = null;
1666:
1667: try {
1668: session = openSession();
1669:
1670: StringMaker query = new StringMaker();
1671:
1672: query.append("SELECT COUNT(*) ");
1673: query
1674: .append("FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
1675:
1676: query.append("groupId = ?");
1677:
1678: query.append(" ");
1679:
1680: Query q = session.createQuery(query.toString());
1681:
1682: int queryPos = 0;
1683:
1684: q.setLong(queryPos++, groupId);
1685:
1686: Long count = null;
1687:
1688: Iterator itr = q.list().iterator();
1689:
1690: if (itr.hasNext()) {
1691: count = (Long) itr.next();
1692: }
1693:
1694: if (count == null) {
1695: count = new Long(0);
1696: }
1697:
1698: FinderCache.putResult(finderClassNameCacheEnabled,
1699: finderClassName, finderMethodName,
1700: finderParams, finderArgs, count);
1701:
1702: return count.intValue();
1703: } catch (Exception e) {
1704: throw HibernateUtil.processException(e);
1705: } finally {
1706: closeSession(session);
1707: }
1708: } else {
1709: return ((Long) result).intValue();
1710: }
1711: }
1712:
1713: public int countByCompanyId(long companyId) throws SystemException {
1714: boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
1715: String finderClassName = MBCategory.class.getName();
1716: String finderMethodName = "countByCompanyId";
1717: String[] finderParams = new String[] { Long.class.getName() };
1718: Object[] finderArgs = new Object[] { new Long(companyId) };
1719:
1720: Object result = null;
1721:
1722: if (finderClassNameCacheEnabled) {
1723: result = FinderCache.getResult(finderClassName,
1724: finderMethodName, finderParams, finderArgs,
1725: getSessionFactory());
1726: }
1727:
1728: if (result == null) {
1729: Session session = null;
1730:
1731: try {
1732: session = openSession();
1733:
1734: StringMaker query = new StringMaker();
1735:
1736: query.append("SELECT COUNT(*) ");
1737: query
1738: .append("FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
1739:
1740: query.append("companyId = ?");
1741:
1742: query.append(" ");
1743:
1744: Query q = session.createQuery(query.toString());
1745:
1746: int queryPos = 0;
1747:
1748: q.setLong(queryPos++, companyId);
1749:
1750: Long count = null;
1751:
1752: Iterator itr = q.list().iterator();
1753:
1754: if (itr.hasNext()) {
1755: count = (Long) itr.next();
1756: }
1757:
1758: if (count == null) {
1759: count = new Long(0);
1760: }
1761:
1762: FinderCache.putResult(finderClassNameCacheEnabled,
1763: finderClassName, finderMethodName,
1764: finderParams, finderArgs, count);
1765:
1766: return count.intValue();
1767: } catch (Exception e) {
1768: throw HibernateUtil.processException(e);
1769: } finally {
1770: closeSession(session);
1771: }
1772: } else {
1773: return ((Long) result).intValue();
1774: }
1775: }
1776:
1777: public int countByG_P(long groupId, long parentCategoryId)
1778: throws SystemException {
1779: boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
1780: String finderClassName = MBCategory.class.getName();
1781: String finderMethodName = "countByG_P";
1782: String[] finderParams = new String[] { Long.class.getName(),
1783: Long.class.getName() };
1784: Object[] finderArgs = new Object[] { new Long(groupId),
1785: new Long(parentCategoryId) };
1786:
1787: Object result = null;
1788:
1789: if (finderClassNameCacheEnabled) {
1790: result = FinderCache.getResult(finderClassName,
1791: finderMethodName, finderParams, finderArgs,
1792: getSessionFactory());
1793: }
1794:
1795: if (result == null) {
1796: Session session = null;
1797:
1798: try {
1799: session = openSession();
1800:
1801: StringMaker query = new StringMaker();
1802:
1803: query.append("SELECT COUNT(*) ");
1804: query
1805: .append("FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
1806:
1807: query.append("groupId = ?");
1808:
1809: query.append(" AND ");
1810:
1811: query.append("parentCategoryId = ?");
1812:
1813: query.append(" ");
1814:
1815: Query q = session.createQuery(query.toString());
1816:
1817: int queryPos = 0;
1818:
1819: q.setLong(queryPos++, groupId);
1820:
1821: q.setLong(queryPos++, parentCategoryId);
1822:
1823: Long count = null;
1824:
1825: Iterator itr = q.list().iterator();
1826:
1827: if (itr.hasNext()) {
1828: count = (Long) itr.next();
1829: }
1830:
1831: if (count == null) {
1832: count = new Long(0);
1833: }
1834:
1835: FinderCache.putResult(finderClassNameCacheEnabled,
1836: finderClassName, finderMethodName,
1837: finderParams, finderArgs, count);
1838:
1839: return count.intValue();
1840: } catch (Exception e) {
1841: throw HibernateUtil.processException(e);
1842: } finally {
1843: closeSession(session);
1844: }
1845: } else {
1846: return ((Long) result).intValue();
1847: }
1848: }
1849:
1850: public int countAll() throws SystemException {
1851: boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
1852: String finderClassName = MBCategory.class.getName();
1853: String finderMethodName = "countAll";
1854: String[] finderParams = new String[] {};
1855: Object[] finderArgs = new Object[] {};
1856:
1857: Object result = null;
1858:
1859: if (finderClassNameCacheEnabled) {
1860: result = FinderCache.getResult(finderClassName,
1861: finderMethodName, finderParams, finderArgs,
1862: getSessionFactory());
1863: }
1864:
1865: if (result == null) {
1866: Session session = null;
1867:
1868: try {
1869: session = openSession();
1870:
1871: Query q = session
1872: .createQuery("SELECT COUNT(*) FROM com.liferay.portlet.messageboards.model.MBCategory");
1873:
1874: Long count = null;
1875:
1876: Iterator itr = q.list().iterator();
1877:
1878: if (itr.hasNext()) {
1879: count = (Long) itr.next();
1880: }
1881:
1882: if (count == null) {
1883: count = new Long(0);
1884: }
1885:
1886: FinderCache.putResult(finderClassNameCacheEnabled,
1887: finderClassName, finderMethodName,
1888: finderParams, finderArgs, count);
1889:
1890: return count.intValue();
1891: } catch (Exception e) {
1892: throw HibernateUtil.processException(e);
1893: } finally {
1894: closeSession(session);
1895: }
1896: } else {
1897: return ((Long) result).intValue();
1898: }
1899: }
1900:
1901: protected void initDao() {
1902: }
1903:
1904: private static ModelListener _getListener() {
1905: if (Validator.isNotNull(_LISTENER)) {
1906: try {
1907: return (ModelListener) Class.forName(_LISTENER)
1908: .newInstance();
1909: } catch (Exception e) {
1910: _log.error(e);
1911: }
1912: }
1913:
1914: return null;
1915: }
1916:
1917: private static final String _LISTENER = GetterUtil
1918: .getString(PropsUtil
1919: .get("value.object.listener.com.liferay.portlet.messageboards.model.MBCategory"));
1920: private static Log _log = LogFactory
1921: .getLog(MBCategoryPersistenceImpl.class);
1922: }
|