001    /**
002     * Copyright (c) 2000-2012 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_WITH_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_WITHOUT_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                    else {
337                            if ((expandoRowModelImpl.getColumnBitmask() &
338                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID.getColumnBitmask()) != 0) {
339                                    Object[] args = new Object[] {
340                                                    Long.valueOf(expandoRowModelImpl.getOriginalTableId())
341                                            };
342    
343                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
344                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
345                                            args);
346    
347                                    args = new Object[] {
348                                                    Long.valueOf(expandoRowModelImpl.getTableId())
349                                            };
350    
351                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
352                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
353                                            args);
354                            }
355                    }
356    
357                    EntityCacheUtil.putResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
358                            ExpandoRowImpl.class, expandoRow.getPrimaryKey(), expandoRow);
359    
360                    if (isNew) {
361                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
362                                    new Object[] {
363                                            Long.valueOf(expandoRow.getTableId()),
364                                            Long.valueOf(expandoRow.getClassPK())
365                                    }, expandoRow);
366                    }
367                    else {
368                            if ((expandoRowModelImpl.getColumnBitmask() &
369                                            FINDER_PATH_FETCH_BY_T_C.getColumnBitmask()) != 0) {
370                                    Object[] args = new Object[] {
371                                                    Long.valueOf(expandoRowModelImpl.getOriginalTableId()),
372                                                    Long.valueOf(expandoRowModelImpl.getOriginalClassPK())
373                                            };
374    
375                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_C, args);
376                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C, args);
377    
378                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
379                                            new Object[] {
380                                                    Long.valueOf(expandoRow.getTableId()),
381                                                    Long.valueOf(expandoRow.getClassPK())
382                                            }, expandoRow);
383                            }
384                    }
385    
386                    return expandoRow;
387            }
388    
389            protected ExpandoRow toUnwrappedModel(ExpandoRow expandoRow) {
390                    if (expandoRow instanceof ExpandoRowImpl) {
391                            return expandoRow;
392                    }
393    
394                    ExpandoRowImpl expandoRowImpl = new ExpandoRowImpl();
395    
396                    expandoRowImpl.setNew(expandoRow.isNew());
397                    expandoRowImpl.setPrimaryKey(expandoRow.getPrimaryKey());
398    
399                    expandoRowImpl.setRowId(expandoRow.getRowId());
400                    expandoRowImpl.setCompanyId(expandoRow.getCompanyId());
401                    expandoRowImpl.setTableId(expandoRow.getTableId());
402                    expandoRowImpl.setClassPK(expandoRow.getClassPK());
403    
404                    return expandoRowImpl;
405            }
406    
407            /**
408             * Returns the expando row with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
409             *
410             * @param primaryKey the primary key of the expando row
411             * @return the expando row
412             * @throws com.liferay.portal.NoSuchModelException if a expando row with the primary key could not be found
413             * @throws SystemException if a system exception occurred
414             */
415            @Override
416            public ExpandoRow findByPrimaryKey(Serializable primaryKey)
417                    throws NoSuchModelException, SystemException {
418                    return findByPrimaryKey(((Long)primaryKey).longValue());
419            }
420    
421            /**
422             * Returns the expando row with the primary key or throws a {@link com.liferay.portlet.expando.NoSuchRowException} if it could not be found.
423             *
424             * @param rowId the primary key of the expando row
425             * @return the expando row
426             * @throws com.liferay.portlet.expando.NoSuchRowException if a expando row with the primary key could not be found
427             * @throws SystemException if a system exception occurred
428             */
429            public ExpandoRow findByPrimaryKey(long rowId)
430                    throws NoSuchRowException, SystemException {
431                    ExpandoRow expandoRow = fetchByPrimaryKey(rowId);
432    
433                    if (expandoRow == null) {
434                            if (_log.isWarnEnabled()) {
435                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + rowId);
436                            }
437    
438                            throw new NoSuchRowException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
439                                    rowId);
440                    }
441    
442                    return expandoRow;
443            }
444    
445            /**
446             * Returns the expando row with the primary key or returns <code>null</code> if it could not be found.
447             *
448             * @param primaryKey the primary key of the expando row
449             * @return the expando row, or <code>null</code> if a expando row with the primary key could not be found
450             * @throws SystemException if a system exception occurred
451             */
452            @Override
453            public ExpandoRow fetchByPrimaryKey(Serializable primaryKey)
454                    throws SystemException {
455                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
456            }
457    
458            /**
459             * Returns the expando row with the primary key or returns <code>null</code> if it could not be found.
460             *
461             * @param rowId the primary key of the expando row
462             * @return the expando row, or <code>null</code> if a expando row with the primary key could not be found
463             * @throws SystemException if a system exception occurred
464             */
465            public ExpandoRow fetchByPrimaryKey(long rowId) throws SystemException {
466                    ExpandoRow expandoRow = (ExpandoRow)EntityCacheUtil.getResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
467                                    ExpandoRowImpl.class, rowId);
468    
469                    if (expandoRow == _nullExpandoRow) {
470                            return null;
471                    }
472    
473                    if (expandoRow == null) {
474                            Session session = null;
475    
476                            boolean hasException = false;
477    
478                            try {
479                                    session = openSession();
480    
481                                    expandoRow = (ExpandoRow)session.get(ExpandoRowImpl.class,
482                                                    Long.valueOf(rowId));
483                            }
484                            catch (Exception e) {
485                                    hasException = true;
486    
487                                    throw processException(e);
488                            }
489                            finally {
490                                    if (expandoRow != null) {
491                                            cacheResult(expandoRow);
492                                    }
493                                    else if (!hasException) {
494                                            EntityCacheUtil.putResult(ExpandoRowModelImpl.ENTITY_CACHE_ENABLED,
495                                                    ExpandoRowImpl.class, rowId, _nullExpandoRow);
496                                    }
497    
498                                    closeSession(session);
499                            }
500                    }
501    
502                    return expandoRow;
503            }
504    
505            /**
506             * Returns all the expando rows where tableId = &#63;.
507             *
508             * @param tableId the table ID
509             * @return the matching expando rows
510             * @throws SystemException if a system exception occurred
511             */
512            public List<ExpandoRow> findByTableId(long tableId)
513                    throws SystemException {
514                    return findByTableId(tableId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
515            }
516    
517            /**
518             * Returns a range of all the expando rows where tableId = &#63;.
519             *
520             * <p>
521             * 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.
522             * </p>
523             *
524             * @param tableId the table ID
525             * @param start the lower bound of the range of expando rows
526             * @param end the upper bound of the range of expando rows (not inclusive)
527             * @return the range of matching expando rows
528             * @throws SystemException if a system exception occurred
529             */
530            public List<ExpandoRow> findByTableId(long tableId, int start, int end)
531                    throws SystemException {
532                    return findByTableId(tableId, start, end, null);
533            }
534    
535            /**
536             * Returns an ordered range of all the expando rows where tableId = &#63;.
537             *
538             * <p>
539             * 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.
540             * </p>
541             *
542             * @param tableId the table ID
543             * @param start the lower bound of the range of expando rows
544             * @param end the upper bound of the range of expando rows (not inclusive)
545             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
546             * @return the ordered range of matching expando rows
547             * @throws SystemException if a system exception occurred
548             */
549            public List<ExpandoRow> findByTableId(long tableId, int start, int end,
550                    OrderByComparator orderByComparator) throws SystemException {
551                    FinderPath finderPath = null;
552                    Object[] finderArgs = null;
553    
554                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
555                                    (orderByComparator == null)) {
556                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID;
557                            finderArgs = new Object[] { tableId };
558                    }
559                    else {
560                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TABLEID;
561                            finderArgs = new Object[] { tableId, start, end, orderByComparator };
562                    }
563    
564                    List<ExpandoRow> list = (List<ExpandoRow>)FinderCacheUtil.getResult(finderPath,
565                                    finderArgs, this);
566    
567                    if ((list != null) && !list.isEmpty()) {
568                            for (ExpandoRow expandoRow : list) {
569                                    if ((tableId != expandoRow.getTableId())) {
570                                            list = null;
571    
572                                            break;
573                                    }
574                            }
575                    }
576    
577                    if (list == null) {
578                            StringBundler query = null;
579    
580                            if (orderByComparator != null) {
581                                    query = new StringBundler(3 +
582                                                    (orderByComparator.getOrderByFields().length * 3));
583                            }
584                            else {
585                                    query = new StringBundler(2);
586                            }
587    
588                            query.append(_SQL_SELECT_EXPANDOROW_WHERE);
589    
590                            query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
591    
592                            if (orderByComparator != null) {
593                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
594                                            orderByComparator);
595                            }
596    
597                            String sql = query.toString();
598    
599                            Session session = null;
600    
601                            try {
602                                    session = openSession();
603    
604                                    Query q = session.createQuery(sql);
605    
606                                    QueryPos qPos = QueryPos.getInstance(q);
607    
608                                    qPos.add(tableId);
609    
610                                    list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(), start,
611                                                    end);
612                            }
613                            catch (Exception e) {
614                                    throw processException(e);
615                            }
616                            finally {
617                                    if (list == null) {
618                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
619                                    }
620                                    else {
621                                            cacheResult(list);
622    
623                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
624                                    }
625    
626                                    closeSession(session);
627                            }
628                    }
629    
630                    return list;
631            }
632    
633            /**
634             * Returns the first expando row in the ordered set where tableId = &#63;.
635             *
636             * <p>
637             * 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.
638             * </p>
639             *
640             * @param tableId the table ID
641             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
642             * @return the first matching expando row
643             * @throws com.liferay.portlet.expando.NoSuchRowException if a matching expando row could not be found
644             * @throws SystemException if a system exception occurred
645             */
646            public ExpandoRow findByTableId_First(long tableId,
647                    OrderByComparator orderByComparator)
648                    throws NoSuchRowException, SystemException {
649                    List<ExpandoRow> list = findByTableId(tableId, 0, 1, orderByComparator);
650    
651                    if (list.isEmpty()) {
652                            StringBundler msg = new StringBundler(4);
653    
654                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
655    
656                            msg.append("tableId=");
657                            msg.append(tableId);
658    
659                            msg.append(StringPool.CLOSE_CURLY_BRACE);
660    
661                            throw new NoSuchRowException(msg.toString());
662                    }
663                    else {
664                            return list.get(0);
665                    }
666            }
667    
668            /**
669             * Returns the last expando row in the ordered set where tableId = &#63;.
670             *
671             * <p>
672             * 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.
673             * </p>
674             *
675             * @param tableId the table ID
676             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
677             * @return the last matching expando row
678             * @throws com.liferay.portlet.expando.NoSuchRowException if a matching expando row could not be found
679             * @throws SystemException if a system exception occurred
680             */
681            public ExpandoRow findByTableId_Last(long tableId,
682                    OrderByComparator orderByComparator)
683                    throws NoSuchRowException, SystemException {
684                    int count = countByTableId(tableId);
685    
686                    List<ExpandoRow> list = findByTableId(tableId, count - 1, count,
687                                    orderByComparator);
688    
689                    if (list.isEmpty()) {
690                            StringBundler msg = new StringBundler(4);
691    
692                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
693    
694                            msg.append("tableId=");
695                            msg.append(tableId);
696    
697                            msg.append(StringPool.CLOSE_CURLY_BRACE);
698    
699                            throw new NoSuchRowException(msg.toString());
700                    }
701                    else {
702                            return list.get(0);
703                    }
704            }
705    
706            /**
707             * Returns the expando rows before and after the current expando row in the ordered set where tableId = &#63;.
708             *
709             * <p>
710             * 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.
711             * </p>
712             *
713             * @param rowId the primary key of the current expando row
714             * @param tableId the table ID
715             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
716             * @return the previous, current, and next expando row
717             * @throws com.liferay.portlet.expando.NoSuchRowException if a expando row with the primary key could not be found
718             * @throws SystemException if a system exception occurred
719             */
720            public ExpandoRow[] findByTableId_PrevAndNext(long rowId, long tableId,
721                    OrderByComparator orderByComparator)
722                    throws NoSuchRowException, SystemException {
723                    ExpandoRow expandoRow = findByPrimaryKey(rowId);
724    
725                    Session session = null;
726    
727                    try {
728                            session = openSession();
729    
730                            ExpandoRow[] array = new ExpandoRowImpl[3];
731    
732                            array[0] = getByTableId_PrevAndNext(session, expandoRow, tableId,
733                                            orderByComparator, true);
734    
735                            array[1] = expandoRow;
736    
737                            array[2] = getByTableId_PrevAndNext(session, expandoRow, tableId,
738                                            orderByComparator, false);
739    
740                            return array;
741                    }
742                    catch (Exception e) {
743                            throw processException(e);
744                    }
745                    finally {
746                            closeSession(session);
747                    }
748            }
749    
750            protected ExpandoRow getByTableId_PrevAndNext(Session session,
751                    ExpandoRow expandoRow, long tableId,
752                    OrderByComparator orderByComparator, boolean previous) {
753                    StringBundler query = null;
754    
755                    if (orderByComparator != null) {
756                            query = new StringBundler(6 +
757                                            (orderByComparator.getOrderByFields().length * 6));
758                    }
759                    else {
760                            query = new StringBundler(3);
761                    }
762    
763                    query.append(_SQL_SELECT_EXPANDOROW_WHERE);
764    
765                    query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
766    
767                    if (orderByComparator != null) {
768                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
769    
770                            if (orderByConditionFields.length > 0) {
771                                    query.append(WHERE_AND);
772                            }
773    
774                            for (int i = 0; i < orderByConditionFields.length; i++) {
775                                    query.append(_ORDER_BY_ENTITY_ALIAS);
776                                    query.append(orderByConditionFields[i]);
777    
778                                    if ((i + 1) < orderByConditionFields.length) {
779                                            if (orderByComparator.isAscending() ^ previous) {
780                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
781                                            }
782                                            else {
783                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
784                                            }
785                                    }
786                                    else {
787                                            if (orderByComparator.isAscending() ^ previous) {
788                                                    query.append(WHERE_GREATER_THAN);
789                                            }
790                                            else {
791                                                    query.append(WHERE_LESSER_THAN);
792                                            }
793                                    }
794                            }
795    
796                            query.append(ORDER_BY_CLAUSE);
797    
798                            String[] orderByFields = orderByComparator.getOrderByFields();
799    
800                            for (int i = 0; i < orderByFields.length; i++) {
801                                    query.append(_ORDER_BY_ENTITY_ALIAS);
802                                    query.append(orderByFields[i]);
803    
804                                    if ((i + 1) < orderByFields.length) {
805                                            if (orderByComparator.isAscending() ^ previous) {
806                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
807                                            }
808                                            else {
809                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
810                                            }
811                                    }
812                                    else {
813                                            if (orderByComparator.isAscending() ^ previous) {
814                                                    query.append(ORDER_BY_ASC);
815                                            }
816                                            else {
817                                                    query.append(ORDER_BY_DESC);
818                                            }
819                                    }
820                            }
821                    }
822    
823                    String sql = query.toString();
824    
825                    Query q = session.createQuery(sql);
826    
827                    q.setFirstResult(0);
828                    q.setMaxResults(2);
829    
830                    QueryPos qPos = QueryPos.getInstance(q);
831    
832                    qPos.add(tableId);
833    
834                    if (orderByComparator != null) {
835                            Object[] values = orderByComparator.getOrderByConditionValues(expandoRow);
836    
837                            for (Object value : values) {
838                                    qPos.add(value);
839                            }
840                    }
841    
842                    List<ExpandoRow> list = q.list();
843    
844                    if (list.size() == 2) {
845                            return list.get(1);
846                    }
847                    else {
848                            return null;
849                    }
850            }
851    
852            /**
853             * 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.
854             *
855             * @param tableId the table ID
856             * @param classPK the class p k
857             * @return the matching expando row
858             * @throws com.liferay.portlet.expando.NoSuchRowException if a matching expando row could not be found
859             * @throws SystemException if a system exception occurred
860             */
861            public ExpandoRow findByT_C(long tableId, long classPK)
862                    throws NoSuchRowException, SystemException {
863                    ExpandoRow expandoRow = fetchByT_C(tableId, classPK);
864    
865                    if (expandoRow == null) {
866                            StringBundler msg = new StringBundler(6);
867    
868                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
869    
870                            msg.append("tableId=");
871                            msg.append(tableId);
872    
873                            msg.append(", classPK=");
874                            msg.append(classPK);
875    
876                            msg.append(StringPool.CLOSE_CURLY_BRACE);
877    
878                            if (_log.isWarnEnabled()) {
879                                    _log.warn(msg.toString());
880                            }
881    
882                            throw new NoSuchRowException(msg.toString());
883                    }
884    
885                    return expandoRow;
886            }
887    
888            /**
889             * 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.
890             *
891             * @param tableId the table ID
892             * @param classPK the class p k
893             * @return the matching expando row, or <code>null</code> if a matching expando row could not be found
894             * @throws SystemException if a system exception occurred
895             */
896            public ExpandoRow fetchByT_C(long tableId, long classPK)
897                    throws SystemException {
898                    return fetchByT_C(tableId, classPK, true);
899            }
900    
901            /**
902             * 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.
903             *
904             * @param tableId the table ID
905             * @param classPK the class p k
906             * @param retrieveFromCache whether to use the finder cache
907             * @return the matching expando row, or <code>null</code> if a matching expando row could not be found
908             * @throws SystemException if a system exception occurred
909             */
910            public ExpandoRow fetchByT_C(long tableId, long classPK,
911                    boolean retrieveFromCache) throws SystemException {
912                    Object[] finderArgs = new Object[] { tableId, classPK };
913    
914                    Object result = null;
915    
916                    if (retrieveFromCache) {
917                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_T_C,
918                                            finderArgs, this);
919                    }
920    
921                    if (result instanceof ExpandoRow) {
922                            ExpandoRow expandoRow = (ExpandoRow)result;
923    
924                            if ((tableId != expandoRow.getTableId()) ||
925                                            (classPK != expandoRow.getClassPK())) {
926                                    result = null;
927                            }
928                    }
929    
930                    if (result == null) {
931                            StringBundler query = new StringBundler(3);
932    
933                            query.append(_SQL_SELECT_EXPANDOROW_WHERE);
934    
935                            query.append(_FINDER_COLUMN_T_C_TABLEID_2);
936    
937                            query.append(_FINDER_COLUMN_T_C_CLASSPK_2);
938    
939                            String sql = query.toString();
940    
941                            Session session = null;
942    
943                            try {
944                                    session = openSession();
945    
946                                    Query q = session.createQuery(sql);
947    
948                                    QueryPos qPos = QueryPos.getInstance(q);
949    
950                                    qPos.add(tableId);
951    
952                                    qPos.add(classPK);
953    
954                                    List<ExpandoRow> list = q.list();
955    
956                                    result = list;
957    
958                                    ExpandoRow expandoRow = null;
959    
960                                    if (list.isEmpty()) {
961                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
962                                                    finderArgs, list);
963                                    }
964                                    else {
965                                            expandoRow = list.get(0);
966    
967                                            cacheResult(expandoRow);
968    
969                                            if ((expandoRow.getTableId() != tableId) ||
970                                                            (expandoRow.getClassPK() != classPK)) {
971                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
972                                                            finderArgs, expandoRow);
973                                            }
974                                    }
975    
976                                    return expandoRow;
977                            }
978                            catch (Exception e) {
979                                    throw processException(e);
980                            }
981                            finally {
982                                    if (result == null) {
983                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C,
984                                                    finderArgs);
985                                    }
986    
987                                    closeSession(session);
988                            }
989                    }
990                    else {
991                            if (result instanceof List<?>) {
992                                    return null;
993                            }
994                            else {
995                                    return (ExpandoRow)result;
996                            }
997                    }
998            }
999    
1000            /**
1001             * Returns all the expando rows.
1002             *
1003             * @return the expando rows
1004             * @throws SystemException if a system exception occurred
1005             */
1006            public List<ExpandoRow> findAll() throws SystemException {
1007                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1008            }
1009    
1010            /**
1011             * Returns a range of all the expando rows.
1012             *
1013             * <p>
1014             * 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.
1015             * </p>
1016             *
1017             * @param start the lower bound of the range of expando rows
1018             * @param end the upper bound of the range of expando rows (not inclusive)
1019             * @return the range of expando rows
1020             * @throws SystemException if a system exception occurred
1021             */
1022            public List<ExpandoRow> findAll(int start, int end)
1023                    throws SystemException {
1024                    return findAll(start, end, null);
1025            }
1026    
1027            /**
1028             * Returns an ordered range of all the expando rows.
1029             *
1030             * <p>
1031             * 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.
1032             * </p>
1033             *
1034             * @param start the lower bound of the range of expando rows
1035             * @param end the upper bound of the range of expando rows (not inclusive)
1036             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1037             * @return the ordered range of expando rows
1038             * @throws SystemException if a system exception occurred
1039             */
1040            public List<ExpandoRow> findAll(int start, int end,
1041                    OrderByComparator orderByComparator) throws SystemException {
1042                    FinderPath finderPath = null;
1043                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1044    
1045                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1046                                    (orderByComparator == null)) {
1047                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1048                            finderArgs = FINDER_ARGS_EMPTY;
1049                    }
1050                    else {
1051                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1052                            finderArgs = new Object[] { start, end, orderByComparator };
1053                    }
1054    
1055                    List<ExpandoRow> list = (List<ExpandoRow>)FinderCacheUtil.getResult(finderPath,
1056                                    finderArgs, this);
1057    
1058                    if (list == null) {
1059                            StringBundler query = null;
1060                            String sql = null;
1061    
1062                            if (orderByComparator != null) {
1063                                    query = new StringBundler(2 +
1064                                                    (orderByComparator.getOrderByFields().length * 3));
1065    
1066                                    query.append(_SQL_SELECT_EXPANDOROW);
1067    
1068                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1069                                            orderByComparator);
1070    
1071                                    sql = query.toString();
1072                            }
1073                            else {
1074                                    sql = _SQL_SELECT_EXPANDOROW;
1075                            }
1076    
1077                            Session session = null;
1078    
1079                            try {
1080                                    session = openSession();
1081    
1082                                    Query q = session.createQuery(sql);
1083    
1084                                    if (orderByComparator == null) {
1085                                            list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(),
1086                                                            start, end, false);
1087    
1088                                            Collections.sort(list);
1089                                    }
1090                                    else {
1091                                            list = (List<ExpandoRow>)QueryUtil.list(q, getDialect(),
1092                                                            start, end);
1093                                    }
1094                            }
1095                            catch (Exception e) {
1096                                    throw processException(e);
1097                            }
1098                            finally {
1099                                    if (list == null) {
1100                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1101                                    }
1102                                    else {
1103                                            cacheResult(list);
1104    
1105                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1106                                    }
1107    
1108                                    closeSession(session);
1109                            }
1110                    }
1111    
1112                    return list;
1113            }
1114    
1115            /**
1116             * Removes all the expando rows where tableId = &#63; from the database.
1117             *
1118             * @param tableId the table ID
1119             * @throws SystemException if a system exception occurred
1120             */
1121            public void removeByTableId(long tableId) throws SystemException {
1122                    for (ExpandoRow expandoRow : findByTableId(tableId)) {
1123                            remove(expandoRow);
1124                    }
1125            }
1126    
1127            /**
1128             * Removes the expando row where tableId = &#63; and classPK = &#63; from the database.
1129             *
1130             * @param tableId the table ID
1131             * @param classPK the class p k
1132             * @throws SystemException if a system exception occurred
1133             */
1134            public void removeByT_C(long tableId, long classPK)
1135                    throws NoSuchRowException, SystemException {
1136                    ExpandoRow expandoRow = findByT_C(tableId, classPK);
1137    
1138                    remove(expandoRow);
1139            }
1140    
1141            /**
1142             * Removes all the expando rows from the database.
1143             *
1144             * @throws SystemException if a system exception occurred
1145             */
1146            public void removeAll() throws SystemException {
1147                    for (ExpandoRow expandoRow : findAll()) {
1148                            remove(expandoRow);
1149                    }
1150            }
1151    
1152            /**
1153             * Returns the number of expando rows where tableId = &#63;.
1154             *
1155             * @param tableId the table ID
1156             * @return the number of matching expando rows
1157             * @throws SystemException if a system exception occurred
1158             */
1159            public int countByTableId(long tableId) throws SystemException {
1160                    Object[] finderArgs = new Object[] { tableId };
1161    
1162                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TABLEID,
1163                                    finderArgs, this);
1164    
1165                    if (count == null) {
1166                            StringBundler query = new StringBundler(2);
1167    
1168                            query.append(_SQL_COUNT_EXPANDOROW_WHERE);
1169    
1170                            query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
1171    
1172                            String sql = query.toString();
1173    
1174                            Session session = null;
1175    
1176                            try {
1177                                    session = openSession();
1178    
1179                                    Query q = session.createQuery(sql);
1180    
1181                                    QueryPos qPos = QueryPos.getInstance(q);
1182    
1183                                    qPos.add(tableId);
1184    
1185                                    count = (Long)q.uniqueResult();
1186                            }
1187                            catch (Exception e) {
1188                                    throw processException(e);
1189                            }
1190                            finally {
1191                                    if (count == null) {
1192                                            count = Long.valueOf(0);
1193                                    }
1194    
1195                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TABLEID,
1196                                            finderArgs, count);
1197    
1198                                    closeSession(session);
1199                            }
1200                    }
1201    
1202                    return count.intValue();
1203            }
1204    
1205            /**
1206             * Returns the number of expando rows where tableId = &#63; and classPK = &#63;.
1207             *
1208             * @param tableId the table ID
1209             * @param classPK the class p k
1210             * @return the number of matching expando rows
1211             * @throws SystemException if a system exception occurred
1212             */
1213            public int countByT_C(long tableId, long classPK) throws SystemException {
1214                    Object[] finderArgs = new Object[] { tableId, classPK };
1215    
1216                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_C,
1217                                    finderArgs, this);
1218    
1219                    if (count == null) {
1220                            StringBundler query = new StringBundler(3);
1221    
1222                            query.append(_SQL_COUNT_EXPANDOROW_WHERE);
1223    
1224                            query.append(_FINDER_COLUMN_T_C_TABLEID_2);
1225    
1226                            query.append(_FINDER_COLUMN_T_C_CLASSPK_2);
1227    
1228                            String sql = query.toString();
1229    
1230                            Session session = null;
1231    
1232                            try {
1233                                    session = openSession();
1234    
1235                                    Query q = session.createQuery(sql);
1236    
1237                                    QueryPos qPos = QueryPos.getInstance(q);
1238    
1239                                    qPos.add(tableId);
1240    
1241                                    qPos.add(classPK);
1242    
1243                                    count = (Long)q.uniqueResult();
1244                            }
1245                            catch (Exception e) {
1246                                    throw processException(e);
1247                            }
1248                            finally {
1249                                    if (count == null) {
1250                                            count = Long.valueOf(0);
1251                                    }
1252    
1253                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_C, finderArgs,
1254                                            count);
1255    
1256                                    closeSession(session);
1257                            }
1258                    }
1259    
1260                    return count.intValue();
1261            }
1262    
1263            /**
1264             * Returns the number of expando rows.
1265             *
1266             * @return the number of expando rows
1267             * @throws SystemException if a system exception occurred
1268             */
1269            public int countAll() throws SystemException {
1270                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1271                                    FINDER_ARGS_EMPTY, this);
1272    
1273                    if (count == null) {
1274                            Session session = null;
1275    
1276                            try {
1277                                    session = openSession();
1278    
1279                                    Query q = session.createQuery(_SQL_COUNT_EXPANDOROW);
1280    
1281                                    count = (Long)q.uniqueResult();
1282                            }
1283                            catch (Exception e) {
1284                                    throw processException(e);
1285                            }
1286                            finally {
1287                                    if (count == null) {
1288                                            count = Long.valueOf(0);
1289                                    }
1290    
1291                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1292                                            FINDER_ARGS_EMPTY, count);
1293    
1294                                    closeSession(session);
1295                            }
1296                    }
1297    
1298                    return count.intValue();
1299            }
1300    
1301            /**
1302             * Initializes the expando row persistence.
1303             */
1304            public void afterPropertiesSet() {
1305                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1306                                            com.liferay.portal.util.PropsUtil.get(
1307                                                    "value.object.listener.com.liferay.portlet.expando.model.ExpandoRow")));
1308    
1309                    if (listenerClassNames.length > 0) {
1310                            try {
1311                                    List<ModelListener<ExpandoRow>> listenersList = new ArrayList<ModelListener<ExpandoRow>>();
1312    
1313                                    for (String listenerClassName : listenerClassNames) {
1314                                            listenersList.add((ModelListener<ExpandoRow>)InstanceFactory.newInstance(
1315                                                            listenerClassName));
1316                                    }
1317    
1318                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1319                            }
1320                            catch (Exception e) {
1321                                    _log.error(e);
1322                            }
1323                    }
1324            }
1325    
1326            public void destroy() {
1327                    EntityCacheUtil.removeCache(ExpandoRowImpl.class.getName());
1328                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1329                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1330            }
1331    
1332            @BeanReference(type = ExpandoColumnPersistence.class)
1333            protected ExpandoColumnPersistence expandoColumnPersistence;
1334            @BeanReference(type = ExpandoRowPersistence.class)
1335            protected ExpandoRowPersistence expandoRowPersistence;
1336            @BeanReference(type = ExpandoTablePersistence.class)
1337            protected ExpandoTablePersistence expandoTablePersistence;
1338            @BeanReference(type = ExpandoValuePersistence.class)
1339            protected ExpandoValuePersistence expandoValuePersistence;
1340            @BeanReference(type = ResourcePersistence.class)
1341            protected ResourcePersistence resourcePersistence;
1342            @BeanReference(type = UserPersistence.class)
1343            protected UserPersistence userPersistence;
1344            private static final String _SQL_SELECT_EXPANDOROW = "SELECT expandoRow FROM ExpandoRow expandoRow";
1345            private static final String _SQL_SELECT_EXPANDOROW_WHERE = "SELECT expandoRow FROM ExpandoRow expandoRow WHERE ";
1346            private static final String _SQL_COUNT_EXPANDOROW = "SELECT COUNT(expandoRow) FROM ExpandoRow expandoRow";
1347            private static final String _SQL_COUNT_EXPANDOROW_WHERE = "SELECT COUNT(expandoRow) FROM ExpandoRow expandoRow WHERE ";
1348            private static final String _FINDER_COLUMN_TABLEID_TABLEID_2 = "expandoRow.tableId = ?";
1349            private static final String _FINDER_COLUMN_T_C_TABLEID_2 = "expandoRow.tableId = ? AND ";
1350            private static final String _FINDER_COLUMN_T_C_CLASSPK_2 = "expandoRow.classPK = ?";
1351            private static final String _ORDER_BY_ENTITY_ALIAS = "expandoRow.";
1352            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoRow exists with the primary key ";
1353            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoRow exists with the key {";
1354            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1355            private static Log _log = LogFactoryUtil.getLog(ExpandoRowPersistenceImpl.class);
1356            private static ExpandoRow _nullExpandoRow = new ExpandoRowImpl() {
1357                            @Override
1358                            public Object clone() {
1359                                    return this;
1360                            }
1361    
1362                            @Override
1363                            public CacheModel<ExpandoRow> toCacheModel() {
1364                                    return _nullExpandoRowCacheModel;
1365                            }
1366                    };
1367    
1368            private static CacheModel<ExpandoRow> _nullExpandoRowCacheModel = new CacheModel<ExpandoRow>() {
1369                            public ExpandoRow toEntityModel() {
1370                                    return _nullExpandoRow;
1371                            }
1372                    };
1373    }