1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.asset.service.persistence;
16  
17  import com.liferay.portal.NoSuchModelException;
18  import com.liferay.portal.kernel.annotation.BeanReference;
19  import com.liferay.portal.kernel.cache.CacheRegistry;
20  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
21  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
22  import com.liferay.portal.kernel.dao.jdbc.RowMapper;
23  import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
24  import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
25  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
26  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
27  import com.liferay.portal.kernel.dao.orm.FinderPath;
28  import com.liferay.portal.kernel.dao.orm.Query;
29  import com.liferay.portal.kernel.dao.orm.QueryPos;
30  import com.liferay.portal.kernel.dao.orm.QueryUtil;
31  import com.liferay.portal.kernel.dao.orm.SQLQuery;
32  import com.liferay.portal.kernel.dao.orm.Session;
33  import com.liferay.portal.kernel.dao.orm.Type;
34  import com.liferay.portal.kernel.exception.SystemException;
35  import com.liferay.portal.kernel.log.Log;
36  import com.liferay.portal.kernel.log.LogFactoryUtil;
37  import com.liferay.portal.kernel.util.GetterUtil;
38  import com.liferay.portal.kernel.util.InstanceFactory;
39  import com.liferay.portal.kernel.util.OrderByComparator;
40  import com.liferay.portal.kernel.util.SetUtil;
41  import com.liferay.portal.kernel.util.StringBundler;
42  import com.liferay.portal.kernel.util.StringPool;
43  import com.liferay.portal.kernel.util.StringUtil;
44  import com.liferay.portal.model.ModelListener;
45  import com.liferay.portal.service.persistence.BatchSessionUtil;
46  import com.liferay.portal.service.persistence.CompanyPersistence;
47  import com.liferay.portal.service.persistence.GroupPersistence;
48  import com.liferay.portal.service.persistence.ResourcePersistence;
49  import com.liferay.portal.service.persistence.UserPersistence;
50  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
51  
52  import com.liferay.portlet.asset.NoSuchEntryException;
53  import com.liferay.portlet.asset.model.AssetEntry;
54  import com.liferay.portlet.asset.model.impl.AssetEntryImpl;
55  import com.liferay.portlet.asset.model.impl.AssetEntryModelImpl;
56  import com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence;
57  import com.liferay.portlet.bookmarks.service.persistence.BookmarksEntryPersistence;
58  import com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryPersistence;
59  import com.liferay.portlet.documentlibrary.service.persistence.DLFolderPersistence;
60  import com.liferay.portlet.journal.service.persistence.JournalArticlePersistence;
61  import com.liferay.portlet.journal.service.persistence.JournalArticleResourcePersistence;
62  import com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence;
63  import com.liferay.portlet.social.service.persistence.SocialEquityLogPersistence;
64  import com.liferay.portlet.wiki.service.persistence.WikiPagePersistence;
65  import com.liferay.portlet.wiki.service.persistence.WikiPageResourcePersistence;
66  
67  import java.io.Serializable;
68  
69  import java.sql.Types;
70  
71  import java.util.ArrayList;
72  import java.util.Collections;
73  import java.util.List;
74  import java.util.Set;
75  
76  /**
77   * <a href="AssetEntryPersistenceImpl.java.html"><b><i>View Source</i></b></a>
78   *
79   * <p>
80   * ServiceBuilder generated this class. Modifications in this class will be
81   * overwritten the next time is generated.
82   * </p>
83   *
84   * @author    Brian Wing Shun Chan
85   * @see       AssetEntryPersistence
86   * @see       AssetEntryUtil
87   * @generated
88   */
89  public class AssetEntryPersistenceImpl extends BasePersistenceImpl<AssetEntry>
90      implements AssetEntryPersistence {
91      public static final String FINDER_CLASS_NAME_ENTITY = AssetEntryImpl.class.getName();
92      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
93          ".List";
94      public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
95              AssetEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
96              "findByCompanyId",
97              new String[] {
98                  Long.class.getName(),
99                  
100             "java.lang.Integer", "java.lang.Integer",
101                 "com.liferay.portal.kernel.util.OrderByComparator"
102             });
103     public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
104             AssetEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
105             "countByCompanyId", new String[] { Long.class.getName() });
106     public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
107             AssetEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
108             "fetchByC_C",
109             new String[] { Long.class.getName(), Long.class.getName() });
110     public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
111             AssetEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
112             "countByC_C",
113             new String[] { Long.class.getName(), Long.class.getName() });
114     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
115             AssetEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
116             "findAll", new String[0]);
117     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
118             AssetEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
119             "countAll", new String[0]);
120 
121     public void cacheResult(AssetEntry assetEntry) {
122         EntityCacheUtil.putResult(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
123             AssetEntryImpl.class, assetEntry.getPrimaryKey(), assetEntry);
124 
125         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
126             new Object[] {
127                 new Long(assetEntry.getClassNameId()),
128                 new Long(assetEntry.getClassPK())
129             }, assetEntry);
130     }
131 
132     public void cacheResult(List<AssetEntry> assetEntries) {
133         for (AssetEntry assetEntry : assetEntries) {
134             if (EntityCacheUtil.getResult(
135                         AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
136                         AssetEntryImpl.class, assetEntry.getPrimaryKey(), this) == null) {
137                 cacheResult(assetEntry);
138             }
139         }
140     }
141 
142     public void clearCache() {
143         CacheRegistry.clear(AssetEntryImpl.class.getName());
144         EntityCacheUtil.clearCache(AssetEntryImpl.class.getName());
145         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
146         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
147     }
148 
149     public void clearCache(AssetEntry assetEntry) {
150         EntityCacheUtil.removeResult(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
151             AssetEntryImpl.class, assetEntry.getPrimaryKey());
152 
153         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
154             new Object[] {
155                 new Long(assetEntry.getClassNameId()),
156                 new Long(assetEntry.getClassPK())
157             });
158     }
159 
160     public AssetEntry create(long entryId) {
161         AssetEntry assetEntry = new AssetEntryImpl();
162 
163         assetEntry.setNew(true);
164         assetEntry.setPrimaryKey(entryId);
165 
166         return assetEntry;
167     }
168 
169     public AssetEntry remove(Serializable primaryKey)
170         throws NoSuchModelException, SystemException {
171         return remove(((Long)primaryKey).longValue());
172     }
173 
174     public AssetEntry remove(long entryId)
175         throws NoSuchEntryException, SystemException {
176         Session session = null;
177 
178         try {
179             session = openSession();
180 
181             AssetEntry assetEntry = (AssetEntry)session.get(AssetEntryImpl.class,
182                     new Long(entryId));
183 
184             if (assetEntry == null) {
185                 if (_log.isWarnEnabled()) {
186                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + entryId);
187                 }
188 
189                 throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
190                     entryId);
191             }
192 
193             return remove(assetEntry);
194         }
195         catch (NoSuchEntryException nsee) {
196             throw nsee;
197         }
198         catch (Exception e) {
199             throw processException(e);
200         }
201         finally {
202             closeSession(session);
203         }
204     }
205 
206     public AssetEntry remove(AssetEntry assetEntry) throws SystemException {
207         for (ModelListener<AssetEntry> listener : listeners) {
208             listener.onBeforeRemove(assetEntry);
209         }
210 
211         assetEntry = removeImpl(assetEntry);
212 
213         for (ModelListener<AssetEntry> listener : listeners) {
214             listener.onAfterRemove(assetEntry);
215         }
216 
217         return assetEntry;
218     }
219 
220     protected AssetEntry removeImpl(AssetEntry assetEntry)
221         throws SystemException {
222         assetEntry = toUnwrappedModel(assetEntry);
223 
224         try {
225             clearAssetCategories.clear(assetEntry.getPrimaryKey());
226         }
227         catch (Exception e) {
228             throw processException(e);
229         }
230         finally {
231             FinderCacheUtil.clearCache(AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
232         }
233 
234         try {
235             clearAssetTags.clear(assetEntry.getPrimaryKey());
236         }
237         catch (Exception e) {
238             throw processException(e);
239         }
240         finally {
241             FinderCacheUtil.clearCache(AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
242         }
243 
244         Session session = null;
245 
246         try {
247             session = openSession();
248 
249             if (assetEntry.isCachedModel() || BatchSessionUtil.isEnabled()) {
250                 Object staleObject = session.get(AssetEntryImpl.class,
251                         assetEntry.getPrimaryKeyObj());
252 
253                 if (staleObject != null) {
254                     session.evict(staleObject);
255                 }
256             }
257 
258             session.delete(assetEntry);
259 
260             session.flush();
261         }
262         catch (Exception e) {
263             throw processException(e);
264         }
265         finally {
266             closeSession(session);
267         }
268 
269         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
270 
271         AssetEntryModelImpl assetEntryModelImpl = (AssetEntryModelImpl)assetEntry;
272 
273         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
274             new Object[] {
275                 new Long(assetEntryModelImpl.getOriginalClassNameId()),
276                 new Long(assetEntryModelImpl.getOriginalClassPK())
277             });
278 
279         EntityCacheUtil.removeResult(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
280             AssetEntryImpl.class, assetEntry.getPrimaryKey());
281 
282         return assetEntry;
283     }
284 
285     public AssetEntry updateImpl(
286         com.liferay.portlet.asset.model.AssetEntry assetEntry, boolean merge)
287         throws SystemException {
288         assetEntry = toUnwrappedModel(assetEntry);
289 
290         boolean isNew = assetEntry.isNew();
291 
292         AssetEntryModelImpl assetEntryModelImpl = (AssetEntryModelImpl)assetEntry;
293 
294         Session session = null;
295 
296         try {
297             session = openSession();
298 
299             BatchSessionUtil.update(session, assetEntry, merge);
300 
301             assetEntry.setNew(false);
302         }
303         catch (Exception e) {
304             throw processException(e);
305         }
306         finally {
307             closeSession(session);
308         }
309 
310         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
311 
312         EntityCacheUtil.putResult(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
313             AssetEntryImpl.class, assetEntry.getPrimaryKey(), assetEntry);
314 
315         if (!isNew &&
316                 ((assetEntry.getClassNameId() != assetEntryModelImpl.getOriginalClassNameId()) ||
317                 (assetEntry.getClassPK() != assetEntryModelImpl.getOriginalClassPK()))) {
318             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
319                 new Object[] {
320                     new Long(assetEntryModelImpl.getOriginalClassNameId()),
321                     new Long(assetEntryModelImpl.getOriginalClassPK())
322                 });
323         }
324 
325         if (isNew ||
326                 ((assetEntry.getClassNameId() != assetEntryModelImpl.getOriginalClassNameId()) ||
327                 (assetEntry.getClassPK() != assetEntryModelImpl.getOriginalClassPK()))) {
328             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
329                 new Object[] {
330                     new Long(assetEntry.getClassNameId()),
331                     new Long(assetEntry.getClassPK())
332                 }, assetEntry);
333         }
334 
335         return assetEntry;
336     }
337 
338     protected AssetEntry toUnwrappedModel(AssetEntry assetEntry) {
339         if (assetEntry instanceof AssetEntryImpl) {
340             return assetEntry;
341         }
342 
343         AssetEntryImpl assetEntryImpl = new AssetEntryImpl();
344 
345         assetEntryImpl.setNew(assetEntry.isNew());
346         assetEntryImpl.setPrimaryKey(assetEntry.getPrimaryKey());
347 
348         assetEntryImpl.setEntryId(assetEntry.getEntryId());
349         assetEntryImpl.setGroupId(assetEntry.getGroupId());
350         assetEntryImpl.setCompanyId(assetEntry.getCompanyId());
351         assetEntryImpl.setUserId(assetEntry.getUserId());
352         assetEntryImpl.setUserName(assetEntry.getUserName());
353         assetEntryImpl.setCreateDate(assetEntry.getCreateDate());
354         assetEntryImpl.setModifiedDate(assetEntry.getModifiedDate());
355         assetEntryImpl.setClassNameId(assetEntry.getClassNameId());
356         assetEntryImpl.setClassPK(assetEntry.getClassPK());
357         assetEntryImpl.setVisible(assetEntry.isVisible());
358         assetEntryImpl.setStartDate(assetEntry.getStartDate());
359         assetEntryImpl.setEndDate(assetEntry.getEndDate());
360         assetEntryImpl.setPublishDate(assetEntry.getPublishDate());
361         assetEntryImpl.setExpirationDate(assetEntry.getExpirationDate());
362         assetEntryImpl.setMimeType(assetEntry.getMimeType());
363         assetEntryImpl.setTitle(assetEntry.getTitle());
364         assetEntryImpl.setDescription(assetEntry.getDescription());
365         assetEntryImpl.setSummary(assetEntry.getSummary());
366         assetEntryImpl.setUrl(assetEntry.getUrl());
367         assetEntryImpl.setHeight(assetEntry.getHeight());
368         assetEntryImpl.setWidth(assetEntry.getWidth());
369         assetEntryImpl.setPriority(assetEntry.getPriority());
370         assetEntryImpl.setViewCount(assetEntry.getViewCount());
371         assetEntryImpl.setSocialInformationEquity(assetEntry.getSocialInformationEquity());
372 
373         return assetEntryImpl;
374     }
375 
376     public AssetEntry findByPrimaryKey(Serializable primaryKey)
377         throws NoSuchModelException, SystemException {
378         return findByPrimaryKey(((Long)primaryKey).longValue());
379     }
380 
381     public AssetEntry findByPrimaryKey(long entryId)
382         throws NoSuchEntryException, SystemException {
383         AssetEntry assetEntry = fetchByPrimaryKey(entryId);
384 
385         if (assetEntry == null) {
386             if (_log.isWarnEnabled()) {
387                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + entryId);
388             }
389 
390             throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
391                 entryId);
392         }
393 
394         return assetEntry;
395     }
396 
397     public AssetEntry fetchByPrimaryKey(Serializable primaryKey)
398         throws SystemException {
399         return fetchByPrimaryKey(((Long)primaryKey).longValue());
400     }
401 
402     public AssetEntry fetchByPrimaryKey(long entryId) throws SystemException {
403         AssetEntry assetEntry = (AssetEntry)EntityCacheUtil.getResult(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
404                 AssetEntryImpl.class, entryId, this);
405 
406         if (assetEntry == null) {
407             Session session = null;
408 
409             try {
410                 session = openSession();
411 
412                 assetEntry = (AssetEntry)session.get(AssetEntryImpl.class,
413                         new Long(entryId));
414             }
415             catch (Exception e) {
416                 throw processException(e);
417             }
418             finally {
419                 if (assetEntry != null) {
420                     cacheResult(assetEntry);
421                 }
422 
423                 closeSession(session);
424             }
425         }
426 
427         return assetEntry;
428     }
429 
430     public List<AssetEntry> findByCompanyId(long companyId)
431         throws SystemException {
432         return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
433             null);
434     }
435 
436     public List<AssetEntry> findByCompanyId(long companyId, int start, int end)
437         throws SystemException {
438         return findByCompanyId(companyId, start, end, null);
439     }
440 
441     public List<AssetEntry> findByCompanyId(long companyId, int start, int end,
442         OrderByComparator orderByComparator) throws SystemException {
443         Object[] finderArgs = new Object[] {
444                 new Long(companyId),
445                 
446                 String.valueOf(start), String.valueOf(end),
447                 String.valueOf(orderByComparator)
448             };
449 
450         List<AssetEntry> list = (List<AssetEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
451                 finderArgs, this);
452 
453         if (list == null) {
454             Session session = null;
455 
456             try {
457                 session = openSession();
458 
459                 StringBundler query = null;
460 
461                 if (orderByComparator != null) {
462                     query = new StringBundler(3 +
463                             (orderByComparator.getOrderByFields().length * 3));
464                 }
465                 else {
466                     query = new StringBundler(2);
467                 }
468 
469                 query.append(_SQL_SELECT_ASSETENTRY_WHERE);
470 
471                 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
472 
473                 if (orderByComparator != null) {
474                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
475                         orderByComparator);
476                 }
477 
478                 String sql = query.toString();
479 
480                 Query q = session.createQuery(sql);
481 
482                 QueryPos qPos = QueryPos.getInstance(q);
483 
484                 qPos.add(companyId);
485 
486                 list = (List<AssetEntry>)QueryUtil.list(q, getDialect(), start,
487                         end);
488             }
489             catch (Exception e) {
490                 throw processException(e);
491             }
492             finally {
493                 if (list == null) {
494                     list = new ArrayList<AssetEntry>();
495                 }
496 
497                 cacheResult(list);
498 
499                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
500                     finderArgs, list);
501 
502                 closeSession(session);
503             }
504         }
505 
506         return list;
507     }
508 
509     public AssetEntry findByCompanyId_First(long companyId,
510         OrderByComparator orderByComparator)
511         throws NoSuchEntryException, SystemException {
512         List<AssetEntry> list = findByCompanyId(companyId, 0, 1,
513                 orderByComparator);
514 
515         if (list.isEmpty()) {
516             StringBundler msg = new StringBundler(4);
517 
518             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
519 
520             msg.append("companyId=");
521             msg.append(companyId);
522 
523             msg.append(StringPool.CLOSE_CURLY_BRACE);
524 
525             throw new NoSuchEntryException(msg.toString());
526         }
527         else {
528             return list.get(0);
529         }
530     }
531 
532     public AssetEntry findByCompanyId_Last(long companyId,
533         OrderByComparator orderByComparator)
534         throws NoSuchEntryException, SystemException {
535         int count = countByCompanyId(companyId);
536 
537         List<AssetEntry> list = findByCompanyId(companyId, count - 1, count,
538                 orderByComparator);
539 
540         if (list.isEmpty()) {
541             StringBundler msg = new StringBundler(4);
542 
543             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
544 
545             msg.append("companyId=");
546             msg.append(companyId);
547 
548             msg.append(StringPool.CLOSE_CURLY_BRACE);
549 
550             throw new NoSuchEntryException(msg.toString());
551         }
552         else {
553             return list.get(0);
554         }
555     }
556 
557     public AssetEntry[] findByCompanyId_PrevAndNext(long entryId,
558         long companyId, OrderByComparator orderByComparator)
559         throws NoSuchEntryException, SystemException {
560         AssetEntry assetEntry = findByPrimaryKey(entryId);
561 
562         Session session = null;
563 
564         try {
565             session = openSession();
566 
567             AssetEntry[] array = new AssetEntryImpl[3];
568 
569             array[0] = getByCompanyId_PrevAndNext(session, assetEntry,
570                     companyId, orderByComparator, true);
571 
572             array[1] = assetEntry;
573 
574             array[2] = getByCompanyId_PrevAndNext(session, assetEntry,
575                     companyId, orderByComparator, false);
576 
577             return array;
578         }
579         catch (Exception e) {
580             throw processException(e);
581         }
582         finally {
583             closeSession(session);
584         }
585     }
586 
587     protected AssetEntry getByCompanyId_PrevAndNext(Session session,
588         AssetEntry assetEntry, long companyId,
589         OrderByComparator orderByComparator, boolean previous) {
590         StringBundler query = null;
591 
592         if (orderByComparator != null) {
593             query = new StringBundler(6 +
594                     (orderByComparator.getOrderByFields().length * 6));
595         }
596         else {
597             query = new StringBundler(3);
598         }
599 
600         query.append(_SQL_SELECT_ASSETENTRY_WHERE);
601 
602         query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
603 
604         if (orderByComparator != null) {
605             String[] orderByFields = orderByComparator.getOrderByFields();
606 
607             if (orderByFields.length > 0) {
608                 query.append(WHERE_AND);
609             }
610 
611             for (int i = 0; i < orderByFields.length; i++) {
612                 query.append(_ORDER_BY_ENTITY_ALIAS);
613                 query.append(orderByFields[i]);
614 
615                 if ((i + 1) < orderByFields.length) {
616                     if (orderByComparator.isAscending() ^ previous) {
617                         query.append(WHERE_GREATER_THAN_HAS_NEXT);
618                     }
619                     else {
620                         query.append(WHERE_LESSER_THAN_HAS_NEXT);
621                     }
622                 }
623                 else {
624                     if (orderByComparator.isAscending() ^ previous) {
625                         query.append(WHERE_GREATER_THAN);
626                     }
627                     else {
628                         query.append(WHERE_LESSER_THAN);
629                     }
630                 }
631             }
632 
633             query.append(ORDER_BY_CLAUSE);
634 
635             for (int i = 0; i < orderByFields.length; i++) {
636                 query.append(_ORDER_BY_ENTITY_ALIAS);
637                 query.append(orderByFields[i]);
638 
639                 if ((i + 1) < orderByFields.length) {
640                     if (orderByComparator.isAscending() ^ previous) {
641                         query.append(ORDER_BY_ASC_HAS_NEXT);
642                     }
643                     else {
644                         query.append(ORDER_BY_DESC_HAS_NEXT);
645                     }
646                 }
647                 else {
648                     if (orderByComparator.isAscending() ^ previous) {
649                         query.append(ORDER_BY_ASC);
650                     }
651                     else {
652                         query.append(ORDER_BY_DESC);
653                     }
654                 }
655             }
656         }
657 
658         String sql = query.toString();
659 
660         Query q = session.createQuery(sql);
661 
662         q.setFirstResult(0);
663         q.setMaxResults(2);
664 
665         QueryPos qPos = QueryPos.getInstance(q);
666 
667         qPos.add(companyId);
668 
669         if (orderByComparator != null) {
670             Object[] values = orderByComparator.getOrderByValues(assetEntry);
671 
672             for (Object value : values) {
673                 qPos.add(value);
674             }
675         }
676 
677         List<AssetEntry> list = q.list();
678 
679         if (list.size() == 2) {
680             return list.get(1);
681         }
682         else {
683             return null;
684         }
685     }
686 
687     public AssetEntry findByC_C(long classNameId, long classPK)
688         throws NoSuchEntryException, SystemException {
689         AssetEntry assetEntry = fetchByC_C(classNameId, classPK);
690 
691         if (assetEntry == null) {
692             StringBundler msg = new StringBundler(6);
693 
694             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
695 
696             msg.append("classNameId=");
697             msg.append(classNameId);
698 
699             msg.append(", classPK=");
700             msg.append(classPK);
701 
702             msg.append(StringPool.CLOSE_CURLY_BRACE);
703 
704             if (_log.isWarnEnabled()) {
705                 _log.warn(msg.toString());
706             }
707 
708             throw new NoSuchEntryException(msg.toString());
709         }
710 
711         return assetEntry;
712     }
713 
714     public AssetEntry fetchByC_C(long classNameId, long classPK)
715         throws SystemException {
716         return fetchByC_C(classNameId, classPK, true);
717     }
718 
719     public AssetEntry fetchByC_C(long classNameId, long classPK,
720         boolean retrieveFromCache) throws SystemException {
721         Object[] finderArgs = new Object[] {
722                 new Long(classNameId), new Long(classPK)
723             };
724 
725         Object result = null;
726 
727         if (retrieveFromCache) {
728             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
729                     finderArgs, this);
730         }
731 
732         if (result == null) {
733             Session session = null;
734 
735             try {
736                 session = openSession();
737 
738                 StringBundler query = new StringBundler(3);
739 
740                 query.append(_SQL_SELECT_ASSETENTRY_WHERE);
741 
742                 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
743 
744                 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
745 
746                 String sql = query.toString();
747 
748                 Query q = session.createQuery(sql);
749 
750                 QueryPos qPos = QueryPos.getInstance(q);
751 
752                 qPos.add(classNameId);
753 
754                 qPos.add(classPK);
755 
756                 List<AssetEntry> list = q.list();
757 
758                 result = list;
759 
760                 AssetEntry assetEntry = null;
761 
762                 if (list.isEmpty()) {
763                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
764                         finderArgs, list);
765                 }
766                 else {
767                     assetEntry = list.get(0);
768 
769                     cacheResult(assetEntry);
770 
771                     if ((assetEntry.getClassNameId() != classNameId) ||
772                             (assetEntry.getClassPK() != classPK)) {
773                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
774                             finderArgs, assetEntry);
775                     }
776                 }
777 
778                 return assetEntry;
779             }
780             catch (Exception e) {
781                 throw processException(e);
782             }
783             finally {
784                 if (result == null) {
785                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
786                         finderArgs, new ArrayList<AssetEntry>());
787                 }
788 
789                 closeSession(session);
790             }
791         }
792         else {
793             if (result instanceof List<?>) {
794                 return null;
795             }
796             else {
797                 return (AssetEntry)result;
798             }
799         }
800     }
801 
802     public List<AssetEntry> findAll() throws SystemException {
803         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
804     }
805 
806     public List<AssetEntry> findAll(int start, int end)
807         throws SystemException {
808         return findAll(start, end, null);
809     }
810 
811     public List<AssetEntry> findAll(int start, int end,
812         OrderByComparator orderByComparator) throws SystemException {
813         Object[] finderArgs = new Object[] {
814                 String.valueOf(start), String.valueOf(end),
815                 String.valueOf(orderByComparator)
816             };
817 
818         List<AssetEntry> list = (List<AssetEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
819                 finderArgs, this);
820 
821         if (list == null) {
822             Session session = null;
823 
824             try {
825                 session = openSession();
826 
827                 StringBundler query = null;
828                 String sql = null;
829 
830                 if (orderByComparator != null) {
831                     query = new StringBundler(2 +
832                             (orderByComparator.getOrderByFields().length * 3));
833 
834                     query.append(_SQL_SELECT_ASSETENTRY);
835 
836                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
837                         orderByComparator);
838 
839                     sql = query.toString();
840                 }
841 
842                 sql = _SQL_SELECT_ASSETENTRY;
843 
844                 Query q = session.createQuery(sql);
845 
846                 if (orderByComparator == null) {
847                     list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
848                             start, end, false);
849 
850                     Collections.sort(list);
851                 }
852                 else {
853                     list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
854                             start, end);
855                 }
856             }
857             catch (Exception e) {
858                 throw processException(e);
859             }
860             finally {
861                 if (list == null) {
862                     list = new ArrayList<AssetEntry>();
863                 }
864 
865                 cacheResult(list);
866 
867                 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
868 
869                 closeSession(session);
870             }
871         }
872 
873         return list;
874     }
875 
876     public void removeByCompanyId(long companyId) throws SystemException {
877         for (AssetEntry assetEntry : findByCompanyId(companyId)) {
878             remove(assetEntry);
879         }
880     }
881 
882     public void removeByC_C(long classNameId, long classPK)
883         throws NoSuchEntryException, SystemException {
884         AssetEntry assetEntry = findByC_C(classNameId, classPK);
885 
886         remove(assetEntry);
887     }
888 
889     public void removeAll() throws SystemException {
890         for (AssetEntry assetEntry : findAll()) {
891             remove(assetEntry);
892         }
893     }
894 
895     public int countByCompanyId(long companyId) throws SystemException {
896         Object[] finderArgs = new Object[] { new Long(companyId) };
897 
898         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
899                 finderArgs, this);
900 
901         if (count == null) {
902             Session session = null;
903 
904             try {
905                 session = openSession();
906 
907                 StringBundler query = new StringBundler(2);
908 
909                 query.append(_SQL_COUNT_ASSETENTRY_WHERE);
910 
911                 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
912 
913                 String sql = query.toString();
914 
915                 Query q = session.createQuery(sql);
916 
917                 QueryPos qPos = QueryPos.getInstance(q);
918 
919                 qPos.add(companyId);
920 
921                 count = (Long)q.uniqueResult();
922             }
923             catch (Exception e) {
924                 throw processException(e);
925             }
926             finally {
927                 if (count == null) {
928                     count = Long.valueOf(0);
929                 }
930 
931                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
932                     finderArgs, count);
933 
934                 closeSession(session);
935             }
936         }
937 
938         return count.intValue();
939     }
940 
941     public int countByC_C(long classNameId, long classPK)
942         throws SystemException {
943         Object[] finderArgs = new Object[] {
944                 new Long(classNameId), new Long(classPK)
945             };
946 
947         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
948                 finderArgs, this);
949 
950         if (count == null) {
951             Session session = null;
952 
953             try {
954                 session = openSession();
955 
956                 StringBundler query = new StringBundler(3);
957 
958                 query.append(_SQL_COUNT_ASSETENTRY_WHERE);
959 
960                 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
961 
962                 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
963 
964                 String sql = query.toString();
965 
966                 Query q = session.createQuery(sql);
967 
968                 QueryPos qPos = QueryPos.getInstance(q);
969 
970                 qPos.add(classNameId);
971 
972                 qPos.add(classPK);
973 
974                 count = (Long)q.uniqueResult();
975             }
976             catch (Exception e) {
977                 throw processException(e);
978             }
979             finally {
980                 if (count == null) {
981                     count = Long.valueOf(0);
982                 }
983 
984                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
985                     count);
986 
987                 closeSession(session);
988             }
989         }
990 
991         return count.intValue();
992     }
993 
994     public int countAll() throws SystemException {
995         Object[] finderArgs = new Object[0];
996 
997         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
998                 finderArgs, this);
999 
1000        if (count == null) {
1001            Session session = null;
1002
1003            try {
1004                session = openSession();
1005
1006                Query q = session.createQuery(_SQL_COUNT_ASSETENTRY);
1007
1008                count = (Long)q.uniqueResult();
1009            }
1010            catch (Exception e) {
1011                throw processException(e);
1012            }
1013            finally {
1014                if (count == null) {
1015                    count = Long.valueOf(0);
1016                }
1017
1018                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1019                    count);
1020
1021                closeSession(session);
1022            }
1023        }
1024
1025        return count.intValue();
1026    }
1027
1028    public List<com.liferay.portlet.asset.model.AssetCategory> getAssetCategories(
1029        long pk) throws SystemException {
1030        return getAssetCategories(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1031    }
1032
1033    public List<com.liferay.portlet.asset.model.AssetCategory> getAssetCategories(
1034        long pk, int start, int end) throws SystemException {
1035        return getAssetCategories(pk, start, end, null);
1036    }
1037
1038    public static final FinderPath FINDER_PATH_GET_ASSETCATEGORIES = new FinderPath(com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
1039            AssetEntryModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETCATEGORIES,
1040            AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME,
1041            "getAssetCategories",
1042            new String[] {
1043                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1044                "com.liferay.portal.kernel.util.OrderByComparator"
1045            });
1046
1047    public List<com.liferay.portlet.asset.model.AssetCategory> getAssetCategories(
1048        long pk, int start, int end, OrderByComparator orderByComparator)
1049        throws SystemException {
1050        Object[] finderArgs = new Object[] {
1051                new Long(pk), String.valueOf(start), String.valueOf(end),
1052                String.valueOf(orderByComparator)
1053            };
1054
1055        List<com.liferay.portlet.asset.model.AssetCategory> list = (List<com.liferay.portlet.asset.model.AssetCategory>)FinderCacheUtil.getResult(FINDER_PATH_GET_ASSETCATEGORIES,
1056                finderArgs, this);
1057
1058        if (list == null) {
1059            Session session = null;
1060
1061            try {
1062                session = openSession();
1063
1064                String sql = null;
1065
1066                if (orderByComparator != null) {
1067                    sql = _SQL_GETASSETCATEGORIES.concat(ORDER_BY_CLAUSE)
1068                                                 .concat(orderByComparator.getOrderBy());
1069                }
1070
1071                else {
1072                    sql = _SQL_GETASSETCATEGORIES.concat(com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl.ORDER_BY_SQL);
1073                }
1074
1075                SQLQuery q = session.createSQLQuery(sql);
1076
1077                q.addEntity("AssetCategory",
1078                    com.liferay.portlet.asset.model.impl.AssetCategoryImpl.class);
1079
1080                QueryPos qPos = QueryPos.getInstance(q);
1081
1082                qPos.add(pk);
1083
1084                list = (List<com.liferay.portlet.asset.model.AssetCategory>)QueryUtil.list(q,
1085                        getDialect(), start, end);
1086            }
1087            catch (Exception e) {
1088                throw processException(e);
1089            }
1090            finally {
1091                if (list == null) {
1092                    list = new ArrayList<com.liferay.portlet.asset.model.AssetCategory>();
1093                }
1094
1095                assetCategoryPersistence.cacheResult(list);
1096
1097                FinderCacheUtil.putResult(FINDER_PATH_GET_ASSETCATEGORIES,
1098                    finderArgs, list);
1099
1100                closeSession(session);
1101            }
1102        }
1103
1104        return list;
1105    }
1106
1107    public static final FinderPath FINDER_PATH_GET_ASSETCATEGORIES_SIZE = new FinderPath(com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
1108            AssetEntryModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETCATEGORIES,
1109            AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME,
1110            "getAssetCategoriesSize", new String[] { Long.class.getName() });
1111
1112    public int getAssetCategoriesSize(long pk) throws SystemException {
1113        Object[] finderArgs = new Object[] { new Long(pk) };
1114
1115        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_ASSETCATEGORIES_SIZE,
1116                finderArgs, this);
1117
1118        if (count == null) {
1119            Session session = null;
1120
1121            try {
1122                session = openSession();
1123
1124                SQLQuery q = session.createSQLQuery(_SQL_GETASSETCATEGORIESSIZE);
1125
1126                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1127
1128                QueryPos qPos = QueryPos.getInstance(q);
1129
1130                qPos.add(pk);
1131
1132                count = (Long)q.uniqueResult();
1133            }
1134            catch (Exception e) {
1135                throw processException(e);
1136            }
1137            finally {
1138                if (count == null) {
1139                    count = Long.valueOf(0);
1140                }
1141
1142                FinderCacheUtil.putResult(FINDER_PATH_GET_ASSETCATEGORIES_SIZE,
1143                    finderArgs, count);
1144
1145                closeSession(session);
1146            }
1147        }
1148
1149        return count.intValue();
1150    }
1151
1152    public static final FinderPath FINDER_PATH_CONTAINS_ASSETCATEGORY = new FinderPath(com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
1153            AssetEntryModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETCATEGORIES,
1154            AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME,
1155            "containsAssetCategory",
1156            new String[] { Long.class.getName(), Long.class.getName() });
1157
1158    public boolean containsAssetCategory(long pk, long assetCategoryPK)
1159        throws SystemException {
1160        Object[] finderArgs = new Object[] {
1161                new Long(pk),
1162                
1163                new Long(assetCategoryPK)
1164            };
1165
1166        Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_ASSETCATEGORY,
1167                finderArgs, this);
1168
1169        if (value == null) {
1170            try {
1171                value = Boolean.valueOf(containsAssetCategory.contains(pk,
1172                            assetCategoryPK));
1173            }
1174            catch (Exception e) {
1175                throw processException(e);
1176            }
1177            finally {
1178                if (value == null) {
1179                    value = Boolean.FALSE;
1180                }
1181
1182                FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_ASSETCATEGORY,
1183                    finderArgs, value);
1184            }
1185        }
1186
1187        return value.booleanValue();
1188    }
1189
1190    public boolean containsAssetCategories(long pk) throws SystemException {
1191        if (getAssetCategoriesSize(pk) > 0) {
1192            return true;
1193        }
1194        else {
1195            return false;
1196        }
1197    }
1198
1199    public void addAssetCategory(long pk, long assetCategoryPK)
1200        throws SystemException {
1201        try {
1202            addAssetCategory.add(pk, assetCategoryPK);
1203        }
1204        catch (Exception e) {
1205            throw processException(e);
1206        }
1207        finally {
1208            FinderCacheUtil.clearCache(AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
1209        }
1210    }
1211
1212    public void addAssetCategory(long pk,
1213        com.liferay.portlet.asset.model.AssetCategory assetCategory)
1214        throws SystemException {
1215        try {
1216            addAssetCategory.add(pk, assetCategory.getPrimaryKey());
1217        }
1218        catch (Exception e) {
1219            throw processException(e);
1220        }
1221        finally {
1222            FinderCacheUtil.clearCache(AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
1223        }
1224    }
1225
1226    public void addAssetCategories(long pk, long[] assetCategoryPKs)
1227        throws SystemException {
1228        try {
1229            for (long assetCategoryPK : assetCategoryPKs) {
1230                addAssetCategory.add(pk, assetCategoryPK);
1231            }
1232        }
1233        catch (Exception e) {
1234            throw processException(e);
1235        }
1236        finally {
1237            FinderCacheUtil.clearCache(AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
1238        }
1239    }
1240
1241    public void addAssetCategories(long pk,
1242        List<com.liferay.portlet.asset.model.AssetCategory> assetCategories)
1243        throws SystemException {
1244        try {
1245            for (com.liferay.portlet.asset.model.AssetCategory assetCategory : assetCategories) {
1246                addAssetCategory.add(pk, assetCategory.getPrimaryKey());
1247            }
1248        }
1249        catch (Exception e) {
1250            throw processException(e);
1251        }
1252        finally {
1253            FinderCacheUtil.clearCache(AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
1254        }
1255    }
1256
1257    public void clearAssetCategories(long pk) throws SystemException {
1258        try {
1259            clearAssetCategories.clear(pk);
1260        }
1261        catch (Exception e) {
1262            throw processException(e);
1263        }
1264        finally {
1265            FinderCacheUtil.clearCache(AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
1266        }
1267    }
1268
1269    public void removeAssetCategory(long pk, long assetCategoryPK)
1270        throws SystemException {
1271        try {
1272            removeAssetCategory.remove(pk, assetCategoryPK);
1273        }
1274        catch (Exception e) {
1275            throw processException(e);
1276        }
1277        finally {
1278            FinderCacheUtil.clearCache(AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
1279        }
1280    }
1281
1282    public void removeAssetCategory(long pk,
1283        com.liferay.portlet.asset.model.AssetCategory assetCategory)
1284        throws SystemException {
1285        try {
1286            removeAssetCategory.remove(pk, assetCategory.getPrimaryKey());
1287        }
1288        catch (Exception e) {
1289            throw processException(e);
1290        }
1291        finally {
1292            FinderCacheUtil.clearCache(AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
1293        }
1294    }
1295
1296    public void removeAssetCategories(long pk, long[] assetCategoryPKs)
1297        throws SystemException {
1298        try {
1299            for (long assetCategoryPK : assetCategoryPKs) {
1300                removeAssetCategory.remove(pk, assetCategoryPK);
1301            }
1302        }
1303        catch (Exception e) {
1304            throw processException(e);
1305        }
1306        finally {
1307            FinderCacheUtil.clearCache(AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
1308        }
1309    }
1310
1311    public void removeAssetCategories(long pk,
1312        List<com.liferay.portlet.asset.model.AssetCategory> assetCategories)
1313        throws SystemException {
1314        try {
1315            for (com.liferay.portlet.asset.model.AssetCategory assetCategory : assetCategories) {
1316                removeAssetCategory.remove(pk, assetCategory.getPrimaryKey());
1317            }
1318        }
1319        catch (Exception e) {
1320            throw processException(e);
1321        }
1322        finally {
1323            FinderCacheUtil.clearCache(AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
1324        }
1325    }
1326
1327    public void setAssetCategories(long pk, long[] assetCategoryPKs)
1328        throws SystemException {
1329        try {
1330            Set<Long> assetCategoryPKSet = SetUtil.fromArray(assetCategoryPKs);
1331
1332            List<com.liferay.portlet.asset.model.AssetCategory> assetCategories = getAssetCategories(pk);
1333
1334            for (com.liferay.portlet.asset.model.AssetCategory assetCategory : assetCategories) {
1335                if (!assetCategoryPKSet.contains(assetCategory.getPrimaryKey())) {
1336                    removeAssetCategory.remove(pk, assetCategory.getPrimaryKey());
1337                }
1338                else {
1339                    assetCategoryPKSet.remove(assetCategory.getPrimaryKey());
1340                }
1341            }
1342
1343            for (Long assetCategoryPK : assetCategoryPKSet) {
1344                addAssetCategory.add(pk, assetCategoryPK);
1345            }
1346        }
1347        catch (Exception e) {
1348            throw processException(e);
1349        }
1350        finally {
1351            FinderCacheUtil.clearCache(AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
1352        }
1353    }
1354
1355    public void setAssetCategories(long pk,
1356        List<com.liferay.portlet.asset.model.AssetCategory> assetCategories)
1357        throws SystemException {
1358        try {
1359            long[] assetCategoryPKs = new long[assetCategories.size()];
1360
1361            for (int i = 0; i < assetCategories.size(); i++) {
1362                com.liferay.portlet.asset.model.AssetCategory assetCategory = assetCategories.get(i);
1363
1364                assetCategoryPKs[i] = assetCategory.getPrimaryKey();
1365            }
1366
1367            setAssetCategories(pk, assetCategoryPKs);
1368        }
1369        catch (Exception e) {
1370            throw processException(e);
1371        }
1372        finally {
1373            FinderCacheUtil.clearCache(AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
1374        }
1375    }
1376
1377    public List<com.liferay.portlet.asset.model.AssetTag> getAssetTags(long pk)
1378        throws SystemException {
1379        return getAssetTags(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1380    }
1381
1382    public List<com.liferay.portlet.asset.model.AssetTag> getAssetTags(
1383        long pk, int start, int end) throws SystemException {
1384        return getAssetTags(pk, start, end, null);
1385    }
1386
1387    public static final FinderPath FINDER_PATH_GET_ASSETTAGS = new FinderPath(com.liferay.portlet.asset.model.impl.AssetTagModelImpl.ENTITY_CACHE_ENABLED,
1388            AssetEntryModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETTAGS,
1389            AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME,
1390            "getAssetTags",
1391            new String[] {
1392                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1393                "com.liferay.portal.kernel.util.OrderByComparator"
1394            });
1395
1396    public List<com.liferay.portlet.asset.model.AssetTag> getAssetTags(
1397        long pk, int start, int end, OrderByComparator orderByComparator)
1398        throws SystemException {
1399        Object[] finderArgs = new Object[] {
1400                new Long(pk), String.valueOf(start), String.valueOf(end),
1401                String.valueOf(orderByComparator)
1402            };
1403
1404        List<com.liferay.portlet.asset.model.AssetTag> list = (List<com.liferay.portlet.asset.model.AssetTag>)FinderCacheUtil.getResult(FINDER_PATH_GET_ASSETTAGS,
1405                finderArgs, this);
1406
1407        if (list == null) {
1408            Session session = null;
1409
1410            try {
1411                session = openSession();
1412
1413                String sql = null;
1414
1415                if (orderByComparator != null) {
1416                    sql = _SQL_GETASSETTAGS.concat(ORDER_BY_CLAUSE)
1417                                           .concat(orderByComparator.getOrderBy());
1418                }
1419
1420                else {
1421                    sql = _SQL_GETASSETTAGS.concat(com.liferay.portlet.asset.model.impl.AssetTagModelImpl.ORDER_BY_SQL);
1422                }
1423
1424                SQLQuery q = session.createSQLQuery(sql);
1425
1426                q.addEntity("AssetTag",
1427                    com.liferay.portlet.asset.model.impl.AssetTagImpl.class);
1428
1429                QueryPos qPos = QueryPos.getInstance(q);
1430
1431                qPos.add(pk);
1432
1433                list = (List<com.liferay.portlet.asset.model.AssetTag>)QueryUtil.list(q,
1434                        getDialect(), start, end);
1435            }
1436            catch (Exception e) {
1437                throw processException(e);
1438            }
1439            finally {
1440                if (list == null) {
1441                    list = new ArrayList<com.liferay.portlet.asset.model.AssetTag>();
1442                }
1443
1444                assetTagPersistence.cacheResult(list);
1445
1446                FinderCacheUtil.putResult(FINDER_PATH_GET_ASSETTAGS,
1447                    finderArgs, list);
1448
1449                closeSession(session);
1450            }
1451        }
1452
1453        return list;
1454    }
1455
1456    public static final FinderPath FINDER_PATH_GET_ASSETTAGS_SIZE = new FinderPath(com.liferay.portlet.asset.model.impl.AssetTagModelImpl.ENTITY_CACHE_ENABLED,
1457            AssetEntryModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETTAGS,
1458            AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME,
1459            "getAssetTagsSize", new String[] { Long.class.getName() });
1460
1461    public int getAssetTagsSize(long pk) throws SystemException {
1462        Object[] finderArgs = new Object[] { new Long(pk) };
1463
1464        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_ASSETTAGS_SIZE,
1465                finderArgs, this);
1466
1467        if (count == null) {
1468            Session session = null;
1469
1470            try {
1471                session = openSession();
1472
1473                SQLQuery q = session.createSQLQuery(_SQL_GETASSETTAGSSIZE);
1474
1475                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1476
1477                QueryPos qPos = QueryPos.getInstance(q);
1478
1479                qPos.add(pk);
1480
1481                count = (Long)q.uniqueResult();
1482            }
1483            catch (Exception e) {
1484                throw processException(e);
1485            }
1486            finally {
1487                if (count == null) {
1488                    count = Long.valueOf(0);
1489                }
1490
1491                FinderCacheUtil.putResult(FINDER_PATH_GET_ASSETTAGS_SIZE,
1492                    finderArgs, count);
1493
1494                closeSession(session);
1495            }
1496        }
1497
1498        return count.intValue();
1499    }
1500
1501    public static final FinderPath FINDER_PATH_CONTAINS_ASSETTAG = new FinderPath(com.liferay.portlet.asset.model.impl.AssetTagModelImpl.ENTITY_CACHE_ENABLED,
1502            AssetEntryModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETTAGS,
1503            AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME,
1504            "containsAssetTag",
1505            new String[] { Long.class.getName(), Long.class.getName() });
1506
1507    public boolean containsAssetTag(long pk, long assetTagPK)
1508        throws SystemException {
1509        Object[] finderArgs = new Object[] { new Long(pk), new Long(assetTagPK) };
1510
1511        Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_ASSETTAG,
1512                finderArgs, this);
1513
1514        if (value == null) {
1515            try {
1516                value = Boolean.valueOf(containsAssetTag.contains(pk, assetTagPK));
1517            }
1518            catch (Exception e) {
1519                throw processException(e);
1520            }
1521            finally {
1522                if (value == null) {
1523                    value = Boolean.FALSE;
1524                }
1525
1526                FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_ASSETTAG,
1527                    finderArgs, value);
1528            }
1529        }
1530
1531        return value.booleanValue();
1532    }
1533
1534    public boolean containsAssetTags(long pk) throws SystemException {
1535        if (getAssetTagsSize(pk) > 0) {
1536            return true;
1537        }
1538        else {
1539            return false;
1540        }
1541    }
1542
1543    public void addAssetTag(long pk, long assetTagPK) throws SystemException {
1544        try {
1545            addAssetTag.add(pk, assetTagPK);
1546        }
1547        catch (Exception e) {
1548            throw processException(e);
1549        }
1550        finally {
1551            FinderCacheUtil.clearCache(AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1552        }
1553    }
1554
1555    public void addAssetTag(long pk,
1556        com.liferay.portlet.asset.model.AssetTag assetTag)
1557        throws SystemException {
1558        try {
1559            addAssetTag.add(pk, assetTag.getPrimaryKey());
1560        }
1561        catch (Exception e) {
1562            throw processException(e);
1563        }
1564        finally {
1565            FinderCacheUtil.clearCache(AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1566        }
1567    }
1568
1569    public void addAssetTags(long pk, long[] assetTagPKs)
1570        throws SystemException {
1571        try {
1572            for (long assetTagPK : assetTagPKs) {
1573                addAssetTag.add(pk, assetTagPK);
1574            }
1575        }
1576        catch (Exception e) {
1577            throw processException(e);
1578        }
1579        finally {
1580            FinderCacheUtil.clearCache(AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1581        }
1582    }
1583
1584    public void addAssetTags(long pk,
1585        List<com.liferay.portlet.asset.model.AssetTag> assetTags)
1586        throws SystemException {
1587        try {
1588            for (com.liferay.portlet.asset.model.AssetTag assetTag : assetTags) {
1589                addAssetTag.add(pk, assetTag.getPrimaryKey());
1590            }
1591        }
1592        catch (Exception e) {
1593            throw processException(e);
1594        }
1595        finally {
1596            FinderCacheUtil.clearCache(AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1597        }
1598    }
1599
1600    public void clearAssetTags(long pk) throws SystemException {
1601        try {
1602            clearAssetTags.clear(pk);
1603        }
1604        catch (Exception e) {
1605            throw processException(e);
1606        }
1607        finally {
1608            FinderCacheUtil.clearCache(AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1609        }
1610    }
1611
1612    public void removeAssetTag(long pk, long assetTagPK)
1613        throws SystemException {
1614        try {
1615            removeAssetTag.remove(pk, assetTagPK);
1616        }
1617        catch (Exception e) {
1618            throw processException(e);
1619        }
1620        finally {
1621            FinderCacheUtil.clearCache(AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1622        }
1623    }
1624
1625    public void removeAssetTag(long pk,
1626        com.liferay.portlet.asset.model.AssetTag assetTag)
1627        throws SystemException {
1628        try {
1629            removeAssetTag.remove(pk, assetTag.getPrimaryKey());
1630        }
1631        catch (Exception e) {
1632            throw processException(e);
1633        }
1634        finally {
1635            FinderCacheUtil.clearCache(AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1636        }
1637    }
1638
1639    public void removeAssetTags(long pk, long[] assetTagPKs)
1640        throws SystemException {
1641        try {
1642            for (long assetTagPK : assetTagPKs) {
1643                removeAssetTag.remove(pk, assetTagPK);
1644            }
1645        }
1646        catch (Exception e) {
1647            throw processException(e);
1648        }
1649        finally {
1650            FinderCacheUtil.clearCache(AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1651        }
1652    }
1653
1654    public void removeAssetTags(long pk,
1655        List<com.liferay.portlet.asset.model.AssetTag> assetTags)
1656        throws SystemException {
1657        try {
1658            for (com.liferay.portlet.asset.model.AssetTag assetTag : assetTags) {
1659                removeAssetTag.remove(pk, assetTag.getPrimaryKey());
1660            }
1661        }
1662        catch (Exception e) {
1663            throw processException(e);
1664        }
1665        finally {
1666            FinderCacheUtil.clearCache(AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1667        }
1668    }
1669
1670    public void setAssetTags(long pk, long[] assetTagPKs)
1671        throws SystemException {
1672        try {
1673            Set<Long> assetTagPKSet = SetUtil.fromArray(assetTagPKs);
1674
1675            List<com.liferay.portlet.asset.model.AssetTag> assetTags = getAssetTags(pk);
1676
1677            for (com.liferay.portlet.asset.model.AssetTag assetTag : assetTags) {
1678                if (!assetTagPKSet.contains(assetTag.getPrimaryKey())) {
1679                    removeAssetTag.remove(pk, assetTag.getPrimaryKey());
1680                }
1681                else {
1682                    assetTagPKSet.remove(assetTag.getPrimaryKey());
1683                }
1684            }
1685
1686            for (Long assetTagPK : assetTagPKSet) {
1687                addAssetTag.add(pk, assetTagPK);
1688            }
1689        }
1690        catch (Exception e) {
1691            throw processException(e);
1692        }
1693        finally {
1694            FinderCacheUtil.clearCache(AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1695        }
1696    }
1697
1698    public void setAssetTags(long pk,
1699        List<com.liferay.portlet.asset.model.AssetTag> assetTags)
1700        throws SystemException {
1701        try {
1702            long[] assetTagPKs = new long[assetTags.size()];
1703
1704            for (int i = 0; i < assetTags.size(); i++) {
1705                com.liferay.portlet.asset.model.AssetTag assetTag = assetTags.get(i);
1706
1707                assetTagPKs[i] = assetTag.getPrimaryKey();
1708            }
1709
1710            setAssetTags(pk, assetTagPKs);
1711        }
1712        catch (Exception e) {
1713            throw processException(e);
1714        }
1715        finally {
1716            FinderCacheUtil.clearCache(AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1717        }
1718    }
1719
1720    public void afterPropertiesSet() {
1721        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1722                    com.liferay.portal.util.PropsUtil.get(
1723                        "value.object.listener.com.liferay.portlet.asset.model.AssetEntry")));
1724
1725        if (listenerClassNames.length > 0) {
1726            try {
1727                List<ModelListener<AssetEntry>> listenersList = new ArrayList<ModelListener<AssetEntry>>();
1728
1729                for (String listenerClassName : listenerClassNames) {
1730                    listenersList.add((ModelListener<AssetEntry>)InstanceFactory.newInstance(
1731                            listenerClassName));
1732                }
1733
1734                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1735            }
1736            catch (Exception e) {
1737                _log.error(e);
1738            }
1739        }
1740
1741        containsAssetCategory = new ContainsAssetCategory(this);
1742
1743        addAssetCategory = new AddAssetCategory(this);
1744        clearAssetCategories = new ClearAssetCategories(this);
1745        removeAssetCategory = new RemoveAssetCategory(this);
1746
1747        containsAssetTag = new ContainsAssetTag(this);
1748
1749        addAssetTag = new AddAssetTag(this);
1750        clearAssetTags = new ClearAssetTags(this);
1751        removeAssetTag = new RemoveAssetTag(this);
1752    }
1753
1754    @BeanReference(type = AssetCategoryPersistence.class)
1755    protected AssetCategoryPersistence assetCategoryPersistence;
1756    @BeanReference(type = AssetCategoryPropertyPersistence.class)
1757    protected AssetCategoryPropertyPersistence assetCategoryPropertyPersistence;
1758    @BeanReference(type = AssetEntryPersistence.class)
1759    protected AssetEntryPersistence assetEntryPersistence;
1760    @BeanReference(type = AssetLinkPersistence.class)
1761    protected AssetLinkPersistence assetLinkPersistence;
1762    @BeanReference(type = AssetTagPersistence.class)
1763    protected AssetTagPersistence assetTagPersistence;
1764    @BeanReference(type = AssetTagPropertyPersistence.class)
1765    protected AssetTagPropertyPersistence assetTagPropertyPersistence;
1766    @BeanReference(type = AssetTagStatsPersistence.class)
1767    protected AssetTagStatsPersistence assetTagStatsPersistence;
1768    @BeanReference(type = AssetVocabularyPersistence.class)
1769    protected AssetVocabularyPersistence assetVocabularyPersistence;
1770    @BeanReference(type = CompanyPersistence.class)
1771    protected CompanyPersistence companyPersistence;
1772    @BeanReference(type = GroupPersistence.class)
1773    protected GroupPersistence groupPersistence;
1774    @BeanReference(type = ResourcePersistence.class)
1775    protected ResourcePersistence resourcePersistence;
1776    @BeanReference(type = UserPersistence.class)
1777    protected UserPersistence userPersistence;
1778    @BeanReference(type = BlogsEntryPersistence.class)
1779    protected BlogsEntryPersistence blogsEntryPersistence;
1780    @BeanReference(type = BookmarksEntryPersistence.class)
1781    protected BookmarksEntryPersistence bookmarksEntryPersistence;
1782    @BeanReference(type = DLFileEntryPersistence.class)
1783    protected DLFileEntryPersistence dlFileEntryPersistence;
1784    @BeanReference(type = DLFolderPersistence.class)
1785    protected DLFolderPersistence dlFolderPersistence;
1786    @BeanReference(type = JournalArticlePersistence.class)
1787    protected JournalArticlePersistence journalArticlePersistence;
1788    @BeanReference(type = JournalArticleResourcePersistence.class)
1789    protected JournalArticleResourcePersistence journalArticleResourcePersistence;
1790    @BeanReference(type = MBMessagePersistence.class)
1791    protected MBMessagePersistence mbMessagePersistence;
1792    @BeanReference(type = SocialEquityLogPersistence.class)
1793    protected SocialEquityLogPersistence socialEquityLogPersistence;
1794    @BeanReference(type = WikiPagePersistence.class)
1795    protected WikiPagePersistence wikiPagePersistence;
1796    @BeanReference(type = WikiPageResourcePersistence.class)
1797    protected WikiPageResourcePersistence wikiPageResourcePersistence;
1798    protected ContainsAssetCategory containsAssetCategory;
1799    protected AddAssetCategory addAssetCategory;
1800    protected ClearAssetCategories clearAssetCategories;
1801    protected RemoveAssetCategory removeAssetCategory;
1802    protected ContainsAssetTag containsAssetTag;
1803    protected AddAssetTag addAssetTag;
1804    protected ClearAssetTags clearAssetTags;
1805    protected RemoveAssetTag removeAssetTag;
1806
1807    protected class ContainsAssetCategory {
1808        protected ContainsAssetCategory(
1809            AssetEntryPersistenceImpl persistenceImpl) {
1810            super();
1811
1812            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
1813                    _SQL_CONTAINSASSETCATEGORY,
1814                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
1815        }
1816
1817        protected boolean contains(long entryId, long categoryId) {
1818            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
1819                        new Long(entryId), new Long(categoryId)
1820                    });
1821
1822            if (results.size() > 0) {
1823                Integer count = results.get(0);
1824
1825                if (count.intValue() > 0) {
1826                    return true;
1827                }
1828            }
1829
1830            return false;
1831        }
1832
1833        private MappingSqlQuery<Integer> _mappingSqlQuery;
1834    }
1835
1836    protected class AddAssetCategory {
1837        protected AddAssetCategory(AssetEntryPersistenceImpl persistenceImpl) {
1838            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1839                    "INSERT INTO AssetEntries_AssetCategories (entryId, categoryId) VALUES (?, ?)",
1840                    new int[] { Types.BIGINT, Types.BIGINT });
1841            _persistenceImpl = persistenceImpl;
1842        }
1843
1844        protected void add(long entryId, long categoryId)
1845            throws SystemException {
1846            if (!_persistenceImpl.containsAssetCategory.contains(entryId,
1847                        categoryId)) {
1848                ModelListener<com.liferay.portlet.asset.model.AssetCategory>[] assetCategoryListeners =
1849                    assetCategoryPersistence.getListeners();
1850
1851                for (ModelListener<AssetEntry> listener : listeners) {
1852                    listener.onBeforeAddAssociation(entryId,
1853                        com.liferay.portlet.asset.model.AssetCategory.class.getName(),
1854                        categoryId);
1855                }
1856
1857                for (ModelListener<com.liferay.portlet.asset.model.AssetCategory> listener : assetCategoryListeners) {
1858                    listener.onBeforeAddAssociation(categoryId,
1859                        AssetEntry.class.getName(), entryId);
1860                }
1861
1862                _sqlUpdate.update(new Object[] {
1863                        new Long(entryId), new Long(categoryId)
1864                    });
1865
1866                for (ModelListener<AssetEntry> listener : listeners) {
1867                    listener.onAfterAddAssociation(entryId,
1868                        com.liferay.portlet.asset.model.AssetCategory.class.getName(),
1869                        categoryId);
1870                }
1871
1872                for (ModelListener<com.liferay.portlet.asset.model.AssetCategory> listener : assetCategoryListeners) {
1873                    listener.onAfterAddAssociation(categoryId,
1874                        AssetEntry.class.getName(), entryId);
1875                }
1876            }
1877        }
1878
1879        private SqlUpdate _sqlUpdate;
1880        private AssetEntryPersistenceImpl _persistenceImpl;
1881    }
1882
1883    protected class ClearAssetCategories {
1884        protected ClearAssetCategories(
1885            AssetEntryPersistenceImpl persistenceImpl) {
1886            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1887                    "DELETE FROM AssetEntries_AssetCategories WHERE entryId = ?",
1888                    new int[] { Types.BIGINT });
1889        }
1890
1891        protected void clear(long entryId) throws SystemException {
1892            ModelListener<com.liferay.portlet.asset.model.AssetCategory>[] assetCategoryListeners =
1893                assetCategoryPersistence.getListeners();
1894
1895            List<com.liferay.portlet.asset.model.AssetCategory> assetCategories = null;
1896
1897            if ((listeners.length > 0) || (assetCategoryListeners.length > 0)) {
1898                assetCategories = getAssetCategories(entryId);
1899
1900                for (com.liferay.portlet.asset.model.AssetCategory assetCategory : assetCategories) {
1901                    for (ModelListener<AssetEntry> listener : listeners) {
1902                        listener.onBeforeRemoveAssociation(entryId,
1903                            com.liferay.portlet.asset.model.AssetCategory.class.getName(),
1904                            assetCategory.getPrimaryKey());
1905                    }
1906
1907                    for (ModelListener<com.liferay.portlet.asset.model.AssetCategory> listener : assetCategoryListeners) {
1908                        listener.onBeforeRemoveAssociation(assetCategory.getPrimaryKey(),
1909                            AssetEntry.class.getName(), entryId);
1910                    }
1911                }
1912            }
1913
1914            _sqlUpdate.update(new Object[] { new Long(entryId) });
1915
1916            if ((listeners.length > 0) || (assetCategoryListeners.length > 0)) {
1917                for (com.liferay.portlet.asset.model.AssetCategory assetCategory : assetCategories) {
1918                    for (ModelListener<AssetEntry> listener : listeners) {
1919                        listener.onAfterRemoveAssociation(entryId,
1920                            com.liferay.portlet.asset.model.AssetCategory.class.getName(),
1921                            assetCategory.getPrimaryKey());
1922                    }
1923
1924                    for (ModelListener<com.liferay.portlet.asset.model.AssetCategory> listener : assetCategoryListeners) {
1925                        listener.onAfterRemoveAssociation(assetCategory.getPrimaryKey(),
1926                            AssetEntry.class.getName(), entryId);
1927                    }
1928                }
1929            }
1930        }
1931
1932        private SqlUpdate _sqlUpdate;
1933    }
1934
1935    protected class RemoveAssetCategory {
1936        protected RemoveAssetCategory(AssetEntryPersistenceImpl persistenceImpl) {
1937            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1938                    "DELETE FROM AssetEntries_AssetCategories WHERE entryId = ? AND categoryId = ?",
1939                    new int[] { Types.BIGINT, Types.BIGINT });
1940            _persistenceImpl = persistenceImpl;
1941        }
1942
1943        protected void remove(long entryId, long categoryId)
1944            throws SystemException {
1945            if (_persistenceImpl.containsAssetCategory.contains(entryId,
1946                        categoryId)) {
1947                ModelListener<com.liferay.portlet.asset.model.AssetCategory>[] assetCategoryListeners =
1948                    assetCategoryPersistence.getListeners();
1949
1950                for (ModelListener<AssetEntry> listener : listeners) {
1951                    listener.onBeforeRemoveAssociation(entryId,
1952                        com.liferay.portlet.asset.model.AssetCategory.class.getName(),
1953                        categoryId);
1954                }
1955
1956                for (ModelListener<com.liferay.portlet.asset.model.AssetCategory> listener : assetCategoryListeners) {
1957                    listener.onBeforeRemoveAssociation(categoryId,
1958                        AssetEntry.class.getName(), entryId);
1959                }
1960
1961                _sqlUpdate.update(new Object[] {
1962                        new Long(entryId), new Long(categoryId)
1963                    });
1964
1965                for (ModelListener<AssetEntry> listener : listeners) {
1966                    listener.onAfterRemoveAssociation(entryId,
1967                        com.liferay.portlet.asset.model.AssetCategory.class.getName(),
1968                        categoryId);
1969                }
1970
1971                for (ModelListener<com.liferay.portlet.asset.model.AssetCategory> listener : assetCategoryListeners) {
1972                    listener.onAfterRemoveAssociation(categoryId,
1973                        AssetEntry.class.getName(), entryId);
1974                }
1975            }
1976        }
1977
1978        private SqlUpdate _sqlUpdate;
1979        private AssetEntryPersistenceImpl _persistenceImpl;
1980    }
1981
1982    protected class ContainsAssetTag {
1983        protected ContainsAssetTag(AssetEntryPersistenceImpl persistenceImpl) {
1984            super();
1985
1986            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
1987                    _SQL_CONTAINSASSETTAG,
1988                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
1989        }
1990
1991        protected boolean contains(long entryId, long tagId) {
1992            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
1993                        new Long(entryId), new Long(tagId)
1994                    });
1995
1996            if (results.size() > 0) {
1997                Integer count = results.get(0);
1998
1999                if (count.intValue() > 0) {
2000                    return true;
2001                }
2002            }
2003
2004            return false;
2005        }
2006
2007        private MappingSqlQuery<Integer> _mappingSqlQuery;
2008    }
2009
2010    protected class AddAssetTag {
2011        protected AddAssetTag(AssetEntryPersistenceImpl persistenceImpl) {
2012            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2013                    "INSERT INTO AssetEntries_AssetTags (entryId, tagId) VALUES (?, ?)",
2014                    new int[] { Types.BIGINT, Types.BIGINT });
2015            _persistenceImpl = persistenceImpl;
2016        }
2017
2018        protected void add(long entryId, long tagId) throws SystemException {
2019            if (!_persistenceImpl.containsAssetTag.contains(entryId, tagId)) {
2020                ModelListener<com.liferay.portlet.asset.model.AssetTag>[] assetTagListeners =
2021                    assetTagPersistence.getListeners();
2022
2023                for (ModelListener<AssetEntry> listener : listeners) {
2024                    listener.onBeforeAddAssociation(entryId,
2025                        com.liferay.portlet.asset.model.AssetTag.class.getName(),
2026                        tagId);
2027                }
2028
2029                for (ModelListener<com.liferay.portlet.asset.model.AssetTag> listener : assetTagListeners) {
2030                    listener.onBeforeAddAssociation(tagId,
2031                        AssetEntry.class.getName(), entryId);
2032                }
2033
2034                _sqlUpdate.update(new Object[] {
2035                        new Long(entryId), new Long(tagId)
2036                    });
2037
2038                for (ModelListener<AssetEntry> listener : listeners) {
2039                    listener.onAfterAddAssociation(entryId,
2040                        com.liferay.portlet.asset.model.AssetTag.class.getName(),
2041                        tagId);
2042                }
2043
2044                for (ModelListener<com.liferay.portlet.asset.model.AssetTag> listener : assetTagListeners) {
2045                    listener.onAfterAddAssociation(tagId,
2046                        AssetEntry.class.getName(), entryId);
2047                }
2048            }
2049        }
2050
2051        private SqlUpdate _sqlUpdate;
2052        private AssetEntryPersistenceImpl _persistenceImpl;
2053    }
2054
2055    protected class ClearAssetTags {
2056        protected ClearAssetTags(AssetEntryPersistenceImpl persistenceImpl) {
2057            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2058                    "DELETE FROM AssetEntries_AssetTags WHERE entryId = ?",
2059                    new int[] { Types.BIGINT });
2060        }
2061
2062        protected void clear(long entryId) throws SystemException {
2063            ModelListener<com.liferay.portlet.asset.model.AssetTag>[] assetTagListeners =
2064                assetTagPersistence.getListeners();
2065
2066            List<com.liferay.portlet.asset.model.AssetTag> assetTags = null;
2067
2068            if ((listeners.length > 0) || (assetTagListeners.length > 0)) {
2069                assetTags = getAssetTags(entryId);
2070
2071                for (com.liferay.portlet.asset.model.AssetTag assetTag : assetTags) {
2072                    for (ModelListener<AssetEntry> listener : listeners) {
2073                        listener.onBeforeRemoveAssociation(entryId,
2074                            com.liferay.portlet.asset.model.AssetTag.class.getName(),
2075                            assetTag.getPrimaryKey());
2076                    }
2077
2078                    for (ModelListener<com.liferay.portlet.asset.model.AssetTag> listener : assetTagListeners) {
2079                        listener.onBeforeRemoveAssociation(assetTag.getPrimaryKey(),
2080                            AssetEntry.class.getName(), entryId);
2081                    }
2082                }
2083            }
2084
2085            _sqlUpdate.update(new Object[] { new Long(entryId) });
2086
2087            if ((listeners.length > 0) || (assetTagListeners.length > 0)) {
2088                for (com.liferay.portlet.asset.model.AssetTag assetTag : assetTags) {
2089                    for (ModelListener<AssetEntry> listener : listeners) {
2090                        listener.onAfterRemoveAssociation(entryId,
2091                            com.liferay.portlet.asset.model.AssetTag.class.getName(),
2092                            assetTag.getPrimaryKey());
2093                    }
2094
2095                    for (ModelListener<com.liferay.portlet.asset.model.AssetTag> listener : assetTagListeners) {
2096                        listener.onAfterRemoveAssociation(assetTag.getPrimaryKey(),
2097                            AssetEntry.class.getName(), entryId);
2098                    }
2099                }
2100            }
2101        }
2102
2103        private SqlUpdate _sqlUpdate;
2104    }
2105
2106    protected class RemoveAssetTag {
2107        protected RemoveAssetTag(AssetEntryPersistenceImpl persistenceImpl) {
2108            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2109                    "DELETE FROM AssetEntries_AssetTags WHERE entryId = ? AND tagId = ?",
2110                    new int[] { Types.BIGINT, Types.BIGINT });
2111            _persistenceImpl = persistenceImpl;
2112        }
2113
2114        protected void remove(long entryId, long tagId)
2115            throws SystemException {
2116            if (_persistenceImpl.containsAssetTag.contains(entryId, tagId)) {
2117                ModelListener<com.liferay.portlet.asset.model.AssetTag>[] assetTagListeners =
2118                    assetTagPersistence.getListeners();
2119
2120                for (ModelListener<AssetEntry> listener : listeners) {
2121                    listener.onBeforeRemoveAssociation(entryId,
2122                        com.liferay.portlet.asset.model.AssetTag.class.getName(),
2123                        tagId);
2124                }
2125
2126                for (ModelListener<com.liferay.portlet.asset.model.AssetTag> listener : assetTagListeners) {
2127                    listener.onBeforeRemoveAssociation(tagId,
2128                        AssetEntry.class.getName(), entryId);
2129                }
2130
2131                _sqlUpdate.update(new Object[] {
2132                        new Long(entryId), new Long(tagId)
2133                    });
2134
2135                for (ModelListener<AssetEntry> listener : listeners) {
2136                    listener.onAfterRemoveAssociation(entryId,
2137                        com.liferay.portlet.asset.model.AssetTag.class.getName(),
2138                        tagId);
2139                }
2140
2141                for (ModelListener<com.liferay.portlet.asset.model.AssetTag> listener : assetTagListeners) {
2142                    listener.onAfterRemoveAssociation(tagId,
2143                        AssetEntry.class.getName(), entryId);
2144                }
2145            }
2146        }
2147
2148        private SqlUpdate _sqlUpdate;
2149        private AssetEntryPersistenceImpl _persistenceImpl;
2150    }
2151
2152    private static final String _SQL_SELECT_ASSETENTRY = "SELECT assetEntry FROM AssetEntry assetEntry";
2153    private static final String _SQL_SELECT_ASSETENTRY_WHERE = "SELECT assetEntry FROM AssetEntry assetEntry WHERE ";
2154    private static final String _SQL_COUNT_ASSETENTRY = "SELECT COUNT(assetEntry) FROM AssetEntry assetEntry";
2155    private static final String _SQL_COUNT_ASSETENTRY_WHERE = "SELECT COUNT(assetEntry) FROM AssetEntry assetEntry WHERE ";
2156    private static final String _SQL_GETASSETCATEGORIES = "SELECT {AssetCategory.*} FROM AssetCategory INNER JOIN AssetEntries_AssetCategories ON (AssetEntries_AssetCategories.categoryId = AssetCategory.categoryId) WHERE (AssetEntries_AssetCategories.entryId = ?)";
2157    private static final String _SQL_GETASSETCATEGORIESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM AssetEntries_AssetCategories WHERE entryId = ?";
2158    private static final String _SQL_CONTAINSASSETCATEGORY = "SELECT COUNT(*) AS COUNT_VALUE FROM AssetEntries_AssetCategories WHERE entryId = ? AND categoryId = ?";
2159    private static final String _SQL_GETASSETTAGS = "SELECT {AssetTag.*} FROM AssetTag INNER JOIN AssetEntries_AssetTags ON (AssetEntries_AssetTags.tagId = AssetTag.tagId) WHERE (AssetEntries_AssetTags.entryId = ?)";
2160    private static final String _SQL_GETASSETTAGSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM AssetEntries_AssetTags WHERE entryId = ?";
2161    private static final String _SQL_CONTAINSASSETTAG = "SELECT COUNT(*) AS COUNT_VALUE FROM AssetEntries_AssetTags WHERE entryId = ? AND tagId = ?";
2162    private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "assetEntry.companyId = ?";
2163    private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "assetEntry.classNameId = ? AND ";
2164    private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "assetEntry.classPK = ?";
2165    private static final String _ORDER_BY_ENTITY_ALIAS = "assetEntry.";
2166    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetEntry exists with the primary key ";
2167    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetEntry exists with the key {";
2168    private static Log _log = LogFactoryUtil.getLog(AssetEntryPersistenceImpl.class);
2169}