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