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