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