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