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