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