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