1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   * 
13   */
14  
15  package com.liferay.portlet.expando.service.persistence;
16  
17  import com.liferay.portal.NoSuchModelException;
18  import com.liferay.portal.SystemException;
19  import com.liferay.portal.kernel.annotation.BeanReference;
20  import com.liferay.portal.kernel.cache.CacheRegistry;
21  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
22  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
23  import com.liferay.portal.kernel.dao.orm.FinderPath;
24  import com.liferay.portal.kernel.dao.orm.Query;
25  import com.liferay.portal.kernel.dao.orm.QueryPos;
26  import com.liferay.portal.kernel.dao.orm.QueryUtil;
27  import com.liferay.portal.kernel.dao.orm.Session;
28  import com.liferay.portal.kernel.log.Log;
29  import com.liferay.portal.kernel.log.LogFactoryUtil;
30  import com.liferay.portal.kernel.util.GetterUtil;
31  import com.liferay.portal.kernel.util.OrderByComparator;
32  import com.liferay.portal.kernel.util.StringBundler;
33  import com.liferay.portal.kernel.util.StringPool;
34  import com.liferay.portal.kernel.util.StringUtil;
35  import com.liferay.portal.model.ModelListener;
36  import com.liferay.portal.service.persistence.BatchSessionUtil;
37  import com.liferay.portal.service.persistence.ResourcePersistence;
38  import com.liferay.portal.service.persistence.UserPersistence;
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 java.io.Serializable;
47  
48  import java.util.ArrayList;
49  import java.util.Collections;
50  import java.util.List;
51  
52  /**
53   * <a href="ExpandoValuePersistenceImpl.java.html"><b><i>View Source</i></b></a>
54   *
55   * <p>
56   * ServiceBuilder generated this class. Modifications in this class will be
57   * overwritten the next time is generated.
58   * </p>
59   *
60   * @author    Brian Wing Shun Chan
61   * @see       ExpandoValuePersistence
62   * @see       ExpandoValueUtil
63   * @generated
64   */
65  public class ExpandoValuePersistenceImpl extends BasePersistenceImpl<ExpandoValue>
66      implements ExpandoValuePersistence {
67      public static final String FINDER_CLASS_NAME_ENTITY = ExpandoValueImpl.class.getName();
68      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
69          ".List";
70      public static final FinderPath FINDER_PATH_FIND_BY_TABLEID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
71              ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
72              "findByTableId", new String[] { Long.class.getName() });
73      public static final FinderPath FINDER_PATH_FIND_BY_OBC_TABLEID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
74              ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
75              "findByTableId",
76              new String[] {
77                  Long.class.getName(),
78                  
79              "java.lang.Integer", "java.lang.Integer",
80                  "com.liferay.portal.kernel.util.OrderByComparator"
81              });
82      public static final FinderPath FINDER_PATH_COUNT_BY_TABLEID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
83              ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
84              "countByTableId", new String[] { Long.class.getName() });
85      public static final FinderPath FINDER_PATH_FIND_BY_COLUMNID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
86              ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
87              "findByColumnId", new String[] { Long.class.getName() });
88      public static final FinderPath FINDER_PATH_FIND_BY_OBC_COLUMNID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
89              ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
90              "findByColumnId",
91              new String[] {
92                  Long.class.getName(),
93                  
94              "java.lang.Integer", "java.lang.Integer",
95                  "com.liferay.portal.kernel.util.OrderByComparator"
96              });
97      public static final FinderPath FINDER_PATH_COUNT_BY_COLUMNID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
98              ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
99              "countByColumnId", new String[] { Long.class.getName() });
100     public static final FinderPath FINDER_PATH_FIND_BY_ROWID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
101             ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
102             "findByRowId", new String[] { Long.class.getName() });
103     public static final FinderPath FINDER_PATH_FIND_BY_OBC_ROWID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
104             ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
105             "findByRowId",
106             new String[] {
107                 Long.class.getName(),
108                 
109             "java.lang.Integer", "java.lang.Integer",
110                 "com.liferay.portal.kernel.util.OrderByComparator"
111             });
112     public static final FinderPath FINDER_PATH_COUNT_BY_ROWID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
113             ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
114             "countByRowId", new String[] { Long.class.getName() });
115     public static final FinderPath FINDER_PATH_FIND_BY_T_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
116             ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
117             "findByT_C",
118             new String[] { Long.class.getName(), Long.class.getName() });
119     public static final FinderPath FINDER_PATH_FIND_BY_OBC_T_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
120             ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
121             "findByT_C",
122             new String[] {
123                 Long.class.getName(), Long.class.getName(),
124                 
125             "java.lang.Integer", "java.lang.Integer",
126                 "com.liferay.portal.kernel.util.OrderByComparator"
127             });
128     public static final FinderPath FINDER_PATH_COUNT_BY_T_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
129             ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
130             "countByT_C",
131             new String[] { Long.class.getName(), Long.class.getName() });
132     public static final FinderPath FINDER_PATH_FIND_BY_T_CPK = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
133             ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
134             "findByT_CPK",
135             new String[] { Long.class.getName(), Long.class.getName() });
136     public static final FinderPath FINDER_PATH_FIND_BY_OBC_T_CPK = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
137             ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
138             "findByT_CPK",
139             new String[] {
140                 Long.class.getName(), Long.class.getName(),
141                 
142             "java.lang.Integer", "java.lang.Integer",
143                 "com.liferay.portal.kernel.util.OrderByComparator"
144             });
145     public static final FinderPath FINDER_PATH_COUNT_BY_T_CPK = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
146             ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
147             "countByT_CPK",
148             new String[] { Long.class.getName(), Long.class.getName() });
149     public static final FinderPath FINDER_PATH_FIND_BY_T_R = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
150             ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
151             "findByT_R",
152             new String[] { Long.class.getName(), Long.class.getName() });
153     public static final FinderPath FINDER_PATH_FIND_BY_OBC_T_R = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
154             ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
155             "findByT_R",
156             new String[] {
157                 Long.class.getName(), Long.class.getName(),
158                 
159             "java.lang.Integer", "java.lang.Integer",
160                 "com.liferay.portal.kernel.util.OrderByComparator"
161             });
162     public static final FinderPath FINDER_PATH_COUNT_BY_T_R = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
163             ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
164             "countByT_R",
165             new String[] { Long.class.getName(), Long.class.getName() });
166     public static final FinderPath FINDER_PATH_FETCH_BY_C_R = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
167             ExpandoValueModelImpl.FINDER_CACHE_ENABLED,
168             FINDER_CLASS_NAME_ENTITY, "fetchByC_R",
169             new String[] { Long.class.getName(), Long.class.getName() });
170     public static final FinderPath FINDER_PATH_COUNT_BY_C_R = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
171             ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
172             "countByC_R",
173             new String[] { Long.class.getName(), Long.class.getName() });
174     public static final FinderPath FINDER_PATH_FIND_BY_C_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
175             ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
176             "findByC_C",
177             new String[] { Long.class.getName(), Long.class.getName() });
178     public static final FinderPath FINDER_PATH_FIND_BY_OBC_C_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
179             ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
180             "findByC_C",
181             new String[] {
182                 Long.class.getName(), Long.class.getName(),
183                 
184             "java.lang.Integer", "java.lang.Integer",
185                 "com.liferay.portal.kernel.util.OrderByComparator"
186             });
187     public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
188             ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
189             "countByC_C",
190             new String[] { Long.class.getName(), Long.class.getName() });
191     public static final FinderPath FINDER_PATH_FETCH_BY_T_C_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
192             ExpandoValueModelImpl.FINDER_CACHE_ENABLED,
193             FINDER_CLASS_NAME_ENTITY, "fetchByT_C_C",
194             new String[] {
195                 Long.class.getName(), Long.class.getName(), Long.class.getName()
196             });
197     public static final FinderPath FINDER_PATH_COUNT_BY_T_C_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
198             ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
199             "countByT_C_C",
200             new String[] {
201                 Long.class.getName(), Long.class.getName(), Long.class.getName()
202             });
203     public static final FinderPath FINDER_PATH_FIND_BY_T_C_D = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
204             ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
205             "findByT_C_D",
206             new String[] {
207                 Long.class.getName(), Long.class.getName(),
208                 String.class.getName()
209             });
210     public static final FinderPath FINDER_PATH_FIND_BY_OBC_T_C_D = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
211             ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
212             "findByT_C_D",
213             new String[] {
214                 Long.class.getName(), Long.class.getName(),
215                 String.class.getName(),
216                 
217             "java.lang.Integer", "java.lang.Integer",
218                 "com.liferay.portal.kernel.util.OrderByComparator"
219             });
220     public static final FinderPath FINDER_PATH_COUNT_BY_T_C_D = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
221             ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
222             "countByT_C_D",
223             new String[] {
224                 Long.class.getName(), Long.class.getName(),
225                 String.class.getName()
226             });
227     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
228             ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
229             "findAll", new String[0]);
230     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
231             ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
232             "countAll", new String[0]);
233 
234     public void cacheResult(ExpandoValue expandoValue) {
235         EntityCacheUtil.putResult(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
236             ExpandoValueImpl.class, expandoValue.getPrimaryKey(), expandoValue);
237 
238         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R,
239             new Object[] {
240                 new Long(expandoValue.getColumnId()),
241                 new Long(expandoValue.getRowId())
242             }, expandoValue);
243 
244         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C_C,
245             new Object[] {
246                 new Long(expandoValue.getTableId()),
247                 new Long(expandoValue.getColumnId()),
248                 new Long(expandoValue.getClassPK())
249             }, expandoValue);
250     }
251 
252     public void cacheResult(List<ExpandoValue> expandoValues) {
253         for (ExpandoValue expandoValue : expandoValues) {
254             if (EntityCacheUtil.getResult(
255                         ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
256                         ExpandoValueImpl.class, expandoValue.getPrimaryKey(),
257                         this) == null) {
258                 cacheResult(expandoValue);
259             }
260         }
261     }
262 
263     public void clearCache() {
264         CacheRegistry.clear(ExpandoValueImpl.class.getName());
265         EntityCacheUtil.clearCache(ExpandoValueImpl.class.getName());
266         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
267         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
268     }
269 
270     public ExpandoValue create(long valueId) {
271         ExpandoValue expandoValue = new ExpandoValueImpl();
272 
273         expandoValue.setNew(true);
274         expandoValue.setPrimaryKey(valueId);
275 
276         return expandoValue;
277     }
278 
279     public ExpandoValue remove(Serializable primaryKey)
280         throws NoSuchModelException, SystemException {
281         return remove(((Long)primaryKey).longValue());
282     }
283 
284     public ExpandoValue remove(long valueId)
285         throws NoSuchValueException, SystemException {
286         Session session = null;
287 
288         try {
289             session = openSession();
290 
291             ExpandoValue expandoValue = (ExpandoValue)session.get(ExpandoValueImpl.class,
292                     new Long(valueId));
293 
294             if (expandoValue == null) {
295                 if (_log.isWarnEnabled()) {
296                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + valueId);
297                 }
298 
299                 throw new NoSuchValueException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
300                     valueId);
301             }
302 
303             return remove(expandoValue);
304         }
305         catch (NoSuchValueException nsee) {
306             throw nsee;
307         }
308         catch (Exception e) {
309             throw processException(e);
310         }
311         finally {
312             closeSession(session);
313         }
314     }
315 
316     public ExpandoValue remove(ExpandoValue expandoValue)
317         throws SystemException {
318         for (ModelListener<ExpandoValue> listener : listeners) {
319             listener.onBeforeRemove(expandoValue);
320         }
321 
322         expandoValue = removeImpl(expandoValue);
323 
324         for (ModelListener<ExpandoValue> listener : listeners) {
325             listener.onAfterRemove(expandoValue);
326         }
327 
328         return expandoValue;
329     }
330 
331     protected ExpandoValue removeImpl(ExpandoValue expandoValue)
332         throws SystemException {
333         expandoValue = toUnwrappedModel(expandoValue);
334 
335         Session session = null;
336 
337         try {
338             session = openSession();
339 
340             if (expandoValue.isCachedModel() || BatchSessionUtil.isEnabled()) {
341                 Object staleObject = session.get(ExpandoValueImpl.class,
342                         expandoValue.getPrimaryKeyObj());
343 
344                 if (staleObject != null) {
345                     session.evict(staleObject);
346                 }
347             }
348 
349             session.delete(expandoValue);
350 
351             session.flush();
352         }
353         catch (Exception e) {
354             throw processException(e);
355         }
356         finally {
357             closeSession(session);
358         }
359 
360         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
361 
362         ExpandoValueModelImpl expandoValueModelImpl = (ExpandoValueModelImpl)expandoValue;
363 
364         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_R,
365             new Object[] {
366                 new Long(expandoValueModelImpl.getOriginalColumnId()),
367                 new Long(expandoValueModelImpl.getOriginalRowId())
368             });
369 
370         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C_C,
371             new Object[] {
372                 new Long(expandoValueModelImpl.getOriginalTableId()),
373                 new Long(expandoValueModelImpl.getOriginalColumnId()),
374                 new Long(expandoValueModelImpl.getOriginalClassPK())
375             });
376 
377         EntityCacheUtil.removeResult(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
378             ExpandoValueImpl.class, expandoValue.getPrimaryKey());
379 
380         return expandoValue;
381     }
382 
383     /**
384      * @deprecated Use {@link BasePersistence#update(com.liferay.portal.model.BaseModel, boolean)}.
385      */
386     public ExpandoValue update(ExpandoValue expandoValue)
387         throws SystemException {
388         if (_log.isWarnEnabled()) {
389             _log.warn(
390                 "Using the deprecated update(ExpandoValue expandoValue) method. Use update(ExpandoValue expandoValue, boolean merge) instead.");
391         }
392 
393         return update(expandoValue, false);
394     }
395 
396     public ExpandoValue updateImpl(
397         com.liferay.portlet.expando.model.ExpandoValue expandoValue,
398         boolean merge) throws SystemException {
399         expandoValue = toUnwrappedModel(expandoValue);
400 
401         boolean isNew = expandoValue.isNew();
402 
403         ExpandoValueModelImpl expandoValueModelImpl = (ExpandoValueModelImpl)expandoValue;
404 
405         Session session = null;
406 
407         try {
408             session = openSession();
409 
410             BatchSessionUtil.update(session, expandoValue, merge);
411 
412             expandoValue.setNew(false);
413         }
414         catch (Exception e) {
415             throw processException(e);
416         }
417         finally {
418             closeSession(session);
419         }
420 
421         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
422 
423         EntityCacheUtil.putResult(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
424             ExpandoValueImpl.class, expandoValue.getPrimaryKey(), expandoValue);
425 
426         if (!isNew &&
427                 ((expandoValue.getColumnId() != expandoValueModelImpl.getOriginalColumnId()) ||
428                 (expandoValue.getRowId() != expandoValueModelImpl.getOriginalRowId()))) {
429             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_R,
430                 new Object[] {
431                     new Long(expandoValueModelImpl.getOriginalColumnId()),
432                     new Long(expandoValueModelImpl.getOriginalRowId())
433                 });
434         }
435 
436         if (isNew ||
437                 ((expandoValue.getColumnId() != expandoValueModelImpl.getOriginalColumnId()) ||
438                 (expandoValue.getRowId() != expandoValueModelImpl.getOriginalRowId()))) {
439             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R,
440                 new Object[] {
441                     new Long(expandoValue.getColumnId()),
442                     new Long(expandoValue.getRowId())
443                 }, expandoValue);
444         }
445 
446         if (!isNew &&
447                 ((expandoValue.getTableId() != expandoValueModelImpl.getOriginalTableId()) ||
448                 (expandoValue.getColumnId() != expandoValueModelImpl.getOriginalColumnId()) ||
449                 (expandoValue.getClassPK() != expandoValueModelImpl.getOriginalClassPK()))) {
450             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C_C,
451                 new Object[] {
452                     new Long(expandoValueModelImpl.getOriginalTableId()),
453                     new Long(expandoValueModelImpl.getOriginalColumnId()),
454                     new Long(expandoValueModelImpl.getOriginalClassPK())
455                 });
456         }
457 
458         if (isNew ||
459                 ((expandoValue.getTableId() != expandoValueModelImpl.getOriginalTableId()) ||
460                 (expandoValue.getColumnId() != expandoValueModelImpl.getOriginalColumnId()) ||
461                 (expandoValue.getClassPK() != expandoValueModelImpl.getOriginalClassPK()))) {
462             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C_C,
463                 new Object[] {
464                     new Long(expandoValue.getTableId()),
465                     new Long(expandoValue.getColumnId()),
466                     new Long(expandoValue.getClassPK())
467                 }, expandoValue);
468         }
469 
470         return expandoValue;
471     }
472 
473     protected ExpandoValue toUnwrappedModel(ExpandoValue expandoValue) {
474         if (expandoValue instanceof ExpandoValueImpl) {
475             return expandoValue;
476         }
477 
478         ExpandoValueImpl expandoValueImpl = new ExpandoValueImpl();
479 
480         expandoValueImpl.setNew(expandoValue.isNew());
481         expandoValueImpl.setPrimaryKey(expandoValue.getPrimaryKey());
482 
483         expandoValueImpl.setValueId(expandoValue.getValueId());
484         expandoValueImpl.setCompanyId(expandoValue.getCompanyId());
485         expandoValueImpl.setTableId(expandoValue.getTableId());
486         expandoValueImpl.setColumnId(expandoValue.getColumnId());
487         expandoValueImpl.setRowId(expandoValue.getRowId());
488         expandoValueImpl.setClassNameId(expandoValue.getClassNameId());
489         expandoValueImpl.setClassPK(expandoValue.getClassPK());
490         expandoValueImpl.setData(expandoValue.getData());
491 
492         return expandoValueImpl;
493     }
494 
495     public ExpandoValue findByPrimaryKey(Serializable primaryKey)
496         throws NoSuchModelException, SystemException {
497         return findByPrimaryKey(((Long)primaryKey).longValue());
498     }
499 
500     public ExpandoValue findByPrimaryKey(long valueId)
501         throws NoSuchValueException, SystemException {
502         ExpandoValue expandoValue = fetchByPrimaryKey(valueId);
503 
504         if (expandoValue == null) {
505             if (_log.isWarnEnabled()) {
506                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + valueId);
507             }
508 
509             throw new NoSuchValueException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
510                 valueId);
511         }
512 
513         return expandoValue;
514     }
515 
516     public ExpandoValue fetchByPrimaryKey(Serializable primaryKey)
517         throws SystemException {
518         return fetchByPrimaryKey(((Long)primaryKey).longValue());
519     }
520 
521     public ExpandoValue fetchByPrimaryKey(long valueId)
522         throws SystemException {
523         ExpandoValue expandoValue = (ExpandoValue)EntityCacheUtil.getResult(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
524                 ExpandoValueImpl.class, valueId, this);
525 
526         if (expandoValue == null) {
527             Session session = null;
528 
529             try {
530                 session = openSession();
531 
532                 expandoValue = (ExpandoValue)session.get(ExpandoValueImpl.class,
533                         new Long(valueId));
534             }
535             catch (Exception e) {
536                 throw processException(e);
537             }
538             finally {
539                 if (expandoValue != null) {
540                     cacheResult(expandoValue);
541                 }
542 
543                 closeSession(session);
544             }
545         }
546 
547         return expandoValue;
548     }
549 
550     public List<ExpandoValue> findByTableId(long tableId)
551         throws SystemException {
552         Object[] finderArgs = new Object[] { new Long(tableId) };
553 
554         List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_TABLEID,
555                 finderArgs, this);
556 
557         if (list == null) {
558             Session session = null;
559 
560             try {
561                 session = openSession();
562 
563                 StringBundler query = new StringBundler(3);
564 
565                 query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
566 
567                 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
568 
569                 query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
570 
571                 String sql = query.toString();
572 
573                 Query q = session.createQuery(sql);
574 
575                 QueryPos qPos = QueryPos.getInstance(q);
576 
577                 qPos.add(tableId);
578 
579                 list = q.list();
580             }
581             catch (Exception e) {
582                 throw processException(e);
583             }
584             finally {
585                 if (list == null) {
586                     list = new ArrayList<ExpandoValue>();
587                 }
588 
589                 cacheResult(list);
590 
591                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_TABLEID,
592                     finderArgs, list);
593 
594                 closeSession(session);
595             }
596         }
597 
598         return list;
599     }
600 
601     public List<ExpandoValue> findByTableId(long tableId, int start, int end)
602         throws SystemException {
603         return findByTableId(tableId, start, end, null);
604     }
605 
606     public List<ExpandoValue> findByTableId(long tableId, int start, int end,
607         OrderByComparator orderByComparator) throws SystemException {
608         Object[] finderArgs = new Object[] {
609                 new Long(tableId),
610                 
611                 String.valueOf(start), String.valueOf(end),
612                 String.valueOf(orderByComparator)
613             };
614 
615         List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_TABLEID,
616                 finderArgs, this);
617 
618         if (list == null) {
619             Session session = null;
620 
621             try {
622                 session = openSession();
623 
624                 StringBundler query = null;
625 
626                 if (orderByComparator != null) {
627                     query = new StringBundler(3 +
628                             (orderByComparator.getOrderByFields().length * 3));
629                 }
630                 else {
631                     query = new StringBundler(3);
632                 }
633 
634                 query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
635 
636                 query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
637 
638                 if (orderByComparator != null) {
639                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
640                         orderByComparator);
641                 }
642 
643                 else {
644                     query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
645                 }
646 
647                 String sql = query.toString();
648 
649                 Query q = session.createQuery(sql);
650 
651                 QueryPos qPos = QueryPos.getInstance(q);
652 
653                 qPos.add(tableId);
654 
655                 list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
656                         start, end);
657             }
658             catch (Exception e) {
659                 throw processException(e);
660             }
661             finally {
662                 if (list == null) {
663                     list = new ArrayList<ExpandoValue>();
664                 }
665 
666                 cacheResult(list);
667 
668                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_TABLEID,
669                     finderArgs, list);
670 
671                 closeSession(session);
672             }
673         }
674 
675         return list;
676     }
677 
678     public ExpandoValue findByTableId_First(long tableId,
679         OrderByComparator orderByComparator)
680         throws NoSuchValueException, SystemException {
681         List<ExpandoValue> list = findByTableId(tableId, 0, 1, orderByComparator);
682 
683         if (list.isEmpty()) {
684             StringBundler msg = new StringBundler(4);
685 
686             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
687 
688             msg.append("tableId=");
689             msg.append(tableId);
690 
691             msg.append(StringPool.CLOSE_CURLY_BRACE);
692 
693             throw new NoSuchValueException(msg.toString());
694         }
695         else {
696             return list.get(0);
697         }
698     }
699 
700     public ExpandoValue findByTableId_Last(long tableId,
701         OrderByComparator orderByComparator)
702         throws NoSuchValueException, SystemException {
703         int count = countByTableId(tableId);
704 
705         List<ExpandoValue> list = findByTableId(tableId, count - 1, count,
706                 orderByComparator);
707 
708         if (list.isEmpty()) {
709             StringBundler msg = new StringBundler(4);
710 
711             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
712 
713             msg.append("tableId=");
714             msg.append(tableId);
715 
716             msg.append(StringPool.CLOSE_CURLY_BRACE);
717 
718             throw new NoSuchValueException(msg.toString());
719         }
720         else {
721             return list.get(0);
722         }
723     }
724 
725     public ExpandoValue[] findByTableId_PrevAndNext(long valueId, long tableId,
726         OrderByComparator orderByComparator)
727         throws NoSuchValueException, SystemException {
728         ExpandoValue expandoValue = findByPrimaryKey(valueId);
729 
730         int count = countByTableId(tableId);
731 
732         Session session = null;
733 
734         try {
735             session = openSession();
736 
737             StringBundler query = null;
738 
739             if (orderByComparator != null) {
740                 query = new StringBundler(3 +
741                         (orderByComparator.getOrderByFields().length * 3));
742             }
743             else {
744                 query = new StringBundler(3);
745             }
746 
747             query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
748 
749             query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
750 
751             if (orderByComparator != null) {
752                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
753                     orderByComparator);
754             }
755 
756             else {
757                 query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
758             }
759 
760             String sql = query.toString();
761 
762             Query q = session.createQuery(sql);
763 
764             QueryPos qPos = QueryPos.getInstance(q);
765 
766             qPos.add(tableId);
767 
768             Object[] objArray = QueryUtil.getPrevAndNext(q, count,
769                     orderByComparator, expandoValue);
770 
771             ExpandoValue[] array = new ExpandoValueImpl[3];
772 
773             array[0] = (ExpandoValue)objArray[0];
774             array[1] = (ExpandoValue)objArray[1];
775             array[2] = (ExpandoValue)objArray[2];
776 
777             return array;
778         }
779         catch (Exception e) {
780             throw processException(e);
781         }
782         finally {
783             closeSession(session);
784         }
785     }
786 
787     public List<ExpandoValue> findByColumnId(long columnId)
788         throws SystemException {
789         Object[] finderArgs = new Object[] { new Long(columnId) };
790 
791         List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COLUMNID,
792                 finderArgs, this);
793 
794         if (list == null) {
795             Session session = null;
796 
797             try {
798                 session = openSession();
799 
800                 StringBundler query = new StringBundler(3);
801 
802                 query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
803 
804                 query.append(_FINDER_COLUMN_COLUMNID_COLUMNID_2);
805 
806                 query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
807 
808                 String sql = query.toString();
809 
810                 Query q = session.createQuery(sql);
811 
812                 QueryPos qPos = QueryPos.getInstance(q);
813 
814                 qPos.add(columnId);
815 
816                 list = q.list();
817             }
818             catch (Exception e) {
819                 throw processException(e);
820             }
821             finally {
822                 if (list == null) {
823                     list = new ArrayList<ExpandoValue>();
824                 }
825 
826                 cacheResult(list);
827 
828                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COLUMNID,
829                     finderArgs, list);
830 
831                 closeSession(session);
832             }
833         }
834 
835         return list;
836     }
837 
838     public List<ExpandoValue> findByColumnId(long columnId, int start, int end)
839         throws SystemException {
840         return findByColumnId(columnId, start, end, null);
841     }
842 
843     public List<ExpandoValue> findByColumnId(long columnId, int start, int end,
844         OrderByComparator orderByComparator) throws SystemException {
845         Object[] finderArgs = new Object[] {
846                 new Long(columnId),
847                 
848                 String.valueOf(start), String.valueOf(end),
849                 String.valueOf(orderByComparator)
850             };
851 
852         List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_COLUMNID,
853                 finderArgs, this);
854 
855         if (list == null) {
856             Session session = null;
857 
858             try {
859                 session = openSession();
860 
861                 StringBundler query = null;
862 
863                 if (orderByComparator != null) {
864                     query = new StringBundler(3 +
865                             (orderByComparator.getOrderByFields().length * 3));
866                 }
867                 else {
868                     query = new StringBundler(3);
869                 }
870 
871                 query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
872 
873                 query.append(_FINDER_COLUMN_COLUMNID_COLUMNID_2);
874 
875                 if (orderByComparator != null) {
876                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
877                         orderByComparator);
878                 }
879 
880                 else {
881                     query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
882                 }
883 
884                 String sql = query.toString();
885 
886                 Query q = session.createQuery(sql);
887 
888                 QueryPos qPos = QueryPos.getInstance(q);
889 
890                 qPos.add(columnId);
891 
892                 list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
893                         start, end);
894             }
895             catch (Exception e) {
896                 throw processException(e);
897             }
898             finally {
899                 if (list == null) {
900                     list = new ArrayList<ExpandoValue>();
901                 }
902 
903                 cacheResult(list);
904 
905                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_COLUMNID,
906                     finderArgs, list);
907 
908                 closeSession(session);
909             }
910         }
911 
912         return list;
913     }
914 
915     public ExpandoValue findByColumnId_First(long columnId,
916         OrderByComparator orderByComparator)
917         throws NoSuchValueException, SystemException {
918         List<ExpandoValue> list = findByColumnId(columnId, 0, 1,
919                 orderByComparator);
920 
921         if (list.isEmpty()) {
922             StringBundler msg = new StringBundler(4);
923 
924             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
925 
926             msg.append("columnId=");
927             msg.append(columnId);
928 
929             msg.append(StringPool.CLOSE_CURLY_BRACE);
930 
931             throw new NoSuchValueException(msg.toString());
932         }
933         else {
934             return list.get(0);
935         }
936     }
937 
938     public ExpandoValue findByColumnId_Last(long columnId,
939         OrderByComparator orderByComparator)
940         throws NoSuchValueException, SystemException {
941         int count = countByColumnId(columnId);
942 
943         List<ExpandoValue> list = findByColumnId(columnId, count - 1, count,
944                 orderByComparator);
945 
946         if (list.isEmpty()) {
947             StringBundler msg = new StringBundler(4);
948 
949             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
950 
951             msg.append("columnId=");
952             msg.append(columnId);
953 
954             msg.append(StringPool.CLOSE_CURLY_BRACE);
955 
956             throw new NoSuchValueException(msg.toString());
957         }
958         else {
959             return list.get(0);
960         }
961     }
962 
963     public ExpandoValue[] findByColumnId_PrevAndNext(long valueId,
964         long columnId, OrderByComparator orderByComparator)
965         throws NoSuchValueException, SystemException {
966         ExpandoValue expandoValue = findByPrimaryKey(valueId);
967 
968         int count = countByColumnId(columnId);
969 
970         Session session = null;
971 
972         try {
973             session = openSession();
974 
975             StringBundler query = null;
976 
977             if (orderByComparator != null) {
978                 query = new StringBundler(3 +
979                         (orderByComparator.getOrderByFields().length * 3));
980             }
981             else {
982                 query = new StringBundler(3);
983             }
984 
985             query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
986 
987             query.append(_FINDER_COLUMN_COLUMNID_COLUMNID_2);
988 
989             if (orderByComparator != null) {
990                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
991                     orderByComparator);
992             }
993 
994             else {
995                 query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
996             }
997 
998             String sql = query.toString();
999 
1000            Query q = session.createQuery(sql);
1001
1002            QueryPos qPos = QueryPos.getInstance(q);
1003
1004            qPos.add(columnId);
1005
1006            Object[] objArray = QueryUtil.getPrevAndNext(q, count,
1007                    orderByComparator, expandoValue);
1008
1009            ExpandoValue[] array = new ExpandoValueImpl[3];
1010
1011            array[0] = (ExpandoValue)objArray[0];
1012            array[1] = (ExpandoValue)objArray[1];
1013            array[2] = (ExpandoValue)objArray[2];
1014
1015            return array;
1016        }
1017        catch (Exception e) {
1018            throw processException(e);
1019        }
1020        finally {
1021            closeSession(session);
1022        }
1023    }
1024
1025    public List<ExpandoValue> findByRowId(long rowId) throws SystemException {
1026        Object[] finderArgs = new Object[] { new Long(rowId) };
1027
1028        List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ROWID,
1029                finderArgs, this);
1030
1031        if (list == null) {
1032            Session session = null;
1033
1034            try {
1035                session = openSession();
1036
1037                StringBundler query = new StringBundler(3);
1038
1039                query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1040
1041                query.append(_FINDER_COLUMN_ROWID_ROWID_2);
1042
1043                query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1044
1045                String sql = query.toString();
1046
1047                Query q = session.createQuery(sql);
1048
1049                QueryPos qPos = QueryPos.getInstance(q);
1050
1051                qPos.add(rowId);
1052
1053                list = q.list();
1054            }
1055            catch (Exception e) {
1056                throw processException(e);
1057            }
1058            finally {
1059                if (list == null) {
1060                    list = new ArrayList<ExpandoValue>();
1061                }
1062
1063                cacheResult(list);
1064
1065                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ROWID,
1066                    finderArgs, list);
1067
1068                closeSession(session);
1069            }
1070        }
1071
1072        return list;
1073    }
1074
1075    public List<ExpandoValue> findByRowId(long rowId, int start, int end)
1076        throws SystemException {
1077        return findByRowId(rowId, start, end, null);
1078    }
1079
1080    public List<ExpandoValue> findByRowId(long rowId, int start, int end,
1081        OrderByComparator orderByComparator) throws SystemException {
1082        Object[] finderArgs = new Object[] {
1083                new Long(rowId),
1084                
1085                String.valueOf(start), String.valueOf(end),
1086                String.valueOf(orderByComparator)
1087            };
1088
1089        List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_ROWID,
1090                finderArgs, this);
1091
1092        if (list == null) {
1093            Session session = null;
1094
1095            try {
1096                session = openSession();
1097
1098                StringBundler query = null;
1099
1100                if (orderByComparator != null) {
1101                    query = new StringBundler(3 +
1102                            (orderByComparator.getOrderByFields().length * 3));
1103                }
1104                else {
1105                    query = new StringBundler(3);
1106                }
1107
1108                query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1109
1110                query.append(_FINDER_COLUMN_ROWID_ROWID_2);
1111
1112                if (orderByComparator != null) {
1113                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1114                        orderByComparator);
1115                }
1116
1117                else {
1118                    query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1119                }
1120
1121                String sql = query.toString();
1122
1123                Query q = session.createQuery(sql);
1124
1125                QueryPos qPos = QueryPos.getInstance(q);
1126
1127                qPos.add(rowId);
1128
1129                list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
1130                        start, end);
1131            }
1132            catch (Exception e) {
1133                throw processException(e);
1134            }
1135            finally {
1136                if (list == null) {
1137                    list = new ArrayList<ExpandoValue>();
1138                }
1139
1140                cacheResult(list);
1141
1142                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_ROWID,
1143                    finderArgs, list);
1144
1145                closeSession(session);
1146            }
1147        }
1148
1149        return list;
1150    }
1151
1152    public ExpandoValue findByRowId_First(long rowId,
1153        OrderByComparator orderByComparator)
1154        throws NoSuchValueException, SystemException {
1155        List<ExpandoValue> list = findByRowId(rowId, 0, 1, orderByComparator);
1156
1157        if (list.isEmpty()) {
1158            StringBundler msg = new StringBundler(4);
1159
1160            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1161
1162            msg.append("rowId=");
1163            msg.append(rowId);
1164
1165            msg.append(StringPool.CLOSE_CURLY_BRACE);
1166
1167            throw new NoSuchValueException(msg.toString());
1168        }
1169        else {
1170            return list.get(0);
1171        }
1172    }
1173
1174    public ExpandoValue findByRowId_Last(long rowId,
1175        OrderByComparator orderByComparator)
1176        throws NoSuchValueException, SystemException {
1177        int count = countByRowId(rowId);
1178
1179        List<ExpandoValue> list = findByRowId(rowId, count - 1, count,
1180                orderByComparator);
1181
1182        if (list.isEmpty()) {
1183            StringBundler msg = new StringBundler(4);
1184
1185            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1186
1187            msg.append("rowId=");
1188            msg.append(rowId);
1189
1190            msg.append(StringPool.CLOSE_CURLY_BRACE);
1191
1192            throw new NoSuchValueException(msg.toString());
1193        }
1194        else {
1195            return list.get(0);
1196        }
1197    }
1198
1199    public ExpandoValue[] findByRowId_PrevAndNext(long valueId, long rowId,
1200        OrderByComparator orderByComparator)
1201        throws NoSuchValueException, SystemException {
1202        ExpandoValue expandoValue = findByPrimaryKey(valueId);
1203
1204        int count = countByRowId(rowId);
1205
1206        Session session = null;
1207
1208        try {
1209            session = openSession();
1210
1211            StringBundler query = null;
1212
1213            if (orderByComparator != null) {
1214                query = new StringBundler(3 +
1215                        (orderByComparator.getOrderByFields().length * 3));
1216            }
1217            else {
1218                query = new StringBundler(3);
1219            }
1220
1221            query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1222
1223            query.append(_FINDER_COLUMN_ROWID_ROWID_2);
1224
1225            if (orderByComparator != null) {
1226                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1227                    orderByComparator);
1228            }
1229
1230            else {
1231                query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1232            }
1233
1234            String sql = query.toString();
1235
1236            Query q = session.createQuery(sql);
1237
1238            QueryPos qPos = QueryPos.getInstance(q);
1239
1240            qPos.add(rowId);
1241
1242            Object[] objArray = QueryUtil.getPrevAndNext(q, count,
1243                    orderByComparator, expandoValue);
1244
1245            ExpandoValue[] array = new ExpandoValueImpl[3];
1246
1247            array[0] = (ExpandoValue)objArray[0];
1248            array[1] = (ExpandoValue)objArray[1];
1249            array[2] = (ExpandoValue)objArray[2];
1250
1251            return array;
1252        }
1253        catch (Exception e) {
1254            throw processException(e);
1255        }
1256        finally {
1257            closeSession(session);
1258        }
1259    }
1260
1261    public List<ExpandoValue> findByT_C(long tableId, long columnId)
1262        throws SystemException {
1263        Object[] finderArgs = new Object[] { new Long(tableId), new Long(columnId) };
1264
1265        List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_T_C,
1266                finderArgs, this);
1267
1268        if (list == null) {
1269            Session session = null;
1270
1271            try {
1272                session = openSession();
1273
1274                StringBundler query = new StringBundler(4);
1275
1276                query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1277
1278                query.append(_FINDER_COLUMN_T_C_TABLEID_2);
1279
1280                query.append(_FINDER_COLUMN_T_C_COLUMNID_2);
1281
1282                query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1283
1284                String sql = query.toString();
1285
1286                Query q = session.createQuery(sql);
1287
1288                QueryPos qPos = QueryPos.getInstance(q);
1289
1290                qPos.add(tableId);
1291
1292                qPos.add(columnId);
1293
1294                list = q.list();
1295            }
1296            catch (Exception e) {
1297                throw processException(e);
1298            }
1299            finally {
1300                if (list == null) {
1301                    list = new ArrayList<ExpandoValue>();
1302                }
1303
1304                cacheResult(list);
1305
1306                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_T_C, finderArgs,
1307                    list);
1308
1309                closeSession(session);
1310            }
1311        }
1312
1313        return list;
1314    }
1315
1316    public List<ExpandoValue> findByT_C(long tableId, long columnId, int start,
1317        int end) throws SystemException {
1318        return findByT_C(tableId, columnId, start, end, null);
1319    }
1320
1321    public List<ExpandoValue> findByT_C(long tableId, long columnId, int start,
1322        int end, OrderByComparator orderByComparator) throws SystemException {
1323        Object[] finderArgs = new Object[] {
1324                new Long(tableId), new Long(columnId),
1325                
1326                String.valueOf(start), String.valueOf(end),
1327                String.valueOf(orderByComparator)
1328            };
1329
1330        List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_T_C,
1331                finderArgs, this);
1332
1333        if (list == null) {
1334            Session session = null;
1335
1336            try {
1337                session = openSession();
1338
1339                StringBundler query = null;
1340
1341                if (orderByComparator != null) {
1342                    query = new StringBundler(4 +
1343                            (orderByComparator.getOrderByFields().length * 3));
1344                }
1345                else {
1346                    query = new StringBundler(4);
1347                }
1348
1349                query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1350
1351                query.append(_FINDER_COLUMN_T_C_TABLEID_2);
1352
1353                query.append(_FINDER_COLUMN_T_C_COLUMNID_2);
1354
1355                if (orderByComparator != null) {
1356                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1357                        orderByComparator);
1358                }
1359
1360                else {
1361                    query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1362                }
1363
1364                String sql = query.toString();
1365
1366                Query q = session.createQuery(sql);
1367
1368                QueryPos qPos = QueryPos.getInstance(q);
1369
1370                qPos.add(tableId);
1371
1372                qPos.add(columnId);
1373
1374                list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
1375                        start, end);
1376            }
1377            catch (Exception e) {
1378                throw processException(e);
1379            }
1380            finally {
1381                if (list == null) {
1382                    list = new ArrayList<ExpandoValue>();
1383                }
1384
1385                cacheResult(list);
1386
1387                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_T_C,
1388                    finderArgs, list);
1389
1390                closeSession(session);
1391            }
1392        }
1393
1394        return list;
1395    }
1396
1397    public ExpandoValue findByT_C_First(long tableId, long columnId,
1398        OrderByComparator orderByComparator)
1399        throws NoSuchValueException, SystemException {
1400        List<ExpandoValue> list = findByT_C(tableId, columnId, 0, 1,
1401                orderByComparator);
1402
1403        if (list.isEmpty()) {
1404            StringBundler msg = new StringBundler(6);
1405
1406            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1407
1408            msg.append("tableId=");
1409            msg.append(tableId);
1410
1411            msg.append(", columnId=");
1412            msg.append(columnId);
1413
1414            msg.append(StringPool.CLOSE_CURLY_BRACE);
1415
1416            throw new NoSuchValueException(msg.toString());
1417        }
1418        else {
1419            return list.get(0);
1420        }
1421    }
1422
1423    public ExpandoValue findByT_C_Last(long tableId, long columnId,
1424        OrderByComparator orderByComparator)
1425        throws NoSuchValueException, SystemException {
1426        int count = countByT_C(tableId, columnId);
1427
1428        List<ExpandoValue> list = findByT_C(tableId, columnId, count - 1,
1429                count, orderByComparator);
1430
1431        if (list.isEmpty()) {
1432            StringBundler msg = new StringBundler(6);
1433
1434            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1435
1436            msg.append("tableId=");
1437            msg.append(tableId);
1438
1439            msg.append(", columnId=");
1440            msg.append(columnId);
1441
1442            msg.append(StringPool.CLOSE_CURLY_BRACE);
1443
1444            throw new NoSuchValueException(msg.toString());
1445        }
1446        else {
1447            return list.get(0);
1448        }
1449    }
1450
1451    public ExpandoValue[] findByT_C_PrevAndNext(long valueId, long tableId,
1452        long columnId, OrderByComparator orderByComparator)
1453        throws NoSuchValueException, SystemException {
1454        ExpandoValue expandoValue = findByPrimaryKey(valueId);
1455
1456        int count = countByT_C(tableId, columnId);
1457
1458        Session session = null;
1459
1460        try {
1461            session = openSession();
1462
1463            StringBundler query = null;
1464
1465            if (orderByComparator != null) {
1466                query = new StringBundler(4 +
1467                        (orderByComparator.getOrderByFields().length * 3));
1468            }
1469            else {
1470                query = new StringBundler(4);
1471            }
1472
1473            query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1474
1475            query.append(_FINDER_COLUMN_T_C_TABLEID_2);
1476
1477            query.append(_FINDER_COLUMN_T_C_COLUMNID_2);
1478
1479            if (orderByComparator != null) {
1480                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1481                    orderByComparator);
1482            }
1483
1484            else {
1485                query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1486            }
1487
1488            String sql = query.toString();
1489
1490            Query q = session.createQuery(sql);
1491
1492            QueryPos qPos = QueryPos.getInstance(q);
1493
1494            qPos.add(tableId);
1495
1496            qPos.add(columnId);
1497
1498            Object[] objArray = QueryUtil.getPrevAndNext(q, count,
1499                    orderByComparator, expandoValue);
1500
1501            ExpandoValue[] array = new ExpandoValueImpl[3];
1502
1503            array[0] = (ExpandoValue)objArray[0];
1504            array[1] = (ExpandoValue)objArray[1];
1505            array[2] = (ExpandoValue)objArray[2];
1506
1507            return array;
1508        }
1509        catch (Exception e) {
1510            throw processException(e);
1511        }
1512        finally {
1513            closeSession(session);
1514        }
1515    }
1516
1517    public List<ExpandoValue> findByT_CPK(long tableId, long classPK)
1518        throws SystemException {
1519        Object[] finderArgs = new Object[] { new Long(tableId), new Long(classPK) };
1520
1521        List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_T_CPK,
1522                finderArgs, this);
1523
1524        if (list == null) {
1525            Session session = null;
1526
1527            try {
1528                session = openSession();
1529
1530                StringBundler query = new StringBundler(4);
1531
1532                query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1533
1534                query.append(_FINDER_COLUMN_T_CPK_TABLEID_2);
1535
1536                query.append(_FINDER_COLUMN_T_CPK_CLASSPK_2);
1537
1538                query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1539
1540                String sql = query.toString();
1541
1542                Query q = session.createQuery(sql);
1543
1544                QueryPos qPos = QueryPos.getInstance(q);
1545
1546                qPos.add(tableId);
1547
1548                qPos.add(classPK);
1549
1550                list = q.list();
1551            }
1552            catch (Exception e) {
1553                throw processException(e);
1554            }
1555            finally {
1556                if (list == null) {
1557                    list = new ArrayList<ExpandoValue>();
1558                }
1559
1560                cacheResult(list);
1561
1562                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_T_CPK,
1563                    finderArgs, list);
1564
1565                closeSession(session);
1566            }
1567        }
1568
1569        return list;
1570    }
1571
1572    public List<ExpandoValue> findByT_CPK(long tableId, long classPK,
1573        int start, int end) throws SystemException {
1574        return findByT_CPK(tableId, classPK, start, end, null);
1575    }
1576
1577    public List<ExpandoValue> findByT_CPK(long tableId, long classPK,
1578        int start, int end, OrderByComparator orderByComparator)
1579        throws SystemException {
1580        Object[] finderArgs = new Object[] {
1581                new Long(tableId), new Long(classPK),
1582                
1583                String.valueOf(start), String.valueOf(end),
1584                String.valueOf(orderByComparator)
1585            };
1586
1587        List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_T_CPK,
1588                finderArgs, this);
1589
1590        if (list == null) {
1591            Session session = null;
1592
1593            try {
1594                session = openSession();
1595
1596                StringBundler query = null;
1597
1598                if (orderByComparator != null) {
1599                    query = new StringBundler(4 +
1600                            (orderByComparator.getOrderByFields().length * 3));
1601                }
1602                else {
1603                    query = new StringBundler(4);
1604                }
1605
1606                query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1607
1608                query.append(_FINDER_COLUMN_T_CPK_TABLEID_2);
1609
1610                query.append(_FINDER_COLUMN_T_CPK_CLASSPK_2);
1611
1612                if (orderByComparator != null) {
1613                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1614                        orderByComparator);
1615                }
1616
1617                else {
1618                    query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1619                }
1620
1621                String sql = query.toString();
1622
1623                Query q = session.createQuery(sql);
1624
1625                QueryPos qPos = QueryPos.getInstance(q);
1626
1627                qPos.add(tableId);
1628
1629                qPos.add(classPK);
1630
1631                list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
1632                        start, end);
1633            }
1634            catch (Exception e) {
1635                throw processException(e);
1636            }
1637            finally {
1638                if (list == null) {
1639                    list = new ArrayList<ExpandoValue>();
1640                }
1641
1642                cacheResult(list);
1643
1644                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_T_CPK,
1645                    finderArgs, list);
1646
1647                closeSession(session);
1648            }
1649        }
1650
1651        return list;
1652    }
1653
1654    public ExpandoValue findByT_CPK_First(long tableId, long classPK,
1655        OrderByComparator orderByComparator)
1656        throws NoSuchValueException, SystemException {
1657        List<ExpandoValue> list = findByT_CPK(tableId, classPK, 0, 1,
1658                orderByComparator);
1659
1660        if (list.isEmpty()) {
1661            StringBundler msg = new StringBundler(6);
1662
1663            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1664
1665            msg.append("tableId=");
1666            msg.append(tableId);
1667
1668            msg.append(", classPK=");
1669            msg.append(classPK);
1670
1671            msg.append(StringPool.CLOSE_CURLY_BRACE);
1672
1673            throw new NoSuchValueException(msg.toString());
1674        }
1675        else {
1676            return list.get(0);
1677        }
1678    }
1679
1680    public ExpandoValue findByT_CPK_Last(long tableId, long classPK,
1681        OrderByComparator orderByComparator)
1682        throws NoSuchValueException, SystemException {
1683        int count = countByT_CPK(tableId, classPK);
1684
1685        List<ExpandoValue> list = findByT_CPK(tableId, classPK, count - 1,
1686                count, orderByComparator);
1687
1688        if (list.isEmpty()) {
1689            StringBundler msg = new StringBundler(6);
1690
1691            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1692
1693            msg.append("tableId=");
1694            msg.append(tableId);
1695
1696            msg.append(", classPK=");
1697            msg.append(classPK);
1698
1699            msg.append(StringPool.CLOSE_CURLY_BRACE);
1700
1701            throw new NoSuchValueException(msg.toString());
1702        }
1703        else {
1704            return list.get(0);
1705        }
1706    }
1707
1708    public ExpandoValue[] findByT_CPK_PrevAndNext(long valueId, long tableId,
1709        long classPK, OrderByComparator orderByComparator)
1710        throws NoSuchValueException, SystemException {
1711        ExpandoValue expandoValue = findByPrimaryKey(valueId);
1712
1713        int count = countByT_CPK(tableId, classPK);
1714
1715        Session session = null;
1716
1717        try {
1718            session = openSession();
1719
1720            StringBundler query = null;
1721
1722            if (orderByComparator != null) {
1723                query = new StringBundler(4 +
1724                        (orderByComparator.getOrderByFields().length * 3));
1725            }
1726            else {
1727                query = new StringBundler(4);
1728            }
1729
1730            query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1731
1732            query.append(_FINDER_COLUMN_T_CPK_TABLEID_2);
1733
1734            query.append(_FINDER_COLUMN_T_CPK_CLASSPK_2);
1735
1736            if (orderByComparator != null) {
1737                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1738                    orderByComparator);
1739            }
1740
1741            else {
1742                query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1743            }
1744
1745            String sql = query.toString();
1746
1747            Query q = session.createQuery(sql);
1748
1749            QueryPos qPos = QueryPos.getInstance(q);
1750
1751            qPos.add(tableId);
1752
1753            qPos.add(classPK);
1754
1755            Object[] objArray = QueryUtil.getPrevAndNext(q, count,
1756                    orderByComparator, expandoValue);
1757
1758            ExpandoValue[] array = new ExpandoValueImpl[3];
1759
1760            array[0] = (ExpandoValue)objArray[0];
1761            array[1] = (ExpandoValue)objArray[1];
1762            array[2] = (ExpandoValue)objArray[2];
1763
1764            return array;
1765        }
1766        catch (Exception e) {
1767            throw processException(e);
1768        }
1769        finally {
1770            closeSession(session);
1771        }
1772    }
1773
1774    public List<ExpandoValue> findByT_R(long tableId, long rowId)
1775        throws SystemException {
1776        Object[] finderArgs = new Object[] { new Long(tableId), new Long(rowId) };
1777
1778        List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_T_R,
1779                finderArgs, this);
1780
1781        if (list == null) {
1782            Session session = null;
1783
1784            try {
1785                session = openSession();
1786
1787                StringBundler query = new StringBundler(4);
1788
1789                query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1790
1791                query.append(_FINDER_COLUMN_T_R_TABLEID_2);
1792
1793                query.append(_FINDER_COLUMN_T_R_ROWID_2);
1794
1795                query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1796
1797                String sql = query.toString();
1798
1799                Query q = session.createQuery(sql);
1800
1801                QueryPos qPos = QueryPos.getInstance(q);
1802
1803                qPos.add(tableId);
1804
1805                qPos.add(rowId);
1806
1807                list = q.list();
1808            }
1809            catch (Exception e) {
1810                throw processException(e);
1811            }
1812            finally {
1813                if (list == null) {
1814                    list = new ArrayList<ExpandoValue>();
1815                }
1816
1817                cacheResult(list);
1818
1819                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_T_R, finderArgs,
1820                    list);
1821
1822                closeSession(session);
1823            }
1824        }
1825
1826        return list;
1827    }
1828
1829    public List<ExpandoValue> findByT_R(long tableId, long rowId, int start,
1830        int end) throws SystemException {
1831        return findByT_R(tableId, rowId, start, end, null);
1832    }
1833
1834    public List<ExpandoValue> findByT_R(long tableId, long rowId, int start,
1835        int end, OrderByComparator orderByComparator) throws SystemException {
1836        Object[] finderArgs = new Object[] {
1837                new Long(tableId), new Long(rowId),
1838                
1839                String.valueOf(start), String.valueOf(end),
1840                String.valueOf(orderByComparator)
1841            };
1842
1843        List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_T_R,
1844                finderArgs, this);
1845
1846        if (list == null) {
1847            Session session = null;
1848
1849            try {
1850                session = openSession();
1851
1852                StringBundler query = null;
1853
1854                if (orderByComparator != null) {
1855                    query = new StringBundler(4 +
1856                            (orderByComparator.getOrderByFields().length * 3));
1857                }
1858                else {
1859                    query = new StringBundler(4);
1860                }
1861
1862                query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1863
1864                query.append(_FINDER_COLUMN_T_R_TABLEID_2);
1865
1866                query.append(_FINDER_COLUMN_T_R_ROWID_2);
1867
1868                if (orderByComparator != null) {
1869                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1870                        orderByComparator);
1871                }
1872
1873                else {
1874                    query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1875                }
1876
1877                String sql = query.toString();
1878
1879                Query q = session.createQuery(sql);
1880
1881                QueryPos qPos = QueryPos.getInstance(q);
1882
1883                qPos.add(tableId);
1884
1885                qPos.add(rowId);
1886
1887                list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
1888                        start, end);
1889            }
1890            catch (Exception e) {
1891                throw processException(e);
1892            }
1893            finally {
1894                if (list == null) {
1895                    list = new ArrayList<ExpandoValue>();
1896                }
1897
1898                cacheResult(list);
1899
1900                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_T_R,
1901                    finderArgs, list);
1902
1903                closeSession(session);
1904            }
1905        }
1906
1907        return list;
1908    }
1909
1910    public ExpandoValue findByT_R_First(long tableId, long rowId,
1911        OrderByComparator orderByComparator)
1912        throws NoSuchValueException, SystemException {
1913        List<ExpandoValue> list = findByT_R(tableId, rowId, 0, 1,
1914                orderByComparator);
1915
1916        if (list.isEmpty()) {
1917            StringBundler msg = new StringBundler(6);
1918
1919            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1920
1921            msg.append("tableId=");
1922            msg.append(tableId);
1923
1924            msg.append(", rowId=");
1925            msg.append(rowId);
1926
1927            msg.append(StringPool.CLOSE_CURLY_BRACE);
1928
1929            throw new NoSuchValueException(msg.toString());
1930        }
1931        else {
1932            return list.get(0);
1933        }
1934    }
1935
1936    public ExpandoValue findByT_R_Last(long tableId, long rowId,
1937        OrderByComparator orderByComparator)
1938        throws NoSuchValueException, SystemException {
1939        int count = countByT_R(tableId, rowId);
1940
1941        List<ExpandoValue> list = findByT_R(tableId, rowId, count - 1, count,
1942                orderByComparator);
1943
1944        if (list.isEmpty()) {
1945            StringBundler msg = new StringBundler(6);
1946
1947            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1948
1949            msg.append("tableId=");
1950            msg.append(tableId);
1951
1952            msg.append(", rowId=");
1953            msg.append(rowId);
1954
1955            msg.append(StringPool.CLOSE_CURLY_BRACE);
1956
1957            throw new NoSuchValueException(msg.toString());
1958        }
1959        else {
1960            return list.get(0);
1961        }
1962    }
1963
1964    public ExpandoValue[] findByT_R_PrevAndNext(long valueId, long tableId,
1965        long rowId, OrderByComparator orderByComparator)
1966        throws NoSuchValueException, SystemException {
1967        ExpandoValue expandoValue = findByPrimaryKey(valueId);
1968
1969        int count = countByT_R(tableId, rowId);
1970
1971        Session session = null;
1972
1973        try {
1974            session = openSession();
1975
1976            StringBundler query = null;
1977
1978            if (orderByComparator != null) {
1979                query = new StringBundler(4 +
1980                        (orderByComparator.getOrderByFields().length * 3));
1981            }
1982            else {
1983                query = new StringBundler(4);
1984            }
1985
1986            query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1987
1988            query.append(_FINDER_COLUMN_T_R_TABLEID_2);
1989
1990            query.append(_FINDER_COLUMN_T_R_ROWID_2);
1991
1992            if (orderByComparator != null) {
1993                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1994                    orderByComparator);
1995            }
1996
1997            else {
1998                query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1999            }
2000
2001            String sql = query.toString();
2002
2003            Query q = session.createQuery(sql);
2004
2005            QueryPos qPos = QueryPos.getInstance(q);
2006
2007            qPos.add(tableId);
2008
2009            qPos.add(rowId);
2010
2011            Object[] objArray = QueryUtil.getPrevAndNext(q, count,
2012                    orderByComparator, expandoValue);
2013
2014            ExpandoValue[] array = new ExpandoValueImpl[3];
2015
2016            array[0] = (ExpandoValue)objArray[0];
2017            array[1] = (ExpandoValue)objArray[1];
2018            array[2] = (ExpandoValue)objArray[2];
2019
2020            return array;
2021        }
2022        catch (Exception e) {
2023            throw processException(e);
2024        }
2025        finally {
2026            closeSession(session);
2027        }
2028    }
2029
2030    public ExpandoValue findByC_R(long columnId, long rowId)
2031        throws NoSuchValueException, SystemException {
2032        ExpandoValue expandoValue = fetchByC_R(columnId, rowId);
2033
2034        if (expandoValue == null) {
2035            StringBundler msg = new StringBundler(6);
2036
2037            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2038
2039            msg.append("columnId=");
2040            msg.append(columnId);
2041
2042            msg.append(", rowId=");
2043            msg.append(rowId);
2044
2045            msg.append(StringPool.CLOSE_CURLY_BRACE);
2046
2047            if (_log.isWarnEnabled()) {
2048                _log.warn(msg.toString());
2049            }
2050
2051            throw new NoSuchValueException(msg.toString());
2052        }
2053
2054        return expandoValue;
2055    }
2056
2057    public ExpandoValue fetchByC_R(long columnId, long rowId)
2058        throws SystemException {
2059        return fetchByC_R(columnId, rowId, true);
2060    }
2061
2062    public ExpandoValue fetchByC_R(long columnId, long rowId,
2063        boolean retrieveFromCache) throws SystemException {
2064        Object[] finderArgs = new Object[] { new Long(columnId), new Long(rowId) };
2065
2066        Object result = null;
2067
2068        if (retrieveFromCache) {
2069            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_R,
2070                    finderArgs, this);
2071        }
2072
2073        if (result == null) {
2074            Session session = null;
2075
2076            try {
2077                session = openSession();
2078
2079                StringBundler query = new StringBundler(4);
2080
2081                query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
2082
2083                query.append(_FINDER_COLUMN_C_R_COLUMNID_2);
2084
2085                query.append(_FINDER_COLUMN_C_R_ROWID_2);
2086
2087                query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
2088
2089                String sql = query.toString();
2090
2091                Query q = session.createQuery(sql);
2092
2093                QueryPos qPos = QueryPos.getInstance(q);
2094
2095                qPos.add(columnId);
2096
2097                qPos.add(rowId);
2098
2099                List<ExpandoValue> list = q.list();
2100
2101                result = list;
2102
2103                ExpandoValue expandoValue = null;
2104
2105                if (list.isEmpty()) {
2106                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R,
2107                        finderArgs, list);
2108                }
2109                else {
2110                    expandoValue = list.get(0);
2111
2112                    cacheResult(expandoValue);
2113
2114                    if ((expandoValue.getColumnId() != columnId) ||
2115                            (expandoValue.getRowId() != rowId)) {
2116                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R,
2117                            finderArgs, expandoValue);
2118                    }
2119                }
2120
2121                return expandoValue;
2122            }
2123            catch (Exception e) {
2124                throw processException(e);
2125            }
2126            finally {
2127                if (result == null) {
2128                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R,
2129                        finderArgs, new ArrayList<ExpandoValue>());
2130                }
2131
2132                closeSession(session);
2133            }
2134        }
2135        else {
2136            if (result instanceof List<?>) {
2137                return null;
2138            }
2139            else {
2140                return (ExpandoValue)result;
2141            }
2142        }
2143    }
2144
2145    public List<ExpandoValue> findByC_C(long classNameId, long classPK)
2146        throws SystemException {
2147        Object[] finderArgs = new Object[] {
2148                new Long(classNameId), new Long(classPK)
2149            };
2150
2151        List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C,
2152                finderArgs, this);
2153
2154        if (list == null) {
2155            Session session = null;
2156
2157            try {
2158                session = openSession();
2159
2160                StringBundler query = new StringBundler(4);
2161
2162                query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
2163
2164                query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2165
2166                query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
2167
2168                query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
2169
2170                String sql = query.toString();
2171
2172                Query q = session.createQuery(sql);
2173
2174                QueryPos qPos = QueryPos.getInstance(q);
2175
2176                qPos.add(classNameId);
2177
2178                qPos.add(classPK);
2179
2180                list = q.list();
2181            }
2182            catch (Exception e) {
2183                throw processException(e);
2184            }
2185            finally {
2186                if (list == null) {
2187                    list = new ArrayList<ExpandoValue>();
2188                }
2189
2190                cacheResult(list);
2191
2192                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C, finderArgs,
2193                    list);
2194
2195                closeSession(session);
2196            }
2197        }
2198
2199        return list;
2200    }
2201
2202    public List<ExpandoValue> findByC_C(long classNameId, long classPK,
2203        int start, int end) throws SystemException {
2204        return findByC_C(classNameId, classPK, start, end, null);
2205    }
2206
2207    public List<ExpandoValue> findByC_C(long classNameId, long classPK,
2208        int start, int end, OrderByComparator orderByComparator)
2209        throws SystemException {
2210        Object[] finderArgs = new Object[] {
2211                new Long(classNameId), new Long(classPK),
2212                
2213                String.valueOf(start), String.valueOf(end),
2214                String.valueOf(orderByComparator)
2215            };
2216
2217        List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_C,
2218                finderArgs, this);
2219
2220        if (list == null) {
2221            Session session = null;
2222
2223            try {
2224                session = openSession();
2225
2226                StringBundler query = null;
2227
2228                if (orderByComparator != null) {
2229                    query = new StringBundler(4 +
2230                            (orderByComparator.getOrderByFields().length * 3));
2231                }
2232                else {
2233                    query = new StringBundler(4);
2234                }
2235
2236                query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
2237
2238                query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2239
2240                query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
2241
2242                if (orderByComparator != null) {
2243                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2244                        orderByComparator);
2245                }
2246
2247                else {
2248                    query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
2249                }
2250
2251                String sql = query.toString();
2252
2253                Query q = session.createQuery(sql);
2254
2255                QueryPos qPos = QueryPos.getInstance(q);
2256
2257                qPos.add(classNameId);
2258
2259                qPos.add(classPK);
2260
2261                list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
2262                        start, end);
2263            }
2264            catch (Exception e) {
2265                throw processException(e);
2266            }
2267            finally {
2268                if (list == null) {
2269                    list = new ArrayList<ExpandoValue>();
2270                }
2271
2272                cacheResult(list);
2273
2274                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_C,
2275                    finderArgs, list);
2276
2277                closeSession(session);
2278            }
2279        }
2280
2281        return list;
2282    }
2283
2284    public ExpandoValue findByC_C_First(long classNameId, long classPK,
2285        OrderByComparator orderByComparator)
2286        throws NoSuchValueException, SystemException {
2287        List<ExpandoValue> list = findByC_C(classNameId, classPK, 0, 1,
2288                orderByComparator);
2289
2290        if (list.isEmpty()) {
2291            StringBundler msg = new StringBundler(6);
2292
2293            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2294
2295            msg.append("classNameId=");
2296            msg.append(classNameId);
2297
2298            msg.append(", classPK=");
2299            msg.append(classPK);
2300
2301            msg.append(StringPool.CLOSE_CURLY_BRACE);
2302
2303            throw new NoSuchValueException(msg.toString());
2304        }
2305        else {
2306            return list.get(0);
2307        }
2308    }
2309
2310    public ExpandoValue findByC_C_Last(long classNameId, long classPK,
2311        OrderByComparator orderByComparator)
2312        throws NoSuchValueException, SystemException {
2313        int count = countByC_C(classNameId, classPK);
2314
2315        List<ExpandoValue> list = findByC_C(classNameId, classPK, count - 1,
2316                count, orderByComparator);
2317
2318        if (list.isEmpty()) {
2319            StringBundler msg = new StringBundler(6);
2320
2321            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2322
2323            msg.append("classNameId=");
2324            msg.append(classNameId);
2325
2326            msg.append(", classPK=");
2327            msg.append(classPK);
2328
2329            msg.append(StringPool.CLOSE_CURLY_BRACE);
2330
2331            throw new NoSuchValueException(msg.toString());
2332        }
2333        else {
2334            return list.get(0);
2335        }
2336    }
2337
2338    public ExpandoValue[] findByC_C_PrevAndNext(long valueId, long classNameId,
2339        long classPK, OrderByComparator orderByComparator)
2340        throws NoSuchValueException, SystemException {
2341        ExpandoValue expandoValue = findByPrimaryKey(valueId);
2342
2343        int count = countByC_C(classNameId, classPK);
2344
2345        Session session = null;
2346
2347        try {
2348            session = openSession();
2349
2350            StringBundler query = null;
2351
2352            if (orderByComparator != null) {
2353                query = new StringBundler(4 +
2354                        (orderByComparator.getOrderByFields().length * 3));
2355            }
2356            else {
2357                query = new StringBundler(4);
2358            }
2359
2360            query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
2361
2362            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2363
2364            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
2365
2366            if (orderByComparator != null) {
2367                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2368                    orderByComparator);
2369            }
2370
2371            else {
2372                query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
2373            }
2374
2375            String sql = query.toString();
2376
2377            Query q = session.createQuery(sql);
2378
2379            QueryPos qPos = QueryPos.getInstance(q);
2380
2381            qPos.add(classNameId);
2382
2383            qPos.add(classPK);
2384
2385            Object[] objArray = QueryUtil.getPrevAndNext(q, count,
2386                    orderByComparator, expandoValue);
2387
2388            ExpandoValue[] array = new ExpandoValueImpl[3];
2389
2390            array[0] = (ExpandoValue)objArray[0];
2391            array[1] = (ExpandoValue)objArray[1];
2392            array[2] = (ExpandoValue)objArray[2];
2393
2394            return array;
2395        }
2396        catch (Exception e) {
2397            throw processException(e);
2398        }
2399        finally {
2400            closeSession(session);
2401        }
2402    }
2403
2404    public ExpandoValue findByT_C_C(long tableId, long columnId, long classPK)
2405        throws NoSuchValueException, SystemException {
2406        ExpandoValue expandoValue = fetchByT_C_C(tableId, columnId, classPK);
2407
2408        if (expandoValue == null) {
2409            StringBundler msg = new StringBundler(8);
2410
2411            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2412
2413            msg.append("tableId=");
2414            msg.append(tableId);
2415
2416            msg.append(", columnId=");
2417            msg.append(columnId);
2418
2419            msg.append(", classPK=");
2420            msg.append(classPK);
2421
2422            msg.append(StringPool.CLOSE_CURLY_BRACE);
2423
2424            if (_log.isWarnEnabled()) {
2425                _log.warn(msg.toString());
2426            }
2427
2428            throw new NoSuchValueException(msg.toString());
2429        }
2430
2431        return expandoValue;
2432    }
2433
2434    public ExpandoValue fetchByT_C_C(long tableId, long columnId, long classPK)
2435        throws SystemException {
2436        return fetchByT_C_C(tableId, columnId, classPK, true);
2437    }
2438
2439    public ExpandoValue fetchByT_C_C(long tableId, long columnId, long classPK,
2440        boolean retrieveFromCache) throws SystemException {
2441        Object[] finderArgs = new Object[] {
2442                new Long(tableId), new Long(columnId), new Long(classPK)
2443            };
2444
2445        Object result = null;
2446
2447        if (retrieveFromCache) {
2448            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_T_C_C,
2449                    finderArgs, this);
2450        }
2451
2452        if (result == null) {
2453            Session session = null;
2454
2455            try {
2456                session = openSession();
2457
2458                StringBundler query = new StringBundler(5);
2459
2460                query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
2461
2462                query.append(_FINDER_COLUMN_T_C_C_TABLEID_2);
2463
2464                query.append(_FINDER_COLUMN_T_C_C_COLUMNID_2);
2465
2466                query.append(_FINDER_COLUMN_T_C_C_CLASSPK_2);
2467
2468                query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
2469
2470                String sql = query.toString();
2471
2472                Query q = session.createQuery(sql);
2473
2474                QueryPos qPos = QueryPos.getInstance(q);
2475
2476                qPos.add(tableId);
2477
2478                qPos.add(columnId);
2479
2480                qPos.add(classPK);
2481
2482                List<ExpandoValue> list = q.list();
2483
2484                result = list;
2485
2486                ExpandoValue expandoValue = null;
2487
2488                if (list.isEmpty()) {
2489                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C_C,
2490                        finderArgs, list);
2491                }
2492                else {
2493                    expandoValue = list.get(0);
2494
2495                    cacheResult(expandoValue);
2496
2497                    if ((expandoValue.getTableId() != tableId) ||
2498                            (expandoValue.getColumnId() != columnId) ||
2499                            (expandoValue.getClassPK() != classPK)) {
2500                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C_C,
2501                            finderArgs, expandoValue);
2502                    }
2503                }
2504
2505                return expandoValue;
2506            }
2507            catch (Exception e) {
2508                throw processException(e);
2509            }
2510            finally {
2511                if (result == null) {
2512                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C_C,
2513                        finderArgs, new ArrayList<ExpandoValue>());
2514                }
2515
2516                closeSession(session);
2517            }
2518        }
2519        else {
2520            if (result instanceof List<?>) {
2521                return null;
2522            }
2523            else {
2524                return (ExpandoValue)result;
2525            }
2526        }
2527    }
2528
2529    public List<ExpandoValue> findByT_C_D(long tableId, long columnId,
2530        String data) throws SystemException {
2531        Object[] finderArgs = new Object[] {
2532                new Long(tableId), new Long(columnId),
2533                
2534                data
2535            };
2536
2537        List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_T_C_D,
2538                finderArgs, this);
2539
2540        if (list == null) {
2541            Session session = null;
2542
2543            try {
2544                session = openSession();
2545
2546                StringBundler query = new StringBundler(5);
2547
2548                query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
2549
2550                query.append(_FINDER_COLUMN_T_C_D_TABLEID_2);
2551
2552                query.append(_FINDER_COLUMN_T_C_D_COLUMNID_2);
2553
2554                if (data == null) {
2555                    query.append(_FINDER_COLUMN_T_C_D_DATA_1);
2556                }
2557                else {
2558                    if (data.equals(StringPool.BLANK)) {
2559                        query.append(_FINDER_COLUMN_T_C_D_DATA_3);
2560                    }
2561                    else {
2562                        query.append(_FINDER_COLUMN_T_C_D_DATA_2);
2563                    }
2564                }
2565
2566                query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
2567
2568                String sql = query.toString();
2569
2570                Query q = session.createQuery(sql);
2571
2572                QueryPos qPos = QueryPos.getInstance(q);
2573
2574                qPos.add(tableId);
2575
2576                qPos.add(columnId);
2577
2578                if (data != null) {
2579                    qPos.add(data);
2580                }
2581
2582                list = q.list();
2583            }
2584            catch (Exception e) {
2585                throw processException(e);
2586            }
2587            finally {
2588                if (list == null) {
2589                    list = new ArrayList<ExpandoValue>();
2590                }
2591
2592                cacheResult(list);
2593
2594                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_T_C_D,
2595                    finderArgs, list);
2596
2597                closeSession(session);
2598            }
2599        }
2600
2601        return list;
2602    }
2603
2604    public List<ExpandoValue> findByT_C_D(long tableId, long columnId,
2605        String data, int start, int end) throws SystemException {
2606        return findByT_C_D(tableId, columnId, data, start, end, null);
2607    }
2608
2609    public List<ExpandoValue> findByT_C_D(long tableId, long columnId,
2610        String data, int start, int end, OrderByComparator orderByComparator)
2611        throws SystemException {
2612        Object[] finderArgs = new Object[] {
2613                new Long(tableId), new Long(columnId),
2614                
2615                data,
2616                
2617                String.valueOf(start), String.valueOf(end),
2618                String.valueOf(orderByComparator)
2619            };
2620
2621        List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_T_C_D,
2622                finderArgs, this);
2623
2624        if (list == null) {
2625            Session session = null;
2626
2627            try {
2628                session = openSession();
2629
2630                StringBundler query = null;
2631
2632                if (orderByComparator != null) {
2633                    query = new StringBundler(5 +
2634                            (orderByComparator.getOrderByFields().length * 3));
2635                }
2636                else {
2637                    query = new StringBundler(5);
2638                }
2639
2640                query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
2641
2642                query.append(_FINDER_COLUMN_T_C_D_TABLEID_2);
2643
2644                query.append(_FINDER_COLUMN_T_C_D_COLUMNID_2);
2645
2646                if (data == null) {
2647                    query.append(_FINDER_COLUMN_T_C_D_DATA_1);
2648                }
2649                else {
2650                    if (data.equals(StringPool.BLANK)) {
2651                        query.append(_FINDER_COLUMN_T_C_D_DATA_3);
2652                    }
2653                    else {
2654                        query.append(_FINDER_COLUMN_T_C_D_DATA_2);
2655                    }
2656                }
2657
2658                if (orderByComparator != null) {
2659                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2660                        orderByComparator);
2661                }
2662
2663                else {
2664                    query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
2665                }
2666
2667                String sql = query.toString();
2668
2669                Query q = session.createQuery(sql);
2670
2671                QueryPos qPos = QueryPos.getInstance(q);
2672
2673                qPos.add(tableId);
2674
2675                qPos.add(columnId);
2676
2677                if (data != null) {
2678                    qPos.add(data);
2679                }
2680
2681                list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
2682                        start, end);
2683            }
2684            catch (Exception e) {
2685                throw processException(e);
2686            }
2687            finally {
2688                if (list == null) {
2689                    list = new ArrayList<ExpandoValue>();
2690                }
2691
2692                cacheResult(list);
2693
2694                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_T_C_D,
2695                    finderArgs, list);
2696
2697                closeSession(session);
2698            }
2699        }
2700
2701        return list;
2702    }
2703
2704    public ExpandoValue findByT_C_D_First(long tableId, long columnId,
2705        String data, OrderByComparator orderByComparator)
2706        throws NoSuchValueException, SystemException {
2707        List<ExpandoValue> list = findByT_C_D(tableId, columnId, data, 0, 1,
2708                orderByComparator);
2709
2710        if (list.isEmpty()) {
2711            StringBundler msg = new StringBundler(8);
2712
2713            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2714
2715            msg.append("tableId=");
2716            msg.append(tableId);
2717
2718            msg.append(", columnId=");
2719            msg.append(columnId);
2720
2721            msg.append(", data=");
2722            msg.append(data);
2723
2724            msg.append(StringPool.CLOSE_CURLY_BRACE);
2725
2726            throw new NoSuchValueException(msg.toString());
2727        }
2728        else {
2729            return list.get(0);
2730        }
2731    }
2732
2733    public ExpandoValue findByT_C_D_Last(long tableId, long columnId,
2734        String data, OrderByComparator orderByComparator)
2735        throws NoSuchValueException, SystemException {
2736        int count = countByT_C_D(tableId, columnId, data);
2737
2738        List<ExpandoValue> list = findByT_C_D(tableId, columnId, data,
2739                count - 1, count, orderByComparator);
2740
2741        if (list.isEmpty()) {
2742            StringBundler msg = new StringBundler(8);
2743
2744            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2745
2746            msg.append("tableId=");
2747            msg.append(tableId);
2748
2749            msg.append(", columnId=");
2750            msg.append(columnId);
2751
2752            msg.append(", data=");
2753            msg.append(data);
2754
2755            msg.append(StringPool.CLOSE_CURLY_BRACE);
2756
2757            throw new NoSuchValueException(msg.toString());
2758        }
2759        else {
2760            return list.get(0);
2761        }
2762    }
2763
2764    public ExpandoValue[] findByT_C_D_PrevAndNext(long valueId, long tableId,
2765        long columnId, String data, OrderByComparator orderByComparator)
2766        throws NoSuchValueException, SystemException {
2767        ExpandoValue expandoValue = findByPrimaryKey(valueId);
2768
2769        int count = countByT_C_D(tableId, columnId, data);
2770
2771        Session session = null;
2772
2773        try {
2774            session = openSession();
2775
2776            StringBundler query = null;
2777
2778            if (orderByComparator != null) {
2779                query = new StringBundler(5 +
2780                        (orderByComparator.getOrderByFields().length * 3));
2781            }
2782            else {
2783                query = new StringBundler(5);
2784            }
2785
2786            query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
2787
2788            query.append(_FINDER_COLUMN_T_C_D_TABLEID_2);
2789
2790            query.append(_FINDER_COLUMN_T_C_D_COLUMNID_2);
2791
2792            if (data == null) {
2793                query.append(_FINDER_COLUMN_T_C_D_DATA_1);
2794            }
2795            else {
2796                if (data.equals(StringPool.BLANK)) {
2797                    query.append(_FINDER_COLUMN_T_C_D_DATA_3);
2798                }
2799                else {
2800                    query.append(_FINDER_COLUMN_T_C_D_DATA_2);
2801                }
2802            }
2803
2804            if (orderByComparator != null) {
2805                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2806                    orderByComparator);
2807            }
2808
2809            else {
2810                query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
2811            }
2812
2813            String sql = query.toString();
2814
2815            Query q = session.createQuery(sql);
2816
2817            QueryPos qPos = QueryPos.getInstance(q);
2818
2819            qPos.add(tableId);
2820
2821            qPos.add(columnId);
2822
2823            if (data != null) {
2824                qPos.add(data);
2825            }
2826
2827            Object[] objArray = QueryUtil.getPrevAndNext(q, count,
2828                    orderByComparator, expandoValue);
2829
2830            ExpandoValue[] array = new ExpandoValueImpl[3];
2831
2832            array[0] = (ExpandoValue)objArray[0];
2833            array[1] = (ExpandoValue)objArray[1];
2834            array[2] = (ExpandoValue)objArray[2];
2835
2836            return array;
2837        }
2838        catch (Exception e) {
2839            throw processException(e);
2840        }
2841        finally {
2842            closeSession(session);
2843        }
2844    }
2845
2846    public List<ExpandoValue> findAll() throws SystemException {
2847        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2848    }
2849
2850    public List<ExpandoValue> findAll(int start, int end)
2851        throws SystemException {
2852        return findAll(start, end, null);
2853    }
2854
2855    public List<ExpandoValue> findAll(int start, int end,
2856        OrderByComparator orderByComparator) throws SystemException {
2857        Object[] finderArgs = new Object[] {
2858                String.valueOf(start), String.valueOf(end),
2859                String.valueOf(orderByComparator)
2860            };
2861
2862        List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2863                finderArgs, this);
2864
2865        if (list == null) {
2866            Session session = null;
2867
2868            try {
2869                session = openSession();
2870
2871                StringBundler query = null;
2872                String sql = null;
2873
2874                if (orderByComparator != null) {
2875                    query = new StringBundler(2 +
2876                            (orderByComparator.getOrderByFields().length * 3));
2877
2878                    query.append(_SQL_SELECT_EXPANDOVALUE);
2879
2880                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2881                        orderByComparator);
2882
2883                    sql = query.toString();
2884                }
2885
2886                else {
2887                    sql = _SQL_SELECT_EXPANDOVALUE.concat(ExpandoValueModelImpl.ORDER_BY_JPQL);
2888                }
2889
2890                Query q = session.createQuery(sql);
2891
2892                if (orderByComparator == null) {
2893                    list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
2894                            start, end, false);
2895
2896                    Collections.sort(list);
2897                }
2898                else {
2899                    list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
2900                            start, end);
2901                }
2902            }
2903            catch (Exception e) {
2904                throw processException(e);
2905            }
2906            finally {
2907                if (list == null) {
2908                    list = new ArrayList<ExpandoValue>();
2909                }
2910
2911                cacheResult(list);
2912
2913                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2914
2915                closeSession(session);
2916            }
2917        }
2918
2919        return list;
2920    }
2921
2922    public void removeByTableId(long tableId) throws SystemException {
2923        for (ExpandoValue expandoValue : findByTableId(tableId)) {
2924            remove(expandoValue);
2925        }
2926    }
2927
2928    public void removeByColumnId(long columnId) throws SystemException {
2929        for (ExpandoValue expandoValue : findByColumnId(columnId)) {
2930            remove(expandoValue);
2931        }
2932    }
2933
2934    public void removeByRowId(long rowId) throws SystemException {
2935        for (ExpandoValue expandoValue : findByRowId(rowId)) {
2936            remove(expandoValue);
2937        }
2938    }
2939
2940    public void removeByT_C(long tableId, long columnId)
2941        throws SystemException {
2942        for (ExpandoValue expandoValue : findByT_C(tableId, columnId)) {
2943            remove(expandoValue);
2944        }
2945    }
2946
2947    public void removeByT_CPK(long tableId, long classPK)
2948        throws SystemException {
2949        for (ExpandoValue expandoValue : findByT_CPK(tableId, classPK)) {
2950            remove(expandoValue);
2951        }
2952    }
2953
2954    public void removeByT_R(long tableId, long rowId) throws SystemException {
2955        for (ExpandoValue expandoValue : findByT_R(tableId, rowId)) {
2956            remove(expandoValue);
2957        }
2958    }
2959
2960    public void removeByC_R(long columnId, long rowId)
2961        throws NoSuchValueException, SystemException {
2962        ExpandoValue expandoValue = findByC_R(columnId, rowId);
2963
2964        remove(expandoValue);
2965    }
2966
2967    public void removeByC_C(long classNameId, long classPK)
2968        throws SystemException {
2969        for (ExpandoValue expandoValue : findByC_C(classNameId, classPK)) {
2970            remove(expandoValue);
2971        }
2972    }
2973
2974    public void removeByT_C_C(long tableId, long columnId, long classPK)
2975        throws NoSuchValueException, SystemException {
2976        ExpandoValue expandoValue = findByT_C_C(tableId, columnId, classPK);
2977
2978        remove(expandoValue);
2979    }
2980
2981    public void removeByT_C_D(long tableId, long columnId, String data)
2982        throws SystemException {
2983        for (ExpandoValue expandoValue : findByT_C_D(tableId, columnId, data)) {
2984            remove(expandoValue);
2985        }
2986    }
2987
2988    public void removeAll() throws SystemException {
2989        for (ExpandoValue expandoValue : findAll()) {
2990            remove(expandoValue);
2991        }
2992    }
2993
2994    public int countByTableId(long tableId) throws SystemException {
2995        Object[] finderArgs = new Object[] { new Long(tableId) };
2996
2997        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TABLEID,
2998                finderArgs, this);
2999
3000        if (count == null) {
3001            Session session = null;
3002
3003            try {
3004                session = openSession();
3005
3006                StringBundler query = new StringBundler(2);
3007
3008                query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
3009
3010                query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
3011
3012                String sql = query.toString();
3013
3014                Query q = session.createQuery(sql);
3015
3016                QueryPos qPos = QueryPos.getInstance(q);
3017
3018                qPos.add(tableId);
3019
3020                count = (Long)q.uniqueResult();
3021            }
3022            catch (Exception e) {
3023                throw processException(e);
3024            }
3025            finally {
3026                if (count == null) {
3027                    count = Long.valueOf(0);
3028                }
3029
3030                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TABLEID,
3031                    finderArgs, count);
3032
3033                closeSession(session);
3034            }
3035        }
3036
3037        return count.intValue();
3038    }
3039
3040    public int countByColumnId(long columnId) throws SystemException {
3041        Object[] finderArgs = new Object[] { new Long(columnId) };
3042
3043        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COLUMNID,
3044                finderArgs, this);
3045
3046        if (count == null) {
3047            Session session = null;
3048
3049            try {
3050                session = openSession();
3051
3052                StringBundler query = new StringBundler(2);
3053
3054                query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
3055
3056                query.append(_FINDER_COLUMN_COLUMNID_COLUMNID_2);
3057
3058                String sql = query.toString();
3059
3060                Query q = session.createQuery(sql);
3061
3062                QueryPos qPos = QueryPos.getInstance(q);
3063
3064                qPos.add(columnId);
3065
3066                count = (Long)q.uniqueResult();
3067            }
3068            catch (Exception e) {
3069                throw processException(e);
3070            }
3071            finally {
3072                if (count == null) {
3073                    count = Long.valueOf(0);
3074                }
3075
3076                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COLUMNID,
3077                    finderArgs, count);
3078
3079                closeSession(session);
3080            }
3081        }
3082
3083        return count.intValue();
3084    }
3085
3086    public int countByRowId(long rowId) throws SystemException {
3087        Object[] finderArgs = new Object[] { new Long(rowId) };
3088
3089        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ROWID,
3090                finderArgs, this);
3091
3092        if (count == null) {
3093            Session session = null;
3094
3095            try {
3096                session = openSession();
3097
3098                StringBundler query = new StringBundler(2);
3099
3100                query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
3101
3102                query.append(_FINDER_COLUMN_ROWID_ROWID_2);
3103
3104                String sql = query.toString();
3105
3106                Query q = session.createQuery(sql);
3107
3108                QueryPos qPos = QueryPos.getInstance(q);
3109
3110                qPos.add(rowId);
3111
3112                count = (Long)q.uniqueResult();
3113            }
3114            catch (Exception e) {
3115                throw processException(e);
3116            }
3117            finally {
3118                if (count == null) {
3119                    count = Long.valueOf(0);
3120                }
3121
3122                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROWID,
3123                    finderArgs, count);
3124
3125                closeSession(session);
3126            }
3127        }
3128
3129        return count.intValue();
3130    }
3131
3132    public int countByT_C(long tableId, long columnId)
3133        throws SystemException {
3134        Object[] finderArgs = new Object[] { new Long(tableId), new Long(columnId) };
3135
3136        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_C,
3137                finderArgs, this);
3138
3139        if (count == null) {
3140            Session session = null;
3141
3142            try {
3143                session = openSession();
3144
3145                StringBundler query = new StringBundler(3);
3146
3147                query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
3148
3149                query.append(_FINDER_COLUMN_T_C_TABLEID_2);
3150
3151                query.append(_FINDER_COLUMN_T_C_COLUMNID_2);
3152
3153                String sql = query.toString();
3154
3155                Query q = session.createQuery(sql);
3156
3157                QueryPos qPos = QueryPos.getInstance(q);
3158
3159                qPos.add(tableId);
3160
3161                qPos.add(columnId);
3162
3163                count = (Long)q.uniqueResult();
3164            }
3165            catch (Exception e) {
3166                throw processException(e);
3167            }
3168            finally {
3169                if (count == null) {
3170                    count = Long.valueOf(0);
3171                }
3172
3173                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_C, finderArgs,
3174                    count);
3175
3176                closeSession(session);
3177            }
3178        }
3179
3180        return count.intValue();
3181    }
3182
3183    public int countByT_CPK(long tableId, long classPK)
3184        throws SystemException {
3185        Object[] finderArgs = new Object[] { new Long(tableId), new Long(classPK) };
3186
3187        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_CPK,
3188                finderArgs, this);
3189
3190        if (count == null) {
3191            Session session = null;
3192
3193            try {
3194                session = openSession();
3195
3196                StringBundler query = new StringBundler(3);
3197
3198                query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
3199
3200                query.append(_FINDER_COLUMN_T_CPK_TABLEID_2);
3201
3202                query.append(_FINDER_COLUMN_T_CPK_CLASSPK_2);
3203
3204                String sql = query.toString();
3205
3206                Query q = session.createQuery(sql);
3207
3208                QueryPos qPos = QueryPos.getInstance(q);
3209
3210                qPos.add(tableId);
3211
3212                qPos.add(classPK);
3213
3214                count = (Long)q.uniqueResult();
3215            }
3216            catch (Exception e) {
3217                throw processException(e);
3218            }
3219            finally {
3220                if (count == null) {
3221                    count = Long.valueOf(0);
3222                }
3223
3224                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_CPK,
3225                    finderArgs, count);
3226
3227                closeSession(session);
3228            }
3229        }
3230
3231        return count.intValue();
3232    }
3233
3234    public int countByT_R(long tableId, long rowId) throws SystemException {
3235        Object[] finderArgs = new Object[] { new Long(tableId), new Long(rowId) };
3236
3237        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_R,
3238                finderArgs, this);
3239
3240        if (count == null) {
3241            Session session = null;
3242
3243            try {
3244                session = openSession();
3245
3246                StringBundler query = new StringBundler(3);
3247
3248                query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
3249
3250                query.append(_FINDER_COLUMN_T_R_TABLEID_2);
3251
3252                query.append(_FINDER_COLUMN_T_R_ROWID_2);
3253
3254                String sql = query.toString();
3255
3256                Query q = session.createQuery(sql);
3257
3258                QueryPos qPos = QueryPos.getInstance(q);
3259
3260                qPos.add(tableId);
3261
3262                qPos.add(rowId);
3263
3264                count = (Long)q.uniqueResult();
3265            }
3266            catch (Exception e) {
3267                throw processException(e);
3268            }
3269            finally {
3270                if (count == null) {
3271                    count = Long.valueOf(0);
3272                }
3273
3274                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_R, finderArgs,
3275                    count);
3276
3277                closeSession(session);
3278            }
3279        }
3280
3281        return count.intValue();
3282    }
3283
3284    public int countByC_R(long columnId, long rowId) throws SystemException {
3285        Object[] finderArgs = new Object[] { new Long(columnId), new Long(rowId) };
3286
3287        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_R,
3288                finderArgs, this);
3289
3290        if (count == null) {
3291            Session session = null;
3292
3293            try {
3294                session = openSession();
3295
3296                StringBundler query = new StringBundler(3);
3297
3298                query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
3299
3300                query.append(_FINDER_COLUMN_C_R_COLUMNID_2);
3301
3302                query.append(_FINDER_COLUMN_C_R_ROWID_2);
3303
3304                String sql = query.toString();
3305
3306                Query q = session.createQuery(sql);
3307
3308                QueryPos qPos = QueryPos.getInstance(q);
3309
3310                qPos.add(columnId);
3311
3312                qPos.add(rowId);
3313
3314                count = (Long)q.uniqueResult();
3315            }
3316            catch (Exception e) {
3317                throw processException(e);
3318            }
3319            finally {
3320                if (count == null) {
3321                    count = Long.valueOf(0);
3322                }
3323
3324                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_R, finderArgs,
3325                    count);
3326
3327                closeSession(session);
3328            }
3329        }
3330
3331        return count.intValue();
3332    }
3333
3334    public int countByC_C(long classNameId, long classPK)
3335        throws SystemException {
3336        Object[] finderArgs = new Object[] {
3337                new Long(classNameId), new Long(classPK)
3338            };
3339
3340        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
3341                finderArgs, this);
3342
3343        if (count == null) {
3344            Session session = null;
3345
3346            try {
3347                session = openSession();
3348
3349                StringBundler query = new StringBundler(3);
3350
3351                query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
3352
3353                query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3354
3355                query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3356
3357                String sql = query.toString();
3358
3359                Query q = session.createQuery(sql);
3360
3361                QueryPos qPos = QueryPos.getInstance(q);
3362
3363                qPos.add(classNameId);
3364
3365                qPos.add(classPK);
3366
3367                count = (Long)q.uniqueResult();
3368            }
3369            catch (Exception e) {
3370                throw processException(e);
3371            }
3372            finally {
3373                if (count == null) {
3374                    count = Long.valueOf(0);
3375                }
3376
3377                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
3378                    count);
3379
3380                closeSession(session);
3381            }
3382        }
3383
3384        return count.intValue();
3385    }
3386
3387    public int countByT_C_C(long tableId, long columnId, long classPK)
3388        throws SystemException {
3389        Object[] finderArgs = new Object[] {
3390                new Long(tableId), new Long(columnId), new Long(classPK)
3391            };
3392
3393        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_C_C,
3394                finderArgs, this);
3395
3396        if (count == null) {
3397            Session session = null;
3398
3399            try {
3400                session = openSession();
3401
3402                StringBundler query = new StringBundler(4);
3403
3404                query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
3405
3406                query.append(_FINDER_COLUMN_T_C_C_TABLEID_2);
3407
3408                query.append(_FINDER_COLUMN_T_C_C_COLUMNID_2);
3409
3410                query.append(_FINDER_COLUMN_T_C_C_CLASSPK_2);
3411
3412                String sql = query.toString();
3413
3414                Query q = session.createQuery(sql);
3415
3416                QueryPos qPos = QueryPos.getInstance(q);
3417
3418                qPos.add(tableId);
3419
3420                qPos.add(columnId);
3421
3422                qPos.add(classPK);
3423
3424                count = (Long)q.uniqueResult();
3425            }
3426            catch (Exception e) {
3427                throw processException(e);
3428            }
3429            finally {
3430                if (count == null) {
3431                    count = Long.valueOf(0);
3432                }
3433
3434                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_C_C,
3435                    finderArgs, count);
3436
3437                closeSession(session);
3438            }
3439        }
3440
3441        return count.intValue();
3442    }
3443
3444    public int countByT_C_D(long tableId, long columnId, String data)
3445        throws SystemException {
3446        Object[] finderArgs = new Object[] {
3447                new Long(tableId), new Long(columnId),
3448                
3449                data
3450            };
3451
3452        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_C_D,
3453                finderArgs, this);
3454
3455        if (count == null) {
3456            Session session = null;
3457
3458            try {
3459                session = openSession();
3460
3461                StringBundler query = new StringBundler(4);
3462
3463                query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
3464
3465                query.append(_FINDER_COLUMN_T_C_D_TABLEID_2);
3466
3467                query.append(_FINDER_COLUMN_T_C_D_COLUMNID_2);
3468
3469                if (data == null) {
3470                    query.append(_FINDER_COLUMN_T_C_D_DATA_1);
3471                }
3472                else {
3473                    if (data.equals(StringPool.BLANK)) {
3474                        query.append(_FINDER_COLUMN_T_C_D_DATA_3);
3475                    }
3476                    else {
3477                        query.append(_FINDER_COLUMN_T_C_D_DATA_2);
3478                    }
3479                }
3480
3481                String sql = query.toString();
3482
3483                Query q = session.createQuery(sql);
3484
3485                QueryPos qPos = QueryPos.getInstance(q);
3486
3487                qPos.add(tableId);
3488
3489                qPos.add(columnId);
3490
3491                if (data != null) {
3492                    qPos.add(data);
3493                }
3494
3495                count = (Long)q.uniqueResult();
3496            }
3497            catch (Exception e) {
3498                throw processException(e);
3499            }
3500            finally {
3501                if (count == null) {
3502                    count = Long.valueOf(0);
3503                }
3504
3505                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_C_D,
3506                    finderArgs, count);
3507
3508                closeSession(session);
3509            }
3510        }
3511
3512        return count.intValue();
3513    }
3514
3515    public int countAll() throws SystemException {
3516        Object[] finderArgs = new Object[0];
3517
3518        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3519                finderArgs, this);
3520
3521        if (count == null) {
3522            Session session = null;
3523
3524            try {
3525                session = openSession();
3526
3527                Query q = session.createQuery(_SQL_COUNT_EXPANDOVALUE);
3528
3529                count = (Long)q.uniqueResult();
3530            }
3531            catch (Exception e) {
3532                throw processException(e);
3533            }
3534            finally {
3535                if (count == null) {
3536                    count = Long.valueOf(0);
3537                }
3538
3539                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
3540                    count);
3541
3542                closeSession(session);
3543            }
3544        }
3545
3546        return count.intValue();
3547    }
3548
3549    public void afterPropertiesSet() {
3550        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3551                    com.liferay.portal.util.PropsUtil.get(
3552                        "value.object.listener.com.liferay.portlet.expando.model.ExpandoValue")));
3553
3554        if (listenerClassNames.length > 0) {
3555            try {
3556                List<ModelListener<ExpandoValue>> listenersList = new ArrayList<ModelListener<ExpandoValue>>();
3557
3558                for (String listenerClassName : listenerClassNames) {
3559                    listenersList.add((ModelListener<ExpandoValue>)Class.forName(
3560                            listenerClassName).newInstance());
3561                }
3562
3563                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3564            }
3565            catch (Exception e) {
3566                _log.error(e);
3567            }
3568        }
3569    }
3570
3571    @BeanReference(type = ExpandoColumnPersistence.class)
3572    protected ExpandoColumnPersistence expandoColumnPersistence;
3573    @BeanReference(type = ExpandoRowPersistence.class)
3574    protected ExpandoRowPersistence expandoRowPersistence;
3575    @BeanReference(type = ExpandoTablePersistence.class)
3576    protected ExpandoTablePersistence expandoTablePersistence;
3577    @BeanReference(type = ExpandoValuePersistence.class)
3578    protected ExpandoValuePersistence expandoValuePersistence;
3579    @BeanReference(type = ResourcePersistence.class)
3580    protected ResourcePersistence resourcePersistence;
3581    @BeanReference(type = UserPersistence.class)
3582    protected UserPersistence userPersistence;
3583    private static final String _SQL_SELECT_EXPANDOVALUE = "SELECT expandoValue FROM ExpandoValue expandoValue";
3584    private static final String _SQL_SELECT_EXPANDOVALUE_WHERE = "SELECT expandoValue FROM ExpandoValue expandoValue WHERE ";
3585    private static final String _SQL_COUNT_EXPANDOVALUE = "SELECT COUNT(expandoValue) FROM ExpandoValue expandoValue";
3586    private static final String _SQL_COUNT_EXPANDOVALUE_WHERE = "SELECT COUNT(expandoValue) FROM ExpandoValue expandoValue WHERE ";
3587    private static final String _FINDER_COLUMN_TABLEID_TABLEID_2 = "expandoValue.tableId = ?";
3588    private static final String _FINDER_COLUMN_COLUMNID_COLUMNID_2 = "expandoValue.columnId = ?";
3589    private static final String _FINDER_COLUMN_ROWID_ROWID_2 = "expandoValue.rowId = ?";
3590    private static final String _FINDER_COLUMN_T_C_TABLEID_2 = "expandoValue.tableId = ? AND ";
3591    private static final String _FINDER_COLUMN_T_C_COLUMNID_2 = "expandoValue.columnId = ?";
3592    private static final String _FINDER_COLUMN_T_CPK_TABLEID_2 = "expandoValue.tableId = ? AND ";
3593    private static final String _FINDER_COLUMN_T_CPK_CLASSPK_2 = "expandoValue.classPK = ?";
3594    private static final String _FINDER_COLUMN_T_R_TABLEID_2 = "expandoValue.tableId = ? AND ";
3595    private static final String _FINDER_COLUMN_T_R_ROWID_2 = "expandoValue.rowId = ?";
3596    private static final String _FINDER_COLUMN_C_R_COLUMNID_2 = "expandoValue.columnId = ? AND ";
3597    private static final String _FINDER_COLUMN_C_R_ROWID_2 = "expandoValue.rowId = ?";
3598    private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "expandoValue.classNameId = ? AND ";
3599    private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "expandoValue.classPK = ?";
3600    private static final String _FINDER_COLUMN_T_C_C_TABLEID_2 = "expandoValue.tableId = ? AND ";
3601    private static final String _FINDER_COLUMN_T_C_C_COLUMNID_2 = "expandoValue.columnId = ? AND ";
3602    private static final String _FINDER_COLUMN_T_C_C_CLASSPK_2 = "expandoValue.classPK = ?";
3603    private static final String _FINDER_COLUMN_T_C_D_TABLEID_2 = "expandoValue.tableId = ? AND ";
3604    private static final String _FINDER_COLUMN_T_C_D_COLUMNID_2 = "expandoValue.columnId = ? AND ";
3605    private static final String _FINDER_COLUMN_T_C_D_DATA_1 = "expandoValue.data IS NULL";
3606    private static final String _FINDER_COLUMN_T_C_D_DATA_2 = "expandoValue.data = ?";
3607    private static final String _FINDER_COLUMN_T_C_D_DATA_3 = "(expandoValue.data IS NULL OR expandoValue.data = ?)";
3608    private static final String _ORDER_BY_ENTITY_ALIAS = "expandoValue.";
3609    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoValue exists with the primary key ";
3610    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoValue exists with the key {";
3611    private static Log _log = LogFactoryUtil.getLog(ExpandoValuePersistenceImpl.class);
3612}