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