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