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