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