001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.expando.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.service.persistence.BatchSessionUtil;
040    import com.liferay.portal.service.persistence.ResourcePersistence;
041    import com.liferay.portal.service.persistence.UserPersistence;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import com.liferay.portlet.expando.NoSuchValueException;
045    import com.liferay.portlet.expando.model.ExpandoValue;
046    import com.liferay.portlet.expando.model.impl.ExpandoValueImpl;
047    import com.liferay.portlet.expando.model.impl.ExpandoValueModelImpl;
048    
049    import java.io.Serializable;
050    
051    import java.util.ArrayList;
052    import java.util.Collections;
053    import java.util.List;
054    
055    /**
056     * The persistence implementation for the expando value service.
057     *
058     * <p>
059     * Caching information and settings can be found in <code>portal.properties</code>
060     * </p>
061     *
062     * @author Brian Wing Shun Chan
063     * @see ExpandoValuePersistence
064     * @see ExpandoValueUtil
065     * @generated
066     */
067    public class ExpandoValuePersistenceImpl extends BasePersistenceImpl<ExpandoValue>
068            implements ExpandoValuePersistence {
069            /*
070             * NOTE FOR DEVELOPERS:
071             *
072             * Never modify or reference this class directly. Always use {@link ExpandoValueUtil} to access the expando value persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
073             */
074            public static final String FINDER_CLASS_NAME_ENTITY = ExpandoValueImpl.class.getName();
075            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076                    ".List1";
077            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List2";
079            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TABLEID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
080                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
081                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByTableId",
082                            new String[] {
083                                    Long.class.getName(),
084                                    
085                            "java.lang.Integer", "java.lang.Integer",
086                                    "com.liferay.portal.kernel.util.OrderByComparator"
087                            });
088            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID =
089                    new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
090                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
091                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTableId",
092                            new String[] { Long.class.getName() },
093                            ExpandoValueModelImpl.TABLEID_COLUMN_BITMASK);
094            public static final FinderPath FINDER_PATH_COUNT_BY_TABLEID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
095                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, Long.class,
096                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTableId",
097                            new String[] { Long.class.getName() });
098            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COLUMNID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
099                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
100                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByColumnId",
101                            new String[] {
102                                    Long.class.getName(),
103                                    
104                            "java.lang.Integer", "java.lang.Integer",
105                                    "com.liferay.portal.kernel.util.OrderByComparator"
106                            });
107            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COLUMNID =
108                    new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
109                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
110                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByColumnId",
111                            new String[] { Long.class.getName() },
112                            ExpandoValueModelImpl.COLUMNID_COLUMN_BITMASK);
113            public static final FinderPath FINDER_PATH_COUNT_BY_COLUMNID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
114                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, Long.class,
115                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByColumnId",
116                            new String[] { Long.class.getName() });
117            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ROWID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
118                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
119                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByRowId",
120                            new String[] {
121                                    Long.class.getName(),
122                                    
123                            "java.lang.Integer", "java.lang.Integer",
124                                    "com.liferay.portal.kernel.util.OrderByComparator"
125                            });
126            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROWID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
127                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
128                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRowId",
129                            new String[] { Long.class.getName() },
130                            ExpandoValueModelImpl.ROWID_COLUMN_BITMASK);
131            public static final FinderPath FINDER_PATH_COUNT_BY_ROWID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
132                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, Long.class,
133                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRowId",
134                            new String[] { Long.class.getName() });
135            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
136                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
137                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_C",
138                            new String[] {
139                                    Long.class.getName(), Long.class.getName(),
140                                    
141                            "java.lang.Integer", "java.lang.Integer",
142                                    "com.liferay.portal.kernel.util.OrderByComparator"
143                            });
144            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
145                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
146                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_C",
147                            new String[] { Long.class.getName(), Long.class.getName() },
148                            ExpandoValueModelImpl.TABLEID_COLUMN_BITMASK |
149                            ExpandoValueModelImpl.COLUMNID_COLUMN_BITMASK);
150            public static final FinderPath FINDER_PATH_COUNT_BY_T_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
151                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, Long.class,
152                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_C",
153                            new String[] { Long.class.getName(), Long.class.getName() });
154            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_CPK = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
155                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
156                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_CPK",
157                            new String[] {
158                                    Long.class.getName(), Long.class.getName(),
159                                    
160                            "java.lang.Integer", "java.lang.Integer",
161                                    "com.liferay.portal.kernel.util.OrderByComparator"
162                            });
163            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_CPK = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
164                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
165                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_CPK",
166                            new String[] { Long.class.getName(), Long.class.getName() },
167                            ExpandoValueModelImpl.TABLEID_COLUMN_BITMASK |
168                            ExpandoValueModelImpl.CLASSPK_COLUMN_BITMASK);
169            public static final FinderPath FINDER_PATH_COUNT_BY_T_CPK = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
170                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, Long.class,
171                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_CPK",
172                            new String[] { Long.class.getName(), Long.class.getName() });
173            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_R = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
174                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
175                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_R",
176                            new String[] {
177                                    Long.class.getName(), Long.class.getName(),
178                                    
179                            "java.lang.Integer", "java.lang.Integer",
180                                    "com.liferay.portal.kernel.util.OrderByComparator"
181                            });
182            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_R = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
183                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
184                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_R",
185                            new String[] { Long.class.getName(), Long.class.getName() },
186                            ExpandoValueModelImpl.TABLEID_COLUMN_BITMASK |
187                            ExpandoValueModelImpl.ROWID_COLUMN_BITMASK);
188            public static final FinderPath FINDER_PATH_COUNT_BY_T_R = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
189                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, Long.class,
190                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_R",
191                            new String[] { Long.class.getName(), Long.class.getName() });
192            public static final FinderPath FINDER_PATH_FETCH_BY_C_R = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
193                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
194                            FINDER_CLASS_NAME_ENTITY, "fetchByC_R",
195                            new String[] { Long.class.getName(), Long.class.getName() },
196                            ExpandoValueModelImpl.COLUMNID_COLUMN_BITMASK |
197                            ExpandoValueModelImpl.ROWID_COLUMN_BITMASK);
198            public static final FinderPath FINDER_PATH_COUNT_BY_C_R = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
199                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, Long.class,
200                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_R",
201                            new String[] { Long.class.getName(), Long.class.getName() });
202            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
203                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
204                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
205                            new String[] {
206                                    Long.class.getName(), Long.class.getName(),
207                                    
208                            "java.lang.Integer", "java.lang.Integer",
209                                    "com.liferay.portal.kernel.util.OrderByComparator"
210                            });
211            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
212                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
213                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
214                            new String[] { Long.class.getName(), Long.class.getName() },
215                            ExpandoValueModelImpl.CLASSNAMEID_COLUMN_BITMASK |
216                            ExpandoValueModelImpl.CLASSPK_COLUMN_BITMASK);
217            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
218                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, Long.class,
219                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
220                            new String[] { Long.class.getName(), Long.class.getName() });
221            public static final FinderPath FINDER_PATH_FETCH_BY_T_C_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
222                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
223                            FINDER_CLASS_NAME_ENTITY, "fetchByT_C_C",
224                            new String[] {
225                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
226                            },
227                            ExpandoValueModelImpl.TABLEID_COLUMN_BITMASK |
228                            ExpandoValueModelImpl.COLUMNID_COLUMN_BITMASK |
229                            ExpandoValueModelImpl.CLASSPK_COLUMN_BITMASK);
230            public static final FinderPath FINDER_PATH_COUNT_BY_T_C_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
231                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, Long.class,
232                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_C_C",
233                            new String[] {
234                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
235                            });
236            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_C_D = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
237                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
238                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_C_D",
239                            new String[] {
240                                    Long.class.getName(), Long.class.getName(),
241                                    String.class.getName(),
242                                    
243                            "java.lang.Integer", "java.lang.Integer",
244                                    "com.liferay.portal.kernel.util.OrderByComparator"
245                            });
246            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_C_D = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
247                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
248                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_C_D",
249                            new String[] {
250                                    Long.class.getName(), Long.class.getName(),
251                                    String.class.getName()
252                            },
253                            ExpandoValueModelImpl.TABLEID_COLUMN_BITMASK |
254                            ExpandoValueModelImpl.COLUMNID_COLUMN_BITMASK |
255                            ExpandoValueModelImpl.DATA_COLUMN_BITMASK);
256            public static final FinderPath FINDER_PATH_COUNT_BY_T_C_D = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
257                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, Long.class,
258                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_C_D",
259                            new String[] {
260                                    Long.class.getName(), Long.class.getName(),
261                                    String.class.getName()
262                            });
263            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
264                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
265                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
266            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
267                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, ExpandoValueImpl.class,
268                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
269            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
270                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, Long.class,
271                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
272    
273            /**
274             * Caches the expando value in the entity cache if it is enabled.
275             *
276             * @param expandoValue the expando value
277             */
278            public void cacheResult(ExpandoValue expandoValue) {
279                    EntityCacheUtil.putResult(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
280                            ExpandoValueImpl.class, expandoValue.getPrimaryKey(), expandoValue);
281    
282                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R,
283                            new Object[] {
284                                    Long.valueOf(expandoValue.getColumnId()),
285                                    Long.valueOf(expandoValue.getRowId())
286                            }, expandoValue);
287    
288                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C_C,
289                            new Object[] {
290                                    Long.valueOf(expandoValue.getTableId()),
291                                    Long.valueOf(expandoValue.getColumnId()),
292                                    Long.valueOf(expandoValue.getClassPK())
293                            }, expandoValue);
294    
295                    expandoValue.resetOriginalValues();
296            }
297    
298            /**
299             * Caches the expando values in the entity cache if it is enabled.
300             *
301             * @param expandoValues the expando values
302             */
303            public void cacheResult(List<ExpandoValue> expandoValues) {
304                    for (ExpandoValue expandoValue : expandoValues) {
305                            if (EntityCacheUtil.getResult(
306                                                    ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
307                                                    ExpandoValueImpl.class, expandoValue.getPrimaryKey()) == null) {
308                                    cacheResult(expandoValue);
309                            }
310                            else {
311                                    expandoValue.resetOriginalValues();
312                            }
313                    }
314            }
315    
316            /**
317             * Clears the cache for all expando values.
318             *
319             * <p>
320             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
321             * </p>
322             */
323            @Override
324            public void clearCache() {
325                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
326                            CacheRegistryUtil.clear(ExpandoValueImpl.class.getName());
327                    }
328    
329                    EntityCacheUtil.clearCache(ExpandoValueImpl.class.getName());
330    
331                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
332                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
333                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
334            }
335    
336            /**
337             * Clears the cache for the expando value.
338             *
339             * <p>
340             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
341             * </p>
342             */
343            @Override
344            public void clearCache(ExpandoValue expandoValue) {
345                    EntityCacheUtil.removeResult(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
346                            ExpandoValueImpl.class, expandoValue.getPrimaryKey());
347    
348                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
349                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
350    
351                    clearUniqueFindersCache(expandoValue);
352            }
353    
354            @Override
355            public void clearCache(List<ExpandoValue> expandoValues) {
356                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
357                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
358    
359                    for (ExpandoValue expandoValue : expandoValues) {
360                            EntityCacheUtil.removeResult(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
361                                    ExpandoValueImpl.class, expandoValue.getPrimaryKey());
362    
363                            clearUniqueFindersCache(expandoValue);
364                    }
365            }
366    
367            protected void clearUniqueFindersCache(ExpandoValue expandoValue) {
368                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_R,
369                            new Object[] {
370                                    Long.valueOf(expandoValue.getColumnId()),
371                                    Long.valueOf(expandoValue.getRowId())
372                            });
373    
374                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C_C,
375                            new Object[] {
376                                    Long.valueOf(expandoValue.getTableId()),
377                                    Long.valueOf(expandoValue.getColumnId()),
378                                    Long.valueOf(expandoValue.getClassPK())
379                            });
380            }
381    
382            /**
383             * Creates a new expando value with the primary key. Does not add the expando value to the database.
384             *
385             * @param valueId the primary key for the new expando value
386             * @return the new expando value
387             */
388            public ExpandoValue create(long valueId) {
389                    ExpandoValue expandoValue = new ExpandoValueImpl();
390    
391                    expandoValue.setNew(true);
392                    expandoValue.setPrimaryKey(valueId);
393    
394                    return expandoValue;
395            }
396    
397            /**
398             * Removes the expando value with the primary key from the database. Also notifies the appropriate model listeners.
399             *
400             * @param valueId the primary key of the expando value
401             * @return the expando value that was removed
402             * @throws com.liferay.portlet.expando.NoSuchValueException if a expando value with the primary key could not be found
403             * @throws SystemException if a system exception occurred
404             */
405            public ExpandoValue remove(long valueId)
406                    throws NoSuchValueException, SystemException {
407                    return remove(Long.valueOf(valueId));
408            }
409    
410            /**
411             * Removes the expando value with the primary key from the database. Also notifies the appropriate model listeners.
412             *
413             * @param primaryKey the primary key of the expando value
414             * @return the expando value that was removed
415             * @throws com.liferay.portlet.expando.NoSuchValueException if a expando value with the primary key could not be found
416             * @throws SystemException if a system exception occurred
417             */
418            @Override
419            public ExpandoValue remove(Serializable primaryKey)
420                    throws NoSuchValueException, SystemException {
421                    Session session = null;
422    
423                    try {
424                            session = openSession();
425    
426                            ExpandoValue expandoValue = (ExpandoValue)session.get(ExpandoValueImpl.class,
427                                            primaryKey);
428    
429                            if (expandoValue == null) {
430                                    if (_log.isWarnEnabled()) {
431                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
432                                    }
433    
434                                    throw new NoSuchValueException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
435                                            primaryKey);
436                            }
437    
438                            return remove(expandoValue);
439                    }
440                    catch (NoSuchValueException nsee) {
441                            throw nsee;
442                    }
443                    catch (Exception e) {
444                            throw processException(e);
445                    }
446                    finally {
447                            closeSession(session);
448                    }
449            }
450    
451            @Override
452            protected ExpandoValue removeImpl(ExpandoValue expandoValue)
453                    throws SystemException {
454                    expandoValue = toUnwrappedModel(expandoValue);
455    
456                    Session session = null;
457    
458                    try {
459                            session = openSession();
460    
461                            BatchSessionUtil.delete(session, expandoValue);
462                    }
463                    catch (Exception e) {
464                            throw processException(e);
465                    }
466                    finally {
467                            closeSession(session);
468                    }
469    
470                    clearCache(expandoValue);
471    
472                    return expandoValue;
473            }
474    
475            @Override
476            public ExpandoValue updateImpl(
477                    com.liferay.portlet.expando.model.ExpandoValue expandoValue,
478                    boolean merge) throws SystemException {
479                    expandoValue = toUnwrappedModel(expandoValue);
480    
481                    boolean isNew = expandoValue.isNew();
482    
483                    ExpandoValueModelImpl expandoValueModelImpl = (ExpandoValueModelImpl)expandoValue;
484    
485                    Session session = null;
486    
487                    try {
488                            session = openSession();
489    
490                            BatchSessionUtil.update(session, expandoValue, merge);
491    
492                            expandoValue.setNew(false);
493                    }
494                    catch (Exception e) {
495                            throw processException(e);
496                    }
497                    finally {
498                            closeSession(session);
499                    }
500    
501                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
502    
503                    if (isNew || !ExpandoValueModelImpl.COLUMN_BITMASK_ENABLED) {
504                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
505                    }
506    
507                    else {
508                            if ((expandoValueModelImpl.getColumnBitmask() &
509                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID.getColumnBitmask()) != 0) {
510                                    Object[] args = new Object[] {
511                                                    Long.valueOf(expandoValueModelImpl.getOriginalTableId())
512                                            };
513    
514                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
515                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
516                                            args);
517    
518                                    args = new Object[] {
519                                                    Long.valueOf(expandoValueModelImpl.getTableId())
520                                            };
521    
522                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
523                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
524                                            args);
525                            }
526    
527                            if ((expandoValueModelImpl.getColumnBitmask() &
528                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COLUMNID.getColumnBitmask()) != 0) {
529                                    Object[] args = new Object[] {
530                                                    Long.valueOf(expandoValueModelImpl.getOriginalColumnId())
531                                            };
532    
533                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COLUMNID, args);
534                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COLUMNID,
535                                            args);
536    
537                                    args = new Object[] {
538                                                    Long.valueOf(expandoValueModelImpl.getColumnId())
539                                            };
540    
541                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COLUMNID, args);
542                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COLUMNID,
543                                            args);
544                            }
545    
546                            if ((expandoValueModelImpl.getColumnBitmask() &
547                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROWID.getColumnBitmask()) != 0) {
548                                    Object[] args = new Object[] {
549                                                    Long.valueOf(expandoValueModelImpl.getOriginalRowId())
550                                            };
551    
552                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROWID, args);
553                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROWID,
554                                            args);
555    
556                                    args = new Object[] {
557                                                    Long.valueOf(expandoValueModelImpl.getRowId())
558                                            };
559    
560                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROWID, args);
561                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROWID,
562                                            args);
563                            }
564    
565                            if ((expandoValueModelImpl.getColumnBitmask() &
566                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_C.getColumnBitmask()) != 0) {
567                                    Object[] args = new Object[] {
568                                                    Long.valueOf(expandoValueModelImpl.getOriginalTableId()),
569                                                    Long.valueOf(expandoValueModelImpl.getOriginalColumnId())
570                                            };
571    
572                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_C, args);
573                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_C,
574                                            args);
575    
576                                    args = new Object[] {
577                                                    Long.valueOf(expandoValueModelImpl.getTableId()),
578                                                    Long.valueOf(expandoValueModelImpl.getColumnId())
579                                            };
580    
581                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_C, args);
582                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_C,
583                                            args);
584                            }
585    
586                            if ((expandoValueModelImpl.getColumnBitmask() &
587                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_CPK.getColumnBitmask()) != 0) {
588                                    Object[] args = new Object[] {
589                                                    Long.valueOf(expandoValueModelImpl.getOriginalTableId()),
590                                                    Long.valueOf(expandoValueModelImpl.getOriginalClassPK())
591                                            };
592    
593                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_CPK, args);
594                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_CPK,
595                                            args);
596    
597                                    args = new Object[] {
598                                                    Long.valueOf(expandoValueModelImpl.getTableId()),
599                                                    Long.valueOf(expandoValueModelImpl.getClassPK())
600                                            };
601    
602                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_CPK, args);
603                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_CPK,
604                                            args);
605                            }
606    
607                            if ((expandoValueModelImpl.getColumnBitmask() &
608                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_R.getColumnBitmask()) != 0) {
609                                    Object[] args = new Object[] {
610                                                    Long.valueOf(expandoValueModelImpl.getOriginalTableId()),
611                                                    Long.valueOf(expandoValueModelImpl.getOriginalRowId())
612                                            };
613    
614                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_R, args);
615                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_R,
616                                            args);
617    
618                                    args = new Object[] {
619                                                    Long.valueOf(expandoValueModelImpl.getTableId()),
620                                                    Long.valueOf(expandoValueModelImpl.getRowId())
621                                            };
622    
623                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_R, args);
624                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_R,
625                                            args);
626                            }
627    
628                            if ((expandoValueModelImpl.getColumnBitmask() &
629                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
630                                    Object[] args = new Object[] {
631                                                    Long.valueOf(expandoValueModelImpl.getOriginalClassNameId()),
632                                                    Long.valueOf(expandoValueModelImpl.getOriginalClassPK())
633                                            };
634    
635                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
636                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
637                                            args);
638    
639                                    args = new Object[] {
640                                                    Long.valueOf(expandoValueModelImpl.getClassNameId()),
641                                                    Long.valueOf(expandoValueModelImpl.getClassPK())
642                                            };
643    
644                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
645                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
646                                            args);
647                            }
648    
649                            if ((expandoValueModelImpl.getColumnBitmask() &
650                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_C_D.getColumnBitmask()) != 0) {
651                                    Object[] args = new Object[] {
652                                                    Long.valueOf(expandoValueModelImpl.getOriginalTableId()),
653                                                    Long.valueOf(expandoValueModelImpl.getOriginalColumnId()),
654                                                    
655                                                    expandoValueModelImpl.getOriginalData()
656                                            };
657    
658                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_C_D, args);
659                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_C_D,
660                                            args);
661    
662                                    args = new Object[] {
663                                                    Long.valueOf(expandoValueModelImpl.getTableId()),
664                                                    Long.valueOf(expandoValueModelImpl.getColumnId()),
665                                                    
666                                                    expandoValueModelImpl.getData()
667                                            };
668    
669                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_C_D, args);
670                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_C_D,
671                                            args);
672                            }
673                    }
674    
675                    EntityCacheUtil.putResult(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
676                            ExpandoValueImpl.class, expandoValue.getPrimaryKey(), expandoValue);
677    
678                    if (isNew) {
679                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R,
680                                    new Object[] {
681                                            Long.valueOf(expandoValue.getColumnId()),
682                                            Long.valueOf(expandoValue.getRowId())
683                                    }, expandoValue);
684    
685                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C_C,
686                                    new Object[] {
687                                            Long.valueOf(expandoValue.getTableId()),
688                                            Long.valueOf(expandoValue.getColumnId()),
689                                            Long.valueOf(expandoValue.getClassPK())
690                                    }, expandoValue);
691                    }
692                    else {
693                            if ((expandoValueModelImpl.getColumnBitmask() &
694                                            FINDER_PATH_FETCH_BY_C_R.getColumnBitmask()) != 0) {
695                                    Object[] args = new Object[] {
696                                                    Long.valueOf(expandoValueModelImpl.getOriginalColumnId()),
697                                                    Long.valueOf(expandoValueModelImpl.getOriginalRowId())
698                                            };
699    
700                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_R, args);
701    
702                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_R, args);
703    
704                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R,
705                                            new Object[] {
706                                                    Long.valueOf(expandoValue.getColumnId()),
707                                                    Long.valueOf(expandoValue.getRowId())
708                                            }, expandoValue);
709                            }
710    
711                            if ((expandoValueModelImpl.getColumnBitmask() &
712                                            FINDER_PATH_FETCH_BY_T_C_C.getColumnBitmask()) != 0) {
713                                    Object[] args = new Object[] {
714                                                    Long.valueOf(expandoValueModelImpl.getOriginalTableId()),
715                                                    Long.valueOf(expandoValueModelImpl.getOriginalColumnId()),
716                                                    Long.valueOf(expandoValueModelImpl.getOriginalClassPK())
717                                            };
718    
719                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_C_C, args);
720    
721                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C_C, args);
722    
723                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C_C,
724                                            new Object[] {
725                                                    Long.valueOf(expandoValue.getTableId()),
726                                                    Long.valueOf(expandoValue.getColumnId()),
727                                                    Long.valueOf(expandoValue.getClassPK())
728                                            }, expandoValue);
729                            }
730                    }
731    
732                    return expandoValue;
733            }
734    
735            protected ExpandoValue toUnwrappedModel(ExpandoValue expandoValue) {
736                    if (expandoValue instanceof ExpandoValueImpl) {
737                            return expandoValue;
738                    }
739    
740                    ExpandoValueImpl expandoValueImpl = new ExpandoValueImpl();
741    
742                    expandoValueImpl.setNew(expandoValue.isNew());
743                    expandoValueImpl.setPrimaryKey(expandoValue.getPrimaryKey());
744    
745                    expandoValueImpl.setValueId(expandoValue.getValueId());
746                    expandoValueImpl.setCompanyId(expandoValue.getCompanyId());
747                    expandoValueImpl.setTableId(expandoValue.getTableId());
748                    expandoValueImpl.setColumnId(expandoValue.getColumnId());
749                    expandoValueImpl.setRowId(expandoValue.getRowId());
750                    expandoValueImpl.setClassNameId(expandoValue.getClassNameId());
751                    expandoValueImpl.setClassPK(expandoValue.getClassPK());
752                    expandoValueImpl.setData(expandoValue.getData());
753    
754                    return expandoValueImpl;
755            }
756    
757            /**
758             * Returns the expando value with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
759             *
760             * @param primaryKey the primary key of the expando value
761             * @return the expando value
762             * @throws com.liferay.portal.NoSuchModelException if a expando value with the primary key could not be found
763             * @throws SystemException if a system exception occurred
764             */
765            @Override
766            public ExpandoValue findByPrimaryKey(Serializable primaryKey)
767                    throws NoSuchModelException, SystemException {
768                    return findByPrimaryKey(((Long)primaryKey).longValue());
769            }
770    
771            /**
772             * Returns the expando value with the primary key or throws a {@link com.liferay.portlet.expando.NoSuchValueException} if it could not be found.
773             *
774             * @param valueId the primary key of the expando value
775             * @return the expando value
776             * @throws com.liferay.portlet.expando.NoSuchValueException if a expando value with the primary key could not be found
777             * @throws SystemException if a system exception occurred
778             */
779            public ExpandoValue findByPrimaryKey(long valueId)
780                    throws NoSuchValueException, SystemException {
781                    ExpandoValue expandoValue = fetchByPrimaryKey(valueId);
782    
783                    if (expandoValue == null) {
784                            if (_log.isWarnEnabled()) {
785                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + valueId);
786                            }
787    
788                            throw new NoSuchValueException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
789                                    valueId);
790                    }
791    
792                    return expandoValue;
793            }
794    
795            /**
796             * Returns the expando value with the primary key or returns <code>null</code> if it could not be found.
797             *
798             * @param primaryKey the primary key of the expando value
799             * @return the expando value, or <code>null</code> if a expando value with the primary key could not be found
800             * @throws SystemException if a system exception occurred
801             */
802            @Override
803            public ExpandoValue fetchByPrimaryKey(Serializable primaryKey)
804                    throws SystemException {
805                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
806            }
807    
808            /**
809             * Returns the expando value with the primary key or returns <code>null</code> if it could not be found.
810             *
811             * @param valueId the primary key of the expando value
812             * @return the expando value, or <code>null</code> if a expando value with the primary key could not be found
813             * @throws SystemException if a system exception occurred
814             */
815            public ExpandoValue fetchByPrimaryKey(long valueId)
816                    throws SystemException {
817                    ExpandoValue expandoValue = (ExpandoValue)EntityCacheUtil.getResult(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
818                                    ExpandoValueImpl.class, valueId);
819    
820                    if (expandoValue == _nullExpandoValue) {
821                            return null;
822                    }
823    
824                    if (expandoValue == null) {
825                            Session session = null;
826    
827                            boolean hasException = false;
828    
829                            try {
830                                    session = openSession();
831    
832                                    expandoValue = (ExpandoValue)session.get(ExpandoValueImpl.class,
833                                                    Long.valueOf(valueId));
834                            }
835                            catch (Exception e) {
836                                    hasException = true;
837    
838                                    throw processException(e);
839                            }
840                            finally {
841                                    if (expandoValue != null) {
842                                            cacheResult(expandoValue);
843                                    }
844                                    else if (!hasException) {
845                                            EntityCacheUtil.putResult(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
846                                                    ExpandoValueImpl.class, valueId, _nullExpandoValue);
847                                    }
848    
849                                    closeSession(session);
850                            }
851                    }
852    
853                    return expandoValue;
854            }
855    
856            /**
857             * Returns all the expando values where tableId = &#63;.
858             *
859             * @param tableId the table ID
860             * @return the matching expando values
861             * @throws SystemException if a system exception occurred
862             */
863            public List<ExpandoValue> findByTableId(long tableId)
864                    throws SystemException {
865                    return findByTableId(tableId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
866            }
867    
868            /**
869             * Returns a range of all the expando values where tableId = &#63;.
870             *
871             * <p>
872             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
873             * </p>
874             *
875             * @param tableId the table ID
876             * @param start the lower bound of the range of expando values
877             * @param end the upper bound of the range of expando values (not inclusive)
878             * @return the range of matching expando values
879             * @throws SystemException if a system exception occurred
880             */
881            public List<ExpandoValue> findByTableId(long tableId, int start, int end)
882                    throws SystemException {
883                    return findByTableId(tableId, start, end, null);
884            }
885    
886            /**
887             * Returns an ordered range of all the expando values where tableId = &#63;.
888             *
889             * <p>
890             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
891             * </p>
892             *
893             * @param tableId the table ID
894             * @param start the lower bound of the range of expando values
895             * @param end the upper bound of the range of expando values (not inclusive)
896             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
897             * @return the ordered range of matching expando values
898             * @throws SystemException if a system exception occurred
899             */
900            public List<ExpandoValue> findByTableId(long tableId, int start, int end,
901                    OrderByComparator orderByComparator) throws SystemException {
902                    FinderPath finderPath = null;
903                    Object[] finderArgs = null;
904    
905                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
906                                    (orderByComparator == null)) {
907                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID;
908                            finderArgs = new Object[] { tableId };
909                    }
910                    else {
911                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TABLEID;
912                            finderArgs = new Object[] { tableId, start, end, orderByComparator };
913                    }
914    
915                    List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(finderPath,
916                                    finderArgs, this);
917    
918                    if ((list != null) && !list.isEmpty()) {
919                            for (ExpandoValue expandoValue : list) {
920                                    if ((tableId != expandoValue.getTableId())) {
921                                            list = null;
922    
923                                            break;
924                                    }
925                            }
926                    }
927    
928                    if (list == null) {
929                            StringBundler query = null;
930    
931                            if (orderByComparator != null) {
932                                    query = new StringBundler(3 +
933                                                    (orderByComparator.getOrderByFields().length * 3));
934                            }
935                            else {
936                                    query = new StringBundler(3);
937                            }
938    
939                            query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
940    
941                            query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
942    
943                            if (orderByComparator != null) {
944                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
945                                            orderByComparator);
946                            }
947    
948                            else {
949                                    query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
950                            }
951    
952                            String sql = query.toString();
953    
954                            Session session = null;
955    
956                            try {
957                                    session = openSession();
958    
959                                    Query q = session.createQuery(sql);
960    
961                                    QueryPos qPos = QueryPos.getInstance(q);
962    
963                                    qPos.add(tableId);
964    
965                                    list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
966                                                    start, end);
967                            }
968                            catch (Exception e) {
969                                    throw processException(e);
970                            }
971                            finally {
972                                    if (list == null) {
973                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
974                                    }
975                                    else {
976                                            cacheResult(list);
977    
978                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
979                                    }
980    
981                                    closeSession(session);
982                            }
983                    }
984    
985                    return list;
986            }
987    
988            /**
989             * Returns the first expando value in the ordered set where tableId = &#63;.
990             *
991             * @param tableId the table ID
992             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
993             * @return the first matching expando value
994             * @throws com.liferay.portlet.expando.NoSuchValueException if a matching expando value could not be found
995             * @throws SystemException if a system exception occurred
996             */
997            public ExpandoValue findByTableId_First(long tableId,
998                    OrderByComparator orderByComparator)
999                    throws NoSuchValueException, SystemException {
1000                    ExpandoValue expandoValue = fetchByTableId_First(tableId,
1001                                    orderByComparator);
1002    
1003                    if (expandoValue != null) {
1004                            return expandoValue;
1005                    }
1006    
1007                    StringBundler msg = new StringBundler(4);
1008    
1009                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1010    
1011                    msg.append("tableId=");
1012                    msg.append(tableId);
1013    
1014                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1015    
1016                    throw new NoSuchValueException(msg.toString());
1017            }
1018    
1019            /**
1020             * Returns the first expando value in the ordered set where tableId = &#63;.
1021             *
1022             * @param tableId the table ID
1023             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1024             * @return the first matching expando value, or <code>null</code> if a matching expando value could not be found
1025             * @throws SystemException if a system exception occurred
1026             */
1027            public ExpandoValue fetchByTableId_First(long tableId,
1028                    OrderByComparator orderByComparator) throws SystemException {
1029                    List<ExpandoValue> list = findByTableId(tableId, 0, 1, orderByComparator);
1030    
1031                    if (!list.isEmpty()) {
1032                            return list.get(0);
1033                    }
1034    
1035                    return null;
1036            }
1037    
1038            /**
1039             * Returns the last expando value in the ordered set where tableId = &#63;.
1040             *
1041             * @param tableId the table ID
1042             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1043             * @return the last matching expando value
1044             * @throws com.liferay.portlet.expando.NoSuchValueException if a matching expando value could not be found
1045             * @throws SystemException if a system exception occurred
1046             */
1047            public ExpandoValue findByTableId_Last(long tableId,
1048                    OrderByComparator orderByComparator)
1049                    throws NoSuchValueException, SystemException {
1050                    ExpandoValue expandoValue = fetchByTableId_Last(tableId,
1051                                    orderByComparator);
1052    
1053                    if (expandoValue != null) {
1054                            return expandoValue;
1055                    }
1056    
1057                    StringBundler msg = new StringBundler(4);
1058    
1059                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1060    
1061                    msg.append("tableId=");
1062                    msg.append(tableId);
1063    
1064                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1065    
1066                    throw new NoSuchValueException(msg.toString());
1067            }
1068    
1069            /**
1070             * Returns the last expando value in the ordered set where tableId = &#63;.
1071             *
1072             * @param tableId the table ID
1073             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1074             * @return the last matching expando value, or <code>null</code> if a matching expando value could not be found
1075             * @throws SystemException if a system exception occurred
1076             */
1077            public ExpandoValue fetchByTableId_Last(long tableId,
1078                    OrderByComparator orderByComparator) throws SystemException {
1079                    int count = countByTableId(tableId);
1080    
1081                    List<ExpandoValue> list = findByTableId(tableId, count - 1, count,
1082                                    orderByComparator);
1083    
1084                    if (!list.isEmpty()) {
1085                            return list.get(0);
1086                    }
1087    
1088                    return null;
1089            }
1090    
1091            /**
1092             * Returns the expando values before and after the current expando value in the ordered set where tableId = &#63;.
1093             *
1094             * @param valueId the primary key of the current expando value
1095             * @param tableId the table ID
1096             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1097             * @return the previous, current, and next expando value
1098             * @throws com.liferay.portlet.expando.NoSuchValueException if a expando value with the primary key could not be found
1099             * @throws SystemException if a system exception occurred
1100             */
1101            public ExpandoValue[] findByTableId_PrevAndNext(long valueId, long tableId,
1102                    OrderByComparator orderByComparator)
1103                    throws NoSuchValueException, SystemException {
1104                    ExpandoValue expandoValue = findByPrimaryKey(valueId);
1105    
1106                    Session session = null;
1107    
1108                    try {
1109                            session = openSession();
1110    
1111                            ExpandoValue[] array = new ExpandoValueImpl[3];
1112    
1113                            array[0] = getByTableId_PrevAndNext(session, expandoValue, tableId,
1114                                            orderByComparator, true);
1115    
1116                            array[1] = expandoValue;
1117    
1118                            array[2] = getByTableId_PrevAndNext(session, expandoValue, tableId,
1119                                            orderByComparator, false);
1120    
1121                            return array;
1122                    }
1123                    catch (Exception e) {
1124                            throw processException(e);
1125                    }
1126                    finally {
1127                            closeSession(session);
1128                    }
1129            }
1130    
1131            protected ExpandoValue getByTableId_PrevAndNext(Session session,
1132                    ExpandoValue expandoValue, long tableId,
1133                    OrderByComparator orderByComparator, boolean previous) {
1134                    StringBundler query = null;
1135    
1136                    if (orderByComparator != null) {
1137                            query = new StringBundler(6 +
1138                                            (orderByComparator.getOrderByFields().length * 6));
1139                    }
1140                    else {
1141                            query = new StringBundler(3);
1142                    }
1143    
1144                    query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1145    
1146                    query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
1147    
1148                    if (orderByComparator != null) {
1149                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1150    
1151                            if (orderByConditionFields.length > 0) {
1152                                    query.append(WHERE_AND);
1153                            }
1154    
1155                            for (int i = 0; i < orderByConditionFields.length; i++) {
1156                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1157                                    query.append(orderByConditionFields[i]);
1158    
1159                                    if ((i + 1) < orderByConditionFields.length) {
1160                                            if (orderByComparator.isAscending() ^ previous) {
1161                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1162                                            }
1163                                            else {
1164                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1165                                            }
1166                                    }
1167                                    else {
1168                                            if (orderByComparator.isAscending() ^ previous) {
1169                                                    query.append(WHERE_GREATER_THAN);
1170                                            }
1171                                            else {
1172                                                    query.append(WHERE_LESSER_THAN);
1173                                            }
1174                                    }
1175                            }
1176    
1177                            query.append(ORDER_BY_CLAUSE);
1178    
1179                            String[] orderByFields = orderByComparator.getOrderByFields();
1180    
1181                            for (int i = 0; i < orderByFields.length; i++) {
1182                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1183                                    query.append(orderByFields[i]);
1184    
1185                                    if ((i + 1) < orderByFields.length) {
1186                                            if (orderByComparator.isAscending() ^ previous) {
1187                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1188                                            }
1189                                            else {
1190                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1191                                            }
1192                                    }
1193                                    else {
1194                                            if (orderByComparator.isAscending() ^ previous) {
1195                                                    query.append(ORDER_BY_ASC);
1196                                            }
1197                                            else {
1198                                                    query.append(ORDER_BY_DESC);
1199                                            }
1200                                    }
1201                            }
1202                    }
1203    
1204                    else {
1205                            query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1206                    }
1207    
1208                    String sql = query.toString();
1209    
1210                    Query q = session.createQuery(sql);
1211    
1212                    q.setFirstResult(0);
1213                    q.setMaxResults(2);
1214    
1215                    QueryPos qPos = QueryPos.getInstance(q);
1216    
1217                    qPos.add(tableId);
1218    
1219                    if (orderByComparator != null) {
1220                            Object[] values = orderByComparator.getOrderByConditionValues(expandoValue);
1221    
1222                            for (Object value : values) {
1223                                    qPos.add(value);
1224                            }
1225                    }
1226    
1227                    List<ExpandoValue> list = q.list();
1228    
1229                    if (list.size() == 2) {
1230                            return list.get(1);
1231                    }
1232                    else {
1233                            return null;
1234                    }
1235            }
1236    
1237            /**
1238             * Returns all the expando values where columnId = &#63;.
1239             *
1240             * @param columnId the column ID
1241             * @return the matching expando values
1242             * @throws SystemException if a system exception occurred
1243             */
1244            public List<ExpandoValue> findByColumnId(long columnId)
1245                    throws SystemException {
1246                    return findByColumnId(columnId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1247                            null);
1248            }
1249    
1250            /**
1251             * Returns a range of all the expando values where columnId = &#63;.
1252             *
1253             * <p>
1254             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1255             * </p>
1256             *
1257             * @param columnId the column ID
1258             * @param start the lower bound of the range of expando values
1259             * @param end the upper bound of the range of expando values (not inclusive)
1260             * @return the range of matching expando values
1261             * @throws SystemException if a system exception occurred
1262             */
1263            public List<ExpandoValue> findByColumnId(long columnId, int start, int end)
1264                    throws SystemException {
1265                    return findByColumnId(columnId, start, end, null);
1266            }
1267    
1268            /**
1269             * Returns an ordered range of all the expando values where columnId = &#63;.
1270             *
1271             * <p>
1272             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1273             * </p>
1274             *
1275             * @param columnId the column ID
1276             * @param start the lower bound of the range of expando values
1277             * @param end the upper bound of the range of expando values (not inclusive)
1278             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1279             * @return the ordered range of matching expando values
1280             * @throws SystemException if a system exception occurred
1281             */
1282            public List<ExpandoValue> findByColumnId(long columnId, int start, int end,
1283                    OrderByComparator orderByComparator) throws SystemException {
1284                    FinderPath finderPath = null;
1285                    Object[] finderArgs = null;
1286    
1287                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1288                                    (orderByComparator == null)) {
1289                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COLUMNID;
1290                            finderArgs = new Object[] { columnId };
1291                    }
1292                    else {
1293                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COLUMNID;
1294                            finderArgs = new Object[] { columnId, start, end, orderByComparator };
1295                    }
1296    
1297                    List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(finderPath,
1298                                    finderArgs, this);
1299    
1300                    if ((list != null) && !list.isEmpty()) {
1301                            for (ExpandoValue expandoValue : list) {
1302                                    if ((columnId != expandoValue.getColumnId())) {
1303                                            list = null;
1304    
1305                                            break;
1306                                    }
1307                            }
1308                    }
1309    
1310                    if (list == null) {
1311                            StringBundler query = null;
1312    
1313                            if (orderByComparator != null) {
1314                                    query = new StringBundler(3 +
1315                                                    (orderByComparator.getOrderByFields().length * 3));
1316                            }
1317                            else {
1318                                    query = new StringBundler(3);
1319                            }
1320    
1321                            query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1322    
1323                            query.append(_FINDER_COLUMN_COLUMNID_COLUMNID_2);
1324    
1325                            if (orderByComparator != null) {
1326                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1327                                            orderByComparator);
1328                            }
1329    
1330                            else {
1331                                    query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1332                            }
1333    
1334                            String sql = query.toString();
1335    
1336                            Session session = null;
1337    
1338                            try {
1339                                    session = openSession();
1340    
1341                                    Query q = session.createQuery(sql);
1342    
1343                                    QueryPos qPos = QueryPos.getInstance(q);
1344    
1345                                    qPos.add(columnId);
1346    
1347                                    list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
1348                                                    start, end);
1349                            }
1350                            catch (Exception e) {
1351                                    throw processException(e);
1352                            }
1353                            finally {
1354                                    if (list == null) {
1355                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1356                                    }
1357                                    else {
1358                                            cacheResult(list);
1359    
1360                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1361                                    }
1362    
1363                                    closeSession(session);
1364                            }
1365                    }
1366    
1367                    return list;
1368            }
1369    
1370            /**
1371             * Returns the first expando value in the ordered set where columnId = &#63;.
1372             *
1373             * @param columnId the column ID
1374             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1375             * @return the first matching expando value
1376             * @throws com.liferay.portlet.expando.NoSuchValueException if a matching expando value could not be found
1377             * @throws SystemException if a system exception occurred
1378             */
1379            public ExpandoValue findByColumnId_First(long columnId,
1380                    OrderByComparator orderByComparator)
1381                    throws NoSuchValueException, SystemException {
1382                    ExpandoValue expandoValue = fetchByColumnId_First(columnId,
1383                                    orderByComparator);
1384    
1385                    if (expandoValue != null) {
1386                            return expandoValue;
1387                    }
1388    
1389                    StringBundler msg = new StringBundler(4);
1390    
1391                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1392    
1393                    msg.append("columnId=");
1394                    msg.append(columnId);
1395    
1396                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1397    
1398                    throw new NoSuchValueException(msg.toString());
1399            }
1400    
1401            /**
1402             * Returns the first expando value in the ordered set where columnId = &#63;.
1403             *
1404             * @param columnId the column ID
1405             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1406             * @return the first matching expando value, or <code>null</code> if a matching expando value could not be found
1407             * @throws SystemException if a system exception occurred
1408             */
1409            public ExpandoValue fetchByColumnId_First(long columnId,
1410                    OrderByComparator orderByComparator) throws SystemException {
1411                    List<ExpandoValue> list = findByColumnId(columnId, 0, 1,
1412                                    orderByComparator);
1413    
1414                    if (!list.isEmpty()) {
1415                            return list.get(0);
1416                    }
1417    
1418                    return null;
1419            }
1420    
1421            /**
1422             * Returns the last expando value in the ordered set where columnId = &#63;.
1423             *
1424             * @param columnId the column ID
1425             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1426             * @return the last matching expando value
1427             * @throws com.liferay.portlet.expando.NoSuchValueException if a matching expando value could not be found
1428             * @throws SystemException if a system exception occurred
1429             */
1430            public ExpandoValue findByColumnId_Last(long columnId,
1431                    OrderByComparator orderByComparator)
1432                    throws NoSuchValueException, SystemException {
1433                    ExpandoValue expandoValue = fetchByColumnId_Last(columnId,
1434                                    orderByComparator);
1435    
1436                    if (expandoValue != null) {
1437                            return expandoValue;
1438                    }
1439    
1440                    StringBundler msg = new StringBundler(4);
1441    
1442                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1443    
1444                    msg.append("columnId=");
1445                    msg.append(columnId);
1446    
1447                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1448    
1449                    throw new NoSuchValueException(msg.toString());
1450            }
1451    
1452            /**
1453             * Returns the last expando value in the ordered set where columnId = &#63;.
1454             *
1455             * @param columnId the column ID
1456             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1457             * @return the last matching expando value, or <code>null</code> if a matching expando value could not be found
1458             * @throws SystemException if a system exception occurred
1459             */
1460            public ExpandoValue fetchByColumnId_Last(long columnId,
1461                    OrderByComparator orderByComparator) throws SystemException {
1462                    int count = countByColumnId(columnId);
1463    
1464                    List<ExpandoValue> list = findByColumnId(columnId, count - 1, count,
1465                                    orderByComparator);
1466    
1467                    if (!list.isEmpty()) {
1468                            return list.get(0);
1469                    }
1470    
1471                    return null;
1472            }
1473    
1474            /**
1475             * Returns the expando values before and after the current expando value in the ordered set where columnId = &#63;.
1476             *
1477             * @param valueId the primary key of the current expando value
1478             * @param columnId the column ID
1479             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1480             * @return the previous, current, and next expando value
1481             * @throws com.liferay.portlet.expando.NoSuchValueException if a expando value with the primary key could not be found
1482             * @throws SystemException if a system exception occurred
1483             */
1484            public ExpandoValue[] findByColumnId_PrevAndNext(long valueId,
1485                    long columnId, OrderByComparator orderByComparator)
1486                    throws NoSuchValueException, SystemException {
1487                    ExpandoValue expandoValue = findByPrimaryKey(valueId);
1488    
1489                    Session session = null;
1490    
1491                    try {
1492                            session = openSession();
1493    
1494                            ExpandoValue[] array = new ExpandoValueImpl[3];
1495    
1496                            array[0] = getByColumnId_PrevAndNext(session, expandoValue,
1497                                            columnId, orderByComparator, true);
1498    
1499                            array[1] = expandoValue;
1500    
1501                            array[2] = getByColumnId_PrevAndNext(session, expandoValue,
1502                                            columnId, orderByComparator, false);
1503    
1504                            return array;
1505                    }
1506                    catch (Exception e) {
1507                            throw processException(e);
1508                    }
1509                    finally {
1510                            closeSession(session);
1511                    }
1512            }
1513    
1514            protected ExpandoValue getByColumnId_PrevAndNext(Session session,
1515                    ExpandoValue expandoValue, long columnId,
1516                    OrderByComparator orderByComparator, boolean previous) {
1517                    StringBundler query = null;
1518    
1519                    if (orderByComparator != null) {
1520                            query = new StringBundler(6 +
1521                                            (orderByComparator.getOrderByFields().length * 6));
1522                    }
1523                    else {
1524                            query = new StringBundler(3);
1525                    }
1526    
1527                    query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1528    
1529                    query.append(_FINDER_COLUMN_COLUMNID_COLUMNID_2);
1530    
1531                    if (orderByComparator != null) {
1532                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1533    
1534                            if (orderByConditionFields.length > 0) {
1535                                    query.append(WHERE_AND);
1536                            }
1537    
1538                            for (int i = 0; i < orderByConditionFields.length; i++) {
1539                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1540                                    query.append(orderByConditionFields[i]);
1541    
1542                                    if ((i + 1) < orderByConditionFields.length) {
1543                                            if (orderByComparator.isAscending() ^ previous) {
1544                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1545                                            }
1546                                            else {
1547                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1548                                            }
1549                                    }
1550                                    else {
1551                                            if (orderByComparator.isAscending() ^ previous) {
1552                                                    query.append(WHERE_GREATER_THAN);
1553                                            }
1554                                            else {
1555                                                    query.append(WHERE_LESSER_THAN);
1556                                            }
1557                                    }
1558                            }
1559    
1560                            query.append(ORDER_BY_CLAUSE);
1561    
1562                            String[] orderByFields = orderByComparator.getOrderByFields();
1563    
1564                            for (int i = 0; i < orderByFields.length; i++) {
1565                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1566                                    query.append(orderByFields[i]);
1567    
1568                                    if ((i + 1) < orderByFields.length) {
1569                                            if (orderByComparator.isAscending() ^ previous) {
1570                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1571                                            }
1572                                            else {
1573                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1574                                            }
1575                                    }
1576                                    else {
1577                                            if (orderByComparator.isAscending() ^ previous) {
1578                                                    query.append(ORDER_BY_ASC);
1579                                            }
1580                                            else {
1581                                                    query.append(ORDER_BY_DESC);
1582                                            }
1583                                    }
1584                            }
1585                    }
1586    
1587                    else {
1588                            query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1589                    }
1590    
1591                    String sql = query.toString();
1592    
1593                    Query q = session.createQuery(sql);
1594    
1595                    q.setFirstResult(0);
1596                    q.setMaxResults(2);
1597    
1598                    QueryPos qPos = QueryPos.getInstance(q);
1599    
1600                    qPos.add(columnId);
1601    
1602                    if (orderByComparator != null) {
1603                            Object[] values = orderByComparator.getOrderByConditionValues(expandoValue);
1604    
1605                            for (Object value : values) {
1606                                    qPos.add(value);
1607                            }
1608                    }
1609    
1610                    List<ExpandoValue> list = q.list();
1611    
1612                    if (list.size() == 2) {
1613                            return list.get(1);
1614                    }
1615                    else {
1616                            return null;
1617                    }
1618            }
1619    
1620            /**
1621             * Returns all the expando values where rowId = &#63;.
1622             *
1623             * @param rowId the row ID
1624             * @return the matching expando values
1625             * @throws SystemException if a system exception occurred
1626             */
1627            public List<ExpandoValue> findByRowId(long rowId) throws SystemException {
1628                    return findByRowId(rowId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1629            }
1630    
1631            /**
1632             * Returns a range of all the expando values where rowId = &#63;.
1633             *
1634             * <p>
1635             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1636             * </p>
1637             *
1638             * @param rowId the row ID
1639             * @param start the lower bound of the range of expando values
1640             * @param end the upper bound of the range of expando values (not inclusive)
1641             * @return the range of matching expando values
1642             * @throws SystemException if a system exception occurred
1643             */
1644            public List<ExpandoValue> findByRowId(long rowId, int start, int end)
1645                    throws SystemException {
1646                    return findByRowId(rowId, start, end, null);
1647            }
1648    
1649            /**
1650             * Returns an ordered range of all the expando values where rowId = &#63;.
1651             *
1652             * <p>
1653             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1654             * </p>
1655             *
1656             * @param rowId the row ID
1657             * @param start the lower bound of the range of expando values
1658             * @param end the upper bound of the range of expando values (not inclusive)
1659             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1660             * @return the ordered range of matching expando values
1661             * @throws SystemException if a system exception occurred
1662             */
1663            public List<ExpandoValue> findByRowId(long rowId, int start, int end,
1664                    OrderByComparator orderByComparator) throws SystemException {
1665                    FinderPath finderPath = null;
1666                    Object[] finderArgs = null;
1667    
1668                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1669                                    (orderByComparator == null)) {
1670                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROWID;
1671                            finderArgs = new Object[] { rowId };
1672                    }
1673                    else {
1674                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ROWID;
1675                            finderArgs = new Object[] { rowId, start, end, orderByComparator };
1676                    }
1677    
1678                    List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(finderPath,
1679                                    finderArgs, this);
1680    
1681                    if ((list != null) && !list.isEmpty()) {
1682                            for (ExpandoValue expandoValue : list) {
1683                                    if ((rowId != expandoValue.getRowId())) {
1684                                            list = null;
1685    
1686                                            break;
1687                                    }
1688                            }
1689                    }
1690    
1691                    if (list == null) {
1692                            StringBundler query = null;
1693    
1694                            if (orderByComparator != null) {
1695                                    query = new StringBundler(3 +
1696                                                    (orderByComparator.getOrderByFields().length * 3));
1697                            }
1698                            else {
1699                                    query = new StringBundler(3);
1700                            }
1701    
1702                            query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1703    
1704                            query.append(_FINDER_COLUMN_ROWID_ROWID_2);
1705    
1706                            if (orderByComparator != null) {
1707                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1708                                            orderByComparator);
1709                            }
1710    
1711                            else {
1712                                    query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1713                            }
1714    
1715                            String sql = query.toString();
1716    
1717                            Session session = null;
1718    
1719                            try {
1720                                    session = openSession();
1721    
1722                                    Query q = session.createQuery(sql);
1723    
1724                                    QueryPos qPos = QueryPos.getInstance(q);
1725    
1726                                    qPos.add(rowId);
1727    
1728                                    list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
1729                                                    start, end);
1730                            }
1731                            catch (Exception e) {
1732                                    throw processException(e);
1733                            }
1734                            finally {
1735                                    if (list == null) {
1736                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1737                                    }
1738                                    else {
1739                                            cacheResult(list);
1740    
1741                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1742                                    }
1743    
1744                                    closeSession(session);
1745                            }
1746                    }
1747    
1748                    return list;
1749            }
1750    
1751            /**
1752             * Returns the first expando value in the ordered set where rowId = &#63;.
1753             *
1754             * @param rowId the row ID
1755             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1756             * @return the first matching expando value
1757             * @throws com.liferay.portlet.expando.NoSuchValueException if a matching expando value could not be found
1758             * @throws SystemException if a system exception occurred
1759             */
1760            public ExpandoValue findByRowId_First(long rowId,
1761                    OrderByComparator orderByComparator)
1762                    throws NoSuchValueException, SystemException {
1763                    ExpandoValue expandoValue = fetchByRowId_First(rowId, orderByComparator);
1764    
1765                    if (expandoValue != null) {
1766                            return expandoValue;
1767                    }
1768    
1769                    StringBundler msg = new StringBundler(4);
1770    
1771                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1772    
1773                    msg.append("rowId=");
1774                    msg.append(rowId);
1775    
1776                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1777    
1778                    throw new NoSuchValueException(msg.toString());
1779            }
1780    
1781            /**
1782             * Returns the first expando value in the ordered set where rowId = &#63;.
1783             *
1784             * @param rowId the row ID
1785             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1786             * @return the first matching expando value, or <code>null</code> if a matching expando value could not be found
1787             * @throws SystemException if a system exception occurred
1788             */
1789            public ExpandoValue fetchByRowId_First(long rowId,
1790                    OrderByComparator orderByComparator) throws SystemException {
1791                    List<ExpandoValue> list = findByRowId(rowId, 0, 1, orderByComparator);
1792    
1793                    if (!list.isEmpty()) {
1794                            return list.get(0);
1795                    }
1796    
1797                    return null;
1798            }
1799    
1800            /**
1801             * Returns the last expando value in the ordered set where rowId = &#63;.
1802             *
1803             * @param rowId the row ID
1804             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1805             * @return the last matching expando value
1806             * @throws com.liferay.portlet.expando.NoSuchValueException if a matching expando value could not be found
1807             * @throws SystemException if a system exception occurred
1808             */
1809            public ExpandoValue findByRowId_Last(long rowId,
1810                    OrderByComparator orderByComparator)
1811                    throws NoSuchValueException, SystemException {
1812                    ExpandoValue expandoValue = fetchByRowId_Last(rowId, orderByComparator);
1813    
1814                    if (expandoValue != null) {
1815                            return expandoValue;
1816                    }
1817    
1818                    StringBundler msg = new StringBundler(4);
1819    
1820                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1821    
1822                    msg.append("rowId=");
1823                    msg.append(rowId);
1824    
1825                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1826    
1827                    throw new NoSuchValueException(msg.toString());
1828            }
1829    
1830            /**
1831             * Returns the last expando value in the ordered set where rowId = &#63;.
1832             *
1833             * @param rowId the row ID
1834             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1835             * @return the last matching expando value, or <code>null</code> if a matching expando value could not be found
1836             * @throws SystemException if a system exception occurred
1837             */
1838            public ExpandoValue fetchByRowId_Last(long rowId,
1839                    OrderByComparator orderByComparator) throws SystemException {
1840                    int count = countByRowId(rowId);
1841    
1842                    List<ExpandoValue> list = findByRowId(rowId, count - 1, count,
1843                                    orderByComparator);
1844    
1845                    if (!list.isEmpty()) {
1846                            return list.get(0);
1847                    }
1848    
1849                    return null;
1850            }
1851    
1852            /**
1853             * Returns the expando values before and after the current expando value in the ordered set where rowId = &#63;.
1854             *
1855             * @param valueId the primary key of the current expando value
1856             * @param rowId the row ID
1857             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1858             * @return the previous, current, and next expando value
1859             * @throws com.liferay.portlet.expando.NoSuchValueException if a expando value with the primary key could not be found
1860             * @throws SystemException if a system exception occurred
1861             */
1862            public ExpandoValue[] findByRowId_PrevAndNext(long valueId, long rowId,
1863                    OrderByComparator orderByComparator)
1864                    throws NoSuchValueException, SystemException {
1865                    ExpandoValue expandoValue = findByPrimaryKey(valueId);
1866    
1867                    Session session = null;
1868    
1869                    try {
1870                            session = openSession();
1871    
1872                            ExpandoValue[] array = new ExpandoValueImpl[3];
1873    
1874                            array[0] = getByRowId_PrevAndNext(session, expandoValue, rowId,
1875                                            orderByComparator, true);
1876    
1877                            array[1] = expandoValue;
1878    
1879                            array[2] = getByRowId_PrevAndNext(session, expandoValue, rowId,
1880                                            orderByComparator, false);
1881    
1882                            return array;
1883                    }
1884                    catch (Exception e) {
1885                            throw processException(e);
1886                    }
1887                    finally {
1888                            closeSession(session);
1889                    }
1890            }
1891    
1892            protected ExpandoValue getByRowId_PrevAndNext(Session session,
1893                    ExpandoValue expandoValue, long rowId,
1894                    OrderByComparator orderByComparator, boolean previous) {
1895                    StringBundler query = null;
1896    
1897                    if (orderByComparator != null) {
1898                            query = new StringBundler(6 +
1899                                            (orderByComparator.getOrderByFields().length * 6));
1900                    }
1901                    else {
1902                            query = new StringBundler(3);
1903                    }
1904    
1905                    query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1906    
1907                    query.append(_FINDER_COLUMN_ROWID_ROWID_2);
1908    
1909                    if (orderByComparator != null) {
1910                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1911    
1912                            if (orderByConditionFields.length > 0) {
1913                                    query.append(WHERE_AND);
1914                            }
1915    
1916                            for (int i = 0; i < orderByConditionFields.length; i++) {
1917                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1918                                    query.append(orderByConditionFields[i]);
1919    
1920                                    if ((i + 1) < orderByConditionFields.length) {
1921                                            if (orderByComparator.isAscending() ^ previous) {
1922                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1923                                            }
1924                                            else {
1925                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1926                                            }
1927                                    }
1928                                    else {
1929                                            if (orderByComparator.isAscending() ^ previous) {
1930                                                    query.append(WHERE_GREATER_THAN);
1931                                            }
1932                                            else {
1933                                                    query.append(WHERE_LESSER_THAN);
1934                                            }
1935                                    }
1936                            }
1937    
1938                            query.append(ORDER_BY_CLAUSE);
1939    
1940                            String[] orderByFields = orderByComparator.getOrderByFields();
1941    
1942                            for (int i = 0; i < orderByFields.length; i++) {
1943                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1944                                    query.append(orderByFields[i]);
1945    
1946                                    if ((i + 1) < orderByFields.length) {
1947                                            if (orderByComparator.isAscending() ^ previous) {
1948                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1949                                            }
1950                                            else {
1951                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1952                                            }
1953                                    }
1954                                    else {
1955                                            if (orderByComparator.isAscending() ^ previous) {
1956                                                    query.append(ORDER_BY_ASC);
1957                                            }
1958                                            else {
1959                                                    query.append(ORDER_BY_DESC);
1960                                            }
1961                                    }
1962                            }
1963                    }
1964    
1965                    else {
1966                            query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1967                    }
1968    
1969                    String sql = query.toString();
1970    
1971                    Query q = session.createQuery(sql);
1972    
1973                    q.setFirstResult(0);
1974                    q.setMaxResults(2);
1975    
1976                    QueryPos qPos = QueryPos.getInstance(q);
1977    
1978                    qPos.add(rowId);
1979    
1980                    if (orderByComparator != null) {
1981                            Object[] values = orderByComparator.getOrderByConditionValues(expandoValue);
1982    
1983                            for (Object value : values) {
1984                                    qPos.add(value);
1985                            }
1986                    }
1987    
1988                    List<ExpandoValue> list = q.list();
1989    
1990                    if (list.size() == 2) {
1991                            return list.get(1);
1992                    }
1993                    else {
1994                            return null;
1995                    }
1996            }
1997    
1998            /**
1999             * Returns all the expando values where tableId = &#63; and columnId = &#63;.
2000             *
2001             * @param tableId the table ID
2002             * @param columnId the column ID
2003             * @return the matching expando values
2004             * @throws SystemException if a system exception occurred
2005             */
2006            public List<ExpandoValue> findByT_C(long tableId, long columnId)
2007                    throws SystemException {
2008                    return findByT_C(tableId, columnId, QueryUtil.ALL_POS,
2009                            QueryUtil.ALL_POS, null);
2010            }
2011    
2012            /**
2013             * Returns a range of all the expando values where tableId = &#63; and columnId = &#63;.
2014             *
2015             * <p>
2016             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2017             * </p>
2018             *
2019             * @param tableId the table ID
2020             * @param columnId the column ID
2021             * @param start the lower bound of the range of expando values
2022             * @param end the upper bound of the range of expando values (not inclusive)
2023             * @return the range of matching expando values
2024             * @throws SystemException if a system exception occurred
2025             */
2026            public List<ExpandoValue> findByT_C(long tableId, long columnId, int start,
2027                    int end) throws SystemException {
2028                    return findByT_C(tableId, columnId, start, end, null);
2029            }
2030    
2031            /**
2032             * Returns an ordered range of all the expando values where tableId = &#63; and columnId = &#63;.
2033             *
2034             * <p>
2035             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2036             * </p>
2037             *
2038             * @param tableId the table ID
2039             * @param columnId the column ID
2040             * @param start the lower bound of the range of expando values
2041             * @param end the upper bound of the range of expando values (not inclusive)
2042             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2043             * @return the ordered range of matching expando values
2044             * @throws SystemException if a system exception occurred
2045             */
2046            public List<ExpandoValue> findByT_C(long tableId, long columnId, int start,
2047                    int end, OrderByComparator orderByComparator) throws SystemException {
2048                    FinderPath finderPath = null;
2049                    Object[] finderArgs = null;
2050    
2051                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2052                                    (orderByComparator == null)) {
2053                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_C;
2054                            finderArgs = new Object[] { tableId, columnId };
2055                    }
2056                    else {
2057                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_C;
2058                            finderArgs = new Object[] {
2059                                            tableId, columnId,
2060                                            
2061                                            start, end, orderByComparator
2062                                    };
2063                    }
2064    
2065                    List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(finderPath,
2066                                    finderArgs, this);
2067    
2068                    if ((list != null) && !list.isEmpty()) {
2069                            for (ExpandoValue expandoValue : list) {
2070                                    if ((tableId != expandoValue.getTableId()) ||
2071                                                    (columnId != expandoValue.getColumnId())) {
2072                                            list = null;
2073    
2074                                            break;
2075                                    }
2076                            }
2077                    }
2078    
2079                    if (list == null) {
2080                            StringBundler query = null;
2081    
2082                            if (orderByComparator != null) {
2083                                    query = new StringBundler(4 +
2084                                                    (orderByComparator.getOrderByFields().length * 3));
2085                            }
2086                            else {
2087                                    query = new StringBundler(4);
2088                            }
2089    
2090                            query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
2091    
2092                            query.append(_FINDER_COLUMN_T_C_TABLEID_2);
2093    
2094                            query.append(_FINDER_COLUMN_T_C_COLUMNID_2);
2095    
2096                            if (orderByComparator != null) {
2097                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2098                                            orderByComparator);
2099                            }
2100    
2101                            else {
2102                                    query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
2103                            }
2104    
2105                            String sql = query.toString();
2106    
2107                            Session session = null;
2108    
2109                            try {
2110                                    session = openSession();
2111    
2112                                    Query q = session.createQuery(sql);
2113    
2114                                    QueryPos qPos = QueryPos.getInstance(q);
2115    
2116                                    qPos.add(tableId);
2117    
2118                                    qPos.add(columnId);
2119    
2120                                    list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
2121                                                    start, end);
2122                            }
2123                            catch (Exception e) {
2124                                    throw processException(e);
2125                            }
2126                            finally {
2127                                    if (list == null) {
2128                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2129                                    }
2130                                    else {
2131                                            cacheResult(list);
2132    
2133                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2134                                    }
2135    
2136                                    closeSession(session);
2137                            }
2138                    }
2139    
2140                    return list;
2141            }
2142    
2143            /**
2144             * Returns the first expando value in the ordered set where tableId = &#63; and columnId = &#63;.
2145             *
2146             * @param tableId the table ID
2147             * @param columnId the column ID
2148             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2149             * @return the first matching expando value
2150             * @throws com.liferay.portlet.expando.NoSuchValueException if a matching expando value could not be found
2151             * @throws SystemException if a system exception occurred
2152             */
2153            public ExpandoValue findByT_C_First(long tableId, long columnId,
2154                    OrderByComparator orderByComparator)
2155                    throws NoSuchValueException, SystemException {
2156                    ExpandoValue expandoValue = fetchByT_C_First(tableId, columnId,
2157                                    orderByComparator);
2158    
2159                    if (expandoValue != null) {
2160                            return expandoValue;
2161                    }
2162    
2163                    StringBundler msg = new StringBundler(6);
2164    
2165                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2166    
2167                    msg.append("tableId=");
2168                    msg.append(tableId);
2169    
2170                    msg.append(", columnId=");
2171                    msg.append(columnId);
2172    
2173                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2174    
2175                    throw new NoSuchValueException(msg.toString());
2176            }
2177    
2178            /**
2179             * Returns the first expando value in the ordered set where tableId = &#63; and columnId = &#63;.
2180             *
2181             * @param tableId the table ID
2182             * @param columnId the column ID
2183             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2184             * @return the first matching expando value, or <code>null</code> if a matching expando value could not be found
2185             * @throws SystemException if a system exception occurred
2186             */
2187            public ExpandoValue fetchByT_C_First(long tableId, long columnId,
2188                    OrderByComparator orderByComparator) throws SystemException {
2189                    List<ExpandoValue> list = findByT_C(tableId, columnId, 0, 1,
2190                                    orderByComparator);
2191    
2192                    if (!list.isEmpty()) {
2193                            return list.get(0);
2194                    }
2195    
2196                    return null;
2197            }
2198    
2199            /**
2200             * Returns the last expando value in the ordered set where tableId = &#63; and columnId = &#63;.
2201             *
2202             * @param tableId the table ID
2203             * @param columnId the column ID
2204             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2205             * @return the last matching expando value
2206             * @throws com.liferay.portlet.expando.NoSuchValueException if a matching expando value could not be found
2207             * @throws SystemException if a system exception occurred
2208             */
2209            public ExpandoValue findByT_C_Last(long tableId, long columnId,
2210                    OrderByComparator orderByComparator)
2211                    throws NoSuchValueException, SystemException {
2212                    ExpandoValue expandoValue = fetchByT_C_Last(tableId, columnId,
2213                                    orderByComparator);
2214    
2215                    if (expandoValue != null) {
2216                            return expandoValue;
2217                    }
2218    
2219                    StringBundler msg = new StringBundler(6);
2220    
2221                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2222    
2223                    msg.append("tableId=");
2224                    msg.append(tableId);
2225    
2226                    msg.append(", columnId=");
2227                    msg.append(columnId);
2228    
2229                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2230    
2231                    throw new NoSuchValueException(msg.toString());
2232            }
2233    
2234            /**
2235             * Returns the last expando value in the ordered set where tableId = &#63; and columnId = &#63;.
2236             *
2237             * @param tableId the table ID
2238             * @param columnId the column ID
2239             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2240             * @return the last matching expando value, or <code>null</code> if a matching expando value could not be found
2241             * @throws SystemException if a system exception occurred
2242             */
2243            public ExpandoValue fetchByT_C_Last(long tableId, long columnId,
2244                    OrderByComparator orderByComparator) throws SystemException {
2245                    int count = countByT_C(tableId, columnId);
2246    
2247                    List<ExpandoValue> list = findByT_C(tableId, columnId, count - 1,
2248                                    count, orderByComparator);
2249    
2250                    if (!list.isEmpty()) {
2251                            return list.get(0);
2252                    }
2253    
2254                    return null;
2255            }
2256    
2257            /**
2258             * Returns the expando values before and after the current expando value in the ordered set where tableId = &#63; and columnId = &#63;.
2259             *
2260             * @param valueId the primary key of the current expando value
2261             * @param tableId the table ID
2262             * @param columnId the column ID
2263             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2264             * @return the previous, current, and next expando value
2265             * @throws com.liferay.portlet.expando.NoSuchValueException if a expando value with the primary key could not be found
2266             * @throws SystemException if a system exception occurred
2267             */
2268            public ExpandoValue[] findByT_C_PrevAndNext(long valueId, long tableId,
2269                    long columnId, OrderByComparator orderByComparator)
2270                    throws NoSuchValueException, SystemException {
2271                    ExpandoValue expandoValue = findByPrimaryKey(valueId);
2272    
2273                    Session session = null;
2274    
2275                    try {
2276                            session = openSession();
2277    
2278                            ExpandoValue[] array = new ExpandoValueImpl[3];
2279    
2280                            array[0] = getByT_C_PrevAndNext(session, expandoValue, tableId,
2281                                            columnId, orderByComparator, true);
2282    
2283                            array[1] = expandoValue;
2284    
2285                            array[2] = getByT_C_PrevAndNext(session, expandoValue, tableId,
2286                                            columnId, orderByComparator, false);
2287    
2288                            return array;
2289                    }
2290                    catch (Exception e) {
2291                            throw processException(e);
2292                    }
2293                    finally {
2294                            closeSession(session);
2295                    }
2296            }
2297    
2298            protected ExpandoValue getByT_C_PrevAndNext(Session session,
2299                    ExpandoValue expandoValue, long tableId, long columnId,
2300                    OrderByComparator orderByComparator, boolean previous) {
2301                    StringBundler query = null;
2302    
2303                    if (orderByComparator != null) {
2304                            query = new StringBundler(6 +
2305                                            (orderByComparator.getOrderByFields().length * 6));
2306                    }
2307                    else {
2308                            query = new StringBundler(3);
2309                    }
2310    
2311                    query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
2312    
2313                    query.append(_FINDER_COLUMN_T_C_TABLEID_2);
2314    
2315                    query.append(_FINDER_COLUMN_T_C_COLUMNID_2);
2316    
2317                    if (orderByComparator != null) {
2318                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2319    
2320                            if (orderByConditionFields.length > 0) {
2321                                    query.append(WHERE_AND);
2322                            }
2323    
2324                            for (int i = 0; i < orderByConditionFields.length; i++) {
2325                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2326                                    query.append(orderByConditionFields[i]);
2327    
2328                                    if ((i + 1) < orderByConditionFields.length) {
2329                                            if (orderByComparator.isAscending() ^ previous) {
2330                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2331                                            }
2332                                            else {
2333                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2334                                            }
2335                                    }
2336                                    else {
2337                                            if (orderByComparator.isAscending() ^ previous) {
2338                                                    query.append(WHERE_GREATER_THAN);
2339                                            }
2340                                            else {
2341                                                    query.append(WHERE_LESSER_THAN);
2342                                            }
2343                                    }
2344                            }
2345    
2346                            query.append(ORDER_BY_CLAUSE);
2347    
2348                            String[] orderByFields = orderByComparator.getOrderByFields();
2349    
2350                            for (int i = 0; i < orderByFields.length; i++) {
2351                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2352                                    query.append(orderByFields[i]);
2353    
2354                                    if ((i + 1) < orderByFields.length) {
2355                                            if (orderByComparator.isAscending() ^ previous) {
2356                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2357                                            }
2358                                            else {
2359                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2360                                            }
2361                                    }
2362                                    else {
2363                                            if (orderByComparator.isAscending() ^ previous) {
2364                                                    query.append(ORDER_BY_ASC);
2365                                            }
2366                                            else {
2367                                                    query.append(ORDER_BY_DESC);
2368                                            }
2369                                    }
2370                            }
2371                    }
2372    
2373                    else {
2374                            query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
2375                    }
2376    
2377                    String sql = query.toString();
2378    
2379                    Query q = session.createQuery(sql);
2380    
2381                    q.setFirstResult(0);
2382                    q.setMaxResults(2);
2383    
2384                    QueryPos qPos = QueryPos.getInstance(q);
2385    
2386                    qPos.add(tableId);
2387    
2388                    qPos.add(columnId);
2389    
2390                    if (orderByComparator != null) {
2391                            Object[] values = orderByComparator.getOrderByConditionValues(expandoValue);
2392    
2393                            for (Object value : values) {
2394                                    qPos.add(value);
2395                            }
2396                    }
2397    
2398                    List<ExpandoValue> list = q.list();
2399    
2400                    if (list.size() == 2) {
2401                            return list.get(1);
2402                    }
2403                    else {
2404                            return null;
2405                    }
2406            }
2407    
2408            /**
2409             * Returns all the expando values where tableId = &#63; and classPK = &#63;.
2410             *
2411             * @param tableId the table ID
2412             * @param classPK the class p k
2413             * @return the matching expando values
2414             * @throws SystemException if a system exception occurred
2415             */
2416            public List<ExpandoValue> findByT_CPK(long tableId, long classPK)
2417                    throws SystemException {
2418                    return findByT_CPK(tableId, classPK, QueryUtil.ALL_POS,
2419                            QueryUtil.ALL_POS, null);
2420            }
2421    
2422            /**
2423             * Returns a range of all the expando values where tableId = &#63; and classPK = &#63;.
2424             *
2425             * <p>
2426             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2427             * </p>
2428             *
2429             * @param tableId the table ID
2430             * @param classPK the class p k
2431             * @param start the lower bound of the range of expando values
2432             * @param end the upper bound of the range of expando values (not inclusive)
2433             * @return the range of matching expando values
2434             * @throws SystemException if a system exception occurred
2435             */
2436            public List<ExpandoValue> findByT_CPK(long tableId, long classPK,
2437                    int start, int end) throws SystemException {
2438                    return findByT_CPK(tableId, classPK, start, end, null);
2439            }
2440    
2441            /**
2442             * Returns an ordered range of all the expando values where tableId = &#63; and classPK = &#63;.
2443             *
2444             * <p>
2445             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2446             * </p>
2447             *
2448             * @param tableId the table ID
2449             * @param classPK the class p k
2450             * @param start the lower bound of the range of expando values
2451             * @param end the upper bound of the range of expando values (not inclusive)
2452             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2453             * @return the ordered range of matching expando values
2454             * @throws SystemException if a system exception occurred
2455             */
2456            public List<ExpandoValue> findByT_CPK(long tableId, long classPK,
2457                    int start, int end, OrderByComparator orderByComparator)
2458                    throws SystemException {
2459                    FinderPath finderPath = null;
2460                    Object[] finderArgs = null;
2461    
2462                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2463                                    (orderByComparator == null)) {
2464                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_CPK;
2465                            finderArgs = new Object[] { tableId, classPK };
2466                    }
2467                    else {
2468                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_CPK;
2469                            finderArgs = new Object[] {
2470                                            tableId, classPK,
2471                                            
2472                                            start, end, orderByComparator
2473                                    };
2474                    }
2475    
2476                    List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(finderPath,
2477                                    finderArgs, this);
2478    
2479                    if ((list != null) && !list.isEmpty()) {
2480                            for (ExpandoValue expandoValue : list) {
2481                                    if ((tableId != expandoValue.getTableId()) ||
2482                                                    (classPK != expandoValue.getClassPK())) {
2483                                            list = null;
2484    
2485                                            break;
2486                                    }
2487                            }
2488                    }
2489    
2490                    if (list == null) {
2491                            StringBundler query = null;
2492    
2493                            if (orderByComparator != null) {
2494                                    query = new StringBundler(4 +
2495                                                    (orderByComparator.getOrderByFields().length * 3));
2496                            }
2497                            else {
2498                                    query = new StringBundler(4);
2499                            }
2500    
2501                            query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
2502    
2503                            query.append(_FINDER_COLUMN_T_CPK_TABLEID_2);
2504    
2505                            query.append(_FINDER_COLUMN_T_CPK_CLASSPK_2);
2506    
2507                            if (orderByComparator != null) {
2508                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2509                                            orderByComparator);
2510                            }
2511    
2512                            else {
2513                                    query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
2514                            }
2515    
2516                            String sql = query.toString();
2517    
2518                            Session session = null;
2519    
2520                            try {
2521                                    session = openSession();
2522    
2523                                    Query q = session.createQuery(sql);
2524    
2525                                    QueryPos qPos = QueryPos.getInstance(q);
2526    
2527                                    qPos.add(tableId);
2528    
2529                                    qPos.add(classPK);
2530    
2531                                    list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
2532                                                    start, end);
2533                            }
2534                            catch (Exception e) {
2535                                    throw processException(e);
2536                            }
2537                            finally {
2538                                    if (list == null) {
2539                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2540                                    }
2541                                    else {
2542                                            cacheResult(list);
2543    
2544                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2545                                    }
2546    
2547                                    closeSession(session);
2548                            }
2549                    }
2550    
2551                    return list;
2552            }
2553    
2554            /**
2555             * Returns the first expando value in the ordered set where tableId = &#63; and classPK = &#63;.
2556             *
2557             * @param tableId the table ID
2558             * @param classPK the class p k
2559             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2560             * @return the first matching expando value
2561             * @throws com.liferay.portlet.expando.NoSuchValueException if a matching expando value could not be found
2562             * @throws SystemException if a system exception occurred
2563             */
2564            public ExpandoValue findByT_CPK_First(long tableId, long classPK,
2565                    OrderByComparator orderByComparator)
2566                    throws NoSuchValueException, SystemException {
2567                    ExpandoValue expandoValue = fetchByT_CPK_First(tableId, classPK,
2568                                    orderByComparator);
2569    
2570                    if (expandoValue != null) {
2571                            return expandoValue;
2572                    }
2573    
2574                    StringBundler msg = new StringBundler(6);
2575    
2576                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2577    
2578                    msg.append("tableId=");
2579                    msg.append(tableId);
2580    
2581                    msg.append(", classPK=");
2582                    msg.append(classPK);
2583    
2584                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2585    
2586                    throw new NoSuchValueException(msg.toString());
2587            }
2588    
2589            /**
2590             * Returns the first expando value in the ordered set where tableId = &#63; and classPK = &#63;.
2591             *
2592             * @param tableId the table ID
2593             * @param classPK the class p k
2594             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2595             * @return the first matching expando value, or <code>null</code> if a matching expando value could not be found
2596             * @throws SystemException if a system exception occurred
2597             */
2598            public ExpandoValue fetchByT_CPK_First(long tableId, long classPK,
2599                    OrderByComparator orderByComparator) throws SystemException {
2600                    List<ExpandoValue> list = findByT_CPK(tableId, classPK, 0, 1,
2601                                    orderByComparator);
2602    
2603                    if (!list.isEmpty()) {
2604                            return list.get(0);
2605                    }
2606    
2607                    return null;
2608            }
2609    
2610            /**
2611             * Returns the last expando value in the ordered set where tableId = &#63; and classPK = &#63;.
2612             *
2613             * @param tableId the table ID
2614             * @param classPK the class p k
2615             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2616             * @return the last matching expando value
2617             * @throws com.liferay.portlet.expando.NoSuchValueException if a matching expando value could not be found
2618             * @throws SystemException if a system exception occurred
2619             */
2620            public ExpandoValue findByT_CPK_Last(long tableId, long classPK,
2621                    OrderByComparator orderByComparator)
2622                    throws NoSuchValueException, SystemException {
2623                    ExpandoValue expandoValue = fetchByT_CPK_Last(tableId, classPK,
2624                                    orderByComparator);
2625    
2626                    if (expandoValue != null) {
2627                            return expandoValue;
2628                    }
2629    
2630                    StringBundler msg = new StringBundler(6);
2631    
2632                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2633    
2634                    msg.append("tableId=");
2635                    msg.append(tableId);
2636    
2637                    msg.append(", classPK=");
2638                    msg.append(classPK);
2639    
2640                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2641    
2642                    throw new NoSuchValueException(msg.toString());
2643            }
2644    
2645            /**
2646             * Returns the last expando value in the ordered set where tableId = &#63; and classPK = &#63;.
2647             *
2648             * @param tableId the table ID
2649             * @param classPK the class p k
2650             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2651             * @return the last matching expando value, or <code>null</code> if a matching expando value could not be found
2652             * @throws SystemException if a system exception occurred
2653             */
2654            public ExpandoValue fetchByT_CPK_Last(long tableId, long classPK,
2655                    OrderByComparator orderByComparator) throws SystemException {
2656                    int count = countByT_CPK(tableId, classPK);
2657    
2658                    List<ExpandoValue> list = findByT_CPK(tableId, classPK, count - 1,
2659                                    count, orderByComparator);
2660    
2661                    if (!list.isEmpty()) {
2662                            return list.get(0);
2663                    }
2664    
2665                    return null;
2666            }
2667    
2668            /**
2669             * Returns the expando values before and after the current expando value in the ordered set where tableId = &#63; and classPK = &#63;.
2670             *
2671             * @param valueId the primary key of the current expando value
2672             * @param tableId the table ID
2673             * @param classPK the class p k
2674             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2675             * @return the previous, current, and next expando value
2676             * @throws com.liferay.portlet.expando.NoSuchValueException if a expando value with the primary key could not be found
2677             * @throws SystemException if a system exception occurred
2678             */
2679            public ExpandoValue[] findByT_CPK_PrevAndNext(long valueId, long tableId,
2680                    long classPK, OrderByComparator orderByComparator)
2681                    throws NoSuchValueException, SystemException {
2682                    ExpandoValue expandoValue = findByPrimaryKey(valueId);
2683    
2684                    Session session = null;
2685    
2686                    try {
2687                            session = openSession();
2688    
2689                            ExpandoValue[] array = new ExpandoValueImpl[3];
2690    
2691                            array[0] = getByT_CPK_PrevAndNext(session, expandoValue, tableId,
2692                                            classPK, orderByComparator, true);
2693    
2694                            array[1] = expandoValue;
2695    
2696                            array[2] = getByT_CPK_PrevAndNext(session, expandoValue, tableId,
2697                                            classPK, orderByComparator, false);
2698    
2699                            return array;
2700                    }
2701                    catch (Exception e) {
2702                            throw processException(e);
2703                    }
2704                    finally {
2705                            closeSession(session);
2706                    }
2707            }
2708    
2709            protected ExpandoValue getByT_CPK_PrevAndNext(Session session,
2710                    ExpandoValue expandoValue, long tableId, long classPK,
2711                    OrderByComparator orderByComparator, boolean previous) {
2712                    StringBundler query = null;
2713    
2714                    if (orderByComparator != null) {
2715                            query = new StringBundler(6 +
2716                                            (orderByComparator.getOrderByFields().length * 6));
2717                    }
2718                    else {
2719                            query = new StringBundler(3);
2720                    }
2721    
2722                    query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
2723    
2724                    query.append(_FINDER_COLUMN_T_CPK_TABLEID_2);
2725    
2726                    query.append(_FINDER_COLUMN_T_CPK_CLASSPK_2);
2727    
2728                    if (orderByComparator != null) {
2729                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2730    
2731                            if (orderByConditionFields.length > 0) {
2732                                    query.append(WHERE_AND);
2733                            }
2734    
2735                            for (int i = 0; i < orderByConditionFields.length; i++) {
2736                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2737                                    query.append(orderByConditionFields[i]);
2738    
2739                                    if ((i + 1) < orderByConditionFields.length) {
2740                                            if (orderByComparator.isAscending() ^ previous) {
2741                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2742                                            }
2743                                            else {
2744                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2745                                            }
2746                                    }
2747                                    else {
2748                                            if (orderByComparator.isAscending() ^ previous) {
2749                                                    query.append(WHERE_GREATER_THAN);
2750                                            }
2751                                            else {
2752                                                    query.append(WHERE_LESSER_THAN);
2753                                            }
2754                                    }
2755                            }
2756    
2757                            query.append(ORDER_BY_CLAUSE);
2758    
2759                            String[] orderByFields = orderByComparator.getOrderByFields();
2760    
2761                            for (int i = 0; i < orderByFields.length; i++) {
2762                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2763                                    query.append(orderByFields[i]);
2764    
2765                                    if ((i + 1) < orderByFields.length) {
2766                                            if (orderByComparator.isAscending() ^ previous) {
2767                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2768                                            }
2769                                            else {
2770                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2771                                            }
2772                                    }
2773                                    else {
2774                                            if (orderByComparator.isAscending() ^ previous) {
2775                                                    query.append(ORDER_BY_ASC);
2776                                            }
2777                                            else {
2778                                                    query.append(ORDER_BY_DESC);
2779                                            }
2780                                    }
2781                            }
2782                    }
2783    
2784                    else {
2785                            query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
2786                    }
2787    
2788                    String sql = query.toString();
2789    
2790                    Query q = session.createQuery(sql);
2791    
2792                    q.setFirstResult(0);
2793                    q.setMaxResults(2);
2794    
2795                    QueryPos qPos = QueryPos.getInstance(q);
2796    
2797                    qPos.add(tableId);
2798    
2799                    qPos.add(classPK);
2800    
2801                    if (orderByComparator != null) {
2802                            Object[] values = orderByComparator.getOrderByConditionValues(expandoValue);
2803    
2804                            for (Object value : values) {
2805                                    qPos.add(value);
2806                            }
2807                    }
2808    
2809                    List<ExpandoValue> list = q.list();
2810    
2811                    if (list.size() == 2) {
2812                            return list.get(1);
2813                    }
2814                    else {
2815                            return null;
2816                    }
2817            }
2818    
2819            /**
2820             * Returns all the expando values where tableId = &#63; and rowId = &#63;.
2821             *
2822             * @param tableId the table ID
2823             * @param rowId the row ID
2824             * @return the matching expando values
2825             * @throws SystemException if a system exception occurred
2826             */
2827            public List<ExpandoValue> findByT_R(long tableId, long rowId)
2828                    throws SystemException {
2829                    return findByT_R(tableId, rowId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2830                            null);
2831            }
2832    
2833            /**
2834             * Returns a range of all the expando values where tableId = &#63; and rowId = &#63;.
2835             *
2836             * <p>
2837             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2838             * </p>
2839             *
2840             * @param tableId the table ID
2841             * @param rowId the row ID
2842             * @param start the lower bound of the range of expando values
2843             * @param end the upper bound of the range of expando values (not inclusive)
2844             * @return the range of matching expando values
2845             * @throws SystemException if a system exception occurred
2846             */
2847            public List<ExpandoValue> findByT_R(long tableId, long rowId, int start,
2848                    int end) throws SystemException {
2849                    return findByT_R(tableId, rowId, start, end, null);
2850            }
2851    
2852            /**
2853             * Returns an ordered range of all the expando values where tableId = &#63; and rowId = &#63;.
2854             *
2855             * <p>
2856             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2857             * </p>
2858             *
2859             * @param tableId the table ID
2860             * @param rowId the row ID
2861             * @param start the lower bound of the range of expando values
2862             * @param end the upper bound of the range of expando values (not inclusive)
2863             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2864             * @return the ordered range of matching expando values
2865             * @throws SystemException if a system exception occurred
2866             */
2867            public List<ExpandoValue> findByT_R(long tableId, long rowId, int start,
2868                    int end, OrderByComparator orderByComparator) throws SystemException {
2869                    FinderPath finderPath = null;
2870                    Object[] finderArgs = null;
2871    
2872                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2873                                    (orderByComparator == null)) {
2874                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_R;
2875                            finderArgs = new Object[] { tableId, rowId };
2876                    }
2877                    else {
2878                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_R;
2879                            finderArgs = new Object[] {
2880                                            tableId, rowId,
2881                                            
2882                                            start, end, orderByComparator
2883                                    };
2884                    }
2885    
2886                    List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(finderPath,
2887                                    finderArgs, this);
2888    
2889                    if ((list != null) && !list.isEmpty()) {
2890                            for (ExpandoValue expandoValue : list) {
2891                                    if ((tableId != expandoValue.getTableId()) ||
2892                                                    (rowId != expandoValue.getRowId())) {
2893                                            list = null;
2894    
2895                                            break;
2896                                    }
2897                            }
2898                    }
2899    
2900                    if (list == null) {
2901                            StringBundler query = null;
2902    
2903                            if (orderByComparator != null) {
2904                                    query = new StringBundler(4 +
2905                                                    (orderByComparator.getOrderByFields().length * 3));
2906                            }
2907                            else {
2908                                    query = new StringBundler(4);
2909                            }
2910    
2911                            query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
2912    
2913                            query.append(_FINDER_COLUMN_T_R_TABLEID_2);
2914    
2915                            query.append(_FINDER_COLUMN_T_R_ROWID_2);
2916    
2917                            if (orderByComparator != null) {
2918                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2919                                            orderByComparator);
2920                            }
2921    
2922                            else {
2923                                    query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
2924                            }
2925    
2926                            String sql = query.toString();
2927    
2928                            Session session = null;
2929    
2930                            try {
2931                                    session = openSession();
2932    
2933                                    Query q = session.createQuery(sql);
2934    
2935                                    QueryPos qPos = QueryPos.getInstance(q);
2936    
2937                                    qPos.add(tableId);
2938    
2939                                    qPos.add(rowId);
2940    
2941                                    list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
2942                                                    start, end);
2943                            }
2944                            catch (Exception e) {
2945                                    throw processException(e);
2946                            }
2947                            finally {
2948                                    if (list == null) {
2949                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2950                                    }
2951                                    else {
2952                                            cacheResult(list);
2953    
2954                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2955                                    }
2956    
2957                                    closeSession(session);
2958                            }
2959                    }
2960    
2961                    return list;
2962            }
2963    
2964            /**
2965             * Returns the first expando value in the ordered set where tableId = &#63; and rowId = &#63;.
2966             *
2967             * @param tableId the table ID
2968             * @param rowId the row ID
2969             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2970             * @return the first matching expando value
2971             * @throws com.liferay.portlet.expando.NoSuchValueException if a matching expando value could not be found
2972             * @throws SystemException if a system exception occurred
2973             */
2974            public ExpandoValue findByT_R_First(long tableId, long rowId,
2975                    OrderByComparator orderByComparator)
2976                    throws NoSuchValueException, SystemException {
2977                    ExpandoValue expandoValue = fetchByT_R_First(tableId, rowId,
2978                                    orderByComparator);
2979    
2980                    if (expandoValue != null) {
2981                            return expandoValue;
2982                    }
2983    
2984                    StringBundler msg = new StringBundler(6);
2985    
2986                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2987    
2988                    msg.append("tableId=");
2989                    msg.append(tableId);
2990    
2991                    msg.append(", rowId=");
2992                    msg.append(rowId);
2993    
2994                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2995    
2996                    throw new NoSuchValueException(msg.toString());
2997            }
2998    
2999            /**
3000             * Returns the first expando value in the ordered set where tableId = &#63; and rowId = &#63;.
3001             *
3002             * @param tableId the table ID
3003             * @param rowId the row ID
3004             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3005             * @return the first matching expando value, or <code>null</code> if a matching expando value could not be found
3006             * @throws SystemException if a system exception occurred
3007             */
3008            public ExpandoValue fetchByT_R_First(long tableId, long rowId,
3009                    OrderByComparator orderByComparator) throws SystemException {
3010                    List<ExpandoValue> list = findByT_R(tableId, rowId, 0, 1,
3011                                    orderByComparator);
3012    
3013                    if (!list.isEmpty()) {
3014                            return list.get(0);
3015                    }
3016    
3017                    return null;
3018            }
3019    
3020            /**
3021             * Returns the last expando value in the ordered set where tableId = &#63; and rowId = &#63;.
3022             *
3023             * @param tableId the table ID
3024             * @param rowId the row ID
3025             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3026             * @return the last matching expando value
3027             * @throws com.liferay.portlet.expando.NoSuchValueException if a matching expando value could not be found
3028             * @throws SystemException if a system exception occurred
3029             */
3030            public ExpandoValue findByT_R_Last(long tableId, long rowId,
3031                    OrderByComparator orderByComparator)
3032                    throws NoSuchValueException, SystemException {
3033                    ExpandoValue expandoValue = fetchByT_R_Last(tableId, rowId,
3034                                    orderByComparator);
3035    
3036                    if (expandoValue != null) {
3037                            return expandoValue;
3038                    }
3039    
3040                    StringBundler msg = new StringBundler(6);
3041    
3042                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3043    
3044                    msg.append("tableId=");
3045                    msg.append(tableId);
3046    
3047                    msg.append(", rowId=");
3048                    msg.append(rowId);
3049    
3050                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3051    
3052                    throw new NoSuchValueException(msg.toString());
3053            }
3054    
3055            /**
3056             * Returns the last expando value in the ordered set where tableId = &#63; and rowId = &#63;.
3057             *
3058             * @param tableId the table ID
3059             * @param rowId the row ID
3060             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3061             * @return the last matching expando value, or <code>null</code> if a matching expando value could not be found
3062             * @throws SystemException if a system exception occurred
3063             */
3064            public ExpandoValue fetchByT_R_Last(long tableId, long rowId,
3065                    OrderByComparator orderByComparator) throws SystemException {
3066                    int count = countByT_R(tableId, rowId);
3067    
3068                    List<ExpandoValue> list = findByT_R(tableId, rowId, count - 1, count,
3069                                    orderByComparator);
3070    
3071                    if (!list.isEmpty()) {
3072                            return list.get(0);
3073                    }
3074    
3075                    return null;
3076            }
3077    
3078            /**
3079             * Returns the expando values before and after the current expando value in the ordered set where tableId = &#63; and rowId = &#63;.
3080             *
3081             * @param valueId the primary key of the current expando value
3082             * @param tableId the table ID
3083             * @param rowId the row ID
3084             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3085             * @return the previous, current, and next expando value
3086             * @throws com.liferay.portlet.expando.NoSuchValueException if a expando value with the primary key could not be found
3087             * @throws SystemException if a system exception occurred
3088             */
3089            public ExpandoValue[] findByT_R_PrevAndNext(long valueId, long tableId,
3090                    long rowId, OrderByComparator orderByComparator)
3091                    throws NoSuchValueException, SystemException {
3092                    ExpandoValue expandoValue = findByPrimaryKey(valueId);
3093    
3094                    Session session = null;
3095    
3096                    try {
3097                            session = openSession();
3098    
3099                            ExpandoValue[] array = new ExpandoValueImpl[3];
3100    
3101                            array[0] = getByT_R_PrevAndNext(session, expandoValue, tableId,
3102                                            rowId, orderByComparator, true);
3103    
3104                            array[1] = expandoValue;
3105    
3106                            array[2] = getByT_R_PrevAndNext(session, expandoValue, tableId,
3107                                            rowId, orderByComparator, false);
3108    
3109                            return array;
3110                    }
3111                    catch (Exception e) {
3112                            throw processException(e);
3113                    }
3114                    finally {
3115                            closeSession(session);
3116                    }
3117            }
3118    
3119            protected ExpandoValue getByT_R_PrevAndNext(Session session,
3120                    ExpandoValue expandoValue, long tableId, long rowId,
3121                    OrderByComparator orderByComparator, boolean previous) {
3122                    StringBundler query = null;
3123    
3124                    if (orderByComparator != null) {
3125                            query = new StringBundler(6 +
3126                                            (orderByComparator.getOrderByFields().length * 6));
3127                    }
3128                    else {
3129                            query = new StringBundler(3);
3130                    }
3131    
3132                    query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
3133    
3134                    query.append(_FINDER_COLUMN_T_R_TABLEID_2);
3135    
3136                    query.append(_FINDER_COLUMN_T_R_ROWID_2);
3137    
3138                    if (orderByComparator != null) {
3139                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3140    
3141                            if (orderByConditionFields.length > 0) {
3142                                    query.append(WHERE_AND);
3143                            }
3144    
3145                            for (int i = 0; i < orderByConditionFields.length; i++) {
3146                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3147                                    query.append(orderByConditionFields[i]);
3148    
3149                                    if ((i + 1) < orderByConditionFields.length) {
3150                                            if (orderByComparator.isAscending() ^ previous) {
3151                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3152                                            }
3153                                            else {
3154                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3155                                            }
3156                                    }
3157                                    else {
3158                                            if (orderByComparator.isAscending() ^ previous) {
3159                                                    query.append(WHERE_GREATER_THAN);
3160                                            }
3161                                            else {
3162                                                    query.append(WHERE_LESSER_THAN);
3163                                            }
3164                                    }
3165                            }
3166    
3167                            query.append(ORDER_BY_CLAUSE);
3168    
3169                            String[] orderByFields = orderByComparator.getOrderByFields();
3170    
3171                            for (int i = 0; i < orderByFields.length; i++) {
3172                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3173                                    query.append(orderByFields[i]);
3174    
3175                                    if ((i + 1) < orderByFields.length) {
3176                                            if (orderByComparator.isAscending() ^ previous) {
3177                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3178                                            }
3179                                            else {
3180                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3181                                            }
3182                                    }
3183                                    else {
3184                                            if (orderByComparator.isAscending() ^ previous) {
3185                                                    query.append(ORDER_BY_ASC);
3186                                            }
3187                                            else {
3188                                                    query.append(ORDER_BY_DESC);
3189                                            }
3190                                    }
3191                            }
3192                    }
3193    
3194                    else {
3195                            query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
3196                    }
3197    
3198                    String sql = query.toString();
3199    
3200                    Query q = session.createQuery(sql);
3201    
3202                    q.setFirstResult(0);
3203                    q.setMaxResults(2);
3204    
3205                    QueryPos qPos = QueryPos.getInstance(q);
3206    
3207                    qPos.add(tableId);
3208    
3209                    qPos.add(rowId);
3210    
3211                    if (orderByComparator != null) {
3212                            Object[] values = orderByComparator.getOrderByConditionValues(expandoValue);
3213    
3214                            for (Object value : values) {
3215                                    qPos.add(value);
3216                            }
3217                    }
3218    
3219                    List<ExpandoValue> list = q.list();
3220    
3221                    if (list.size() == 2) {
3222                            return list.get(1);
3223                    }
3224                    else {
3225                            return null;
3226                    }
3227            }
3228    
3229            /**
3230             * Returns the expando value where columnId = &#63; and rowId = &#63; or throws a {@link com.liferay.portlet.expando.NoSuchValueException} if it could not be found.
3231             *
3232             * @param columnId the column ID
3233             * @param rowId the row ID
3234             * @return the matching expando value
3235             * @throws com.liferay.portlet.expando.NoSuchValueException if a matching expando value could not be found
3236             * @throws SystemException if a system exception occurred
3237             */
3238            public ExpandoValue findByC_R(long columnId, long rowId)
3239                    throws NoSuchValueException, SystemException {
3240                    ExpandoValue expandoValue = fetchByC_R(columnId, rowId);
3241    
3242                    if (expandoValue == null) {
3243                            StringBundler msg = new StringBundler(6);
3244    
3245                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3246    
3247                            msg.append("columnId=");
3248                            msg.append(columnId);
3249    
3250                            msg.append(", rowId=");
3251                            msg.append(rowId);
3252    
3253                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3254    
3255                            if (_log.isWarnEnabled()) {
3256                                    _log.warn(msg.toString());
3257                            }
3258    
3259                            throw new NoSuchValueException(msg.toString());
3260                    }
3261    
3262                    return expandoValue;
3263            }
3264    
3265            /**
3266             * Returns the expando value where columnId = &#63; and rowId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
3267             *
3268             * @param columnId the column ID
3269             * @param rowId the row ID
3270             * @return the matching expando value, or <code>null</code> if a matching expando value could not be found
3271             * @throws SystemException if a system exception occurred
3272             */
3273            public ExpandoValue fetchByC_R(long columnId, long rowId)
3274                    throws SystemException {
3275                    return fetchByC_R(columnId, rowId, true);
3276            }
3277    
3278            /**
3279             * Returns the expando value where columnId = &#63; and rowId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
3280             *
3281             * @param columnId the column ID
3282             * @param rowId the row ID
3283             * @param retrieveFromCache whether to use the finder cache
3284             * @return the matching expando value, or <code>null</code> if a matching expando value could not be found
3285             * @throws SystemException if a system exception occurred
3286             */
3287            public ExpandoValue fetchByC_R(long columnId, long rowId,
3288                    boolean retrieveFromCache) throws SystemException {
3289                    Object[] finderArgs = new Object[] { columnId, rowId };
3290    
3291                    Object result = null;
3292    
3293                    if (retrieveFromCache) {
3294                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_R,
3295                                            finderArgs, this);
3296                    }
3297    
3298                    if (result instanceof ExpandoValue) {
3299                            ExpandoValue expandoValue = (ExpandoValue)result;
3300    
3301                            if ((columnId != expandoValue.getColumnId()) ||
3302                                            (rowId != expandoValue.getRowId())) {
3303                                    result = null;
3304                            }
3305                    }
3306    
3307                    if (result == null) {
3308                            StringBundler query = new StringBundler(4);
3309    
3310                            query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
3311    
3312                            query.append(_FINDER_COLUMN_C_R_COLUMNID_2);
3313    
3314                            query.append(_FINDER_COLUMN_C_R_ROWID_2);
3315    
3316                            query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
3317    
3318                            String sql = query.toString();
3319    
3320                            Session session = null;
3321    
3322                            try {
3323                                    session = openSession();
3324    
3325                                    Query q = session.createQuery(sql);
3326    
3327                                    QueryPos qPos = QueryPos.getInstance(q);
3328    
3329                                    qPos.add(columnId);
3330    
3331                                    qPos.add(rowId);
3332    
3333                                    List<ExpandoValue> list = q.list();
3334    
3335                                    result = list;
3336    
3337                                    ExpandoValue expandoValue = null;
3338    
3339                                    if (list.isEmpty()) {
3340                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R,
3341                                                    finderArgs, list);
3342                                    }
3343                                    else {
3344                                            expandoValue = list.get(0);
3345    
3346                                            cacheResult(expandoValue);
3347    
3348                                            if ((expandoValue.getColumnId() != columnId) ||
3349                                                            (expandoValue.getRowId() != rowId)) {
3350                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R,
3351                                                            finderArgs, expandoValue);
3352                                            }
3353                                    }
3354    
3355                                    return expandoValue;
3356                            }
3357                            catch (Exception e) {
3358                                    throw processException(e);
3359                            }
3360                            finally {
3361                                    if (result == null) {
3362                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_R,
3363                                                    finderArgs);
3364                                    }
3365    
3366                                    closeSession(session);
3367                            }
3368                    }
3369                    else {
3370                            if (result instanceof List<?>) {
3371                                    return null;
3372                            }
3373                            else {
3374                                    return (ExpandoValue)result;
3375                            }
3376                    }
3377            }
3378    
3379            /**
3380             * Returns all the expando values where classNameId = &#63; and classPK = &#63;.
3381             *
3382             * @param classNameId the class name ID
3383             * @param classPK the class p k
3384             * @return the matching expando values
3385             * @throws SystemException if a system exception occurred
3386             */
3387            public List<ExpandoValue> findByC_C(long classNameId, long classPK)
3388                    throws SystemException {
3389                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
3390                            QueryUtil.ALL_POS, null);
3391            }
3392    
3393            /**
3394             * Returns a range of all the expando values where classNameId = &#63; and classPK = &#63;.
3395             *
3396             * <p>
3397             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3398             * </p>
3399             *
3400             * @param classNameId the class name ID
3401             * @param classPK the class p k
3402             * @param start the lower bound of the range of expando values
3403             * @param end the upper bound of the range of expando values (not inclusive)
3404             * @return the range of matching expando values
3405             * @throws SystemException if a system exception occurred
3406             */
3407            public List<ExpandoValue> findByC_C(long classNameId, long classPK,
3408                    int start, int end) throws SystemException {
3409                    return findByC_C(classNameId, classPK, start, end, null);
3410            }
3411    
3412            /**
3413             * Returns an ordered range of all the expando values where classNameId = &#63; and classPK = &#63;.
3414             *
3415             * <p>
3416             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3417             * </p>
3418             *
3419             * @param classNameId the class name ID
3420             * @param classPK the class p k
3421             * @param start the lower bound of the range of expando values
3422             * @param end the upper bound of the range of expando values (not inclusive)
3423             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3424             * @return the ordered range of matching expando values
3425             * @throws SystemException if a system exception occurred
3426             */
3427            public List<ExpandoValue> findByC_C(long classNameId, long classPK,
3428                    int start, int end, OrderByComparator orderByComparator)
3429                    throws SystemException {
3430                    FinderPath finderPath = null;
3431                    Object[] finderArgs = null;
3432    
3433                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3434                                    (orderByComparator == null)) {
3435                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
3436                            finderArgs = new Object[] { classNameId, classPK };
3437                    }
3438                    else {
3439                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
3440                            finderArgs = new Object[] {
3441                                            classNameId, classPK,
3442                                            
3443                                            start, end, orderByComparator
3444                                    };
3445                    }
3446    
3447                    List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(finderPath,
3448                                    finderArgs, this);
3449    
3450                    if ((list != null) && !list.isEmpty()) {
3451                            for (ExpandoValue expandoValue : list) {
3452                                    if ((classNameId != expandoValue.getClassNameId()) ||
3453                                                    (classPK != expandoValue.getClassPK())) {
3454                                            list = null;
3455    
3456                                            break;
3457                                    }
3458                            }
3459                    }
3460    
3461                    if (list == null) {
3462                            StringBundler query = null;
3463    
3464                            if (orderByComparator != null) {
3465                                    query = new StringBundler(4 +
3466                                                    (orderByComparator.getOrderByFields().length * 3));
3467                            }
3468                            else {
3469                                    query = new StringBundler(4);
3470                            }
3471    
3472                            query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
3473    
3474                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3475    
3476                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3477    
3478                            if (orderByComparator != null) {
3479                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3480                                            orderByComparator);
3481                            }
3482    
3483                            else {
3484                                    query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
3485                            }
3486    
3487                            String sql = query.toString();
3488    
3489                            Session session = null;
3490    
3491                            try {
3492                                    session = openSession();
3493    
3494                                    Query q = session.createQuery(sql);
3495    
3496                                    QueryPos qPos = QueryPos.getInstance(q);
3497    
3498                                    qPos.add(classNameId);
3499    
3500                                    qPos.add(classPK);
3501    
3502                                    list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
3503                                                    start, end);
3504                            }
3505                            catch (Exception e) {
3506                                    throw processException(e);
3507                            }
3508                            finally {
3509                                    if (list == null) {
3510                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3511                                    }
3512                                    else {
3513                                            cacheResult(list);
3514    
3515                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3516                                    }
3517    
3518                                    closeSession(session);
3519                            }
3520                    }
3521    
3522                    return list;
3523            }
3524    
3525            /**
3526             * Returns the first expando value in the ordered set where classNameId = &#63; and classPK = &#63;.
3527             *
3528             * @param classNameId the class name ID
3529             * @param classPK the class p k
3530             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3531             * @return the first matching expando value
3532             * @throws com.liferay.portlet.expando.NoSuchValueException if a matching expando value could not be found
3533             * @throws SystemException if a system exception occurred
3534             */
3535            public ExpandoValue findByC_C_First(long classNameId, long classPK,
3536                    OrderByComparator orderByComparator)
3537                    throws NoSuchValueException, SystemException {
3538                    ExpandoValue expandoValue = fetchByC_C_First(classNameId, classPK,
3539                                    orderByComparator);
3540    
3541                    if (expandoValue != null) {
3542                            return expandoValue;
3543                    }
3544    
3545                    StringBundler msg = new StringBundler(6);
3546    
3547                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3548    
3549                    msg.append("classNameId=");
3550                    msg.append(classNameId);
3551    
3552                    msg.append(", classPK=");
3553                    msg.append(classPK);
3554    
3555                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3556    
3557                    throw new NoSuchValueException(msg.toString());
3558            }
3559    
3560            /**
3561             * Returns the first expando value in the ordered set where classNameId = &#63; and classPK = &#63;.
3562             *
3563             * @param classNameId the class name ID
3564             * @param classPK the class p k
3565             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3566             * @return the first matching expando value, or <code>null</code> if a matching expando value could not be found
3567             * @throws SystemException if a system exception occurred
3568             */
3569            public ExpandoValue fetchByC_C_First(long classNameId, long classPK,
3570                    OrderByComparator orderByComparator) throws SystemException {
3571                    List<ExpandoValue> list = findByC_C(classNameId, classPK, 0, 1,
3572                                    orderByComparator);
3573    
3574                    if (!list.isEmpty()) {
3575                            return list.get(0);
3576                    }
3577    
3578                    return null;
3579            }
3580    
3581            /**
3582             * Returns the last expando value in the ordered set where classNameId = &#63; and classPK = &#63;.
3583             *
3584             * @param classNameId the class name ID
3585             * @param classPK the class p k
3586             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3587             * @return the last matching expando value
3588             * @throws com.liferay.portlet.expando.NoSuchValueException if a matching expando value could not be found
3589             * @throws SystemException if a system exception occurred
3590             */
3591            public ExpandoValue findByC_C_Last(long classNameId, long classPK,
3592                    OrderByComparator orderByComparator)
3593                    throws NoSuchValueException, SystemException {
3594                    ExpandoValue expandoValue = fetchByC_C_Last(classNameId, classPK,
3595                                    orderByComparator);
3596    
3597                    if (expandoValue != null) {
3598                            return expandoValue;
3599                    }
3600    
3601                    StringBundler msg = new StringBundler(6);
3602    
3603                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3604    
3605                    msg.append("classNameId=");
3606                    msg.append(classNameId);
3607    
3608                    msg.append(", classPK=");
3609                    msg.append(classPK);
3610    
3611                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3612    
3613                    throw new NoSuchValueException(msg.toString());
3614            }
3615    
3616            /**
3617             * Returns the last expando value in the ordered set where classNameId = &#63; and classPK = &#63;.
3618             *
3619             * @param classNameId the class name ID
3620             * @param classPK the class p k
3621             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3622             * @return the last matching expando value, or <code>null</code> if a matching expando value could not be found
3623             * @throws SystemException if a system exception occurred
3624             */
3625            public ExpandoValue fetchByC_C_Last(long classNameId, long classPK,
3626                    OrderByComparator orderByComparator) throws SystemException {
3627                    int count = countByC_C(classNameId, classPK);
3628    
3629                    List<ExpandoValue> list = findByC_C(classNameId, classPK, count - 1,
3630                                    count, orderByComparator);
3631    
3632                    if (!list.isEmpty()) {
3633                            return list.get(0);
3634                    }
3635    
3636                    return null;
3637            }
3638    
3639            /**
3640             * Returns the expando values before and after the current expando value in the ordered set where classNameId = &#63; and classPK = &#63;.
3641             *
3642             * @param valueId the primary key of the current expando value
3643             * @param classNameId the class name ID
3644             * @param classPK the class p k
3645             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3646             * @return the previous, current, and next expando value
3647             * @throws com.liferay.portlet.expando.NoSuchValueException if a expando value with the primary key could not be found
3648             * @throws SystemException if a system exception occurred
3649             */
3650            public ExpandoValue[] findByC_C_PrevAndNext(long valueId, long classNameId,
3651                    long classPK, OrderByComparator orderByComparator)
3652                    throws NoSuchValueException, SystemException {
3653                    ExpandoValue expandoValue = findByPrimaryKey(valueId);
3654    
3655                    Session session = null;
3656    
3657                    try {
3658                            session = openSession();
3659    
3660                            ExpandoValue[] array = new ExpandoValueImpl[3];
3661    
3662                            array[0] = getByC_C_PrevAndNext(session, expandoValue, classNameId,
3663                                            classPK, orderByComparator, true);
3664    
3665                            array[1] = expandoValue;
3666    
3667                            array[2] = getByC_C_PrevAndNext(session, expandoValue, classNameId,
3668                                            classPK, orderByComparator, false);
3669    
3670                            return array;
3671                    }
3672                    catch (Exception e) {
3673                            throw processException(e);
3674                    }
3675                    finally {
3676                            closeSession(session);
3677                    }
3678            }
3679    
3680            protected ExpandoValue getByC_C_PrevAndNext(Session session,
3681                    ExpandoValue expandoValue, long classNameId, long classPK,
3682                    OrderByComparator orderByComparator, boolean previous) {
3683                    StringBundler query = null;
3684    
3685                    if (orderByComparator != null) {
3686                            query = new StringBundler(6 +
3687                                            (orderByComparator.getOrderByFields().length * 6));
3688                    }
3689                    else {
3690                            query = new StringBundler(3);
3691                    }
3692    
3693                    query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
3694    
3695                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3696    
3697                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3698    
3699                    if (orderByComparator != null) {
3700                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3701    
3702                            if (orderByConditionFields.length > 0) {
3703                                    query.append(WHERE_AND);
3704                            }
3705    
3706                            for (int i = 0; i < orderByConditionFields.length; i++) {
3707                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3708                                    query.append(orderByConditionFields[i]);
3709    
3710                                    if ((i + 1) < orderByConditionFields.length) {
3711                                            if (orderByComparator.isAscending() ^ previous) {
3712                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3713                                            }
3714                                            else {
3715                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3716                                            }
3717                                    }
3718                                    else {
3719                                            if (orderByComparator.isAscending() ^ previous) {
3720                                                    query.append(WHERE_GREATER_THAN);
3721                                            }
3722                                            else {
3723                                                    query.append(WHERE_LESSER_THAN);
3724                                            }
3725                                    }
3726                            }
3727    
3728                            query.append(ORDER_BY_CLAUSE);
3729    
3730                            String[] orderByFields = orderByComparator.getOrderByFields();
3731    
3732                            for (int i = 0; i < orderByFields.length; i++) {
3733                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3734                                    query.append(orderByFields[i]);
3735    
3736                                    if ((i + 1) < orderByFields.length) {
3737                                            if (orderByComparator.isAscending() ^ previous) {
3738                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3739                                            }
3740                                            else {
3741                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3742                                            }
3743                                    }
3744                                    else {
3745                                            if (orderByComparator.isAscending() ^ previous) {
3746                                                    query.append(ORDER_BY_ASC);
3747                                            }
3748                                            else {
3749                                                    query.append(ORDER_BY_DESC);
3750                                            }
3751                                    }
3752                            }
3753                    }
3754    
3755                    else {
3756                            query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
3757                    }
3758    
3759                    String sql = query.toString();
3760    
3761                    Query q = session.createQuery(sql);
3762    
3763                    q.setFirstResult(0);
3764                    q.setMaxResults(2);
3765    
3766                    QueryPos qPos = QueryPos.getInstance(q);
3767    
3768                    qPos.add(classNameId);
3769    
3770                    qPos.add(classPK);
3771    
3772                    if (orderByComparator != null) {
3773                            Object[] values = orderByComparator.getOrderByConditionValues(expandoValue);
3774    
3775                            for (Object value : values) {
3776                                    qPos.add(value);
3777                            }
3778                    }
3779    
3780                    List<ExpandoValue> list = q.list();
3781    
3782                    if (list.size() == 2) {
3783                            return list.get(1);
3784                    }
3785                    else {
3786                            return null;
3787                    }
3788            }
3789    
3790            /**
3791             * Returns the expando value where tableId = &#63; and columnId = &#63; and classPK = &#63; or throws a {@link com.liferay.portlet.expando.NoSuchValueException} if it could not be found.
3792             *
3793             * @param tableId the table ID
3794             * @param columnId the column ID
3795             * @param classPK the class p k
3796             * @return the matching expando value
3797             * @throws com.liferay.portlet.expando.NoSuchValueException if a matching expando value could not be found
3798             * @throws SystemException if a system exception occurred
3799             */
3800            public ExpandoValue findByT_C_C(long tableId, long columnId, long classPK)
3801                    throws NoSuchValueException, SystemException {
3802                    ExpandoValue expandoValue = fetchByT_C_C(tableId, columnId, classPK);
3803    
3804                    if (expandoValue == null) {
3805                            StringBundler msg = new StringBundler(8);
3806    
3807                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3808    
3809                            msg.append("tableId=");
3810                            msg.append(tableId);
3811    
3812                            msg.append(", columnId=");
3813                            msg.append(columnId);
3814    
3815                            msg.append(", classPK=");
3816                            msg.append(classPK);
3817    
3818                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3819    
3820                            if (_log.isWarnEnabled()) {
3821                                    _log.warn(msg.toString());
3822                            }
3823    
3824                            throw new NoSuchValueException(msg.toString());
3825                    }
3826    
3827                    return expandoValue;
3828            }
3829    
3830            /**
3831             * Returns the expando value where tableId = &#63; and columnId = &#63; and classPK = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
3832             *
3833             * @param tableId the table ID
3834             * @param columnId the column ID
3835             * @param classPK the class p k
3836             * @return the matching expando value, or <code>null</code> if a matching expando value could not be found
3837             * @throws SystemException if a system exception occurred
3838             */
3839            public ExpandoValue fetchByT_C_C(long tableId, long columnId, long classPK)
3840                    throws SystemException {
3841                    return fetchByT_C_C(tableId, columnId, classPK, true);
3842            }
3843    
3844            /**
3845             * Returns the expando value where tableId = &#63; and columnId = &#63; and classPK = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
3846             *
3847             * @param tableId the table ID
3848             * @param columnId the column ID
3849             * @param classPK the class p k
3850             * @param retrieveFromCache whether to use the finder cache
3851             * @return the matching expando value, or <code>null</code> if a matching expando value could not be found
3852             * @throws SystemException if a system exception occurred
3853             */
3854            public ExpandoValue fetchByT_C_C(long tableId, long columnId, long classPK,
3855                    boolean retrieveFromCache) throws SystemException {
3856                    Object[] finderArgs = new Object[] { tableId, columnId, classPK };
3857    
3858                    Object result = null;
3859    
3860                    if (retrieveFromCache) {
3861                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_T_C_C,
3862                                            finderArgs, this);
3863                    }
3864    
3865                    if (result instanceof ExpandoValue) {
3866                            ExpandoValue expandoValue = (ExpandoValue)result;
3867    
3868                            if ((tableId != expandoValue.getTableId()) ||
3869                                            (columnId != expandoValue.getColumnId()) ||
3870                                            (classPK != expandoValue.getClassPK())) {
3871                                    result = null;
3872                            }
3873                    }
3874    
3875                    if (result == null) {
3876                            StringBundler query = new StringBundler(5);
3877    
3878                            query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
3879    
3880                            query.append(_FINDER_COLUMN_T_C_C_TABLEID_2);
3881    
3882                            query.append(_FINDER_COLUMN_T_C_C_COLUMNID_2);
3883    
3884                            query.append(_FINDER_COLUMN_T_C_C_CLASSPK_2);
3885    
3886                            query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
3887    
3888                            String sql = query.toString();
3889    
3890                            Session session = null;
3891    
3892                            try {
3893                                    session = openSession();
3894    
3895                                    Query q = session.createQuery(sql);
3896    
3897                                    QueryPos qPos = QueryPos.getInstance(q);
3898    
3899                                    qPos.add(tableId);
3900    
3901                                    qPos.add(columnId);
3902    
3903                                    qPos.add(classPK);
3904    
3905                                    List<ExpandoValue> list = q.list();
3906    
3907                                    result = list;
3908    
3909                                    ExpandoValue expandoValue = null;
3910    
3911                                    if (list.isEmpty()) {
3912                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C_C,
3913                                                    finderArgs, list);
3914                                    }
3915                                    else {
3916                                            expandoValue = list.get(0);
3917    
3918                                            cacheResult(expandoValue);
3919    
3920                                            if ((expandoValue.getTableId() != tableId) ||
3921                                                            (expandoValue.getColumnId() != columnId) ||
3922                                                            (expandoValue.getClassPK() != classPK)) {
3923                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C_C,
3924                                                            finderArgs, expandoValue);
3925                                            }
3926                                    }
3927    
3928                                    return expandoValue;
3929                            }
3930                            catch (Exception e) {
3931                                    throw processException(e);
3932                            }
3933                            finally {
3934                                    if (result == null) {
3935                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C_C,
3936                                                    finderArgs);
3937                                    }
3938    
3939                                    closeSession(session);
3940                            }
3941                    }
3942                    else {
3943                            if (result instanceof List<?>) {
3944                                    return null;
3945                            }
3946                            else {
3947                                    return (ExpandoValue)result;
3948                            }
3949                    }
3950            }
3951    
3952            /**
3953             * Returns all the expando values where tableId = &#63; and columnId = &#63; and data = &#63;.
3954             *
3955             * @param tableId the table ID
3956             * @param columnId the column ID
3957             * @param data the data
3958             * @return the matching expando values
3959             * @throws SystemException if a system exception occurred
3960             */
3961            public List<ExpandoValue> findByT_C_D(long tableId, long columnId,
3962                    String data) throws SystemException {
3963                    return findByT_C_D(tableId, columnId, data, QueryUtil.ALL_POS,
3964                            QueryUtil.ALL_POS, null);
3965            }
3966    
3967            /**
3968             * Returns a range of all the expando values where tableId = &#63; and columnId = &#63; and data = &#63;.
3969             *
3970             * <p>
3971             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3972             * </p>
3973             *
3974             * @param tableId the table ID
3975             * @param columnId the column ID
3976             * @param data the data
3977             * @param start the lower bound of the range of expando values
3978             * @param end the upper bound of the range of expando values (not inclusive)
3979             * @return the range of matching expando values
3980             * @throws SystemException if a system exception occurred
3981             */
3982            public List<ExpandoValue> findByT_C_D(long tableId, long columnId,
3983                    String data, int start, int end) throws SystemException {
3984                    return findByT_C_D(tableId, columnId, data, start, end, null);
3985            }
3986    
3987            /**
3988             * Returns an ordered range of all the expando values where tableId = &#63; and columnId = &#63; and data = &#63;.
3989             *
3990             * <p>
3991             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3992             * </p>
3993             *
3994             * @param tableId the table ID
3995             * @param columnId the column ID
3996             * @param data the data
3997             * @param start the lower bound of the range of expando values
3998             * @param end the upper bound of the range of expando values (not inclusive)
3999             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4000             * @return the ordered range of matching expando values
4001             * @throws SystemException if a system exception occurred
4002             */
4003            public List<ExpandoValue> findByT_C_D(long tableId, long columnId,
4004                    String data, int start, int end, OrderByComparator orderByComparator)
4005                    throws SystemException {
4006                    FinderPath finderPath = null;
4007                    Object[] finderArgs = null;
4008    
4009                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4010                                    (orderByComparator == null)) {
4011                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_C_D;
4012                            finderArgs = new Object[] { tableId, columnId, data };
4013                    }
4014                    else {
4015                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_C_D;
4016                            finderArgs = new Object[] {
4017                                            tableId, columnId, data,
4018                                            
4019                                            start, end, orderByComparator
4020                                    };
4021                    }
4022    
4023                    List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(finderPath,
4024                                    finderArgs, this);
4025    
4026                    if ((list != null) && !list.isEmpty()) {
4027                            for (ExpandoValue expandoValue : list) {
4028                                    if ((tableId != expandoValue.getTableId()) ||
4029                                                    (columnId != expandoValue.getColumnId()) ||
4030                                                    !Validator.equals(data, expandoValue.getData())) {
4031                                            list = null;
4032    
4033                                            break;
4034                                    }
4035                            }
4036                    }
4037    
4038                    if (list == null) {
4039                            StringBundler query = null;
4040    
4041                            if (orderByComparator != null) {
4042                                    query = new StringBundler(5 +
4043                                                    (orderByComparator.getOrderByFields().length * 3));
4044                            }
4045                            else {
4046                                    query = new StringBundler(5);
4047                            }
4048    
4049                            query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
4050    
4051                            query.append(_FINDER_COLUMN_T_C_D_TABLEID_2);
4052    
4053                            query.append(_FINDER_COLUMN_T_C_D_COLUMNID_2);
4054    
4055                            if (data == null) {
4056                                    query.append(_FINDER_COLUMN_T_C_D_DATA_1);
4057                            }
4058                            else {
4059                                    if (data.equals(StringPool.BLANK)) {
4060                                            query.append(_FINDER_COLUMN_T_C_D_DATA_3);
4061                                    }
4062                                    else {
4063                                            query.append(_FINDER_COLUMN_T_C_D_DATA_2);
4064                                    }
4065                            }
4066    
4067                            if (orderByComparator != null) {
4068                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4069                                            orderByComparator);
4070                            }
4071    
4072                            else {
4073                                    query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
4074                            }
4075    
4076                            String sql = query.toString();
4077    
4078                            Session session = null;
4079    
4080                            try {
4081                                    session = openSession();
4082    
4083                                    Query q = session.createQuery(sql);
4084    
4085                                    QueryPos qPos = QueryPos.getInstance(q);
4086    
4087                                    qPos.add(tableId);
4088    
4089                                    qPos.add(columnId);
4090    
4091                                    if (data != null) {
4092                                            qPos.add(data);
4093                                    }
4094    
4095                                    list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
4096                                                    start, end);
4097                            }
4098                            catch (Exception e) {
4099                                    throw processException(e);
4100                            }
4101                            finally {
4102                                    if (list == null) {
4103                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
4104                                    }
4105                                    else {
4106                                            cacheResult(list);
4107    
4108                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
4109                                    }
4110    
4111                                    closeSession(session);
4112                            }
4113                    }
4114    
4115                    return list;
4116            }
4117    
4118            /**
4119             * Returns the first expando value in the ordered set where tableId = &#63; and columnId = &#63; and data = &#63;.
4120             *
4121             * @param tableId the table ID
4122             * @param columnId the column ID
4123             * @param data the data
4124             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4125             * @return the first matching expando value
4126             * @throws com.liferay.portlet.expando.NoSuchValueException if a matching expando value could not be found
4127             * @throws SystemException if a system exception occurred
4128             */
4129            public ExpandoValue findByT_C_D_First(long tableId, long columnId,
4130                    String data, OrderByComparator orderByComparator)
4131                    throws NoSuchValueException, SystemException {
4132                    ExpandoValue expandoValue = fetchByT_C_D_First(tableId, columnId, data,
4133                                    orderByComparator);
4134    
4135                    if (expandoValue != null) {
4136                            return expandoValue;
4137                    }
4138    
4139                    StringBundler msg = new StringBundler(8);
4140    
4141                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4142    
4143                    msg.append("tableId=");
4144                    msg.append(tableId);
4145    
4146                    msg.append(", columnId=");
4147                    msg.append(columnId);
4148    
4149                    msg.append(", data=");
4150                    msg.append(data);
4151    
4152                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4153    
4154                    throw new NoSuchValueException(msg.toString());
4155            }
4156    
4157            /**
4158             * Returns the first expando value in the ordered set where tableId = &#63; and columnId = &#63; and data = &#63;.
4159             *
4160             * @param tableId the table ID
4161             * @param columnId the column ID
4162             * @param data the data
4163             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4164             * @return the first matching expando value, or <code>null</code> if a matching expando value could not be found
4165             * @throws SystemException if a system exception occurred
4166             */
4167            public ExpandoValue fetchByT_C_D_First(long tableId, long columnId,
4168                    String data, OrderByComparator orderByComparator)
4169                    throws SystemException {
4170                    List<ExpandoValue> list = findByT_C_D(tableId, columnId, data, 0, 1,
4171                                    orderByComparator);
4172    
4173                    if (!list.isEmpty()) {
4174                            return list.get(0);
4175                    }
4176    
4177                    return null;
4178            }
4179    
4180            /**
4181             * Returns the last expando value in the ordered set where tableId = &#63; and columnId = &#63; and data = &#63;.
4182             *
4183             * @param tableId the table ID
4184             * @param columnId the column ID
4185             * @param data the data
4186             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4187             * @return the last matching expando value
4188             * @throws com.liferay.portlet.expando.NoSuchValueException if a matching expando value could not be found
4189             * @throws SystemException if a system exception occurred
4190             */
4191            public ExpandoValue findByT_C_D_Last(long tableId, long columnId,
4192                    String data, OrderByComparator orderByComparator)
4193                    throws NoSuchValueException, SystemException {
4194                    ExpandoValue expandoValue = fetchByT_C_D_Last(tableId, columnId, data,
4195                                    orderByComparator);
4196    
4197                    if (expandoValue != null) {
4198                            return expandoValue;
4199                    }
4200    
4201                    StringBundler msg = new StringBundler(8);
4202    
4203                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4204    
4205                    msg.append("tableId=");
4206                    msg.append(tableId);
4207    
4208                    msg.append(", columnId=");
4209                    msg.append(columnId);
4210    
4211                    msg.append(", data=");
4212                    msg.append(data);
4213    
4214                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4215    
4216                    throw new NoSuchValueException(msg.toString());
4217            }
4218    
4219            /**
4220             * Returns the last expando value in the ordered set where tableId = &#63; and columnId = &#63; and data = &#63;.
4221             *
4222             * @param tableId the table ID
4223             * @param columnId the column ID
4224             * @param data the data
4225             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4226             * @return the last matching expando value, or <code>null</code> if a matching expando value could not be found
4227             * @throws SystemException if a system exception occurred
4228             */
4229            public ExpandoValue fetchByT_C_D_Last(long tableId, long columnId,
4230                    String data, OrderByComparator orderByComparator)
4231                    throws SystemException {
4232                    int count = countByT_C_D(tableId, columnId, data);
4233    
4234                    List<ExpandoValue> list = findByT_C_D(tableId, columnId, data,
4235                                    count - 1, count, orderByComparator);
4236    
4237                    if (!list.isEmpty()) {
4238                            return list.get(0);
4239                    }
4240    
4241                    return null;
4242            }
4243    
4244            /**
4245             * Returns the expando values before and after the current expando value in the ordered set where tableId = &#63; and columnId = &#63; and data = &#63;.
4246             *
4247             * @param valueId the primary key of the current expando value
4248             * @param tableId the table ID
4249             * @param columnId the column ID
4250             * @param data the data
4251             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4252             * @return the previous, current, and next expando value
4253             * @throws com.liferay.portlet.expando.NoSuchValueException if a expando value with the primary key could not be found
4254             * @throws SystemException if a system exception occurred
4255             */
4256            public ExpandoValue[] findByT_C_D_PrevAndNext(long valueId, long tableId,
4257                    long columnId, String data, OrderByComparator orderByComparator)
4258                    throws NoSuchValueException, SystemException {
4259                    ExpandoValue expandoValue = findByPrimaryKey(valueId);
4260    
4261                    Session session = null;
4262    
4263                    try {
4264                            session = openSession();
4265    
4266                            ExpandoValue[] array = new ExpandoValueImpl[3];
4267    
4268                            array[0] = getByT_C_D_PrevAndNext(session, expandoValue, tableId,
4269                                            columnId, data, orderByComparator, true);
4270    
4271                            array[1] = expandoValue;
4272    
4273                            array[2] = getByT_C_D_PrevAndNext(session, expandoValue, tableId,
4274                                            columnId, data, orderByComparator, false);
4275    
4276                            return array;
4277                    }
4278                    catch (Exception e) {
4279                            throw processException(e);
4280                    }
4281                    finally {
4282                            closeSession(session);
4283                    }
4284            }
4285    
4286            protected ExpandoValue getByT_C_D_PrevAndNext(Session session,
4287                    ExpandoValue expandoValue, long tableId, long columnId, String data,
4288                    OrderByComparator orderByComparator, boolean previous) {
4289                    StringBundler query = null;
4290    
4291                    if (orderByComparator != null) {
4292                            query = new StringBundler(6 +
4293                                            (orderByComparator.getOrderByFields().length * 6));
4294                    }
4295                    else {
4296                            query = new StringBundler(3);
4297                    }
4298    
4299                    query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
4300    
4301                    query.append(_FINDER_COLUMN_T_C_D_TABLEID_2);
4302    
4303                    query.append(_FINDER_COLUMN_T_C_D_COLUMNID_2);
4304    
4305                    if (data == null) {
4306                            query.append(_FINDER_COLUMN_T_C_D_DATA_1);
4307                    }
4308                    else {
4309                            if (data.equals(StringPool.BLANK)) {
4310                                    query.append(_FINDER_COLUMN_T_C_D_DATA_3);
4311                            }
4312                            else {
4313                                    query.append(_FINDER_COLUMN_T_C_D_DATA_2);
4314                            }
4315                    }
4316    
4317                    if (orderByComparator != null) {
4318                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4319    
4320                            if (orderByConditionFields.length > 0) {
4321                                    query.append(WHERE_AND);
4322                            }
4323    
4324                            for (int i = 0; i < orderByConditionFields.length; i++) {
4325                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4326                                    query.append(orderByConditionFields[i]);
4327    
4328                                    if ((i + 1) < orderByConditionFields.length) {
4329                                            if (orderByComparator.isAscending() ^ previous) {
4330                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4331                                            }
4332                                            else {
4333                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4334                                            }
4335                                    }
4336                                    else {
4337                                            if (orderByComparator.isAscending() ^ previous) {
4338                                                    query.append(WHERE_GREATER_THAN);
4339                                            }
4340                                            else {
4341                                                    query.append(WHERE_LESSER_THAN);
4342                                            }
4343                                    }
4344                            }
4345    
4346                            query.append(ORDER_BY_CLAUSE);
4347    
4348                            String[] orderByFields = orderByComparator.getOrderByFields();
4349    
4350                            for (int i = 0; i < orderByFields.length; i++) {
4351                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4352                                    query.append(orderByFields[i]);
4353    
4354                                    if ((i + 1) < orderByFields.length) {
4355                                            if (orderByComparator.isAscending() ^ previous) {
4356                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4357                                            }
4358                                            else {
4359                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4360                                            }
4361                                    }
4362                                    else {
4363                                            if (orderByComparator.isAscending() ^ previous) {
4364                                                    query.append(ORDER_BY_ASC);
4365                                            }
4366                                            else {
4367                                                    query.append(ORDER_BY_DESC);
4368                                            }
4369                                    }
4370                            }
4371                    }
4372    
4373                    else {
4374                            query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
4375                    }
4376    
4377                    String sql = query.toString();
4378    
4379                    Query q = session.createQuery(sql);
4380    
4381                    q.setFirstResult(0);
4382                    q.setMaxResults(2);
4383    
4384                    QueryPos qPos = QueryPos.getInstance(q);
4385    
4386                    qPos.add(tableId);
4387    
4388                    qPos.add(columnId);
4389    
4390                    if (data != null) {
4391                            qPos.add(data);
4392                    }
4393    
4394                    if (orderByComparator != null) {
4395                            Object[] values = orderByComparator.getOrderByConditionValues(expandoValue);
4396    
4397                            for (Object value : values) {
4398                                    qPos.add(value);
4399                            }
4400                    }
4401    
4402                    List<ExpandoValue> list = q.list();
4403    
4404                    if (list.size() == 2) {
4405                            return list.get(1);
4406                    }
4407                    else {
4408                            return null;
4409                    }
4410            }
4411    
4412            /**
4413             * Returns all the expando values.
4414             *
4415             * @return the expando values
4416             * @throws SystemException if a system exception occurred
4417             */
4418            public List<ExpandoValue> findAll() throws SystemException {
4419                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4420            }
4421    
4422            /**
4423             * Returns a range of all the expando values.
4424             *
4425             * <p>
4426             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4427             * </p>
4428             *
4429             * @param start the lower bound of the range of expando values
4430             * @param end the upper bound of the range of expando values (not inclusive)
4431             * @return the range of expando values
4432             * @throws SystemException if a system exception occurred
4433             */
4434            public List<ExpandoValue> findAll(int start, int end)
4435                    throws SystemException {
4436                    return findAll(start, end, null);
4437            }
4438    
4439            /**
4440             * Returns an ordered range of all the expando values.
4441             *
4442             * <p>
4443             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4444             * </p>
4445             *
4446             * @param start the lower bound of the range of expando values
4447             * @param end the upper bound of the range of expando values (not inclusive)
4448             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4449             * @return the ordered range of expando values
4450             * @throws SystemException if a system exception occurred
4451             */
4452            public List<ExpandoValue> findAll(int start, int end,
4453                    OrderByComparator orderByComparator) throws SystemException {
4454                    FinderPath finderPath = null;
4455                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
4456    
4457                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4458                                    (orderByComparator == null)) {
4459                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
4460                            finderArgs = FINDER_ARGS_EMPTY;
4461                    }
4462                    else {
4463                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
4464                            finderArgs = new Object[] { start, end, orderByComparator };
4465                    }
4466    
4467                    List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(finderPath,
4468                                    finderArgs, this);
4469    
4470                    if (list == null) {
4471                            StringBundler query = null;
4472                            String sql = null;
4473    
4474                            if (orderByComparator != null) {
4475                                    query = new StringBundler(2 +
4476                                                    (orderByComparator.getOrderByFields().length * 3));
4477    
4478                                    query.append(_SQL_SELECT_EXPANDOVALUE);
4479    
4480                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4481                                            orderByComparator);
4482    
4483                                    sql = query.toString();
4484                            }
4485                            else {
4486                                    sql = _SQL_SELECT_EXPANDOVALUE.concat(ExpandoValueModelImpl.ORDER_BY_JPQL);
4487                            }
4488    
4489                            Session session = null;
4490    
4491                            try {
4492                                    session = openSession();
4493    
4494                                    Query q = session.createQuery(sql);
4495    
4496                                    if (orderByComparator == null) {
4497                                            list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
4498                                                            start, end, false);
4499    
4500                                            Collections.sort(list);
4501                                    }
4502                                    else {
4503                                            list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
4504                                                            start, end);
4505                                    }
4506                            }
4507                            catch (Exception e) {
4508                                    throw processException(e);
4509                            }
4510                            finally {
4511                                    if (list == null) {
4512                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
4513                                    }
4514                                    else {
4515                                            cacheResult(list);
4516    
4517                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
4518                                    }
4519    
4520                                    closeSession(session);
4521                            }
4522                    }
4523    
4524                    return list;
4525            }
4526    
4527            /**
4528             * Removes all the expando values where tableId = &#63; from the database.
4529             *
4530             * @param tableId the table ID
4531             * @throws SystemException if a system exception occurred
4532             */
4533            public void removeByTableId(long tableId) throws SystemException {
4534                    for (ExpandoValue expandoValue : findByTableId(tableId)) {
4535                            remove(expandoValue);
4536                    }
4537            }
4538    
4539            /**
4540             * Removes all the expando values where columnId = &#63; from the database.
4541             *
4542             * @param columnId the column ID
4543             * @throws SystemException if a system exception occurred
4544             */
4545            public void removeByColumnId(long columnId) throws SystemException {
4546                    for (ExpandoValue expandoValue : findByColumnId(columnId)) {
4547                            remove(expandoValue);
4548                    }
4549            }
4550    
4551            /**
4552             * Removes all the expando values where rowId = &#63; from the database.
4553             *
4554             * @param rowId the row ID
4555             * @throws SystemException if a system exception occurred
4556             */
4557            public void removeByRowId(long rowId) throws SystemException {
4558                    for (ExpandoValue expandoValue : findByRowId(rowId)) {
4559                            remove(expandoValue);
4560                    }
4561            }
4562    
4563            /**
4564             * Removes all the expando values where tableId = &#63; and columnId = &#63; from the database.
4565             *
4566             * @param tableId the table ID
4567             * @param columnId the column ID
4568             * @throws SystemException if a system exception occurred
4569             */
4570            public void removeByT_C(long tableId, long columnId)
4571                    throws SystemException {
4572                    for (ExpandoValue expandoValue : findByT_C(tableId, columnId)) {
4573                            remove(expandoValue);
4574                    }
4575            }
4576    
4577            /**
4578             * Removes all the expando values where tableId = &#63; and classPK = &#63; from the database.
4579             *
4580             * @param tableId the table ID
4581             * @param classPK the class p k
4582             * @throws SystemException if a system exception occurred
4583             */
4584            public void removeByT_CPK(long tableId, long classPK)
4585                    throws SystemException {
4586                    for (ExpandoValue expandoValue : findByT_CPK(tableId, classPK)) {
4587                            remove(expandoValue);
4588                    }
4589            }
4590    
4591            /**
4592             * Removes all the expando values where tableId = &#63; and rowId = &#63; from the database.
4593             *
4594             * @param tableId the table ID
4595             * @param rowId the row ID
4596             * @throws SystemException if a system exception occurred
4597             */
4598            public void removeByT_R(long tableId, long rowId) throws SystemException {
4599                    for (ExpandoValue expandoValue : findByT_R(tableId, rowId)) {
4600                            remove(expandoValue);
4601                    }
4602            }
4603    
4604            /**
4605             * Removes the expando value where columnId = &#63; and rowId = &#63; from the database.
4606             *
4607             * @param columnId the column ID
4608             * @param rowId the row ID
4609             * @return the expando value that was removed
4610             * @throws SystemException if a system exception occurred
4611             */
4612            public ExpandoValue removeByC_R(long columnId, long rowId)
4613                    throws NoSuchValueException, SystemException {
4614                    ExpandoValue expandoValue = findByC_R(columnId, rowId);
4615    
4616                    return remove(expandoValue);
4617            }
4618    
4619            /**
4620             * Removes all the expando values where classNameId = &#63; and classPK = &#63; from the database.
4621             *
4622             * @param classNameId the class name ID
4623             * @param classPK the class p k
4624             * @throws SystemException if a system exception occurred
4625             */
4626            public void removeByC_C(long classNameId, long classPK)
4627                    throws SystemException {
4628                    for (ExpandoValue expandoValue : findByC_C(classNameId, classPK)) {
4629                            remove(expandoValue);
4630                    }
4631            }
4632    
4633            /**
4634             * Removes the expando value where tableId = &#63; and columnId = &#63; and classPK = &#63; from the database.
4635             *
4636             * @param tableId the table ID
4637             * @param columnId the column ID
4638             * @param classPK the class p k
4639             * @return the expando value that was removed
4640             * @throws SystemException if a system exception occurred
4641             */
4642            public ExpandoValue removeByT_C_C(long tableId, long columnId, long classPK)
4643                    throws NoSuchValueException, SystemException {
4644                    ExpandoValue expandoValue = findByT_C_C(tableId, columnId, classPK);
4645    
4646                    return remove(expandoValue);
4647            }
4648    
4649            /**
4650             * Removes all the expando values where tableId = &#63; and columnId = &#63; and data = &#63; from the database.
4651             *
4652             * @param tableId the table ID
4653             * @param columnId the column ID
4654             * @param data the data
4655             * @throws SystemException if a system exception occurred
4656             */
4657            public void removeByT_C_D(long tableId, long columnId, String data)
4658                    throws SystemException {
4659                    for (ExpandoValue expandoValue : findByT_C_D(tableId, columnId, data)) {
4660                            remove(expandoValue);
4661                    }
4662            }
4663    
4664            /**
4665             * Removes all the expando values from the database.
4666             *
4667             * @throws SystemException if a system exception occurred
4668             */
4669            public void removeAll() throws SystemException {
4670                    for (ExpandoValue expandoValue : findAll()) {
4671                            remove(expandoValue);
4672                    }
4673            }
4674    
4675            /**
4676             * Returns the number of expando values where tableId = &#63;.
4677             *
4678             * @param tableId the table ID
4679             * @return the number of matching expando values
4680             * @throws SystemException if a system exception occurred
4681             */
4682            public int countByTableId(long tableId) throws SystemException {
4683                    Object[] finderArgs = new Object[] { tableId };
4684    
4685                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TABLEID,
4686                                    finderArgs, this);
4687    
4688                    if (count == null) {
4689                            StringBundler query = new StringBundler(2);
4690    
4691                            query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
4692    
4693                            query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
4694    
4695                            String sql = query.toString();
4696    
4697                            Session session = null;
4698    
4699                            try {
4700                                    session = openSession();
4701    
4702                                    Query q = session.createQuery(sql);
4703    
4704                                    QueryPos qPos = QueryPos.getInstance(q);
4705    
4706                                    qPos.add(tableId);
4707    
4708                                    count = (Long)q.uniqueResult();
4709                            }
4710                            catch (Exception e) {
4711                                    throw processException(e);
4712                            }
4713                            finally {
4714                                    if (count == null) {
4715                                            count = Long.valueOf(0);
4716                                    }
4717    
4718                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TABLEID,
4719                                            finderArgs, count);
4720    
4721                                    closeSession(session);
4722                            }
4723                    }
4724    
4725                    return count.intValue();
4726            }
4727    
4728            /**
4729             * Returns the number of expando values where columnId = &#63;.
4730             *
4731             * @param columnId the column ID
4732             * @return the number of matching expando values
4733             * @throws SystemException if a system exception occurred
4734             */
4735            public int countByColumnId(long columnId) throws SystemException {
4736                    Object[] finderArgs = new Object[] { columnId };
4737    
4738                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COLUMNID,
4739                                    finderArgs, this);
4740    
4741                    if (count == null) {
4742                            StringBundler query = new StringBundler(2);
4743    
4744                            query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
4745    
4746                            query.append(_FINDER_COLUMN_COLUMNID_COLUMNID_2);
4747    
4748                            String sql = query.toString();
4749    
4750                            Session session = null;
4751    
4752                            try {
4753                                    session = openSession();
4754    
4755                                    Query q = session.createQuery(sql);
4756    
4757                                    QueryPos qPos = QueryPos.getInstance(q);
4758    
4759                                    qPos.add(columnId);
4760    
4761                                    count = (Long)q.uniqueResult();
4762                            }
4763                            catch (Exception e) {
4764                                    throw processException(e);
4765                            }
4766                            finally {
4767                                    if (count == null) {
4768                                            count = Long.valueOf(0);
4769                                    }
4770    
4771                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COLUMNID,
4772                                            finderArgs, count);
4773    
4774                                    closeSession(session);
4775                            }
4776                    }
4777    
4778                    return count.intValue();
4779            }
4780    
4781            /**
4782             * Returns the number of expando values where rowId = &#63;.
4783             *
4784             * @param rowId the row ID
4785             * @return the number of matching expando values
4786             * @throws SystemException if a system exception occurred
4787             */
4788            public int countByRowId(long rowId) throws SystemException {
4789                    Object[] finderArgs = new Object[] { rowId };
4790    
4791                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ROWID,
4792                                    finderArgs, this);
4793    
4794                    if (count == null) {
4795                            StringBundler query = new StringBundler(2);
4796    
4797                            query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
4798    
4799                            query.append(_FINDER_COLUMN_ROWID_ROWID_2);
4800    
4801                            String sql = query.toString();
4802    
4803                            Session session = null;
4804    
4805                            try {
4806                                    session = openSession();
4807    
4808                                    Query q = session.createQuery(sql);
4809    
4810                                    QueryPos qPos = QueryPos.getInstance(q);
4811    
4812                                    qPos.add(rowId);
4813    
4814                                    count = (Long)q.uniqueResult();
4815                            }
4816                            catch (Exception e) {
4817                                    throw processException(e);
4818                            }
4819                            finally {
4820                                    if (count == null) {
4821                                            count = Long.valueOf(0);
4822                                    }
4823    
4824                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROWID,
4825                                            finderArgs, count);
4826    
4827                                    closeSession(session);
4828                            }
4829                    }
4830    
4831                    return count.intValue();
4832            }
4833    
4834            /**
4835             * Returns the number of expando values where tableId = &#63; and columnId = &#63;.
4836             *
4837             * @param tableId the table ID
4838             * @param columnId the column ID
4839             * @return the number of matching expando values
4840             * @throws SystemException if a system exception occurred
4841             */
4842            public int countByT_C(long tableId, long columnId)
4843                    throws SystemException {
4844                    Object[] finderArgs = new Object[] { tableId, columnId };
4845    
4846                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_C,
4847                                    finderArgs, this);
4848    
4849                    if (count == null) {
4850                            StringBundler query = new StringBundler(3);
4851    
4852                            query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
4853    
4854                            query.append(_FINDER_COLUMN_T_C_TABLEID_2);
4855    
4856                            query.append(_FINDER_COLUMN_T_C_COLUMNID_2);
4857    
4858                            String sql = query.toString();
4859    
4860                            Session session = null;
4861    
4862                            try {
4863                                    session = openSession();
4864    
4865                                    Query q = session.createQuery(sql);
4866    
4867                                    QueryPos qPos = QueryPos.getInstance(q);
4868    
4869                                    qPos.add(tableId);
4870    
4871                                    qPos.add(columnId);
4872    
4873                                    count = (Long)q.uniqueResult();
4874                            }
4875                            catch (Exception e) {
4876                                    throw processException(e);
4877                            }
4878                            finally {
4879                                    if (count == null) {
4880                                            count = Long.valueOf(0);
4881                                    }
4882    
4883                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_C, finderArgs,
4884                                            count);
4885    
4886                                    closeSession(session);
4887                            }
4888                    }
4889    
4890                    return count.intValue();
4891            }
4892    
4893            /**
4894             * Returns the number of expando values where tableId = &#63; and classPK = &#63;.
4895             *
4896             * @param tableId the table ID
4897             * @param classPK the class p k
4898             * @return the number of matching expando values
4899             * @throws SystemException if a system exception occurred
4900             */
4901            public int countByT_CPK(long tableId, long classPK)
4902                    throws SystemException {
4903                    Object[] finderArgs = new Object[] { tableId, classPK };
4904    
4905                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_CPK,
4906                                    finderArgs, this);
4907    
4908                    if (count == null) {
4909                            StringBundler query = new StringBundler(3);
4910    
4911                            query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
4912    
4913                            query.append(_FINDER_COLUMN_T_CPK_TABLEID_2);
4914    
4915                            query.append(_FINDER_COLUMN_T_CPK_CLASSPK_2);
4916    
4917                            String sql = query.toString();
4918    
4919                            Session session = null;
4920    
4921                            try {
4922                                    session = openSession();
4923    
4924                                    Query q = session.createQuery(sql);
4925    
4926                                    QueryPos qPos = QueryPos.getInstance(q);
4927    
4928                                    qPos.add(tableId);
4929    
4930                                    qPos.add(classPK);
4931    
4932                                    count = (Long)q.uniqueResult();
4933                            }
4934                            catch (Exception e) {
4935                                    throw processException(e);
4936                            }
4937                            finally {
4938                                    if (count == null) {
4939                                            count = Long.valueOf(0);
4940                                    }
4941    
4942                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_CPK,
4943                                            finderArgs, count);
4944    
4945                                    closeSession(session);
4946                            }
4947                    }
4948    
4949                    return count.intValue();
4950            }
4951    
4952            /**
4953             * Returns the number of expando values where tableId = &#63; and rowId = &#63;.
4954             *
4955             * @param tableId the table ID
4956             * @param rowId the row ID
4957             * @return the number of matching expando values
4958             * @throws SystemException if a system exception occurred
4959             */
4960            public int countByT_R(long tableId, long rowId) throws SystemException {
4961                    Object[] finderArgs = new Object[] { tableId, rowId };
4962    
4963                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_R,
4964                                    finderArgs, this);
4965    
4966                    if (count == null) {
4967                            StringBundler query = new StringBundler(3);
4968    
4969                            query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
4970    
4971                            query.append(_FINDER_COLUMN_T_R_TABLEID_2);
4972    
4973                            query.append(_FINDER_COLUMN_T_R_ROWID_2);
4974    
4975                            String sql = query.toString();
4976    
4977                            Session session = null;
4978    
4979                            try {
4980                                    session = openSession();
4981    
4982                                    Query q = session.createQuery(sql);
4983    
4984                                    QueryPos qPos = QueryPos.getInstance(q);
4985    
4986                                    qPos.add(tableId);
4987    
4988                                    qPos.add(rowId);
4989    
4990                                    count = (Long)q.uniqueResult();
4991                            }
4992                            catch (Exception e) {
4993                                    throw processException(e);
4994                            }
4995                            finally {
4996                                    if (count == null) {
4997                                            count = Long.valueOf(0);
4998                                    }
4999    
5000                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_R, finderArgs,
5001                                            count);
5002    
5003                                    closeSession(session);
5004                            }
5005                    }
5006    
5007                    return count.intValue();
5008            }
5009    
5010            /**
5011             * Returns the number of expando values where columnId = &#63; and rowId = &#63;.
5012             *
5013             * @param columnId the column ID
5014             * @param rowId the row ID
5015             * @return the number of matching expando values
5016             * @throws SystemException if a system exception occurred
5017             */
5018            public int countByC_R(long columnId, long rowId) throws SystemException {
5019                    Object[] finderArgs = new Object[] { columnId, rowId };
5020    
5021                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_R,
5022                                    finderArgs, this);
5023    
5024                    if (count == null) {
5025                            StringBundler query = new StringBundler(3);
5026    
5027                            query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
5028    
5029                            query.append(_FINDER_COLUMN_C_R_COLUMNID_2);
5030    
5031                            query.append(_FINDER_COLUMN_C_R_ROWID_2);
5032    
5033                            String sql = query.toString();
5034    
5035                            Session session = null;
5036    
5037                            try {
5038                                    session = openSession();
5039    
5040                                    Query q = session.createQuery(sql);
5041    
5042                                    QueryPos qPos = QueryPos.getInstance(q);
5043    
5044                                    qPos.add(columnId);
5045    
5046                                    qPos.add(rowId);
5047    
5048                                    count = (Long)q.uniqueResult();
5049                            }
5050                            catch (Exception e) {
5051                                    throw processException(e);
5052                            }
5053                            finally {
5054                                    if (count == null) {
5055                                            count = Long.valueOf(0);
5056                                    }
5057    
5058                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_R, finderArgs,
5059                                            count);
5060    
5061                                    closeSession(session);
5062                            }
5063                    }
5064    
5065                    return count.intValue();
5066            }
5067    
5068            /**
5069             * Returns the number of expando values where classNameId = &#63; and classPK = &#63;.
5070             *
5071             * @param classNameId the class name ID
5072             * @param classPK the class p k
5073             * @return the number of matching expando values
5074             * @throws SystemException if a system exception occurred
5075             */
5076            public int countByC_C(long classNameId, long classPK)
5077                    throws SystemException {
5078                    Object[] finderArgs = new Object[] { classNameId, classPK };
5079    
5080                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
5081                                    finderArgs, this);
5082    
5083                    if (count == null) {
5084                            StringBundler query = new StringBundler(3);
5085    
5086                            query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
5087    
5088                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
5089    
5090                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
5091    
5092                            String sql = query.toString();
5093    
5094                            Session session = null;
5095    
5096                            try {
5097                                    session = openSession();
5098    
5099                                    Query q = session.createQuery(sql);
5100    
5101                                    QueryPos qPos = QueryPos.getInstance(q);
5102    
5103                                    qPos.add(classNameId);
5104    
5105                                    qPos.add(classPK);
5106    
5107                                    count = (Long)q.uniqueResult();
5108                            }
5109                            catch (Exception e) {
5110                                    throw processException(e);
5111                            }
5112                            finally {
5113                                    if (count == null) {
5114                                            count = Long.valueOf(0);
5115                                    }
5116    
5117                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
5118                                            count);
5119    
5120                                    closeSession(session);
5121                            }
5122                    }
5123    
5124                    return count.intValue();
5125            }
5126    
5127            /**
5128             * Returns the number of expando values where tableId = &#63; and columnId = &#63; and classPK = &#63;.
5129             *
5130             * @param tableId the table ID
5131             * @param columnId the column ID
5132             * @param classPK the class p k
5133             * @return the number of matching expando values
5134             * @throws SystemException if a system exception occurred
5135             */
5136            public int countByT_C_C(long tableId, long columnId, long classPK)
5137                    throws SystemException {
5138                    Object[] finderArgs = new Object[] { tableId, columnId, classPK };
5139    
5140                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_C_C,
5141                                    finderArgs, this);
5142    
5143                    if (count == null) {
5144                            StringBundler query = new StringBundler(4);
5145    
5146                            query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
5147    
5148                            query.append(_FINDER_COLUMN_T_C_C_TABLEID_2);
5149    
5150                            query.append(_FINDER_COLUMN_T_C_C_COLUMNID_2);
5151    
5152                            query.append(_FINDER_COLUMN_T_C_C_CLASSPK_2);
5153    
5154                            String sql = query.toString();
5155    
5156                            Session session = null;
5157    
5158                            try {
5159                                    session = openSession();
5160    
5161                                    Query q = session.createQuery(sql);
5162    
5163                                    QueryPos qPos = QueryPos.getInstance(q);
5164    
5165                                    qPos.add(tableId);
5166    
5167                                    qPos.add(columnId);
5168    
5169                                    qPos.add(classPK);
5170    
5171                                    count = (Long)q.uniqueResult();
5172                            }
5173                            catch (Exception e) {
5174                                    throw processException(e);
5175                            }
5176                            finally {
5177                                    if (count == null) {
5178                                            count = Long.valueOf(0);
5179                                    }
5180    
5181                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_C_C,
5182                                            finderArgs, count);
5183    
5184                                    closeSession(session);
5185                            }
5186                    }
5187    
5188                    return count.intValue();
5189            }
5190    
5191            /**
5192             * Returns the number of expando values where tableId = &#63; and columnId = &#63; and data = &#63;.
5193             *
5194             * @param tableId the table ID
5195             * @param columnId the column ID
5196             * @param data the data
5197             * @return the number of matching expando values
5198             * @throws SystemException if a system exception occurred
5199             */
5200            public int countByT_C_D(long tableId, long columnId, String data)
5201                    throws SystemException {
5202                    Object[] finderArgs = new Object[] { tableId, columnId, data };
5203    
5204                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_C_D,
5205                                    finderArgs, this);
5206    
5207                    if (count == null) {
5208                            StringBundler query = new StringBundler(4);
5209    
5210                            query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
5211    
5212                            query.append(_FINDER_COLUMN_T_C_D_TABLEID_2);
5213    
5214                            query.append(_FINDER_COLUMN_T_C_D_COLUMNID_2);
5215    
5216                            if (data == null) {
5217                                    query.append(_FINDER_COLUMN_T_C_D_DATA_1);
5218                            }
5219                            else {
5220                                    if (data.equals(StringPool.BLANK)) {
5221                                            query.append(_FINDER_COLUMN_T_C_D_DATA_3);
5222                                    }
5223                                    else {
5224                                            query.append(_FINDER_COLUMN_T_C_D_DATA_2);
5225                                    }
5226                            }
5227    
5228                            String sql = query.toString();
5229    
5230                            Session session = null;
5231    
5232                            try {
5233                                    session = openSession();
5234    
5235                                    Query q = session.createQuery(sql);
5236    
5237                                    QueryPos qPos = QueryPos.getInstance(q);
5238    
5239                                    qPos.add(tableId);
5240    
5241                                    qPos.add(columnId);
5242    
5243                                    if (data != null) {
5244                                            qPos.add(data);
5245                                    }
5246    
5247                                    count = (Long)q.uniqueResult();
5248                            }
5249                            catch (Exception e) {
5250                                    throw processException(e);
5251                            }
5252                            finally {
5253                                    if (count == null) {
5254                                            count = Long.valueOf(0);
5255                                    }
5256    
5257                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_C_D,
5258                                            finderArgs, count);
5259    
5260                                    closeSession(session);
5261                            }
5262                    }
5263    
5264                    return count.intValue();
5265            }
5266    
5267            /**
5268             * Returns the number of expando values.
5269             *
5270             * @return the number of expando values
5271             * @throws SystemException if a system exception occurred
5272             */
5273            public int countAll() throws SystemException {
5274                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
5275                                    FINDER_ARGS_EMPTY, this);
5276    
5277                    if (count == null) {
5278                            Session session = null;
5279    
5280                            try {
5281                                    session = openSession();
5282    
5283                                    Query q = session.createQuery(_SQL_COUNT_EXPANDOVALUE);
5284    
5285                                    count = (Long)q.uniqueResult();
5286                            }
5287                            catch (Exception e) {
5288                                    throw processException(e);
5289                            }
5290                            finally {
5291                                    if (count == null) {
5292                                            count = Long.valueOf(0);
5293                                    }
5294    
5295                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
5296                                            FINDER_ARGS_EMPTY, count);
5297    
5298                                    closeSession(session);
5299                            }
5300                    }
5301    
5302                    return count.intValue();
5303            }
5304    
5305            /**
5306             * Initializes the expando value persistence.
5307             */
5308            public void afterPropertiesSet() {
5309                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
5310                                            com.liferay.portal.util.PropsUtil.get(
5311                                                    "value.object.listener.com.liferay.portlet.expando.model.ExpandoValue")));
5312    
5313                    if (listenerClassNames.length > 0) {
5314                            try {
5315                                    List<ModelListener<ExpandoValue>> listenersList = new ArrayList<ModelListener<ExpandoValue>>();
5316    
5317                                    for (String listenerClassName : listenerClassNames) {
5318                                            listenersList.add((ModelListener<ExpandoValue>)InstanceFactory.newInstance(
5319                                                            listenerClassName));
5320                                    }
5321    
5322                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
5323                            }
5324                            catch (Exception e) {
5325                                    _log.error(e);
5326                            }
5327                    }
5328            }
5329    
5330            public void destroy() {
5331                    EntityCacheUtil.removeCache(ExpandoValueImpl.class.getName());
5332                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
5333                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5334            }
5335    
5336            @BeanReference(type = ExpandoColumnPersistence.class)
5337            protected ExpandoColumnPersistence expandoColumnPersistence;
5338            @BeanReference(type = ExpandoRowPersistence.class)
5339            protected ExpandoRowPersistence expandoRowPersistence;
5340            @BeanReference(type = ExpandoTablePersistence.class)
5341            protected ExpandoTablePersistence expandoTablePersistence;
5342            @BeanReference(type = ExpandoValuePersistence.class)
5343            protected ExpandoValuePersistence expandoValuePersistence;
5344            @BeanReference(type = ResourcePersistence.class)
5345            protected ResourcePersistence resourcePersistence;
5346            @BeanReference(type = UserPersistence.class)
5347            protected UserPersistence userPersistence;
5348            private static final String _SQL_SELECT_EXPANDOVALUE = "SELECT expandoValue FROM ExpandoValue expandoValue";
5349            private static final String _SQL_SELECT_EXPANDOVALUE_WHERE = "SELECT expandoValue FROM ExpandoValue expandoValue WHERE ";
5350            private static final String _SQL_COUNT_EXPANDOVALUE = "SELECT COUNT(expandoValue) FROM ExpandoValue expandoValue";
5351            private static final String _SQL_COUNT_EXPANDOVALUE_WHERE = "SELECT COUNT(expandoValue) FROM ExpandoValue expandoValue WHERE ";
5352            private static final String _FINDER_COLUMN_TABLEID_TABLEID_2 = "expandoValue.tableId = ?";
5353            private static final String _FINDER_COLUMN_COLUMNID_COLUMNID_2 = "expandoValue.columnId = ?";
5354            private static final String _FINDER_COLUMN_ROWID_ROWID_2 = "expandoValue.rowId = ?";
5355            private static final String _FINDER_COLUMN_T_C_TABLEID_2 = "expandoValue.tableId = ? AND ";
5356            private static final String _FINDER_COLUMN_T_C_COLUMNID_2 = "expandoValue.columnId = ?";
5357            private static final String _FINDER_COLUMN_T_CPK_TABLEID_2 = "expandoValue.tableId = ? AND ";
5358            private static final String _FINDER_COLUMN_T_CPK_CLASSPK_2 = "expandoValue.classPK = ?";
5359            private static final String _FINDER_COLUMN_T_R_TABLEID_2 = "expandoValue.tableId = ? AND ";
5360            private static final String _FINDER_COLUMN_T_R_ROWID_2 = "expandoValue.rowId = ?";
5361            private static final String _FINDER_COLUMN_C_R_COLUMNID_2 = "expandoValue.columnId = ? AND ";
5362            private static final String _FINDER_COLUMN_C_R_ROWID_2 = "expandoValue.rowId = ?";
5363            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "expandoValue.classNameId = ? AND ";
5364            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "expandoValue.classPK = ?";
5365            private static final String _FINDER_COLUMN_T_C_C_TABLEID_2 = "expandoValue.tableId = ? AND ";
5366            private static final String _FINDER_COLUMN_T_C_C_COLUMNID_2 = "expandoValue.columnId = ? AND ";
5367            private static final String _FINDER_COLUMN_T_C_C_CLASSPK_2 = "expandoValue.classPK = ?";
5368            private static final String _FINDER_COLUMN_T_C_D_TABLEID_2 = "expandoValue.tableId = ? AND ";
5369            private static final String _FINDER_COLUMN_T_C_D_COLUMNID_2 = "expandoValue.columnId = ? AND ";
5370            private static final String _FINDER_COLUMN_T_C_D_DATA_1 = "expandoValue.data IS NULL";
5371            private static final String _FINDER_COLUMN_T_C_D_DATA_2 = "expandoValue.data = ?";
5372            private static final String _FINDER_COLUMN_T_C_D_DATA_3 = "(expandoValue.data IS NULL OR expandoValue.data = ?)";
5373            private static final String _ORDER_BY_ENTITY_ALIAS = "expandoValue.";
5374            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoValue exists with the primary key ";
5375            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoValue exists with the key {";
5376            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
5377            private static Log _log = LogFactoryUtil.getLog(ExpandoValuePersistenceImpl.class);
5378            private static ExpandoValue _nullExpandoValue = new ExpandoValueImpl() {
5379                            @Override
5380                            public Object clone() {
5381                                    return this;
5382                            }
5383    
5384                            @Override
5385                            public CacheModel<ExpandoValue> toCacheModel() {
5386                                    return _nullExpandoValueCacheModel;
5387                            }
5388                    };
5389    
5390            private static CacheModel<ExpandoValue> _nullExpandoValueCacheModel = new CacheModel<ExpandoValue>() {
5391                            public ExpandoValue toEntityModel() {
5392                                    return _nullExpandoValue;
5393                            }
5394                    };
5395    }