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