1   /**
2    * Copyright (c) 2000-2008 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.jdbc.MappingSqlQuery;
27  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
28  import com.liferay.portal.kernel.dao.jdbc.RowMapper;
29  import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
30  import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
31  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
32  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
33  import com.liferay.portal.kernel.dao.orm.Query;
34  import com.liferay.portal.kernel.dao.orm.QueryPos;
35  import com.liferay.portal.kernel.dao.orm.QueryUtil;
36  import com.liferay.portal.kernel.dao.orm.SQLQuery;
37  import com.liferay.portal.kernel.dao.orm.Session;
38  import com.liferay.portal.kernel.dao.orm.Type;
39  import com.liferay.portal.kernel.util.GetterUtil;
40  import com.liferay.portal.kernel.util.ListUtil;
41  import com.liferay.portal.kernel.util.OrderByComparator;
42  import com.liferay.portal.kernel.util.StringPool;
43  import com.liferay.portal.kernel.util.StringUtil;
44  import com.liferay.portal.model.ModelListener;
45  import com.liferay.portal.service.persistence.BatchSessionUtil;
46  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
47  
48  import com.liferay.portlet.tags.NoSuchEntryException;
49  import com.liferay.portlet.tags.model.TagsEntry;
50  import com.liferay.portlet.tags.model.impl.TagsEntryImpl;
51  import com.liferay.portlet.tags.model.impl.TagsEntryModelImpl;
52  
53  import org.apache.commons.logging.Log;
54  import org.apache.commons.logging.LogFactory;
55  
56  import java.sql.Types;
57  
58  import java.util.ArrayList;
59  import java.util.Collections;
60  import java.util.Iterator;
61  import java.util.List;
62  
63  /**
64   * <a href="TagsEntryPersistenceImpl.java.html"><b><i>View Source</i></b></a>
65   *
66   * @author Brian Wing Shun Chan
67   *
68   */
69  public class TagsEntryPersistenceImpl extends BasePersistenceImpl
70      implements TagsEntryPersistence {
71      public TagsEntry create(long entryId) {
72          TagsEntry tagsEntry = new TagsEntryImpl();
73  
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 processException(e);
107         }
108         finally {
109             closeSession(session);
110         }
111     }
112 
113     public TagsEntry remove(TagsEntry tagsEntry) throws SystemException {
114         if (_listeners.length > 0) {
115             for (ModelListener listener : _listeners) {
116                 listener.onBeforeRemove(tagsEntry);
117             }
118         }
119 
120         tagsEntry = removeImpl(tagsEntry);
121 
122         if (_listeners.length > 0) {
123             for (ModelListener listener : _listeners) {
124                 listener.onAfterRemove(tagsEntry);
125             }
126         }
127 
128         return tagsEntry;
129     }
130 
131     protected TagsEntry removeImpl(TagsEntry tagsEntry)
132         throws SystemException {
133         try {
134             clearTagsAssets.clear(tagsEntry.getPrimaryKey());
135         }
136         catch (Exception e) {
137             throw processException(e);
138         }
139         finally {
140             FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
141         }
142 
143         Session session = null;
144 
145         try {
146             session = openSession();
147 
148             if (BatchSessionUtil.isEnabled()) {
149                 Object staleObject = session.get(TagsEntryImpl.class,
150                         tagsEntry.getPrimaryKeyObj());
151 
152                 if (staleObject != null) {
153                     session.evict(staleObject);
154                 }
155             }
156 
157             session.delete(tagsEntry);
158 
159             session.flush();
160 
161             return tagsEntry;
162         }
163         catch (Exception e) {
164             throw processException(e);
165         }
166         finally {
167             closeSession(session);
168 
169             FinderCacheUtil.clearCache(TagsEntry.class.getName());
170         }
171     }
172 
173     /**
174      * @deprecated Use <code>update(TagsEntry tagsEntry, boolean merge)</code>.
175      */
176     public TagsEntry update(TagsEntry tagsEntry) throws SystemException {
177         if (_log.isWarnEnabled()) {
178             _log.warn(
179                 "Using the deprecated update(TagsEntry tagsEntry) method. Use update(TagsEntry tagsEntry, boolean merge) instead.");
180         }
181 
182         return update(tagsEntry, false);
183     }
184 
185     /**
186      * Add, update, or merge, the entity. This method also calls the model
187      * listeners to trigger the proper events associated with adding, deleting,
188      * or updating an entity.
189      *
190      * @param        tagsEntry the entity to add, update, or merge
191      * @param        merge boolean value for whether to merge the entity. The
192      *                default value is false. Setting merge to true is more
193      *                expensive and should only be true when tagsEntry is
194      *                transient. See LEP-5473 for a detailed discussion of this
195      *                method.
196      * @return        true if the portlet can be displayed via Ajax
197      */
198     public TagsEntry update(TagsEntry tagsEntry, boolean merge)
199         throws SystemException {
200         boolean isNew = tagsEntry.isNew();
201 
202         if (_listeners.length > 0) {
203             for (ModelListener listener : _listeners) {
204                 if (isNew) {
205                     listener.onBeforeCreate(tagsEntry);
206                 }
207                 else {
208                     listener.onBeforeUpdate(tagsEntry);
209                 }
210             }
211         }
212 
213         tagsEntry = updateImpl(tagsEntry, merge);
214 
215         if (_listeners.length > 0) {
216             for (ModelListener listener : _listeners) {
217                 if (isNew) {
218                     listener.onAfterCreate(tagsEntry);
219                 }
220                 else {
221                     listener.onAfterUpdate(tagsEntry);
222                 }
223             }
224         }
225 
226         return tagsEntry;
227     }
228 
229     public TagsEntry updateImpl(
230         com.liferay.portlet.tags.model.TagsEntry tagsEntry, boolean merge)
231         throws SystemException {
232         FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
233 
234         Session session = null;
235 
236         try {
237             session = openSession();
238 
239             BatchSessionUtil.update(session, tagsEntry, merge);
240 
241             tagsEntry.setNew(false);
242 
243             return tagsEntry;
244         }
245         catch (Exception e) {
246             throw processException(e);
247         }
248         finally {
249             closeSession(session);
250 
251             FinderCacheUtil.clearCache(TagsEntry.class.getName());
252         }
253     }
254 
255     public TagsEntry findByPrimaryKey(long entryId)
256         throws NoSuchEntryException, SystemException {
257         TagsEntry tagsEntry = fetchByPrimaryKey(entryId);
258 
259         if (tagsEntry == null) {
260             if (_log.isWarnEnabled()) {
261                 _log.warn("No TagsEntry exists with the primary key " +
262                     entryId);
263             }
264 
265             throw new NoSuchEntryException(
266                 "No TagsEntry exists with the primary key " + entryId);
267         }
268 
269         return tagsEntry;
270     }
271 
272     public TagsEntry fetchByPrimaryKey(long entryId) throws SystemException {
273         Session session = null;
274 
275         try {
276             session = openSession();
277 
278             return (TagsEntry)session.get(TagsEntryImpl.class, new Long(entryId));
279         }
280         catch (Exception e) {
281             throw processException(e);
282         }
283         finally {
284             closeSession(session);
285         }
286     }
287 
288     public TagsEntry findByC_N(long companyId, String name)
289         throws NoSuchEntryException, SystemException {
290         TagsEntry tagsEntry = fetchByC_N(companyId, name);
291 
292         if (tagsEntry == null) {
293             StringBuilder msg = new StringBuilder();
294 
295             msg.append("No TagsEntry exists with the key {");
296 
297             msg.append("companyId=" + companyId);
298 
299             msg.append(", ");
300             msg.append("name=" + name);
301 
302             msg.append(StringPool.CLOSE_CURLY_BRACE);
303 
304             if (_log.isWarnEnabled()) {
305                 _log.warn(msg.toString());
306             }
307 
308             throw new NoSuchEntryException(msg.toString());
309         }
310 
311         return tagsEntry;
312     }
313 
314     public TagsEntry fetchByC_N(long companyId, String name)
315         throws SystemException {
316         boolean finderClassNameCacheEnabled = TagsEntryModelImpl.CACHE_ENABLED;
317         String finderClassName = TagsEntry.class.getName();
318         String finderMethodName = "fetchByC_N";
319         String[] finderParams = new String[] {
320                 Long.class.getName(), String.class.getName()
321             };
322         Object[] finderArgs = new Object[] { new Long(companyId), name };
323 
324         Object result = null;
325 
326         if (finderClassNameCacheEnabled) {
327             result = FinderCacheUtil.getResult(finderClassName,
328                     finderMethodName, finderParams, finderArgs, this);
329         }
330 
331         if (result == null) {
332             Session session = null;
333 
334             try {
335                 session = openSession();
336 
337                 StringBuilder query = new StringBuilder();
338 
339                 query.append(
340                     "FROM com.liferay.portlet.tags.model.TagsEntry WHERE ");
341 
342                 query.append("companyId = ?");
343 
344                 query.append(" AND ");
345 
346                 if (name == null) {
347                     query.append("name IS NULL");
348                 }
349                 else {
350                     query.append("name = ?");
351                 }
352 
353                 query.append(" ");
354 
355                 query.append("ORDER BY ");
356 
357                 query.append("name ASC");
358 
359                 Query q = session.createQuery(query.toString());
360 
361                 QueryPos qPos = QueryPos.getInstance(q);
362 
363                 qPos.add(companyId);
364 
365                 if (name != null) {
366                     qPos.add(name);
367                 }
368 
369                 List<TagsEntry> list = q.list();
370 
371                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
372                     finderClassName, finderMethodName, finderParams,
373                     finderArgs, list);
374 
375                 if (list.size() == 0) {
376                     return null;
377                 }
378                 else {
379                     return list.get(0);
380                 }
381             }
382             catch (Exception e) {
383                 throw processException(e);
384             }
385             finally {
386                 closeSession(session);
387             }
388         }
389         else {
390             List<TagsEntry> list = (List<TagsEntry>)result;
391 
392             if (list.size() == 0) {
393                 return null;
394             }
395             else {
396                 return list.get(0);
397             }
398         }
399     }
400 
401     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
402         throws SystemException {
403         Session session = null;
404 
405         try {
406             session = openSession();
407 
408             dynamicQuery.compile(session);
409 
410             return dynamicQuery.list();
411         }
412         catch (Exception e) {
413             throw processException(e);
414         }
415         finally {
416             closeSession(session);
417         }
418     }
419 
420     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
421         int start, int end) throws SystemException {
422         Session session = null;
423 
424         try {
425             session = openSession();
426 
427             dynamicQuery.setLimit(start, end);
428 
429             dynamicQuery.compile(session);
430 
431             return dynamicQuery.list();
432         }
433         catch (Exception e) {
434             throw processException(e);
435         }
436         finally {
437             closeSession(session);
438         }
439     }
440 
441     public List<TagsEntry> findAll() throws SystemException {
442         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
443     }
444 
445     public List<TagsEntry> findAll(int start, int end)
446         throws SystemException {
447         return findAll(start, end, null);
448     }
449 
450     public List<TagsEntry> findAll(int start, int end, OrderByComparator obc)
451         throws SystemException {
452         boolean finderClassNameCacheEnabled = TagsEntryModelImpl.CACHE_ENABLED;
453         String finderClassName = TagsEntry.class.getName();
454         String finderMethodName = "findAll";
455         String[] finderParams = new String[] {
456                 "java.lang.Integer", "java.lang.Integer",
457                 "com.liferay.portal.kernel.util.OrderByComparator"
458             };
459         Object[] finderArgs = new Object[] {
460                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
461             };
462 
463         Object result = null;
464 
465         if (finderClassNameCacheEnabled) {
466             result = FinderCacheUtil.getResult(finderClassName,
467                     finderMethodName, finderParams, finderArgs, this);
468         }
469 
470         if (result == null) {
471             Session session = null;
472 
473             try {
474                 session = openSession();
475 
476                 StringBuilder query = new StringBuilder();
477 
478                 query.append("FROM com.liferay.portlet.tags.model.TagsEntry ");
479 
480                 if (obc != null) {
481                     query.append("ORDER BY ");
482                     query.append(obc.getOrderBy());
483                 }
484 
485                 else {
486                     query.append("ORDER BY ");
487 
488                     query.append("name ASC");
489                 }
490 
491                 Query q = session.createQuery(query.toString());
492 
493                 List<TagsEntry> list = null;
494 
495                 if (obc == null) {
496                     list = (List<TagsEntry>)QueryUtil.list(q, getDialect(),
497                             start, end, false);
498 
499                     Collections.sort(list);
500                 }
501                 else {
502                     list = (List<TagsEntry>)QueryUtil.list(q, getDialect(),
503                             start, end);
504                 }
505 
506                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
507                     finderClassName, finderMethodName, finderParams,
508                     finderArgs, list);
509 
510                 return list;
511             }
512             catch (Exception e) {
513                 throw processException(e);
514             }
515             finally {
516                 closeSession(session);
517             }
518         }
519         else {
520             return (List<TagsEntry>)result;
521         }
522     }
523 
524     public void removeByC_N(long companyId, String name)
525         throws NoSuchEntryException, SystemException {
526         TagsEntry tagsEntry = findByC_N(companyId, name);
527 
528         remove(tagsEntry);
529     }
530 
531     public void removeAll() throws SystemException {
532         for (TagsEntry tagsEntry : findAll()) {
533             remove(tagsEntry);
534         }
535     }
536 
537     public int countByC_N(long companyId, String name)
538         throws SystemException {
539         boolean finderClassNameCacheEnabled = TagsEntryModelImpl.CACHE_ENABLED;
540         String finderClassName = TagsEntry.class.getName();
541         String finderMethodName = "countByC_N";
542         String[] finderParams = new String[] {
543                 Long.class.getName(), String.class.getName()
544             };
545         Object[] finderArgs = new Object[] { new Long(companyId), name };
546 
547         Object result = null;
548 
549         if (finderClassNameCacheEnabled) {
550             result = FinderCacheUtil.getResult(finderClassName,
551                     finderMethodName, finderParams, finderArgs, this);
552         }
553 
554         if (result == null) {
555             Session session = null;
556 
557             try {
558                 session = openSession();
559 
560                 StringBuilder query = new StringBuilder();
561 
562                 query.append("SELECT COUNT(*) ");
563                 query.append(
564                     "FROM com.liferay.portlet.tags.model.TagsEntry WHERE ");
565 
566                 query.append("companyId = ?");
567 
568                 query.append(" AND ");
569 
570                 if (name == null) {
571                     query.append("name IS NULL");
572                 }
573                 else {
574                     query.append("name = ?");
575                 }
576 
577                 query.append(" ");
578 
579                 Query q = session.createQuery(query.toString());
580 
581                 QueryPos qPos = QueryPos.getInstance(q);
582 
583                 qPos.add(companyId);
584 
585                 if (name != null) {
586                     qPos.add(name);
587                 }
588 
589                 Long count = null;
590 
591                 Iterator<Long> itr = q.list().iterator();
592 
593                 if (itr.hasNext()) {
594                     count = itr.next();
595                 }
596 
597                 if (count == null) {
598                     count = new Long(0);
599                 }
600 
601                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
602                     finderClassName, finderMethodName, finderParams,
603                     finderArgs, count);
604 
605                 return count.intValue();
606             }
607             catch (Exception e) {
608                 throw processException(e);
609             }
610             finally {
611                 closeSession(session);
612             }
613         }
614         else {
615             return ((Long)result).intValue();
616         }
617     }
618 
619     public int countAll() throws SystemException {
620         boolean finderClassNameCacheEnabled = TagsEntryModelImpl.CACHE_ENABLED;
621         String finderClassName = TagsEntry.class.getName();
622         String finderMethodName = "countAll";
623         String[] finderParams = new String[] {  };
624         Object[] finderArgs = new Object[] {  };
625 
626         Object result = null;
627 
628         if (finderClassNameCacheEnabled) {
629             result = FinderCacheUtil.getResult(finderClassName,
630                     finderMethodName, finderParams, finderArgs, this);
631         }
632 
633         if (result == null) {
634             Session session = null;
635 
636             try {
637                 session = openSession();
638 
639                 Query q = session.createQuery(
640                         "SELECT COUNT(*) FROM com.liferay.portlet.tags.model.TagsEntry");
641 
642                 Long count = null;
643 
644                 Iterator<Long> itr = q.list().iterator();
645 
646                 if (itr.hasNext()) {
647                     count = itr.next();
648                 }
649 
650                 if (count == null) {
651                     count = new Long(0);
652                 }
653 
654                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
655                     finderClassName, finderMethodName, finderParams,
656                     finderArgs, count);
657 
658                 return count.intValue();
659             }
660             catch (Exception e) {
661                 throw processException(e);
662             }
663             finally {
664                 closeSession(session);
665             }
666         }
667         else {
668             return ((Long)result).intValue();
669         }
670     }
671 
672     public List<com.liferay.portlet.tags.model.TagsAsset> getTagsAssets(long pk)
673         throws SystemException {
674         return getTagsAssets(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
675     }
676 
677     public List<com.liferay.portlet.tags.model.TagsAsset> getTagsAssets(
678         long pk, int start, int end) throws SystemException {
679         return getTagsAssets(pk, start, end, null);
680     }
681 
682     public List<com.liferay.portlet.tags.model.TagsAsset> getTagsAssets(
683         long pk, int start, int end, OrderByComparator obc)
684         throws SystemException {
685         boolean finderClassNameCacheEnabled = TagsEntryModelImpl.CACHE_ENABLED_TAGSASSETS_TAGSENTRIES;
686 
687         String finderClassName = "TagsAssets_TagsEntries";
688 
689         String finderMethodName = "getTagsAssets";
690         String[] finderParams = new String[] {
691                 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
692                 "com.liferay.portal.kernel.util.OrderByComparator"
693             };
694         Object[] finderArgs = new Object[] {
695                 new Long(pk), String.valueOf(start), String.valueOf(end),
696                 String.valueOf(obc)
697             };
698 
699         Object result = null;
700 
701         if (finderClassNameCacheEnabled) {
702             result = FinderCacheUtil.getResult(finderClassName,
703                     finderMethodName, finderParams, finderArgs, this);
704         }
705 
706         if (result == null) {
707             Session session = null;
708 
709             try {
710                 session = openSession();
711 
712                 StringBuilder sb = new StringBuilder();
713 
714                 sb.append(_SQL_GETTAGSASSETS);
715 
716                 if (obc != null) {
717                     sb.append("ORDER BY ");
718                     sb.append(obc.getOrderBy());
719                 }
720 
721                 String sql = sb.toString();
722 
723                 SQLQuery q = session.createSQLQuery(sql);
724 
725                 q.addEntity("TagsAsset",
726                     com.liferay.portlet.tags.model.impl.TagsAssetImpl.class);
727 
728                 QueryPos qPos = QueryPos.getInstance(q);
729 
730                 qPos.add(pk);
731 
732                 List<com.liferay.portlet.tags.model.TagsAsset> list = (List<com.liferay.portlet.tags.model.TagsAsset>)QueryUtil.list(q,
733                         getDialect(), start, end);
734 
735                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
736                     finderClassName, finderMethodName, finderParams,
737                     finderArgs, list);
738 
739                 return list;
740             }
741             catch (Exception e) {
742                 throw processException(e);
743             }
744             finally {
745                 closeSession(session);
746             }
747         }
748         else {
749             return (List<com.liferay.portlet.tags.model.TagsAsset>)result;
750         }
751     }
752 
753     public int getTagsAssetsSize(long pk) throws SystemException {
754         boolean finderClassNameCacheEnabled = TagsEntryModelImpl.CACHE_ENABLED_TAGSASSETS_TAGSENTRIES;
755 
756         String finderClassName = "TagsAssets_TagsEntries";
757 
758         String finderMethodName = "getTagsAssetsSize";
759         String[] finderParams = new String[] { Long.class.getName() };
760         Object[] finderArgs = new Object[] { new Long(pk) };
761 
762         Object result = null;
763 
764         if (finderClassNameCacheEnabled) {
765             result = FinderCacheUtil.getResult(finderClassName,
766                     finderMethodName, finderParams, finderArgs, this);
767         }
768 
769         if (result == null) {
770             Session session = null;
771 
772             try {
773                 session = openSession();
774 
775                 SQLQuery q = session.createSQLQuery(_SQL_GETTAGSASSETSSIZE);
776 
777                 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
778 
779                 QueryPos qPos = QueryPos.getInstance(q);
780 
781                 qPos.add(pk);
782 
783                 Long count = null;
784 
785                 Iterator<Long> itr = q.list().iterator();
786 
787                 if (itr.hasNext()) {
788                     count = itr.next();
789                 }
790 
791                 if (count == null) {
792                     count = new Long(0);
793                 }
794 
795                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
796                     finderClassName, finderMethodName, finderParams,
797                     finderArgs, count);
798 
799                 return count.intValue();
800             }
801             catch (Exception e) {
802                 throw processException(e);
803             }
804             finally {
805                 closeSession(session);
806             }
807         }
808         else {
809             return ((Long)result).intValue();
810         }
811     }
812 
813     public boolean containsTagsAsset(long pk, long tagsAssetPK)
814         throws SystemException {
815         boolean finderClassNameCacheEnabled = TagsEntryModelImpl.CACHE_ENABLED_TAGSASSETS_TAGSENTRIES;
816 
817         String finderClassName = "TagsAssets_TagsEntries";
818 
819         String finderMethodName = "containsTagsAssets";
820         String[] finderParams = new String[] {
821                 Long.class.getName(),
822                 
823                 Long.class.getName()
824             };
825         Object[] finderArgs = new Object[] { new Long(pk), new Long(tagsAssetPK) };
826 
827         Object result = null;
828 
829         if (finderClassNameCacheEnabled) {
830             result = FinderCacheUtil.getResult(finderClassName,
831                     finderMethodName, finderParams, finderArgs, this);
832         }
833 
834         if (result == null) {
835             try {
836                 Boolean value = Boolean.valueOf(containsTagsAsset.contains(pk,
837                             tagsAssetPK));
838 
839                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
840                     finderClassName, finderMethodName, finderParams,
841                     finderArgs, value);
842 
843                 return value.booleanValue();
844             }
845             catch (Exception e) {
846                 throw processException(e);
847             }
848         }
849         else {
850             return ((Boolean)result).booleanValue();
851         }
852     }
853 
854     public boolean containsTagsAssets(long pk) throws SystemException {
855         if (getTagsAssetsSize(pk) > 0) {
856             return true;
857         }
858         else {
859             return false;
860         }
861     }
862 
863     public void addTagsAsset(long pk, long tagsAssetPK)
864         throws SystemException {
865         try {
866             addTagsAsset.add(pk, tagsAssetPK);
867         }
868         catch (Exception e) {
869             throw processException(e);
870         }
871         finally {
872             FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
873         }
874     }
875 
876     public void addTagsAsset(long pk,
877         com.liferay.portlet.tags.model.TagsAsset tagsAsset)
878         throws SystemException {
879         try {
880             addTagsAsset.add(pk, tagsAsset.getPrimaryKey());
881         }
882         catch (Exception e) {
883             throw processException(e);
884         }
885         finally {
886             FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
887         }
888     }
889 
890     public void addTagsAssets(long pk, long[] tagsAssetPKs)
891         throws SystemException {
892         try {
893             for (long tagsAssetPK : tagsAssetPKs) {
894                 addTagsAsset.add(pk, tagsAssetPK);
895             }
896         }
897         catch (Exception e) {
898             throw processException(e);
899         }
900         finally {
901             FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
902         }
903     }
904 
905     public void addTagsAssets(long pk,
906         List<com.liferay.portlet.tags.model.TagsAsset> tagsAssets)
907         throws SystemException {
908         try {
909             for (com.liferay.portlet.tags.model.TagsAsset tagsAsset : tagsAssets) {
910                 addTagsAsset.add(pk, tagsAsset.getPrimaryKey());
911             }
912         }
913         catch (Exception e) {
914             throw processException(e);
915         }
916         finally {
917             FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
918         }
919     }
920 
921     public void clearTagsAssets(long pk) throws SystemException {
922         try {
923             clearTagsAssets.clear(pk);
924         }
925         catch (Exception e) {
926             throw processException(e);
927         }
928         finally {
929             FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
930         }
931     }
932 
933     public void removeTagsAsset(long pk, long tagsAssetPK)
934         throws SystemException {
935         try {
936             removeTagsAsset.remove(pk, tagsAssetPK);
937         }
938         catch (Exception e) {
939             throw processException(e);
940         }
941         finally {
942             FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
943         }
944     }
945 
946     public void removeTagsAsset(long pk,
947         com.liferay.portlet.tags.model.TagsAsset tagsAsset)
948         throws SystemException {
949         try {
950             removeTagsAsset.remove(pk, tagsAsset.getPrimaryKey());
951         }
952         catch (Exception e) {
953             throw processException(e);
954         }
955         finally {
956             FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
957         }
958     }
959 
960     public void removeTagsAssets(long pk, long[] tagsAssetPKs)
961         throws SystemException {
962         try {
963             for (long tagsAssetPK : tagsAssetPKs) {
964                 removeTagsAsset.remove(pk, tagsAssetPK);
965             }
966         }
967         catch (Exception e) {
968             throw processException(e);
969         }
970         finally {
971             FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
972         }
973     }
974 
975     public void removeTagsAssets(long pk,
976         List<com.liferay.portlet.tags.model.TagsAsset> tagsAssets)
977         throws SystemException {
978         try {
979             for (com.liferay.portlet.tags.model.TagsAsset tagsAsset : tagsAssets) {
980                 removeTagsAsset.remove(pk, tagsAsset.getPrimaryKey());
981             }
982         }
983         catch (Exception e) {
984             throw processException(e);
985         }
986         finally {
987             FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
988         }
989     }
990 
991     public void setTagsAssets(long pk, long[] tagsAssetPKs)
992         throws SystemException {
993         try {
994             clearTagsAssets.clear(pk);
995 
996             for (long tagsAssetPK : tagsAssetPKs) {
997                 addTagsAsset.add(pk, tagsAssetPK);
998             }
999         }
1000        catch (Exception e) {
1001            throw processException(e);
1002        }
1003        finally {
1004            FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1005        }
1006    }
1007
1008    public void setTagsAssets(long pk,
1009        List<com.liferay.portlet.tags.model.TagsAsset> tagsAssets)
1010        throws SystemException {
1011        try {
1012            clearTagsAssets.clear(pk);
1013
1014            for (com.liferay.portlet.tags.model.TagsAsset tagsAsset : tagsAssets) {
1015                addTagsAsset.add(pk, tagsAsset.getPrimaryKey());
1016            }
1017        }
1018        catch (Exception e) {
1019            throw processException(e);
1020        }
1021        finally {
1022            FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1023        }
1024    }
1025
1026    public void registerListener(ModelListener listener) {
1027        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1028
1029        listeners.add(listener);
1030
1031        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1032    }
1033
1034    public void unregisterListener(ModelListener listener) {
1035        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1036
1037        listeners.remove(listener);
1038
1039        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1040    }
1041
1042    public void afterPropertiesSet() {
1043        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1044                    com.liferay.portal.util.PropsUtil.get(
1045                        "value.object.listener.com.liferay.portlet.tags.model.TagsEntry")));
1046
1047        if (listenerClassNames.length > 0) {
1048            try {
1049                List<ModelListener> listeners = new ArrayList<ModelListener>();
1050
1051                for (String listenerClassName : listenerClassNames) {
1052                    listeners.add((ModelListener)Class.forName(
1053                            listenerClassName).newInstance());
1054                }
1055
1056                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1057            }
1058            catch (Exception e) {
1059                _log.error(e);
1060            }
1061        }
1062
1063        containsTagsAsset = new ContainsTagsAsset(this);
1064
1065        addTagsAsset = new AddTagsAsset(this);
1066        clearTagsAssets = new ClearTagsAssets(this);
1067        removeTagsAsset = new RemoveTagsAsset(this);
1068    }
1069
1070    protected ContainsTagsAsset containsTagsAsset;
1071    protected AddTagsAsset addTagsAsset;
1072    protected ClearTagsAssets clearTagsAssets;
1073    protected RemoveTagsAsset removeTagsAsset;
1074
1075    protected class ContainsTagsAsset {
1076        protected ContainsTagsAsset(TagsEntryPersistenceImpl persistenceImpl) {
1077            super();
1078
1079            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
1080                    _SQL_CONTAINSTAGSASSET,
1081                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
1082        }
1083
1084        protected boolean contains(long entryId, long assetId) {
1085            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
1086                        new Long(entryId), new Long(assetId)
1087                    });
1088
1089            if (results.size() > 0) {
1090                Integer count = results.get(0);
1091
1092                if (count.intValue() > 0) {
1093                    return true;
1094                }
1095            }
1096
1097            return false;
1098        }
1099
1100        private MappingSqlQuery _mappingSqlQuery;
1101    }
1102
1103    protected class AddTagsAsset {
1104        protected AddTagsAsset(TagsEntryPersistenceImpl persistenceImpl) {
1105            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1106                    "INSERT INTO TagsAssets_TagsEntries (entryId, assetId) VALUES (?, ?)",
1107                    new int[] { Types.BIGINT, Types.BIGINT });
1108            _persistenceImpl = persistenceImpl;
1109        }
1110
1111        protected void add(long entryId, long assetId) {
1112            if (!_persistenceImpl.containsTagsAsset.contains(entryId, assetId)) {
1113                _sqlUpdate.update(new Object[] {
1114                        new Long(entryId), new Long(assetId)
1115                    });
1116            }
1117        }
1118
1119        private SqlUpdate _sqlUpdate;
1120        private TagsEntryPersistenceImpl _persistenceImpl;
1121    }
1122
1123    protected class ClearTagsAssets {
1124        protected ClearTagsAssets(TagsEntryPersistenceImpl persistenceImpl) {
1125            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1126                    "DELETE FROM TagsAssets_TagsEntries WHERE entryId = ?",
1127                    new int[] { Types.BIGINT });
1128        }
1129
1130        protected void clear(long entryId) {
1131            _sqlUpdate.update(new Object[] { new Long(entryId) });
1132        }
1133
1134        private SqlUpdate _sqlUpdate;
1135    }
1136
1137    protected class RemoveTagsAsset {
1138        protected RemoveTagsAsset(TagsEntryPersistenceImpl persistenceImpl) {
1139            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1140                    "DELETE FROM TagsAssets_TagsEntries WHERE entryId = ? AND assetId = ?",
1141                    new int[] { Types.BIGINT, Types.BIGINT });
1142        }
1143
1144        protected void remove(long entryId, long assetId) {
1145            _sqlUpdate.update(new Object[] { new Long(entryId), new Long(
1146                        assetId) });
1147        }
1148
1149        private SqlUpdate _sqlUpdate;
1150    }
1151
1152    private static final String _SQL_GETTAGSASSETS = "SELECT {TagsAsset.*} FROM TagsAsset INNER JOIN TagsAssets_TagsEntries ON (TagsAssets_TagsEntries.assetId = TagsAsset.assetId) WHERE (TagsAssets_TagsEntries.entryId = ?)";
1153    private static final String _SQL_GETTAGSASSETSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM TagsAssets_TagsEntries WHERE entryId = ?";
1154    private static final String _SQL_CONTAINSTAGSASSET = "SELECT COUNT(*) AS COUNT_VALUE FROM TagsAssets_TagsEntries WHERE entryId = ? AND assetId = ?";
1155    private static Log _log = LogFactory.getLog(TagsEntryPersistenceImpl.class);
1156    private ModelListener[] _listeners = new ModelListener[0];
1157}