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