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