001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.expando.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.OrderByComparator;
030    import com.liferay.portal.kernel.util.SetUtil;
031    import com.liferay.portal.kernel.util.StringBundler;
032    import com.liferay.portal.kernel.util.StringPool;
033    import com.liferay.portal.model.CacheModel;
034    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
035    
036    import com.liferay.portlet.expando.NoSuchRowException;
037    import com.liferay.portlet.expando.model.ExpandoRow;
038    import com.liferay.portlet.expando.model.impl.ExpandoRowImpl;
039    import com.liferay.portlet.expando.model.impl.ExpandoRowModelImpl;
040    import com.liferay.portlet.expando.service.persistence.ExpandoRowPersistence;
041    
042    import java.io.Serializable;
043    
044    import java.util.Collections;
045    import java.util.HashMap;
046    import java.util.HashSet;
047    import java.util.Iterator;
048    import java.util.List;
049    import java.util.Map;
050    import java.util.Set;
051    
052    /**
053     * The persistence implementation for the expando row 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 ExpandoRowPersistence
061     * @see ExpandoRowUtil
062     * @generated
063     */
064    @ProviderType
065    public class ExpandoRowPersistenceImpl extends BasePersistenceImpl<ExpandoRow>
066            implements ExpandoRowPersistence {
067            /*
068             * NOTE FOR DEVELOPERS:
069             *
070             * Never modify or reference this class directly. Always use {@link ExpandoRowUtil} to access the expando row persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
071             */
072            public static final String FINDER_CLASS_NAME_ENTITY = ExpandoRowImpl.class.getName();
073            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074                    ".List1";
075            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076                    ".List2";
077            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
078                            ExpandoRowModelImpl.FINDER_CACHE_ENABLED, ExpandoRowImpl.class,
079                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
080            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
081                            ExpandoRowModelImpl.FINDER_CACHE_ENABLED, ExpandoRowImpl.class,
082                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
083            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
084                            ExpandoRowModelImpl.FINDER_CACHE_ENABLED, Long.class,
085                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
086            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TABLEID = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
087                            ExpandoRowModelImpl.FINDER_CACHE_ENABLED, ExpandoRowImpl.class,
088                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByTableId",
089                            new String[] {
090                                    Long.class.getName(),
091                                    
092                            Integer.class.getName(), Integer.class.getName(),
093                                    OrderByComparator.class.getName()
094                            });
095            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID =
096                    new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
097                            ExpandoRowModelImpl.FINDER_CACHE_ENABLED, ExpandoRowImpl.class,
098                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTableId",
099                            new String[] { Long.class.getName() },
100                            ExpandoRowModelImpl.TABLEID_COLUMN_BITMASK);
101            public static final FinderPath FINDER_PATH_COUNT_BY_TABLEID = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
102                            ExpandoRowModelImpl.FINDER_CACHE_ENABLED, Long.class,
103                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTableId",
104                            new String[] { Long.class.getName() });
105    
106            /**
107             * Returns all the expando rows where tableId = &#63;.
108             *
109             * @param tableId the table ID
110             * @return the matching expando rows
111             */
112            @Override
113            public List<ExpandoRow> findByTableId(long tableId) {
114                    return findByTableId(tableId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
115            }
116    
117            /**
118             * Returns a range of all the expando rows where tableId = &#63;.
119             *
120             * <p>
121             * 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.ExpandoRowModelImpl}. 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.
122             * </p>
123             *
124             * @param tableId the table ID
125             * @param start the lower bound of the range of expando rows
126             * @param end the upper bound of the range of expando rows (not inclusive)
127             * @return the range of matching expando rows
128             */
129            @Override
130            public List<ExpandoRow> findByTableId(long tableId, int start, int end) {
131                    return findByTableId(tableId, start, end, null);
132            }
133    
134            /**
135             * Returns an ordered range of all the expando rows where tableId = &#63;.
136             *
137             * <p>
138             * 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.ExpandoRowModelImpl}. 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.
139             * </p>
140             *
141             * @param tableId the table ID
142             * @param start the lower bound of the range of expando rows
143             * @param end the upper bound of the range of expando rows (not inclusive)
144             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
145             * @return the ordered range of matching expando rows
146             */
147            @Override
148            public List<ExpandoRow> findByTableId(long tableId, int start, int end,
149                    OrderByComparator<ExpandoRow> orderByComparator) {
150                    boolean pagination = true;
151                    FinderPath finderPath = null;
152                    Object[] finderArgs = null;
153    
154                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
155                                    (orderByComparator == null)) {
156                            pagination = false;
157                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID;
158                            finderArgs = new Object[] { tableId };
159                    }
160                    else {
161                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TABLEID;
162                            finderArgs = new Object[] { tableId, start, end, orderByComparator };
163                    }
164    
165                    List<ExpandoRow> list = (List<ExpandoRow>)FinderCacheUtil.getResult(finderPath,
166                                    finderArgs, this);
167    
168                    if ((list != null) && !list.isEmpty()) {
169                            for (ExpandoRow expandoRow : list) {
170                                    if ((tableId != expandoRow.getTableId())) {
171                                            list = null;
172    
173                                            break;
174                                    }
175                            }
176                    }
177    
178                    if (list == null) {
179                            StringBundler query = null;
180    
181                            if (orderByComparator != null) {
182                                    query = new StringBundler(3 +
183                                                    (orderByComparator.getOrderByFields().length * 3));
184                            }
185                            else {
186                                    query = new StringBundler(3);
187                            }
188    
189                            query.append(_SQL_SELECT_EXPANDOROW_WHERE);
190    
191                            query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
192    
193                            if (orderByComparator != null) {
194                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
195                                            orderByComparator);
196                            }
197                            else
198                             if (pagination) {
199                                    query.append(ExpandoRowModelImpl.ORDER_BY_JPQL);
200                            }
201    
202                            String sql = query.toString();
203    
204                            Session session = null;
205    
206                            try {
207                                    session = openSession();
208    
209                                    Query q = session.createQuery(sql);
210    
211                                    QueryPos qPos = QueryPos.getInstance(q);
212    
213                                    qPos.add(tableId);
214    
215                                    if (!pagination) {
216                                            list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(),
217                                                            start, end, false);
218    
219                                            Collections.sort(list);
220    
221                                            list = Collections.unmodifiableList(list);
222                                    }
223                                    else {
224                                            list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(),
225                                                            start, end);
226                                    }
227    
228                                    cacheResult(list);
229    
230                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
231                            }
232                            catch (Exception e) {
233                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
234    
235                                    throw processException(e);
236                            }
237                            finally {
238                                    closeSession(session);
239                            }
240                    }
241    
242                    return list;
243            }
244    
245            /**
246             * Returns the first expando row in the ordered set where tableId = &#63;.
247             *
248             * @param tableId the table ID
249             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
250             * @return the first matching expando row
251             * @throws com.liferay.portlet.expando.NoSuchRowException if a matching expando row could not be found
252             */
253            @Override
254            public ExpandoRow findByTableId_First(long tableId,
255                    OrderByComparator<ExpandoRow> orderByComparator)
256                    throws NoSuchRowException {
257                    ExpandoRow expandoRow = fetchByTableId_First(tableId, orderByComparator);
258    
259                    if (expandoRow != null) {
260                            return expandoRow;
261                    }
262    
263                    StringBundler msg = new StringBundler(4);
264    
265                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
266    
267                    msg.append("tableId=");
268                    msg.append(tableId);
269    
270                    msg.append(StringPool.CLOSE_CURLY_BRACE);
271    
272                    throw new NoSuchRowException(msg.toString());
273            }
274    
275            /**
276             * Returns the first expando row in the ordered set where tableId = &#63;.
277             *
278             * @param tableId the table ID
279             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
280             * @return the first matching expando row, or <code>null</code> if a matching expando row could not be found
281             */
282            @Override
283            public ExpandoRow fetchByTableId_First(long tableId,
284                    OrderByComparator<ExpandoRow> orderByComparator) {
285                    List<ExpandoRow> list = findByTableId(tableId, 0, 1, orderByComparator);
286    
287                    if (!list.isEmpty()) {
288                            return list.get(0);
289                    }
290    
291                    return null;
292            }
293    
294            /**
295             * Returns the last expando row in the ordered set where tableId = &#63;.
296             *
297             * @param tableId the table ID
298             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
299             * @return the last matching expando row
300             * @throws com.liferay.portlet.expando.NoSuchRowException if a matching expando row could not be found
301             */
302            @Override
303            public ExpandoRow findByTableId_Last(long tableId,
304                    OrderByComparator<ExpandoRow> orderByComparator)
305                    throws NoSuchRowException {
306                    ExpandoRow expandoRow = fetchByTableId_Last(tableId, orderByComparator);
307    
308                    if (expandoRow != null) {
309                            return expandoRow;
310                    }
311    
312                    StringBundler msg = new StringBundler(4);
313    
314                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
315    
316                    msg.append("tableId=");
317                    msg.append(tableId);
318    
319                    msg.append(StringPool.CLOSE_CURLY_BRACE);
320    
321                    throw new NoSuchRowException(msg.toString());
322            }
323    
324            /**
325             * Returns the last expando row in the ordered set where tableId = &#63;.
326             *
327             * @param tableId the table ID
328             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
329             * @return the last matching expando row, or <code>null</code> if a matching expando row could not be found
330             */
331            @Override
332            public ExpandoRow fetchByTableId_Last(long tableId,
333                    OrderByComparator<ExpandoRow> orderByComparator) {
334                    int count = countByTableId(tableId);
335    
336                    if (count == 0) {
337                            return null;
338                    }
339    
340                    List<ExpandoRow> list = findByTableId(tableId, count - 1, count,
341                                    orderByComparator);
342    
343                    if (!list.isEmpty()) {
344                            return list.get(0);
345                    }
346    
347                    return null;
348            }
349    
350            /**
351             * Returns the expando rows before and after the current expando row in the ordered set where tableId = &#63;.
352             *
353             * @param rowId the primary key of the current expando row
354             * @param tableId the table ID
355             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
356             * @return the previous, current, and next expando row
357             * @throws com.liferay.portlet.expando.NoSuchRowException if a expando row with the primary key could not be found
358             */
359            @Override
360            public ExpandoRow[] findByTableId_PrevAndNext(long rowId, long tableId,
361                    OrderByComparator<ExpandoRow> orderByComparator)
362                    throws NoSuchRowException {
363                    ExpandoRow expandoRow = findByPrimaryKey(rowId);
364    
365                    Session session = null;
366    
367                    try {
368                            session = openSession();
369    
370                            ExpandoRow[] array = new ExpandoRowImpl[3];
371    
372                            array[0] = getByTableId_PrevAndNext(session, expandoRow, tableId,
373                                            orderByComparator, true);
374    
375                            array[1] = expandoRow;
376    
377                            array[2] = getByTableId_PrevAndNext(session, expandoRow, tableId,
378                                            orderByComparator, false);
379    
380                            return array;
381                    }
382                    catch (Exception e) {
383                            throw processException(e);
384                    }
385                    finally {
386                            closeSession(session);
387                    }
388            }
389    
390            protected ExpandoRow getByTableId_PrevAndNext(Session session,
391                    ExpandoRow expandoRow, long tableId,
392                    OrderByComparator<ExpandoRow> orderByComparator, boolean previous) {
393                    StringBundler query = null;
394    
395                    if (orderByComparator != null) {
396                            query = new StringBundler(6 +
397                                            (orderByComparator.getOrderByFields().length * 6));
398                    }
399                    else {
400                            query = new StringBundler(3);
401                    }
402    
403                    query.append(_SQL_SELECT_EXPANDOROW_WHERE);
404    
405                    query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
406    
407                    if (orderByComparator != null) {
408                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
409    
410                            if (orderByConditionFields.length > 0) {
411                                    query.append(WHERE_AND);
412                            }
413    
414                            for (int i = 0; i < orderByConditionFields.length; i++) {
415                                    query.append(_ORDER_BY_ENTITY_ALIAS);
416                                    query.append(orderByConditionFields[i]);
417    
418                                    if ((i + 1) < orderByConditionFields.length) {
419                                            if (orderByComparator.isAscending() ^ previous) {
420                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
421                                            }
422                                            else {
423                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
424                                            }
425                                    }
426                                    else {
427                                            if (orderByComparator.isAscending() ^ previous) {
428                                                    query.append(WHERE_GREATER_THAN);
429                                            }
430                                            else {
431                                                    query.append(WHERE_LESSER_THAN);
432                                            }
433                                    }
434                            }
435    
436                            query.append(ORDER_BY_CLAUSE);
437    
438                            String[] orderByFields = orderByComparator.getOrderByFields();
439    
440                            for (int i = 0; i < orderByFields.length; i++) {
441                                    query.append(_ORDER_BY_ENTITY_ALIAS);
442                                    query.append(orderByFields[i]);
443    
444                                    if ((i + 1) < orderByFields.length) {
445                                            if (orderByComparator.isAscending() ^ previous) {
446                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
447                                            }
448                                            else {
449                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
450                                            }
451                                    }
452                                    else {
453                                            if (orderByComparator.isAscending() ^ previous) {
454                                                    query.append(ORDER_BY_ASC);
455                                            }
456                                            else {
457                                                    query.append(ORDER_BY_DESC);
458                                            }
459                                    }
460                            }
461                    }
462                    else {
463                            query.append(ExpandoRowModelImpl.ORDER_BY_JPQL);
464                    }
465    
466                    String sql = query.toString();
467    
468                    Query q = session.createQuery(sql);
469    
470                    q.setFirstResult(0);
471                    q.setMaxResults(2);
472    
473                    QueryPos qPos = QueryPos.getInstance(q);
474    
475                    qPos.add(tableId);
476    
477                    if (orderByComparator != null) {
478                            Object[] values = orderByComparator.getOrderByConditionValues(expandoRow);
479    
480                            for (Object value : values) {
481                                    qPos.add(value);
482                            }
483                    }
484    
485                    List<ExpandoRow> list = q.list();
486    
487                    if (list.size() == 2) {
488                            return list.get(1);
489                    }
490                    else {
491                            return null;
492                    }
493            }
494    
495            /**
496             * Removes all the expando rows where tableId = &#63; from the database.
497             *
498             * @param tableId the table ID
499             */
500            @Override
501            public void removeByTableId(long tableId) {
502                    for (ExpandoRow expandoRow : findByTableId(tableId, QueryUtil.ALL_POS,
503                                    QueryUtil.ALL_POS, null)) {
504                            remove(expandoRow);
505                    }
506            }
507    
508            /**
509             * Returns the number of expando rows where tableId = &#63;.
510             *
511             * @param tableId the table ID
512             * @return the number of matching expando rows
513             */
514            @Override
515            public int countByTableId(long tableId) {
516                    FinderPath finderPath = FINDER_PATH_COUNT_BY_TABLEID;
517    
518                    Object[] finderArgs = new Object[] { tableId };
519    
520                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
521                                    this);
522    
523                    if (count == null) {
524                            StringBundler query = new StringBundler(2);
525    
526                            query.append(_SQL_COUNT_EXPANDOROW_WHERE);
527    
528                            query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
529    
530                            String sql = query.toString();
531    
532                            Session session = null;
533    
534                            try {
535                                    session = openSession();
536    
537                                    Query q = session.createQuery(sql);
538    
539                                    QueryPos qPos = QueryPos.getInstance(q);
540    
541                                    qPos.add(tableId);
542    
543                                    count = (Long)q.uniqueResult();
544    
545                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
546                            }
547                            catch (Exception e) {
548                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
549    
550                                    throw processException(e);
551                            }
552                            finally {
553                                    closeSession(session);
554                            }
555                    }
556    
557                    return count.intValue();
558            }
559    
560            private static final String _FINDER_COLUMN_TABLEID_TABLEID_2 = "expandoRow.tableId = ?";
561            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSPK = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
562                            ExpandoRowModelImpl.FINDER_CACHE_ENABLED, ExpandoRowImpl.class,
563                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByClassPK",
564                            new String[] {
565                                    Long.class.getName(),
566                                    
567                            Integer.class.getName(), Integer.class.getName(),
568                                    OrderByComparator.class.getName()
569                            });
570            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSPK =
571                    new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
572                            ExpandoRowModelImpl.FINDER_CACHE_ENABLED, ExpandoRowImpl.class,
573                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByClassPK",
574                            new String[] { Long.class.getName() },
575                            ExpandoRowModelImpl.CLASSPK_COLUMN_BITMASK);
576            public static final FinderPath FINDER_PATH_COUNT_BY_CLASSPK = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
577                            ExpandoRowModelImpl.FINDER_CACHE_ENABLED, Long.class,
578                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByClassPK",
579                            new String[] { Long.class.getName() });
580    
581            /**
582             * Returns all the expando rows where classPK = &#63;.
583             *
584             * @param classPK the class p k
585             * @return the matching expando rows
586             */
587            @Override
588            public List<ExpandoRow> findByClassPK(long classPK) {
589                    return findByClassPK(classPK, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
590            }
591    
592            /**
593             * Returns a range of all the expando rows where classPK = &#63;.
594             *
595             * <p>
596             * 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.ExpandoRowModelImpl}. 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.
597             * </p>
598             *
599             * @param classPK the class p k
600             * @param start the lower bound of the range of expando rows
601             * @param end the upper bound of the range of expando rows (not inclusive)
602             * @return the range of matching expando rows
603             */
604            @Override
605            public List<ExpandoRow> findByClassPK(long classPK, int start, int end) {
606                    return findByClassPK(classPK, start, end, null);
607            }
608    
609            /**
610             * Returns an ordered range of all the expando rows where classPK = &#63;.
611             *
612             * <p>
613             * 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.ExpandoRowModelImpl}. 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.
614             * </p>
615             *
616             * @param classPK the class p k
617             * @param start the lower bound of the range of expando rows
618             * @param end the upper bound of the range of expando rows (not inclusive)
619             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
620             * @return the ordered range of matching expando rows
621             */
622            @Override
623            public List<ExpandoRow> findByClassPK(long classPK, int start, int end,
624                    OrderByComparator<ExpandoRow> orderByComparator) {
625                    boolean pagination = true;
626                    FinderPath finderPath = null;
627                    Object[] finderArgs = null;
628    
629                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
630                                    (orderByComparator == null)) {
631                            pagination = false;
632                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSPK;
633                            finderArgs = new Object[] { classPK };
634                    }
635                    else {
636                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSPK;
637                            finderArgs = new Object[] { classPK, start, end, orderByComparator };
638                    }
639    
640                    List<ExpandoRow> list = (List<ExpandoRow>)FinderCacheUtil.getResult(finderPath,
641                                    finderArgs, this);
642    
643                    if ((list != null) && !list.isEmpty()) {
644                            for (ExpandoRow expandoRow : list) {
645                                    if ((classPK != expandoRow.getClassPK())) {
646                                            list = null;
647    
648                                            break;
649                                    }
650                            }
651                    }
652    
653                    if (list == null) {
654                            StringBundler query = null;
655    
656                            if (orderByComparator != null) {
657                                    query = new StringBundler(3 +
658                                                    (orderByComparator.getOrderByFields().length * 3));
659                            }
660                            else {
661                                    query = new StringBundler(3);
662                            }
663    
664                            query.append(_SQL_SELECT_EXPANDOROW_WHERE);
665    
666                            query.append(_FINDER_COLUMN_CLASSPK_CLASSPK_2);
667    
668                            if (orderByComparator != null) {
669                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
670                                            orderByComparator);
671                            }
672                            else
673                             if (pagination) {
674                                    query.append(ExpandoRowModelImpl.ORDER_BY_JPQL);
675                            }
676    
677                            String sql = query.toString();
678    
679                            Session session = null;
680    
681                            try {
682                                    session = openSession();
683    
684                                    Query q = session.createQuery(sql);
685    
686                                    QueryPos qPos = QueryPos.getInstance(q);
687    
688                                    qPos.add(classPK);
689    
690                                    if (!pagination) {
691                                            list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(),
692                                                            start, end, false);
693    
694                                            Collections.sort(list);
695    
696                                            list = Collections.unmodifiableList(list);
697                                    }
698                                    else {
699                                            list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(),
700                                                            start, end);
701                                    }
702    
703                                    cacheResult(list);
704    
705                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
706                            }
707                            catch (Exception e) {
708                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
709    
710                                    throw processException(e);
711                            }
712                            finally {
713                                    closeSession(session);
714                            }
715                    }
716    
717                    return list;
718            }
719    
720            /**
721             * Returns the first expando row in the ordered set where classPK = &#63;.
722             *
723             * @param classPK the class p k
724             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
725             * @return the first matching expando row
726             * @throws com.liferay.portlet.expando.NoSuchRowException if a matching expando row could not be found
727             */
728            @Override
729            public ExpandoRow findByClassPK_First(long classPK,
730                    OrderByComparator<ExpandoRow> orderByComparator)
731                    throws NoSuchRowException {
732                    ExpandoRow expandoRow = fetchByClassPK_First(classPK, orderByComparator);
733    
734                    if (expandoRow != null) {
735                            return expandoRow;
736                    }
737    
738                    StringBundler msg = new StringBundler(4);
739    
740                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
741    
742                    msg.append("classPK=");
743                    msg.append(classPK);
744    
745                    msg.append(StringPool.CLOSE_CURLY_BRACE);
746    
747                    throw new NoSuchRowException(msg.toString());
748            }
749    
750            /**
751             * Returns the first expando row in the ordered set where classPK = &#63;.
752             *
753             * @param classPK the class p k
754             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
755             * @return the first matching expando row, or <code>null</code> if a matching expando row could not be found
756             */
757            @Override
758            public ExpandoRow fetchByClassPK_First(long classPK,
759                    OrderByComparator<ExpandoRow> orderByComparator) {
760                    List<ExpandoRow> list = findByClassPK(classPK, 0, 1, orderByComparator);
761    
762                    if (!list.isEmpty()) {
763                            return list.get(0);
764                    }
765    
766                    return null;
767            }
768    
769            /**
770             * Returns the last expando row in the ordered set where classPK = &#63;.
771             *
772             * @param classPK the class p k
773             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
774             * @return the last matching expando row
775             * @throws com.liferay.portlet.expando.NoSuchRowException if a matching expando row could not be found
776             */
777            @Override
778            public ExpandoRow findByClassPK_Last(long classPK,
779                    OrderByComparator<ExpandoRow> orderByComparator)
780                    throws NoSuchRowException {
781                    ExpandoRow expandoRow = fetchByClassPK_Last(classPK, orderByComparator);
782    
783                    if (expandoRow != null) {
784                            return expandoRow;
785                    }
786    
787                    StringBundler msg = new StringBundler(4);
788    
789                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
790    
791                    msg.append("classPK=");
792                    msg.append(classPK);
793    
794                    msg.append(StringPool.CLOSE_CURLY_BRACE);
795    
796                    throw new NoSuchRowException(msg.toString());
797            }
798    
799            /**
800             * Returns the last expando row in the ordered set where classPK = &#63;.
801             *
802             * @param classPK the class p k
803             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
804             * @return the last matching expando row, or <code>null</code> if a matching expando row could not be found
805             */
806            @Override
807            public ExpandoRow fetchByClassPK_Last(long classPK,
808                    OrderByComparator<ExpandoRow> orderByComparator) {
809                    int count = countByClassPK(classPK);
810    
811                    if (count == 0) {
812                            return null;
813                    }
814    
815                    List<ExpandoRow> list = findByClassPK(classPK, count - 1, count,
816                                    orderByComparator);
817    
818                    if (!list.isEmpty()) {
819                            return list.get(0);
820                    }
821    
822                    return null;
823            }
824    
825            /**
826             * Returns the expando rows before and after the current expando row in the ordered set where classPK = &#63;.
827             *
828             * @param rowId the primary key of the current expando row
829             * @param classPK the class p k
830             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
831             * @return the previous, current, and next expando row
832             * @throws com.liferay.portlet.expando.NoSuchRowException if a expando row with the primary key could not be found
833             */
834            @Override
835            public ExpandoRow[] findByClassPK_PrevAndNext(long rowId, long classPK,
836                    OrderByComparator<ExpandoRow> orderByComparator)
837                    throws NoSuchRowException {
838                    ExpandoRow expandoRow = findByPrimaryKey(rowId);
839    
840                    Session session = null;
841    
842                    try {
843                            session = openSession();
844    
845                            ExpandoRow[] array = new ExpandoRowImpl[3];
846    
847                            array[0] = getByClassPK_PrevAndNext(session, expandoRow, classPK,
848                                            orderByComparator, true);
849    
850                            array[1] = expandoRow;
851    
852                            array[2] = getByClassPK_PrevAndNext(session, expandoRow, classPK,
853                                            orderByComparator, false);
854    
855                            return array;
856                    }
857                    catch (Exception e) {
858                            throw processException(e);
859                    }
860                    finally {
861                            closeSession(session);
862                    }
863            }
864    
865            protected ExpandoRow getByClassPK_PrevAndNext(Session session,
866                    ExpandoRow expandoRow, long classPK,
867                    OrderByComparator<ExpandoRow> orderByComparator, boolean previous) {
868                    StringBundler query = null;
869    
870                    if (orderByComparator != null) {
871                            query = new StringBundler(6 +
872                                            (orderByComparator.getOrderByFields().length * 6));
873                    }
874                    else {
875                            query = new StringBundler(3);
876                    }
877    
878                    query.append(_SQL_SELECT_EXPANDOROW_WHERE);
879    
880                    query.append(_FINDER_COLUMN_CLASSPK_CLASSPK_2);
881    
882                    if (orderByComparator != null) {
883                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
884    
885                            if (orderByConditionFields.length > 0) {
886                                    query.append(WHERE_AND);
887                            }
888    
889                            for (int i = 0; i < orderByConditionFields.length; i++) {
890                                    query.append(_ORDER_BY_ENTITY_ALIAS);
891                                    query.append(orderByConditionFields[i]);
892    
893                                    if ((i + 1) < orderByConditionFields.length) {
894                                            if (orderByComparator.isAscending() ^ previous) {
895                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
896                                            }
897                                            else {
898                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
899                                            }
900                                    }
901                                    else {
902                                            if (orderByComparator.isAscending() ^ previous) {
903                                                    query.append(WHERE_GREATER_THAN);
904                                            }
905                                            else {
906                                                    query.append(WHERE_LESSER_THAN);
907                                            }
908                                    }
909                            }
910    
911                            query.append(ORDER_BY_CLAUSE);
912    
913                            String[] orderByFields = orderByComparator.getOrderByFields();
914    
915                            for (int i = 0; i < orderByFields.length; i++) {
916                                    query.append(_ORDER_BY_ENTITY_ALIAS);
917                                    query.append(orderByFields[i]);
918    
919                                    if ((i + 1) < orderByFields.length) {
920                                            if (orderByComparator.isAscending() ^ previous) {
921                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
922                                            }
923                                            else {
924                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
925                                            }
926                                    }
927                                    else {
928                                            if (orderByComparator.isAscending() ^ previous) {
929                                                    query.append(ORDER_BY_ASC);
930                                            }
931                                            else {
932                                                    query.append(ORDER_BY_DESC);
933                                            }
934                                    }
935                            }
936                    }
937                    else {
938                            query.append(ExpandoRowModelImpl.ORDER_BY_JPQL);
939                    }
940    
941                    String sql = query.toString();
942    
943                    Query q = session.createQuery(sql);
944    
945                    q.setFirstResult(0);
946                    q.setMaxResults(2);
947    
948                    QueryPos qPos = QueryPos.getInstance(q);
949    
950                    qPos.add(classPK);
951    
952                    if (orderByComparator != null) {
953                            Object[] values = orderByComparator.getOrderByConditionValues(expandoRow);
954    
955                            for (Object value : values) {
956                                    qPos.add(value);
957                            }
958                    }
959    
960                    List<ExpandoRow> list = q.list();
961    
962                    if (list.size() == 2) {
963                            return list.get(1);
964                    }
965                    else {
966                            return null;
967                    }
968            }
969    
970            /**
971             * Removes all the expando rows where classPK = &#63; from the database.
972             *
973             * @param classPK the class p k
974             */
975            @Override
976            public void removeByClassPK(long classPK) {
977                    for (ExpandoRow expandoRow : findByClassPK(classPK, QueryUtil.ALL_POS,
978                                    QueryUtil.ALL_POS, null)) {
979                            remove(expandoRow);
980                    }
981            }
982    
983            /**
984             * Returns the number of expando rows where classPK = &#63;.
985             *
986             * @param classPK the class p k
987             * @return the number of matching expando rows
988             */
989            @Override
990            public int countByClassPK(long classPK) {
991                    FinderPath finderPath = FINDER_PATH_COUNT_BY_CLASSPK;
992    
993                    Object[] finderArgs = new Object[] { classPK };
994    
995                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
996                                    this);
997    
998                    if (count == null) {
999                            StringBundler query = new StringBundler(2);
1000    
1001                            query.append(_SQL_COUNT_EXPANDOROW_WHERE);
1002    
1003                            query.append(_FINDER_COLUMN_CLASSPK_CLASSPK_2);
1004    
1005                            String sql = query.toString();
1006    
1007                            Session session = null;
1008    
1009                            try {
1010                                    session = openSession();
1011    
1012                                    Query q = session.createQuery(sql);
1013    
1014                                    QueryPos qPos = QueryPos.getInstance(q);
1015    
1016                                    qPos.add(classPK);
1017    
1018                                    count = (Long)q.uniqueResult();
1019    
1020                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1021                            }
1022                            catch (Exception e) {
1023                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1024    
1025                                    throw processException(e);
1026                            }
1027                            finally {
1028                                    closeSession(session);
1029                            }
1030                    }
1031    
1032                    return count.intValue();
1033            }
1034    
1035            private static final String _FINDER_COLUMN_CLASSPK_CLASSPK_2 = "expandoRow.classPK = ?";
1036            public static final FinderPath FINDER_PATH_FETCH_BY_T_C = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1037                            ExpandoRowModelImpl.FINDER_CACHE_ENABLED, ExpandoRowImpl.class,
1038                            FINDER_CLASS_NAME_ENTITY, "fetchByT_C",
1039                            new String[] { Long.class.getName(), Long.class.getName() },
1040                            ExpandoRowModelImpl.TABLEID_COLUMN_BITMASK |
1041                            ExpandoRowModelImpl.CLASSPK_COLUMN_BITMASK);
1042            public static final FinderPath FINDER_PATH_COUNT_BY_T_C = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1043                            ExpandoRowModelImpl.FINDER_CACHE_ENABLED, Long.class,
1044                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_C",
1045                            new String[] { Long.class.getName(), Long.class.getName() });
1046    
1047            /**
1048             * Returns the expando row where tableId = &#63; and classPK = &#63; or throws a {@link com.liferay.portlet.expando.NoSuchRowException} if it could not be found.
1049             *
1050             * @param tableId the table ID
1051             * @param classPK the class p k
1052             * @return the matching expando row
1053             * @throws com.liferay.portlet.expando.NoSuchRowException if a matching expando row could not be found
1054             */
1055            @Override
1056            public ExpandoRow findByT_C(long tableId, long classPK)
1057                    throws NoSuchRowException {
1058                    ExpandoRow expandoRow = fetchByT_C(tableId, classPK);
1059    
1060                    if (expandoRow == null) {
1061                            StringBundler msg = new StringBundler(6);
1062    
1063                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1064    
1065                            msg.append("tableId=");
1066                            msg.append(tableId);
1067    
1068                            msg.append(", classPK=");
1069                            msg.append(classPK);
1070    
1071                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1072    
1073                            if (_log.isWarnEnabled()) {
1074                                    _log.warn(msg.toString());
1075                            }
1076    
1077                            throw new NoSuchRowException(msg.toString());
1078                    }
1079    
1080                    return expandoRow;
1081            }
1082    
1083            /**
1084             * Returns the expando row where tableId = &#63; and classPK = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1085             *
1086             * @param tableId the table ID
1087             * @param classPK the class p k
1088             * @return the matching expando row, or <code>null</code> if a matching expando row could not be found
1089             */
1090            @Override
1091            public ExpandoRow fetchByT_C(long tableId, long classPK) {
1092                    return fetchByT_C(tableId, classPK, true);
1093            }
1094    
1095            /**
1096             * Returns the expando row where tableId = &#63; and classPK = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1097             *
1098             * @param tableId the table ID
1099             * @param classPK the class p k
1100             * @param retrieveFromCache whether to use the finder cache
1101             * @return the matching expando row, or <code>null</code> if a matching expando row could not be found
1102             */
1103            @Override
1104            public ExpandoRow fetchByT_C(long tableId, long classPK,
1105                    boolean retrieveFromCache) {
1106                    Object[] finderArgs = new Object[] { tableId, classPK };
1107    
1108                    Object result = null;
1109    
1110                    if (retrieveFromCache) {
1111                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_T_C,
1112                                            finderArgs, this);
1113                    }
1114    
1115                    if (result instanceof ExpandoRow) {
1116                            ExpandoRow expandoRow = (ExpandoRow)result;
1117    
1118                            if ((tableId != expandoRow.getTableId()) ||
1119                                            (classPK != expandoRow.getClassPK())) {
1120                                    result = null;
1121                            }
1122                    }
1123    
1124                    if (result == null) {
1125                            StringBundler query = new StringBundler(4);
1126    
1127                            query.append(_SQL_SELECT_EXPANDOROW_WHERE);
1128    
1129                            query.append(_FINDER_COLUMN_T_C_TABLEID_2);
1130    
1131                            query.append(_FINDER_COLUMN_T_C_CLASSPK_2);
1132    
1133                            String sql = query.toString();
1134    
1135                            Session session = null;
1136    
1137                            try {
1138                                    session = openSession();
1139    
1140                                    Query q = session.createQuery(sql);
1141    
1142                                    QueryPos qPos = QueryPos.getInstance(q);
1143    
1144                                    qPos.add(tableId);
1145    
1146                                    qPos.add(classPK);
1147    
1148                                    List<ExpandoRow> list = q.list();
1149    
1150                                    if (list.isEmpty()) {
1151                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
1152                                                    finderArgs, list);
1153                                    }
1154                                    else {
1155                                            ExpandoRow expandoRow = list.get(0);
1156    
1157                                            result = expandoRow;
1158    
1159                                            cacheResult(expandoRow);
1160    
1161                                            if ((expandoRow.getTableId() != tableId) ||
1162                                                            (expandoRow.getClassPK() != classPK)) {
1163                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
1164                                                            finderArgs, expandoRow);
1165                                            }
1166                                    }
1167                            }
1168                            catch (Exception e) {
1169                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C,
1170                                            finderArgs);
1171    
1172                                    throw processException(e);
1173                            }
1174                            finally {
1175                                    closeSession(session);
1176                            }
1177                    }
1178    
1179                    if (result instanceof List<?>) {
1180                            return null;
1181                    }
1182                    else {
1183                            return (ExpandoRow)result;
1184                    }
1185            }
1186    
1187            /**
1188             * Removes the expando row where tableId = &#63; and classPK = &#63; from the database.
1189             *
1190             * @param tableId the table ID
1191             * @param classPK the class p k
1192             * @return the expando row that was removed
1193             */
1194            @Override
1195            public ExpandoRow removeByT_C(long tableId, long classPK)
1196                    throws NoSuchRowException {
1197                    ExpandoRow expandoRow = findByT_C(tableId, classPK);
1198    
1199                    return remove(expandoRow);
1200            }
1201    
1202            /**
1203             * Returns the number of expando rows where tableId = &#63; and classPK = &#63;.
1204             *
1205             * @param tableId the table ID
1206             * @param classPK the class p k
1207             * @return the number of matching expando rows
1208             */
1209            @Override
1210            public int countByT_C(long tableId, long classPK) {
1211                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_C;
1212    
1213                    Object[] finderArgs = new Object[] { tableId, classPK };
1214    
1215                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1216                                    this);
1217    
1218                    if (count == null) {
1219                            StringBundler query = new StringBundler(3);
1220    
1221                            query.append(_SQL_COUNT_EXPANDOROW_WHERE);
1222    
1223                            query.append(_FINDER_COLUMN_T_C_TABLEID_2);
1224    
1225                            query.append(_FINDER_COLUMN_T_C_CLASSPK_2);
1226    
1227                            String sql = query.toString();
1228    
1229                            Session session = null;
1230    
1231                            try {
1232                                    session = openSession();
1233    
1234                                    Query q = session.createQuery(sql);
1235    
1236                                    QueryPos qPos = QueryPos.getInstance(q);
1237    
1238                                    qPos.add(tableId);
1239    
1240                                    qPos.add(classPK);
1241    
1242                                    count = (Long)q.uniqueResult();
1243    
1244                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1245                            }
1246                            catch (Exception e) {
1247                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1248    
1249                                    throw processException(e);
1250                            }
1251                            finally {
1252                                    closeSession(session);
1253                            }
1254                    }
1255    
1256                    return count.intValue();
1257            }
1258    
1259            private static final String _FINDER_COLUMN_T_C_TABLEID_2 = "expandoRow.tableId = ? AND ";
1260            private static final String _FINDER_COLUMN_T_C_CLASSPK_2 = "expandoRow.classPK = ?";
1261    
1262            public ExpandoRowPersistenceImpl() {
1263                    setModelClass(ExpandoRow.class);
1264            }
1265    
1266            /**
1267             * Caches the expando row in the entity cache if it is enabled.
1268             *
1269             * @param expandoRow the expando row
1270             */
1271            @Override
1272            public void cacheResult(ExpandoRow expandoRow) {
1273                    EntityCacheUtil.putResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1274                            ExpandoRowImpl.class, expandoRow.getPrimaryKey(), expandoRow);
1275    
1276                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
1277                            new Object[] { expandoRow.getTableId(), expandoRow.getClassPK() },
1278                            expandoRow);
1279    
1280                    expandoRow.resetOriginalValues();
1281            }
1282    
1283            /**
1284             * Caches the expando rows in the entity cache if it is enabled.
1285             *
1286             * @param expandoRows the expando rows
1287             */
1288            @Override
1289            public void cacheResult(List<ExpandoRow> expandoRows) {
1290                    for (ExpandoRow expandoRow : expandoRows) {
1291                            if (EntityCacheUtil.getResult(
1292                                                    ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1293                                                    ExpandoRowImpl.class, expandoRow.getPrimaryKey()) == null) {
1294                                    cacheResult(expandoRow);
1295                            }
1296                            else {
1297                                    expandoRow.resetOriginalValues();
1298                            }
1299                    }
1300            }
1301    
1302            /**
1303             * Clears the cache for all expando rows.
1304             *
1305             * <p>
1306             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1307             * </p>
1308             */
1309            @Override
1310            public void clearCache() {
1311                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1312                            CacheRegistryUtil.clear(ExpandoRowImpl.class.getName());
1313                    }
1314    
1315                    EntityCacheUtil.clearCache(ExpandoRowImpl.class);
1316    
1317                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1318                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1319                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1320            }
1321    
1322            /**
1323             * Clears the cache for the expando row.
1324             *
1325             * <p>
1326             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1327             * </p>
1328             */
1329            @Override
1330            public void clearCache(ExpandoRow expandoRow) {
1331                    EntityCacheUtil.removeResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1332                            ExpandoRowImpl.class, expandoRow.getPrimaryKey());
1333    
1334                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1335                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1336    
1337                    clearUniqueFindersCache(expandoRow);
1338            }
1339    
1340            @Override
1341            public void clearCache(List<ExpandoRow> expandoRows) {
1342                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1343                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1344    
1345                    for (ExpandoRow expandoRow : expandoRows) {
1346                            EntityCacheUtil.removeResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1347                                    ExpandoRowImpl.class, expandoRow.getPrimaryKey());
1348    
1349                            clearUniqueFindersCache(expandoRow);
1350                    }
1351            }
1352    
1353            protected void cacheUniqueFindersCache(ExpandoRow expandoRow) {
1354                    if (expandoRow.isNew()) {
1355                            Object[] args = new Object[] {
1356                                            expandoRow.getTableId(), expandoRow.getClassPK()
1357                                    };
1358    
1359                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_C, args,
1360                                    Long.valueOf(1));
1361                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C, args, expandoRow);
1362                    }
1363                    else {
1364                            ExpandoRowModelImpl expandoRowModelImpl = (ExpandoRowModelImpl)expandoRow;
1365    
1366                            if ((expandoRowModelImpl.getColumnBitmask() &
1367                                            FINDER_PATH_FETCH_BY_T_C.getColumnBitmask()) != 0) {
1368                                    Object[] args = new Object[] {
1369                                                    expandoRow.getTableId(), expandoRow.getClassPK()
1370                                            };
1371    
1372                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_C, args,
1373                                            Long.valueOf(1));
1374                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C, args,
1375                                            expandoRow);
1376                            }
1377                    }
1378            }
1379    
1380            protected void clearUniqueFindersCache(ExpandoRow expandoRow) {
1381                    ExpandoRowModelImpl expandoRowModelImpl = (ExpandoRowModelImpl)expandoRow;
1382    
1383                    Object[] args = new Object[] {
1384                                    expandoRow.getTableId(), expandoRow.getClassPK()
1385                            };
1386    
1387                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_C, args);
1388                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C, args);
1389    
1390                    if ((expandoRowModelImpl.getColumnBitmask() &
1391                                    FINDER_PATH_FETCH_BY_T_C.getColumnBitmask()) != 0) {
1392                            args = new Object[] {
1393                                            expandoRowModelImpl.getOriginalTableId(),
1394                                            expandoRowModelImpl.getOriginalClassPK()
1395                                    };
1396    
1397                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_C, args);
1398                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C, args);
1399                    }
1400            }
1401    
1402            /**
1403             * Creates a new expando row with the primary key. Does not add the expando row to the database.
1404             *
1405             * @param rowId the primary key for the new expando row
1406             * @return the new expando row
1407             */
1408            @Override
1409            public ExpandoRow create(long rowId) {
1410                    ExpandoRow expandoRow = new ExpandoRowImpl();
1411    
1412                    expandoRow.setNew(true);
1413                    expandoRow.setPrimaryKey(rowId);
1414    
1415                    return expandoRow;
1416            }
1417    
1418            /**
1419             * Removes the expando row with the primary key from the database. Also notifies the appropriate model listeners.
1420             *
1421             * @param rowId the primary key of the expando row
1422             * @return the expando row that was removed
1423             * @throws com.liferay.portlet.expando.NoSuchRowException if a expando row with the primary key could not be found
1424             */
1425            @Override
1426            public ExpandoRow remove(long rowId) throws NoSuchRowException {
1427                    return remove((Serializable)rowId);
1428            }
1429    
1430            /**
1431             * Removes the expando row with the primary key from the database. Also notifies the appropriate model listeners.
1432             *
1433             * @param primaryKey the primary key of the expando row
1434             * @return the expando row that was removed
1435             * @throws com.liferay.portlet.expando.NoSuchRowException if a expando row with the primary key could not be found
1436             */
1437            @Override
1438            public ExpandoRow remove(Serializable primaryKey) throws NoSuchRowException {
1439                    Session session = null;
1440    
1441                    try {
1442                            session = openSession();
1443    
1444                            ExpandoRow expandoRow = (ExpandoRow)session.get(ExpandoRowImpl.class,
1445                                            primaryKey);
1446    
1447                            if (expandoRow == null) {
1448                                    if (_log.isWarnEnabled()) {
1449                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1450                                    }
1451    
1452                                    throw new NoSuchRowException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1453                                            primaryKey);
1454                            }
1455    
1456                            return remove(expandoRow);
1457                    }
1458                    catch (NoSuchRowException nsee) {
1459                            throw nsee;
1460                    }
1461                    catch (Exception e) {
1462                            throw processException(e);
1463                    }
1464                    finally {
1465                            closeSession(session);
1466                    }
1467            }
1468    
1469            @Override
1470            protected ExpandoRow removeImpl(ExpandoRow expandoRow) {
1471                    expandoRow = toUnwrappedModel(expandoRow);
1472    
1473                    Session session = null;
1474    
1475                    try {
1476                            session = openSession();
1477    
1478                            if (!session.contains(expandoRow)) {
1479                                    expandoRow = (ExpandoRow)session.get(ExpandoRowImpl.class,
1480                                                    expandoRow.getPrimaryKeyObj());
1481                            }
1482    
1483                            if (expandoRow != null) {
1484                                    session.delete(expandoRow);
1485                            }
1486                    }
1487                    catch (Exception e) {
1488                            throw processException(e);
1489                    }
1490                    finally {
1491                            closeSession(session);
1492                    }
1493    
1494                    if (expandoRow != null) {
1495                            clearCache(expandoRow);
1496                    }
1497    
1498                    return expandoRow;
1499            }
1500    
1501            @Override
1502            public ExpandoRow updateImpl(
1503                    com.liferay.portlet.expando.model.ExpandoRow expandoRow) {
1504                    expandoRow = toUnwrappedModel(expandoRow);
1505    
1506                    boolean isNew = expandoRow.isNew();
1507    
1508                    ExpandoRowModelImpl expandoRowModelImpl = (ExpandoRowModelImpl)expandoRow;
1509    
1510                    Session session = null;
1511    
1512                    try {
1513                            session = openSession();
1514    
1515                            if (expandoRow.isNew()) {
1516                                    session.save(expandoRow);
1517    
1518                                    expandoRow.setNew(false);
1519                            }
1520                            else {
1521                                    session.merge(expandoRow);
1522                            }
1523                    }
1524                    catch (Exception e) {
1525                            throw processException(e);
1526                    }
1527                    finally {
1528                            closeSession(session);
1529                    }
1530    
1531                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1532    
1533                    if (isNew || !ExpandoRowModelImpl.COLUMN_BITMASK_ENABLED) {
1534                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1535                    }
1536    
1537                    else {
1538                            if ((expandoRowModelImpl.getColumnBitmask() &
1539                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID.getColumnBitmask()) != 0) {
1540                                    Object[] args = new Object[] {
1541                                                    expandoRowModelImpl.getOriginalTableId()
1542                                            };
1543    
1544                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
1545                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
1546                                            args);
1547    
1548                                    args = new Object[] { expandoRowModelImpl.getTableId() };
1549    
1550                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
1551                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
1552                                            args);
1553                            }
1554    
1555                            if ((expandoRowModelImpl.getColumnBitmask() &
1556                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSPK.getColumnBitmask()) != 0) {
1557                                    Object[] args = new Object[] {
1558                                                    expandoRowModelImpl.getOriginalClassPK()
1559                                            };
1560    
1561                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSPK, args);
1562                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSPK,
1563                                            args);
1564    
1565                                    args = new Object[] { expandoRowModelImpl.getClassPK() };
1566    
1567                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSPK, args);
1568                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSPK,
1569                                            args);
1570                            }
1571                    }
1572    
1573                    EntityCacheUtil.putResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1574                            ExpandoRowImpl.class, expandoRow.getPrimaryKey(), expandoRow, false);
1575    
1576                    clearUniqueFindersCache(expandoRow);
1577                    cacheUniqueFindersCache(expandoRow);
1578    
1579                    expandoRow.resetOriginalValues();
1580    
1581                    return expandoRow;
1582            }
1583    
1584            protected ExpandoRow toUnwrappedModel(ExpandoRow expandoRow) {
1585                    if (expandoRow instanceof ExpandoRowImpl) {
1586                            return expandoRow;
1587                    }
1588    
1589                    ExpandoRowImpl expandoRowImpl = new ExpandoRowImpl();
1590    
1591                    expandoRowImpl.setNew(expandoRow.isNew());
1592                    expandoRowImpl.setPrimaryKey(expandoRow.getPrimaryKey());
1593    
1594                    expandoRowImpl.setRowId(expandoRow.getRowId());
1595                    expandoRowImpl.setCompanyId(expandoRow.getCompanyId());
1596                    expandoRowImpl.setModifiedDate(expandoRow.getModifiedDate());
1597                    expandoRowImpl.setTableId(expandoRow.getTableId());
1598                    expandoRowImpl.setClassPK(expandoRow.getClassPK());
1599    
1600                    return expandoRowImpl;
1601            }
1602    
1603            /**
1604             * Returns the expando row with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1605             *
1606             * @param primaryKey the primary key of the expando row
1607             * @return the expando row
1608             * @throws com.liferay.portlet.expando.NoSuchRowException if a expando row with the primary key could not be found
1609             */
1610            @Override
1611            public ExpandoRow findByPrimaryKey(Serializable primaryKey)
1612                    throws NoSuchRowException {
1613                    ExpandoRow expandoRow = fetchByPrimaryKey(primaryKey);
1614    
1615                    if (expandoRow == null) {
1616                            if (_log.isWarnEnabled()) {
1617                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1618                            }
1619    
1620                            throw new NoSuchRowException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1621                                    primaryKey);
1622                    }
1623    
1624                    return expandoRow;
1625            }
1626    
1627            /**
1628             * Returns the expando row with the primary key or throws a {@link com.liferay.portlet.expando.NoSuchRowException} if it could not be found.
1629             *
1630             * @param rowId the primary key of the expando row
1631             * @return the expando row
1632             * @throws com.liferay.portlet.expando.NoSuchRowException if a expando row with the primary key could not be found
1633             */
1634            @Override
1635            public ExpandoRow findByPrimaryKey(long rowId) throws NoSuchRowException {
1636                    return findByPrimaryKey((Serializable)rowId);
1637            }
1638    
1639            /**
1640             * Returns the expando row with the primary key or returns <code>null</code> if it could not be found.
1641             *
1642             * @param primaryKey the primary key of the expando row
1643             * @return the expando row, or <code>null</code> if a expando row with the primary key could not be found
1644             */
1645            @Override
1646            public ExpandoRow fetchByPrimaryKey(Serializable primaryKey) {
1647                    ExpandoRow expandoRow = (ExpandoRow)EntityCacheUtil.getResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1648                                    ExpandoRowImpl.class, primaryKey);
1649    
1650                    if (expandoRow == _nullExpandoRow) {
1651                            return null;
1652                    }
1653    
1654                    if (expandoRow == null) {
1655                            Session session = null;
1656    
1657                            try {
1658                                    session = openSession();
1659    
1660                                    expandoRow = (ExpandoRow)session.get(ExpandoRowImpl.class,
1661                                                    primaryKey);
1662    
1663                                    if (expandoRow != null) {
1664                                            cacheResult(expandoRow);
1665                                    }
1666                                    else {
1667                                            EntityCacheUtil.putResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1668                                                    ExpandoRowImpl.class, primaryKey, _nullExpandoRow);
1669                                    }
1670                            }
1671                            catch (Exception e) {
1672                                    EntityCacheUtil.removeResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1673                                            ExpandoRowImpl.class, primaryKey);
1674    
1675                                    throw processException(e);
1676                            }
1677                            finally {
1678                                    closeSession(session);
1679                            }
1680                    }
1681    
1682                    return expandoRow;
1683            }
1684    
1685            /**
1686             * Returns the expando row with the primary key or returns <code>null</code> if it could not be found.
1687             *
1688             * @param rowId the primary key of the expando row
1689             * @return the expando row, or <code>null</code> if a expando row with the primary key could not be found
1690             */
1691            @Override
1692            public ExpandoRow fetchByPrimaryKey(long rowId) {
1693                    return fetchByPrimaryKey((Serializable)rowId);
1694            }
1695    
1696            @Override
1697            public Map<Serializable, ExpandoRow> fetchByPrimaryKeys(
1698                    Set<Serializable> primaryKeys) {
1699                    if (primaryKeys.isEmpty()) {
1700                            return Collections.emptyMap();
1701                    }
1702    
1703                    Map<Serializable, ExpandoRow> map = new HashMap<Serializable, ExpandoRow>();
1704    
1705                    if (primaryKeys.size() == 1) {
1706                            Iterator<Serializable> iterator = primaryKeys.iterator();
1707    
1708                            Serializable primaryKey = iterator.next();
1709    
1710                            ExpandoRow expandoRow = fetchByPrimaryKey(primaryKey);
1711    
1712                            if (expandoRow != null) {
1713                                    map.put(primaryKey, expandoRow);
1714                            }
1715    
1716                            return map;
1717                    }
1718    
1719                    Set<Serializable> uncachedPrimaryKeys = null;
1720    
1721                    for (Serializable primaryKey : primaryKeys) {
1722                            ExpandoRow expandoRow = (ExpandoRow)EntityCacheUtil.getResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1723                                            ExpandoRowImpl.class, primaryKey);
1724    
1725                            if (expandoRow == null) {
1726                                    if (uncachedPrimaryKeys == null) {
1727                                            uncachedPrimaryKeys = new HashSet<Serializable>();
1728                                    }
1729    
1730                                    uncachedPrimaryKeys.add(primaryKey);
1731                            }
1732                            else {
1733                                    map.put(primaryKey, expandoRow);
1734                            }
1735                    }
1736    
1737                    if (uncachedPrimaryKeys == null) {
1738                            return map;
1739                    }
1740    
1741                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1742                                    1);
1743    
1744                    query.append(_SQL_SELECT_EXPANDOROW_WHERE_PKS_IN);
1745    
1746                    for (Serializable primaryKey : uncachedPrimaryKeys) {
1747                            query.append(String.valueOf(primaryKey));
1748    
1749                            query.append(StringPool.COMMA);
1750                    }
1751    
1752                    query.setIndex(query.index() - 1);
1753    
1754                    query.append(StringPool.CLOSE_PARENTHESIS);
1755    
1756                    String sql = query.toString();
1757    
1758                    Session session = null;
1759    
1760                    try {
1761                            session = openSession();
1762    
1763                            Query q = session.createQuery(sql);
1764    
1765                            for (ExpandoRow expandoRow : (List<ExpandoRow>)q.list()) {
1766                                    map.put(expandoRow.getPrimaryKeyObj(), expandoRow);
1767    
1768                                    cacheResult(expandoRow);
1769    
1770                                    uncachedPrimaryKeys.remove(expandoRow.getPrimaryKeyObj());
1771                            }
1772    
1773                            for (Serializable primaryKey : uncachedPrimaryKeys) {
1774                                    EntityCacheUtil.putResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
1775                                            ExpandoRowImpl.class, primaryKey, _nullExpandoRow);
1776                            }
1777                    }
1778                    catch (Exception e) {
1779                            throw processException(e);
1780                    }
1781                    finally {
1782                            closeSession(session);
1783                    }
1784    
1785                    return map;
1786            }
1787    
1788            /**
1789             * Returns all the expando rows.
1790             *
1791             * @return the expando rows
1792             */
1793            @Override
1794            public List<ExpandoRow> findAll() {
1795                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1796            }
1797    
1798            /**
1799             * Returns a range of all the expando rows.
1800             *
1801             * <p>
1802             * 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.ExpandoRowModelImpl}. 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.
1803             * </p>
1804             *
1805             * @param start the lower bound of the range of expando rows
1806             * @param end the upper bound of the range of expando rows (not inclusive)
1807             * @return the range of expando rows
1808             */
1809            @Override
1810            public List<ExpandoRow> findAll(int start, int end) {
1811                    return findAll(start, end, null);
1812            }
1813    
1814            /**
1815             * Returns an ordered range of all the expando rows.
1816             *
1817             * <p>
1818             * 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.ExpandoRowModelImpl}. 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.
1819             * </p>
1820             *
1821             * @param start the lower bound of the range of expando rows
1822             * @param end the upper bound of the range of expando rows (not inclusive)
1823             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1824             * @return the ordered range of expando rows
1825             */
1826            @Override
1827            public List<ExpandoRow> findAll(int start, int end,
1828                    OrderByComparator<ExpandoRow> orderByComparator) {
1829                    boolean pagination = true;
1830                    FinderPath finderPath = null;
1831                    Object[] finderArgs = null;
1832    
1833                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1834                                    (orderByComparator == null)) {
1835                            pagination = false;
1836                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1837                            finderArgs = FINDER_ARGS_EMPTY;
1838                    }
1839                    else {
1840                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1841                            finderArgs = new Object[] { start, end, orderByComparator };
1842                    }
1843    
1844                    List<ExpandoRow> list = (List<ExpandoRow>)FinderCacheUtil.getResult(finderPath,
1845                                    finderArgs, this);
1846    
1847                    if (list == null) {
1848                            StringBundler query = null;
1849                            String sql = null;
1850    
1851                            if (orderByComparator != null) {
1852                                    query = new StringBundler(2 +
1853                                                    (orderByComparator.getOrderByFields().length * 3));
1854    
1855                                    query.append(_SQL_SELECT_EXPANDOROW);
1856    
1857                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1858                                            orderByComparator);
1859    
1860                                    sql = query.toString();
1861                            }
1862                            else {
1863                                    sql = _SQL_SELECT_EXPANDOROW;
1864    
1865                                    if (pagination) {
1866                                            sql = sql.concat(ExpandoRowModelImpl.ORDER_BY_JPQL);
1867                                    }
1868                            }
1869    
1870                            Session session = null;
1871    
1872                            try {
1873                                    session = openSession();
1874    
1875                                    Query q = session.createQuery(sql);
1876    
1877                                    if (!pagination) {
1878                                            list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(),
1879                                                            start, end, false);
1880    
1881                                            Collections.sort(list);
1882    
1883                                            list = Collections.unmodifiableList(list);
1884                                    }
1885                                    else {
1886                                            list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(),
1887                                                            start, end);
1888                                    }
1889    
1890                                    cacheResult(list);
1891    
1892                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1893                            }
1894                            catch (Exception e) {
1895                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1896    
1897                                    throw processException(e);
1898                            }
1899                            finally {
1900                                    closeSession(session);
1901                            }
1902                    }
1903    
1904                    return list;
1905            }
1906    
1907            /**
1908             * Removes all the expando rows from the database.
1909             *
1910             */
1911            @Override
1912            public void removeAll() {
1913                    for (ExpandoRow expandoRow : findAll()) {
1914                            remove(expandoRow);
1915                    }
1916            }
1917    
1918            /**
1919             * Returns the number of expando rows.
1920             *
1921             * @return the number of expando rows
1922             */
1923            @Override
1924            public int countAll() {
1925                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1926                                    FINDER_ARGS_EMPTY, this);
1927    
1928                    if (count == null) {
1929                            Session session = null;
1930    
1931                            try {
1932                                    session = openSession();
1933    
1934                                    Query q = session.createQuery(_SQL_COUNT_EXPANDOROW);
1935    
1936                                    count = (Long)q.uniqueResult();
1937    
1938                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1939                                            FINDER_ARGS_EMPTY, count);
1940                            }
1941                            catch (Exception e) {
1942                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1943                                            FINDER_ARGS_EMPTY);
1944    
1945                                    throw processException(e);
1946                            }
1947                            finally {
1948                                    closeSession(session);
1949                            }
1950                    }
1951    
1952                    return count.intValue();
1953            }
1954    
1955            @Override
1956            protected Set<String> getBadColumnNames() {
1957                    return _badColumnNames;
1958            }
1959    
1960            /**
1961             * Initializes the expando row persistence.
1962             */
1963            public void afterPropertiesSet() {
1964            }
1965    
1966            public void destroy() {
1967                    EntityCacheUtil.removeCache(ExpandoRowImpl.class.getName());
1968                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1969                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1970                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1971            }
1972    
1973            private static final String _SQL_SELECT_EXPANDOROW = "SELECT expandoRow FROM ExpandoRow expandoRow";
1974            private static final String _SQL_SELECT_EXPANDOROW_WHERE_PKS_IN = "SELECT expandoRow FROM ExpandoRow expandoRow WHERE rowId_ IN (";
1975            private static final String _SQL_SELECT_EXPANDOROW_WHERE = "SELECT expandoRow FROM ExpandoRow expandoRow WHERE ";
1976            private static final String _SQL_COUNT_EXPANDOROW = "SELECT COUNT(expandoRow) FROM ExpandoRow expandoRow";
1977            private static final String _SQL_COUNT_EXPANDOROW_WHERE = "SELECT COUNT(expandoRow) FROM ExpandoRow expandoRow WHERE ";
1978            private static final String _ORDER_BY_ENTITY_ALIAS = "expandoRow.";
1979            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoRow exists with the primary key ";
1980            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoRow exists with the key {";
1981            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1982            private static final Log _log = LogFactoryUtil.getLog(ExpandoRowPersistenceImpl.class);
1983            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1984                                    "rowId"
1985                            });
1986            private static final ExpandoRow _nullExpandoRow = new ExpandoRowImpl() {
1987                            @Override
1988                            public Object clone() {
1989                                    return this;
1990                            }
1991    
1992                            @Override
1993                            public CacheModel<ExpandoRow> toCacheModel() {
1994                                    return _nullExpandoRowCacheModel;
1995                            }
1996                    };
1997    
1998            private static final CacheModel<ExpandoRow> _nullExpandoRowCacheModel = new CacheModel<ExpandoRow>() {
1999                            @Override
2000                            public ExpandoRow toEntityModel() {
2001                                    return _nullExpandoRow;
2002                            }
2003                    };
2004    }