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