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