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