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