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