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         try {
201             clearTagsEntries.clear(tagsAsset.getPrimaryKey());
202         }
203         catch (Exception e) {
204             throw processException(e);
205         }
206         finally {
207             FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
208         }
209 
210         Session session = null;
211 
212         try {
213             session = openSession();
214 
215             if (tagsAsset.isCachedModel() || BatchSessionUtil.isEnabled()) {
216                 Object staleObject = session.get(TagsAssetImpl.class,
217                         tagsAsset.getPrimaryKeyObj());
218 
219                 if (staleObject != null) {
220                     session.evict(staleObject);
221                 }
222             }
223 
224             session.delete(tagsAsset);
225 
226             session.flush();
227         }
228         catch (Exception e) {
229             throw processException(e);
230         }
231         finally {
232             closeSession(session);
233         }
234 
235         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
236 
237         TagsAssetModelImpl tagsAssetModelImpl = (TagsAssetModelImpl)tagsAsset;
238 
239         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
240             new Object[] {
241                 new Long(tagsAssetModelImpl.getOriginalClassNameId()),
242                 new Long(tagsAssetModelImpl.getOriginalClassPK())
243             });
244 
245         EntityCacheUtil.removeResult(TagsAssetModelImpl.ENTITY_CACHE_ENABLED,
246             TagsAssetImpl.class, tagsAsset.getPrimaryKey());
247 
248         return tagsAsset;
249     }
250 
251     /**
252      * @deprecated Use {@link #update(TagsAsset, boolean merge)}.
253      */
254     public TagsAsset update(TagsAsset tagsAsset) throws SystemException {
255         if (_log.isWarnEnabled()) {
256             _log.warn(
257                 "Using the deprecated update(TagsAsset tagsAsset) method. Use update(TagsAsset tagsAsset, boolean merge) instead.");
258         }
259 
260         return update(tagsAsset, false);
261     }
262 
263     /**
264      * Add, update, or merge, the entity. This method also calls the model
265      * listeners to trigger the proper events associated with adding, deleting,
266      * or updating an entity.
267      *
268      * @param  tagsAsset the entity to add, update, or merge
269      * @param  merge boolean value for whether to merge the entity. The default
270      *         value is false. Setting merge to true is more expensive and
271      *         should only be true when tagsAsset is transient. See
272      *         LEP-5473 for a detailed discussion of this method.
273      * @return the entity that was added, updated, or merged
274      */
275     public TagsAsset update(TagsAsset tagsAsset, boolean merge)
276         throws SystemException {
277         boolean isNew = tagsAsset.isNew();
278 
279         for (ModelListener<TagsAsset> listener : listeners) {
280             if (isNew) {
281                 listener.onBeforeCreate(tagsAsset);
282             }
283             else {
284                 listener.onBeforeUpdate(tagsAsset);
285             }
286         }
287 
288         tagsAsset = updateImpl(tagsAsset, merge);
289 
290         for (ModelListener<TagsAsset> listener : listeners) {
291             if (isNew) {
292                 listener.onAfterCreate(tagsAsset);
293             }
294             else {
295                 listener.onAfterUpdate(tagsAsset);
296             }
297         }
298 
299         return tagsAsset;
300     }
301 
302     public TagsAsset updateImpl(
303         com.liferay.portlet.tags.model.TagsAsset tagsAsset, boolean merge)
304         throws SystemException {
305         boolean isNew = tagsAsset.isNew();
306 
307         TagsAssetModelImpl tagsAssetModelImpl = (TagsAssetModelImpl)tagsAsset;
308 
309         Session session = null;
310 
311         try {
312             session = openSession();
313 
314             BatchSessionUtil.update(session, tagsAsset, merge);
315 
316             tagsAsset.setNew(false);
317         }
318         catch (Exception e) {
319             throw processException(e);
320         }
321         finally {
322             closeSession(session);
323         }
324 
325         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
326 
327         EntityCacheUtil.putResult(TagsAssetModelImpl.ENTITY_CACHE_ENABLED,
328             TagsAssetImpl.class, tagsAsset.getPrimaryKey(), tagsAsset);
329 
330         if (!isNew &&
331                 ((tagsAsset.getClassNameId() != tagsAssetModelImpl.getOriginalClassNameId()) ||
332                 (tagsAsset.getClassPK() != tagsAssetModelImpl.getOriginalClassPK()))) {
333             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
334                 new Object[] {
335                     new Long(tagsAssetModelImpl.getOriginalClassNameId()),
336                     new Long(tagsAssetModelImpl.getOriginalClassPK())
337                 });
338         }
339 
340         if (isNew ||
341                 ((tagsAsset.getClassNameId() != tagsAssetModelImpl.getOriginalClassNameId()) ||
342                 (tagsAsset.getClassPK() != tagsAssetModelImpl.getOriginalClassPK()))) {
343             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
344                 new Object[] {
345                     new Long(tagsAsset.getClassNameId()),
346                     new Long(tagsAsset.getClassPK())
347                 }, tagsAsset);
348         }
349 
350         return tagsAsset;
351     }
352 
353     public TagsAsset findByPrimaryKey(long assetId)
354         throws NoSuchAssetException, SystemException {
355         TagsAsset tagsAsset = fetchByPrimaryKey(assetId);
356 
357         if (tagsAsset == null) {
358             if (_log.isWarnEnabled()) {
359                 _log.warn("No TagsAsset exists with the primary key " +
360                     assetId);
361             }
362 
363             throw new NoSuchAssetException(
364                 "No TagsAsset exists with the primary key " + assetId);
365         }
366 
367         return tagsAsset;
368     }
369 
370     public TagsAsset fetchByPrimaryKey(long assetId) throws SystemException {
371         TagsAsset tagsAsset = (TagsAsset)EntityCacheUtil.getResult(TagsAssetModelImpl.ENTITY_CACHE_ENABLED,
372                 TagsAssetImpl.class, assetId, this);
373 
374         if (tagsAsset == null) {
375             Session session = null;
376 
377             try {
378                 session = openSession();
379 
380                 tagsAsset = (TagsAsset)session.get(TagsAssetImpl.class,
381                         new Long(assetId));
382             }
383             catch (Exception e) {
384                 throw processException(e);
385             }
386             finally {
387                 if (tagsAsset != null) {
388                     cacheResult(tagsAsset);
389                 }
390 
391                 closeSession(session);
392             }
393         }
394 
395         return tagsAsset;
396     }
397 
398     public List<TagsAsset> findByCompanyId(long companyId)
399         throws SystemException {
400         Object[] finderArgs = new Object[] { new Long(companyId) };
401 
402         List<TagsAsset> list = (List<TagsAsset>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
403                 finderArgs, this);
404 
405         if (list == null) {
406             Session session = null;
407 
408             try {
409                 session = openSession();
410 
411                 StringBuilder query = new StringBuilder();
412 
413                 query.append("SELECT tagsAsset FROM TagsAsset tagsAsset WHERE ");
414 
415                 query.append("tagsAsset.companyId = ?");
416 
417                 query.append(" ");
418 
419                 Query q = session.createQuery(query.toString());
420 
421                 QueryPos qPos = QueryPos.getInstance(q);
422 
423                 qPos.add(companyId);
424 
425                 list = q.list();
426             }
427             catch (Exception e) {
428                 throw processException(e);
429             }
430             finally {
431                 if (list == null) {
432                     list = new ArrayList<TagsAsset>();
433                 }
434 
435                 cacheResult(list);
436 
437                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
438                     finderArgs, list);
439 
440                 closeSession(session);
441             }
442         }
443 
444         return list;
445     }
446 
447     public List<TagsAsset> findByCompanyId(long companyId, int start, int end)
448         throws SystemException {
449         return findByCompanyId(companyId, start, end, null);
450     }
451 
452     public List<TagsAsset> findByCompanyId(long companyId, int start, int end,
453         OrderByComparator obc) throws SystemException {
454         Object[] finderArgs = new Object[] {
455                 new Long(companyId),
456                 
457                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
458             };
459 
460         List<TagsAsset> list = (List<TagsAsset>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
461                 finderArgs, this);
462 
463         if (list == null) {
464             Session session = null;
465 
466             try {
467                 session = openSession();
468 
469                 StringBuilder query = new StringBuilder();
470 
471                 query.append("SELECT tagsAsset FROM TagsAsset tagsAsset WHERE ");
472 
473                 query.append("tagsAsset.companyId = ?");
474 
475                 query.append(" ");
476 
477                 if (obc != null) {
478                     query.append("ORDER BY ");
479 
480                     String[] orderByFields = obc.getOrderByFields();
481 
482                     for (int i = 0; i < orderByFields.length; i++) {
483                         query.append("tagsAsset.");
484                         query.append(orderByFields[i]);
485 
486                         if (obc.isAscending()) {
487                             query.append(" ASC");
488                         }
489                         else {
490                             query.append(" DESC");
491                         }
492 
493                         if ((i + 1) < orderByFields.length) {
494                             query.append(", ");
495                         }
496                     }
497                 }
498 
499                 Query q = session.createQuery(query.toString());
500 
501                 QueryPos qPos = QueryPos.getInstance(q);
502 
503                 qPos.add(companyId);
504 
505                 list = (List<TagsAsset>)QueryUtil.list(q, getDialect(), start,
506                         end);
507             }
508             catch (Exception e) {
509                 throw processException(e);
510             }
511             finally {
512                 if (list == null) {
513                     list = new ArrayList<TagsAsset>();
514                 }
515 
516                 cacheResult(list);
517 
518                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
519                     finderArgs, list);
520 
521                 closeSession(session);
522             }
523         }
524 
525         return list;
526     }
527 
528     public TagsAsset findByCompanyId_First(long companyId, OrderByComparator obc)
529         throws NoSuchAssetException, SystemException {
530         List<TagsAsset> list = findByCompanyId(companyId, 0, 1, obc);
531 
532         if (list.isEmpty()) {
533             StringBuilder msg = new StringBuilder();
534 
535             msg.append("No TagsAsset exists with the key {");
536 
537             msg.append("companyId=" + companyId);
538 
539             msg.append(StringPool.CLOSE_CURLY_BRACE);
540 
541             throw new NoSuchAssetException(msg.toString());
542         }
543         else {
544             return list.get(0);
545         }
546     }
547 
548     public TagsAsset findByCompanyId_Last(long companyId, OrderByComparator obc)
549         throws NoSuchAssetException, SystemException {
550         int count = countByCompanyId(companyId);
551 
552         List<TagsAsset> list = findByCompanyId(companyId, count - 1, count, obc);
553 
554         if (list.isEmpty()) {
555             StringBuilder msg = new StringBuilder();
556 
557             msg.append("No TagsAsset exists with the key {");
558 
559             msg.append("companyId=" + companyId);
560 
561             msg.append(StringPool.CLOSE_CURLY_BRACE);
562 
563             throw new NoSuchAssetException(msg.toString());
564         }
565         else {
566             return list.get(0);
567         }
568     }
569 
570     public TagsAsset[] findByCompanyId_PrevAndNext(long assetId,
571         long companyId, OrderByComparator obc)
572         throws NoSuchAssetException, SystemException {
573         TagsAsset tagsAsset = findByPrimaryKey(assetId);
574 
575         int count = countByCompanyId(companyId);
576 
577         Session session = null;
578 
579         try {
580             session = openSession();
581 
582             StringBuilder query = new StringBuilder();
583 
584             query.append("SELECT tagsAsset FROM TagsAsset tagsAsset WHERE ");
585 
586             query.append("tagsAsset.companyId = ?");
587 
588             query.append(" ");
589 
590             if (obc != null) {
591                 query.append("ORDER BY ");
592 
593                 String[] orderByFields = obc.getOrderByFields();
594 
595                 for (int i = 0; i < orderByFields.length; i++) {
596                     query.append("tagsAsset.");
597                     query.append(orderByFields[i]);
598 
599                     if (obc.isAscending()) {
600                         query.append(" ASC");
601                     }
602                     else {
603                         query.append(" DESC");
604                     }
605 
606                     if ((i + 1) < orderByFields.length) {
607                         query.append(", ");
608                     }
609                 }
610             }
611 
612             Query q = session.createQuery(query.toString());
613 
614             QueryPos qPos = QueryPos.getInstance(q);
615 
616             qPos.add(companyId);
617 
618             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
619                     tagsAsset);
620 
621             TagsAsset[] array = new TagsAssetImpl[3];
622 
623             array[0] = (TagsAsset)objArray[0];
624             array[1] = (TagsAsset)objArray[1];
625             array[2] = (TagsAsset)objArray[2];
626 
627             return array;
628         }
629         catch (Exception e) {
630             throw processException(e);
631         }
632         finally {
633             closeSession(session);
634         }
635     }
636 
637     public TagsAsset findByC_C(long classNameId, long classPK)
638         throws NoSuchAssetException, SystemException {
639         TagsAsset tagsAsset = fetchByC_C(classNameId, classPK);
640 
641         if (tagsAsset == null) {
642             StringBuilder msg = new StringBuilder();
643 
644             msg.append("No TagsAsset exists with the key {");
645 
646             msg.append("classNameId=" + classNameId);
647 
648             msg.append(", ");
649             msg.append("classPK=" + classPK);
650 
651             msg.append(StringPool.CLOSE_CURLY_BRACE);
652 
653             if (_log.isWarnEnabled()) {
654                 _log.warn(msg.toString());
655             }
656 
657             throw new NoSuchAssetException(msg.toString());
658         }
659 
660         return tagsAsset;
661     }
662 
663     public TagsAsset fetchByC_C(long classNameId, long classPK)
664         throws SystemException {
665         return fetchByC_C(classNameId, classPK, true);
666     }
667 
668     public TagsAsset fetchByC_C(long classNameId, long classPK,
669         boolean retrieveFromCache) throws SystemException {
670         Object[] finderArgs = new Object[] {
671                 new Long(classNameId), new Long(classPK)
672             };
673 
674         Object result = null;
675 
676         if (retrieveFromCache) {
677             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
678                     finderArgs, this);
679         }
680 
681         if (result == null) {
682             Session session = null;
683 
684             try {
685                 session = openSession();
686 
687                 StringBuilder query = new StringBuilder();
688 
689                 query.append("SELECT tagsAsset FROM TagsAsset tagsAsset WHERE ");
690 
691                 query.append("tagsAsset.classNameId = ?");
692 
693                 query.append(" AND ");
694 
695                 query.append("tagsAsset.classPK = ?");
696 
697                 query.append(" ");
698 
699                 Query q = session.createQuery(query.toString());
700 
701                 QueryPos qPos = QueryPos.getInstance(q);
702 
703                 qPos.add(classNameId);
704 
705                 qPos.add(classPK);
706 
707                 List<TagsAsset> list = q.list();
708 
709                 result = list;
710 
711                 TagsAsset tagsAsset = null;
712 
713                 if (list.isEmpty()) {
714                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
715                         finderArgs, list);
716                 }
717                 else {
718                     tagsAsset = list.get(0);
719 
720                     cacheResult(tagsAsset);
721 
722                     if ((tagsAsset.getClassNameId() != classNameId) ||
723                             (tagsAsset.getClassPK() != classPK)) {
724                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
725                             finderArgs, tagsAsset);
726                     }
727                 }
728 
729                 return tagsAsset;
730             }
731             catch (Exception e) {
732                 throw processException(e);
733             }
734             finally {
735                 if (result == null) {
736                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
737                         finderArgs, new ArrayList<TagsAsset>());
738                 }
739 
740                 closeSession(session);
741             }
742         }
743         else {
744             if (result instanceof List<?>) {
745                 return null;
746             }
747             else {
748                 return (TagsAsset)result;
749             }
750         }
751     }
752 
753     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
754         throws SystemException {
755         Session session = null;
756 
757         try {
758             session = openSession();
759 
760             dynamicQuery.compile(session);
761 
762             return dynamicQuery.list();
763         }
764         catch (Exception e) {
765             throw processException(e);
766         }
767         finally {
768             closeSession(session);
769         }
770     }
771 
772     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
773         int start, int end) throws SystemException {
774         Session session = null;
775 
776         try {
777             session = openSession();
778 
779             dynamicQuery.setLimit(start, end);
780 
781             dynamicQuery.compile(session);
782 
783             return dynamicQuery.list();
784         }
785         catch (Exception e) {
786             throw processException(e);
787         }
788         finally {
789             closeSession(session);
790         }
791     }
792 
793     public List<TagsAsset> findAll() throws SystemException {
794         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
795     }
796 
797     public List<TagsAsset> findAll(int start, int end)
798         throws SystemException {
799         return findAll(start, end, null);
800     }
801 
802     public List<TagsAsset> findAll(int start, int end, OrderByComparator obc)
803         throws SystemException {
804         Object[] finderArgs = new Object[] {
805                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
806             };
807 
808         List<TagsAsset> list = (List<TagsAsset>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
809                 finderArgs, this);
810 
811         if (list == null) {
812             Session session = null;
813 
814             try {
815                 session = openSession();
816 
817                 StringBuilder query = new StringBuilder();
818 
819                 query.append("SELECT tagsAsset FROM TagsAsset tagsAsset ");
820 
821                 if (obc != null) {
822                     query.append("ORDER BY ");
823 
824                     String[] orderByFields = obc.getOrderByFields();
825 
826                     for (int i = 0; i < orderByFields.length; i++) {
827                         query.append("tagsAsset.");
828                         query.append(orderByFields[i]);
829 
830                         if (obc.isAscending()) {
831                             query.append(" ASC");
832                         }
833                         else {
834                             query.append(" DESC");
835                         }
836 
837                         if ((i + 1) < orderByFields.length) {
838                             query.append(", ");
839                         }
840                     }
841                 }
842 
843                 Query q = session.createQuery(query.toString());
844 
845                 if (obc == null) {
846                     list = (List<TagsAsset>)QueryUtil.list(q, getDialect(),
847                             start, end, false);
848 
849                     Collections.sort(list);
850                 }
851                 else {
852                     list = (List<TagsAsset>)QueryUtil.list(q, getDialect(),
853                             start, end);
854                 }
855             }
856             catch (Exception e) {
857                 throw processException(e);
858             }
859             finally {
860                 if (list == null) {
861                     list = new ArrayList<TagsAsset>();
862                 }
863 
864                 cacheResult(list);
865 
866                 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
867 
868                 closeSession(session);
869             }
870         }
871 
872         return list;
873     }
874 
875     public void removeByCompanyId(long companyId) throws SystemException {
876         for (TagsAsset tagsAsset : findByCompanyId(companyId)) {
877             remove(tagsAsset);
878         }
879     }
880 
881     public void removeByC_C(long classNameId, long classPK)
882         throws NoSuchAssetException, SystemException {
883         TagsAsset tagsAsset = findByC_C(classNameId, classPK);
884 
885         remove(tagsAsset);
886     }
887 
888     public void removeAll() throws SystemException {
889         for (TagsAsset tagsAsset : findAll()) {
890             remove(tagsAsset);
891         }
892     }
893 
894     public int countByCompanyId(long companyId) throws SystemException {
895         Object[] finderArgs = new Object[] { new Long(companyId) };
896 
897         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
898                 finderArgs, this);
899 
900         if (count == null) {
901             Session session = null;
902 
903             try {
904                 session = openSession();
905 
906                 StringBuilder query = new StringBuilder();
907 
908                 query.append("SELECT COUNT(tagsAsset) ");
909                 query.append("FROM TagsAsset tagsAsset WHERE ");
910 
911                 query.append("tagsAsset.companyId = ?");
912 
913                 query.append(" ");
914 
915                 Query q = session.createQuery(query.toString());
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                 StringBuilder query = new StringBuilder();
957 
958                 query.append("SELECT COUNT(tagsAsset) ");
959                 query.append("FROM TagsAsset tagsAsset WHERE ");
960 
961                 query.append("tagsAsset.classNameId = ?");
962 
963                 query.append(" AND ");
964 
965                 query.append("tagsAsset.classPK = ?");
966 
967                 query.append(" ");
968 
969                 Query q = session.createQuery(query.toString());
970 
971                 QueryPos qPos = QueryPos.getInstance(q);
972 
973                 qPos.add(classNameId);
974 
975                 qPos.add(classPK);
976 
977                 count = (Long)q.uniqueResult();
978             }
979             catch (Exception e) {
980                 throw processException(e);
981             }
982             finally {
983                 if (count == null) {
984                     count = Long.valueOf(0);
985                 }
986 
987                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
988                     count);
989 
990                 closeSession(session);
991             }
992         }
993 
994         return count.intValue();
995     }
996 
997     public int countAll() throws SystemException {
998         Object[] finderArgs = new Object[0];
999 
1000        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1001                finderArgs, this);
1002
1003        if (count == null) {
1004            Session session = null;
1005
1006            try {
1007                session = openSession();
1008
1009                Query q = session.createQuery(
1010                        "SELECT COUNT(tagsAsset) FROM TagsAsset tagsAsset");
1011
1012                count = (Long)q.uniqueResult();
1013            }
1014            catch (Exception e) {
1015                throw processException(e);
1016            }
1017            finally {
1018                if (count == null) {
1019                    count = Long.valueOf(0);
1020                }
1021
1022                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1023                    count);
1024
1025                closeSession(session);
1026            }
1027        }
1028
1029        return count.intValue();
1030    }
1031
1032    public List<com.liferay.portlet.tags.model.TagsEntry> getTagsEntries(
1033        long pk) throws SystemException {
1034        return getTagsEntries(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1035    }
1036
1037    public List<com.liferay.portlet.tags.model.TagsEntry> getTagsEntries(
1038        long pk, int start, int end) throws SystemException {
1039        return getTagsEntries(pk, start, end, null);
1040    }
1041
1042    public static final FinderPath FINDER_PATH_GET_TAGSENTRIES = new FinderPath(com.liferay.portlet.tags.model.impl.TagsEntryModelImpl.ENTITY_CACHE_ENABLED,
1043            TagsAssetModelImpl.FINDER_CACHE_ENABLED_TAGSASSETS_TAGSENTRIES,
1044            "TagsAssets_TagsEntries", "getTagsEntries",
1045            new String[] {
1046                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1047                "com.liferay.portal.kernel.util.OrderByComparator"
1048            });
1049
1050    public List<com.liferay.portlet.tags.model.TagsEntry> getTagsEntries(
1051        long pk, int start, int end, OrderByComparator obc)
1052        throws SystemException {
1053        Object[] finderArgs = new Object[] {
1054                new Long(pk), String.valueOf(start), String.valueOf(end),
1055                String.valueOf(obc)
1056            };
1057
1058        List<com.liferay.portlet.tags.model.TagsEntry> list = (List<com.liferay.portlet.tags.model.TagsEntry>)FinderCacheUtil.getResult(FINDER_PATH_GET_TAGSENTRIES,
1059                finderArgs, this);
1060
1061        if (list == null) {
1062            Session session = null;
1063
1064            try {
1065                session = openSession();
1066
1067                StringBuilder sb = new StringBuilder();
1068
1069                sb.append(_SQL_GETTAGSENTRIES);
1070
1071                if (obc != null) {
1072                    sb.append("ORDER BY ");
1073                    sb.append(obc.getOrderBy());
1074                }
1075
1076                else {
1077                    sb.append("ORDER BY ");
1078
1079                    sb.append("TagsEntry.name ASC");
1080                }
1081
1082                String sql = sb.toString();
1083
1084                SQLQuery q = session.createSQLQuery(sql);
1085
1086                q.addEntity("TagsEntry",
1087                    com.liferay.portlet.tags.model.impl.TagsEntryImpl.class);
1088
1089                QueryPos qPos = QueryPos.getInstance(q);
1090
1091                qPos.add(pk);
1092
1093                list = (List<com.liferay.portlet.tags.model.TagsEntry>)QueryUtil.list(q,
1094                        getDialect(), start, end);
1095            }
1096            catch (Exception e) {
1097                throw processException(e);
1098            }
1099            finally {
1100                if (list == null) {
1101                    list = new ArrayList<com.liferay.portlet.tags.model.TagsEntry>();
1102                }
1103
1104                tagsEntryPersistence.cacheResult(list);
1105
1106                FinderCacheUtil.putResult(FINDER_PATH_GET_TAGSENTRIES,
1107                    finderArgs, list);
1108
1109                closeSession(session);
1110            }
1111        }
1112
1113        return list;
1114    }
1115
1116    public static final FinderPath FINDER_PATH_GET_TAGSENTRIES_SIZE = new FinderPath(com.liferay.portlet.tags.model.impl.TagsEntryModelImpl.ENTITY_CACHE_ENABLED,
1117            TagsAssetModelImpl.FINDER_CACHE_ENABLED_TAGSASSETS_TAGSENTRIES,
1118            "TagsAssets_TagsEntries", "getTagsEntriesSize",
1119            new String[] { Long.class.getName() });
1120
1121    public int getTagsEntriesSize(long pk) throws SystemException {
1122        Object[] finderArgs = new Object[] { new Long(pk) };
1123
1124        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_TAGSENTRIES_SIZE,
1125                finderArgs, this);
1126
1127        if (count == null) {
1128            Session session = null;
1129
1130            try {
1131                session = openSession();
1132
1133                SQLQuery q = session.createSQLQuery(_SQL_GETTAGSENTRIESSIZE);
1134
1135                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1136
1137                QueryPos qPos = QueryPos.getInstance(q);
1138
1139                qPos.add(pk);
1140
1141                count = (Long)q.uniqueResult();
1142            }
1143            catch (Exception e) {
1144                throw processException(e);
1145            }
1146            finally {
1147                if (count == null) {
1148                    count = Long.valueOf(0);
1149                }
1150
1151                FinderCacheUtil.putResult(FINDER_PATH_GET_TAGSENTRIES_SIZE,
1152                    finderArgs, count);
1153
1154                closeSession(session);
1155            }
1156        }
1157
1158        return count.intValue();
1159    }
1160
1161    public static final FinderPath FINDER_PATH_CONTAINS_TAGSENTRY = new FinderPath(com.liferay.portlet.tags.model.impl.TagsEntryModelImpl.ENTITY_CACHE_ENABLED,
1162            TagsAssetModelImpl.FINDER_CACHE_ENABLED_TAGSASSETS_TAGSENTRIES,
1163            "TagsAssets_TagsEntries", "containsTagsEntry",
1164            new String[] { Long.class.getName(), Long.class.getName() });
1165
1166    public boolean containsTagsEntry(long pk, long tagsEntryPK)
1167        throws SystemException {
1168        Object[] finderArgs = new Object[] { new Long(pk), new Long(tagsEntryPK) };
1169
1170        Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_TAGSENTRY,
1171                finderArgs, this);
1172
1173        if (value == null) {
1174            try {
1175                value = Boolean.valueOf(containsTagsEntry.contains(pk,
1176                            tagsEntryPK));
1177            }
1178            catch (Exception e) {
1179                throw processException(e);
1180            }
1181            finally {
1182                if (value == null) {
1183                    value = Boolean.FALSE;
1184                }
1185
1186                FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_TAGSENTRY,
1187                    finderArgs, value);
1188            }
1189        }
1190
1191        return value.booleanValue();
1192    }
1193
1194    public boolean containsTagsEntries(long pk) throws SystemException {
1195        if (getTagsEntriesSize(pk) > 0) {
1196            return true;
1197        }
1198        else {
1199            return false;
1200        }
1201    }
1202
1203    public void addTagsEntry(long pk, long tagsEntryPK)
1204        throws SystemException {
1205        try {
1206            addTagsEntry.add(pk, tagsEntryPK);
1207        }
1208        catch (Exception e) {
1209            throw processException(e);
1210        }
1211        finally {
1212            FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1213        }
1214    }
1215
1216    public void addTagsEntry(long pk,
1217        com.liferay.portlet.tags.model.TagsEntry tagsEntry)
1218        throws SystemException {
1219        try {
1220            addTagsEntry.add(pk, tagsEntry.getPrimaryKey());
1221        }
1222        catch (Exception e) {
1223            throw processException(e);
1224        }
1225        finally {
1226            FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1227        }
1228    }
1229
1230    public void addTagsEntries(long pk, long[] tagsEntryPKs)
1231        throws SystemException {
1232        try {
1233            for (long tagsEntryPK : tagsEntryPKs) {
1234                addTagsEntry.add(pk, tagsEntryPK);
1235            }
1236        }
1237        catch (Exception e) {
1238            throw processException(e);
1239        }
1240        finally {
1241            FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1242        }
1243    }
1244
1245    public void addTagsEntries(long pk,
1246        List<com.liferay.portlet.tags.model.TagsEntry> tagsEntries)
1247        throws SystemException {
1248        try {
1249            for (com.liferay.portlet.tags.model.TagsEntry tagsEntry : tagsEntries) {
1250                addTagsEntry.add(pk, tagsEntry.getPrimaryKey());
1251            }
1252        }
1253        catch (Exception e) {
1254            throw processException(e);
1255        }
1256        finally {
1257            FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1258        }
1259    }
1260
1261    public void clearTagsEntries(long pk) throws SystemException {
1262        try {
1263            clearTagsEntries.clear(pk);
1264        }
1265        catch (Exception e) {
1266            throw processException(e);
1267        }
1268        finally {
1269            FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1270        }
1271    }
1272
1273    public void removeTagsEntry(long pk, long tagsEntryPK)
1274        throws SystemException {
1275        try {
1276            removeTagsEntry.remove(pk, tagsEntryPK);
1277        }
1278        catch (Exception e) {
1279            throw processException(e);
1280        }
1281        finally {
1282            FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1283        }
1284    }
1285
1286    public void removeTagsEntry(long pk,
1287        com.liferay.portlet.tags.model.TagsEntry tagsEntry)
1288        throws SystemException {
1289        try {
1290            removeTagsEntry.remove(pk, tagsEntry.getPrimaryKey());
1291        }
1292        catch (Exception e) {
1293            throw processException(e);
1294        }
1295        finally {
1296            FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1297        }
1298    }
1299
1300    public void removeTagsEntries(long pk, long[] tagsEntryPKs)
1301        throws SystemException {
1302        try {
1303            for (long tagsEntryPK : tagsEntryPKs) {
1304                removeTagsEntry.remove(pk, tagsEntryPK);
1305            }
1306        }
1307        catch (Exception e) {
1308            throw processException(e);
1309        }
1310        finally {
1311            FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1312        }
1313    }
1314
1315    public void removeTagsEntries(long pk,
1316        List<com.liferay.portlet.tags.model.TagsEntry> tagsEntries)
1317        throws SystemException {
1318        try {
1319            for (com.liferay.portlet.tags.model.TagsEntry tagsEntry : tagsEntries) {
1320                removeTagsEntry.remove(pk, tagsEntry.getPrimaryKey());
1321            }
1322        }
1323        catch (Exception e) {
1324            throw processException(e);
1325        }
1326        finally {
1327            FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1328        }
1329    }
1330
1331    public void setTagsEntries(long pk, long[] tagsEntryPKs)
1332        throws SystemException {
1333        try {
1334            Set<Long> tagsEntryPKSet = SetUtil.fromArray(tagsEntryPKs);
1335
1336            List<com.liferay.portlet.tags.model.TagsEntry> tagsEntries = getTagsEntries(pk);
1337
1338            for (com.liferay.portlet.tags.model.TagsEntry tagsEntry : tagsEntries) {
1339                if (!tagsEntryPKSet.contains(tagsEntry.getPrimaryKey())) {
1340                    removeTagsEntry.remove(pk, tagsEntry.getPrimaryKey());
1341                }
1342                else {
1343                    tagsEntryPKSet.remove(tagsEntry.getPrimaryKey());
1344                }
1345            }
1346
1347            for (Long tagsEntryPK : tagsEntryPKSet) {
1348                addTagsEntry.add(pk, tagsEntryPK);
1349            }
1350        }
1351        catch (Exception e) {
1352            throw processException(e);
1353        }
1354        finally {
1355            FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1356        }
1357    }
1358
1359    public void setTagsEntries(long pk,
1360        List<com.liferay.portlet.tags.model.TagsEntry> tagsEntries)
1361        throws SystemException {
1362        try {
1363            long[] tagsEntryPKs = new long[tagsEntries.size()];
1364
1365            for (int i = 0; i < tagsEntries.size(); i++) {
1366                com.liferay.portlet.tags.model.TagsEntry tagsEntry = tagsEntries.get(i);
1367
1368                tagsEntryPKs[i] = tagsEntry.getPrimaryKey();
1369            }
1370
1371            setTagsEntries(pk, tagsEntryPKs);
1372        }
1373        catch (Exception e) {
1374            throw processException(e);
1375        }
1376        finally {
1377            FinderCacheUtil.clearCache("TagsAssets_TagsEntries");
1378        }
1379    }
1380
1381    public void afterPropertiesSet() {
1382        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1383                    com.liferay.portal.util.PropsUtil.get(
1384                        "value.object.listener.com.liferay.portlet.tags.model.TagsAsset")));
1385
1386        if (listenerClassNames.length > 0) {
1387            try {
1388                List<ModelListener<TagsAsset>> listenersList = new ArrayList<ModelListener<TagsAsset>>();
1389
1390                for (String listenerClassName : listenerClassNames) {
1391                    listenersList.add((ModelListener<TagsAsset>)Class.forName(
1392                            listenerClassName).newInstance());
1393                }
1394
1395                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1396            }
1397            catch (Exception e) {
1398                _log.error(e);
1399            }
1400        }
1401
1402        containsTagsEntry = new ContainsTagsEntry(this);
1403
1404        addTagsEntry = new AddTagsEntry(this);
1405        clearTagsEntries = new ClearTagsEntries(this);
1406        removeTagsEntry = new RemoveTagsEntry(this);
1407    }
1408
1409    @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsAssetPersistence.impl")
1410    protected com.liferay.portlet.tags.service.persistence.TagsAssetPersistence tagsAssetPersistence;
1411    @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsEntryPersistence.impl")
1412    protected com.liferay.portlet.tags.service.persistence.TagsEntryPersistence tagsEntryPersistence;
1413    @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsPropertyPersistence.impl")
1414    protected com.liferay.portlet.tags.service.persistence.TagsPropertyPersistence tagsPropertyPersistence;
1415    @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsSourcePersistence.impl")
1416    protected com.liferay.portlet.tags.service.persistence.TagsSourcePersistence tagsSourcePersistence;
1417    @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
1418    protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
1419    @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
1420    protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
1421    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1422    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1423    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1424    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1425    @BeanReference(name = "com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence.impl")
1426    protected com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence blogsEntryPersistence;
1427    @BeanReference(name = "com.liferay.portlet.bookmarks.service.persistence.BookmarksEntryPersistence.impl")
1428    protected com.liferay.portlet.bookmarks.service.persistence.BookmarksEntryPersistence bookmarksEntryPersistence;
1429    @BeanReference(name = "com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryPersistence.impl")
1430    protected com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryPersistence dlFileEntryPersistence;
1431    @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalArticlePersistence.impl")
1432    protected com.liferay.portlet.journal.service.persistence.JournalArticlePersistence journalArticlePersistence;
1433    @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalArticleResourcePersistence.impl")
1434    protected com.liferay.portlet.journal.service.persistence.JournalArticleResourcePersistence journalArticleResourcePersistence;
1435    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence.impl")
1436    protected com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence mbMessagePersistence;
1437    @BeanReference(name = "com.liferay.portlet.wiki.service.persistence.WikiPagePersistence.impl")
1438    protected com.liferay.portlet.wiki.service.persistence.WikiPagePersistence wikiPagePersistence;
1439    @BeanReference(name = "com.liferay.portlet.wiki.service.persistence.WikiPageResourcePersistence.impl")
1440    protected com.liferay.portlet.wiki.service.persistence.WikiPageResourcePersistence wikiPageResourcePersistence;
1441    protected ContainsTagsEntry containsTagsEntry;
1442    protected AddTagsEntry addTagsEntry;
1443    protected ClearTagsEntries clearTagsEntries;
1444    protected RemoveTagsEntry removeTagsEntry;
1445
1446    protected class ContainsTagsEntry {
1447        protected ContainsTagsEntry(TagsAssetPersistenceImpl persistenceImpl) {
1448            super();
1449
1450            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
1451                    _SQL_CONTAINSTAGSENTRY,
1452                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
1453        }
1454
1455        protected boolean contains(long assetId, long entryId) {
1456            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
1457                        new Long(assetId), new Long(entryId)
1458                    });
1459
1460            if (results.size() > 0) {
1461                Integer count = results.get(0);
1462
1463                if (count.intValue() > 0) {
1464                    return true;
1465                }
1466            }
1467
1468            return false;
1469        }
1470
1471        private MappingSqlQuery _mappingSqlQuery;
1472    }
1473
1474    protected class AddTagsEntry {
1475        protected AddTagsEntry(TagsAssetPersistenceImpl persistenceImpl) {
1476            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1477                    "INSERT INTO TagsAssets_TagsEntries (assetId, entryId) VALUES (?, ?)",
1478                    new int[] { Types.BIGINT, Types.BIGINT });
1479            _persistenceImpl = persistenceImpl;
1480        }
1481
1482        protected void add(long assetId, long entryId) {
1483            if (!_persistenceImpl.containsTagsEntry.contains(assetId, entryId)) {
1484                _sqlUpdate.update(new Object[] {
1485                        new Long(assetId), new Long(entryId)
1486                    });
1487            }
1488        }
1489
1490        private SqlUpdate _sqlUpdate;
1491        private TagsAssetPersistenceImpl _persistenceImpl;
1492    }
1493
1494    protected class ClearTagsEntries {
1495        protected ClearTagsEntries(TagsAssetPersistenceImpl persistenceImpl) {
1496            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1497                    "DELETE FROM TagsAssets_TagsEntries WHERE assetId = ?",
1498                    new int[] { Types.BIGINT });
1499        }
1500
1501        protected void clear(long assetId) {
1502            _sqlUpdate.update(new Object[] { new Long(assetId) });
1503        }
1504
1505        private SqlUpdate _sqlUpdate;
1506    }
1507
1508    protected class RemoveTagsEntry {
1509        protected RemoveTagsEntry(TagsAssetPersistenceImpl persistenceImpl) {
1510            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1511                    "DELETE FROM TagsAssets_TagsEntries WHERE assetId = ? AND entryId = ?",
1512                    new int[] { Types.BIGINT, Types.BIGINT });
1513        }
1514
1515        protected void remove(long assetId, long entryId) {
1516            _sqlUpdate.update(new Object[] { new Long(assetId), new Long(
1517                        entryId) });
1518        }
1519
1520        private SqlUpdate _sqlUpdate;
1521    }
1522
1523    private static final String _SQL_GETTAGSENTRIES = "SELECT {TagsEntry.*} FROM TagsEntry INNER JOIN TagsAssets_TagsEntries ON (TagsAssets_TagsEntries.entryId = TagsEntry.entryId) WHERE (TagsAssets_TagsEntries.assetId = ?)";
1524    private static final String _SQL_GETTAGSENTRIESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM TagsAssets_TagsEntries WHERE assetId = ?";
1525    private static final String _SQL_CONTAINSTAGSENTRY = "SELECT COUNT(*) AS COUNT_VALUE FROM TagsAssets_TagsEntries WHERE assetId = ? AND entryId = ?";
1526    private static Log _log = LogFactoryUtil.getLog(TagsAssetPersistenceImpl.class);
1527}