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