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