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