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