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