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