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