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