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