1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.tags.service.persistence;
24  
25  import com.liferay.portal.SystemException;
26  import com.liferay.portal.kernel.dao.DynamicQuery;
27  import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
28  import com.liferay.portal.kernel.util.OrderByComparator;
29  import com.liferay.portal.kernel.util.StringMaker;
30  import com.liferay.portal.kernel.util.StringPool;
31  import com.liferay.portal.service.persistence.BasePersistence;
32  import com.liferay.portal.spring.hibernate.FinderCache;
33  import com.liferay.portal.spring.hibernate.HibernateUtil;
34  
35  import com.liferay.portlet.tags.NoSuchEntryException;
36  import com.liferay.portlet.tags.model.TagsEntry;
37  import com.liferay.portlet.tags.model.impl.TagsEntryImpl;
38  
39  import com.liferay.util.dao.hibernate.QueryPos;
40  import com.liferay.util.dao.hibernate.QueryUtil;
41  
42  import org.apache.commons.logging.Log;
43  import org.apache.commons.logging.LogFactory;
44  
45  import org.hibernate.Hibernate;
46  import org.hibernate.Query;
47  import org.hibernate.SQLQuery;
48  import org.hibernate.Session;
49  
50  import org.springframework.dao.DataAccessException;
51  
52  import org.springframework.jdbc.core.SqlParameter;
53  import org.springframework.jdbc.object.MappingSqlQuery;
54  import org.springframework.jdbc.object.SqlUpdate;
55  
56  import java.sql.ResultSet;
57  import java.sql.SQLException;
58  import java.sql.Types;
59  
60  import java.util.Collections;
61  import java.util.Iterator;
62  import java.util.List;
63  
64  /**
65   * <a href="TagsEntryPersistenceImpl.java.html"><b><i>View Source</i></b></a>
66   *
67   * @author Brian Wing Shun Chan
68   *
69   */
70  public class TagsEntryPersistenceImpl extends BasePersistence
71      implements TagsEntryPersistence {
72      public TagsEntry create(long entryId) {
73          TagsEntry tagsEntry = new TagsEntryImpl();
74          tagsEntry.setNew(true);
75          tagsEntry.setPrimaryKey(entryId);
76  
77          return tagsEntry;
78      }
79  
80      public TagsEntry remove(long entryId)
81          throws NoSuchEntryException, SystemException {
82          Session session = null;
83  
84          try {
85              session = openSession();
86  
87              TagsEntry tagsEntry = (TagsEntry)session.get(TagsEntryImpl.class,
88                      new Long(entryId));
89  
90              if (tagsEntry == null) {
91                  if (_log.isWarnEnabled()) {
92                      _log.warn("No TagsEntry exists with the primary key " +
93                          entryId);
94                  }
95  
96                  throw new NoSuchEntryException(
97                      "No TagsEntry exists with the primary key " + entryId);
98              }
99  
100             return remove(tagsEntry);
101         }
102         catch (NoSuchEntryException nsee) {
103             throw nsee;
104         }
105         catch (Exception e) {
106             throw HibernateUtil.processException(e);
107         }
108         finally {
109             closeSession(session);
110         }
111     }
112 
113     public TagsEntry remove(TagsEntry tagsEntry) throws SystemException {
114         try {
115             clearTagsAssets.clear(tagsEntry.getPrimaryKey());
116         }
117         catch (Exception e) {
118             throw HibernateUtil.processException(e);
119         }
120         finally {
121             FinderCache.clearCache("TagsAssets_TagsEntries");
122         }
123 
124         Session session = null;
125 
126         try {
127             session = openSession();
128             session.delete(tagsEntry);
129             session.flush();
130 
131             return tagsEntry;
132         }
133         catch (Exception e) {
134             throw HibernateUtil.processException(e);
135         }
136         finally {
137             closeSession(session);
138             FinderCache.clearCache(TagsEntry.class.getName());
139         }
140     }
141 
142     public TagsEntry update(com.liferay.portlet.tags.model.TagsEntry tagsEntry)
143         throws SystemException {
144         return update(tagsEntry, false);
145     }
146 
147     public TagsEntry update(
148         com.liferay.portlet.tags.model.TagsEntry tagsEntry, boolean merge)
149         throws SystemException {
150         FinderCache.clearCache("TagsAssets_TagsEntries");
151 
152         Session session = null;
153 
154         try {
155             session = openSession();
156 
157             if (merge) {
158                 session.merge(tagsEntry);
159             }
160             else {
161                 if (tagsEntry.isNew()) {
162                     session.save(tagsEntry);
163                 }
164             }
165 
166             session.flush();
167             tagsEntry.setNew(false);
168 
169             return tagsEntry;
170         }
171         catch (Exception e) {
172             throw HibernateUtil.processException(e);
173         }
174         finally {
175             closeSession(session);
176             FinderCache.clearCache(TagsEntry.class.getName());
177         }
178     }
179 
180     public TagsEntry findByPrimaryKey(long entryId)
181         throws NoSuchEntryException, SystemException {
182         TagsEntry tagsEntry = fetchByPrimaryKey(entryId);
183 
184         if (tagsEntry == null) {
185             if (_log.isWarnEnabled()) {
186                 _log.warn("No TagsEntry exists with the primary key " +
187                     entryId);
188             }
189 
190             throw new NoSuchEntryException(
191                 "No TagsEntry exists with the primary key " + entryId);
192         }
193 
194         return tagsEntry;
195     }
196 
197     public TagsEntry fetchByPrimaryKey(long entryId) throws SystemException {
198         Session session = null;
199 
200         try {
201             session = openSession();
202 
203             return (TagsEntry)session.get(TagsEntryImpl.class, new Long(entryId));
204         }
205         catch (Exception e) {
206             throw HibernateUtil.processException(e);
207         }
208         finally {
209             closeSession(session);
210         }
211     }
212 
213     public TagsEntry findByC_N(long companyId, String name)
214         throws NoSuchEntryException, SystemException {
215         TagsEntry tagsEntry = fetchByC_N(companyId, name);
216 
217         if (tagsEntry == null) {
218             StringMaker msg = new StringMaker();
219             msg.append("No TagsEntry exists with the key ");
220             msg.append(StringPool.OPEN_CURLY_BRACE);
221             msg.append("companyId=");
222             msg.append(companyId);
223             msg.append(", ");
224             msg.append("name=");
225             msg.append(name);
226             msg.append(StringPool.CLOSE_CURLY_BRACE);
227 
228             if (_log.isWarnEnabled()) {
229                 _log.warn(msg.toString());
230             }
231 
232             throw new NoSuchEntryException(msg.toString());
233         }
234 
235         return tagsEntry;
236     }
237 
238     public TagsEntry fetchByC_N(long companyId, String name)
239         throws SystemException {
240         String finderClassName = TagsEntry.class.getName();
241         String finderMethodName = "fetchByC_N";
242         String[] finderParams = new String[] {
243                 Long.class.getName(), String.class.getName()
244             };
245         Object[] finderArgs = new Object[] { new Long(companyId), name };
246         Object result = FinderCache.getResult(finderClassName,
247                 finderMethodName, finderParams, finderArgs, getSessionFactory());
248 
249         if (result == null) {
250             Session session = null;
251 
252             try {
253                 session = openSession();
254 
255                 StringMaker query = new StringMaker();
256                 query.append(
257                     "FROM com.liferay.portlet.tags.model.TagsEntry WHERE ");
258                 query.append("companyId = ?");
259                 query.append(" AND ");
260 
261                 if (name == null) {
262                     query.append("name IS NULL");
263                 }
264                 else {
265                     query.append("name = ?");
266                 }
267 
268                 query.append(" ");
269                 query.append("ORDER BY ");
270                 query.append("name ASC");
271 
272                 Query q = session.createQuery(query.toString());
273                 int queryPos = 0;
274                 q.setLong(queryPos++, companyId);
275 
276                 if (name != null) {
277                     q.setString(queryPos++, name);
278                 }
279 
280                 List list = q.list();
281                 FinderCache.putResult(finderClassName, finderMethodName,
282                     finderParams, finderArgs, list);
283 
284                 if (list.size() == 0) {
285                     return null;
286                 }
287                 else {
288                     return (TagsEntry)list.get(0);
289                 }
290             }
291             catch (Exception e) {
292                 throw HibernateUtil.processException(e);
293             }
294             finally {
295                 closeSession(session);
296             }
297         }
298         else {
299             List list = (List)result;
300 
301             if (list.size() == 0) {
302                 return null;
303             }
304             else {
305                 return (TagsEntry)list.get(0);
306             }
307         }
308     }
309 
310     public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
311         throws SystemException {
312         Session session = null;
313 
314         try {
315             session = openSession();
316 
317             DynamicQuery query = queryInitializer.initialize(session);
318 
319             return query.list();
320         }
321         catch (Exception e) {
322             throw HibernateUtil.processException(e);
323         }
324         finally {
325             closeSession(session);
326         }
327     }
328 
329     public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
330         int begin, int end) throws SystemException {
331         Session session = null;
332 
333         try {
334             session = openSession();
335 
336             DynamicQuery query = queryInitializer.initialize(session);
337             query.setLimit(begin, end);
338 
339             return query.list();
340         }
341         catch (Exception e) {
342             throw HibernateUtil.processException(e);
343         }
344         finally {
345             closeSession(session);
346         }
347     }
348 
349     public List findAll() throws SystemException {
350         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
351     }
352 
353     public List findAll(int begin, int end) throws SystemException {
354         return findAll(begin, end, null);
355     }
356 
357     public List findAll(int begin, int end, OrderByComparator obc)
358         throws SystemException {
359         String finderClassName = TagsEntry.class.getName();
360         String finderMethodName = "findAll";
361         String[] finderParams = new String[] {
362                 "java.lang.Integer", "java.lang.Integer",
363                 "com.liferay.portal.kernel.util.OrderByComparator"
364             };
365         Object[] finderArgs = new Object[] {
366                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
367             };
368         Object result = FinderCache.getResult(finderClassName,
369                 finderMethodName, finderParams, finderArgs, getSessionFactory());
370 
371         if (result == null) {
372             Session session = null;
373 
374             try {
375                 session = openSession();
376 
377                 StringMaker query = new StringMaker();
378                 query.append("FROM com.liferay.portlet.tags.model.TagsEntry ");
379 
380                 if (obc != null) {
381                     query.append("ORDER BY ");
382                     query.append(obc.getOrderBy());
383                 }
384                 else {
385                     query.append("ORDER BY ");
386                     query.append("name ASC");
387                 }
388 
389                 Query q = session.createQuery(query.toString());
390                 List list = QueryUtil.list(q, getDialect(), begin, end);
391 
392                 if (obc == null) {
393                     Collections.sort(list);
394                 }
395 
396                 FinderCache.putResult(finderClassName, finderMethodName,
397                     finderParams, finderArgs, list);
398 
399                 return list;
400             }
401             catch (Exception e) {
402                 throw HibernateUtil.processException(e);
403             }
404             finally {
405                 closeSession(session);
406             }
407         }
408         else {
409             return (List)result;
410         }
411     }
412 
413     public void removeByC_N(long companyId, String name)
414         throws NoSuchEntryException, SystemException {
415         TagsEntry tagsEntry = findByC_N(companyId, name);
416         remove(tagsEntry);
417     }
418 
419     public void removeAll() throws SystemException {
420         Iterator itr = findAll().iterator();
421 
422         while (itr.hasNext()) {
423             remove((TagsEntry)itr.next());
424         }
425     }
426 
427     public int countByC_N(long companyId, String name)
428         throws SystemException {
429         String finderClassName = TagsEntry.class.getName();
430         String finderMethodName = "countByC_N";
431         String[] finderParams = new String[] {
432                 Long.class.getName(), String.class.getName()
433             };
434         Object[] finderArgs = new Object[] { new Long(companyId), name };
435         Object result = FinderCache.getResult(finderClassName,
436                 finderMethodName, finderParams, finderArgs, getSessionFactory());
437 
438         if (result == null) {
439             Session session = null;
440 
441             try {
442                 session = openSession();
443 
444                 StringMaker query = new StringMaker();
445                 query.append("SELECT COUNT(*) ");
446                 query.append(
447                     "FROM com.liferay.portlet.tags.model.TagsEntry WHERE ");
448                 query.append("companyId = ?");
449                 query.append(" AND ");
450 
451                 if (name == null) {
452                     query.append("name IS NULL");
453                 }
454                 else {
455                     query.append("name = ?");
456                 }
457 
458                 query.append(" ");
459 
460                 Query q = session.createQuery(query.toString());
461                 int queryPos = 0;
462                 q.setLong(queryPos++, companyId);
463 
464                 if (name != null) {
465                     q.setString(queryPos++, name);
466                 }
467 
468                 Long count = null;
469                 Iterator itr = q.list().iterator();
470 
471                 if (itr.hasNext()) {
472                     count = (Long)itr.next();
473                 }
474 
475                 if (count == null) {
476                     count = new Long(0);
477                 }
478 
479                 FinderCache.putResult(finderClassName, finderMethodName,
480                     finderParams, finderArgs, count);
481 
482                 return count.intValue();
483             }
484             catch (Exception e) {
485                 throw HibernateUtil.processException(e);
486             }
487             finally {
488                 closeSession(session);
489             }
490         }
491         else {
492             return ((Long)result).intValue();
493         }
494     }
495 
496     public int countAll() throws SystemException {
497         String finderClassName = TagsEntry.class.getName();
498         String finderMethodName = "countAll";
499         String[] finderParams = new String[] {  };
500         Object[] finderArgs = new Object[] {  };
501         Object result = FinderCache.getResult(finderClassName,
502                 finderMethodName, finderParams, finderArgs, getSessionFactory());
503 
504         if (result == null) {
505             Session session = null;
506 
507             try {
508                 session = openSession();
509 
510                 StringMaker query = new StringMaker();
511                 query.append("SELECT COUNT(*) ");
512                 query.append("FROM com.liferay.portlet.tags.model.TagsEntry");
513 
514                 Query q = session.createQuery(query.toString());
515                 Long count = null;
516                 Iterator itr = q.list().iterator();
517 
518                 if (itr.hasNext()) {
519                     count = (Long)itr.next();
520                 }
521 
522                 if (count == null) {
523                     count = new Long(0);
524                 }
525 
526                 FinderCache.putResult(finderClassName, finderMethodName,
527                     finderParams, finderArgs, count);
528 
529                 return count.intValue();
530             }
531             catch (Exception e) {
532                 throw HibernateUtil.processException(e);
533             }
534             finally {
535                 closeSession(session);
536             }
537         }
538         else {
539             return ((Long)result).intValue();
540         }
541     }
542 
543     public List getTagsAssets(long pk)
544         throws NoSuchEntryException, SystemException {
545         return getTagsAssets(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
546     }
547 
548     public List getTagsAssets(long pk, int begin, int end)
549         throws NoSuchEntryException, SystemException {
550         return getTagsAssets(pk, begin, end, null);
551     }
552 
553     public List getTagsAssets(long pk, int begin, int end, OrderByComparator obc)
554         throws NoSuchEntryException, SystemException {
555         String finderClassName = "TagsAssets_TagsEntries";
556         String finderMethodName = "getTagsAssets";
557         String[] finderParams = new String[] {
558                 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
559                 "com.liferay.portal.kernel.util.OrderByComparator"
560             };
561         Object[] finderArgs = new Object[] {
562                 new Long(pk), String.valueOf(begin), String.valueOf(end),
563                 String.valueOf(obc)
564             };
565         Object result = FinderCache.getResult(finderClassName,
566                 finderMethodName, finderParams, finderArgs, getSessionFactory());
567 
568         if (result == null) {
569             Session session = null;
570 
571             try {
572                 session = HibernateUtil.openSession();
573 
574                 StringMaker sm = new StringMaker();
575                 sm.append(_SQL_GETTAGSASSETS);
576 
577                 if (obc != null) {
578                     sm.append("ORDER BY ");
579                     sm.append(obc.getOrderBy());
580                 }
581 
582                 String sql = sm.toString();
583                 SQLQuery q = session.createSQLQuery(sql);
584                 q.addEntity("TagsAsset",
585                     com.liferay.portlet.tags.model.impl.TagsAssetImpl.class);
586 
587                 QueryPos qPos = QueryPos.getInstance(q);
588                 qPos.add(pk);
589 
590                 List list = QueryUtil.list(q, getDialect(), begin, end);
591                 FinderCache.putResult(finderClassName, finderMethodName,
592                     finderParams, finderArgs, list);
593 
594                 return list;
595             }
596             catch (Exception e) {
597                 throw new SystemException(e);
598             }
599             finally {
600                 closeSession(session);
601             }
602         }
603         else {
604             return (List)result;
605         }
606     }
607 
608     public int getTagsAssetsSize(long pk) throws SystemException {
609         String finderClassName = "TagsAssets_TagsEntries";
610         String finderMethodName = "getTagsAssetsSize";
611         String[] finderParams = new String[] { Long.class.getName() };
612         Object[] finderArgs = new Object[] { new Long(pk) };
613         Object result = FinderCache.getResult(finderClassName,
614                 finderMethodName, finderParams, finderArgs, getSessionFactory());
615 
616         if (result == null) {
617             Session session = null;
618 
619             try {
620                 session = openSession();
621 
622                 SQLQuery q = session.createSQLQuery(_SQL_GETTAGSASSETSSIZE);
623                 q.addScalar(HibernateUtil.getCountColumnName(), Hibernate.LONG);
624 
625                 QueryPos qPos = QueryPos.getInstance(q);
626                 qPos.add(pk);
627 
628                 Long count = null;
629                 Iterator itr = q.list().iterator();
630 
631                 if (itr.hasNext()) {
632                     count = (Long)itr.next();
633                 }
634 
635                 if (count == null) {
636                     count = new Long(0);
637                 }
638 
639                 FinderCache.putResult(finderClassName, finderMethodName,
640                     finderParams, finderArgs, count);
641 
642                 return count.intValue();
643             }
644             catch (Exception e) {
645                 throw HibernateUtil.processException(e);
646             }
647             finally {
648                 closeSession(session);
649             }
650         }
651         else {
652             return ((Long)result).intValue();
653         }
654     }
655 
656     public boolean containsTagsAsset(long pk, long tagsAssetPK)
657         throws SystemException {
658         String finderClassName = "TagsAssets_TagsEntries";
659         String finderMethodName = "containsTagsAssets";
660         String[] finderParams = new String[] {
661                 Long.class.getName(), Long.class.getName()
662             };
663         Object[] finderArgs = new Object[] { new Long(pk), new Long(tagsAssetPK) };
664         Object result = FinderCache.getResult(finderClassName,
665                 finderMethodName, finderParams, finderArgs, getSessionFactory());
666 
667         if (result == null) {
668             try {
669                 Boolean value = Boolean.valueOf(containsTagsAsset.contains(pk,
670                             tagsAssetPK));
671                 FinderCache.putResult(finderClassName, finderMethodName,
672                     finderParams, finderArgs, value);
673 
674                 return value.booleanValue();
675             }
676             catch (DataAccessException dae) {
677                 throw new SystemException(dae);
678             }
679         }
680         else {
681             return ((Boolean)result).booleanValue();
682         }
683     }
684 
685     public boolean containsTagsAssets(long pk) throws SystemException {
686         if (getTagsAssetsSize(pk) > 0) {
687             return true;
688         }
689         else {
690             return false;
691         }
692     }
693 
694     public void addTagsAsset(long pk, long tagsAssetPK)
695         throws NoSuchEntryException, 
696             com.liferay.portlet.tags.NoSuchAssetException, SystemException {
697         try {
698             addTagsAsset.add(pk, tagsAssetPK);
699         }
700         catch (DataAccessException dae) {
701             throw new SystemException(dae);
702         }
703         finally {
704             FinderCache.clearCache("TagsAssets_TagsEntries");
705         }
706     }
707 
708     public void addTagsAsset(long pk,
709         com.liferay.portlet.tags.model.TagsAsset tagsAsset)
710         throws NoSuchEntryException, 
711             com.liferay.portlet.tags.NoSuchAssetException, SystemException {
712         try {
713             addTagsAsset.add(pk, tagsAsset.getPrimaryKey());
714         }
715         catch (DataAccessException dae) {
716             throw new SystemException(dae);
717         }
718         finally {
719             FinderCache.clearCache("TagsAssets_TagsEntries");
720         }
721     }
722 
723     public void addTagsAssets(long pk, long[] tagsAssetPKs)
724         throws NoSuchEntryException, 
725             com.liferay.portlet.tags.NoSuchAssetException, SystemException {
726         try {
727             for (int i = 0; i < tagsAssetPKs.length; i++) {
728                 addTagsAsset.add(pk, tagsAssetPKs[i]);
729             }
730         }
731         catch (DataAccessException dae) {
732             throw new SystemException(dae);
733         }
734         finally {
735             FinderCache.clearCache("TagsAssets_TagsEntries");
736         }
737     }
738 
739     public void addTagsAssets(long pk, List tagsAssets)
740         throws NoSuchEntryException, 
741             com.liferay.portlet.tags.NoSuchAssetException, SystemException {
742         try {
743             for (int i = 0; i < tagsAssets.size(); i++) {
744                 com.liferay.portlet.tags.model.TagsAsset tagsAsset = (com.liferay.portlet.tags.model.TagsAsset)tagsAssets.get(i);
745                 addTagsAsset.add(pk, tagsAsset.getPrimaryKey());
746             }
747         }
748         catch (DataAccessException dae) {
749             throw new SystemException(dae);
750         }
751         finally {
752             FinderCache.clearCache("TagsAssets_TagsEntries");
753         }
754     }
755 
756     public void clearTagsAssets(long pk)
757         throws NoSuchEntryException, SystemException {
758         try {
759             clearTagsAssets.clear(pk);
760         }
761         catch (DataAccessException dae) {
762             throw new SystemException(dae);
763         }
764         finally {
765             FinderCache.clearCache("TagsAssets_TagsEntries");
766         }
767     }
768 
769     public void removeTagsAsset(long pk, long tagsAssetPK)
770         throws NoSuchEntryException, 
771             com.liferay.portlet.tags.NoSuchAssetException, SystemException {
772         try {
773             removeTagsAsset.remove(pk, tagsAssetPK);
774         }
775         catch (DataAccessException dae) {
776             throw new SystemException(dae);
777         }
778         finally {
779             FinderCache.clearCache("TagsAssets_TagsEntries");
780         }
781     }
782 
783     public void removeTagsAsset(long pk,
784         com.liferay.portlet.tags.model.TagsAsset tagsAsset)
785         throws NoSuchEntryException, 
786             com.liferay.portlet.tags.NoSuchAssetException, SystemException {
787         try {
788             removeTagsAsset.remove(pk, tagsAsset.getPrimaryKey());
789         }
790         catch (DataAccessException dae) {
791             throw new SystemException(dae);
792         }
793         finally {
794             FinderCache.clearCache("TagsAssets_TagsEntries");
795         }
796     }
797 
798     public void removeTagsAssets(long pk, long[] tagsAssetPKs)
799         throws NoSuchEntryException, 
800             com.liferay.portlet.tags.NoSuchAssetException, SystemException {
801         try {
802             for (int i = 0; i < tagsAssetPKs.length; i++) {
803                 removeTagsAsset.remove(pk, tagsAssetPKs[i]);
804             }
805         }
806         catch (DataAccessException dae) {
807             throw new SystemException(dae);
808         }
809         finally {
810             FinderCache.clearCache("TagsAssets_TagsEntries");
811         }
812     }
813 
814     public void removeTagsAssets(long pk, List tagsAssets)
815         throws NoSuchEntryException, 
816             com.liferay.portlet.tags.NoSuchAssetException, SystemException {
817         try {
818             for (int i = 0; i < tagsAssets.size(); i++) {
819                 com.liferay.portlet.tags.model.TagsAsset tagsAsset = (com.liferay.portlet.tags.model.TagsAsset)tagsAssets.get(i);
820                 removeTagsAsset.remove(pk, tagsAsset.getPrimaryKey());
821             }
822         }
823         catch (DataAccessException dae) {
824             throw new SystemException(dae);
825         }
826         finally {
827             FinderCache.clearCache("TagsAssets_TagsEntries");
828         }
829     }
830 
831     public void setTagsAssets(long pk, long[] tagsAssetPKs)
832         throws NoSuchEntryException, 
833             com.liferay.portlet.tags.NoSuchAssetException, SystemException {
834         try {
835             clearTagsAssets.clear(pk);
836 
837             for (int i = 0; i < tagsAssetPKs.length; i++) {
838                 addTagsAsset.add(pk, tagsAssetPKs[i]);
839             }
840         }
841         catch (DataAccessException dae) {
842             throw new SystemException(dae);
843         }
844         finally {
845             FinderCache.clearCache("TagsAssets_TagsEntries");
846         }
847     }
848 
849     public void setTagsAssets(long pk, List tagsAssets)
850         throws NoSuchEntryException, 
851             com.liferay.portlet.tags.NoSuchAssetException, SystemException {
852         try {
853             clearTagsAssets.clear(pk);
854 
855             for (int i = 0; i < tagsAssets.size(); i++) {
856                 com.liferay.portlet.tags.model.TagsAsset tagsAsset = (com.liferay.portlet.tags.model.TagsAsset)tagsAssets.get(i);
857                 addTagsAsset.add(pk, tagsAsset.getPrimaryKey());
858             }
859         }
860         catch (DataAccessException dae) {
861             throw new SystemException(dae);
862         }
863         finally {
864             FinderCache.clearCache("TagsAssets_TagsEntries");
865         }
866     }
867 
868     protected void initDao() {
869         containsTagsAsset = new ContainsTagsAsset(this);
870         addTagsAsset = new AddTagsAsset(this);
871         clearTagsAssets = new ClearTagsAssets(this);
872         removeTagsAsset = new RemoveTagsAsset(this);
873     }
874 
875     protected ContainsTagsAsset containsTagsAsset;
876     protected AddTagsAsset addTagsAsset;
877     protected ClearTagsAssets clearTagsAssets;
878     protected RemoveTagsAsset removeTagsAsset;
879 
880     protected class ContainsTagsAsset extends MappingSqlQuery {
881         protected ContainsTagsAsset(TagsEntryPersistenceImpl persistenceImpl) {
882             super(persistenceImpl.getDataSource(), _SQL_CONTAINSTAGSASSET);
883             declareParameter(new SqlParameter(Types.BIGINT));
884             declareParameter(new SqlParameter(Types.BIGINT));
885             compile();
886         }
887 
888         protected Object mapRow(ResultSet rs, int rowNumber)
889             throws SQLException {
890             return new Integer(rs.getInt("COUNT_VALUE"));
891         }
892 
893         protected boolean contains(long entryId, long assetId) {
894             List results = execute(new Object[] {
895                         new Long(entryId), new Long(assetId)
896                     });
897 
898             if (results.size() > 0) {
899                 Integer count = (Integer)results.get(0);
900 
901                 if (count.intValue() > 0) {
902                     return true;
903                 }
904             }
905 
906             return false;
907         }
908     }
909 
910     protected class AddTagsAsset extends SqlUpdate {
911         protected AddTagsAsset(TagsEntryPersistenceImpl persistenceImpl) {
912             super(persistenceImpl.getDataSource(),
913                 "INSERT INTO TagsAssets_TagsEntries (entryId, assetId) VALUES (?, ?)");
914             _persistenceImpl = persistenceImpl;
915             declareParameter(new SqlParameter(Types.BIGINT));
916             declareParameter(new SqlParameter(Types.BIGINT));
917             compile();
918         }
919 
920         protected void add(long entryId, long assetId) {
921             if (!_persistenceImpl.containsTagsAsset.contains(entryId, assetId)) {
922                 update(new Object[] { new Long(entryId), new Long(assetId) });
923             }
924         }
925 
926         private TagsEntryPersistenceImpl _persistenceImpl;
927     }
928 
929     protected class ClearTagsAssets extends SqlUpdate {
930         protected ClearTagsAssets(TagsEntryPersistenceImpl persistenceImpl) {
931             super(persistenceImpl.getDataSource(),
932                 "DELETE FROM TagsAssets_TagsEntries WHERE entryId = ?");
933             declareParameter(new SqlParameter(Types.BIGINT));
934             compile();
935         }
936 
937         protected void clear(long entryId) {
938             update(new Object[] { new Long(entryId) });
939         }
940     }
941 
942     protected class RemoveTagsAsset extends SqlUpdate {
943         protected RemoveTagsAsset(TagsEntryPersistenceImpl persistenceImpl) {
944             super(persistenceImpl.getDataSource(),
945                 "DELETE FROM TagsAssets_TagsEntries WHERE entryId = ? AND assetId = ?");
946             declareParameter(new SqlParameter(Types.BIGINT));
947             declareParameter(new SqlParameter(Types.BIGINT));
948             compile();
949         }
950 
951         protected void remove(long entryId, long assetId) {
952             update(new Object[] { new Long(entryId), new Long(assetId) });
953         }
954     }
955 
956     private static final String _SQL_GETTAGSASSETS = "SELECT {TagsAsset.*} FROM TagsAsset INNER JOIN TagsAssets_TagsEntries ON (TagsAssets_TagsEntries.assetId = TagsAsset.assetId) WHERE (TagsAssets_TagsEntries.entryId = ?)";
957     private static final String _SQL_GETTAGSASSETSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM TagsAssets_TagsEntries WHERE entryId = ?";
958     private static final String _SQL_CONTAINSTAGSASSET = "SELECT COUNT(*) AS COUNT_VALUE FROM TagsAssets_TagsEntries WHERE entryId = ? AND assetId = ?";
959     private static Log _log = LogFactory.getLog(TagsEntryPersistenceImpl.class);
960 }