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            public DDLRecordVersionPersistenceImpl() {
1373                    setModelClass(DDLRecordVersion.class);
1374            }
1375    
1376            /**
1377             * Caches the d d l record version in the entity cache if it is enabled.
1378             *
1379             * @param ddlRecordVersion the d d l record version
1380             */
1381            @Override
1382            public void cacheResult(DDLRecordVersion ddlRecordVersion) {
1383                    EntityCacheUtil.putResult(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
1384                            DDLRecordVersionImpl.class, ddlRecordVersion.getPrimaryKey(),
1385                            ddlRecordVersion);
1386    
1387                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_V,
1388                            new Object[] {
1389                                    ddlRecordVersion.getRecordId(), ddlRecordVersion.getVersion()
1390                            }, ddlRecordVersion);
1391    
1392                    ddlRecordVersion.resetOriginalValues();
1393            }
1394    
1395            /**
1396             * Caches the d d l record versions in the entity cache if it is enabled.
1397             *
1398             * @param ddlRecordVersions the d d l record versions
1399             */
1400            @Override
1401            public void cacheResult(List<DDLRecordVersion> ddlRecordVersions) {
1402                    for (DDLRecordVersion ddlRecordVersion : ddlRecordVersions) {
1403                            if (EntityCacheUtil.getResult(
1404                                                    DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
1405                                                    DDLRecordVersionImpl.class,
1406                                                    ddlRecordVersion.getPrimaryKey()) == null) {
1407                                    cacheResult(ddlRecordVersion);
1408                            }
1409                            else {
1410                                    ddlRecordVersion.resetOriginalValues();
1411                            }
1412                    }
1413            }
1414    
1415            /**
1416             * Clears the cache for all d d l record versions.
1417             *
1418             * <p>
1419             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1420             * </p>
1421             */
1422            @Override
1423            public void clearCache() {
1424                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1425                            CacheRegistryUtil.clear(DDLRecordVersionImpl.class.getName());
1426                    }
1427    
1428                    EntityCacheUtil.clearCache(DDLRecordVersionImpl.class.getName());
1429    
1430                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1431                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1432                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1433            }
1434    
1435            /**
1436             * Clears the cache for the d d l record version.
1437             *
1438             * <p>
1439             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1440             * </p>
1441             */
1442            @Override
1443            public void clearCache(DDLRecordVersion ddlRecordVersion) {
1444                    EntityCacheUtil.removeResult(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
1445                            DDLRecordVersionImpl.class, ddlRecordVersion.getPrimaryKey());
1446    
1447                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1448                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1449    
1450                    clearUniqueFindersCache(ddlRecordVersion);
1451            }
1452    
1453            @Override
1454            public void clearCache(List<DDLRecordVersion> ddlRecordVersions) {
1455                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1456                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1457    
1458                    for (DDLRecordVersion ddlRecordVersion : ddlRecordVersions) {
1459                            EntityCacheUtil.removeResult(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
1460                                    DDLRecordVersionImpl.class, ddlRecordVersion.getPrimaryKey());
1461    
1462                            clearUniqueFindersCache(ddlRecordVersion);
1463                    }
1464            }
1465    
1466            protected void cacheUniqueFindersCache(DDLRecordVersion ddlRecordVersion) {
1467                    if (ddlRecordVersion.isNew()) {
1468                            Object[] args = new Object[] {
1469                                            ddlRecordVersion.getRecordId(),
1470                                            ddlRecordVersion.getVersion()
1471                                    };
1472    
1473                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_V, args,
1474                                    Long.valueOf(1));
1475                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_V, args,
1476                                    ddlRecordVersion);
1477                    }
1478                    else {
1479                            DDLRecordVersionModelImpl ddlRecordVersionModelImpl = (DDLRecordVersionModelImpl)ddlRecordVersion;
1480    
1481                            if ((ddlRecordVersionModelImpl.getColumnBitmask() &
1482                                            FINDER_PATH_FETCH_BY_R_V.getColumnBitmask()) != 0) {
1483                                    Object[] args = new Object[] {
1484                                                    ddlRecordVersion.getRecordId(),
1485                                                    ddlRecordVersion.getVersion()
1486                                            };
1487    
1488                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_V, args,
1489                                            Long.valueOf(1));
1490                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_V, args,
1491                                            ddlRecordVersion);
1492                            }
1493                    }
1494            }
1495    
1496            protected void clearUniqueFindersCache(DDLRecordVersion ddlRecordVersion) {
1497                    DDLRecordVersionModelImpl ddlRecordVersionModelImpl = (DDLRecordVersionModelImpl)ddlRecordVersion;
1498    
1499                    Object[] args = new Object[] {
1500                                    ddlRecordVersion.getRecordId(), ddlRecordVersion.getVersion()
1501                            };
1502    
1503                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_V, args);
1504                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_V, args);
1505    
1506                    if ((ddlRecordVersionModelImpl.getColumnBitmask() &
1507                                    FINDER_PATH_FETCH_BY_R_V.getColumnBitmask()) != 0) {
1508                            args = new Object[] {
1509                                            ddlRecordVersionModelImpl.getOriginalRecordId(),
1510                                            ddlRecordVersionModelImpl.getOriginalVersion()
1511                                    };
1512    
1513                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_V, args);
1514                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_V, args);
1515                    }
1516            }
1517    
1518            /**
1519             * Creates a new d d l record version with the primary key. Does not add the d d l record version to the database.
1520             *
1521             * @param recordVersionId the primary key for the new d d l record version
1522             * @return the new d d l record version
1523             */
1524            @Override
1525            public DDLRecordVersion create(long recordVersionId) {
1526                    DDLRecordVersion ddlRecordVersion = new DDLRecordVersionImpl();
1527    
1528                    ddlRecordVersion.setNew(true);
1529                    ddlRecordVersion.setPrimaryKey(recordVersionId);
1530    
1531                    return ddlRecordVersion;
1532            }
1533    
1534            /**
1535             * Removes the d d l record version with the primary key from the database. Also notifies the appropriate model listeners.
1536             *
1537             * @param recordVersionId the primary key of the d d l record version
1538             * @return the d d l record version that was removed
1539             * @throws com.liferay.portlet.dynamicdatalists.NoSuchRecordVersionException if a d d l record version with the primary key could not be found
1540             * @throws SystemException if a system exception occurred
1541             */
1542            @Override
1543            public DDLRecordVersion remove(long recordVersionId)
1544                    throws NoSuchRecordVersionException, SystemException {
1545                    return remove((Serializable)recordVersionId);
1546            }
1547    
1548            /**
1549             * Removes the d d l record version with the primary key from the database. Also notifies the appropriate model listeners.
1550             *
1551             * @param primaryKey the primary key of the d d l record version
1552             * @return the d d l record version that was removed
1553             * @throws com.liferay.portlet.dynamicdatalists.NoSuchRecordVersionException if a d d l record version with the primary key could not be found
1554             * @throws SystemException if a system exception occurred
1555             */
1556            @Override
1557            public DDLRecordVersion remove(Serializable primaryKey)
1558                    throws NoSuchRecordVersionException, SystemException {
1559                    Session session = null;
1560    
1561                    try {
1562                            session = openSession();
1563    
1564                            DDLRecordVersion ddlRecordVersion = (DDLRecordVersion)session.get(DDLRecordVersionImpl.class,
1565                                            primaryKey);
1566    
1567                            if (ddlRecordVersion == null) {
1568                                    if (_log.isWarnEnabled()) {
1569                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1570                                    }
1571    
1572                                    throw new NoSuchRecordVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1573                                            primaryKey);
1574                            }
1575    
1576                            return remove(ddlRecordVersion);
1577                    }
1578                    catch (NoSuchRecordVersionException nsee) {
1579                            throw nsee;
1580                    }
1581                    catch (Exception e) {
1582                            throw processException(e);
1583                    }
1584                    finally {
1585                            closeSession(session);
1586                    }
1587            }
1588    
1589            @Override
1590            protected DDLRecordVersion removeImpl(DDLRecordVersion ddlRecordVersion)
1591                    throws SystemException {
1592                    ddlRecordVersion = toUnwrappedModel(ddlRecordVersion);
1593    
1594                    Session session = null;
1595    
1596                    try {
1597                            session = openSession();
1598    
1599                            if (!session.contains(ddlRecordVersion)) {
1600                                    ddlRecordVersion = (DDLRecordVersion)session.get(DDLRecordVersionImpl.class,
1601                                                    ddlRecordVersion.getPrimaryKeyObj());
1602                            }
1603    
1604                            if (ddlRecordVersion != null) {
1605                                    session.delete(ddlRecordVersion);
1606                            }
1607                    }
1608                    catch (Exception e) {
1609                            throw processException(e);
1610                    }
1611                    finally {
1612                            closeSession(session);
1613                    }
1614    
1615                    if (ddlRecordVersion != null) {
1616                            clearCache(ddlRecordVersion);
1617                    }
1618    
1619                    return ddlRecordVersion;
1620            }
1621    
1622            @Override
1623            public DDLRecordVersion updateImpl(
1624                    com.liferay.portlet.dynamicdatalists.model.DDLRecordVersion ddlRecordVersion)
1625                    throws SystemException {
1626                    ddlRecordVersion = toUnwrappedModel(ddlRecordVersion);
1627    
1628                    boolean isNew = ddlRecordVersion.isNew();
1629    
1630                    DDLRecordVersionModelImpl ddlRecordVersionModelImpl = (DDLRecordVersionModelImpl)ddlRecordVersion;
1631    
1632                    Session session = null;
1633    
1634                    try {
1635                            session = openSession();
1636    
1637                            if (ddlRecordVersion.isNew()) {
1638                                    session.save(ddlRecordVersion);
1639    
1640                                    ddlRecordVersion.setNew(false);
1641                            }
1642                            else {
1643                                    session.merge(ddlRecordVersion);
1644                            }
1645                    }
1646                    catch (Exception e) {
1647                            throw processException(e);
1648                    }
1649                    finally {
1650                            closeSession(session);
1651                    }
1652    
1653                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1654    
1655                    if (isNew || !DDLRecordVersionModelImpl.COLUMN_BITMASK_ENABLED) {
1656                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1657                    }
1658    
1659                    else {
1660                            if ((ddlRecordVersionModelImpl.getColumnBitmask() &
1661                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECORDID.getColumnBitmask()) != 0) {
1662                                    Object[] args = new Object[] {
1663                                                    ddlRecordVersionModelImpl.getOriginalRecordId()
1664                                            };
1665    
1666                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RECORDID, args);
1667                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECORDID,
1668                                            args);
1669    
1670                                    args = new Object[] { ddlRecordVersionModelImpl.getRecordId() };
1671    
1672                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RECORDID, args);
1673                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECORDID,
1674                                            args);
1675                            }
1676    
1677                            if ((ddlRecordVersionModelImpl.getColumnBitmask() &
1678                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S.getColumnBitmask()) != 0) {
1679                                    Object[] args = new Object[] {
1680                                                    ddlRecordVersionModelImpl.getOriginalRecordId(),
1681                                                    ddlRecordVersionModelImpl.getOriginalStatus()
1682                                            };
1683    
1684                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_S, args);
1685                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S,
1686                                            args);
1687    
1688                                    args = new Object[] {
1689                                                    ddlRecordVersionModelImpl.getRecordId(),
1690                                                    ddlRecordVersionModelImpl.getStatus()
1691                                            };
1692    
1693                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_S, args);
1694                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S,
1695                                            args);
1696                            }
1697                    }
1698    
1699                    EntityCacheUtil.putResult(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
1700                            DDLRecordVersionImpl.class, ddlRecordVersion.getPrimaryKey(),
1701                            ddlRecordVersion);
1702    
1703                    clearUniqueFindersCache(ddlRecordVersion);
1704                    cacheUniqueFindersCache(ddlRecordVersion);
1705    
1706                    return ddlRecordVersion;
1707            }
1708    
1709            protected DDLRecordVersion toUnwrappedModel(
1710                    DDLRecordVersion ddlRecordVersion) {
1711                    if (ddlRecordVersion instanceof DDLRecordVersionImpl) {
1712                            return ddlRecordVersion;
1713                    }
1714    
1715                    DDLRecordVersionImpl ddlRecordVersionImpl = new DDLRecordVersionImpl();
1716    
1717                    ddlRecordVersionImpl.setNew(ddlRecordVersion.isNew());
1718                    ddlRecordVersionImpl.setPrimaryKey(ddlRecordVersion.getPrimaryKey());
1719    
1720                    ddlRecordVersionImpl.setRecordVersionId(ddlRecordVersion.getRecordVersionId());
1721                    ddlRecordVersionImpl.setGroupId(ddlRecordVersion.getGroupId());
1722                    ddlRecordVersionImpl.setCompanyId(ddlRecordVersion.getCompanyId());
1723                    ddlRecordVersionImpl.setUserId(ddlRecordVersion.getUserId());
1724                    ddlRecordVersionImpl.setUserName(ddlRecordVersion.getUserName());
1725                    ddlRecordVersionImpl.setCreateDate(ddlRecordVersion.getCreateDate());
1726                    ddlRecordVersionImpl.setDDMStorageId(ddlRecordVersion.getDDMStorageId());
1727                    ddlRecordVersionImpl.setRecordSetId(ddlRecordVersion.getRecordSetId());
1728                    ddlRecordVersionImpl.setRecordId(ddlRecordVersion.getRecordId());
1729                    ddlRecordVersionImpl.setVersion(ddlRecordVersion.getVersion());
1730                    ddlRecordVersionImpl.setDisplayIndex(ddlRecordVersion.getDisplayIndex());
1731                    ddlRecordVersionImpl.setStatus(ddlRecordVersion.getStatus());
1732                    ddlRecordVersionImpl.setStatusByUserId(ddlRecordVersion.getStatusByUserId());
1733                    ddlRecordVersionImpl.setStatusByUserName(ddlRecordVersion.getStatusByUserName());
1734                    ddlRecordVersionImpl.setStatusDate(ddlRecordVersion.getStatusDate());
1735    
1736                    return ddlRecordVersionImpl;
1737            }
1738    
1739            /**
1740             * 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.
1741             *
1742             * @param primaryKey the primary key of the d d l record version
1743             * @return the d d l record version
1744             * @throws com.liferay.portlet.dynamicdatalists.NoSuchRecordVersionException if a d d l record version with the primary key could not be found
1745             * @throws SystemException if a system exception occurred
1746             */
1747            @Override
1748            public DDLRecordVersion findByPrimaryKey(Serializable primaryKey)
1749                    throws NoSuchRecordVersionException, SystemException {
1750                    DDLRecordVersion ddlRecordVersion = fetchByPrimaryKey(primaryKey);
1751    
1752                    if (ddlRecordVersion == null) {
1753                            if (_log.isWarnEnabled()) {
1754                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1755                            }
1756    
1757                            throw new NoSuchRecordVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1758                                    primaryKey);
1759                    }
1760    
1761                    return ddlRecordVersion;
1762            }
1763    
1764            /**
1765             * 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.
1766             *
1767             * @param recordVersionId the primary key of the d d l record version
1768             * @return the d d l record version
1769             * @throws com.liferay.portlet.dynamicdatalists.NoSuchRecordVersionException if a d d l record version with the primary key could not be found
1770             * @throws SystemException if a system exception occurred
1771             */
1772            @Override
1773            public DDLRecordVersion findByPrimaryKey(long recordVersionId)
1774                    throws NoSuchRecordVersionException, SystemException {
1775                    return findByPrimaryKey((Serializable)recordVersionId);
1776            }
1777    
1778            /**
1779             * Returns the d d l record version with the primary key or returns <code>null</code> if it could not be found.
1780             *
1781             * @param primaryKey the primary key of the d d l record version
1782             * @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
1783             * @throws SystemException if a system exception occurred
1784             */
1785            @Override
1786            public DDLRecordVersion fetchByPrimaryKey(Serializable primaryKey)
1787                    throws SystemException {
1788                    DDLRecordVersion ddlRecordVersion = (DDLRecordVersion)EntityCacheUtil.getResult(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
1789                                    DDLRecordVersionImpl.class, primaryKey);
1790    
1791                    if (ddlRecordVersion == _nullDDLRecordVersion) {
1792                            return null;
1793                    }
1794    
1795                    if (ddlRecordVersion == null) {
1796                            Session session = null;
1797    
1798                            try {
1799                                    session = openSession();
1800    
1801                                    ddlRecordVersion = (DDLRecordVersion)session.get(DDLRecordVersionImpl.class,
1802                                                    primaryKey);
1803    
1804                                    if (ddlRecordVersion != null) {
1805                                            cacheResult(ddlRecordVersion);
1806                                    }
1807                                    else {
1808                                            EntityCacheUtil.putResult(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
1809                                                    DDLRecordVersionImpl.class, primaryKey,
1810                                                    _nullDDLRecordVersion);
1811                                    }
1812                            }
1813                            catch (Exception e) {
1814                                    EntityCacheUtil.removeResult(DDLRecordVersionModelImpl.ENTITY_CACHE_ENABLED,
1815                                            DDLRecordVersionImpl.class, primaryKey);
1816    
1817                                    throw processException(e);
1818                            }
1819                            finally {
1820                                    closeSession(session);
1821                            }
1822                    }
1823    
1824                    return ddlRecordVersion;
1825            }
1826    
1827            /**
1828             * Returns the d d l record version with the primary key or returns <code>null</code> if it could not be found.
1829             *
1830             * @param recordVersionId the primary key of the d d l record version
1831             * @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
1832             * @throws SystemException if a system exception occurred
1833             */
1834            @Override
1835            public DDLRecordVersion fetchByPrimaryKey(long recordVersionId)
1836                    throws SystemException {
1837                    return fetchByPrimaryKey((Serializable)recordVersionId);
1838            }
1839    
1840            /**
1841             * Returns all the d d l record versions.
1842             *
1843             * @return the d d l record versions
1844             * @throws SystemException if a system exception occurred
1845             */
1846            @Override
1847            public List<DDLRecordVersion> findAll() throws SystemException {
1848                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1849            }
1850    
1851            /**
1852             * Returns a range of all the d d l record versions.
1853             *
1854             * <p>
1855             * 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.
1856             * </p>
1857             *
1858             * @param start the lower bound of the range of d d l record versions
1859             * @param end the upper bound of the range of d d l record versions (not inclusive)
1860             * @return the range of d d l record versions
1861             * @throws SystemException if a system exception occurred
1862             */
1863            @Override
1864            public List<DDLRecordVersion> findAll(int start, int end)
1865                    throws SystemException {
1866                    return findAll(start, end, null);
1867            }
1868    
1869            /**
1870             * Returns an ordered range of all the d d l record versions.
1871             *
1872             * <p>
1873             * 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.
1874             * </p>
1875             *
1876             * @param start the lower bound of the range of d d l record versions
1877             * @param end the upper bound of the range of d d l record versions (not inclusive)
1878             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1879             * @return the ordered range of d d l record versions
1880             * @throws SystemException if a system exception occurred
1881             */
1882            @Override
1883            public List<DDLRecordVersion> findAll(int start, int end,
1884                    OrderByComparator orderByComparator) throws SystemException {
1885                    boolean pagination = true;
1886                    FinderPath finderPath = null;
1887                    Object[] finderArgs = null;
1888    
1889                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1890                                    (orderByComparator == null)) {
1891                            pagination = false;
1892                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1893                            finderArgs = FINDER_ARGS_EMPTY;
1894                    }
1895                    else {
1896                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1897                            finderArgs = new Object[] { start, end, orderByComparator };
1898                    }
1899    
1900                    List<DDLRecordVersion> list = (List<DDLRecordVersion>)FinderCacheUtil.getResult(finderPath,
1901                                    finderArgs, this);
1902    
1903                    if (list == null) {
1904                            StringBundler query = null;
1905                            String sql = null;
1906    
1907                            if (orderByComparator != null) {
1908                                    query = new StringBundler(2 +
1909                                                    (orderByComparator.getOrderByFields().length * 3));
1910    
1911                                    query.append(_SQL_SELECT_DDLRECORDVERSION);
1912    
1913                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1914                                            orderByComparator);
1915    
1916                                    sql = query.toString();
1917                            }
1918                            else {
1919                                    sql = _SQL_SELECT_DDLRECORDVERSION;
1920    
1921                                    if (pagination) {
1922                                            sql = sql.concat(DDLRecordVersionModelImpl.ORDER_BY_JPQL);
1923                                    }
1924                            }
1925    
1926                            Session session = null;
1927    
1928                            try {
1929                                    session = openSession();
1930    
1931                                    Query q = session.createQuery(sql);
1932    
1933                                    if (!pagination) {
1934                                            list = (List<DDLRecordVersion>)QueryUtil.list(q,
1935                                                            getDialect(), start, end, false);
1936    
1937                                            Collections.sort(list);
1938    
1939                                            list = new UnmodifiableList<DDLRecordVersion>(list);
1940                                    }
1941                                    else {
1942                                            list = (List<DDLRecordVersion>)QueryUtil.list(q,
1943                                                            getDialect(), start, end);
1944                                    }
1945    
1946                                    cacheResult(list);
1947    
1948                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1949                            }
1950                            catch (Exception e) {
1951                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1952    
1953                                    throw processException(e);
1954                            }
1955                            finally {
1956                                    closeSession(session);
1957                            }
1958                    }
1959    
1960                    return list;
1961            }
1962    
1963            /**
1964             * Removes all the d d l record versions from the database.
1965             *
1966             * @throws SystemException if a system exception occurred
1967             */
1968            @Override
1969            public void removeAll() throws SystemException {
1970                    for (DDLRecordVersion ddlRecordVersion : findAll()) {
1971                            remove(ddlRecordVersion);
1972                    }
1973            }
1974    
1975            /**
1976             * Returns the number of d d l record versions.
1977             *
1978             * @return the number of d d l record versions
1979             * @throws SystemException if a system exception occurred
1980             */
1981            @Override
1982            public int countAll() throws SystemException {
1983                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1984                                    FINDER_ARGS_EMPTY, this);
1985    
1986                    if (count == null) {
1987                            Session session = null;
1988    
1989                            try {
1990                                    session = openSession();
1991    
1992                                    Query q = session.createQuery(_SQL_COUNT_DDLRECORDVERSION);
1993    
1994                                    count = (Long)q.uniqueResult();
1995    
1996                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1997                                            FINDER_ARGS_EMPTY, count);
1998                            }
1999                            catch (Exception e) {
2000                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2001                                            FINDER_ARGS_EMPTY);
2002    
2003                                    throw processException(e);
2004                            }
2005                            finally {
2006                                    closeSession(session);
2007                            }
2008                    }
2009    
2010                    return count.intValue();
2011            }
2012    
2013            /**
2014             * Initializes the d d l record version persistence.
2015             */
2016            public void afterPropertiesSet() {
2017                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2018                                            com.liferay.portal.util.PropsUtil.get(
2019                                                    "value.object.listener.com.liferay.portlet.dynamicdatalists.model.DDLRecordVersion")));
2020    
2021                    if (listenerClassNames.length > 0) {
2022                            try {
2023                                    List<ModelListener<DDLRecordVersion>> listenersList = new ArrayList<ModelListener<DDLRecordVersion>>();
2024    
2025                                    for (String listenerClassName : listenerClassNames) {
2026                                            listenersList.add((ModelListener<DDLRecordVersion>)InstanceFactory.newInstance(
2027                                                            getClassLoader(), listenerClassName));
2028                                    }
2029    
2030                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2031                            }
2032                            catch (Exception e) {
2033                                    _log.error(e);
2034                            }
2035                    }
2036            }
2037    
2038            public void destroy() {
2039                    EntityCacheUtil.removeCache(DDLRecordVersionImpl.class.getName());
2040                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2041                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2042                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2043            }
2044    
2045            private static final String _SQL_SELECT_DDLRECORDVERSION = "SELECT ddlRecordVersion FROM DDLRecordVersion ddlRecordVersion";
2046            private static final String _SQL_SELECT_DDLRECORDVERSION_WHERE = "SELECT ddlRecordVersion FROM DDLRecordVersion ddlRecordVersion WHERE ";
2047            private static final String _SQL_COUNT_DDLRECORDVERSION = "SELECT COUNT(ddlRecordVersion) FROM DDLRecordVersion ddlRecordVersion";
2048            private static final String _SQL_COUNT_DDLRECORDVERSION_WHERE = "SELECT COUNT(ddlRecordVersion) FROM DDLRecordVersion ddlRecordVersion WHERE ";
2049            private static final String _ORDER_BY_ENTITY_ALIAS = "ddlRecordVersion.";
2050            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DDLRecordVersion exists with the primary key ";
2051            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DDLRecordVersion exists with the key {";
2052            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2053            private static Log _log = LogFactoryUtil.getLog(DDLRecordVersionPersistenceImpl.class);
2054            private static DDLRecordVersion _nullDDLRecordVersion = new DDLRecordVersionImpl() {
2055                            @Override
2056                            public Object clone() {
2057                                    return this;
2058                            }
2059    
2060                            @Override
2061                            public CacheModel<DDLRecordVersion> toCacheModel() {
2062                                    return _nullDDLRecordVersionCacheModel;
2063                            }
2064                    };
2065    
2066            private static CacheModel<DDLRecordVersion> _nullDDLRecordVersionCacheModel = new CacheModel<DDLRecordVersion>() {
2067                            @Override
2068                            public DDLRecordVersion toEntityModel() {
2069                                    return _nullDDLRecordVersion;
2070                            }
2071                    };
2072    }