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