001    /**
002     * Copyright (c) 2000-2011 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.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.model.CacheModel;
037    import com.liferay.portal.model.ModelListener;
038    import com.liferay.portal.service.persistence.BatchSessionUtil;
039    import com.liferay.portal.service.persistence.ResourcePersistence;
040    import com.liferay.portal.service.persistence.UserPersistence;
041    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042    
043    import com.liferay.portlet.expando.NoSuchRowException;
044    import com.liferay.portlet.expando.model.ExpandoRow;
045    import com.liferay.portlet.expando.model.impl.ExpandoRowImpl;
046    import com.liferay.portlet.expando.model.impl.ExpandoRowModelImpl;
047    
048    import java.io.Serializable;
049    
050    import java.util.ArrayList;
051    import java.util.Collections;
052    import java.util.List;
053    
054    /**
055     * The persistence implementation for the expando row service.
056     *
057     * <p>
058     * Caching information and settings can be found in <code>portal.properties</code>
059     * </p>
060     *
061     * @author Brian Wing Shun Chan
062     * @see ExpandoRowPersistence
063     * @see ExpandoRowUtil
064     * @generated
065     */
066    public class ExpandoRowPersistenceImpl extends BasePersistenceImpl<ExpandoRow>
067            implements ExpandoRowPersistence {
068            /*
069             * NOTE FOR DEVELOPERS:
070             *
071             * 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.
072             */
073            public static final String FINDER_CLASS_NAME_ENTITY = ExpandoRowImpl.class.getName();
074            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075                    ".List1";
076            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List2";
078            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TABLEID = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
079                            ExpandoRowModelImpl.FINDER_CACHE_ENABLED, ExpandoRowImpl.class,
080                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByTableId",
081                            new String[] {
082                                    Long.class.getName(),
083                                    
084                            "java.lang.Integer", "java.lang.Integer",
085                                    "com.liferay.portal.kernel.util.OrderByComparator"
086                            });
087            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID =
088                    new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
089                            ExpandoRowModelImpl.FINDER_CACHE_ENABLED, ExpandoRowImpl.class,
090                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTableId",
091                            new String[] { Long.class.getName() },
092                            ExpandoRowModelImpl.TABLEID_COLUMN_BITMASK);
093            public static final FinderPath FINDER_PATH_COUNT_BY_TABLEID = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
094                            ExpandoRowModelImpl.FINDER_CACHE_ENABLED, Long.class,
095                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTableId",
096                            new String[] { Long.class.getName() });
097            public static final FinderPath FINDER_PATH_FETCH_BY_T_C = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
098                            ExpandoRowModelImpl.FINDER_CACHE_ENABLED, ExpandoRowImpl.class,
099                            FINDER_CLASS_NAME_ENTITY, "fetchByT_C",
100                            new String[] { Long.class.getName(), Long.class.getName() },
101                            ExpandoRowModelImpl.TABLEID_COLUMN_BITMASK |
102                            ExpandoRowModelImpl.CLASSPK_COLUMN_BITMASK);
103            public static final FinderPath FINDER_PATH_COUNT_BY_T_C = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
104                            ExpandoRowModelImpl.FINDER_CACHE_ENABLED, Long.class,
105                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_C",
106                            new String[] { Long.class.getName(), Long.class.getName() });
107            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
108                            ExpandoRowModelImpl.FINDER_CACHE_ENABLED, ExpandoRowImpl.class,
109                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
110            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
111                            ExpandoRowModelImpl.FINDER_CACHE_ENABLED, ExpandoRowImpl.class,
112                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
113            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
114                            ExpandoRowModelImpl.FINDER_CACHE_ENABLED, Long.class,
115                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
116    
117            /**
118             * Caches the expando row in the entity cache if it is enabled.
119             *
120             * @param expandoRow the expando row
121             */
122            public void cacheResult(ExpandoRow expandoRow) {
123                    EntityCacheUtil.putResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
124                            ExpandoRowImpl.class, expandoRow.getPrimaryKey(), expandoRow);
125    
126                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
127                            new Object[] {
128                                    Long.valueOf(expandoRow.getTableId()),
129                                    Long.valueOf(expandoRow.getClassPK())
130                            }, expandoRow);
131    
132                    expandoRow.resetOriginalValues();
133            }
134    
135            /**
136             * Caches the expando rows in the entity cache if it is enabled.
137             *
138             * @param expandoRows the expando rows
139             */
140            public void cacheResult(List<ExpandoRow> expandoRows) {
141                    for (ExpandoRow expandoRow : expandoRows) {
142                            if (EntityCacheUtil.getResult(
143                                                    ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
144                                                    ExpandoRowImpl.class, expandoRow.getPrimaryKey()) == null) {
145                                    cacheResult(expandoRow);
146                            }
147                            else {
148                                    expandoRow.resetOriginalValues();
149                            }
150                    }
151            }
152    
153            /**
154             * Clears the cache for all expando rows.
155             *
156             * <p>
157             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
158             * </p>
159             */
160            @Override
161            public void clearCache() {
162                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
163                            CacheRegistryUtil.clear(ExpandoRowImpl.class.getName());
164                    }
165    
166                    EntityCacheUtil.clearCache(ExpandoRowImpl.class.getName());
167    
168                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
169                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
170                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
171            }
172    
173            /**
174             * Clears the cache for the expando row.
175             *
176             * <p>
177             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
178             * </p>
179             */
180            @Override
181            public void clearCache(ExpandoRow expandoRow) {
182                    EntityCacheUtil.removeResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
183                            ExpandoRowImpl.class, expandoRow.getPrimaryKey());
184    
185                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
186                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
187    
188                    clearUniqueFindersCache(expandoRow);
189            }
190    
191            @Override
192            public void clearCache(List<ExpandoRow> expandoRows) {
193                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
194                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
195    
196                    for (ExpandoRow expandoRow : expandoRows) {
197                            EntityCacheUtil.removeResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
198                                    ExpandoRowImpl.class, expandoRow.getPrimaryKey());
199    
200                            clearUniqueFindersCache(expandoRow);
201                    }
202            }
203    
204            protected void clearUniqueFindersCache(ExpandoRow expandoRow) {
205                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C,
206                            new Object[] {
207                                    Long.valueOf(expandoRow.getTableId()),
208                                    Long.valueOf(expandoRow.getClassPK())
209                            });
210            }
211    
212            /**
213             * Creates a new expando row with the primary key. Does not add the expando row to the database.
214             *
215             * @param rowId the primary key for the new expando row
216             * @return the new expando row
217             */
218            public ExpandoRow create(long rowId) {
219                    ExpandoRow expandoRow = new ExpandoRowImpl();
220    
221                    expandoRow.setNew(true);
222                    expandoRow.setPrimaryKey(rowId);
223    
224                    return expandoRow;
225            }
226    
227            /**
228             * Removes the expando row with the primary key from the database. Also notifies the appropriate model listeners.
229             *
230             * @param rowId the primary key of the expando row
231             * @return the expando row that was removed
232             * @throws com.liferay.portlet.expando.NoSuchRowException if a expando row with the primary key could not be found
233             * @throws SystemException if a system exception occurred
234             */
235            public ExpandoRow remove(long rowId)
236                    throws NoSuchRowException, SystemException {
237                    return remove(Long.valueOf(rowId));
238            }
239    
240            /**
241             * Removes the expando row with the primary key from the database. Also notifies the appropriate model listeners.
242             *
243             * @param primaryKey the primary key of the expando row
244             * @return the expando row that was removed
245             * @throws com.liferay.portlet.expando.NoSuchRowException if a expando row with the primary key could not be found
246             * @throws SystemException if a system exception occurred
247             */
248            @Override
249            public ExpandoRow remove(Serializable primaryKey)
250                    throws NoSuchRowException, SystemException {
251                    Session session = null;
252    
253                    try {
254                            session = openSession();
255    
256                            ExpandoRow expandoRow = (ExpandoRow)session.get(ExpandoRowImpl.class,
257                                            primaryKey);
258    
259                            if (expandoRow == null) {
260                                    if (_log.isWarnEnabled()) {
261                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
262                                    }
263    
264                                    throw new NoSuchRowException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
265                                            primaryKey);
266                            }
267    
268                            return remove(expandoRow);
269                    }
270                    catch (NoSuchRowException nsee) {
271                            throw nsee;
272                    }
273                    catch (Exception e) {
274                            throw processException(e);
275                    }
276                    finally {
277                            closeSession(session);
278                    }
279            }
280    
281            @Override
282            protected ExpandoRow removeImpl(ExpandoRow expandoRow)
283                    throws SystemException {
284                    expandoRow = toUnwrappedModel(expandoRow);
285    
286                    Session session = null;
287    
288                    try {
289                            session = openSession();
290    
291                            BatchSessionUtil.delete(session, expandoRow);
292                    }
293                    catch (Exception e) {
294                            throw processException(e);
295                    }
296                    finally {
297                            closeSession(session);
298                    }
299    
300                    clearCache(expandoRow);
301    
302                    return expandoRow;
303            }
304    
305            @Override
306            public ExpandoRow updateImpl(
307                    com.liferay.portlet.expando.model.ExpandoRow expandoRow, boolean merge)
308                    throws SystemException {
309                    expandoRow = toUnwrappedModel(expandoRow);
310    
311                    boolean isNew = expandoRow.isNew();
312    
313                    ExpandoRowModelImpl expandoRowModelImpl = (ExpandoRowModelImpl)expandoRow;
314    
315                    Session session = null;
316    
317                    try {
318                            session = openSession();
319    
320                            BatchSessionUtil.update(session, expandoRow, merge);
321    
322                            expandoRow.setNew(false);
323                    }
324                    catch (Exception e) {
325                            throw processException(e);
326                    }
327                    finally {
328                            closeSession(session);
329                    }
330    
331                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
332    
333                    if (isNew || !ExpandoRowModelImpl.COLUMN_BITMASK_ENABLED) {
334                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
335                    }
336    
337                    else {
338                            if ((expandoRowModelImpl.getColumnBitmask() &
339                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID.getColumnBitmask()) != 0) {
340                                    Object[] args = new Object[] {
341                                                    Long.valueOf(expandoRowModelImpl.getOriginalTableId())
342                                            };
343    
344                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
345                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
346                                            args);
347    
348                                    args = new Object[] {
349                                                    Long.valueOf(expandoRowModelImpl.getTableId())
350                                            };
351    
352                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
353                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
354                                            args);
355                            }
356                    }
357    
358                    EntityCacheUtil.putResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
359                            ExpandoRowImpl.class, expandoRow.getPrimaryKey(), expandoRow);
360    
361                    if (isNew) {
362                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
363                                    new Object[] {
364                                            Long.valueOf(expandoRow.getTableId()),
365                                            Long.valueOf(expandoRow.getClassPK())
366                                    }, expandoRow);
367                    }
368                    else {
369                            if ((expandoRowModelImpl.getColumnBitmask() &
370                                            FINDER_PATH_FETCH_BY_T_C.getColumnBitmask()) != 0) {
371                                    Object[] args = new Object[] {
372                                                    Long.valueOf(expandoRowModelImpl.getOriginalTableId()),
373                                                    Long.valueOf(expandoRowModelImpl.getOriginalClassPK())
374                                            };
375    
376                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_C, args);
377                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C, args);
378    
379                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
380                                            new Object[] {
381                                                    Long.valueOf(expandoRow.getTableId()),
382                                                    Long.valueOf(expandoRow.getClassPK())
383                                            }, expandoRow);
384                            }
385                    }
386    
387                    return expandoRow;
388            }
389    
390            protected ExpandoRow toUnwrappedModel(ExpandoRow expandoRow) {
391                    if (expandoRow instanceof ExpandoRowImpl) {
392                            return expandoRow;
393                    }
394    
395                    ExpandoRowImpl expandoRowImpl = new ExpandoRowImpl();
396    
397                    expandoRowImpl.setNew(expandoRow.isNew());
398                    expandoRowImpl.setPrimaryKey(expandoRow.getPrimaryKey());
399    
400                    expandoRowImpl.setRowId(expandoRow.getRowId());
401                    expandoRowImpl.setCompanyId(expandoRow.getCompanyId());
402                    expandoRowImpl.setTableId(expandoRow.getTableId());
403                    expandoRowImpl.setClassPK(expandoRow.getClassPK());
404    
405                    return expandoRowImpl;
406            }
407    
408            /**
409             * Returns the expando row with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
410             *
411             * @param primaryKey the primary key of the expando row
412             * @return the expando row
413             * @throws com.liferay.portal.NoSuchModelException if a expando row with the primary key could not be found
414             * @throws SystemException if a system exception occurred
415             */
416            @Override
417            public ExpandoRow findByPrimaryKey(Serializable primaryKey)
418                    throws NoSuchModelException, SystemException {
419                    return findByPrimaryKey(((Long)primaryKey).longValue());
420            }
421    
422            /**
423             * Returns the expando row with the primary key or throws a {@link com.liferay.portlet.expando.NoSuchRowException} if it could not be found.
424             *
425             * @param rowId the primary key of the expando row
426             * @return the expando row
427             * @throws com.liferay.portlet.expando.NoSuchRowException if a expando row with the primary key could not be found
428             * @throws SystemException if a system exception occurred
429             */
430            public ExpandoRow findByPrimaryKey(long rowId)
431                    throws NoSuchRowException, SystemException {
432                    ExpandoRow expandoRow = fetchByPrimaryKey(rowId);
433    
434                    if (expandoRow == null) {
435                            if (_log.isWarnEnabled()) {
436                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + rowId);
437                            }
438    
439                            throw new NoSuchRowException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
440                                    rowId);
441                    }
442    
443                    return expandoRow;
444            }
445    
446            /**
447             * Returns the expando row with the primary key or returns <code>null</code> if it could not be found.
448             *
449             * @param primaryKey the primary key of the expando row
450             * @return the expando row, or <code>null</code> if a expando row with the primary key could not be found
451             * @throws SystemException if a system exception occurred
452             */
453            @Override
454            public ExpandoRow fetchByPrimaryKey(Serializable primaryKey)
455                    throws SystemException {
456                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
457            }
458    
459            /**
460             * Returns the expando row with the primary key or returns <code>null</code> if it could not be found.
461             *
462             * @param rowId the primary key of the expando row
463             * @return the expando row, or <code>null</code> if a expando row with the primary key could not be found
464             * @throws SystemException if a system exception occurred
465             */
466            public ExpandoRow fetchByPrimaryKey(long rowId) throws SystemException {
467                    ExpandoRow expandoRow = (ExpandoRow)EntityCacheUtil.getResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
468                                    ExpandoRowImpl.class, rowId);
469    
470                    if (expandoRow == _nullExpandoRow) {
471                            return null;
472                    }
473    
474                    if (expandoRow == null) {
475                            Session session = null;
476    
477                            boolean hasException = false;
478    
479                            try {
480                                    session = openSession();
481    
482                                    expandoRow = (ExpandoRow)session.get(ExpandoRowImpl.class,
483                                                    Long.valueOf(rowId));
484                            }
485                            catch (Exception e) {
486                                    hasException = true;
487    
488                                    throw processException(e);
489                            }
490                            finally {
491                                    if (expandoRow != null) {
492                                            cacheResult(expandoRow);
493                                    }
494                                    else if (!hasException) {
495                                            EntityCacheUtil.putResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
496                                                    ExpandoRowImpl.class, rowId, _nullExpandoRow);
497                                    }
498    
499                                    closeSession(session);
500                            }
501                    }
502    
503                    return expandoRow;
504            }
505    
506            /**
507             * Returns all the expando rows where tableId = &#63;.
508             *
509             * @param tableId the table ID
510             * @return the matching expando rows
511             * @throws SystemException if a system exception occurred
512             */
513            public List<ExpandoRow> findByTableId(long tableId)
514                    throws SystemException {
515                    return findByTableId(tableId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
516            }
517    
518            /**
519             * Returns a range of all the expando rows where tableId = &#63;.
520             *
521             * <p>
522             * 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.
523             * </p>
524             *
525             * @param tableId the table ID
526             * @param start the lower bound of the range of expando rows
527             * @param end the upper bound of the range of expando rows (not inclusive)
528             * @return the range of matching expando rows
529             * @throws SystemException if a system exception occurred
530             */
531            public List<ExpandoRow> findByTableId(long tableId, int start, int end)
532                    throws SystemException {
533                    return findByTableId(tableId, start, end, null);
534            }
535    
536            /**
537             * Returns an ordered range of all the expando rows where tableId = &#63;.
538             *
539             * <p>
540             * 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.
541             * </p>
542             *
543             * @param tableId the table ID
544             * @param start the lower bound of the range of expando rows
545             * @param end the upper bound of the range of expando rows (not inclusive)
546             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
547             * @return the ordered range of matching expando rows
548             * @throws SystemException if a system exception occurred
549             */
550            public List<ExpandoRow> findByTableId(long tableId, int start, int end,
551                    OrderByComparator orderByComparator) throws SystemException {
552                    FinderPath finderPath = null;
553                    Object[] finderArgs = null;
554    
555                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
556                                    (orderByComparator == null)) {
557                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID;
558                            finderArgs = new Object[] { tableId };
559                    }
560                    else {
561                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TABLEID;
562                            finderArgs = new Object[] { tableId, start, end, orderByComparator };
563                    }
564    
565                    List<ExpandoRow> list = (List<ExpandoRow>)FinderCacheUtil.getResult(finderPath,
566                                    finderArgs, this);
567    
568                    if (list == null) {
569                            StringBundler query = null;
570    
571                            if (orderByComparator != null) {
572                                    query = new StringBundler(3 +
573                                                    (orderByComparator.getOrderByFields().length * 3));
574                            }
575                            else {
576                                    query = new StringBundler(2);
577                            }
578    
579                            query.append(_SQL_SELECT_EXPANDOROW_WHERE);
580    
581                            query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
582    
583                            if (orderByComparator != null) {
584                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
585                                            orderByComparator);
586                            }
587    
588                            String sql = query.toString();
589    
590                            Session session = null;
591    
592                            try {
593                                    session = openSession();
594    
595                                    Query q = session.createQuery(sql);
596    
597                                    QueryPos qPos = QueryPos.getInstance(q);
598    
599                                    qPos.add(tableId);
600    
601                                    list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(), start,
602                                                    end);
603                            }
604                            catch (Exception e) {
605                                    throw processException(e);
606                            }
607                            finally {
608                                    if (list == null) {
609                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
610                                    }
611                                    else {
612                                            cacheResult(list);
613    
614                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
615                                    }
616    
617                                    closeSession(session);
618                            }
619                    }
620    
621                    return list;
622            }
623    
624            /**
625             * Returns the first expando row in the ordered set where tableId = &#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.
629             * </p>
630             *
631             * @param tableId the table ID
632             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
633             * @return the first matching expando row
634             * @throws com.liferay.portlet.expando.NoSuchRowException if a matching expando row could not be found
635             * @throws SystemException if a system exception occurred
636             */
637            public ExpandoRow findByTableId_First(long tableId,
638                    OrderByComparator orderByComparator)
639                    throws NoSuchRowException, SystemException {
640                    List<ExpandoRow> list = findByTableId(tableId, 0, 1, orderByComparator);
641    
642                    if (list.isEmpty()) {
643                            StringBundler msg = new StringBundler(4);
644    
645                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
646    
647                            msg.append("tableId=");
648                            msg.append(tableId);
649    
650                            msg.append(StringPool.CLOSE_CURLY_BRACE);
651    
652                            throw new NoSuchRowException(msg.toString());
653                    }
654                    else {
655                            return list.get(0);
656                    }
657            }
658    
659            /**
660             * Returns the last expando row in the ordered set where tableId = &#63;.
661             *
662             * <p>
663             * 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.
664             * </p>
665             *
666             * @param tableId the table ID
667             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
668             * @return the last matching expando row
669             * @throws com.liferay.portlet.expando.NoSuchRowException if a matching expando row could not be found
670             * @throws SystemException if a system exception occurred
671             */
672            public ExpandoRow findByTableId_Last(long tableId,
673                    OrderByComparator orderByComparator)
674                    throws NoSuchRowException, SystemException {
675                    int count = countByTableId(tableId);
676    
677                    List<ExpandoRow> list = findByTableId(tableId, count - 1, count,
678                                    orderByComparator);
679    
680                    if (list.isEmpty()) {
681                            StringBundler msg = new StringBundler(4);
682    
683                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
684    
685                            msg.append("tableId=");
686                            msg.append(tableId);
687    
688                            msg.append(StringPool.CLOSE_CURLY_BRACE);
689    
690                            throw new NoSuchRowException(msg.toString());
691                    }
692                    else {
693                            return list.get(0);
694                    }
695            }
696    
697            /**
698             * Returns the expando rows before and after the current expando row in the ordered set where tableId = &#63;.
699             *
700             * <p>
701             * 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.
702             * </p>
703             *
704             * @param rowId the primary key of the current expando row
705             * @param tableId the table ID
706             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
707             * @return the previous, current, and next expando row
708             * @throws com.liferay.portlet.expando.NoSuchRowException if a expando row with the primary key could not be found
709             * @throws SystemException if a system exception occurred
710             */
711            public ExpandoRow[] findByTableId_PrevAndNext(long rowId, long tableId,
712                    OrderByComparator orderByComparator)
713                    throws NoSuchRowException, SystemException {
714                    ExpandoRow expandoRow = findByPrimaryKey(rowId);
715    
716                    Session session = null;
717    
718                    try {
719                            session = openSession();
720    
721                            ExpandoRow[] array = new ExpandoRowImpl[3];
722    
723                            array[0] = getByTableId_PrevAndNext(session, expandoRow, tableId,
724                                            orderByComparator, true);
725    
726                            array[1] = expandoRow;
727    
728                            array[2] = getByTableId_PrevAndNext(session, expandoRow, tableId,
729                                            orderByComparator, false);
730    
731                            return array;
732                    }
733                    catch (Exception e) {
734                            throw processException(e);
735                    }
736                    finally {
737                            closeSession(session);
738                    }
739            }
740    
741            protected ExpandoRow getByTableId_PrevAndNext(Session session,
742                    ExpandoRow expandoRow, long tableId,
743                    OrderByComparator orderByComparator, boolean previous) {
744                    StringBundler query = null;
745    
746                    if (orderByComparator != null) {
747                            query = new StringBundler(6 +
748                                            (orderByComparator.getOrderByFields().length * 6));
749                    }
750                    else {
751                            query = new StringBundler(3);
752                    }
753    
754                    query.append(_SQL_SELECT_EXPANDOROW_WHERE);
755    
756                    query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
757    
758                    if (orderByComparator != null) {
759                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
760    
761                            if (orderByConditionFields.length > 0) {
762                                    query.append(WHERE_AND);
763                            }
764    
765                            for (int i = 0; i < orderByConditionFields.length; i++) {
766                                    query.append(_ORDER_BY_ENTITY_ALIAS);
767                                    query.append(orderByConditionFields[i]);
768    
769                                    if ((i + 1) < orderByConditionFields.length) {
770                                            if (orderByComparator.isAscending() ^ previous) {
771                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
772                                            }
773                                            else {
774                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
775                                            }
776                                    }
777                                    else {
778                                            if (orderByComparator.isAscending() ^ previous) {
779                                                    query.append(WHERE_GREATER_THAN);
780                                            }
781                                            else {
782                                                    query.append(WHERE_LESSER_THAN);
783                                            }
784                                    }
785                            }
786    
787                            query.append(ORDER_BY_CLAUSE);
788    
789                            String[] orderByFields = orderByComparator.getOrderByFields();
790    
791                            for (int i = 0; i < orderByFields.length; i++) {
792                                    query.append(_ORDER_BY_ENTITY_ALIAS);
793                                    query.append(orderByFields[i]);
794    
795                                    if ((i + 1) < orderByFields.length) {
796                                            if (orderByComparator.isAscending() ^ previous) {
797                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
798                                            }
799                                            else {
800                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
801                                            }
802                                    }
803                                    else {
804                                            if (orderByComparator.isAscending() ^ previous) {
805                                                    query.append(ORDER_BY_ASC);
806                                            }
807                                            else {
808                                                    query.append(ORDER_BY_DESC);
809                                            }
810                                    }
811                            }
812                    }
813    
814                    String sql = query.toString();
815    
816                    Query q = session.createQuery(sql);
817    
818                    q.setFirstResult(0);
819                    q.setMaxResults(2);
820    
821                    QueryPos qPos = QueryPos.getInstance(q);
822    
823                    qPos.add(tableId);
824    
825                    if (orderByComparator != null) {
826                            Object[] values = orderByComparator.getOrderByConditionValues(expandoRow);
827    
828                            for (Object value : values) {
829                                    qPos.add(value);
830                            }
831                    }
832    
833                    List<ExpandoRow> list = q.list();
834    
835                    if (list.size() == 2) {
836                            return list.get(1);
837                    }
838                    else {
839                            return null;
840                    }
841            }
842    
843            /**
844             * 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.
845             *
846             * @param tableId the table ID
847             * @param classPK the class p k
848             * @return the matching expando row
849             * @throws com.liferay.portlet.expando.NoSuchRowException if a matching expando row could not be found
850             * @throws SystemException if a system exception occurred
851             */
852            public ExpandoRow findByT_C(long tableId, long classPK)
853                    throws NoSuchRowException, SystemException {
854                    ExpandoRow expandoRow = fetchByT_C(tableId, classPK);
855    
856                    if (expandoRow == null) {
857                            StringBundler msg = new StringBundler(6);
858    
859                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
860    
861                            msg.append("tableId=");
862                            msg.append(tableId);
863    
864                            msg.append(", classPK=");
865                            msg.append(classPK);
866    
867                            msg.append(StringPool.CLOSE_CURLY_BRACE);
868    
869                            if (_log.isWarnEnabled()) {
870                                    _log.warn(msg.toString());
871                            }
872    
873                            throw new NoSuchRowException(msg.toString());
874                    }
875    
876                    return expandoRow;
877            }
878    
879            /**
880             * 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.
881             *
882             * @param tableId the table ID
883             * @param classPK the class p k
884             * @return the matching expando row, or <code>null</code> if a matching expando row could not be found
885             * @throws SystemException if a system exception occurred
886             */
887            public ExpandoRow fetchByT_C(long tableId, long classPK)
888                    throws SystemException {
889                    return fetchByT_C(tableId, classPK, true);
890            }
891    
892            /**
893             * 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.
894             *
895             * @param tableId the table ID
896             * @param classPK the class p k
897             * @param retrieveFromCache whether to use the finder cache
898             * @return the matching expando row, or <code>null</code> if a matching expando row could not be found
899             * @throws SystemException if a system exception occurred
900             */
901            public ExpandoRow fetchByT_C(long tableId, long classPK,
902                    boolean retrieveFromCache) throws SystemException {
903                    Object[] finderArgs = new Object[] { tableId, classPK };
904    
905                    Object result = null;
906    
907                    if (retrieveFromCache) {
908                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_T_C,
909                                            finderArgs, this);
910                    }
911    
912                    if (result == null) {
913                            StringBundler query = new StringBundler(3);
914    
915                            query.append(_SQL_SELECT_EXPANDOROW_WHERE);
916    
917                            query.append(_FINDER_COLUMN_T_C_TABLEID_2);
918    
919                            query.append(_FINDER_COLUMN_T_C_CLASSPK_2);
920    
921                            String sql = query.toString();
922    
923                            Session session = null;
924    
925                            try {
926                                    session = openSession();
927    
928                                    Query q = session.createQuery(sql);
929    
930                                    QueryPos qPos = QueryPos.getInstance(q);
931    
932                                    qPos.add(tableId);
933    
934                                    qPos.add(classPK);
935    
936                                    List<ExpandoRow> list = q.list();
937    
938                                    result = list;
939    
940                                    ExpandoRow expandoRow = null;
941    
942                                    if (list.isEmpty()) {
943                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
944                                                    finderArgs, list);
945                                    }
946                                    else {
947                                            expandoRow = list.get(0);
948    
949                                            cacheResult(expandoRow);
950    
951                                            if ((expandoRow.getTableId() != tableId) ||
952                                                            (expandoRow.getClassPK() != classPK)) {
953                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
954                                                            finderArgs, expandoRow);
955                                            }
956                                    }
957    
958                                    return expandoRow;
959                            }
960                            catch (Exception e) {
961                                    throw processException(e);
962                            }
963                            finally {
964                                    if (result == null) {
965                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C,
966                                                    finderArgs);
967                                    }
968    
969                                    closeSession(session);
970                            }
971                    }
972                    else {
973                            if (result instanceof List<?>) {
974                                    return null;
975                            }
976                            else {
977                                    return (ExpandoRow)result;
978                            }
979                    }
980            }
981    
982            /**
983             * Returns all the expando rows.
984             *
985             * @return the expando rows
986             * @throws SystemException if a system exception occurred
987             */
988            public List<ExpandoRow> findAll() throws SystemException {
989                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
990            }
991    
992            /**
993             * Returns a range of all the expando rows.
994             *
995             * <p>
996             * 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.
997             * </p>
998             *
999             * @param start the lower bound of the range of expando rows
1000             * @param end the upper bound of the range of expando rows (not inclusive)
1001             * @return the range of expando rows
1002             * @throws SystemException if a system exception occurred
1003             */
1004            public List<ExpandoRow> findAll(int start, int end)
1005                    throws SystemException {
1006                    return findAll(start, end, null);
1007            }
1008    
1009            /**
1010             * Returns an ordered range of all the expando rows.
1011             *
1012             * <p>
1013             * 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.
1014             * </p>
1015             *
1016             * @param start the lower bound of the range of expando rows
1017             * @param end the upper bound of the range of expando rows (not inclusive)
1018             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1019             * @return the ordered range of expando rows
1020             * @throws SystemException if a system exception occurred
1021             */
1022            public List<ExpandoRow> findAll(int start, int end,
1023                    OrderByComparator orderByComparator) throws SystemException {
1024                    FinderPath finderPath = null;
1025                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1026    
1027                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1028                                    (orderByComparator == null)) {
1029                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1030                            finderArgs = FINDER_ARGS_EMPTY;
1031                    }
1032                    else {
1033                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1034                            finderArgs = new Object[] { start, end, orderByComparator };
1035                    }
1036    
1037                    List<ExpandoRow> list = (List<ExpandoRow>)FinderCacheUtil.getResult(finderPath,
1038                                    finderArgs, this);
1039    
1040                    if (list == null) {
1041                            StringBundler query = null;
1042                            String sql = null;
1043    
1044                            if (orderByComparator != null) {
1045                                    query = new StringBundler(2 +
1046                                                    (orderByComparator.getOrderByFields().length * 3));
1047    
1048                                    query.append(_SQL_SELECT_EXPANDOROW);
1049    
1050                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1051                                            orderByComparator);
1052    
1053                                    sql = query.toString();
1054                            }
1055                            else {
1056                                    sql = _SQL_SELECT_EXPANDOROW;
1057                            }
1058    
1059                            Session session = null;
1060    
1061                            try {
1062                                    session = openSession();
1063    
1064                                    Query q = session.createQuery(sql);
1065    
1066                                    if (orderByComparator == null) {
1067                                            list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(),
1068                                                            start, end, false);
1069    
1070                                            Collections.sort(list);
1071                                    }
1072                                    else {
1073                                            list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(),
1074                                                            start, end);
1075                                    }
1076                            }
1077                            catch (Exception e) {
1078                                    throw processException(e);
1079                            }
1080                            finally {
1081                                    if (list == null) {
1082                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1083                                    }
1084                                    else {
1085                                            cacheResult(list);
1086    
1087                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1088                                    }
1089    
1090                                    closeSession(session);
1091                            }
1092                    }
1093    
1094                    return list;
1095            }
1096    
1097            /**
1098             * Removes all the expando rows where tableId = &#63; from the database.
1099             *
1100             * @param tableId the table ID
1101             * @throws SystemException if a system exception occurred
1102             */
1103            public void removeByTableId(long tableId) throws SystemException {
1104                    for (ExpandoRow expandoRow : findByTableId(tableId)) {
1105                            remove(expandoRow);
1106                    }
1107            }
1108    
1109            /**
1110             * Removes the expando row where tableId = &#63; and classPK = &#63; from the database.
1111             *
1112             * @param tableId the table ID
1113             * @param classPK the class p k
1114             * @throws SystemException if a system exception occurred
1115             */
1116            public void removeByT_C(long tableId, long classPK)
1117                    throws NoSuchRowException, SystemException {
1118                    ExpandoRow expandoRow = findByT_C(tableId, classPK);
1119    
1120                    remove(expandoRow);
1121            }
1122    
1123            /**
1124             * Removes all the expando rows from the database.
1125             *
1126             * @throws SystemException if a system exception occurred
1127             */
1128            public void removeAll() throws SystemException {
1129                    for (ExpandoRow expandoRow : findAll()) {
1130                            remove(expandoRow);
1131                    }
1132            }
1133    
1134            /**
1135             * Returns the number of expando rows where tableId = &#63;.
1136             *
1137             * @param tableId the table ID
1138             * @return the number of matching expando rows
1139             * @throws SystemException if a system exception occurred
1140             */
1141            public int countByTableId(long tableId) throws SystemException {
1142                    Object[] finderArgs = new Object[] { tableId };
1143    
1144                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TABLEID,
1145                                    finderArgs, this);
1146    
1147                    if (count == null) {
1148                            StringBundler query = new StringBundler(2);
1149    
1150                            query.append(_SQL_COUNT_EXPANDOROW_WHERE);
1151    
1152                            query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
1153    
1154                            String sql = query.toString();
1155    
1156                            Session session = null;
1157    
1158                            try {
1159                                    session = openSession();
1160    
1161                                    Query q = session.createQuery(sql);
1162    
1163                                    QueryPos qPos = QueryPos.getInstance(q);
1164    
1165                                    qPos.add(tableId);
1166    
1167                                    count = (Long)q.uniqueResult();
1168                            }
1169                            catch (Exception e) {
1170                                    throw processException(e);
1171                            }
1172                            finally {
1173                                    if (count == null) {
1174                                            count = Long.valueOf(0);
1175                                    }
1176    
1177                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TABLEID,
1178                                            finderArgs, count);
1179    
1180                                    closeSession(session);
1181                            }
1182                    }
1183    
1184                    return count.intValue();
1185            }
1186    
1187            /**
1188             * Returns the number of expando rows where tableId = &#63; and classPK = &#63;.
1189             *
1190             * @param tableId the table ID
1191             * @param classPK the class p k
1192             * @return the number of matching expando rows
1193             * @throws SystemException if a system exception occurred
1194             */
1195            public int countByT_C(long tableId, long classPK) throws SystemException {
1196                    Object[] finderArgs = new Object[] { tableId, classPK };
1197    
1198                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_C,
1199                                    finderArgs, this);
1200    
1201                    if (count == null) {
1202                            StringBundler query = new StringBundler(3);
1203    
1204                            query.append(_SQL_COUNT_EXPANDOROW_WHERE);
1205    
1206                            query.append(_FINDER_COLUMN_T_C_TABLEID_2);
1207    
1208                            query.append(_FINDER_COLUMN_T_C_CLASSPK_2);
1209    
1210                            String sql = query.toString();
1211    
1212                            Session session = null;
1213    
1214                            try {
1215                                    session = openSession();
1216    
1217                                    Query q = session.createQuery(sql);
1218    
1219                                    QueryPos qPos = QueryPos.getInstance(q);
1220    
1221                                    qPos.add(tableId);
1222    
1223                                    qPos.add(classPK);
1224    
1225                                    count = (Long)q.uniqueResult();
1226                            }
1227                            catch (Exception e) {
1228                                    throw processException(e);
1229                            }
1230                            finally {
1231                                    if (count == null) {
1232                                            count = Long.valueOf(0);
1233                                    }
1234    
1235                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_C, finderArgs,
1236                                            count);
1237    
1238                                    closeSession(session);
1239                            }
1240                    }
1241    
1242                    return count.intValue();
1243            }
1244    
1245            /**
1246             * Returns the number of expando rows.
1247             *
1248             * @return the number of expando rows
1249             * @throws SystemException if a system exception occurred
1250             */
1251            public int countAll() throws SystemException {
1252                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1253                                    FINDER_ARGS_EMPTY, this);
1254    
1255                    if (count == null) {
1256                            Session session = null;
1257    
1258                            try {
1259                                    session = openSession();
1260    
1261                                    Query q = session.createQuery(_SQL_COUNT_EXPANDOROW);
1262    
1263                                    count = (Long)q.uniqueResult();
1264                            }
1265                            catch (Exception e) {
1266                                    throw processException(e);
1267                            }
1268                            finally {
1269                                    if (count == null) {
1270                                            count = Long.valueOf(0);
1271                                    }
1272    
1273                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1274                                            FINDER_ARGS_EMPTY, count);
1275    
1276                                    closeSession(session);
1277                            }
1278                    }
1279    
1280                    return count.intValue();
1281            }
1282    
1283            /**
1284             * Initializes the expando row persistence.
1285             */
1286            public void afterPropertiesSet() {
1287                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1288                                            com.liferay.portal.util.PropsUtil.get(
1289                                                    "value.object.listener.com.liferay.portlet.expando.model.ExpandoRow")));
1290    
1291                    if (listenerClassNames.length > 0) {
1292                            try {
1293                                    List<ModelListener<ExpandoRow>> listenersList = new ArrayList<ModelListener<ExpandoRow>>();
1294    
1295                                    for (String listenerClassName : listenerClassNames) {
1296                                            listenersList.add((ModelListener<ExpandoRow>)InstanceFactory.newInstance(
1297                                                            listenerClassName));
1298                                    }
1299    
1300                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1301                            }
1302                            catch (Exception e) {
1303                                    _log.error(e);
1304                            }
1305                    }
1306            }
1307    
1308            public void destroy() {
1309                    EntityCacheUtil.removeCache(ExpandoRowImpl.class.getName());
1310                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1311                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1312            }
1313    
1314            @BeanReference(type = ExpandoColumnPersistence.class)
1315            protected ExpandoColumnPersistence expandoColumnPersistence;
1316            @BeanReference(type = ExpandoRowPersistence.class)
1317            protected ExpandoRowPersistence expandoRowPersistence;
1318            @BeanReference(type = ExpandoTablePersistence.class)
1319            protected ExpandoTablePersistence expandoTablePersistence;
1320            @BeanReference(type = ExpandoValuePersistence.class)
1321            protected ExpandoValuePersistence expandoValuePersistence;
1322            @BeanReference(type = ResourcePersistence.class)
1323            protected ResourcePersistence resourcePersistence;
1324            @BeanReference(type = UserPersistence.class)
1325            protected UserPersistence userPersistence;
1326            private static final String _SQL_SELECT_EXPANDOROW = "SELECT expandoRow FROM ExpandoRow expandoRow";
1327            private static final String _SQL_SELECT_EXPANDOROW_WHERE = "SELECT expandoRow FROM ExpandoRow expandoRow WHERE ";
1328            private static final String _SQL_COUNT_EXPANDOROW = "SELECT COUNT(expandoRow) FROM ExpandoRow expandoRow";
1329            private static final String _SQL_COUNT_EXPANDOROW_WHERE = "SELECT COUNT(expandoRow) FROM ExpandoRow expandoRow WHERE ";
1330            private static final String _FINDER_COLUMN_TABLEID_TABLEID_2 = "expandoRow.tableId = ?";
1331            private static final String _FINDER_COLUMN_T_C_TABLEID_2 = "expandoRow.tableId = ? AND ";
1332            private static final String _FINDER_COLUMN_T_C_CLASSPK_2 = "expandoRow.classPK = ?";
1333            private static final String _ORDER_BY_ENTITY_ALIAS = "expandoRow.";
1334            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoRow exists with the primary key ";
1335            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoRow exists with the key {";
1336            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1337            private static Log _log = LogFactoryUtil.getLog(ExpandoRowPersistenceImpl.class);
1338            private static ExpandoRow _nullExpandoRow = new ExpandoRowImpl() {
1339                            @Override
1340                            public Object clone() {
1341                                    return this;
1342                            }
1343    
1344                            @Override
1345                            public CacheModel<ExpandoRow> toCacheModel() {
1346                                    return _nullExpandoRowCacheModel;
1347                            }
1348                    };
1349    
1350            private static CacheModel<ExpandoRow> _nullExpandoRowCacheModel = new CacheModel<ExpandoRow>() {
1351                            public ExpandoRow toEntityModel() {
1352                                    return _nullExpandoRow;
1353                            }
1354                    };
1355    }