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