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