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