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