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