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