1   /**
2    * Copyright (c) 2000-2009 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.annotation.BeanReference;
27  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
28  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
29  import com.liferay.portal.kernel.dao.jdbc.RowMapper;
30  import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
31  import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
32  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
33  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
34  import com.liferay.portal.kernel.dao.orm.Query;
35  import com.liferay.portal.kernel.dao.orm.QueryPos;
36  import com.liferay.portal.kernel.dao.orm.QueryUtil;
37  import com.liferay.portal.kernel.dao.orm.SQLQuery;
38  import com.liferay.portal.kernel.dao.orm.Session;
39  import com.liferay.portal.kernel.dao.orm.Type;
40  import com.liferay.portal.kernel.log.Log;
41  import com.liferay.portal.kernel.log.LogFactoryUtil;
42  import com.liferay.portal.kernel.util.GetterUtil;
43  import com.liferay.portal.kernel.util.OrderByComparator;
44  import com.liferay.portal.kernel.util.StringPool;
45  import com.liferay.portal.kernel.util.StringUtil;
46  import com.liferay.portal.model.ModelListener;
47  import com.liferay.portal.service.persistence.BatchSessionUtil;
48  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
49  
50  import com.liferay.portlet.tags.NoSuchAssetException;
51  import com.liferay.portlet.tags.model.TagsAsset;
52  import com.liferay.portlet.tags.model.impl.TagsAssetImpl;
53  import com.liferay.portlet.tags.model.impl.TagsAssetModelImpl;
54  
55  import java.sql.Types;
56  
57  import java.util.ArrayList;
58  import java.util.Collections;
59  import java.util.Iterator;
60  import java.util.List;
61  
62  /**
63   * <a href="TagsAssetPersistenceImpl.java.html"><b><i>View Source</i></b></a>
64   *
65   * @author Brian Wing Shun Chan
66   *
67   */
68  public class TagsAssetPersistenceImpl extends BasePersistenceImpl
69      implements TagsAssetPersistence {
70      public TagsAsset create(long assetId) {
71          TagsAsset tagsAsset = new TagsAssetImpl();
72  
73          tagsAsset.setNew(true);
74          tagsAsset.setPrimaryKey(assetId);
75  
76          return tagsAsset;
77      }
78  
79      public TagsAsset remove(long assetId)
80          throws NoSuchAssetException, SystemException {
81          Session session = null;
82  
83          try {
84              session = openSession();
85  
86              TagsAsset tagsAsset = (TagsAsset)session.get(TagsAssetImpl.class,
87                      new Long(assetId));
88  
89              if (tagsAsset == null) {
90                  if (_log.isWarnEnabled()) {
91                      _log.warn("No TagsAsset exists with the primary key " +
92                          assetId);
93                  }
94  
95                  throw new NoSuchAssetException(
96                      "No TagsAsset exists with the primary key " + assetId);
97              }
98  
99              return remove(tagsAsset);
100         }
101         catch (NoSuchAssetException nsee) {
102             throw nsee;
103         }
104         catch (Exception e) {
105             throw processException(e);
106         }
107         finally {
108             closeSession(session);
109         }
110     }
111 
112     public TagsAsset remove(TagsAsset tagsAsset) throws SystemException {
113         for (ModelListener listener : listeners) {
114             listener.onBeforeRemove(tagsAsset);
115         }
116 
117         tagsAsset = removeImpl(tagsAsset);
118 
119         for (ModelListener listener : listeners) {
120             listener.onAfterRemove(tagsAsset);
121         }
122 
123         return tagsAsset;
124     }
125 
126     protected TagsAsset removeImpl(TagsAsset tagsAsset)
127         throws SystemException {
128         try {
129             clearTagsEntries.clear(tagsAsset.getPrimaryKey());
130         }
131         catch (Exception e) {
132             throw processException(e);
133         }
134         finally {
135             FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
136         }
137 
138         Session session = null;
139 
140         try {
141             session = openSession();
142 
143             if (BatchSessionUtil.isEnabled()) {
144                 Object staleObject = session.get(TagsAssetImpl.class,
145                         tagsAsset.getPrimaryKeyObj());
146 
147                 if (staleObject != null) {
148                     session.evict(staleObject);
149                 }
150             }
151 
152             session.delete(tagsAsset);
153 
154             session.flush();
155 
156             return tagsAsset;
157         }
158         catch (Exception e) {
159             throw processException(e);
160         }
161         finally {
162             closeSession(session);
163 
164             FinderCacheUtil.clearCache(TagsAsset.class.getName());
165         }
166     }
167 
168     /**
169      * @deprecated Use <code>update(TagsAsset tagsAsset, boolean merge)</code>.
170      */
171     public TagsAsset update(TagsAsset tagsAsset) throws SystemException {
172         if (_log.isWarnEnabled()) {
173             _log.warn(
174                 "Using the deprecated update(TagsAsset tagsAsset) method. Use update(TagsAsset tagsAsset, boolean merge) instead.");
175         }
176 
177         return update(tagsAsset, false);
178     }
179 
180     /**
181      * Add, update, or merge, the entity. This method also calls the model
182      * listeners to trigger the proper events associated with adding, deleting,
183      * or updating an entity.
184      *
185      * @param        tagsAsset the entity to add, update, or merge
186      * @param        merge boolean value for whether to merge the entity. The
187      *                default value is false. Setting merge to true is more
188      *                expensive and should only be true when tagsAsset is
189      *                transient. See LEP-5473 for a detailed discussion of this
190      *                method.
191      * @return        true if the portlet can be displayed via Ajax
192      */
193     public TagsAsset update(TagsAsset tagsAsset, boolean merge)
194         throws SystemException {
195         boolean isNew = tagsAsset.isNew();
196 
197         for (ModelListener listener : listeners) {
198             if (isNew) {
199                 listener.onBeforeCreate(tagsAsset);
200             }
201             else {
202                 listener.onBeforeUpdate(tagsAsset);
203             }
204         }
205 
206         tagsAsset = updateImpl(tagsAsset, merge);
207 
208         for (ModelListener listener : listeners) {
209             if (isNew) {
210                 listener.onAfterCreate(tagsAsset);
211             }
212             else {
213                 listener.onAfterUpdate(tagsAsset);
214             }
215         }
216 
217         return tagsAsset;
218     }
219 
220     public TagsAsset updateImpl(
221         com.liferay.portlet.tags.model.TagsAsset tagsAsset, boolean merge)
222         throws SystemException {
223         FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
224 
225         Session session = null;
226 
227         try {
228             session = openSession();
229 
230             BatchSessionUtil.update(session, tagsAsset, merge);
231 
232             tagsAsset.setNew(false);
233 
234             return tagsAsset;
235         }
236         catch (Exception e) {
237             throw processException(e);
238         }
239         finally {
240             closeSession(session);
241 
242             FinderCacheUtil.clearCache(TagsAsset.class.getName());
243         }
244     }
245 
246     public TagsAsset findByPrimaryKey(long assetId)
247         throws NoSuchAssetException, SystemException {
248         TagsAsset tagsAsset = fetchByPrimaryKey(assetId);
249 
250         if (tagsAsset == null) {
251             if (_log.isWarnEnabled()) {
252                 _log.warn("No TagsAsset exists with the primary key " +
253                     assetId);
254             }
255 
256             throw new NoSuchAssetException(
257                 "No TagsAsset exists with the primary key " + assetId);
258         }
259 
260         return tagsAsset;
261     }
262 
263     public TagsAsset fetchByPrimaryKey(long assetId) throws SystemException {
264         Session session = null;
265 
266         try {
267             session = openSession();
268 
269             return (TagsAsset)session.get(TagsAssetImpl.class, new Long(assetId));
270         }
271         catch (Exception e) {
272             throw processException(e);
273         }
274         finally {
275             closeSession(session);
276         }
277     }
278 
279     public List<TagsAsset> findByCompanyId(long companyId)
280         throws SystemException {
281         boolean finderClassNameCacheEnabled = TagsAssetModelImpl.CACHE_ENABLED;
282         String finderClassName = TagsAsset.class.getName();
283         String finderMethodName = "findByCompanyId";
284         String[] finderParams = new String[] { Long.class.getName() };
285         Object[] finderArgs = new Object[] { new Long(companyId) };
286 
287         Object result = null;
288 
289         if (finderClassNameCacheEnabled) {
290             result = FinderCacheUtil.getResult(finderClassName,
291                     finderMethodName, finderParams, finderArgs, this);
292         }
293 
294         if (result == null) {
295             Session session = null;
296 
297             try {
298                 session = openSession();
299 
300                 StringBuilder query = new StringBuilder();
301 
302                 query.append(
303                     "FROM com.liferay.portlet.tags.model.TagsAsset WHERE ");
304 
305                 query.append("companyId = ?");
306 
307                 query.append(" ");
308 
309                 Query q = session.createQuery(query.toString());
310 
311                 QueryPos qPos = QueryPos.getInstance(q);
312 
313                 qPos.add(companyId);
314 
315                 List<TagsAsset> list = q.list();
316 
317                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
318                     finderClassName, finderMethodName, finderParams,
319                     finderArgs, list);
320 
321                 return list;
322             }
323             catch (Exception e) {
324                 throw processException(e);
325             }
326             finally {
327                 closeSession(session);
328             }
329         }
330         else {
331             return (List<TagsAsset>)result;
332         }
333     }
334 
335     public List<TagsAsset> findByCompanyId(long companyId, int start, int end)
336         throws SystemException {
337         return findByCompanyId(companyId, start, end, null);
338     }
339 
340     public List<TagsAsset> findByCompanyId(long companyId, int start, int end,
341         OrderByComparator obc) throws SystemException {
342         boolean finderClassNameCacheEnabled = TagsAssetModelImpl.CACHE_ENABLED;
343         String finderClassName = TagsAsset.class.getName();
344         String finderMethodName = "findByCompanyId";
345         String[] finderParams = new String[] {
346                 Long.class.getName(),
347                 
348                 "java.lang.Integer", "java.lang.Integer",
349                 "com.liferay.portal.kernel.util.OrderByComparator"
350             };
351         Object[] finderArgs = new Object[] {
352                 new Long(companyId),
353                 
354                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
355             };
356 
357         Object result = null;
358 
359         if (finderClassNameCacheEnabled) {
360             result = FinderCacheUtil.getResult(finderClassName,
361                     finderMethodName, finderParams, finderArgs, this);
362         }
363 
364         if (result == null) {
365             Session session = null;
366 
367             try {
368                 session = openSession();
369 
370                 StringBuilder query = new StringBuilder();
371 
372                 query.append(
373                     "FROM com.liferay.portlet.tags.model.TagsAsset WHERE ");
374 
375                 query.append("companyId = ?");
376 
377                 query.append(" ");
378 
379                 if (obc != null) {
380                     query.append("ORDER BY ");
381                     query.append(obc.getOrderBy());
382                 }
383 
384                 Query q = session.createQuery(query.toString());
385 
386                 QueryPos qPos = QueryPos.getInstance(q);
387 
388                 qPos.add(companyId);
389 
390                 List<TagsAsset> list = (List<TagsAsset>)QueryUtil.list(q,
391                         getDialect(), start, end);
392 
393                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
394                     finderClassName, finderMethodName, finderParams,
395                     finderArgs, list);
396 
397                 return list;
398             }
399             catch (Exception e) {
400                 throw processException(e);
401             }
402             finally {
403                 closeSession(session);
404             }
405         }
406         else {
407             return (List<TagsAsset>)result;
408         }
409     }
410 
411     public TagsAsset findByCompanyId_First(long companyId, OrderByComparator obc)
412         throws NoSuchAssetException, SystemException {
413         List<TagsAsset> list = findByCompanyId(companyId, 0, 1, obc);
414 
415         if (list.size() == 0) {
416             StringBuilder msg = new StringBuilder();
417 
418             msg.append("No TagsAsset exists with the key {");
419 
420             msg.append("companyId=" + companyId);
421 
422             msg.append(StringPool.CLOSE_CURLY_BRACE);
423 
424             throw new NoSuchAssetException(msg.toString());
425         }
426         else {
427             return list.get(0);
428         }
429     }
430 
431     public TagsAsset findByCompanyId_Last(long companyId, OrderByComparator obc)
432         throws NoSuchAssetException, SystemException {
433         int count = countByCompanyId(companyId);
434 
435         List<TagsAsset> list = findByCompanyId(companyId, count - 1, count, obc);
436 
437         if (list.size() == 0) {
438             StringBuilder msg = new StringBuilder();
439 
440             msg.append("No TagsAsset exists with the key {");
441 
442             msg.append("companyId=" + companyId);
443 
444             msg.append(StringPool.CLOSE_CURLY_BRACE);
445 
446             throw new NoSuchAssetException(msg.toString());
447         }
448         else {
449             return list.get(0);
450         }
451     }
452 
453     public TagsAsset[] findByCompanyId_PrevAndNext(long assetId,
454         long companyId, OrderByComparator obc)
455         throws NoSuchAssetException, SystemException {
456         TagsAsset tagsAsset = findByPrimaryKey(assetId);
457 
458         int count = countByCompanyId(companyId);
459 
460         Session session = null;
461 
462         try {
463             session = openSession();
464 
465             StringBuilder query = new StringBuilder();
466 
467             query.append("FROM com.liferay.portlet.tags.model.TagsAsset WHERE ");
468 
469             query.append("companyId = ?");
470 
471             query.append(" ");
472 
473             if (obc != null) {
474                 query.append("ORDER BY ");
475                 query.append(obc.getOrderBy());
476             }
477 
478             Query q = session.createQuery(query.toString());
479 
480             QueryPos qPos = QueryPos.getInstance(q);
481 
482             qPos.add(companyId);
483 
484             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
485                     tagsAsset);
486 
487             TagsAsset[] array = new TagsAssetImpl[3];
488 
489             array[0] = (TagsAsset)objArray[0];
490             array[1] = (TagsAsset)objArray[1];
491             array[2] = (TagsAsset)objArray[2];
492 
493             return array;
494         }
495         catch (Exception e) {
496             throw processException(e);
497         }
498         finally {
499             closeSession(session);
500         }
501     }
502 
503     public TagsAsset findByC_C(long classNameId, long classPK)
504         throws NoSuchAssetException, SystemException {
505         TagsAsset tagsAsset = fetchByC_C(classNameId, classPK);
506 
507         if (tagsAsset == null) {
508             StringBuilder msg = new StringBuilder();
509 
510             msg.append("No TagsAsset exists with the key {");
511 
512             msg.append("classNameId=" + classNameId);
513 
514             msg.append(", ");
515             msg.append("classPK=" + classPK);
516 
517             msg.append(StringPool.CLOSE_CURLY_BRACE);
518 
519             if (_log.isWarnEnabled()) {
520                 _log.warn(msg.toString());
521             }
522 
523             throw new NoSuchAssetException(msg.toString());
524         }
525 
526         return tagsAsset;
527     }
528 
529     public TagsAsset fetchByC_C(long classNameId, long classPK)
530         throws SystemException {
531         boolean finderClassNameCacheEnabled = TagsAssetModelImpl.CACHE_ENABLED;
532         String finderClassName = TagsAsset.class.getName();
533         String finderMethodName = "fetchByC_C";
534         String[] finderParams = new String[] {
535                 Long.class.getName(), Long.class.getName()
536             };
537         Object[] finderArgs = new Object[] {
538                 new Long(classNameId), new Long(classPK)
539             };
540 
541         Object result = null;
542 
543         if (finderClassNameCacheEnabled) {
544             result = FinderCacheUtil.getResult(finderClassName,
545                     finderMethodName, finderParams, finderArgs, this);
546         }
547 
548         if (result == null) {
549             Session session = null;
550 
551             try {
552                 session = openSession();
553 
554                 StringBuilder query = new StringBuilder();
555 
556                 query.append(
557                     "FROM com.liferay.portlet.tags.model.TagsAsset WHERE ");
558 
559                 query.append("classNameId = ?");
560 
561                 query.append(" AND ");
562 
563                 query.append("classPK = ?");
564 
565                 query.append(" ");
566 
567                 Query q = session.createQuery(query.toString());
568 
569                 QueryPos qPos = QueryPos.getInstance(q);
570 
571                 qPos.add(classNameId);
572 
573                 qPos.add(classPK);
574 
575                 List<TagsAsset> list = q.list();
576 
577                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
578                     finderClassName, finderMethodName, finderParams,
579                     finderArgs, list);
580 
581                 if (list.size() == 0) {
582                     return null;
583                 }
584                 else {
585                     return list.get(0);
586                 }
587             }
588             catch (Exception e) {
589                 throw processException(e);
590             }
591             finally {
592                 closeSession(session);
593             }
594         }
595         else {
596             List<TagsAsset> list = (List<TagsAsset>)result;
597 
598             if (list.size() == 0) {
599                 return null;
600             }
601             else {
602                 return list.get(0);
603             }
604         }
605     }
606 
607     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
608         throws SystemException {
609         Session session = null;
610 
611         try {
612             session = openSession();
613 
614             dynamicQuery.compile(session);
615 
616             return dynamicQuery.list();
617         }
618         catch (Exception e) {
619             throw processException(e);
620         }
621         finally {
622             closeSession(session);
623         }
624     }
625 
626     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
627         int start, int end) throws SystemException {
628         Session session = null;
629 
630         try {
631             session = openSession();
632 
633             dynamicQuery.setLimit(start, end);
634 
635             dynamicQuery.compile(session);
636 
637             return dynamicQuery.list();
638         }
639         catch (Exception e) {
640             throw processException(e);
641         }
642         finally {
643             closeSession(session);
644         }
645     }
646 
647     public List<TagsAsset> findAll() throws SystemException {
648         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
649     }
650 
651     public List<TagsAsset> findAll(int start, int end)
652         throws SystemException {
653         return findAll(start, end, null);
654     }
655 
656     public List<TagsAsset> findAll(int start, int end, OrderByComparator obc)
657         throws SystemException {
658         boolean finderClassNameCacheEnabled = TagsAssetModelImpl.CACHE_ENABLED;
659         String finderClassName = TagsAsset.class.getName();
660         String finderMethodName = "findAll";
661         String[] finderParams = new String[] {
662                 "java.lang.Integer", "java.lang.Integer",
663                 "com.liferay.portal.kernel.util.OrderByComparator"
664             };
665         Object[] finderArgs = new Object[] {
666                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
667             };
668 
669         Object result = null;
670 
671         if (finderClassNameCacheEnabled) {
672             result = FinderCacheUtil.getResult(finderClassName,
673                     finderMethodName, finderParams, finderArgs, this);
674         }
675 
676         if (result == null) {
677             Session session = null;
678 
679             try {
680                 session = openSession();
681 
682                 StringBuilder query = new StringBuilder();
683 
684                 query.append("FROM com.liferay.portlet.tags.model.TagsAsset ");
685 
686                 if (obc != null) {
687                     query.append("ORDER BY ");
688                     query.append(obc.getOrderBy());
689                 }
690 
691                 Query q = session.createQuery(query.toString());
692 
693                 List<TagsAsset> list = null;
694 
695                 if (obc == null) {
696                     list = (List<TagsAsset>)QueryUtil.list(q, getDialect(),
697                             start, end, false);
698 
699                     Collections.sort(list);
700                 }
701                 else {
702                     list = (List<TagsAsset>)QueryUtil.list(q, getDialect(),
703                             start, end);
704                 }
705 
706                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
707                     finderClassName, finderMethodName, finderParams,
708                     finderArgs, list);
709 
710                 return list;
711             }
712             catch (Exception e) {
713                 throw processException(e);
714             }
715             finally {
716                 closeSession(session);
717             }
718         }
719         else {
720             return (List<TagsAsset>)result;
721         }
722     }
723 
724     public void removeByCompanyId(long companyId) throws SystemException {
725         for (TagsAsset tagsAsset : findByCompanyId(companyId)) {
726             remove(tagsAsset);
727         }
728     }
729 
730     public void removeByC_C(long classNameId, long classPK)
731         throws NoSuchAssetException, SystemException {
732         TagsAsset tagsAsset = findByC_C(classNameId, classPK);
733 
734         remove(tagsAsset);
735     }
736 
737     public void removeAll() throws SystemException {
738         for (TagsAsset tagsAsset : findAll()) {
739             remove(tagsAsset);
740         }
741     }
742 
743     public int countByCompanyId(long companyId) throws SystemException {
744         boolean finderClassNameCacheEnabled = TagsAssetModelImpl.CACHE_ENABLED;
745         String finderClassName = TagsAsset.class.getName();
746         String finderMethodName = "countByCompanyId";
747         String[] finderParams = new String[] { Long.class.getName() };
748         Object[] finderArgs = new Object[] { new Long(companyId) };
749 
750         Object result = null;
751 
752         if (finderClassNameCacheEnabled) {
753             result = FinderCacheUtil.getResult(finderClassName,
754                     finderMethodName, finderParams, finderArgs, this);
755         }
756 
757         if (result == null) {
758             Session session = null;
759 
760             try {
761                 session = openSession();
762 
763                 StringBuilder query = new StringBuilder();
764 
765                 query.append("SELECT COUNT(*) ");
766                 query.append(
767                     "FROM com.liferay.portlet.tags.model.TagsAsset WHERE ");
768 
769                 query.append("companyId = ?");
770 
771                 query.append(" ");
772 
773                 Query q = session.createQuery(query.toString());
774 
775                 QueryPos qPos = QueryPos.getInstance(q);
776 
777                 qPos.add(companyId);
778 
779                 Long count = null;
780 
781                 Iterator<Long> itr = q.list().iterator();
782 
783                 if (itr.hasNext()) {
784                     count = itr.next();
785                 }
786 
787                 if (count == null) {
788                     count = new Long(0);
789                 }
790 
791                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
792                     finderClassName, finderMethodName, finderParams,
793                     finderArgs, count);
794 
795                 return count.intValue();
796             }
797             catch (Exception e) {
798                 throw processException(e);
799             }
800             finally {
801                 closeSession(session);
802             }
803         }
804         else {
805             return ((Long)result).intValue();
806         }
807     }
808 
809     public int countByC_C(long classNameId, long classPK)
810         throws SystemException {
811         boolean finderClassNameCacheEnabled = TagsAssetModelImpl.CACHE_ENABLED;
812         String finderClassName = TagsAsset.class.getName();
813         String finderMethodName = "countByC_C";
814         String[] finderParams = new String[] {
815                 Long.class.getName(), Long.class.getName()
816             };
817         Object[] finderArgs = new Object[] {
818                 new Long(classNameId), new Long(classPK)
819             };
820 
821         Object result = null;
822 
823         if (finderClassNameCacheEnabled) {
824             result = FinderCacheUtil.getResult(finderClassName,
825                     finderMethodName, finderParams, finderArgs, this);
826         }
827 
828         if (result == null) {
829             Session session = null;
830 
831             try {
832                 session = openSession();
833 
834                 StringBuilder query = new StringBuilder();
835 
836                 query.append("SELECT COUNT(*) ");
837                 query.append(
838                     "FROM com.liferay.portlet.tags.model.TagsAsset WHERE ");
839 
840                 query.append("classNameId = ?");
841 
842                 query.append(" AND ");
843 
844                 query.append("classPK = ?");
845 
846                 query.append(" ");
847 
848                 Query q = session.createQuery(query.toString());
849 
850                 QueryPos qPos = QueryPos.getInstance(q);
851 
852                 qPos.add(classNameId);
853 
854                 qPos.add(classPK);
855 
856                 Long count = null;
857 
858                 Iterator<Long> itr = q.list().iterator();
859 
860                 if (itr.hasNext()) {
861                     count = itr.next();
862                 }
863 
864                 if (count == null) {
865                     count = new Long(0);
866                 }
867 
868                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
869                     finderClassName, finderMethodName, finderParams,
870                     finderArgs, count);
871 
872                 return count.intValue();
873             }
874             catch (Exception e) {
875                 throw processException(e);
876             }
877             finally {
878                 closeSession(session);
879             }
880         }
881         else {
882             return ((Long)result).intValue();
883         }
884     }
885 
886     public int countAll() throws SystemException {
887         boolean finderClassNameCacheEnabled = TagsAssetModelImpl.CACHE_ENABLED;
888         String finderClassName = TagsAsset.class.getName();
889         String finderMethodName = "countAll";
890         String[] finderParams = new String[] {  };
891         Object[] finderArgs = new Object[] {  };
892 
893         Object result = null;
894 
895         if (finderClassNameCacheEnabled) {
896             result = FinderCacheUtil.getResult(finderClassName,
897                     finderMethodName, finderParams, finderArgs, this);
898         }
899 
900         if (result == null) {
901             Session session = null;
902 
903             try {
904                 session = openSession();
905 
906                 Query q = session.createQuery(
907                         "SELECT COUNT(*) FROM com.liferay.portlet.tags.model.TagsAsset");
908 
909                 Long count = null;
910 
911                 Iterator<Long> itr = q.list().iterator();
912 
913                 if (itr.hasNext()) {
914                     count = itr.next();
915                 }
916 
917                 if (count == null) {
918                     count = new Long(0);
919                 }
920 
921                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
922                     finderClassName, finderMethodName, finderParams,
923                     finderArgs, count);
924 
925                 return count.intValue();
926             }
927             catch (Exception e) {
928                 throw processException(e);
929             }
930             finally {
931                 closeSession(session);
932             }
933         }
934         else {
935             return ((Long)result).intValue();
936         }
937     }
938 
939     public List<com.liferay.portlet.tags.model.TagsEntry> getTagsEntries(
940         long pk) throws SystemException {
941         return getTagsEntries(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
942     }
943 
944     public List<com.liferay.portlet.tags.model.TagsEntry> getTagsEntries(
945         long pk, int start, int end) throws SystemException {
946         return getTagsEntries(pk, start, end, null);
947     }
948 
949     public List<com.liferay.portlet.tags.model.TagsEntry> getTagsEntries(
950         long pk, int start, int end, OrderByComparator obc)
951         throws SystemException {
952         boolean finderClassNameCacheEnabled = TagsAssetModelImpl.CACHE_ENABLED_TAGSASSETS_TAGSENTRIES;
953 
954         String finderClassName = "TagsAssets_TagsEntries";
955 
956         String finderMethodName = "getTagsEntries";
957         String[] finderParams = new String[] {
958                 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
959                 "com.liferay.portal.kernel.util.OrderByComparator"
960             };
961         Object[] finderArgs = new Object[] {
962                 new Long(pk), String.valueOf(start), String.valueOf(end),
963                 String.valueOf(obc)
964             };
965 
966         Object result = null;
967 
968         if (finderClassNameCacheEnabled) {
969             result = FinderCacheUtil.getResult(finderClassName,
970                     finderMethodName, finderParams, finderArgs, this);
971         }
972 
973         if (result == null) {
974             Session session = null;
975 
976             try {
977                 session = openSession();
978 
979                 StringBuilder sb = new StringBuilder();
980 
981                 sb.append(_SQL_GETTAGSENTRIES);
982 
983                 if (obc != null) {
984                     sb.append("ORDER BY ");
985                     sb.append(obc.getOrderBy());
986                 }
987 
988                 else {
989                     sb.append("ORDER BY ");
990 
991                     sb.append("TagsEntry.name ASC");
992                 }
993 
994                 String sql = sb.toString();
995 
996                 SQLQuery q = session.createSQLQuery(sql);
997 
998                 q.addEntity("TagsEntry",
999                     com.liferay.portlet.tags.model.impl.TagsEntryImpl.class);
1000
1001                QueryPos qPos = QueryPos.getInstance(q);
1002
1003                qPos.add(pk);
1004
1005                List<com.liferay.portlet.tags.model.TagsEntry> list = (List<com.liferay.portlet.tags.model.TagsEntry>)QueryUtil.list(q,
1006                        getDialect(), start, end);
1007
1008                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1009                    finderClassName, finderMethodName, finderParams,
1010                    finderArgs, list);
1011
1012                return list;
1013            }
1014            catch (Exception e) {
1015                throw processException(e);
1016            }
1017            finally {
1018                closeSession(session);
1019            }
1020        }
1021        else {
1022            return (List<com.liferay.portlet.tags.model.TagsEntry>)result;
1023        }
1024    }
1025
1026    public int getTagsEntriesSize(long pk) throws SystemException {
1027        boolean finderClassNameCacheEnabled = TagsAssetModelImpl.CACHE_ENABLED_TAGSASSETS_TAGSENTRIES;
1028
1029        String finderClassName = "TagsAssets_TagsEntries";
1030
1031        String finderMethodName = "getTagsEntriesSize";
1032        String[] finderParams = new String[] { Long.class.getName() };
1033        Object[] finderArgs = new Object[] { new Long(pk) };
1034
1035        Object result = null;
1036
1037        if (finderClassNameCacheEnabled) {
1038            result = FinderCacheUtil.getResult(finderClassName,
1039                    finderMethodName, finderParams, finderArgs, this);
1040        }
1041
1042        if (result == null) {
1043            Session session = null;
1044
1045            try {
1046                session = openSession();
1047
1048                SQLQuery q = session.createSQLQuery(_SQL_GETTAGSENTRIESSIZE);
1049
1050                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1051
1052                QueryPos qPos = QueryPos.getInstance(q);
1053
1054                qPos.add(pk);
1055
1056                Long count = null;
1057
1058                Iterator<Long> itr = q.list().iterator();
1059
1060                if (itr.hasNext()) {
1061                    count = itr.next();
1062                }
1063
1064                if (count == null) {
1065                    count = new Long(0);
1066                }
1067
1068                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1069                    finderClassName, finderMethodName, finderParams,
1070                    finderArgs, count);
1071
1072                return count.intValue();
1073            }
1074            catch (Exception e) {
1075                throw processException(e);
1076            }
1077            finally {
1078                closeSession(session);
1079            }
1080        }
1081        else {
1082            return ((Long)result).intValue();
1083        }
1084    }
1085
1086    public boolean containsTagsEntry(long pk, long tagsEntryPK)
1087        throws SystemException {
1088        boolean finderClassNameCacheEnabled = TagsAssetModelImpl.CACHE_ENABLED_TAGSASSETS_TAGSENTRIES;
1089
1090        String finderClassName = "TagsAssets_TagsEntries";
1091
1092        String finderMethodName = "containsTagsEntries";
1093        String[] finderParams = new String[] {
1094                Long.class.getName(),
1095                
1096                Long.class.getName()
1097            };
1098        Object[] finderArgs = new Object[] { new Long(pk), new Long(tagsEntryPK) };
1099
1100        Object result = null;
1101
1102        if (finderClassNameCacheEnabled) {
1103            result = FinderCacheUtil.getResult(finderClassName,
1104                    finderMethodName, finderParams, finderArgs, this);
1105        }
1106
1107        if (result == null) {
1108            try {
1109                Boolean value = Boolean.valueOf(containsTagsEntry.contains(pk,
1110                            tagsEntryPK));
1111
1112                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1113                    finderClassName, finderMethodName, finderParams,
1114                    finderArgs, value);
1115
1116                return value.booleanValue();
1117            }
1118            catch (Exception e) {
1119                throw processException(e);
1120            }
1121        }
1122        else {
1123            return ((Boolean)result).booleanValue();
1124        }
1125    }
1126
1127    public boolean containsTagsEntries(long pk) throws SystemException {
1128        if (getTagsEntriesSize(pk) > 0) {
1129            return true;
1130        }
1131        else {
1132            return false;
1133        }
1134    }
1135
1136    public void addTagsEntry(long pk, long tagsEntryPK)
1137        throws SystemException {
1138        try {
1139            addTagsEntry.add(pk, tagsEntryPK);
1140        }
1141        catch (Exception e) {
1142            throw processException(e);
1143        }
1144        finally {
1145            FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1146        }
1147    }
1148
1149    public void addTagsEntry(long pk,
1150        com.liferay.portlet.tags.model.TagsEntry tagsEntry)
1151        throws SystemException {
1152        try {
1153            addTagsEntry.add(pk, tagsEntry.getPrimaryKey());
1154        }
1155        catch (Exception e) {
1156            throw processException(e);
1157        }
1158        finally {
1159            FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1160        }
1161    }
1162
1163    public void addTagsEntries(long pk, long[] tagsEntryPKs)
1164        throws SystemException {
1165        try {
1166            for (long tagsEntryPK : tagsEntryPKs) {
1167                addTagsEntry.add(pk, tagsEntryPK);
1168            }
1169        }
1170        catch (Exception e) {
1171            throw processException(e);
1172        }
1173        finally {
1174            FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1175        }
1176    }
1177
1178    public void addTagsEntries(long pk,
1179        List<com.liferay.portlet.tags.model.TagsEntry> tagsEntries)
1180        throws SystemException {
1181        try {
1182            for (com.liferay.portlet.tags.model.TagsEntry tagsEntry : tagsEntries) {
1183                addTagsEntry.add(pk, tagsEntry.getPrimaryKey());
1184            }
1185        }
1186        catch (Exception e) {
1187            throw processException(e);
1188        }
1189        finally {
1190            FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1191        }
1192    }
1193
1194    public void clearTagsEntries(long pk) throws SystemException {
1195        try {
1196            clearTagsEntries.clear(pk);
1197        }
1198        catch (Exception e) {
1199            throw processException(e);
1200        }
1201        finally {
1202            FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1203        }
1204    }
1205
1206    public void removeTagsEntry(long pk, long tagsEntryPK)
1207        throws SystemException {
1208        try {
1209            removeTagsEntry.remove(pk, tagsEntryPK);
1210        }
1211        catch (Exception e) {
1212            throw processException(e);
1213        }
1214        finally {
1215            FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1216        }
1217    }
1218
1219    public void removeTagsEntry(long pk,
1220        com.liferay.portlet.tags.model.TagsEntry tagsEntry)
1221        throws SystemException {
1222        try {
1223            removeTagsEntry.remove(pk, tagsEntry.getPrimaryKey());
1224        }
1225        catch (Exception e) {
1226            throw processException(e);
1227        }
1228        finally {
1229            FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1230        }
1231    }
1232
1233    public void removeTagsEntries(long pk, long[] tagsEntryPKs)
1234        throws SystemException {
1235        try {
1236            for (long tagsEntryPK : tagsEntryPKs) {
1237                removeTagsEntry.remove(pk, tagsEntryPK);
1238            }
1239        }
1240        catch (Exception e) {
1241            throw processException(e);
1242        }
1243        finally {
1244            FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1245        }
1246    }
1247
1248    public void removeTagsEntries(long pk,
1249        List<com.liferay.portlet.tags.model.TagsEntry> tagsEntries)
1250        throws SystemException {
1251        try {
1252            for (com.liferay.portlet.tags.model.TagsEntry tagsEntry : tagsEntries) {
1253                removeTagsEntry.remove(pk, tagsEntry.getPrimaryKey());
1254            }
1255        }
1256        catch (Exception e) {
1257            throw processException(e);
1258        }
1259        finally {
1260            FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1261        }
1262    }
1263
1264    public void setTagsEntries(long pk, long[] tagsEntryPKs)
1265        throws SystemException {
1266        try {
1267            clearTagsEntries.clear(pk);
1268
1269            for (long tagsEntryPK : tagsEntryPKs) {
1270                addTagsEntry.add(pk, tagsEntryPK);
1271            }
1272        }
1273        catch (Exception e) {
1274            throw processException(e);
1275        }
1276        finally {
1277            FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1278        }
1279    }
1280
1281    public void setTagsEntries(long pk,
1282        List<com.liferay.portlet.tags.model.TagsEntry> tagsEntries)
1283        throws SystemException {
1284        try {
1285            clearTagsEntries.clear(pk);
1286
1287            for (com.liferay.portlet.tags.model.TagsEntry tagsEntry : tagsEntries) {
1288                addTagsEntry.add(pk, tagsEntry.getPrimaryKey());
1289            }
1290        }
1291        catch (Exception e) {
1292            throw processException(e);
1293        }
1294        finally {
1295            FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1296        }
1297    }
1298
1299    public void afterPropertiesSet() {
1300        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1301                    com.liferay.portal.util.PropsUtil.get(
1302                        "value.object.listener.com.liferay.portlet.tags.model.TagsAsset")));
1303
1304        if (listenerClassNames.length > 0) {
1305            try {
1306                List<ModelListener> listenersList = new ArrayList<ModelListener>();
1307
1308                for (String listenerClassName : listenerClassNames) {
1309                    listenersList.add((ModelListener)Class.forName(
1310                            listenerClassName).newInstance());
1311                }
1312
1313                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1314            }
1315            catch (Exception e) {
1316                _log.error(e);
1317            }
1318        }
1319
1320        containsTagsEntry = new ContainsTagsEntry(this);
1321
1322        addTagsEntry = new AddTagsEntry(this);
1323        clearTagsEntries = new ClearTagsEntries(this);
1324        removeTagsEntry = new RemoveTagsEntry(this);
1325    }
1326
1327    @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsAssetPersistence.impl")
1328    protected com.liferay.portlet.tags.service.persistence.TagsAssetPersistence tagsAssetPersistence;
1329    @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsEntryPersistence.impl")
1330    protected com.liferay.portlet.tags.service.persistence.TagsEntryPersistence tagsEntryPersistence;
1331    @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsPropertyPersistence.impl")
1332    protected com.liferay.portlet.tags.service.persistence.TagsPropertyPersistence tagsPropertyPersistence;
1333    @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsSourcePersistence.impl")
1334    protected com.liferay.portlet.tags.service.persistence.TagsSourcePersistence tagsSourcePersistence;
1335    @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsVocabularyPersistence.impl")
1336    protected com.liferay.portlet.tags.service.persistence.TagsVocabularyPersistence tagsVocabularyPersistence;
1337    @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
1338    protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
1339    @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
1340    protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
1341    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1342    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1343    @BeanReference(name = "com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence.impl")
1344    protected com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence blogsEntryPersistence;
1345    @BeanReference(name = "com.liferay.portlet.bookmarks.service.persistence.BookmarksEntryPersistence.impl")
1346    protected com.liferay.portlet.bookmarks.service.persistence.BookmarksEntryPersistence bookmarksEntryPersistence;
1347    @BeanReference(name = "com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryPersistence.impl")
1348    protected com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryPersistence dlFileEntryPersistence;
1349    @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalArticlePersistence.impl")
1350    protected com.liferay.portlet.journal.service.persistence.JournalArticlePersistence journalArticlePersistence;
1351    @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalArticleResourcePersistence.impl")
1352    protected com.liferay.portlet.journal.service.persistence.JournalArticleResourcePersistence journalArticleResourcePersistence;
1353    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence.impl")
1354    protected com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence mbMessagePersistence;
1355    @BeanReference(name = "com.liferay.portlet.wiki.service.persistence.WikiPagePersistence.impl")
1356    protected com.liferay.portlet.wiki.service.persistence.WikiPagePersistence wikiPagePersistence;
1357    @BeanReference(name = "com.liferay.portlet.wiki.service.persistence.WikiPageResourcePersistence.impl")
1358    protected com.liferay.portlet.wiki.service.persistence.WikiPageResourcePersistence wikiPageResourcePersistence;
1359    protected ContainsTagsEntry containsTagsEntry;
1360    protected AddTagsEntry addTagsEntry;
1361    protected ClearTagsEntries clearTagsEntries;
1362    protected RemoveTagsEntry removeTagsEntry;
1363
1364    protected class ContainsTagsEntry {
1365        protected ContainsTagsEntry(TagsAssetPersistenceImpl persistenceImpl) {
1366            super();
1367
1368            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
1369                    _SQL_CONTAINSTAGSENTRY,
1370                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
1371        }
1372
1373        protected boolean contains(long assetId, long entryId) {
1374            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
1375                        new Long(assetId), new Long(entryId)
1376                    });
1377
1378            if (results.size() > 0) {
1379                Integer count = results.get(0);
1380
1381                if (count.intValue() > 0) {
1382                    return true;
1383                }
1384            }
1385
1386            return false;
1387        }
1388
1389        private MappingSqlQuery _mappingSqlQuery;
1390    }
1391
1392    protected class AddTagsEntry {
1393        protected AddTagsEntry(TagsAssetPersistenceImpl persistenceImpl) {
1394            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1395                    "INSERT INTO TagsAssets_TagsEntries (assetId, entryId) VALUES (?, ?)",
1396                    new int[] { Types.BIGINT, Types.BIGINT });
1397            _persistenceImpl = persistenceImpl;
1398        }
1399
1400        protected void add(long assetId, long entryId)
1401            throws SystemException {
1402            if (!_persistenceImpl.containsTagsEntry.contains(assetId, entryId)) {
1403                ModelListener[] tagsEntryListeners = tagsEntryPersistence.getListeners();
1404
1405                for (ModelListener listener : listeners) {
1406                    listener.onBeforeAddAssociation(assetId,
1407                        com.liferay.portlet.tags.model.TagsEntry.class.getName(),
1408                        entryId);
1409                }
1410
1411                for (ModelListener listener : tagsEntryListeners) {
1412                    listener.onBeforeAddAssociation(entryId,
1413                        TagsAsset.class.getName(), assetId);
1414                }
1415
1416                _sqlUpdate.update(new Object[] {
1417                        new Long(assetId), new Long(entryId)
1418                    });
1419
1420                for (ModelListener listener : listeners) {
1421                    listener.onAfterAddAssociation(assetId,
1422                        com.liferay.portlet.tags.model.TagsEntry.class.getName(),
1423                        entryId);
1424                }
1425
1426                for (ModelListener listener : tagsEntryListeners) {
1427                    listener.onAfterAddAssociation(entryId,
1428                        TagsAsset.class.getName(), assetId);
1429                }
1430            }
1431        }
1432
1433        private SqlUpdate _sqlUpdate;
1434        private TagsAssetPersistenceImpl _persistenceImpl;
1435    }
1436
1437    protected class ClearTagsEntries {
1438        protected ClearTagsEntries(TagsAssetPersistenceImpl persistenceImpl) {
1439            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1440                    "DELETE FROM TagsAssets_TagsEntries WHERE assetId = ?",
1441                    new int[] { Types.BIGINT });
1442        }
1443
1444        protected void clear(long assetId) throws SystemException {
1445            ModelListener[] tagsEntryListeners = tagsEntryPersistence.getListeners();
1446
1447            List<com.liferay.portlet.tags.model.TagsEntry> tagsEntries = null;
1448
1449            if ((listeners.length > 0) || (tagsEntryListeners.length > 0)) {
1450                tagsEntries = getTagsEntries(assetId);
1451
1452                for (com.liferay.portlet.tags.model.TagsEntry tagsEntry : tagsEntries) {
1453                    for (ModelListener listener : listeners) {
1454                        listener.onBeforeRemoveAssociation(assetId,
1455                            com.liferay.portlet.tags.model.TagsEntry.class.getName(),
1456                            tagsEntry.getPrimaryKey());
1457                    }
1458
1459                    for (ModelListener listener : tagsEntryListeners) {
1460                        listener.onBeforeRemoveAssociation(tagsEntry.getPrimaryKey(),
1461                            TagsAsset.class.getName(), assetId);
1462                    }
1463                }
1464            }
1465
1466            _sqlUpdate.update(new Object[] { new Long(assetId) });
1467
1468            if ((listeners.length > 0) || (tagsEntryListeners.length > 0)) {
1469                for (com.liferay.portlet.tags.model.TagsEntry tagsEntry : tagsEntries) {
1470                    for (ModelListener listener : listeners) {
1471                        listener.onAfterRemoveAssociation(assetId,
1472                            com.liferay.portlet.tags.model.TagsEntry.class.getName(),
1473                            tagsEntry.getPrimaryKey());
1474                    }
1475
1476                    for (ModelListener listener : tagsEntryListeners) {
1477                        listener.onBeforeRemoveAssociation(tagsEntry.getPrimaryKey(),
1478                            TagsAsset.class.getName(), assetId);
1479                    }
1480                }
1481            }
1482        }
1483
1484        private SqlUpdate _sqlUpdate;
1485    }
1486
1487    protected class RemoveTagsEntry {
1488        protected RemoveTagsEntry(TagsAssetPersistenceImpl persistenceImpl) {
1489            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1490                    "DELETE FROM TagsAssets_TagsEntries WHERE assetId = ? AND entryId = ?",
1491                    new int[] { Types.BIGINT, Types.BIGINT });
1492            _persistenceImpl = persistenceImpl;
1493        }
1494
1495        protected void remove(long assetId, long entryId)
1496            throws SystemException {
1497            if (_persistenceImpl.containsTagsEntry.contains(assetId, entryId)) {
1498                ModelListener[] tagsEntryListeners = tagsEntryPersistence.getListeners();
1499
1500                for (ModelListener listener : listeners) {
1501                    listener.onBeforeRemoveAssociation(assetId,
1502                        com.liferay.portlet.tags.model.TagsEntry.class.getName(),
1503                        entryId);
1504                }
1505
1506                for (ModelListener listener : tagsEntryListeners) {
1507                    listener.onBeforeRemoveAssociation(entryId,
1508                        TagsAsset.class.getName(), assetId);
1509                }
1510
1511                _sqlUpdate.update(new Object[] {
1512                        new Long(assetId), new Long(entryId)
1513                    });
1514
1515                for (ModelListener listener : listeners) {
1516                    listener.onAfterRemoveAssociation(assetId,
1517                        com.liferay.portlet.tags.model.TagsEntry.class.getName(),
1518                        entryId);
1519                }
1520
1521                for (ModelListener listener : tagsEntryListeners) {
1522                    listener.onAfterRemoveAssociation(entryId,
1523                        TagsAsset.class.getName(), assetId);
1524                }
1525            }
1526        }
1527
1528        private SqlUpdate _sqlUpdate;
1529        private TagsAssetPersistenceImpl _persistenceImpl;
1530    }
1531
1532    private static final String _SQL_GETTAGSENTRIES = "SELECT {TagsEntry.*} FROM TagsEntry INNER JOIN TagsAssets_TagsEntries ON (TagsAssets_TagsEntries.entryId = TagsEntry.entryId) WHERE (TagsAssets_TagsEntries.assetId = ?)";
1533    private static final String _SQL_GETTAGSENTRIESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM TagsAssets_TagsEntries WHERE assetId = ?";
1534    private static final String _SQL_CONTAINSTAGSENTRY = "SELECT COUNT(*) AS COUNT_VALUE FROM TagsAssets_TagsEntries WHERE assetId = ? AND entryId = ?";
1535    private static Log _log = LogFactoryUtil.getLog(TagsAssetPersistenceImpl.class);
1536}