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