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