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