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