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