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