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