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