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