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