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