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.expando.service.persistence;
24  
25  import com.liferay.portal.SystemException;
26  import com.liferay.portal.kernel.bean.InitializingBean;
27  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
28  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
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.util.GetterUtil;
34  import com.liferay.portal.kernel.util.ListUtil;
35  import com.liferay.portal.kernel.util.OrderByComparator;
36  import com.liferay.portal.kernel.util.StringPool;
37  import com.liferay.portal.kernel.util.StringUtil;
38  import com.liferay.portal.model.ModelListener;
39  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
40  
41  import com.liferay.portlet.expando.NoSuchValueException;
42  import com.liferay.portlet.expando.model.ExpandoValue;
43  import com.liferay.portlet.expando.model.impl.ExpandoValueImpl;
44  import com.liferay.portlet.expando.model.impl.ExpandoValueModelImpl;
45  
46  import org.apache.commons.logging.Log;
47  import org.apache.commons.logging.LogFactory;
48  
49  import java.util.ArrayList;
50  import java.util.Collections;
51  import java.util.Iterator;
52  import java.util.List;
53  
54  /**
55   * <a href="ExpandoValuePersistenceImpl.java.html"><b><i>View Source</i></b></a>
56   *
57   * @author Brian Wing Shun Chan
58   *
59   */
60  public class ExpandoValuePersistenceImpl extends BasePersistenceImpl
61      implements ExpandoValuePersistence, InitializingBean {
62      public ExpandoValue create(long valueId) {
63          ExpandoValue expandoValue = new ExpandoValueImpl();
64  
65          expandoValue.setNew(true);
66          expandoValue.setPrimaryKey(valueId);
67  
68          return expandoValue;
69      }
70  
71      public ExpandoValue remove(long valueId)
72          throws NoSuchValueException, SystemException {
73          Session session = null;
74  
75          try {
76              session = openSession();
77  
78              ExpandoValue expandoValue = (ExpandoValue)session.get(ExpandoValueImpl.class,
79                      new Long(valueId));
80  
81              if (expandoValue == null) {
82                  if (_log.isWarnEnabled()) {
83                      _log.warn("No ExpandoValue exists with the primary key " +
84                          valueId);
85                  }
86  
87                  throw new NoSuchValueException(
88                      "No ExpandoValue exists with the primary key " + valueId);
89              }
90  
91              return remove(expandoValue);
92          }
93          catch (NoSuchValueException nsee) {
94              throw nsee;
95          }
96          catch (Exception e) {
97              throw processException(e);
98          }
99          finally {
100             closeSession(session);
101         }
102     }
103 
104     public ExpandoValue remove(ExpandoValue expandoValue)
105         throws SystemException {
106         if (_listeners.length > 0) {
107             for (ModelListener listener : _listeners) {
108                 listener.onBeforeRemove(expandoValue);
109             }
110         }
111 
112         expandoValue = removeImpl(expandoValue);
113 
114         if (_listeners.length > 0) {
115             for (ModelListener listener : _listeners) {
116                 listener.onAfterRemove(expandoValue);
117             }
118         }
119 
120         return expandoValue;
121     }
122 
123     protected ExpandoValue removeImpl(ExpandoValue expandoValue)
124         throws SystemException {
125         Session session = null;
126 
127         try {
128             session = openSession();
129 
130             session.delete(expandoValue);
131 
132             session.flush();
133 
134             return expandoValue;
135         }
136         catch (Exception e) {
137             throw processException(e);
138         }
139         finally {
140             closeSession(session);
141 
142             FinderCacheUtil.clearCache(ExpandoValue.class.getName());
143         }
144     }
145 
146     /**
147      * @deprecated Use <code>update(ExpandoValue expandoValue, boolean merge)</code>.
148      */
149     public ExpandoValue update(ExpandoValue expandoValue)
150         throws SystemException {
151         if (_log.isWarnEnabled()) {
152             _log.warn(
153                 "Using the deprecated update(ExpandoValue expandoValue) method. Use update(ExpandoValue expandoValue, boolean merge) instead.");
154         }
155 
156         return update(expandoValue, 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        expandoValue 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 expandoValue 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 ExpandoValue update(ExpandoValue expandoValue, boolean merge)
173         throws SystemException {
174         boolean isNew = expandoValue.isNew();
175 
176         if (_listeners.length > 0) {
177             for (ModelListener listener : _listeners) {
178                 if (isNew) {
179                     listener.onBeforeCreate(expandoValue);
180                 }
181                 else {
182                     listener.onBeforeUpdate(expandoValue);
183                 }
184             }
185         }
186 
187         expandoValue = updateImpl(expandoValue, merge);
188 
189         if (_listeners.length > 0) {
190             for (ModelListener listener : _listeners) {
191                 if (isNew) {
192                     listener.onAfterCreate(expandoValue);
193                 }
194                 else {
195                     listener.onAfterUpdate(expandoValue);
196                 }
197             }
198         }
199 
200         return expandoValue;
201     }
202 
203     public ExpandoValue updateImpl(
204         com.liferay.portlet.expando.model.ExpandoValue expandoValue,
205         boolean merge) throws SystemException {
206         Session session = null;
207 
208         try {
209             session = openSession();
210 
211             if (merge) {
212                 session.merge(expandoValue);
213             }
214             else {
215                 if (expandoValue.isNew()) {
216                     session.save(expandoValue);
217                 }
218             }
219 
220             session.flush();
221 
222             expandoValue.setNew(false);
223 
224             return expandoValue;
225         }
226         catch (Exception e) {
227             throw processException(e);
228         }
229         finally {
230             closeSession(session);
231 
232             FinderCacheUtil.clearCache(ExpandoValue.class.getName());
233         }
234     }
235 
236     public ExpandoValue findByPrimaryKey(long valueId)
237         throws NoSuchValueException, SystemException {
238         ExpandoValue expandoValue = fetchByPrimaryKey(valueId);
239 
240         if (expandoValue == null) {
241             if (_log.isWarnEnabled()) {
242                 _log.warn("No ExpandoValue exists with the primary key " +
243                     valueId);
244             }
245 
246             throw new NoSuchValueException(
247                 "No ExpandoValue exists with the primary key " + valueId);
248         }
249 
250         return expandoValue;
251     }
252 
253     public ExpandoValue fetchByPrimaryKey(long valueId)
254         throws SystemException {
255         Session session = null;
256 
257         try {
258             session = openSession();
259 
260             return (ExpandoValue)session.get(ExpandoValueImpl.class,
261                 new Long(valueId));
262         }
263         catch (Exception e) {
264             throw processException(e);
265         }
266         finally {
267             closeSession(session);
268         }
269     }
270 
271     public List<ExpandoValue> findByTableId(long tableId)
272         throws SystemException {
273         boolean finderClassNameCacheEnabled = ExpandoValueModelImpl.CACHE_ENABLED;
274         String finderClassName = ExpandoValue.class.getName();
275         String finderMethodName = "findByTableId";
276         String[] finderParams = new String[] { Long.class.getName() };
277         Object[] finderArgs = new Object[] { new Long(tableId) };
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.expando.model.ExpandoValue WHERE ");
296 
297                 query.append("tableId = ?");
298 
299                 query.append(" ");
300 
301                 query.append("ORDER BY ");
302 
303                 query.append("tableId ASC, ");
304                 query.append("rowId_ ASC, ");
305                 query.append("columnId ASC");
306 
307                 Query q = session.createQuery(query.toString());
308 
309                 QueryPos qPos = QueryPos.getInstance(q);
310 
311                 qPos.add(tableId);
312 
313                 List<ExpandoValue> list = q.list();
314 
315                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
316                     finderClassName, finderMethodName, finderParams,
317                     finderArgs, list);
318 
319                 return list;
320             }
321             catch (Exception e) {
322                 throw processException(e);
323             }
324             finally {
325                 closeSession(session);
326             }
327         }
328         else {
329             return (List<ExpandoValue>)result;
330         }
331     }
332 
333     public List<ExpandoValue> findByTableId(long tableId, int start, int end)
334         throws SystemException {
335         return findByTableId(tableId, start, end, null);
336     }
337 
338     public List<ExpandoValue> findByTableId(long tableId, int start, int end,
339         OrderByComparator obc) throws SystemException {
340         boolean finderClassNameCacheEnabled = ExpandoValueModelImpl.CACHE_ENABLED;
341         String finderClassName = ExpandoValue.class.getName();
342         String finderMethodName = "findByTableId";
343         String[] finderParams = new String[] {
344                 Long.class.getName(),
345                 
346                 "java.lang.Integer", "java.lang.Integer",
347                 "com.liferay.portal.kernel.util.OrderByComparator"
348             };
349         Object[] finderArgs = new Object[] {
350                 new Long(tableId),
351                 
352                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
353             };
354 
355         Object result = null;
356 
357         if (finderClassNameCacheEnabled) {
358             result = FinderCacheUtil.getResult(finderClassName,
359                     finderMethodName, finderParams, finderArgs, this);
360         }
361 
362         if (result == null) {
363             Session session = null;
364 
365             try {
366                 session = openSession();
367 
368                 StringBuilder query = new StringBuilder();
369 
370                 query.append(
371                     "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
372 
373                 query.append("tableId = ?");
374 
375                 query.append(" ");
376 
377                 if (obc != null) {
378                     query.append("ORDER BY ");
379                     query.append(obc.getOrderBy());
380                 }
381 
382                 else {
383                     query.append("ORDER BY ");
384 
385                     query.append("tableId ASC, ");
386                     query.append("rowId_ ASC, ");
387                     query.append("columnId ASC");
388                 }
389 
390                 Query q = session.createQuery(query.toString());
391 
392                 QueryPos qPos = QueryPos.getInstance(q);
393 
394                 qPos.add(tableId);
395 
396                 List<ExpandoValue> list = (List<ExpandoValue>)QueryUtil.list(q,
397                         getDialect(), start, end);
398 
399                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
400                     finderClassName, finderMethodName, finderParams,
401                     finderArgs, list);
402 
403                 return list;
404             }
405             catch (Exception e) {
406                 throw processException(e);
407             }
408             finally {
409                 closeSession(session);
410             }
411         }
412         else {
413             return (List<ExpandoValue>)result;
414         }
415     }
416 
417     public ExpandoValue findByTableId_First(long tableId, OrderByComparator obc)
418         throws NoSuchValueException, SystemException {
419         List<ExpandoValue> list = findByTableId(tableId, 0, 1, obc);
420 
421         if (list.size() == 0) {
422             StringBuilder msg = new StringBuilder();
423 
424             msg.append("No ExpandoValue exists with the key {");
425 
426             msg.append("tableId=" + tableId);
427 
428             msg.append(StringPool.CLOSE_CURLY_BRACE);
429 
430             throw new NoSuchValueException(msg.toString());
431         }
432         else {
433             return list.get(0);
434         }
435     }
436 
437     public ExpandoValue findByTableId_Last(long tableId, OrderByComparator obc)
438         throws NoSuchValueException, SystemException {
439         int count = countByTableId(tableId);
440 
441         List<ExpandoValue> list = findByTableId(tableId, count - 1, count, obc);
442 
443         if (list.size() == 0) {
444             StringBuilder msg = new StringBuilder();
445 
446             msg.append("No ExpandoValue exists with the key {");
447 
448             msg.append("tableId=" + tableId);
449 
450             msg.append(StringPool.CLOSE_CURLY_BRACE);
451 
452             throw new NoSuchValueException(msg.toString());
453         }
454         else {
455             return list.get(0);
456         }
457     }
458 
459     public ExpandoValue[] findByTableId_PrevAndNext(long valueId, long tableId,
460         OrderByComparator obc) throws NoSuchValueException, SystemException {
461         ExpandoValue expandoValue = findByPrimaryKey(valueId);
462 
463         int count = countByTableId(tableId);
464 
465         Session session = null;
466 
467         try {
468             session = openSession();
469 
470             StringBuilder query = new StringBuilder();
471 
472             query.append(
473                 "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
474 
475             query.append("tableId = ?");
476 
477             query.append(" ");
478 
479             if (obc != null) {
480                 query.append("ORDER BY ");
481                 query.append(obc.getOrderBy());
482             }
483 
484             else {
485                 query.append("ORDER BY ");
486 
487                 query.append("tableId ASC, ");
488                 query.append("rowId_ ASC, ");
489                 query.append("columnId ASC");
490             }
491 
492             Query q = session.createQuery(query.toString());
493 
494             QueryPos qPos = QueryPos.getInstance(q);
495 
496             qPos.add(tableId);
497 
498             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
499                     expandoValue);
500 
501             ExpandoValue[] array = new ExpandoValueImpl[3];
502 
503             array[0] = (ExpandoValue)objArray[0];
504             array[1] = (ExpandoValue)objArray[1];
505             array[2] = (ExpandoValue)objArray[2];
506 
507             return array;
508         }
509         catch (Exception e) {
510             throw processException(e);
511         }
512         finally {
513             closeSession(session);
514         }
515     }
516 
517     public List<ExpandoValue> findByColumnId(long columnId)
518         throws SystemException {
519         boolean finderClassNameCacheEnabled = ExpandoValueModelImpl.CACHE_ENABLED;
520         String finderClassName = ExpandoValue.class.getName();
521         String finderMethodName = "findByColumnId";
522         String[] finderParams = new String[] { Long.class.getName() };
523         Object[] finderArgs = new Object[] { new Long(columnId) };
524 
525         Object result = null;
526 
527         if (finderClassNameCacheEnabled) {
528             result = FinderCacheUtil.getResult(finderClassName,
529                     finderMethodName, finderParams, finderArgs, this);
530         }
531 
532         if (result == null) {
533             Session session = null;
534 
535             try {
536                 session = openSession();
537 
538                 StringBuilder query = new StringBuilder();
539 
540                 query.append(
541                     "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
542 
543                 query.append("columnId = ?");
544 
545                 query.append(" ");
546 
547                 query.append("ORDER BY ");
548 
549                 query.append("tableId ASC, ");
550                 query.append("rowId_ ASC, ");
551                 query.append("columnId ASC");
552 
553                 Query q = session.createQuery(query.toString());
554 
555                 QueryPos qPos = QueryPos.getInstance(q);
556 
557                 qPos.add(columnId);
558 
559                 List<ExpandoValue> list = q.list();
560 
561                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
562                     finderClassName, finderMethodName, finderParams,
563                     finderArgs, list);
564 
565                 return list;
566             }
567             catch (Exception e) {
568                 throw processException(e);
569             }
570             finally {
571                 closeSession(session);
572             }
573         }
574         else {
575             return (List<ExpandoValue>)result;
576         }
577     }
578 
579     public List<ExpandoValue> findByColumnId(long columnId, int start, int end)
580         throws SystemException {
581         return findByColumnId(columnId, start, end, null);
582     }
583 
584     public List<ExpandoValue> findByColumnId(long columnId, int start, int end,
585         OrderByComparator obc) throws SystemException {
586         boolean finderClassNameCacheEnabled = ExpandoValueModelImpl.CACHE_ENABLED;
587         String finderClassName = ExpandoValue.class.getName();
588         String finderMethodName = "findByColumnId";
589         String[] finderParams = new String[] {
590                 Long.class.getName(),
591                 
592                 "java.lang.Integer", "java.lang.Integer",
593                 "com.liferay.portal.kernel.util.OrderByComparator"
594             };
595         Object[] finderArgs = new Object[] {
596                 new Long(columnId),
597                 
598                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
599             };
600 
601         Object result = null;
602 
603         if (finderClassNameCacheEnabled) {
604             result = FinderCacheUtil.getResult(finderClassName,
605                     finderMethodName, finderParams, finderArgs, this);
606         }
607 
608         if (result == null) {
609             Session session = null;
610 
611             try {
612                 session = openSession();
613 
614                 StringBuilder query = new StringBuilder();
615 
616                 query.append(
617                     "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
618 
619                 query.append("columnId = ?");
620 
621                 query.append(" ");
622 
623                 if (obc != null) {
624                     query.append("ORDER BY ");
625                     query.append(obc.getOrderBy());
626                 }
627 
628                 else {
629                     query.append("ORDER BY ");
630 
631                     query.append("tableId ASC, ");
632                     query.append("rowId_ ASC, ");
633                     query.append("columnId ASC");
634                 }
635 
636                 Query q = session.createQuery(query.toString());
637 
638                 QueryPos qPos = QueryPos.getInstance(q);
639 
640                 qPos.add(columnId);
641 
642                 List<ExpandoValue> list = (List<ExpandoValue>)QueryUtil.list(q,
643                         getDialect(), start, end);
644 
645                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
646                     finderClassName, finderMethodName, finderParams,
647                     finderArgs, list);
648 
649                 return list;
650             }
651             catch (Exception e) {
652                 throw processException(e);
653             }
654             finally {
655                 closeSession(session);
656             }
657         }
658         else {
659             return (List<ExpandoValue>)result;
660         }
661     }
662 
663     public ExpandoValue findByColumnId_First(long columnId,
664         OrderByComparator obc) throws NoSuchValueException, SystemException {
665         List<ExpandoValue> list = findByColumnId(columnId, 0, 1, obc);
666 
667         if (list.size() == 0) {
668             StringBuilder msg = new StringBuilder();
669 
670             msg.append("No ExpandoValue exists with the key {");
671 
672             msg.append("columnId=" + columnId);
673 
674             msg.append(StringPool.CLOSE_CURLY_BRACE);
675 
676             throw new NoSuchValueException(msg.toString());
677         }
678         else {
679             return list.get(0);
680         }
681     }
682 
683     public ExpandoValue findByColumnId_Last(long columnId, OrderByComparator obc)
684         throws NoSuchValueException, SystemException {
685         int count = countByColumnId(columnId);
686 
687         List<ExpandoValue> list = findByColumnId(columnId, count - 1, count, obc);
688 
689         if (list.size() == 0) {
690             StringBuilder msg = new StringBuilder();
691 
692             msg.append("No ExpandoValue exists with the key {");
693 
694             msg.append("columnId=" + columnId);
695 
696             msg.append(StringPool.CLOSE_CURLY_BRACE);
697 
698             throw new NoSuchValueException(msg.toString());
699         }
700         else {
701             return list.get(0);
702         }
703     }
704 
705     public ExpandoValue[] findByColumnId_PrevAndNext(long valueId,
706         long columnId, OrderByComparator obc)
707         throws NoSuchValueException, SystemException {
708         ExpandoValue expandoValue = findByPrimaryKey(valueId);
709 
710         int count = countByColumnId(columnId);
711 
712         Session session = null;
713 
714         try {
715             session = openSession();
716 
717             StringBuilder query = new StringBuilder();
718 
719             query.append(
720                 "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
721 
722             query.append("columnId = ?");
723 
724             query.append(" ");
725 
726             if (obc != null) {
727                 query.append("ORDER BY ");
728                 query.append(obc.getOrderBy());
729             }
730 
731             else {
732                 query.append("ORDER BY ");
733 
734                 query.append("tableId ASC, ");
735                 query.append("rowId_ ASC, ");
736                 query.append("columnId ASC");
737             }
738 
739             Query q = session.createQuery(query.toString());
740 
741             QueryPos qPos = QueryPos.getInstance(q);
742 
743             qPos.add(columnId);
744 
745             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
746                     expandoValue);
747 
748             ExpandoValue[] array = new ExpandoValueImpl[3];
749 
750             array[0] = (ExpandoValue)objArray[0];
751             array[1] = (ExpandoValue)objArray[1];
752             array[2] = (ExpandoValue)objArray[2];
753 
754             return array;
755         }
756         catch (Exception e) {
757             throw processException(e);
758         }
759         finally {
760             closeSession(session);
761         }
762     }
763 
764     public List<ExpandoValue> findByRowId(long rowId) throws SystemException {
765         boolean finderClassNameCacheEnabled = ExpandoValueModelImpl.CACHE_ENABLED;
766         String finderClassName = ExpandoValue.class.getName();
767         String finderMethodName = "findByRowId";
768         String[] finderParams = new String[] { Long.class.getName() };
769         Object[] finderArgs = new Object[] { new Long(rowId) };
770 
771         Object result = null;
772 
773         if (finderClassNameCacheEnabled) {
774             result = FinderCacheUtil.getResult(finderClassName,
775                     finderMethodName, finderParams, finderArgs, this);
776         }
777 
778         if (result == null) {
779             Session session = null;
780 
781             try {
782                 session = openSession();
783 
784                 StringBuilder query = new StringBuilder();
785 
786                 query.append(
787                     "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
788 
789                 query.append("rowId_ = ?");
790 
791                 query.append(" ");
792 
793                 query.append("ORDER BY ");
794 
795                 query.append("tableId ASC, ");
796                 query.append("rowId_ ASC, ");
797                 query.append("columnId ASC");
798 
799                 Query q = session.createQuery(query.toString());
800 
801                 QueryPos qPos = QueryPos.getInstance(q);
802 
803                 qPos.add(rowId);
804 
805                 List<ExpandoValue> list = q.list();
806 
807                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
808                     finderClassName, finderMethodName, finderParams,
809                     finderArgs, list);
810 
811                 return list;
812             }
813             catch (Exception e) {
814                 throw processException(e);
815             }
816             finally {
817                 closeSession(session);
818             }
819         }
820         else {
821             return (List<ExpandoValue>)result;
822         }
823     }
824 
825     public List<ExpandoValue> findByRowId(long rowId, int start, int end)
826         throws SystemException {
827         return findByRowId(rowId, start, end, null);
828     }
829 
830     public List<ExpandoValue> findByRowId(long rowId, int start, int end,
831         OrderByComparator obc) throws SystemException {
832         boolean finderClassNameCacheEnabled = ExpandoValueModelImpl.CACHE_ENABLED;
833         String finderClassName = ExpandoValue.class.getName();
834         String finderMethodName = "findByRowId";
835         String[] finderParams = new String[] {
836                 Long.class.getName(),
837                 
838                 "java.lang.Integer", "java.lang.Integer",
839                 "com.liferay.portal.kernel.util.OrderByComparator"
840             };
841         Object[] finderArgs = new Object[] {
842                 new Long(rowId),
843                 
844                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
845             };
846 
847         Object result = null;
848 
849         if (finderClassNameCacheEnabled) {
850             result = FinderCacheUtil.getResult(finderClassName,
851                     finderMethodName, finderParams, finderArgs, this);
852         }
853 
854         if (result == null) {
855             Session session = null;
856 
857             try {
858                 session = openSession();
859 
860                 StringBuilder query = new StringBuilder();
861 
862                 query.append(
863                     "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
864 
865                 query.append("rowId_ = ?");
866 
867                 query.append(" ");
868 
869                 if (obc != null) {
870                     query.append("ORDER BY ");
871                     query.append(obc.getOrderBy());
872                 }
873 
874                 else {
875                     query.append("ORDER BY ");
876 
877                     query.append("tableId ASC, ");
878                     query.append("rowId_ ASC, ");
879                     query.append("columnId ASC");
880                 }
881 
882                 Query q = session.createQuery(query.toString());
883 
884                 QueryPos qPos = QueryPos.getInstance(q);
885 
886                 qPos.add(rowId);
887 
888                 List<ExpandoValue> list = (List<ExpandoValue>)QueryUtil.list(q,
889                         getDialect(), start, end);
890 
891                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
892                     finderClassName, finderMethodName, finderParams,
893                     finderArgs, list);
894 
895                 return list;
896             }
897             catch (Exception e) {
898                 throw processException(e);
899             }
900             finally {
901                 closeSession(session);
902             }
903         }
904         else {
905             return (List<ExpandoValue>)result;
906         }
907     }
908 
909     public ExpandoValue findByRowId_First(long rowId, OrderByComparator obc)
910         throws NoSuchValueException, SystemException {
911         List<ExpandoValue> list = findByRowId(rowId, 0, 1, obc);
912 
913         if (list.size() == 0) {
914             StringBuilder msg = new StringBuilder();
915 
916             msg.append("No ExpandoValue exists with the key {");
917 
918             msg.append("rowId=" + rowId);
919 
920             msg.append(StringPool.CLOSE_CURLY_BRACE);
921 
922             throw new NoSuchValueException(msg.toString());
923         }
924         else {
925             return list.get(0);
926         }
927     }
928 
929     public ExpandoValue findByRowId_Last(long rowId, OrderByComparator obc)
930         throws NoSuchValueException, SystemException {
931         int count = countByRowId(rowId);
932 
933         List<ExpandoValue> list = findByRowId(rowId, count - 1, count, obc);
934 
935         if (list.size() == 0) {
936             StringBuilder msg = new StringBuilder();
937 
938             msg.append("No ExpandoValue exists with the key {");
939 
940             msg.append("rowId=" + rowId);
941 
942             msg.append(StringPool.CLOSE_CURLY_BRACE);
943 
944             throw new NoSuchValueException(msg.toString());
945         }
946         else {
947             return list.get(0);
948         }
949     }
950 
951     public ExpandoValue[] findByRowId_PrevAndNext(long valueId, long rowId,
952         OrderByComparator obc) throws NoSuchValueException, SystemException {
953         ExpandoValue expandoValue = findByPrimaryKey(valueId);
954 
955         int count = countByRowId(rowId);
956 
957         Session session = null;
958 
959         try {
960             session = openSession();
961 
962             StringBuilder query = new StringBuilder();
963 
964             query.append(
965                 "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
966 
967             query.append("rowId_ = ?");
968 
969             query.append(" ");
970 
971             if (obc != null) {
972                 query.append("ORDER BY ");
973                 query.append(obc.getOrderBy());
974             }
975 
976             else {
977                 query.append("ORDER BY ");
978 
979                 query.append("tableId ASC, ");
980                 query.append("rowId_ ASC, ");
981                 query.append("columnId ASC");
982             }
983 
984             Query q = session.createQuery(query.toString());
985 
986             QueryPos qPos = QueryPos.getInstance(q);
987 
988             qPos.add(rowId);
989 
990             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
991                     expandoValue);
992 
993             ExpandoValue[] array = new ExpandoValueImpl[3];
994 
995             array[0] = (ExpandoValue)objArray[0];
996             array[1] = (ExpandoValue)objArray[1];
997             array[2] = (ExpandoValue)objArray[2];
998 
999             return array;
1000        }
1001        catch (Exception e) {
1002            throw processException(e);
1003        }
1004        finally {
1005            closeSession(session);
1006        }
1007    }
1008
1009    public List<ExpandoValue> findByT_R(long tableId, long rowId)
1010        throws SystemException {
1011        boolean finderClassNameCacheEnabled = ExpandoValueModelImpl.CACHE_ENABLED;
1012        String finderClassName = ExpandoValue.class.getName();
1013        String finderMethodName = "findByT_R";
1014        String[] finderParams = new String[] {
1015                Long.class.getName(), Long.class.getName()
1016            };
1017        Object[] finderArgs = new Object[] { new Long(tableId), new Long(rowId) };
1018
1019        Object result = null;
1020
1021        if (finderClassNameCacheEnabled) {
1022            result = FinderCacheUtil.getResult(finderClassName,
1023                    finderMethodName, finderParams, finderArgs, this);
1024        }
1025
1026        if (result == null) {
1027            Session session = null;
1028
1029            try {
1030                session = openSession();
1031
1032                StringBuilder query = new StringBuilder();
1033
1034                query.append(
1035                    "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
1036
1037                query.append("tableId = ?");
1038
1039                query.append(" AND ");
1040
1041                query.append("rowId_ = ?");
1042
1043                query.append(" ");
1044
1045                query.append("ORDER BY ");
1046
1047                query.append("tableId ASC, ");
1048                query.append("rowId_ ASC, ");
1049                query.append("columnId ASC");
1050
1051                Query q = session.createQuery(query.toString());
1052
1053                QueryPos qPos = QueryPos.getInstance(q);
1054
1055                qPos.add(tableId);
1056
1057                qPos.add(rowId);
1058
1059                List<ExpandoValue> list = q.list();
1060
1061                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1062                    finderClassName, finderMethodName, finderParams,
1063                    finderArgs, list);
1064
1065                return list;
1066            }
1067            catch (Exception e) {
1068                throw processException(e);
1069            }
1070            finally {
1071                closeSession(session);
1072            }
1073        }
1074        else {
1075            return (List<ExpandoValue>)result;
1076        }
1077    }
1078
1079    public List<ExpandoValue> findByT_R(long tableId, long rowId, int start,
1080        int end) throws SystemException {
1081        return findByT_R(tableId, rowId, start, end, null);
1082    }
1083
1084    public List<ExpandoValue> findByT_R(long tableId, long rowId, int start,
1085        int end, OrderByComparator obc) throws SystemException {
1086        boolean finderClassNameCacheEnabled = ExpandoValueModelImpl.CACHE_ENABLED;
1087        String finderClassName = ExpandoValue.class.getName();
1088        String finderMethodName = "findByT_R";
1089        String[] finderParams = new String[] {
1090                Long.class.getName(), Long.class.getName(),
1091                
1092                "java.lang.Integer", "java.lang.Integer",
1093                "com.liferay.portal.kernel.util.OrderByComparator"
1094            };
1095        Object[] finderArgs = new Object[] {
1096                new Long(tableId), new Long(rowId),
1097                
1098                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1099            };
1100
1101        Object result = null;
1102
1103        if (finderClassNameCacheEnabled) {
1104            result = FinderCacheUtil.getResult(finderClassName,
1105                    finderMethodName, finderParams, finderArgs, this);
1106        }
1107
1108        if (result == null) {
1109            Session session = null;
1110
1111            try {
1112                session = openSession();
1113
1114                StringBuilder query = new StringBuilder();
1115
1116                query.append(
1117                    "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
1118
1119                query.append("tableId = ?");
1120
1121                query.append(" AND ");
1122
1123                query.append("rowId_ = ?");
1124
1125                query.append(" ");
1126
1127                if (obc != null) {
1128                    query.append("ORDER BY ");
1129                    query.append(obc.getOrderBy());
1130                }
1131
1132                else {
1133                    query.append("ORDER BY ");
1134
1135                    query.append("tableId ASC, ");
1136                    query.append("rowId_ ASC, ");
1137                    query.append("columnId ASC");
1138                }
1139
1140                Query q = session.createQuery(query.toString());
1141
1142                QueryPos qPos = QueryPos.getInstance(q);
1143
1144                qPos.add(tableId);
1145
1146                qPos.add(rowId);
1147
1148                List<ExpandoValue> list = (List<ExpandoValue>)QueryUtil.list(q,
1149                        getDialect(), start, end);
1150
1151                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1152                    finderClassName, finderMethodName, finderParams,
1153                    finderArgs, list);
1154
1155                return list;
1156            }
1157            catch (Exception e) {
1158                throw processException(e);
1159            }
1160            finally {
1161                closeSession(session);
1162            }
1163        }
1164        else {
1165            return (List<ExpandoValue>)result;
1166        }
1167    }
1168
1169    public ExpandoValue findByT_R_First(long tableId, long rowId,
1170        OrderByComparator obc) throws NoSuchValueException, SystemException {
1171        List<ExpandoValue> list = findByT_R(tableId, rowId, 0, 1, obc);
1172
1173        if (list.size() == 0) {
1174            StringBuilder msg = new StringBuilder();
1175
1176            msg.append("No ExpandoValue exists with the key {");
1177
1178            msg.append("tableId=" + tableId);
1179
1180            msg.append(", ");
1181            msg.append("rowId=" + rowId);
1182
1183            msg.append(StringPool.CLOSE_CURLY_BRACE);
1184
1185            throw new NoSuchValueException(msg.toString());
1186        }
1187        else {
1188            return list.get(0);
1189        }
1190    }
1191
1192    public ExpandoValue findByT_R_Last(long tableId, long rowId,
1193        OrderByComparator obc) throws NoSuchValueException, SystemException {
1194        int count = countByT_R(tableId, rowId);
1195
1196        List<ExpandoValue> list = findByT_R(tableId, rowId, count - 1, count,
1197                obc);
1198
1199        if (list.size() == 0) {
1200            StringBuilder msg = new StringBuilder();
1201
1202            msg.append("No ExpandoValue exists with the key {");
1203
1204            msg.append("tableId=" + tableId);
1205
1206            msg.append(", ");
1207            msg.append("rowId=" + rowId);
1208
1209            msg.append(StringPool.CLOSE_CURLY_BRACE);
1210
1211            throw new NoSuchValueException(msg.toString());
1212        }
1213        else {
1214            return list.get(0);
1215        }
1216    }
1217
1218    public ExpandoValue[] findByT_R_PrevAndNext(long valueId, long tableId,
1219        long rowId, OrderByComparator obc)
1220        throws NoSuchValueException, SystemException {
1221        ExpandoValue expandoValue = findByPrimaryKey(valueId);
1222
1223        int count = countByT_R(tableId, rowId);
1224
1225        Session session = null;
1226
1227        try {
1228            session = openSession();
1229
1230            StringBuilder query = new StringBuilder();
1231
1232            query.append(
1233                "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
1234
1235            query.append("tableId = ?");
1236
1237            query.append(" AND ");
1238
1239            query.append("rowId_ = ?");
1240
1241            query.append(" ");
1242
1243            if (obc != null) {
1244                query.append("ORDER BY ");
1245                query.append(obc.getOrderBy());
1246            }
1247
1248            else {
1249                query.append("ORDER BY ");
1250
1251                query.append("tableId ASC, ");
1252                query.append("rowId_ ASC, ");
1253                query.append("columnId ASC");
1254            }
1255
1256            Query q = session.createQuery(query.toString());
1257
1258            QueryPos qPos = QueryPos.getInstance(q);
1259
1260            qPos.add(tableId);
1261
1262            qPos.add(rowId);
1263
1264            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1265                    expandoValue);
1266
1267            ExpandoValue[] array = new ExpandoValueImpl[3];
1268
1269            array[0] = (ExpandoValue)objArray[0];
1270            array[1] = (ExpandoValue)objArray[1];
1271            array[2] = (ExpandoValue)objArray[2];
1272
1273            return array;
1274        }
1275        catch (Exception e) {
1276            throw processException(e);
1277        }
1278        finally {
1279            closeSession(session);
1280        }
1281    }
1282
1283    public ExpandoValue findByC_R(long columnId, long rowId)
1284        throws NoSuchValueException, SystemException {
1285        ExpandoValue expandoValue = fetchByC_R(columnId, rowId);
1286
1287        if (expandoValue == null) {
1288            StringBuilder msg = new StringBuilder();
1289
1290            msg.append("No ExpandoValue exists with the key {");
1291
1292            msg.append("columnId=" + columnId);
1293
1294            msg.append(", ");
1295            msg.append("rowId=" + rowId);
1296
1297            msg.append(StringPool.CLOSE_CURLY_BRACE);
1298
1299            if (_log.isWarnEnabled()) {
1300                _log.warn(msg.toString());
1301            }
1302
1303            throw new NoSuchValueException(msg.toString());
1304        }
1305
1306        return expandoValue;
1307    }
1308
1309    public ExpandoValue fetchByC_R(long columnId, long rowId)
1310        throws SystemException {
1311        boolean finderClassNameCacheEnabled = ExpandoValueModelImpl.CACHE_ENABLED;
1312        String finderClassName = ExpandoValue.class.getName();
1313        String finderMethodName = "fetchByC_R";
1314        String[] finderParams = new String[] {
1315                Long.class.getName(), Long.class.getName()
1316            };
1317        Object[] finderArgs = new Object[] { new Long(columnId), new Long(rowId) };
1318
1319        Object result = null;
1320
1321        if (finderClassNameCacheEnabled) {
1322            result = FinderCacheUtil.getResult(finderClassName,
1323                    finderMethodName, finderParams, finderArgs, this);
1324        }
1325
1326        if (result == null) {
1327            Session session = null;
1328
1329            try {
1330                session = openSession();
1331
1332                StringBuilder query = new StringBuilder();
1333
1334                query.append(
1335                    "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
1336
1337                query.append("columnId = ?");
1338
1339                query.append(" AND ");
1340
1341                query.append("rowId_ = ?");
1342
1343                query.append(" ");
1344
1345                query.append("ORDER BY ");
1346
1347                query.append("tableId ASC, ");
1348                query.append("rowId_ ASC, ");
1349                query.append("columnId ASC");
1350
1351                Query q = session.createQuery(query.toString());
1352
1353                QueryPos qPos = QueryPos.getInstance(q);
1354
1355                qPos.add(columnId);
1356
1357                qPos.add(rowId);
1358
1359                List<ExpandoValue> list = q.list();
1360
1361                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1362                    finderClassName, finderMethodName, finderParams,
1363                    finderArgs, list);
1364
1365                if (list.size() == 0) {
1366                    return null;
1367                }
1368                else {
1369                    return list.get(0);
1370                }
1371            }
1372            catch (Exception e) {
1373                throw processException(e);
1374            }
1375            finally {
1376                closeSession(session);
1377            }
1378        }
1379        else {
1380            List<ExpandoValue> list = (List<ExpandoValue>)result;
1381
1382            if (list.size() == 0) {
1383                return null;
1384            }
1385            else {
1386                return list.get(0);
1387            }
1388        }
1389    }
1390
1391    public List<ExpandoValue> findByC_C(long classNameId, long classPK)
1392        throws SystemException {
1393        boolean finderClassNameCacheEnabled = ExpandoValueModelImpl.CACHE_ENABLED;
1394        String finderClassName = ExpandoValue.class.getName();
1395        String finderMethodName = "findByC_C";
1396        String[] finderParams = new String[] {
1397                Long.class.getName(), Long.class.getName()
1398            };
1399        Object[] finderArgs = new Object[] {
1400                new Long(classNameId), new Long(classPK)
1401            };
1402
1403        Object result = null;
1404
1405        if (finderClassNameCacheEnabled) {
1406            result = FinderCacheUtil.getResult(finderClassName,
1407                    finderMethodName, finderParams, finderArgs, this);
1408        }
1409
1410        if (result == null) {
1411            Session session = null;
1412
1413            try {
1414                session = openSession();
1415
1416                StringBuilder query = new StringBuilder();
1417
1418                query.append(
1419                    "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
1420
1421                query.append("classNameId = ?");
1422
1423                query.append(" AND ");
1424
1425                query.append("classPK = ?");
1426
1427                query.append(" ");
1428
1429                query.append("ORDER BY ");
1430
1431                query.append("tableId ASC, ");
1432                query.append("rowId_ ASC, ");
1433                query.append("columnId ASC");
1434
1435                Query q = session.createQuery(query.toString());
1436
1437                QueryPos qPos = QueryPos.getInstance(q);
1438
1439                qPos.add(classNameId);
1440
1441                qPos.add(classPK);
1442
1443                List<ExpandoValue> list = q.list();
1444
1445                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1446                    finderClassName, finderMethodName, finderParams,
1447                    finderArgs, list);
1448
1449                return list;
1450            }
1451            catch (Exception e) {
1452                throw processException(e);
1453            }
1454            finally {
1455                closeSession(session);
1456            }
1457        }
1458        else {
1459            return (List<ExpandoValue>)result;
1460        }
1461    }
1462
1463    public List<ExpandoValue> findByC_C(long classNameId, long classPK,
1464        int start, int end) throws SystemException {
1465        return findByC_C(classNameId, classPK, start, end, null);
1466    }
1467
1468    public List<ExpandoValue> findByC_C(long classNameId, long classPK,
1469        int start, int end, OrderByComparator obc) throws SystemException {
1470        boolean finderClassNameCacheEnabled = ExpandoValueModelImpl.CACHE_ENABLED;
1471        String finderClassName = ExpandoValue.class.getName();
1472        String finderMethodName = "findByC_C";
1473        String[] finderParams = new String[] {
1474                Long.class.getName(), Long.class.getName(),
1475                
1476                "java.lang.Integer", "java.lang.Integer",
1477                "com.liferay.portal.kernel.util.OrderByComparator"
1478            };
1479        Object[] finderArgs = new Object[] {
1480                new Long(classNameId), new Long(classPK),
1481                
1482                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1483            };
1484
1485        Object result = null;
1486
1487        if (finderClassNameCacheEnabled) {
1488            result = FinderCacheUtil.getResult(finderClassName,
1489                    finderMethodName, finderParams, finderArgs, this);
1490        }
1491
1492        if (result == null) {
1493            Session session = null;
1494
1495            try {
1496                session = openSession();
1497
1498                StringBuilder query = new StringBuilder();
1499
1500                query.append(
1501                    "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
1502
1503                query.append("classNameId = ?");
1504
1505                query.append(" AND ");
1506
1507                query.append("classPK = ?");
1508
1509                query.append(" ");
1510
1511                if (obc != null) {
1512                    query.append("ORDER BY ");
1513                    query.append(obc.getOrderBy());
1514                }
1515
1516                else {
1517                    query.append("ORDER BY ");
1518
1519                    query.append("tableId ASC, ");
1520                    query.append("rowId_ ASC, ");
1521                    query.append("columnId ASC");
1522                }
1523
1524                Query q = session.createQuery(query.toString());
1525
1526                QueryPos qPos = QueryPos.getInstance(q);
1527
1528                qPos.add(classNameId);
1529
1530                qPos.add(classPK);
1531
1532                List<ExpandoValue> list = (List<ExpandoValue>)QueryUtil.list(q,
1533                        getDialect(), start, end);
1534
1535                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1536                    finderClassName, finderMethodName, finderParams,
1537                    finderArgs, list);
1538
1539                return list;
1540            }
1541            catch (Exception e) {
1542                throw processException(e);
1543            }
1544            finally {
1545                closeSession(session);
1546            }
1547        }
1548        else {
1549            return (List<ExpandoValue>)result;
1550        }
1551    }
1552
1553    public ExpandoValue findByC_C_First(long classNameId, long classPK,
1554        OrderByComparator obc) throws NoSuchValueException, SystemException {
1555        List<ExpandoValue> list = findByC_C(classNameId, classPK, 0, 1, obc);
1556
1557        if (list.size() == 0) {
1558            StringBuilder msg = new StringBuilder();
1559
1560            msg.append("No ExpandoValue exists with the key {");
1561
1562            msg.append("classNameId=" + classNameId);
1563
1564            msg.append(", ");
1565            msg.append("classPK=" + classPK);
1566
1567            msg.append(StringPool.CLOSE_CURLY_BRACE);
1568
1569            throw new NoSuchValueException(msg.toString());
1570        }
1571        else {
1572            return list.get(0);
1573        }
1574    }
1575
1576    public ExpandoValue findByC_C_Last(long classNameId, long classPK,
1577        OrderByComparator obc) throws NoSuchValueException, SystemException {
1578        int count = countByC_C(classNameId, classPK);
1579
1580        List<ExpandoValue> list = findByC_C(classNameId, classPK, count - 1,
1581                count, obc);
1582
1583        if (list.size() == 0) {
1584            StringBuilder msg = new StringBuilder();
1585
1586            msg.append("No ExpandoValue exists with the key {");
1587
1588            msg.append("classNameId=" + classNameId);
1589
1590            msg.append(", ");
1591            msg.append("classPK=" + classPK);
1592
1593            msg.append(StringPool.CLOSE_CURLY_BRACE);
1594
1595            throw new NoSuchValueException(msg.toString());
1596        }
1597        else {
1598            return list.get(0);
1599        }
1600    }
1601
1602    public ExpandoValue[] findByC_C_PrevAndNext(long valueId, long classNameId,
1603        long classPK, OrderByComparator obc)
1604        throws NoSuchValueException, SystemException {
1605        ExpandoValue expandoValue = findByPrimaryKey(valueId);
1606
1607        int count = countByC_C(classNameId, classPK);
1608
1609        Session session = null;
1610
1611        try {
1612            session = openSession();
1613
1614            StringBuilder query = new StringBuilder();
1615
1616            query.append(
1617                "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
1618
1619            query.append("classNameId = ?");
1620
1621            query.append(" AND ");
1622
1623            query.append("classPK = ?");
1624
1625            query.append(" ");
1626
1627            if (obc != null) {
1628                query.append("ORDER BY ");
1629                query.append(obc.getOrderBy());
1630            }
1631
1632            else {
1633                query.append("ORDER BY ");
1634
1635                query.append("tableId ASC, ");
1636                query.append("rowId_ ASC, ");
1637                query.append("columnId ASC");
1638            }
1639
1640            Query q = session.createQuery(query.toString());
1641
1642            QueryPos qPos = QueryPos.getInstance(q);
1643
1644            qPos.add(classNameId);
1645
1646            qPos.add(classPK);
1647
1648            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1649                    expandoValue);
1650
1651            ExpandoValue[] array = new ExpandoValueImpl[3];
1652
1653            array[0] = (ExpandoValue)objArray[0];
1654            array[1] = (ExpandoValue)objArray[1];
1655            array[2] = (ExpandoValue)objArray[2];
1656
1657            return array;
1658        }
1659        catch (Exception e) {
1660            throw processException(e);
1661        }
1662        finally {
1663            closeSession(session);
1664        }
1665    }
1666
1667    public ExpandoValue findByT_C_R(long tableId, long columnId, long rowId)
1668        throws NoSuchValueException, SystemException {
1669        ExpandoValue expandoValue = fetchByT_C_R(tableId, columnId, rowId);
1670
1671        if (expandoValue == null) {
1672            StringBuilder msg = new StringBuilder();
1673
1674            msg.append("No ExpandoValue exists with the key {");
1675
1676            msg.append("tableId=" + tableId);
1677
1678            msg.append(", ");
1679            msg.append("columnId=" + columnId);
1680
1681            msg.append(", ");
1682            msg.append("rowId=" + rowId);
1683
1684            msg.append(StringPool.CLOSE_CURLY_BRACE);
1685
1686            if (_log.isWarnEnabled()) {
1687                _log.warn(msg.toString());
1688            }
1689
1690            throw new NoSuchValueException(msg.toString());
1691        }
1692
1693        return expandoValue;
1694    }
1695
1696    public ExpandoValue fetchByT_C_R(long tableId, long columnId, long rowId)
1697        throws SystemException {
1698        boolean finderClassNameCacheEnabled = ExpandoValueModelImpl.CACHE_ENABLED;
1699        String finderClassName = ExpandoValue.class.getName();
1700        String finderMethodName = "fetchByT_C_R";
1701        String[] finderParams = new String[] {
1702                Long.class.getName(), Long.class.getName(), Long.class.getName()
1703            };
1704        Object[] finderArgs = new Object[] {
1705                new Long(tableId), new Long(columnId), new Long(rowId)
1706            };
1707
1708        Object result = null;
1709
1710        if (finderClassNameCacheEnabled) {
1711            result = FinderCacheUtil.getResult(finderClassName,
1712                    finderMethodName, finderParams, finderArgs, this);
1713        }
1714
1715        if (result == null) {
1716            Session session = null;
1717
1718            try {
1719                session = openSession();
1720
1721                StringBuilder query = new StringBuilder();
1722
1723                query.append(
1724                    "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
1725
1726                query.append("tableId = ?");
1727
1728                query.append(" AND ");
1729
1730                query.append("columnId = ?");
1731
1732                query.append(" AND ");
1733
1734                query.append("rowId_ = ?");
1735
1736                query.append(" ");
1737
1738                query.append("ORDER BY ");
1739
1740                query.append("tableId ASC, ");
1741                query.append("rowId_ ASC, ");
1742                query.append("columnId ASC");
1743
1744                Query q = session.createQuery(query.toString());
1745
1746                QueryPos qPos = QueryPos.getInstance(q);
1747
1748                qPos.add(tableId);
1749
1750                qPos.add(columnId);
1751
1752                qPos.add(rowId);
1753
1754                List<ExpandoValue> list = q.list();
1755
1756                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1757                    finderClassName, finderMethodName, finderParams,
1758                    finderArgs, list);
1759
1760                if (list.size() == 0) {
1761                    return null;
1762                }
1763                else {
1764                    return list.get(0);
1765                }
1766            }
1767            catch (Exception e) {
1768                throw processException(e);
1769            }
1770            finally {
1771                closeSession(session);
1772            }
1773        }
1774        else {
1775            List<ExpandoValue> list = (List<ExpandoValue>)result;
1776
1777            if (list.size() == 0) {
1778                return null;
1779            }
1780            else {
1781                return list.get(0);
1782            }
1783        }
1784    }
1785
1786    public List<ExpandoValue> findByT_C_C_C(long tableId, long columnId,
1787        long classNameId, long classPK) throws SystemException {
1788        boolean finderClassNameCacheEnabled = ExpandoValueModelImpl.CACHE_ENABLED;
1789        String finderClassName = ExpandoValue.class.getName();
1790        String finderMethodName = "findByT_C_C_C";
1791        String[] finderParams = new String[] {
1792                Long.class.getName(), Long.class.getName(), Long.class.getName(),
1793                Long.class.getName()
1794            };
1795        Object[] finderArgs = new Object[] {
1796                new Long(tableId), new Long(columnId), new Long(classNameId),
1797                new Long(classPK)
1798            };
1799
1800        Object result = null;
1801
1802        if (finderClassNameCacheEnabled) {
1803            result = FinderCacheUtil.getResult(finderClassName,
1804                    finderMethodName, finderParams, finderArgs, this);
1805        }
1806
1807        if (result == null) {
1808            Session session = null;
1809
1810            try {
1811                session = openSession();
1812
1813                StringBuilder query = new StringBuilder();
1814
1815                query.append(
1816                    "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
1817
1818                query.append("tableId = ?");
1819
1820                query.append(" AND ");
1821
1822                query.append("columnId = ?");
1823
1824                query.append(" AND ");
1825
1826                query.append("classNameId = ?");
1827
1828                query.append(" AND ");
1829
1830                query.append("classPK = ?");
1831
1832                query.append(" ");
1833
1834                query.append("ORDER BY ");
1835
1836                query.append("tableId ASC, ");
1837                query.append("rowId_ ASC, ");
1838                query.append("columnId ASC");
1839
1840                Query q = session.createQuery(query.toString());
1841
1842                QueryPos qPos = QueryPos.getInstance(q);
1843
1844                qPos.add(tableId);
1845
1846                qPos.add(columnId);
1847
1848                qPos.add(classNameId);
1849
1850                qPos.add(classPK);
1851
1852                List<ExpandoValue> list = q.list();
1853
1854                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1855                    finderClassName, finderMethodName, finderParams,
1856                    finderArgs, list);
1857
1858                return list;
1859            }
1860            catch (Exception e) {
1861                throw processException(e);
1862            }
1863            finally {
1864                closeSession(session);
1865            }
1866        }
1867        else {
1868            return (List<ExpandoValue>)result;
1869        }
1870    }
1871
1872    public List<ExpandoValue> findByT_C_C_C(long tableId, long columnId,
1873        long classNameId, long classPK, int start, int end)
1874        throws SystemException {
1875        return findByT_C_C_C(tableId, columnId, classNameId, classPK, start,
1876            end, null);
1877    }
1878
1879    public List<ExpandoValue> findByT_C_C_C(long tableId, long columnId,
1880        long classNameId, long classPK, int start, int end,
1881        OrderByComparator obc) throws SystemException {
1882        boolean finderClassNameCacheEnabled = ExpandoValueModelImpl.CACHE_ENABLED;
1883        String finderClassName = ExpandoValue.class.getName();
1884        String finderMethodName = "findByT_C_C_C";
1885        String[] finderParams = new String[] {
1886                Long.class.getName(), Long.class.getName(), Long.class.getName(),
1887                Long.class.getName(),
1888                
1889                "java.lang.Integer", "java.lang.Integer",
1890                "com.liferay.portal.kernel.util.OrderByComparator"
1891            };
1892        Object[] finderArgs = new Object[] {
1893                new Long(tableId), new Long(columnId), new Long(classNameId),
1894                new Long(classPK),
1895                
1896                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1897            };
1898
1899        Object result = null;
1900
1901        if (finderClassNameCacheEnabled) {
1902            result = FinderCacheUtil.getResult(finderClassName,
1903                    finderMethodName, finderParams, finderArgs, this);
1904        }
1905
1906        if (result == null) {
1907            Session session = null;
1908
1909            try {
1910                session = openSession();
1911
1912                StringBuilder query = new StringBuilder();
1913
1914                query.append(
1915                    "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
1916
1917                query.append("tableId = ?");
1918
1919                query.append(" AND ");
1920
1921                query.append("columnId = ?");
1922
1923                query.append(" AND ");
1924
1925                query.append("classNameId = ?");
1926
1927                query.append(" AND ");
1928
1929                query.append("classPK = ?");
1930
1931                query.append(" ");
1932
1933                if (obc != null) {
1934                    query.append("ORDER BY ");
1935                    query.append(obc.getOrderBy());
1936                }
1937
1938                else {
1939                    query.append("ORDER BY ");
1940
1941                    query.append("tableId ASC, ");
1942                    query.append("rowId_ ASC, ");
1943                    query.append("columnId ASC");
1944                }
1945
1946                Query q = session.createQuery(query.toString());
1947
1948                QueryPos qPos = QueryPos.getInstance(q);
1949
1950                qPos.add(tableId);
1951
1952                qPos.add(columnId);
1953
1954                qPos.add(classNameId);
1955
1956                qPos.add(classPK);
1957
1958                List<ExpandoValue> list = (List<ExpandoValue>)QueryUtil.list(q,
1959                        getDialect(), start, end);
1960
1961                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1962                    finderClassName, finderMethodName, finderParams,
1963                    finderArgs, list);
1964
1965                return list;
1966            }
1967            catch (Exception e) {
1968                throw processException(e);
1969            }
1970            finally {
1971                closeSession(session);
1972            }
1973        }
1974        else {
1975            return (List<ExpandoValue>)result;
1976        }
1977    }
1978
1979    public ExpandoValue findByT_C_C_C_First(long tableId, long columnId,
1980        long classNameId, long classPK, OrderByComparator obc)
1981        throws NoSuchValueException, SystemException {
1982        List<ExpandoValue> list = findByT_C_C_C(tableId, columnId, classNameId,
1983                classPK, 0, 1, obc);
1984
1985        if (list.size() == 0) {
1986            StringBuilder msg = new StringBuilder();
1987
1988            msg.append("No ExpandoValue exists with the key {");
1989
1990            msg.append("tableId=" + tableId);
1991
1992            msg.append(", ");
1993            msg.append("columnId=" + columnId);
1994
1995            msg.append(", ");
1996            msg.append("classNameId=" + classNameId);
1997
1998            msg.append(", ");
1999            msg.append("classPK=" + classPK);
2000
2001            msg.append(StringPool.CLOSE_CURLY_BRACE);
2002
2003            throw new NoSuchValueException(msg.toString());
2004        }
2005        else {
2006            return list.get(0);
2007        }
2008    }
2009
2010    public ExpandoValue findByT_C_C_C_Last(long tableId, long columnId,
2011        long classNameId, long classPK, OrderByComparator obc)
2012        throws NoSuchValueException, SystemException {
2013        int count = countByT_C_C_C(tableId, columnId, classNameId, classPK);
2014
2015        List<ExpandoValue> list = findByT_C_C_C(tableId, columnId, classNameId,
2016                classPK, count - 1, count, obc);
2017
2018        if (list.size() == 0) {
2019            StringBuilder msg = new StringBuilder();
2020
2021            msg.append("No ExpandoValue exists with the key {");
2022
2023            msg.append("tableId=" + tableId);
2024
2025            msg.append(", ");
2026            msg.append("columnId=" + columnId);
2027
2028            msg.append(", ");
2029            msg.append("classNameId=" + classNameId);
2030
2031            msg.append(", ");
2032            msg.append("classPK=" + classPK);
2033
2034            msg.append(StringPool.CLOSE_CURLY_BRACE);
2035
2036            throw new NoSuchValueException(msg.toString());
2037        }
2038        else {
2039            return list.get(0);
2040        }
2041    }
2042
2043    public ExpandoValue[] findByT_C_C_C_PrevAndNext(long valueId, long tableId,
2044        long columnId, long classNameId, long classPK, OrderByComparator obc)
2045        throws NoSuchValueException, SystemException {
2046        ExpandoValue expandoValue = findByPrimaryKey(valueId);
2047
2048        int count = countByT_C_C_C(tableId, columnId, classNameId, classPK);
2049
2050        Session session = null;
2051
2052        try {
2053            session = openSession();
2054
2055            StringBuilder query = new StringBuilder();
2056
2057            query.append(
2058                "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
2059
2060            query.append("tableId = ?");
2061
2062            query.append(" AND ");
2063
2064            query.append("columnId = ?");
2065
2066            query.append(" AND ");
2067
2068            query.append("classNameId = ?");
2069
2070            query.append(" AND ");
2071
2072            query.append("classPK = ?");
2073
2074            query.append(" ");
2075
2076            if (obc != null) {
2077                query.append("ORDER BY ");
2078                query.append(obc.getOrderBy());
2079            }
2080
2081            else {
2082                query.append("ORDER BY ");
2083
2084                query.append("tableId ASC, ");
2085                query.append("rowId_ ASC, ");
2086                query.append("columnId ASC");
2087            }
2088
2089            Query q = session.createQuery(query.toString());
2090
2091            QueryPos qPos = QueryPos.getInstance(q);
2092
2093            qPos.add(tableId);
2094
2095            qPos.add(columnId);
2096
2097            qPos.add(classNameId);
2098
2099            qPos.add(classPK);
2100
2101            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
2102                    expandoValue);
2103
2104            ExpandoValue[] array = new ExpandoValueImpl[3];
2105
2106            array[0] = (ExpandoValue)objArray[0];
2107            array[1] = (ExpandoValue)objArray[1];
2108            array[2] = (ExpandoValue)objArray[2];
2109
2110            return array;
2111        }
2112        catch (Exception e) {
2113            throw processException(e);
2114        }
2115        finally {
2116            closeSession(session);
2117        }
2118    }
2119
2120    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
2121        throws SystemException {
2122        Session session = null;
2123
2124        try {
2125            session = openSession();
2126
2127            dynamicQuery.compile(session);
2128
2129            return dynamicQuery.list();
2130        }
2131        catch (Exception e) {
2132            throw processException(e);
2133        }
2134        finally {
2135            closeSession(session);
2136        }
2137    }
2138
2139    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
2140        int start, int end) throws SystemException {
2141        Session session = null;
2142
2143        try {
2144            session = openSession();
2145
2146            dynamicQuery.setLimit(start, end);
2147
2148            dynamicQuery.compile(session);
2149
2150            return dynamicQuery.list();
2151        }
2152        catch (Exception e) {
2153            throw processException(e);
2154        }
2155        finally {
2156            closeSession(session);
2157        }
2158    }
2159
2160    public List<ExpandoValue> findAll() throws SystemException {
2161        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2162    }
2163
2164    public List<ExpandoValue> findAll(int start, int end)
2165        throws SystemException {
2166        return findAll(start, end, null);
2167    }
2168
2169    public List<ExpandoValue> findAll(int start, int end, OrderByComparator obc)
2170        throws SystemException {
2171        boolean finderClassNameCacheEnabled = ExpandoValueModelImpl.CACHE_ENABLED;
2172        String finderClassName = ExpandoValue.class.getName();
2173        String finderMethodName = "findAll";
2174        String[] finderParams = new String[] {
2175                "java.lang.Integer", "java.lang.Integer",
2176                "com.liferay.portal.kernel.util.OrderByComparator"
2177            };
2178        Object[] finderArgs = new Object[] {
2179                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
2180            };
2181
2182        Object result = null;
2183
2184        if (finderClassNameCacheEnabled) {
2185            result = FinderCacheUtil.getResult(finderClassName,
2186                    finderMethodName, finderParams, finderArgs, this);
2187        }
2188
2189        if (result == null) {
2190            Session session = null;
2191
2192            try {
2193                session = openSession();
2194
2195                StringBuilder query = new StringBuilder();
2196
2197                query.append(
2198                    "FROM com.liferay.portlet.expando.model.ExpandoValue ");
2199
2200                if (obc != null) {
2201                    query.append("ORDER BY ");
2202                    query.append(obc.getOrderBy());
2203                }
2204
2205                else {
2206                    query.append("ORDER BY ");
2207
2208                    query.append("tableId ASC, ");
2209                    query.append("rowId_ ASC, ");
2210                    query.append("columnId ASC");
2211                }
2212
2213                Query q = session.createQuery(query.toString());
2214
2215                List<ExpandoValue> list = (List<ExpandoValue>)QueryUtil.list(q,
2216                        getDialect(), start, end);
2217
2218                if (obc == null) {
2219                    Collections.sort(list);
2220                }
2221
2222                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2223                    finderClassName, finderMethodName, finderParams,
2224                    finderArgs, list);
2225
2226                return list;
2227            }
2228            catch (Exception e) {
2229                throw processException(e);
2230            }
2231            finally {
2232                closeSession(session);
2233            }
2234        }
2235        else {
2236            return (List<ExpandoValue>)result;
2237        }
2238    }
2239
2240    public void removeByTableId(long tableId) throws SystemException {
2241        for (ExpandoValue expandoValue : findByTableId(tableId)) {
2242            remove(expandoValue);
2243        }
2244    }
2245
2246    public void removeByColumnId(long columnId) throws SystemException {
2247        for (ExpandoValue expandoValue : findByColumnId(columnId)) {
2248            remove(expandoValue);
2249        }
2250    }
2251
2252    public void removeByRowId(long rowId) throws SystemException {
2253        for (ExpandoValue expandoValue : findByRowId(rowId)) {
2254            remove(expandoValue);
2255        }
2256    }
2257
2258    public void removeByT_R(long tableId, long rowId) throws SystemException {
2259        for (ExpandoValue expandoValue : findByT_R(tableId, rowId)) {
2260            remove(expandoValue);
2261        }
2262    }
2263
2264    public void removeByC_R(long columnId, long rowId)
2265        throws NoSuchValueException, SystemException {
2266        ExpandoValue expandoValue = findByC_R(columnId, rowId);
2267
2268        remove(expandoValue);
2269    }
2270
2271    public void removeByC_C(long classNameId, long classPK)
2272        throws SystemException {
2273        for (ExpandoValue expandoValue : findByC_C(classNameId, classPK)) {
2274            remove(expandoValue);
2275        }
2276    }
2277
2278    public void removeByT_C_R(long tableId, long columnId, long rowId)
2279        throws NoSuchValueException, SystemException {
2280        ExpandoValue expandoValue = findByT_C_R(tableId, columnId, rowId);
2281
2282        remove(expandoValue);
2283    }
2284
2285    public void removeByT_C_C_C(long tableId, long columnId, long classNameId,
2286        long classPK) throws SystemException {
2287        for (ExpandoValue expandoValue : findByT_C_C_C(tableId, columnId,
2288                classNameId, classPK)) {
2289            remove(expandoValue);
2290        }
2291    }
2292
2293    public void removeAll() throws SystemException {
2294        for (ExpandoValue expandoValue : findAll()) {
2295            remove(expandoValue);
2296        }
2297    }
2298
2299    public int countByTableId(long tableId) throws SystemException {
2300        boolean finderClassNameCacheEnabled = ExpandoValueModelImpl.CACHE_ENABLED;
2301        String finderClassName = ExpandoValue.class.getName();
2302        String finderMethodName = "countByTableId";
2303        String[] finderParams = new String[] { Long.class.getName() };
2304        Object[] finderArgs = new Object[] { new Long(tableId) };
2305
2306        Object result = null;
2307
2308        if (finderClassNameCacheEnabled) {
2309            result = FinderCacheUtil.getResult(finderClassName,
2310                    finderMethodName, finderParams, finderArgs, this);
2311        }
2312
2313        if (result == null) {
2314            Session session = null;
2315
2316            try {
2317                session = openSession();
2318
2319                StringBuilder query = new StringBuilder();
2320
2321                query.append("SELECT COUNT(*) ");
2322                query.append(
2323                    "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
2324
2325                query.append("tableId = ?");
2326
2327                query.append(" ");
2328
2329                Query q = session.createQuery(query.toString());
2330
2331                QueryPos qPos = QueryPos.getInstance(q);
2332
2333                qPos.add(tableId);
2334
2335                Long count = null;
2336
2337                Iterator<Long> itr = q.list().iterator();
2338
2339                if (itr.hasNext()) {
2340                    count = itr.next();
2341                }
2342
2343                if (count == null) {
2344                    count = new Long(0);
2345                }
2346
2347                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2348                    finderClassName, finderMethodName, finderParams,
2349                    finderArgs, count);
2350
2351                return count.intValue();
2352            }
2353            catch (Exception e) {
2354                throw processException(e);
2355            }
2356            finally {
2357                closeSession(session);
2358            }
2359        }
2360        else {
2361            return ((Long)result).intValue();
2362        }
2363    }
2364
2365    public int countByColumnId(long columnId) throws SystemException {
2366        boolean finderClassNameCacheEnabled = ExpandoValueModelImpl.CACHE_ENABLED;
2367        String finderClassName = ExpandoValue.class.getName();
2368        String finderMethodName = "countByColumnId";
2369        String[] finderParams = new String[] { Long.class.getName() };
2370        Object[] finderArgs = new Object[] { new Long(columnId) };
2371
2372        Object result = null;
2373
2374        if (finderClassNameCacheEnabled) {
2375            result = FinderCacheUtil.getResult(finderClassName,
2376                    finderMethodName, finderParams, finderArgs, this);
2377        }
2378
2379        if (result == null) {
2380            Session session = null;
2381
2382            try {
2383                session = openSession();
2384
2385                StringBuilder query = new StringBuilder();
2386
2387                query.append("SELECT COUNT(*) ");
2388                query.append(
2389                    "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
2390
2391                query.append("columnId = ?");
2392
2393                query.append(" ");
2394
2395                Query q = session.createQuery(query.toString());
2396
2397                QueryPos qPos = QueryPos.getInstance(q);
2398
2399                qPos.add(columnId);
2400
2401                Long count = null;
2402
2403                Iterator<Long> itr = q.list().iterator();
2404
2405                if (itr.hasNext()) {
2406                    count = itr.next();
2407                }
2408
2409                if (count == null) {
2410                    count = new Long(0);
2411                }
2412
2413                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2414                    finderClassName, finderMethodName, finderParams,
2415                    finderArgs, count);
2416
2417                return count.intValue();
2418            }
2419            catch (Exception e) {
2420                throw processException(e);
2421            }
2422            finally {
2423                closeSession(session);
2424            }
2425        }
2426        else {
2427            return ((Long)result).intValue();
2428        }
2429    }
2430
2431    public int countByRowId(long rowId) throws SystemException {
2432        boolean finderClassNameCacheEnabled = ExpandoValueModelImpl.CACHE_ENABLED;
2433        String finderClassName = ExpandoValue.class.getName();
2434        String finderMethodName = "countByRowId";
2435        String[] finderParams = new String[] { Long.class.getName() };
2436        Object[] finderArgs = new Object[] { new Long(rowId) };
2437
2438        Object result = null;
2439
2440        if (finderClassNameCacheEnabled) {
2441            result = FinderCacheUtil.getResult(finderClassName,
2442                    finderMethodName, finderParams, finderArgs, this);
2443        }
2444
2445        if (result == null) {
2446            Session session = null;
2447
2448            try {
2449                session = openSession();
2450
2451                StringBuilder query = new StringBuilder();
2452
2453                query.append("SELECT COUNT(*) ");
2454                query.append(
2455                    "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
2456
2457                query.append("rowId_ = ?");
2458
2459                query.append(" ");
2460
2461                Query q = session.createQuery(query.toString());
2462
2463                QueryPos qPos = QueryPos.getInstance(q);
2464
2465                qPos.add(rowId);
2466
2467                Long count = null;
2468
2469                Iterator<Long> itr = q.list().iterator();
2470
2471                if (itr.hasNext()) {
2472                    count = itr.next();
2473                }
2474
2475                if (count == null) {
2476                    count = new Long(0);
2477                }
2478
2479                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2480                    finderClassName, finderMethodName, finderParams,
2481                    finderArgs, count);
2482
2483                return count.intValue();
2484            }
2485            catch (Exception e) {
2486                throw processException(e);
2487            }
2488            finally {
2489                closeSession(session);
2490            }
2491        }
2492        else {
2493            return ((Long)result).intValue();
2494        }
2495    }
2496
2497    public int countByT_R(long tableId, long rowId) throws SystemException {
2498        boolean finderClassNameCacheEnabled = ExpandoValueModelImpl.CACHE_ENABLED;
2499        String finderClassName = ExpandoValue.class.getName();
2500        String finderMethodName = "countByT_R";
2501        String[] finderParams = new String[] {
2502                Long.class.getName(), Long.class.getName()
2503            };
2504        Object[] finderArgs = new Object[] { new Long(tableId), new Long(rowId) };
2505
2506        Object result = null;
2507
2508        if (finderClassNameCacheEnabled) {
2509            result = FinderCacheUtil.getResult(finderClassName,
2510                    finderMethodName, finderParams, finderArgs, this);
2511        }
2512
2513        if (result == null) {
2514            Session session = null;
2515
2516            try {
2517                session = openSession();
2518
2519                StringBuilder query = new StringBuilder();
2520
2521                query.append("SELECT COUNT(*) ");
2522                query.append(
2523                    "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
2524
2525                query.append("tableId = ?");
2526
2527                query.append(" AND ");
2528
2529                query.append("rowId_ = ?");
2530
2531                query.append(" ");
2532
2533                Query q = session.createQuery(query.toString());
2534
2535                QueryPos qPos = QueryPos.getInstance(q);
2536
2537                qPos.add(tableId);
2538
2539                qPos.add(rowId);
2540
2541                Long count = null;
2542
2543                Iterator<Long> itr = q.list().iterator();
2544
2545                if (itr.hasNext()) {
2546                    count = itr.next();
2547                }
2548
2549                if (count == null) {
2550                    count = new Long(0);
2551                }
2552
2553                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2554                    finderClassName, finderMethodName, finderParams,
2555                    finderArgs, count);
2556
2557                return count.intValue();
2558            }
2559            catch (Exception e) {
2560                throw processException(e);
2561            }
2562            finally {
2563                closeSession(session);
2564            }
2565        }
2566        else {
2567            return ((Long)result).intValue();
2568        }
2569    }
2570
2571    public int countByC_R(long columnId, long rowId) throws SystemException {
2572        boolean finderClassNameCacheEnabled = ExpandoValueModelImpl.CACHE_ENABLED;
2573        String finderClassName = ExpandoValue.class.getName();
2574        String finderMethodName = "countByC_R";
2575        String[] finderParams = new String[] {
2576                Long.class.getName(), Long.class.getName()
2577            };
2578        Object[] finderArgs = new Object[] { new Long(columnId), new Long(rowId) };
2579
2580        Object result = null;
2581
2582        if (finderClassNameCacheEnabled) {
2583            result = FinderCacheUtil.getResult(finderClassName,
2584                    finderMethodName, finderParams, finderArgs, this);
2585        }
2586
2587        if (result == null) {
2588            Session session = null;
2589
2590            try {
2591                session = openSession();
2592
2593                StringBuilder query = new StringBuilder();
2594
2595                query.append("SELECT COUNT(*) ");
2596                query.append(
2597                    "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
2598
2599                query.append("columnId = ?");
2600
2601                query.append(" AND ");
2602
2603                query.append("rowId_ = ?");
2604
2605                query.append(" ");
2606
2607                Query q = session.createQuery(query.toString());
2608
2609                QueryPos qPos = QueryPos.getInstance(q);
2610
2611                qPos.add(columnId);
2612
2613                qPos.add(rowId);
2614
2615                Long count = null;
2616
2617                Iterator<Long> itr = q.list().iterator();
2618
2619                if (itr.hasNext()) {
2620                    count = itr.next();
2621                }
2622
2623                if (count == null) {
2624                    count = new Long(0);
2625                }
2626
2627                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2628                    finderClassName, finderMethodName, finderParams,
2629                    finderArgs, count);
2630
2631                return count.intValue();
2632            }
2633            catch (Exception e) {
2634                throw processException(e);
2635            }
2636            finally {
2637                closeSession(session);
2638            }
2639        }
2640        else {
2641            return ((Long)result).intValue();
2642        }
2643    }
2644
2645    public int countByC_C(long classNameId, long classPK)
2646        throws SystemException {
2647        boolean finderClassNameCacheEnabled = ExpandoValueModelImpl.CACHE_ENABLED;
2648        String finderClassName = ExpandoValue.class.getName();
2649        String finderMethodName = "countByC_C";
2650        String[] finderParams = new String[] {
2651                Long.class.getName(), Long.class.getName()
2652            };
2653        Object[] finderArgs = new Object[] {
2654                new Long(classNameId), new Long(classPK)
2655            };
2656
2657        Object result = null;
2658
2659        if (finderClassNameCacheEnabled) {
2660            result = FinderCacheUtil.getResult(finderClassName,
2661                    finderMethodName, finderParams, finderArgs, this);
2662        }
2663
2664        if (result == null) {
2665            Session session = null;
2666
2667            try {
2668                session = openSession();
2669
2670                StringBuilder query = new StringBuilder();
2671
2672                query.append("SELECT COUNT(*) ");
2673                query.append(
2674                    "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
2675
2676                query.append("classNameId = ?");
2677
2678                query.append(" AND ");
2679
2680                query.append("classPK = ?");
2681
2682                query.append(" ");
2683
2684                Query q = session.createQuery(query.toString());
2685
2686                QueryPos qPos = QueryPos.getInstance(q);
2687
2688                qPos.add(classNameId);
2689
2690                qPos.add(classPK);
2691
2692                Long count = null;
2693
2694                Iterator<Long> itr = q.list().iterator();
2695
2696                if (itr.hasNext()) {
2697                    count = itr.next();
2698                }
2699
2700                if (count == null) {
2701                    count = new Long(0);
2702                }
2703
2704                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2705                    finderClassName, finderMethodName, finderParams,
2706                    finderArgs, count);
2707
2708                return count.intValue();
2709            }
2710            catch (Exception e) {
2711                throw processException(e);
2712            }
2713            finally {
2714                closeSession(session);
2715            }
2716        }
2717        else {
2718            return ((Long)result).intValue();
2719        }
2720    }
2721
2722    public int countByT_C_R(long tableId, long columnId, long rowId)
2723        throws SystemException {
2724        boolean finderClassNameCacheEnabled = ExpandoValueModelImpl.CACHE_ENABLED;
2725        String finderClassName = ExpandoValue.class.getName();
2726        String finderMethodName = "countByT_C_R";
2727        String[] finderParams = new String[] {
2728                Long.class.getName(), Long.class.getName(), Long.class.getName()
2729            };
2730        Object[] finderArgs = new Object[] {
2731                new Long(tableId), new Long(columnId), new Long(rowId)
2732            };
2733
2734        Object result = null;
2735
2736        if (finderClassNameCacheEnabled) {
2737            result = FinderCacheUtil.getResult(finderClassName,
2738                    finderMethodName, finderParams, finderArgs, this);
2739        }
2740
2741        if (result == null) {
2742            Session session = null;
2743
2744            try {
2745                session = openSession();
2746
2747                StringBuilder query = new StringBuilder();
2748
2749                query.append("SELECT COUNT(*) ");
2750                query.append(
2751                    "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
2752
2753                query.append("tableId = ?");
2754
2755                query.append(" AND ");
2756
2757                query.append("columnId = ?");
2758
2759                query.append(" AND ");
2760
2761                query.append("rowId_ = ?");
2762
2763                query.append(" ");
2764
2765                Query q = session.createQuery(query.toString());
2766
2767                QueryPos qPos = QueryPos.getInstance(q);
2768
2769                qPos.add(tableId);
2770
2771                qPos.add(columnId);
2772
2773                qPos.add(rowId);
2774
2775                Long count = null;
2776
2777                Iterator<Long> itr = q.list().iterator();
2778
2779                if (itr.hasNext()) {
2780                    count = itr.next();
2781                }
2782
2783                if (count == null) {
2784                    count = new Long(0);
2785                }
2786
2787                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2788                    finderClassName, finderMethodName, finderParams,
2789                    finderArgs, count);
2790
2791                return count.intValue();
2792            }
2793            catch (Exception e) {
2794                throw processException(e);
2795            }
2796            finally {
2797                closeSession(session);
2798            }
2799        }
2800        else {
2801            return ((Long)result).intValue();
2802        }
2803    }
2804
2805    public int countByT_C_C_C(long tableId, long columnId, long classNameId,
2806        long classPK) throws SystemException {
2807        boolean finderClassNameCacheEnabled = ExpandoValueModelImpl.CACHE_ENABLED;
2808        String finderClassName = ExpandoValue.class.getName();
2809        String finderMethodName = "countByT_C_C_C";
2810        String[] finderParams = new String[] {
2811                Long.class.getName(), Long.class.getName(), Long.class.getName(),
2812                Long.class.getName()
2813            };
2814        Object[] finderArgs = new Object[] {
2815                new Long(tableId), new Long(columnId), new Long(classNameId),
2816                new Long(classPK)
2817            };
2818
2819        Object result = null;
2820
2821        if (finderClassNameCacheEnabled) {
2822            result = FinderCacheUtil.getResult(finderClassName,
2823                    finderMethodName, finderParams, finderArgs, this);
2824        }
2825
2826        if (result == null) {
2827            Session session = null;
2828
2829            try {
2830                session = openSession();
2831
2832                StringBuilder query = new StringBuilder();
2833
2834                query.append("SELECT COUNT(*) ");
2835                query.append(
2836                    "FROM com.liferay.portlet.expando.model.ExpandoValue WHERE ");
2837
2838                query.append("tableId = ?");
2839
2840                query.append(" AND ");
2841
2842                query.append("columnId = ?");
2843
2844                query.append(" AND ");
2845
2846                query.append("classNameId = ?");
2847
2848                query.append(" AND ");
2849
2850                query.append("classPK = ?");
2851
2852                query.append(" ");
2853
2854                Query q = session.createQuery(query.toString());
2855
2856                QueryPos qPos = QueryPos.getInstance(q);
2857
2858                qPos.add(tableId);
2859
2860                qPos.add(columnId);
2861
2862                qPos.add(classNameId);
2863
2864                qPos.add(classPK);
2865
2866                Long count = null;
2867
2868                Iterator<Long> itr = q.list().iterator();
2869
2870                if (itr.hasNext()) {
2871                    count = itr.next();
2872                }
2873
2874                if (count == null) {
2875                    count = new Long(0);
2876                }
2877
2878                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2879                    finderClassName, finderMethodName, finderParams,
2880                    finderArgs, count);
2881
2882                return count.intValue();
2883            }
2884            catch (Exception e) {
2885                throw processException(e);
2886            }
2887            finally {
2888                closeSession(session);
2889            }
2890        }
2891        else {
2892            return ((Long)result).intValue();
2893        }
2894    }
2895
2896    public int countAll() throws SystemException {
2897        boolean finderClassNameCacheEnabled = ExpandoValueModelImpl.CACHE_ENABLED;
2898        String finderClassName = ExpandoValue.class.getName();
2899        String finderMethodName = "countAll";
2900        String[] finderParams = new String[] {  };
2901        Object[] finderArgs = new Object[] {  };
2902
2903        Object result = null;
2904
2905        if (finderClassNameCacheEnabled) {
2906            result = FinderCacheUtil.getResult(finderClassName,
2907                    finderMethodName, finderParams, finderArgs, this);
2908        }
2909
2910        if (result == null) {
2911            Session session = null;
2912
2913            try {
2914                session = openSession();
2915
2916                Query q = session.createQuery(
2917                        "SELECT COUNT(*) FROM com.liferay.portlet.expando.model.ExpandoValue");
2918
2919                Long count = null;
2920
2921                Iterator<Long> itr = q.list().iterator();
2922
2923                if (itr.hasNext()) {
2924                    count = itr.next();
2925                }
2926
2927                if (count == null) {
2928                    count = new Long(0);
2929                }
2930
2931                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2932                    finderClassName, finderMethodName, finderParams,
2933                    finderArgs, count);
2934
2935                return count.intValue();
2936            }
2937            catch (Exception e) {
2938                throw processException(e);
2939            }
2940            finally {
2941                closeSession(session);
2942            }
2943        }
2944        else {
2945            return ((Long)result).intValue();
2946        }
2947    }
2948
2949    public void registerListener(ModelListener listener) {
2950        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2951
2952        listeners.add(listener);
2953
2954        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2955    }
2956
2957    public void unregisterListener(ModelListener listener) {
2958        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2959
2960        listeners.remove(listener);
2961
2962        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2963    }
2964
2965    public void afterPropertiesSet() {
2966        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2967                    com.liferay.portal.util.PropsUtil.get(
2968                        "value.object.listener.com.liferay.portlet.expando.model.ExpandoValue")));
2969
2970        if (listenerClassNames.length > 0) {
2971            try {
2972                List<ModelListener> listeners = new ArrayList<ModelListener>();
2973
2974                for (String listenerClassName : listenerClassNames) {
2975                    listeners.add((ModelListener)Class.forName(
2976                            listenerClassName).newInstance());
2977                }
2978
2979                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2980            }
2981            catch (Exception e) {
2982                _log.error(e);
2983            }
2984        }
2985    }
2986
2987    private static Log _log = LogFactory.getLog(ExpandoValuePersistenceImpl.class);
2988    private ModelListener[] _listeners = new ModelListener[0];
2989}