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