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