001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.dynamicdatalists.service.persistence;
016    
017    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderPath;
021    import com.liferay.portal.kernel.dao.orm.Query;
022    import com.liferay.portal.kernel.dao.orm.QueryPos;
023    import com.liferay.portal.kernel.dao.orm.QueryUtil;
024    import com.liferay.portal.kernel.dao.orm.Session;
025    import com.liferay.portal.kernel.exception.SystemException;
026    import com.liferay.portal.kernel.log.Log;
027    import com.liferay.portal.kernel.log.LogFactoryUtil;
028    import com.liferay.portal.kernel.util.GetterUtil;
029    import com.liferay.portal.kernel.util.InstanceFactory;
030    import com.liferay.portal.kernel.util.OrderByComparator;
031    import com.liferay.portal.kernel.util.SetUtil;
032    import com.liferay.portal.kernel.util.StringBundler;
033    import com.liferay.portal.kernel.util.StringPool;
034    import com.liferay.portal.kernel.util.StringUtil;
035    import com.liferay.portal.kernel.util.UnmodifiableList;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038    import com.liferay.portal.model.CacheModel;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041    
042    import com.liferay.portlet.dynamicdatalists.NoSuchRecordException;
043    import com.liferay.portlet.dynamicdatalists.model.DDLRecord;
044    import com.liferay.portlet.dynamicdatalists.model.impl.DDLRecordImpl;
045    import com.liferay.portlet.dynamicdatalists.model.impl.DDLRecordModelImpl;
046    
047    import java.io.Serializable;
048    
049    import java.util.ArrayList;
050    import java.util.Collections;
051    import java.util.List;
052    import java.util.Set;
053    
054    /**
055     * The persistence implementation for the d d l record service.
056     *
057     * <p>
058     * Caching information and settings can be found in <code>portal.properties</code>
059     * </p>
060     *
061     * @author Brian Wing Shun Chan
062     * @see DDLRecordPersistence
063     * @see DDLRecordUtil
064     * @generated
065     */
066    public class DDLRecordPersistenceImpl extends BasePersistenceImpl<DDLRecord>
067            implements DDLRecordPersistence {
068            /*
069             * NOTE FOR DEVELOPERS:
070             *
071             * Never modify or reference this class directly. Always use {@link DDLRecordUtil} to access the d d l record persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
072             */
073            public static final String FINDER_CLASS_NAME_ENTITY = DDLRecordImpl.class.getName();
074            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075                    ".List1";
076            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List2";
078            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
079                            DDLRecordModelImpl.FINDER_CACHE_ENABLED, DDLRecordImpl.class,
080                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
081            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
082                            DDLRecordModelImpl.FINDER_CACHE_ENABLED, DDLRecordImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
085                            DDLRecordModelImpl.FINDER_CACHE_ENABLED, Long.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
088                            DDLRecordModelImpl.FINDER_CACHE_ENABLED, DDLRecordImpl.class,
089                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
090                            new String[] {
091                                    String.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_UUID = new FinderPath(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
097                            DDLRecordModelImpl.FINDER_CACHE_ENABLED, DDLRecordImpl.class,
098                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
099                            new String[] { String.class.getName() },
100                            DDLRecordModelImpl.UUID_COLUMN_BITMASK);
101            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
102                            DDLRecordModelImpl.FINDER_CACHE_ENABLED, Long.class,
103                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
104                            new String[] { String.class.getName() });
105    
106            /**
107             * Returns all the d d l records where uuid = &#63;.
108             *
109             * @param uuid the uuid
110             * @return the matching d d l records
111             * @throws SystemException if a system exception occurred
112             */
113            @Override
114            public List<DDLRecord> findByUuid(String uuid) throws SystemException {
115                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
116            }
117    
118            /**
119             * Returns a range of all the d d l records where uuid = &#63;.
120             *
121             * <p>
122             * 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.DDLRecordModelImpl}. 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.
123             * </p>
124             *
125             * @param uuid the uuid
126             * @param start the lower bound of the range of d d l records
127             * @param end the upper bound of the range of d d l records (not inclusive)
128             * @return the range of matching d d l records
129             * @throws SystemException if a system exception occurred
130             */
131            @Override
132            public List<DDLRecord> findByUuid(String uuid, int start, int end)
133                    throws SystemException {
134                    return findByUuid(uuid, start, end, null);
135            }
136    
137            /**
138             * Returns an ordered range of all the d d l records where uuid = &#63;.
139             *
140             * <p>
141             * 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.DDLRecordModelImpl}. 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.
142             * </p>
143             *
144             * @param uuid the uuid
145             * @param start the lower bound of the range of d d l records
146             * @param end the upper bound of the range of d d l records (not inclusive)
147             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
148             * @return the ordered range of matching d d l records
149             * @throws SystemException if a system exception occurred
150             */
151            @Override
152            public List<DDLRecord> findByUuid(String uuid, int start, int end,
153                    OrderByComparator orderByComparator) throws SystemException {
154                    boolean pagination = true;
155                    FinderPath finderPath = null;
156                    Object[] finderArgs = null;
157    
158                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
159                                    (orderByComparator == null)) {
160                            pagination = false;
161                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
162                            finderArgs = new Object[] { uuid };
163                    }
164                    else {
165                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
166                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
167                    }
168    
169                    List<DDLRecord> list = (List<DDLRecord>)FinderCacheUtil.getResult(finderPath,
170                                    finderArgs, this);
171    
172                    if ((list != null) && !list.isEmpty()) {
173                            for (DDLRecord ddlRecord : list) {
174                                    if (!Validator.equals(uuid, ddlRecord.getUuid())) {
175                                            list = null;
176    
177                                            break;
178                                    }
179                            }
180                    }
181    
182                    if (list == null) {
183                            StringBundler query = null;
184    
185                            if (orderByComparator != null) {
186                                    query = new StringBundler(3 +
187                                                    (orderByComparator.getOrderByFields().length * 3));
188                            }
189                            else {
190                                    query = new StringBundler(3);
191                            }
192    
193                            query.append(_SQL_SELECT_DDLRECORD_WHERE);
194    
195                            boolean bindUuid = false;
196    
197                            if (uuid == null) {
198                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
199                            }
200                            else if (uuid.equals(StringPool.BLANK)) {
201                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
202                            }
203                            else {
204                                    bindUuid = true;
205    
206                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
207                            }
208    
209                            if (orderByComparator != null) {
210                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
211                                            orderByComparator);
212                            }
213                            else
214                             if (pagination) {
215                                    query.append(DDLRecordModelImpl.ORDER_BY_JPQL);
216                            }
217    
218                            String sql = query.toString();
219    
220                            Session session = null;
221    
222                            try {
223                                    session = openSession();
224    
225                                    Query q = session.createQuery(sql);
226    
227                                    QueryPos qPos = QueryPos.getInstance(q);
228    
229                                    if (bindUuid) {
230                                            qPos.add(uuid);
231                                    }
232    
233                                    if (!pagination) {
234                                            list = (List<DDLRecord>)QueryUtil.list(q, getDialect(),
235                                                            start, end, false);
236    
237                                            Collections.sort(list);
238    
239                                            list = new UnmodifiableList<DDLRecord>(list);
240                                    }
241                                    else {
242                                            list = (List<DDLRecord>)QueryUtil.list(q, getDialect(),
243                                                            start, end);
244                                    }
245    
246                                    cacheResult(list);
247    
248                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
249                            }
250                            catch (Exception e) {
251                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
252    
253                                    throw processException(e);
254                            }
255                            finally {
256                                    closeSession(session);
257                            }
258                    }
259    
260                    return list;
261            }
262    
263            /**
264             * Returns the first d d l record in the ordered set where uuid = &#63;.
265             *
266             * @param uuid the uuid
267             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
268             * @return the first matching d d l record
269             * @throws com.liferay.portlet.dynamicdatalists.NoSuchRecordException if a matching d d l record could not be found
270             * @throws SystemException if a system exception occurred
271             */
272            @Override
273            public DDLRecord findByUuid_First(String uuid,
274                    OrderByComparator orderByComparator)
275                    throws NoSuchRecordException, SystemException {
276                    DDLRecord ddlRecord = fetchByUuid_First(uuid, orderByComparator);
277    
278                    if (ddlRecord != null) {
279                            return ddlRecord;
280                    }
281    
282                    StringBundler msg = new StringBundler(4);
283    
284                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
285    
286                    msg.append("uuid=");
287                    msg.append(uuid);
288    
289                    msg.append(StringPool.CLOSE_CURLY_BRACE);
290    
291                    throw new NoSuchRecordException(msg.toString());
292            }
293    
294            /**
295             * Returns the first d d l record in the ordered set where uuid = &#63;.
296             *
297             * @param uuid the uuid
298             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
299             * @return the first matching d d l record, or <code>null</code> if a matching d d l record could not be found
300             * @throws SystemException if a system exception occurred
301             */
302            @Override
303            public DDLRecord fetchByUuid_First(String uuid,
304                    OrderByComparator orderByComparator) throws SystemException {
305                    List<DDLRecord> list = findByUuid(uuid, 0, 1, orderByComparator);
306    
307                    if (!list.isEmpty()) {
308                            return list.get(0);
309                    }
310    
311                    return null;
312            }
313    
314            /**
315             * Returns the last d d l record in the ordered set where uuid = &#63;.
316             *
317             * @param uuid the uuid
318             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
319             * @return the last matching d d l record
320             * @throws com.liferay.portlet.dynamicdatalists.NoSuchRecordException if a matching d d l record could not be found
321             * @throws SystemException if a system exception occurred
322             */
323            @Override
324            public DDLRecord findByUuid_Last(String uuid,
325                    OrderByComparator orderByComparator)
326                    throws NoSuchRecordException, SystemException {
327                    DDLRecord ddlRecord = fetchByUuid_Last(uuid, orderByComparator);
328    
329                    if (ddlRecord != null) {
330                            return ddlRecord;
331                    }
332    
333                    StringBundler msg = new StringBundler(4);
334    
335                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
336    
337                    msg.append("uuid=");
338                    msg.append(uuid);
339    
340                    msg.append(StringPool.CLOSE_CURLY_BRACE);
341    
342                    throw new NoSuchRecordException(msg.toString());
343            }
344    
345            /**
346             * Returns the last d d l record in the ordered set where uuid = &#63;.
347             *
348             * @param uuid the uuid
349             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
350             * @return the last matching d d l record, or <code>null</code> if a matching d d l record could not be found
351             * @throws SystemException if a system exception occurred
352             */
353            @Override
354            public DDLRecord fetchByUuid_Last(String uuid,
355                    OrderByComparator orderByComparator) throws SystemException {
356                    int count = countByUuid(uuid);
357    
358                    if (count == 0) {
359                            return null;
360                    }
361    
362                    List<DDLRecord> list = findByUuid(uuid, count - 1, count,
363                                    orderByComparator);
364    
365                    if (!list.isEmpty()) {
366                            return list.get(0);
367                    }
368    
369                    return null;
370            }
371    
372            /**
373             * Returns the d d l records before and after the current d d l record in the ordered set where uuid = &#63;.
374             *
375             * @param recordId the primary key of the current d d l record
376             * @param uuid the uuid
377             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
378             * @return the previous, current, and next d d l record
379             * @throws com.liferay.portlet.dynamicdatalists.NoSuchRecordException if a d d l record with the primary key could not be found
380             * @throws SystemException if a system exception occurred
381             */
382            @Override
383            public DDLRecord[] findByUuid_PrevAndNext(long recordId, String uuid,
384                    OrderByComparator orderByComparator)
385                    throws NoSuchRecordException, SystemException {
386                    DDLRecord ddlRecord = findByPrimaryKey(recordId);
387    
388                    Session session = null;
389    
390                    try {
391                            session = openSession();
392    
393                            DDLRecord[] array = new DDLRecordImpl[3];
394    
395                            array[0] = getByUuid_PrevAndNext(session, ddlRecord, uuid,
396                                            orderByComparator, true);
397    
398                            array[1] = ddlRecord;
399    
400                            array[2] = getByUuid_PrevAndNext(session, ddlRecord, uuid,
401                                            orderByComparator, false);
402    
403                            return array;
404                    }
405                    catch (Exception e) {
406                            throw processException(e);
407                    }
408                    finally {
409                            closeSession(session);
410                    }
411            }
412    
413            protected DDLRecord getByUuid_PrevAndNext(Session session,
414                    DDLRecord ddlRecord, String uuid, OrderByComparator orderByComparator,
415                    boolean previous) {
416                    StringBundler query = null;
417    
418                    if (orderByComparator != null) {
419                            query = new StringBundler(6 +
420                                            (orderByComparator.getOrderByFields().length * 6));
421                    }
422                    else {
423                            query = new StringBundler(3);
424                    }
425    
426                    query.append(_SQL_SELECT_DDLRECORD_WHERE);
427    
428                    boolean bindUuid = false;
429    
430                    if (uuid == null) {
431                            query.append(_FINDER_COLUMN_UUID_UUID_1);
432                    }
433                    else if (uuid.equals(StringPool.BLANK)) {
434                            query.append(_FINDER_COLUMN_UUID_UUID_3);
435                    }
436                    else {
437                            bindUuid = true;
438    
439                            query.append(_FINDER_COLUMN_UUID_UUID_2);
440                    }
441    
442                    if (orderByComparator != null) {
443                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
444    
445                            if (orderByConditionFields.length > 0) {
446                                    query.append(WHERE_AND);
447                            }
448    
449                            for (int i = 0; i < orderByConditionFields.length; i++) {
450                                    query.append(_ORDER_BY_ENTITY_ALIAS);
451                                    query.append(orderByConditionFields[i]);
452    
453                                    if ((i + 1) < orderByConditionFields.length) {
454                                            if (orderByComparator.isAscending() ^ previous) {
455                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
456                                            }
457                                            else {
458                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
459                                            }
460                                    }
461                                    else {
462                                            if (orderByComparator.isAscending() ^ previous) {
463                                                    query.append(WHERE_GREATER_THAN);
464                                            }
465                                            else {
466                                                    query.append(WHERE_LESSER_THAN);
467                                            }
468                                    }
469                            }
470    
471                            query.append(ORDER_BY_CLAUSE);
472    
473                            String[] orderByFields = orderByComparator.getOrderByFields();
474    
475                            for (int i = 0; i < orderByFields.length; i++) {
476                                    query.append(_ORDER_BY_ENTITY_ALIAS);
477                                    query.append(orderByFields[i]);
478    
479                                    if ((i + 1) < orderByFields.length) {
480                                            if (orderByComparator.isAscending() ^ previous) {
481                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
482                                            }
483                                            else {
484                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
485                                            }
486                                    }
487                                    else {
488                                            if (orderByComparator.isAscending() ^ previous) {
489                                                    query.append(ORDER_BY_ASC);
490                                            }
491                                            else {
492                                                    query.append(ORDER_BY_DESC);
493                                            }
494                                    }
495                            }
496                    }
497                    else {
498                            query.append(DDLRecordModelImpl.ORDER_BY_JPQL);
499                    }
500    
501                    String sql = query.toString();
502    
503                    Query q = session.createQuery(sql);
504    
505                    q.setFirstResult(0);
506                    q.setMaxResults(2);
507    
508                    QueryPos qPos = QueryPos.getInstance(q);
509    
510                    if (bindUuid) {
511                            qPos.add(uuid);
512                    }
513    
514                    if (orderByComparator != null) {
515                            Object[] values = orderByComparator.getOrderByConditionValues(ddlRecord);
516    
517                            for (Object value : values) {
518                                    qPos.add(value);
519                            }
520                    }
521    
522                    List<DDLRecord> list = q.list();
523    
524                    if (list.size() == 2) {
525                            return list.get(1);
526                    }
527                    else {
528                            return null;
529                    }
530            }
531    
532            /**
533             * Removes all the d d l records where uuid = &#63; from the database.
534             *
535             * @param uuid the uuid
536             * @throws SystemException if a system exception occurred
537             */
538            @Override
539            public void removeByUuid(String uuid) throws SystemException {
540                    for (DDLRecord ddlRecord : findByUuid(uuid, QueryUtil.ALL_POS,
541                                    QueryUtil.ALL_POS, null)) {
542                            remove(ddlRecord);
543                    }
544            }
545    
546            /**
547             * Returns the number of d d l records where uuid = &#63;.
548             *
549             * @param uuid the uuid
550             * @return the number of matching d d l records
551             * @throws SystemException if a system exception occurred
552             */
553            @Override
554            public int countByUuid(String uuid) throws SystemException {
555                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
556    
557                    Object[] finderArgs = new Object[] { uuid };
558    
559                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
560                                    this);
561    
562                    if (count == null) {
563                            StringBundler query = new StringBundler(2);
564    
565                            query.append(_SQL_COUNT_DDLRECORD_WHERE);
566    
567                            boolean bindUuid = false;
568    
569                            if (uuid == null) {
570                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
571                            }
572                            else if (uuid.equals(StringPool.BLANK)) {
573                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
574                            }
575                            else {
576                                    bindUuid = true;
577    
578                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
579                            }
580    
581                            String sql = query.toString();
582    
583                            Session session = null;
584    
585                            try {
586                                    session = openSession();
587    
588                                    Query q = session.createQuery(sql);
589    
590                                    QueryPos qPos = QueryPos.getInstance(q);
591    
592                                    if (bindUuid) {
593                                            qPos.add(uuid);
594                                    }
595    
596                                    count = (Long)q.uniqueResult();
597    
598                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
599                            }
600                            catch (Exception e) {
601                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
602    
603                                    throw processException(e);
604                            }
605                            finally {
606                                    closeSession(session);
607                            }
608                    }
609    
610                    return count.intValue();
611            }
612    
613            private static final String _FINDER_COLUMN_UUID_UUID_1 = "ddlRecord.uuid IS NULL";
614            private static final String _FINDER_COLUMN_UUID_UUID_2 = "ddlRecord.uuid = ?";
615            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(ddlRecord.uuid IS NULL OR ddlRecord.uuid = '')";
616            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
617                            DDLRecordModelImpl.FINDER_CACHE_ENABLED, DDLRecordImpl.class,
618                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
619                            new String[] { String.class.getName(), Long.class.getName() },
620                            DDLRecordModelImpl.UUID_COLUMN_BITMASK |
621                            DDLRecordModelImpl.GROUPID_COLUMN_BITMASK);
622            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
623                            DDLRecordModelImpl.FINDER_CACHE_ENABLED, Long.class,
624                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
625                            new String[] { String.class.getName(), Long.class.getName() });
626    
627            /**
628             * Returns the d d l record where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.dynamicdatalists.NoSuchRecordException} if it could not be found.
629             *
630             * @param uuid the uuid
631             * @param groupId the group ID
632             * @return the matching d d l record
633             * @throws com.liferay.portlet.dynamicdatalists.NoSuchRecordException if a matching d d l record could not be found
634             * @throws SystemException if a system exception occurred
635             */
636            @Override
637            public DDLRecord findByUUID_G(String uuid, long groupId)
638                    throws NoSuchRecordException, SystemException {
639                    DDLRecord ddlRecord = fetchByUUID_G(uuid, groupId);
640    
641                    if (ddlRecord == null) {
642                            StringBundler msg = new StringBundler(6);
643    
644                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
645    
646                            msg.append("uuid=");
647                            msg.append(uuid);
648    
649                            msg.append(", groupId=");
650                            msg.append(groupId);
651    
652                            msg.append(StringPool.CLOSE_CURLY_BRACE);
653    
654                            if (_log.isWarnEnabled()) {
655                                    _log.warn(msg.toString());
656                            }
657    
658                            throw new NoSuchRecordException(msg.toString());
659                    }
660    
661                    return ddlRecord;
662            }
663    
664            /**
665             * Returns the d d l record where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
666             *
667             * @param uuid the uuid
668             * @param groupId the group ID
669             * @return the matching d d l record, or <code>null</code> if a matching d d l record could not be found
670             * @throws SystemException if a system exception occurred
671             */
672            @Override
673            public DDLRecord fetchByUUID_G(String uuid, long groupId)
674                    throws SystemException {
675                    return fetchByUUID_G(uuid, groupId, true);
676            }
677    
678            /**
679             * Returns the d d l record where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
680             *
681             * @param uuid the uuid
682             * @param groupId the group ID
683             * @param retrieveFromCache whether to use the finder cache
684             * @return the matching d d l record, or <code>null</code> if a matching d d l record could not be found
685             * @throws SystemException if a system exception occurred
686             */
687            @Override
688            public DDLRecord fetchByUUID_G(String uuid, long groupId,
689                    boolean retrieveFromCache) throws SystemException {
690                    Object[] finderArgs = new Object[] { uuid, groupId };
691    
692                    Object result = null;
693    
694                    if (retrieveFromCache) {
695                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
696                                            finderArgs, this);
697                    }
698    
699                    if (result instanceof DDLRecord) {
700                            DDLRecord ddlRecord = (DDLRecord)result;
701    
702                            if (!Validator.equals(uuid, ddlRecord.getUuid()) ||
703                                            (groupId != ddlRecord.getGroupId())) {
704                                    result = null;
705                            }
706                    }
707    
708                    if (result == null) {
709                            StringBundler query = new StringBundler(4);
710    
711                            query.append(_SQL_SELECT_DDLRECORD_WHERE);
712    
713                            boolean bindUuid = false;
714    
715                            if (uuid == null) {
716                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
717                            }
718                            else if (uuid.equals(StringPool.BLANK)) {
719                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
720                            }
721                            else {
722                                    bindUuid = true;
723    
724                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
725                            }
726    
727                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
728    
729                            String sql = query.toString();
730    
731                            Session session = null;
732    
733                            try {
734                                    session = openSession();
735    
736                                    Query q = session.createQuery(sql);
737    
738                                    QueryPos qPos = QueryPos.getInstance(q);
739    
740                                    if (bindUuid) {
741                                            qPos.add(uuid);
742                                    }
743    
744                                    qPos.add(groupId);
745    
746                                    List<DDLRecord> list = q.list();
747    
748                                    if (list.isEmpty()) {
749                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
750                                                    finderArgs, list);
751                                    }
752                                    else {
753                                            DDLRecord ddlRecord = list.get(0);
754    
755                                            result = ddlRecord;
756    
757                                            cacheResult(ddlRecord);
758    
759                                            if ((ddlRecord.getUuid() == null) ||
760                                                            !ddlRecord.getUuid().equals(uuid) ||
761                                                            (ddlRecord.getGroupId() != groupId)) {
762                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
763                                                            finderArgs, ddlRecord);
764                                            }
765                                    }
766                            }
767                            catch (Exception e) {
768                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
769                                            finderArgs);
770    
771                                    throw processException(e);
772                            }
773                            finally {
774                                    closeSession(session);
775                            }
776                    }
777    
778                    if (result instanceof List<?>) {
779                            return null;
780                    }
781                    else {
782                            return (DDLRecord)result;
783                    }
784            }
785    
786            /**
787             * Removes the d d l record where uuid = &#63; and groupId = &#63; from the database.
788             *
789             * @param uuid the uuid
790             * @param groupId the group ID
791             * @return the d d l record that was removed
792             * @throws SystemException if a system exception occurred
793             */
794            @Override
795            public DDLRecord removeByUUID_G(String uuid, long groupId)
796                    throws NoSuchRecordException, SystemException {
797                    DDLRecord ddlRecord = findByUUID_G(uuid, groupId);
798    
799                    return remove(ddlRecord);
800            }
801    
802            /**
803             * Returns the number of d d l records where uuid = &#63; and groupId = &#63;.
804             *
805             * @param uuid the uuid
806             * @param groupId the group ID
807             * @return the number of matching d d l records
808             * @throws SystemException if a system exception occurred
809             */
810            @Override
811            public int countByUUID_G(String uuid, long groupId)
812                    throws SystemException {
813                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
814    
815                    Object[] finderArgs = new Object[] { uuid, groupId };
816    
817                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
818                                    this);
819    
820                    if (count == null) {
821                            StringBundler query = new StringBundler(3);
822    
823                            query.append(_SQL_COUNT_DDLRECORD_WHERE);
824    
825                            boolean bindUuid = false;
826    
827                            if (uuid == null) {
828                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
829                            }
830                            else if (uuid.equals(StringPool.BLANK)) {
831                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
832                            }
833                            else {
834                                    bindUuid = true;
835    
836                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
837                            }
838    
839                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
840    
841                            String sql = query.toString();
842    
843                            Session session = null;
844    
845                            try {
846                                    session = openSession();
847    
848                                    Query q = session.createQuery(sql);
849    
850                                    QueryPos qPos = QueryPos.getInstance(q);
851    
852                                    if (bindUuid) {
853                                            qPos.add(uuid);
854                                    }
855    
856                                    qPos.add(groupId);
857    
858                                    count = (Long)q.uniqueResult();
859    
860                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
861                            }
862                            catch (Exception e) {
863                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
864    
865                                    throw processException(e);
866                            }
867                            finally {
868                                    closeSession(session);
869                            }
870                    }
871    
872                    return count.intValue();
873            }
874    
875            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "ddlRecord.uuid IS NULL AND ";
876            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "ddlRecord.uuid = ? AND ";
877            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(ddlRecord.uuid IS NULL OR ddlRecord.uuid = '') AND ";
878            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "ddlRecord.groupId = ?";
879            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
880                            DDLRecordModelImpl.FINDER_CACHE_ENABLED, DDLRecordImpl.class,
881                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
882                            new String[] {
883                                    String.class.getName(), Long.class.getName(),
884                                    
885                            Integer.class.getName(), Integer.class.getName(),
886                                    OrderByComparator.class.getName()
887                            });
888            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
889                    new FinderPath(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
890                            DDLRecordModelImpl.FINDER_CACHE_ENABLED, DDLRecordImpl.class,
891                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
892                            new String[] { String.class.getName(), Long.class.getName() },
893                            DDLRecordModelImpl.UUID_COLUMN_BITMASK |
894                            DDLRecordModelImpl.COMPANYID_COLUMN_BITMASK);
895            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
896                            DDLRecordModelImpl.FINDER_CACHE_ENABLED, Long.class,
897                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
898                            new String[] { String.class.getName(), Long.class.getName() });
899    
900            /**
901             * Returns all the d d l records where uuid = &#63; and companyId = &#63;.
902             *
903             * @param uuid the uuid
904             * @param companyId the company ID
905             * @return the matching d d l records
906             * @throws SystemException if a system exception occurred
907             */
908            @Override
909            public List<DDLRecord> findByUuid_C(String uuid, long companyId)
910                    throws SystemException {
911                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
912                            QueryUtil.ALL_POS, null);
913            }
914    
915            /**
916             * Returns a range of all the d d l records where uuid = &#63; and companyId = &#63;.
917             *
918             * <p>
919             * 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.DDLRecordModelImpl}. 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.
920             * </p>
921             *
922             * @param uuid the uuid
923             * @param companyId the company ID
924             * @param start the lower bound of the range of d d l records
925             * @param end the upper bound of the range of d d l records (not inclusive)
926             * @return the range of matching d d l records
927             * @throws SystemException if a system exception occurred
928             */
929            @Override
930            public List<DDLRecord> findByUuid_C(String uuid, long companyId, int start,
931                    int end) throws SystemException {
932                    return findByUuid_C(uuid, companyId, start, end, null);
933            }
934    
935            /**
936             * Returns an ordered range of all the d d l records where uuid = &#63; and companyId = &#63;.
937             *
938             * <p>
939             * 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.DDLRecordModelImpl}. 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.
940             * </p>
941             *
942             * @param uuid the uuid
943             * @param companyId the company ID
944             * @param start the lower bound of the range of d d l records
945             * @param end the upper bound of the range of d d l records (not inclusive)
946             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
947             * @return the ordered range of matching d d l records
948             * @throws SystemException if a system exception occurred
949             */
950            @Override
951            public List<DDLRecord> findByUuid_C(String uuid, long companyId, int start,
952                    int end, OrderByComparator orderByComparator) throws SystemException {
953                    boolean pagination = true;
954                    FinderPath finderPath = null;
955                    Object[] finderArgs = null;
956    
957                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
958                                    (orderByComparator == null)) {
959                            pagination = false;
960                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
961                            finderArgs = new Object[] { uuid, companyId };
962                    }
963                    else {
964                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
965                            finderArgs = new Object[] {
966                                            uuid, companyId,
967                                            
968                                            start, end, orderByComparator
969                                    };
970                    }
971    
972                    List<DDLRecord> list = (List<DDLRecord>)FinderCacheUtil.getResult(finderPath,
973                                    finderArgs, this);
974    
975                    if ((list != null) && !list.isEmpty()) {
976                            for (DDLRecord ddlRecord : list) {
977                                    if (!Validator.equals(uuid, ddlRecord.getUuid()) ||
978                                                    (companyId != ddlRecord.getCompanyId())) {
979                                            list = null;
980    
981                                            break;
982                                    }
983                            }
984                    }
985    
986                    if (list == null) {
987                            StringBundler query = null;
988    
989                            if (orderByComparator != null) {
990                                    query = new StringBundler(4 +
991                                                    (orderByComparator.getOrderByFields().length * 3));
992                            }
993                            else {
994                                    query = new StringBundler(4);
995                            }
996    
997                            query.append(_SQL_SELECT_DDLRECORD_WHERE);
998    
999                            boolean bindUuid = false;
1000    
1001                            if (uuid == null) {
1002                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1003                            }
1004                            else if (uuid.equals(StringPool.BLANK)) {
1005                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1006                            }
1007                            else {
1008                                    bindUuid = true;
1009    
1010                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1011                            }
1012    
1013                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1014    
1015                            if (orderByComparator != null) {
1016                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1017                                            orderByComparator);
1018                            }
1019                            else
1020                             if (pagination) {
1021                                    query.append(DDLRecordModelImpl.ORDER_BY_JPQL);
1022                            }
1023    
1024                            String sql = query.toString();
1025    
1026                            Session session = null;
1027    
1028                            try {
1029                                    session = openSession();
1030    
1031                                    Query q = session.createQuery(sql);
1032    
1033                                    QueryPos qPos = QueryPos.getInstance(q);
1034    
1035                                    if (bindUuid) {
1036                                            qPos.add(uuid);
1037                                    }
1038    
1039                                    qPos.add(companyId);
1040    
1041                                    if (!pagination) {
1042                                            list = (List<DDLRecord>)QueryUtil.list(q, getDialect(),
1043                                                            start, end, false);
1044    
1045                                            Collections.sort(list);
1046    
1047                                            list = new UnmodifiableList<DDLRecord>(list);
1048                                    }
1049                                    else {
1050                                            list = (List<DDLRecord>)QueryUtil.list(q, getDialect(),
1051                                                            start, end);
1052                                    }
1053    
1054                                    cacheResult(list);
1055    
1056                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1057                            }
1058                            catch (Exception e) {
1059                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1060    
1061                                    throw processException(e);
1062                            }
1063                            finally {
1064                                    closeSession(session);
1065                            }
1066                    }
1067    
1068                    return list;
1069            }
1070    
1071            /**
1072             * Returns the first d d l record in the ordered set where uuid = &#63; and companyId = &#63;.
1073             *
1074             * @param uuid the uuid
1075             * @param companyId the company ID
1076             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1077             * @return the first matching d d l record
1078             * @throws com.liferay.portlet.dynamicdatalists.NoSuchRecordException if a matching d d l record could not be found
1079             * @throws SystemException if a system exception occurred
1080             */
1081            @Override
1082            public DDLRecord findByUuid_C_First(String uuid, long companyId,
1083                    OrderByComparator orderByComparator)
1084                    throws NoSuchRecordException, SystemException {
1085                    DDLRecord ddlRecord = fetchByUuid_C_First(uuid, companyId,
1086                                    orderByComparator);
1087    
1088                    if (ddlRecord != null) {
1089                            return ddlRecord;
1090                    }
1091    
1092                    StringBundler msg = new StringBundler(6);
1093    
1094                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1095    
1096                    msg.append("uuid=");
1097                    msg.append(uuid);
1098    
1099                    msg.append(", companyId=");
1100                    msg.append(companyId);
1101    
1102                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1103    
1104                    throw new NoSuchRecordException(msg.toString());
1105            }
1106    
1107            /**
1108             * Returns the first d d l record in the ordered set where uuid = &#63; and companyId = &#63;.
1109             *
1110             * @param uuid the uuid
1111             * @param companyId the company ID
1112             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1113             * @return the first matching d d l record, or <code>null</code> if a matching d d l record could not be found
1114             * @throws SystemException if a system exception occurred
1115             */
1116            @Override
1117            public DDLRecord fetchByUuid_C_First(String uuid, long companyId,
1118                    OrderByComparator orderByComparator) throws SystemException {
1119                    List<DDLRecord> list = findByUuid_C(uuid, companyId, 0, 1,
1120                                    orderByComparator);
1121    
1122                    if (!list.isEmpty()) {
1123                            return list.get(0);
1124                    }
1125    
1126                    return null;
1127            }
1128    
1129            /**
1130             * Returns the last d d l record in the ordered set where uuid = &#63; and companyId = &#63;.
1131             *
1132             * @param uuid the uuid
1133             * @param companyId the company ID
1134             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1135             * @return the last matching d d l record
1136             * @throws com.liferay.portlet.dynamicdatalists.NoSuchRecordException if a matching d d l record could not be found
1137             * @throws SystemException if a system exception occurred
1138             */
1139            @Override
1140            public DDLRecord findByUuid_C_Last(String uuid, long companyId,
1141                    OrderByComparator orderByComparator)
1142                    throws NoSuchRecordException, SystemException {
1143                    DDLRecord ddlRecord = fetchByUuid_C_Last(uuid, companyId,
1144                                    orderByComparator);
1145    
1146                    if (ddlRecord != null) {
1147                            return ddlRecord;
1148                    }
1149    
1150                    StringBundler msg = new StringBundler(6);
1151    
1152                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1153    
1154                    msg.append("uuid=");
1155                    msg.append(uuid);
1156    
1157                    msg.append(", companyId=");
1158                    msg.append(companyId);
1159    
1160                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1161    
1162                    throw new NoSuchRecordException(msg.toString());
1163            }
1164    
1165            /**
1166             * Returns the last d d l record in the ordered set where uuid = &#63; and companyId = &#63;.
1167             *
1168             * @param uuid the uuid
1169             * @param companyId the company ID
1170             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1171             * @return the last matching d d l record, or <code>null</code> if a matching d d l record could not be found
1172             * @throws SystemException if a system exception occurred
1173             */
1174            @Override
1175            public DDLRecord fetchByUuid_C_Last(String uuid, long companyId,
1176                    OrderByComparator orderByComparator) throws SystemException {
1177                    int count = countByUuid_C(uuid, companyId);
1178    
1179                    if (count == 0) {
1180                            return null;
1181                    }
1182    
1183                    List<DDLRecord> list = findByUuid_C(uuid, companyId, count - 1, count,
1184                                    orderByComparator);
1185    
1186                    if (!list.isEmpty()) {
1187                            return list.get(0);
1188                    }
1189    
1190                    return null;
1191            }
1192    
1193            /**
1194             * Returns the d d l records before and after the current d d l record in the ordered set where uuid = &#63; and companyId = &#63;.
1195             *
1196             * @param recordId the primary key of the current d d l record
1197             * @param uuid the uuid
1198             * @param companyId the company ID
1199             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1200             * @return the previous, current, and next d d l record
1201             * @throws com.liferay.portlet.dynamicdatalists.NoSuchRecordException if a d d l record with the primary key could not be found
1202             * @throws SystemException if a system exception occurred
1203             */
1204            @Override
1205            public DDLRecord[] findByUuid_C_PrevAndNext(long recordId, String uuid,
1206                    long companyId, OrderByComparator orderByComparator)
1207                    throws NoSuchRecordException, SystemException {
1208                    DDLRecord ddlRecord = findByPrimaryKey(recordId);
1209    
1210                    Session session = null;
1211    
1212                    try {
1213                            session = openSession();
1214    
1215                            DDLRecord[] array = new DDLRecordImpl[3];
1216    
1217                            array[0] = getByUuid_C_PrevAndNext(session, ddlRecord, uuid,
1218                                            companyId, orderByComparator, true);
1219    
1220                            array[1] = ddlRecord;
1221    
1222                            array[2] = getByUuid_C_PrevAndNext(session, ddlRecord, uuid,
1223                                            companyId, orderByComparator, false);
1224    
1225                            return array;
1226                    }
1227                    catch (Exception e) {
1228                            throw processException(e);
1229                    }
1230                    finally {
1231                            closeSession(session);
1232                    }
1233            }
1234    
1235            protected DDLRecord getByUuid_C_PrevAndNext(Session session,
1236                    DDLRecord ddlRecord, String uuid, long companyId,
1237                    OrderByComparator orderByComparator, boolean previous) {
1238                    StringBundler query = null;
1239    
1240                    if (orderByComparator != null) {
1241                            query = new StringBundler(6 +
1242                                            (orderByComparator.getOrderByFields().length * 6));
1243                    }
1244                    else {
1245                            query = new StringBundler(3);
1246                    }
1247    
1248                    query.append(_SQL_SELECT_DDLRECORD_WHERE);
1249    
1250                    boolean bindUuid = false;
1251    
1252                    if (uuid == null) {
1253                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1254                    }
1255                    else if (uuid.equals(StringPool.BLANK)) {
1256                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1257                    }
1258                    else {
1259                            bindUuid = true;
1260    
1261                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1262                    }
1263    
1264                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1265    
1266                    if (orderByComparator != null) {
1267                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1268    
1269                            if (orderByConditionFields.length > 0) {
1270                                    query.append(WHERE_AND);
1271                            }
1272    
1273                            for (int i = 0; i < orderByConditionFields.length; i++) {
1274                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1275                                    query.append(orderByConditionFields[i]);
1276    
1277                                    if ((i + 1) < orderByConditionFields.length) {
1278                                            if (orderByComparator.isAscending() ^ previous) {
1279                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1280                                            }
1281                                            else {
1282                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1283                                            }
1284                                    }
1285                                    else {
1286                                            if (orderByComparator.isAscending() ^ previous) {
1287                                                    query.append(WHERE_GREATER_THAN);
1288                                            }
1289                                            else {
1290                                                    query.append(WHERE_LESSER_THAN);
1291                                            }
1292                                    }
1293                            }
1294    
1295                            query.append(ORDER_BY_CLAUSE);
1296    
1297                            String[] orderByFields = orderByComparator.getOrderByFields();
1298    
1299                            for (int i = 0; i < orderByFields.length; i++) {
1300                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1301                                    query.append(orderByFields[i]);
1302    
1303                                    if ((i + 1) < orderByFields.length) {
1304                                            if (orderByComparator.isAscending() ^ previous) {
1305                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1306                                            }
1307                                            else {
1308                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1309                                            }
1310                                    }
1311                                    else {
1312                                            if (orderByComparator.isAscending() ^ previous) {
1313                                                    query.append(ORDER_BY_ASC);
1314                                            }
1315                                            else {
1316                                                    query.append(ORDER_BY_DESC);
1317                                            }
1318                                    }
1319                            }
1320                    }
1321                    else {
1322                            query.append(DDLRecordModelImpl.ORDER_BY_JPQL);
1323                    }
1324    
1325                    String sql = query.toString();
1326    
1327                    Query q = session.createQuery(sql);
1328    
1329                    q.setFirstResult(0);
1330                    q.setMaxResults(2);
1331    
1332                    QueryPos qPos = QueryPos.getInstance(q);
1333    
1334                    if (bindUuid) {
1335                            qPos.add(uuid);
1336                    }
1337    
1338                    qPos.add(companyId);
1339    
1340                    if (orderByComparator != null) {
1341                            Object[] values = orderByComparator.getOrderByConditionValues(ddlRecord);
1342    
1343                            for (Object value : values) {
1344                                    qPos.add(value);
1345                            }
1346                    }
1347    
1348                    List<DDLRecord> list = q.list();
1349    
1350                    if (list.size() == 2) {
1351                            return list.get(1);
1352                    }
1353                    else {
1354                            return null;
1355                    }
1356            }
1357    
1358            /**
1359             * Removes all the d d l records where uuid = &#63; and companyId = &#63; from the database.
1360             *
1361             * @param uuid the uuid
1362             * @param companyId the company ID
1363             * @throws SystemException if a system exception occurred
1364             */
1365            @Override
1366            public void removeByUuid_C(String uuid, long companyId)
1367                    throws SystemException {
1368                    for (DDLRecord ddlRecord : findByUuid_C(uuid, companyId,
1369                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1370                            remove(ddlRecord);
1371                    }
1372            }
1373    
1374            /**
1375             * Returns the number of d d l records where uuid = &#63; and companyId = &#63;.
1376             *
1377             * @param uuid the uuid
1378             * @param companyId the company ID
1379             * @return the number of matching d d l records
1380             * @throws SystemException if a system exception occurred
1381             */
1382            @Override
1383            public int countByUuid_C(String uuid, long companyId)
1384                    throws SystemException {
1385                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1386    
1387                    Object[] finderArgs = new Object[] { uuid, companyId };
1388    
1389                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1390                                    this);
1391    
1392                    if (count == null) {
1393                            StringBundler query = new StringBundler(3);
1394    
1395                            query.append(_SQL_COUNT_DDLRECORD_WHERE);
1396    
1397                            boolean bindUuid = false;
1398    
1399                            if (uuid == null) {
1400                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1401                            }
1402                            else if (uuid.equals(StringPool.BLANK)) {
1403                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1404                            }
1405                            else {
1406                                    bindUuid = true;
1407    
1408                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1409                            }
1410    
1411                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1412    
1413                            String sql = query.toString();
1414    
1415                            Session session = null;
1416    
1417                            try {
1418                                    session = openSession();
1419    
1420                                    Query q = session.createQuery(sql);
1421    
1422                                    QueryPos qPos = QueryPos.getInstance(q);
1423    
1424                                    if (bindUuid) {
1425                                            qPos.add(uuid);
1426                                    }
1427    
1428                                    qPos.add(companyId);
1429    
1430                                    count = (Long)q.uniqueResult();
1431    
1432                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1433                            }
1434                            catch (Exception e) {
1435                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1436    
1437                                    throw processException(e);
1438                            }
1439                            finally {
1440                                    closeSession(session);
1441                            }
1442                    }
1443    
1444                    return count.intValue();
1445            }
1446    
1447            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "ddlRecord.uuid IS NULL AND ";
1448            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "ddlRecord.uuid = ? AND ";
1449            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(ddlRecord.uuid IS NULL OR ddlRecord.uuid = '') AND ";
1450            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "ddlRecord.companyId = ?";
1451            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
1452                    new FinderPath(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
1453                            DDLRecordModelImpl.FINDER_CACHE_ENABLED, DDLRecordImpl.class,
1454                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
1455                            new String[] {
1456                                    Long.class.getName(),
1457                                    
1458                            Integer.class.getName(), Integer.class.getName(),
1459                                    OrderByComparator.class.getName()
1460                            });
1461            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
1462                    new FinderPath(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
1463                            DDLRecordModelImpl.FINDER_CACHE_ENABLED, DDLRecordImpl.class,
1464                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
1465                            new String[] { Long.class.getName() },
1466                            DDLRecordModelImpl.COMPANYID_COLUMN_BITMASK);
1467            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
1468                            DDLRecordModelImpl.FINDER_CACHE_ENABLED, Long.class,
1469                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
1470                            new String[] { Long.class.getName() });
1471    
1472            /**
1473             * Returns all the d d l records where companyId = &#63;.
1474             *
1475             * @param companyId the company ID
1476             * @return the matching d d l records
1477             * @throws SystemException if a system exception occurred
1478             */
1479            @Override
1480            public List<DDLRecord> findByCompanyId(long companyId)
1481                    throws SystemException {
1482                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1483                            null);
1484            }
1485    
1486            /**
1487             * Returns a range of all the d d l records where companyId = &#63;.
1488             *
1489             * <p>
1490             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. 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.DDLRecordModelImpl}. 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.
1491             * </p>
1492             *
1493             * @param companyId the company ID
1494             * @param start the lower bound of the range of d d l records
1495             * @param end the upper bound of the range of d d l records (not inclusive)
1496             * @return the range of matching d d l records
1497             * @throws SystemException if a system exception occurred
1498             */
1499            @Override
1500            public List<DDLRecord> findByCompanyId(long companyId, int start, int end)
1501                    throws SystemException {
1502                    return findByCompanyId(companyId, start, end, null);
1503            }
1504    
1505            /**
1506             * Returns an ordered range of all the d d l records where companyId = &#63;.
1507             *
1508             * <p>
1509             * 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.DDLRecordModelImpl}. 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.
1510             * </p>
1511             *
1512             * @param companyId the company ID
1513             * @param start the lower bound of the range of d d l records
1514             * @param end the upper bound of the range of d d l records (not inclusive)
1515             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1516             * @return the ordered range of matching d d l records
1517             * @throws SystemException if a system exception occurred
1518             */
1519            @Override
1520            public List<DDLRecord> findByCompanyId(long companyId, int start, int end,
1521                    OrderByComparator orderByComparator) throws SystemException {
1522                    boolean pagination = true;
1523                    FinderPath finderPath = null;
1524                    Object[] finderArgs = null;
1525    
1526                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1527                                    (orderByComparator == null)) {
1528                            pagination = false;
1529                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1530                            finderArgs = new Object[] { companyId };
1531                    }
1532                    else {
1533                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1534                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
1535                    }
1536    
1537                    List<DDLRecord> list = (List<DDLRecord>)FinderCacheUtil.getResult(finderPath,
1538                                    finderArgs, this);
1539    
1540                    if ((list != null) && !list.isEmpty()) {
1541                            for (DDLRecord ddlRecord : list) {
1542                                    if ((companyId != ddlRecord.getCompanyId())) {
1543                                            list = null;
1544    
1545                                            break;
1546                                    }
1547                            }
1548                    }
1549    
1550                    if (list == null) {
1551                            StringBundler query = null;
1552    
1553                            if (orderByComparator != null) {
1554                                    query = new StringBundler(3 +
1555                                                    (orderByComparator.getOrderByFields().length * 3));
1556                            }
1557                            else {
1558                                    query = new StringBundler(3);
1559                            }
1560    
1561                            query.append(_SQL_SELECT_DDLRECORD_WHERE);
1562    
1563                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1564    
1565                            if (orderByComparator != null) {
1566                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1567                                            orderByComparator);
1568                            }
1569                            else
1570                             if (pagination) {
1571                                    query.append(DDLRecordModelImpl.ORDER_BY_JPQL);
1572                            }
1573    
1574                            String sql = query.toString();
1575    
1576                            Session session = null;
1577    
1578                            try {
1579                                    session = openSession();
1580    
1581                                    Query q = session.createQuery(sql);
1582    
1583                                    QueryPos qPos = QueryPos.getInstance(q);
1584    
1585                                    qPos.add(companyId);
1586    
1587                                    if (!pagination) {
1588                                            list = (List<DDLRecord>)QueryUtil.list(q, getDialect(),
1589                                                            start, end, false);
1590    
1591                                            Collections.sort(list);
1592    
1593                                            list = new UnmodifiableList<DDLRecord>(list);
1594                                    }
1595                                    else {
1596                                            list = (List<DDLRecord>)QueryUtil.list(q, getDialect(),
1597                                                            start, end);
1598                                    }
1599    
1600                                    cacheResult(list);
1601    
1602                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1603                            }
1604                            catch (Exception e) {
1605                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1606    
1607                                    throw processException(e);
1608                            }
1609                            finally {
1610                                    closeSession(session);
1611                            }
1612                    }
1613    
1614                    return list;
1615            }
1616    
1617            /**
1618             * Returns the first d d l record in the ordered set where companyId = &#63;.
1619             *
1620             * @param companyId the company ID
1621             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1622             * @return the first matching d d l record
1623             * @throws com.liferay.portlet.dynamicdatalists.NoSuchRecordException if a matching d d l record could not be found
1624             * @throws SystemException if a system exception occurred
1625             */
1626            @Override
1627            public DDLRecord findByCompanyId_First(long companyId,
1628                    OrderByComparator orderByComparator)
1629                    throws NoSuchRecordException, SystemException {
1630                    DDLRecord ddlRecord = fetchByCompanyId_First(companyId,
1631                                    orderByComparator);
1632    
1633                    if (ddlRecord != null) {
1634                            return ddlRecord;
1635                    }
1636    
1637                    StringBundler msg = new StringBundler(4);
1638    
1639                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1640    
1641                    msg.append("companyId=");
1642                    msg.append(companyId);
1643    
1644                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1645    
1646                    throw new NoSuchRecordException(msg.toString());
1647            }
1648    
1649            /**
1650             * Returns the first d d l record in the ordered set where companyId = &#63;.
1651             *
1652             * @param companyId the company ID
1653             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1654             * @return the first matching d d l record, or <code>null</code> if a matching d d l record could not be found
1655             * @throws SystemException if a system exception occurred
1656             */
1657            @Override
1658            public DDLRecord fetchByCompanyId_First(long companyId,
1659                    OrderByComparator orderByComparator) throws SystemException {
1660                    List<DDLRecord> list = findByCompanyId(companyId, 0, 1,
1661                                    orderByComparator);
1662    
1663                    if (!list.isEmpty()) {
1664                            return list.get(0);
1665                    }
1666    
1667                    return null;
1668            }
1669    
1670            /**
1671             * Returns the last d d l record in the ordered set where companyId = &#63;.
1672             *
1673             * @param companyId the company ID
1674             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1675             * @return the last matching d d l record
1676             * @throws com.liferay.portlet.dynamicdatalists.NoSuchRecordException if a matching d d l record could not be found
1677             * @throws SystemException if a system exception occurred
1678             */
1679            @Override
1680            public DDLRecord findByCompanyId_Last(long companyId,
1681                    OrderByComparator orderByComparator)
1682                    throws NoSuchRecordException, SystemException {
1683                    DDLRecord ddlRecord = fetchByCompanyId_Last(companyId, orderByComparator);
1684    
1685                    if (ddlRecord != null) {
1686                            return ddlRecord;
1687                    }
1688    
1689                    StringBundler msg = new StringBundler(4);
1690    
1691                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1692    
1693                    msg.append("companyId=");
1694                    msg.append(companyId);
1695    
1696                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1697    
1698                    throw new NoSuchRecordException(msg.toString());
1699            }
1700    
1701            /**
1702             * Returns the last d d l record in the ordered set where companyId = &#63;.
1703             *
1704             * @param companyId the company ID
1705             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1706             * @return the last matching d d l record, or <code>null</code> if a matching d d l record could not be found
1707             * @throws SystemException if a system exception occurred
1708             */
1709            @Override
1710            public DDLRecord fetchByCompanyId_Last(long companyId,
1711                    OrderByComparator orderByComparator) throws SystemException {
1712                    int count = countByCompanyId(companyId);
1713    
1714                    if (count == 0) {
1715                            return null;
1716                    }
1717    
1718                    List<DDLRecord> list = findByCompanyId(companyId, count - 1, count,
1719                                    orderByComparator);
1720    
1721                    if (!list.isEmpty()) {
1722                            return list.get(0);
1723                    }
1724    
1725                    return null;
1726            }
1727    
1728            /**
1729             * Returns the d d l records before and after the current d d l record in the ordered set where companyId = &#63;.
1730             *
1731             * @param recordId the primary key of the current d d l record
1732             * @param companyId the company ID
1733             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1734             * @return the previous, current, and next d d l record
1735             * @throws com.liferay.portlet.dynamicdatalists.NoSuchRecordException if a d d l record with the primary key could not be found
1736             * @throws SystemException if a system exception occurred
1737             */
1738            @Override
1739            public DDLRecord[] findByCompanyId_PrevAndNext(long recordId,
1740                    long companyId, OrderByComparator orderByComparator)
1741                    throws NoSuchRecordException, SystemException {
1742                    DDLRecord ddlRecord = findByPrimaryKey(recordId);
1743    
1744                    Session session = null;
1745    
1746                    try {
1747                            session = openSession();
1748    
1749                            DDLRecord[] array = new DDLRecordImpl[3];
1750    
1751                            array[0] = getByCompanyId_PrevAndNext(session, ddlRecord,
1752                                            companyId, orderByComparator, true);
1753    
1754                            array[1] = ddlRecord;
1755    
1756                            array[2] = getByCompanyId_PrevAndNext(session, ddlRecord,
1757                                            companyId, orderByComparator, false);
1758    
1759                            return array;
1760                    }
1761                    catch (Exception e) {
1762                            throw processException(e);
1763                    }
1764                    finally {
1765                            closeSession(session);
1766                    }
1767            }
1768    
1769            protected DDLRecord getByCompanyId_PrevAndNext(Session session,
1770                    DDLRecord ddlRecord, long companyId,
1771                    OrderByComparator orderByComparator, boolean previous) {
1772                    StringBundler query = null;
1773    
1774                    if (orderByComparator != null) {
1775                            query = new StringBundler(6 +
1776                                            (orderByComparator.getOrderByFields().length * 6));
1777                    }
1778                    else {
1779                            query = new StringBundler(3);
1780                    }
1781    
1782                    query.append(_SQL_SELECT_DDLRECORD_WHERE);
1783    
1784                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1785    
1786                    if (orderByComparator != null) {
1787                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1788    
1789                            if (orderByConditionFields.length > 0) {
1790                                    query.append(WHERE_AND);
1791                            }
1792    
1793                            for (int i = 0; i < orderByConditionFields.length; i++) {
1794                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1795                                    query.append(orderByConditionFields[i]);
1796    
1797                                    if ((i + 1) < orderByConditionFields.length) {
1798                                            if (orderByComparator.isAscending() ^ previous) {
1799                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1800                                            }
1801                                            else {
1802                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1803                                            }
1804                                    }
1805                                    else {
1806                                            if (orderByComparator.isAscending() ^ previous) {
1807                                                    query.append(WHERE_GREATER_THAN);
1808                                            }
1809                                            else {
1810                                                    query.append(WHERE_LESSER_THAN);
1811                                            }
1812                                    }
1813                            }
1814    
1815                            query.append(ORDER_BY_CLAUSE);
1816    
1817                            String[] orderByFields = orderByComparator.getOrderByFields();
1818    
1819                            for (int i = 0; i < orderByFields.length; i++) {
1820                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1821                                    query.append(orderByFields[i]);
1822    
1823                                    if ((i + 1) < orderByFields.length) {
1824                                            if (orderByComparator.isAscending() ^ previous) {
1825                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1826                                            }
1827                                            else {
1828                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1829                                            }
1830                                    }
1831                                    else {
1832                                            if (orderByComparator.isAscending() ^ previous) {
1833                                                    query.append(ORDER_BY_ASC);
1834                                            }
1835                                            else {
1836                                                    query.append(ORDER_BY_DESC);
1837                                            }
1838                                    }
1839                            }
1840                    }
1841                    else {
1842                            query.append(DDLRecordModelImpl.ORDER_BY_JPQL);
1843                    }
1844    
1845                    String sql = query.toString();
1846    
1847                    Query q = session.createQuery(sql);
1848    
1849                    q.setFirstResult(0);
1850                    q.setMaxResults(2);
1851    
1852                    QueryPos qPos = QueryPos.getInstance(q);
1853    
1854                    qPos.add(companyId);
1855    
1856                    if (orderByComparator != null) {
1857                            Object[] values = orderByComparator.getOrderByConditionValues(ddlRecord);
1858    
1859                            for (Object value : values) {
1860                                    qPos.add(value);
1861                            }
1862                    }
1863    
1864                    List<DDLRecord> list = q.list();
1865    
1866                    if (list.size() == 2) {
1867                            return list.get(1);
1868                    }
1869                    else {
1870                            return null;
1871                    }
1872            }
1873    
1874            /**
1875             * Removes all the d d l records where companyId = &#63; from the database.
1876             *
1877             * @param companyId the company ID
1878             * @throws SystemException if a system exception occurred
1879             */
1880            @Override
1881            public void removeByCompanyId(long companyId) throws SystemException {
1882                    for (DDLRecord ddlRecord : findByCompanyId(companyId,
1883                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1884                            remove(ddlRecord);
1885                    }
1886            }
1887    
1888            /**
1889             * Returns the number of d d l records where companyId = &#63;.
1890             *
1891             * @param companyId the company ID
1892             * @return the number of matching d d l records
1893             * @throws SystemException if a system exception occurred
1894             */
1895            @Override
1896            public int countByCompanyId(long companyId) throws SystemException {
1897                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
1898    
1899                    Object[] finderArgs = new Object[] { companyId };
1900    
1901                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1902                                    this);
1903    
1904                    if (count == null) {
1905                            StringBundler query = new StringBundler(2);
1906    
1907                            query.append(_SQL_COUNT_DDLRECORD_WHERE);
1908    
1909                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1910    
1911                            String sql = query.toString();
1912    
1913                            Session session = null;
1914    
1915                            try {
1916                                    session = openSession();
1917    
1918                                    Query q = session.createQuery(sql);
1919    
1920                                    QueryPos qPos = QueryPos.getInstance(q);
1921    
1922                                    qPos.add(companyId);
1923    
1924                                    count = (Long)q.uniqueResult();
1925    
1926                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1927                            }
1928                            catch (Exception e) {
1929                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1930    
1931                                    throw processException(e);
1932                            }
1933                            finally {
1934                                    closeSession(session);
1935                            }
1936                    }
1937    
1938                    return count.intValue();
1939            }
1940    
1941            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "ddlRecord.companyId = ?";
1942            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_RECORDSETID =
1943                    new FinderPath(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
1944                            DDLRecordModelImpl.FINDER_CACHE_ENABLED, DDLRecordImpl.class,
1945                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByRecordSetId",
1946                            new String[] {
1947                                    Long.class.getName(),
1948                                    
1949                            Integer.class.getName(), Integer.class.getName(),
1950                                    OrderByComparator.class.getName()
1951                            });
1952            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECORDSETID =
1953                    new FinderPath(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
1954                            DDLRecordModelImpl.FINDER_CACHE_ENABLED, DDLRecordImpl.class,
1955                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRecordSetId",
1956                            new String[] { Long.class.getName() },
1957                            DDLRecordModelImpl.RECORDSETID_COLUMN_BITMASK);
1958            public static final FinderPath FINDER_PATH_COUNT_BY_RECORDSETID = new FinderPath(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
1959                            DDLRecordModelImpl.FINDER_CACHE_ENABLED, Long.class,
1960                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRecordSetId",
1961                            new String[] { Long.class.getName() });
1962    
1963            /**
1964             * Returns all the d d l records where recordSetId = &#63;.
1965             *
1966             * @param recordSetId the record set ID
1967             * @return the matching d d l records
1968             * @throws SystemException if a system exception occurred
1969             */
1970            @Override
1971            public List<DDLRecord> findByRecordSetId(long recordSetId)
1972                    throws SystemException {
1973                    return findByRecordSetId(recordSetId, QueryUtil.ALL_POS,
1974                            QueryUtil.ALL_POS, null);
1975            }
1976    
1977            /**
1978             * Returns a range of all the d d l records where recordSetId = &#63;.
1979             *
1980             * <p>
1981             * 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.DDLRecordModelImpl}. 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.
1982             * </p>
1983             *
1984             * @param recordSetId the record set ID
1985             * @param start the lower bound of the range of d d l records
1986             * @param end the upper bound of the range of d d l records (not inclusive)
1987             * @return the range of matching d d l records
1988             * @throws SystemException if a system exception occurred
1989             */
1990            @Override
1991            public List<DDLRecord> findByRecordSetId(long recordSetId, int start,
1992                    int end) throws SystemException {
1993                    return findByRecordSetId(recordSetId, start, end, null);
1994            }
1995    
1996            /**
1997             * Returns an ordered range of all the d d l records where recordSetId = &#63;.
1998             *
1999             * <p>
2000             * 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.DDLRecordModelImpl}. 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.
2001             * </p>
2002             *
2003             * @param recordSetId the record set ID
2004             * @param start the lower bound of the range of d d l records
2005             * @param end the upper bound of the range of d d l records (not inclusive)
2006             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2007             * @return the ordered range of matching d d l records
2008             * @throws SystemException if a system exception occurred
2009             */
2010            @Override
2011            public List<DDLRecord> findByRecordSetId(long recordSetId, int start,
2012                    int end, OrderByComparator orderByComparator) throws SystemException {
2013                    boolean pagination = true;
2014                    FinderPath finderPath = null;
2015                    Object[] finderArgs = null;
2016    
2017                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2018                                    (orderByComparator == null)) {
2019                            pagination = false;
2020                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECORDSETID;
2021                            finderArgs = new Object[] { recordSetId };
2022                    }
2023                    else {
2024                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_RECORDSETID;
2025                            finderArgs = new Object[] { recordSetId, start, end, orderByComparator };
2026                    }
2027    
2028                    List<DDLRecord> list = (List<DDLRecord>)FinderCacheUtil.getResult(finderPath,
2029                                    finderArgs, this);
2030    
2031                    if ((list != null) && !list.isEmpty()) {
2032                            for (DDLRecord ddlRecord : list) {
2033                                    if ((recordSetId != ddlRecord.getRecordSetId())) {
2034                                            list = null;
2035    
2036                                            break;
2037                                    }
2038                            }
2039                    }
2040    
2041                    if (list == null) {
2042                            StringBundler query = null;
2043    
2044                            if (orderByComparator != null) {
2045                                    query = new StringBundler(3 +
2046                                                    (orderByComparator.getOrderByFields().length * 3));
2047                            }
2048                            else {
2049                                    query = new StringBundler(3);
2050                            }
2051    
2052                            query.append(_SQL_SELECT_DDLRECORD_WHERE);
2053    
2054                            query.append(_FINDER_COLUMN_RECORDSETID_RECORDSETID_2);
2055    
2056                            if (orderByComparator != null) {
2057                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2058                                            orderByComparator);
2059                            }
2060                            else
2061                             if (pagination) {
2062                                    query.append(DDLRecordModelImpl.ORDER_BY_JPQL);
2063                            }
2064    
2065                            String sql = query.toString();
2066    
2067                            Session session = null;
2068    
2069                            try {
2070                                    session = openSession();
2071    
2072                                    Query q = session.createQuery(sql);
2073    
2074                                    QueryPos qPos = QueryPos.getInstance(q);
2075    
2076                                    qPos.add(recordSetId);
2077    
2078                                    if (!pagination) {
2079                                            list = (List<DDLRecord>)QueryUtil.list(q, getDialect(),
2080                                                            start, end, false);
2081    
2082                                            Collections.sort(list);
2083    
2084                                            list = new UnmodifiableList<DDLRecord>(list);
2085                                    }
2086                                    else {
2087                                            list = (List<DDLRecord>)QueryUtil.list(q, getDialect(),
2088                                                            start, end);
2089                                    }
2090    
2091                                    cacheResult(list);
2092    
2093                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2094                            }
2095                            catch (Exception e) {
2096                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2097    
2098                                    throw processException(e);
2099                            }
2100                            finally {
2101                                    closeSession(session);
2102                            }
2103                    }
2104    
2105                    return list;
2106            }
2107    
2108            /**
2109             * Returns the first d d l record in the ordered set where recordSetId = &#63;.
2110             *
2111             * @param recordSetId the record set ID
2112             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2113             * @return the first matching d d l record
2114             * @throws com.liferay.portlet.dynamicdatalists.NoSuchRecordException if a matching d d l record could not be found
2115             * @throws SystemException if a system exception occurred
2116             */
2117            @Override
2118            public DDLRecord findByRecordSetId_First(long recordSetId,
2119                    OrderByComparator orderByComparator)
2120                    throws NoSuchRecordException, SystemException {
2121                    DDLRecord ddlRecord = fetchByRecordSetId_First(recordSetId,
2122                                    orderByComparator);
2123    
2124                    if (ddlRecord != null) {
2125                            return ddlRecord;
2126                    }
2127    
2128                    StringBundler msg = new StringBundler(4);
2129    
2130                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2131    
2132                    msg.append("recordSetId=");
2133                    msg.append(recordSetId);
2134    
2135                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2136    
2137                    throw new NoSuchRecordException(msg.toString());
2138            }
2139    
2140            /**
2141             * Returns the first d d l record in the ordered set where recordSetId = &#63;.
2142             *
2143             * @param recordSetId the record set ID
2144             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2145             * @return the first matching d d l record, or <code>null</code> if a matching d d l record could not be found
2146             * @throws SystemException if a system exception occurred
2147             */
2148            @Override
2149            public DDLRecord fetchByRecordSetId_First(long recordSetId,
2150                    OrderByComparator orderByComparator) throws SystemException {
2151                    List<DDLRecord> list = findByRecordSetId(recordSetId, 0, 1,
2152                                    orderByComparator);
2153    
2154                    if (!list.isEmpty()) {
2155                            return list.get(0);
2156                    }
2157    
2158                    return null;
2159            }
2160    
2161            /**
2162             * Returns the last d d l record in the ordered set where recordSetId = &#63;.
2163             *
2164             * @param recordSetId the record set ID
2165             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2166             * @return the last matching d d l record
2167             * @throws com.liferay.portlet.dynamicdatalists.NoSuchRecordException if a matching d d l record could not be found
2168             * @throws SystemException if a system exception occurred
2169             */
2170            @Override
2171            public DDLRecord findByRecordSetId_Last(long recordSetId,
2172                    OrderByComparator orderByComparator)
2173                    throws NoSuchRecordException, SystemException {
2174                    DDLRecord ddlRecord = fetchByRecordSetId_Last(recordSetId,
2175                                    orderByComparator);
2176    
2177                    if (ddlRecord != null) {
2178                            return ddlRecord;
2179                    }
2180    
2181                    StringBundler msg = new StringBundler(4);
2182    
2183                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2184    
2185                    msg.append("recordSetId=");
2186                    msg.append(recordSetId);
2187    
2188                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2189    
2190                    throw new NoSuchRecordException(msg.toString());
2191            }
2192    
2193            /**
2194             * Returns the last d d l record in the ordered set where recordSetId = &#63;.
2195             *
2196             * @param recordSetId the record set ID
2197             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2198             * @return the last matching d d l record, or <code>null</code> if a matching d d l record could not be found
2199             * @throws SystemException if a system exception occurred
2200             */
2201            @Override
2202            public DDLRecord fetchByRecordSetId_Last(long recordSetId,
2203                    OrderByComparator orderByComparator) throws SystemException {
2204                    int count = countByRecordSetId(recordSetId);
2205    
2206                    if (count == 0) {
2207                            return null;
2208                    }
2209    
2210                    List<DDLRecord> list = findByRecordSetId(recordSetId, count - 1, count,
2211                                    orderByComparator);
2212    
2213                    if (!list.isEmpty()) {
2214                            return list.get(0);
2215                    }
2216    
2217                    return null;
2218            }
2219    
2220            /**
2221             * Returns the d d l records before and after the current d d l record in the ordered set where recordSetId = &#63;.
2222             *
2223             * @param recordId the primary key of the current d d l record
2224             * @param recordSetId the record set ID
2225             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2226             * @return the previous, current, and next d d l record
2227             * @throws com.liferay.portlet.dynamicdatalists.NoSuchRecordException if a d d l record with the primary key could not be found
2228             * @throws SystemException if a system exception occurred
2229             */
2230            @Override
2231            public DDLRecord[] findByRecordSetId_PrevAndNext(long recordId,
2232                    long recordSetId, OrderByComparator orderByComparator)
2233                    throws NoSuchRecordException, SystemException {
2234                    DDLRecord ddlRecord = findByPrimaryKey(recordId);
2235    
2236                    Session session = null;
2237    
2238                    try {
2239                            session = openSession();
2240    
2241                            DDLRecord[] array = new DDLRecordImpl[3];
2242    
2243                            array[0] = getByRecordSetId_PrevAndNext(session, ddlRecord,
2244                                            recordSetId, orderByComparator, true);
2245    
2246                            array[1] = ddlRecord;
2247    
2248                            array[2] = getByRecordSetId_PrevAndNext(session, ddlRecord,
2249                                            recordSetId, orderByComparator, false);
2250    
2251                            return array;
2252                    }
2253                    catch (Exception e) {
2254                            throw processException(e);
2255                    }
2256                    finally {
2257                            closeSession(session);
2258                    }
2259            }
2260    
2261            protected DDLRecord getByRecordSetId_PrevAndNext(Session session,
2262                    DDLRecord ddlRecord, long recordSetId,
2263                    OrderByComparator orderByComparator, boolean previous) {
2264                    StringBundler query = null;
2265    
2266                    if (orderByComparator != null) {
2267                            query = new StringBundler(6 +
2268                                            (orderByComparator.getOrderByFields().length * 6));
2269                    }
2270                    else {
2271                            query = new StringBundler(3);
2272                    }
2273    
2274                    query.append(_SQL_SELECT_DDLRECORD_WHERE);
2275    
2276                    query.append(_FINDER_COLUMN_RECORDSETID_RECORDSETID_2);
2277    
2278                    if (orderByComparator != null) {
2279                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2280    
2281                            if (orderByConditionFields.length > 0) {
2282                                    query.append(WHERE_AND);
2283                            }
2284    
2285                            for (int i = 0; i < orderByConditionFields.length; i++) {
2286                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2287                                    query.append(orderByConditionFields[i]);
2288    
2289                                    if ((i + 1) < orderByConditionFields.length) {
2290                                            if (orderByComparator.isAscending() ^ previous) {
2291                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2292                                            }
2293                                            else {
2294                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2295                                            }
2296                                    }
2297                                    else {
2298                                            if (orderByComparator.isAscending() ^ previous) {
2299                                                    query.append(WHERE_GREATER_THAN);
2300                                            }
2301                                            else {
2302                                                    query.append(WHERE_LESSER_THAN);
2303                                            }
2304                                    }
2305                            }
2306    
2307                            query.append(ORDER_BY_CLAUSE);
2308    
2309                            String[] orderByFields = orderByComparator.getOrderByFields();
2310    
2311                            for (int i = 0; i < orderByFields.length; i++) {
2312                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2313                                    query.append(orderByFields[i]);
2314    
2315                                    if ((i + 1) < orderByFields.length) {
2316                                            if (orderByComparator.isAscending() ^ previous) {
2317                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2318                                            }
2319                                            else {
2320                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2321                                            }
2322                                    }
2323                                    else {
2324                                            if (orderByComparator.isAscending() ^ previous) {
2325                                                    query.append(ORDER_BY_ASC);
2326                                            }
2327                                            else {
2328                                                    query.append(ORDER_BY_DESC);
2329                                            }
2330                                    }
2331                            }
2332                    }
2333                    else {
2334                            query.append(DDLRecordModelImpl.ORDER_BY_JPQL);
2335                    }
2336    
2337                    String sql = query.toString();
2338    
2339                    Query q = session.createQuery(sql);
2340    
2341                    q.setFirstResult(0);
2342                    q.setMaxResults(2);
2343    
2344                    QueryPos qPos = QueryPos.getInstance(q);
2345    
2346                    qPos.add(recordSetId);
2347    
2348                    if (orderByComparator != null) {
2349                            Object[] values = orderByComparator.getOrderByConditionValues(ddlRecord);
2350    
2351                            for (Object value : values) {
2352                                    qPos.add(value);
2353                            }
2354                    }
2355    
2356                    List<DDLRecord> list = q.list();
2357    
2358                    if (list.size() == 2) {
2359                            return list.get(1);
2360                    }
2361                    else {
2362                            return null;
2363                    }
2364            }
2365    
2366            /**
2367             * Removes all the d d l records where recordSetId = &#63; from the database.
2368             *
2369             * @param recordSetId the record set ID
2370             * @throws SystemException if a system exception occurred
2371             */
2372            @Override
2373            public void removeByRecordSetId(long recordSetId) throws SystemException {
2374                    for (DDLRecord ddlRecord : findByRecordSetId(recordSetId,
2375                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2376                            remove(ddlRecord);
2377                    }
2378            }
2379    
2380            /**
2381             * Returns the number of d d l records where recordSetId = &#63;.
2382             *
2383             * @param recordSetId the record set ID
2384             * @return the number of matching d d l records
2385             * @throws SystemException if a system exception occurred
2386             */
2387            @Override
2388            public int countByRecordSetId(long recordSetId) throws SystemException {
2389                    FinderPath finderPath = FINDER_PATH_COUNT_BY_RECORDSETID;
2390    
2391                    Object[] finderArgs = new Object[] { recordSetId };
2392    
2393                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2394                                    this);
2395    
2396                    if (count == null) {
2397                            StringBundler query = new StringBundler(2);
2398    
2399                            query.append(_SQL_COUNT_DDLRECORD_WHERE);
2400    
2401                            query.append(_FINDER_COLUMN_RECORDSETID_RECORDSETID_2);
2402    
2403                            String sql = query.toString();
2404    
2405                            Session session = null;
2406    
2407                            try {
2408                                    session = openSession();
2409    
2410                                    Query q = session.createQuery(sql);
2411    
2412                                    QueryPos qPos = QueryPos.getInstance(q);
2413    
2414                                    qPos.add(recordSetId);
2415    
2416                                    count = (Long)q.uniqueResult();
2417    
2418                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2419                            }
2420                            catch (Exception e) {
2421                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2422    
2423                                    throw processException(e);
2424                            }
2425                            finally {
2426                                    closeSession(session);
2427                            }
2428                    }
2429    
2430                    return count.intValue();
2431            }
2432    
2433            private static final String _FINDER_COLUMN_RECORDSETID_RECORDSETID_2 = "ddlRecord.recordSetId = ?";
2434            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_R_U = new FinderPath(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
2435                            DDLRecordModelImpl.FINDER_CACHE_ENABLED, DDLRecordImpl.class,
2436                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByR_U",
2437                            new String[] {
2438                                    Long.class.getName(), Long.class.getName(),
2439                                    
2440                            Integer.class.getName(), Integer.class.getName(),
2441                                    OrderByComparator.class.getName()
2442                            });
2443            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_U = new FinderPath(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
2444                            DDLRecordModelImpl.FINDER_CACHE_ENABLED, DDLRecordImpl.class,
2445                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByR_U",
2446                            new String[] { Long.class.getName(), Long.class.getName() },
2447                            DDLRecordModelImpl.RECORDSETID_COLUMN_BITMASK |
2448                            DDLRecordModelImpl.USERID_COLUMN_BITMASK);
2449            public static final FinderPath FINDER_PATH_COUNT_BY_R_U = new FinderPath(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
2450                            DDLRecordModelImpl.FINDER_CACHE_ENABLED, Long.class,
2451                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_U",
2452                            new String[] { Long.class.getName(), Long.class.getName() });
2453    
2454            /**
2455             * Returns all the d d l records where recordSetId = &#63; and userId = &#63;.
2456             *
2457             * @param recordSetId the record set ID
2458             * @param userId the user ID
2459             * @return the matching d d l records
2460             * @throws SystemException if a system exception occurred
2461             */
2462            @Override
2463            public List<DDLRecord> findByR_U(long recordSetId, long userId)
2464                    throws SystemException {
2465                    return findByR_U(recordSetId, userId, QueryUtil.ALL_POS,
2466                            QueryUtil.ALL_POS, null);
2467            }
2468    
2469            /**
2470             * Returns a range of all the d d l records where recordSetId = &#63; and userId = &#63;.
2471             *
2472             * <p>
2473             * 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.DDLRecordModelImpl}. 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.
2474             * </p>
2475             *
2476             * @param recordSetId the record set ID
2477             * @param userId the user ID
2478             * @param start the lower bound of the range of d d l records
2479             * @param end the upper bound of the range of d d l records (not inclusive)
2480             * @return the range of matching d d l records
2481             * @throws SystemException if a system exception occurred
2482             */
2483            @Override
2484            public List<DDLRecord> findByR_U(long recordSetId, long userId, int start,
2485                    int end) throws SystemException {
2486                    return findByR_U(recordSetId, userId, start, end, null);
2487            }
2488    
2489            /**
2490             * Returns an ordered range of all the d d l records where recordSetId = &#63; and userId = &#63;.
2491             *
2492             * <p>
2493             * 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.DDLRecordModelImpl}. 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.
2494             * </p>
2495             *
2496             * @param recordSetId the record set ID
2497             * @param userId the user ID
2498             * @param start the lower bound of the range of d d l records
2499             * @param end the upper bound of the range of d d l records (not inclusive)
2500             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2501             * @return the ordered range of matching d d l records
2502             * @throws SystemException if a system exception occurred
2503             */
2504            @Override
2505            public List<DDLRecord> findByR_U(long recordSetId, long userId, int start,
2506                    int end, OrderByComparator orderByComparator) throws SystemException {
2507                    boolean pagination = true;
2508                    FinderPath finderPath = null;
2509                    Object[] finderArgs = null;
2510    
2511                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2512                                    (orderByComparator == null)) {
2513                            pagination = false;
2514                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_U;
2515                            finderArgs = new Object[] { recordSetId, userId };
2516                    }
2517                    else {
2518                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_U;
2519                            finderArgs = new Object[] {
2520                                            recordSetId, userId,
2521                                            
2522                                            start, end, orderByComparator
2523                                    };
2524                    }
2525    
2526                    List<DDLRecord> list = (List<DDLRecord>)FinderCacheUtil.getResult(finderPath,
2527                                    finderArgs, this);
2528    
2529                    if ((list != null) && !list.isEmpty()) {
2530                            for (DDLRecord ddlRecord : list) {
2531                                    if ((recordSetId != ddlRecord.getRecordSetId()) ||
2532                                                    (userId != ddlRecord.getUserId())) {
2533                                            list = null;
2534    
2535                                            break;
2536                                    }
2537                            }
2538                    }
2539    
2540                    if (list == null) {
2541                            StringBundler query = null;
2542    
2543                            if (orderByComparator != null) {
2544                                    query = new StringBundler(4 +
2545                                                    (orderByComparator.getOrderByFields().length * 3));
2546                            }
2547                            else {
2548                                    query = new StringBundler(4);
2549                            }
2550    
2551                            query.append(_SQL_SELECT_DDLRECORD_WHERE);
2552    
2553                            query.append(_FINDER_COLUMN_R_U_RECORDSETID_2);
2554    
2555                            query.append(_FINDER_COLUMN_R_U_USERID_2);
2556    
2557                            if (orderByComparator != null) {
2558                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2559                                            orderByComparator);
2560                            }
2561                            else
2562                             if (pagination) {
2563                                    query.append(DDLRecordModelImpl.ORDER_BY_JPQL);
2564                            }
2565    
2566                            String sql = query.toString();
2567    
2568                            Session session = null;
2569    
2570                            try {
2571                                    session = openSession();
2572    
2573                                    Query q = session.createQuery(sql);
2574    
2575                                    QueryPos qPos = QueryPos.getInstance(q);
2576    
2577                                    qPos.add(recordSetId);
2578    
2579                                    qPos.add(userId);
2580    
2581                                    if (!pagination) {
2582                                            list = (List<DDLRecord>)QueryUtil.list(q, getDialect(),
2583                                                            start, end, false);
2584    
2585                                            Collections.sort(list);
2586    
2587                                            list = new UnmodifiableList<DDLRecord>(list);
2588                                    }
2589                                    else {
2590                                            list = (List<DDLRecord>)QueryUtil.list(q, getDialect(),
2591                                                            start, end);
2592                                    }
2593    
2594                                    cacheResult(list);
2595    
2596                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2597                            }
2598                            catch (Exception e) {
2599                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2600    
2601                                    throw processException(e);
2602                            }
2603                            finally {
2604                                    closeSession(session);
2605                            }
2606                    }
2607    
2608                    return list;
2609            }
2610    
2611            /**
2612             * Returns the first d d l record in the ordered set where recordSetId = &#63; and userId = &#63;.
2613             *
2614             * @param recordSetId the record set ID
2615             * @param userId the user ID
2616             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2617             * @return the first matching d d l record
2618             * @throws com.liferay.portlet.dynamicdatalists.NoSuchRecordException if a matching d d l record could not be found
2619             * @throws SystemException if a system exception occurred
2620             */
2621            @Override
2622            public DDLRecord findByR_U_First(long recordSetId, long userId,
2623                    OrderByComparator orderByComparator)
2624                    throws NoSuchRecordException, SystemException {
2625                    DDLRecord ddlRecord = fetchByR_U_First(recordSetId, userId,
2626                                    orderByComparator);
2627    
2628                    if (ddlRecord != null) {
2629                            return ddlRecord;
2630                    }
2631    
2632                    StringBundler msg = new StringBundler(6);
2633    
2634                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2635    
2636                    msg.append("recordSetId=");
2637                    msg.append(recordSetId);
2638    
2639                    msg.append(", userId=");
2640                    msg.append(userId);
2641    
2642                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2643    
2644                    throw new NoSuchRecordException(msg.toString());
2645            }
2646    
2647            /**
2648             * Returns the first d d l record in the ordered set where recordSetId = &#63; and userId = &#63;.
2649             *
2650             * @param recordSetId the record set ID
2651             * @param userId the user ID
2652             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2653             * @return the first matching d d l record, or <code>null</code> if a matching d d l record could not be found
2654             * @throws SystemException if a system exception occurred
2655             */
2656            @Override
2657            public DDLRecord fetchByR_U_First(long recordSetId, long userId,
2658                    OrderByComparator orderByComparator) throws SystemException {
2659                    List<DDLRecord> list = findByR_U(recordSetId, userId, 0, 1,
2660                                    orderByComparator);
2661    
2662                    if (!list.isEmpty()) {
2663                            return list.get(0);
2664                    }
2665    
2666                    return null;
2667            }
2668    
2669            /**
2670             * Returns the last d d l record in the ordered set where recordSetId = &#63; and userId = &#63;.
2671             *
2672             * @param recordSetId the record set ID
2673             * @param userId the user ID
2674             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2675             * @return the last matching d d l record
2676             * @throws com.liferay.portlet.dynamicdatalists.NoSuchRecordException if a matching d d l record could not be found
2677             * @throws SystemException if a system exception occurred
2678             */
2679            @Override
2680            public DDLRecord findByR_U_Last(long recordSetId, long userId,
2681                    OrderByComparator orderByComparator)
2682                    throws NoSuchRecordException, SystemException {
2683                    DDLRecord ddlRecord = fetchByR_U_Last(recordSetId, userId,
2684                                    orderByComparator);
2685    
2686                    if (ddlRecord != null) {
2687                            return ddlRecord;
2688                    }
2689    
2690                    StringBundler msg = new StringBundler(6);
2691    
2692                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2693    
2694                    msg.append("recordSetId=");
2695                    msg.append(recordSetId);
2696    
2697                    msg.append(", userId=");
2698                    msg.append(userId);
2699    
2700                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2701    
2702                    throw new NoSuchRecordException(msg.toString());
2703            }
2704    
2705            /**
2706             * Returns the last d d l record in the ordered set where recordSetId = &#63; and userId = &#63;.
2707             *
2708             * @param recordSetId the record set ID
2709             * @param userId the user ID
2710             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2711             * @return the last matching d d l record, or <code>null</code> if a matching d d l record could not be found
2712             * @throws SystemException if a system exception occurred
2713             */
2714            @Override
2715            public DDLRecord fetchByR_U_Last(long recordSetId, long userId,
2716                    OrderByComparator orderByComparator) throws SystemException {
2717                    int count = countByR_U(recordSetId, userId);
2718    
2719                    if (count == 0) {
2720                            return null;
2721                    }
2722    
2723                    List<DDLRecord> list = findByR_U(recordSetId, userId, count - 1, count,
2724                                    orderByComparator);
2725    
2726                    if (!list.isEmpty()) {
2727                            return list.get(0);
2728                    }
2729    
2730                    return null;
2731            }
2732    
2733            /**
2734             * Returns the d d l records before and after the current d d l record in the ordered set where recordSetId = &#63; and userId = &#63;.
2735             *
2736             * @param recordId the primary key of the current d d l record
2737             * @param recordSetId the record set ID
2738             * @param userId the user ID
2739             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2740             * @return the previous, current, and next d d l record
2741             * @throws com.liferay.portlet.dynamicdatalists.NoSuchRecordException if a d d l record with the primary key could not be found
2742             * @throws SystemException if a system exception occurred
2743             */
2744            @Override
2745            public DDLRecord[] findByR_U_PrevAndNext(long recordId, long recordSetId,
2746                    long userId, OrderByComparator orderByComparator)
2747                    throws NoSuchRecordException, SystemException {
2748                    DDLRecord ddlRecord = findByPrimaryKey(recordId);
2749    
2750                    Session session = null;
2751    
2752                    try {
2753                            session = openSession();
2754    
2755                            DDLRecord[] array = new DDLRecordImpl[3];
2756    
2757                            array[0] = getByR_U_PrevAndNext(session, ddlRecord, recordSetId,
2758                                            userId, orderByComparator, true);
2759    
2760                            array[1] = ddlRecord;
2761    
2762                            array[2] = getByR_U_PrevAndNext(session, ddlRecord, recordSetId,
2763                                            userId, orderByComparator, false);
2764    
2765                            return array;
2766                    }
2767                    catch (Exception e) {
2768                            throw processException(e);
2769                    }
2770                    finally {
2771                            closeSession(session);
2772                    }
2773            }
2774    
2775            protected DDLRecord getByR_U_PrevAndNext(Session session,
2776                    DDLRecord ddlRecord, long recordSetId, long userId,
2777                    OrderByComparator orderByComparator, boolean previous) {
2778                    StringBundler query = null;
2779    
2780                    if (orderByComparator != null) {
2781                            query = new StringBundler(6 +
2782                                            (orderByComparator.getOrderByFields().length * 6));
2783                    }
2784                    else {
2785                            query = new StringBundler(3);
2786                    }
2787    
2788                    query.append(_SQL_SELECT_DDLRECORD_WHERE);
2789    
2790                    query.append(_FINDER_COLUMN_R_U_RECORDSETID_2);
2791    
2792                    query.append(_FINDER_COLUMN_R_U_USERID_2);
2793    
2794                    if (orderByComparator != null) {
2795                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2796    
2797                            if (orderByConditionFields.length > 0) {
2798                                    query.append(WHERE_AND);
2799                            }
2800    
2801                            for (int i = 0; i < orderByConditionFields.length; i++) {
2802                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2803                                    query.append(orderByConditionFields[i]);
2804    
2805                                    if ((i + 1) < orderByConditionFields.length) {
2806                                            if (orderByComparator.isAscending() ^ previous) {
2807                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2808                                            }
2809                                            else {
2810                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2811                                            }
2812                                    }
2813                                    else {
2814                                            if (orderByComparator.isAscending() ^ previous) {
2815                                                    query.append(WHERE_GREATER_THAN);
2816                                            }
2817                                            else {
2818                                                    query.append(WHERE_LESSER_THAN);
2819                                            }
2820                                    }
2821                            }
2822    
2823                            query.append(ORDER_BY_CLAUSE);
2824    
2825                            String[] orderByFields = orderByComparator.getOrderByFields();
2826    
2827                            for (int i = 0; i < orderByFields.length; i++) {
2828                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2829                                    query.append(orderByFields[i]);
2830    
2831                                    if ((i + 1) < orderByFields.length) {
2832                                            if (orderByComparator.isAscending() ^ previous) {
2833                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2834                                            }
2835                                            else {
2836                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2837                                            }
2838                                    }
2839                                    else {
2840                                            if (orderByComparator.isAscending() ^ previous) {
2841                                                    query.append(ORDER_BY_ASC);
2842                                            }
2843                                            else {
2844                                                    query.append(ORDER_BY_DESC);
2845                                            }
2846                                    }
2847                            }
2848                    }
2849                    else {
2850                            query.append(DDLRecordModelImpl.ORDER_BY_JPQL);
2851                    }
2852    
2853                    String sql = query.toString();
2854    
2855                    Query q = session.createQuery(sql);
2856    
2857                    q.setFirstResult(0);
2858                    q.setMaxResults(2);
2859    
2860                    QueryPos qPos = QueryPos.getInstance(q);
2861    
2862                    qPos.add(recordSetId);
2863    
2864                    qPos.add(userId);
2865    
2866                    if (orderByComparator != null) {
2867                            Object[] values = orderByComparator.getOrderByConditionValues(ddlRecord);
2868    
2869                            for (Object value : values) {
2870                                    qPos.add(value);
2871                            }
2872                    }
2873    
2874                    List<DDLRecord> list = q.list();
2875    
2876                    if (list.size() == 2) {
2877                            return list.get(1);
2878                    }
2879                    else {
2880                            return null;
2881                    }
2882            }
2883    
2884            /**
2885             * Removes all the d d l records where recordSetId = &#63; and userId = &#63; from the database.
2886             *
2887             * @param recordSetId the record set ID
2888             * @param userId the user ID
2889             * @throws SystemException if a system exception occurred
2890             */
2891            @Override
2892            public void removeByR_U(long recordSetId, long userId)
2893                    throws SystemException {
2894                    for (DDLRecord ddlRecord : findByR_U(recordSetId, userId,
2895                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2896                            remove(ddlRecord);
2897                    }
2898            }
2899    
2900            /**
2901             * Returns the number of d d l records where recordSetId = &#63; and userId = &#63;.
2902             *
2903             * @param recordSetId the record set ID
2904             * @param userId the user ID
2905             * @return the number of matching d d l records
2906             * @throws SystemException if a system exception occurred
2907             */
2908            @Override
2909            public int countByR_U(long recordSetId, long userId)
2910                    throws SystemException {
2911                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_U;
2912    
2913                    Object[] finderArgs = new Object[] { recordSetId, userId };
2914    
2915                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2916                                    this);
2917    
2918                    if (count == null) {
2919                            StringBundler query = new StringBundler(3);
2920    
2921                            query.append(_SQL_COUNT_DDLRECORD_WHERE);
2922    
2923                            query.append(_FINDER_COLUMN_R_U_RECORDSETID_2);
2924    
2925                            query.append(_FINDER_COLUMN_R_U_USERID_2);
2926    
2927                            String sql = query.toString();
2928    
2929                            Session session = null;
2930    
2931                            try {
2932                                    session = openSession();
2933    
2934                                    Query q = session.createQuery(sql);
2935    
2936                                    QueryPos qPos = QueryPos.getInstance(q);
2937    
2938                                    qPos.add(recordSetId);
2939    
2940                                    qPos.add(userId);
2941    
2942                                    count = (Long)q.uniqueResult();
2943    
2944                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2945                            }
2946                            catch (Exception e) {
2947                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2948    
2949                                    throw processException(e);
2950                            }
2951                            finally {
2952                                    closeSession(session);
2953                            }
2954                    }
2955    
2956                    return count.intValue();
2957            }
2958    
2959            private static final String _FINDER_COLUMN_R_U_RECORDSETID_2 = "ddlRecord.recordSetId = ? AND ";
2960            private static final String _FINDER_COLUMN_R_U_USERID_2 = "ddlRecord.userId = ?";
2961    
2962            public DDLRecordPersistenceImpl() {
2963                    setModelClass(DDLRecord.class);
2964            }
2965    
2966            /**
2967             * Caches the d d l record in the entity cache if it is enabled.
2968             *
2969             * @param ddlRecord the d d l record
2970             */
2971            @Override
2972            public void cacheResult(DDLRecord ddlRecord) {
2973                    EntityCacheUtil.putResult(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
2974                            DDLRecordImpl.class, ddlRecord.getPrimaryKey(), ddlRecord);
2975    
2976                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
2977                            new Object[] { ddlRecord.getUuid(), ddlRecord.getGroupId() },
2978                            ddlRecord);
2979    
2980                    ddlRecord.resetOriginalValues();
2981            }
2982    
2983            /**
2984             * Caches the d d l records in the entity cache if it is enabled.
2985             *
2986             * @param ddlRecords the d d l records
2987             */
2988            @Override
2989            public void cacheResult(List<DDLRecord> ddlRecords) {
2990                    for (DDLRecord ddlRecord : ddlRecords) {
2991                            if (EntityCacheUtil.getResult(
2992                                                    DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
2993                                                    DDLRecordImpl.class, ddlRecord.getPrimaryKey()) == null) {
2994                                    cacheResult(ddlRecord);
2995                            }
2996                            else {
2997                                    ddlRecord.resetOriginalValues();
2998                            }
2999                    }
3000            }
3001    
3002            /**
3003             * Clears the cache for all d d l records.
3004             *
3005             * <p>
3006             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
3007             * </p>
3008             */
3009            @Override
3010            public void clearCache() {
3011                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
3012                            CacheRegistryUtil.clear(DDLRecordImpl.class.getName());
3013                    }
3014    
3015                    EntityCacheUtil.clearCache(DDLRecordImpl.class.getName());
3016    
3017                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
3018                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3019                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3020            }
3021    
3022            /**
3023             * Clears the cache for the d d l record.
3024             *
3025             * <p>
3026             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
3027             * </p>
3028             */
3029            @Override
3030            public void clearCache(DDLRecord ddlRecord) {
3031                    EntityCacheUtil.removeResult(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
3032                            DDLRecordImpl.class, ddlRecord.getPrimaryKey());
3033    
3034                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3035                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3036    
3037                    clearUniqueFindersCache(ddlRecord);
3038            }
3039    
3040            @Override
3041            public void clearCache(List<DDLRecord> ddlRecords) {
3042                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3043                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3044    
3045                    for (DDLRecord ddlRecord : ddlRecords) {
3046                            EntityCacheUtil.removeResult(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
3047                                    DDLRecordImpl.class, ddlRecord.getPrimaryKey());
3048    
3049                            clearUniqueFindersCache(ddlRecord);
3050                    }
3051            }
3052    
3053            protected void cacheUniqueFindersCache(DDLRecord ddlRecord) {
3054                    if (ddlRecord.isNew()) {
3055                            Object[] args = new Object[] {
3056                                            ddlRecord.getUuid(), ddlRecord.getGroupId()
3057                                    };
3058    
3059                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
3060                                    Long.valueOf(1));
3061                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
3062                                    ddlRecord);
3063                    }
3064                    else {
3065                            DDLRecordModelImpl ddlRecordModelImpl = (DDLRecordModelImpl)ddlRecord;
3066    
3067                            if ((ddlRecordModelImpl.getColumnBitmask() &
3068                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
3069                                    Object[] args = new Object[] {
3070                                                    ddlRecord.getUuid(), ddlRecord.getGroupId()
3071                                            };
3072    
3073                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
3074                                            Long.valueOf(1));
3075                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
3076                                            ddlRecord);
3077                            }
3078                    }
3079            }
3080    
3081            protected void clearUniqueFindersCache(DDLRecord ddlRecord) {
3082                    DDLRecordModelImpl ddlRecordModelImpl = (DDLRecordModelImpl)ddlRecord;
3083    
3084                    Object[] args = new Object[] { ddlRecord.getUuid(), ddlRecord.getGroupId() };
3085    
3086                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
3087                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
3088    
3089                    if ((ddlRecordModelImpl.getColumnBitmask() &
3090                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
3091                            args = new Object[] {
3092                                            ddlRecordModelImpl.getOriginalUuid(),
3093                                            ddlRecordModelImpl.getOriginalGroupId()
3094                                    };
3095    
3096                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
3097                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
3098                    }
3099            }
3100    
3101            /**
3102             * Creates a new d d l record with the primary key. Does not add the d d l record to the database.
3103             *
3104             * @param recordId the primary key for the new d d l record
3105             * @return the new d d l record
3106             */
3107            @Override
3108            public DDLRecord create(long recordId) {
3109                    DDLRecord ddlRecord = new DDLRecordImpl();
3110    
3111                    ddlRecord.setNew(true);
3112                    ddlRecord.setPrimaryKey(recordId);
3113    
3114                    String uuid = PortalUUIDUtil.generate();
3115    
3116                    ddlRecord.setUuid(uuid);
3117    
3118                    return ddlRecord;
3119            }
3120    
3121            /**
3122             * Removes the d d l record with the primary key from the database. Also notifies the appropriate model listeners.
3123             *
3124             * @param recordId the primary key of the d d l record
3125             * @return the d d l record that was removed
3126             * @throws com.liferay.portlet.dynamicdatalists.NoSuchRecordException if a d d l record with the primary key could not be found
3127             * @throws SystemException if a system exception occurred
3128             */
3129            @Override
3130            public DDLRecord remove(long recordId)
3131                    throws NoSuchRecordException, SystemException {
3132                    return remove((Serializable)recordId);
3133            }
3134    
3135            /**
3136             * Removes the d d l record with the primary key from the database. Also notifies the appropriate model listeners.
3137             *
3138             * @param primaryKey the primary key of the d d l record
3139             * @return the d d l record that was removed
3140             * @throws com.liferay.portlet.dynamicdatalists.NoSuchRecordException if a d d l record with the primary key could not be found
3141             * @throws SystemException if a system exception occurred
3142             */
3143            @Override
3144            public DDLRecord remove(Serializable primaryKey)
3145                    throws NoSuchRecordException, SystemException {
3146                    Session session = null;
3147    
3148                    try {
3149                            session = openSession();
3150    
3151                            DDLRecord ddlRecord = (DDLRecord)session.get(DDLRecordImpl.class,
3152                                            primaryKey);
3153    
3154                            if (ddlRecord == null) {
3155                                    if (_log.isWarnEnabled()) {
3156                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3157                                    }
3158    
3159                                    throw new NoSuchRecordException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3160                                            primaryKey);
3161                            }
3162    
3163                            return remove(ddlRecord);
3164                    }
3165                    catch (NoSuchRecordException nsee) {
3166                            throw nsee;
3167                    }
3168                    catch (Exception e) {
3169                            throw processException(e);
3170                    }
3171                    finally {
3172                            closeSession(session);
3173                    }
3174            }
3175    
3176            @Override
3177            protected DDLRecord removeImpl(DDLRecord ddlRecord)
3178                    throws SystemException {
3179                    ddlRecord = toUnwrappedModel(ddlRecord);
3180    
3181                    Session session = null;
3182    
3183                    try {
3184                            session = openSession();
3185    
3186                            if (!session.contains(ddlRecord)) {
3187                                    ddlRecord = (DDLRecord)session.get(DDLRecordImpl.class,
3188                                                    ddlRecord.getPrimaryKeyObj());
3189                            }
3190    
3191                            if (ddlRecord != null) {
3192                                    session.delete(ddlRecord);
3193                            }
3194                    }
3195                    catch (Exception e) {
3196                            throw processException(e);
3197                    }
3198                    finally {
3199                            closeSession(session);
3200                    }
3201    
3202                    if (ddlRecord != null) {
3203                            clearCache(ddlRecord);
3204                    }
3205    
3206                    return ddlRecord;
3207            }
3208    
3209            @Override
3210            public DDLRecord updateImpl(
3211                    com.liferay.portlet.dynamicdatalists.model.DDLRecord ddlRecord)
3212                    throws SystemException {
3213                    ddlRecord = toUnwrappedModel(ddlRecord);
3214    
3215                    boolean isNew = ddlRecord.isNew();
3216    
3217                    DDLRecordModelImpl ddlRecordModelImpl = (DDLRecordModelImpl)ddlRecord;
3218    
3219                    if (Validator.isNull(ddlRecord.getUuid())) {
3220                            String uuid = PortalUUIDUtil.generate();
3221    
3222                            ddlRecord.setUuid(uuid);
3223                    }
3224    
3225                    Session session = null;
3226    
3227                    try {
3228                            session = openSession();
3229    
3230                            if (ddlRecord.isNew()) {
3231                                    session.save(ddlRecord);
3232    
3233                                    ddlRecord.setNew(false);
3234                            }
3235                            else {
3236                                    session.merge(ddlRecord);
3237                            }
3238                    }
3239                    catch (Exception e) {
3240                            throw processException(e);
3241                    }
3242                    finally {
3243                            closeSession(session);
3244                    }
3245    
3246                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3247    
3248                    if (isNew || !DDLRecordModelImpl.COLUMN_BITMASK_ENABLED) {
3249                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3250                    }
3251    
3252                    else {
3253                            if ((ddlRecordModelImpl.getColumnBitmask() &
3254                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
3255                                    Object[] args = new Object[] {
3256                                                    ddlRecordModelImpl.getOriginalUuid()
3257                                            };
3258    
3259                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
3260                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
3261                                            args);
3262    
3263                                    args = new Object[] { ddlRecordModelImpl.getUuid() };
3264    
3265                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
3266                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
3267                                            args);
3268                            }
3269    
3270                            if ((ddlRecordModelImpl.getColumnBitmask() &
3271                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
3272                                    Object[] args = new Object[] {
3273                                                    ddlRecordModelImpl.getOriginalUuid(),
3274                                                    ddlRecordModelImpl.getOriginalCompanyId()
3275                                            };
3276    
3277                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
3278                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
3279                                            args);
3280    
3281                                    args = new Object[] {
3282                                                    ddlRecordModelImpl.getUuid(),
3283                                                    ddlRecordModelImpl.getCompanyId()
3284                                            };
3285    
3286                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
3287                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
3288                                            args);
3289                            }
3290    
3291                            if ((ddlRecordModelImpl.getColumnBitmask() &
3292                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
3293                                    Object[] args = new Object[] {
3294                                                    ddlRecordModelImpl.getOriginalCompanyId()
3295                                            };
3296    
3297                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
3298                                            args);
3299                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
3300                                            args);
3301    
3302                                    args = new Object[] { ddlRecordModelImpl.getCompanyId() };
3303    
3304                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
3305                                            args);
3306                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
3307                                            args);
3308                            }
3309    
3310                            if ((ddlRecordModelImpl.getColumnBitmask() &
3311                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECORDSETID.getColumnBitmask()) != 0) {
3312                                    Object[] args = new Object[] {
3313                                                    ddlRecordModelImpl.getOriginalRecordSetId()
3314                                            };
3315    
3316                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RECORDSETID,
3317                                            args);
3318                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECORDSETID,
3319                                            args);
3320    
3321                                    args = new Object[] { ddlRecordModelImpl.getRecordSetId() };
3322    
3323                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RECORDSETID,
3324                                            args);
3325                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECORDSETID,
3326                                            args);
3327                            }
3328    
3329                            if ((ddlRecordModelImpl.getColumnBitmask() &
3330                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_U.getColumnBitmask()) != 0) {
3331                                    Object[] args = new Object[] {
3332                                                    ddlRecordModelImpl.getOriginalRecordSetId(),
3333                                                    ddlRecordModelImpl.getOriginalUserId()
3334                                            };
3335    
3336                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_U, args);
3337                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_U,
3338                                            args);
3339    
3340                                    args = new Object[] {
3341                                                    ddlRecordModelImpl.getRecordSetId(),
3342                                                    ddlRecordModelImpl.getUserId()
3343                                            };
3344    
3345                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_U, args);
3346                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_U,
3347                                            args);
3348                            }
3349                    }
3350    
3351                    EntityCacheUtil.putResult(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
3352                            DDLRecordImpl.class, ddlRecord.getPrimaryKey(), ddlRecord);
3353    
3354                    clearUniqueFindersCache(ddlRecord);
3355                    cacheUniqueFindersCache(ddlRecord);
3356    
3357                    return ddlRecord;
3358            }
3359    
3360            protected DDLRecord toUnwrappedModel(DDLRecord ddlRecord) {
3361                    if (ddlRecord instanceof DDLRecordImpl) {
3362                            return ddlRecord;
3363                    }
3364    
3365                    DDLRecordImpl ddlRecordImpl = new DDLRecordImpl();
3366    
3367                    ddlRecordImpl.setNew(ddlRecord.isNew());
3368                    ddlRecordImpl.setPrimaryKey(ddlRecord.getPrimaryKey());
3369    
3370                    ddlRecordImpl.setUuid(ddlRecord.getUuid());
3371                    ddlRecordImpl.setRecordId(ddlRecord.getRecordId());
3372                    ddlRecordImpl.setGroupId(ddlRecord.getGroupId());
3373                    ddlRecordImpl.setCompanyId(ddlRecord.getCompanyId());
3374                    ddlRecordImpl.setUserId(ddlRecord.getUserId());
3375                    ddlRecordImpl.setUserName(ddlRecord.getUserName());
3376                    ddlRecordImpl.setVersionUserId(ddlRecord.getVersionUserId());
3377                    ddlRecordImpl.setVersionUserName(ddlRecord.getVersionUserName());
3378                    ddlRecordImpl.setCreateDate(ddlRecord.getCreateDate());
3379                    ddlRecordImpl.setModifiedDate(ddlRecord.getModifiedDate());
3380                    ddlRecordImpl.setDDMStorageId(ddlRecord.getDDMStorageId());
3381                    ddlRecordImpl.setRecordSetId(ddlRecord.getRecordSetId());
3382                    ddlRecordImpl.setVersion(ddlRecord.getVersion());
3383                    ddlRecordImpl.setDisplayIndex(ddlRecord.getDisplayIndex());
3384    
3385                    return ddlRecordImpl;
3386            }
3387    
3388            /**
3389             * Returns the d d l record with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
3390             *
3391             * @param primaryKey the primary key of the d d l record
3392             * @return the d d l record
3393             * @throws com.liferay.portlet.dynamicdatalists.NoSuchRecordException if a d d l record with the primary key could not be found
3394             * @throws SystemException if a system exception occurred
3395             */
3396            @Override
3397            public DDLRecord findByPrimaryKey(Serializable primaryKey)
3398                    throws NoSuchRecordException, SystemException {
3399                    DDLRecord ddlRecord = fetchByPrimaryKey(primaryKey);
3400    
3401                    if (ddlRecord == null) {
3402                            if (_log.isWarnEnabled()) {
3403                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3404                            }
3405    
3406                            throw new NoSuchRecordException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3407                                    primaryKey);
3408                    }
3409    
3410                    return ddlRecord;
3411            }
3412    
3413            /**
3414             * Returns the d d l record with the primary key or throws a {@link com.liferay.portlet.dynamicdatalists.NoSuchRecordException} if it could not be found.
3415             *
3416             * @param recordId the primary key of the d d l record
3417             * @return the d d l record
3418             * @throws com.liferay.portlet.dynamicdatalists.NoSuchRecordException if a d d l record with the primary key could not be found
3419             * @throws SystemException if a system exception occurred
3420             */
3421            @Override
3422            public DDLRecord findByPrimaryKey(long recordId)
3423                    throws NoSuchRecordException, SystemException {
3424                    return findByPrimaryKey((Serializable)recordId);
3425            }
3426    
3427            /**
3428             * Returns the d d l record with the primary key or returns <code>null</code> if it could not be found.
3429             *
3430             * @param primaryKey the primary key of the d d l record
3431             * @return the d d l record, or <code>null</code> if a d d l record with the primary key could not be found
3432             * @throws SystemException if a system exception occurred
3433             */
3434            @Override
3435            public DDLRecord fetchByPrimaryKey(Serializable primaryKey)
3436                    throws SystemException {
3437                    DDLRecord ddlRecord = (DDLRecord)EntityCacheUtil.getResult(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
3438                                    DDLRecordImpl.class, primaryKey);
3439    
3440                    if (ddlRecord == _nullDDLRecord) {
3441                            return null;
3442                    }
3443    
3444                    if (ddlRecord == null) {
3445                            Session session = null;
3446    
3447                            try {
3448                                    session = openSession();
3449    
3450                                    ddlRecord = (DDLRecord)session.get(DDLRecordImpl.class,
3451                                                    primaryKey);
3452    
3453                                    if (ddlRecord != null) {
3454                                            cacheResult(ddlRecord);
3455                                    }
3456                                    else {
3457                                            EntityCacheUtil.putResult(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
3458                                                    DDLRecordImpl.class, primaryKey, _nullDDLRecord);
3459                                    }
3460                            }
3461                            catch (Exception e) {
3462                                    EntityCacheUtil.removeResult(DDLRecordModelImpl.ENTITY_CACHE_ENABLED,
3463                                            DDLRecordImpl.class, primaryKey);
3464    
3465                                    throw processException(e);
3466                            }
3467                            finally {
3468                                    closeSession(session);
3469                            }
3470                    }
3471    
3472                    return ddlRecord;
3473            }
3474    
3475            /**
3476             * Returns the d d l record with the primary key or returns <code>null</code> if it could not be found.
3477             *
3478             * @param recordId the primary key of the d d l record
3479             * @return the d d l record, or <code>null</code> if a d d l record with the primary key could not be found
3480             * @throws SystemException if a system exception occurred
3481             */
3482            @Override
3483            public DDLRecord fetchByPrimaryKey(long recordId) throws SystemException {
3484                    return fetchByPrimaryKey((Serializable)recordId);
3485            }
3486    
3487            /**
3488             * Returns all the d d l records.
3489             *
3490             * @return the d d l records
3491             * @throws SystemException if a system exception occurred
3492             */
3493            @Override
3494            public List<DDLRecord> findAll() throws SystemException {
3495                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3496            }
3497    
3498            /**
3499             * Returns a range of all the d d l records.
3500             *
3501             * <p>
3502             * 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.DDLRecordModelImpl}. 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.
3503             * </p>
3504             *
3505             * @param start the lower bound of the range of d d l records
3506             * @param end the upper bound of the range of d d l records (not inclusive)
3507             * @return the range of d d l records
3508             * @throws SystemException if a system exception occurred
3509             */
3510            @Override
3511            public List<DDLRecord> findAll(int start, int end)
3512                    throws SystemException {
3513                    return findAll(start, end, null);
3514            }
3515    
3516            /**
3517             * Returns an ordered range of all the d d l records.
3518             *
3519             * <p>
3520             * 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.DDLRecordModelImpl}. 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.
3521             * </p>
3522             *
3523             * @param start the lower bound of the range of d d l records
3524             * @param end the upper bound of the range of d d l records (not inclusive)
3525             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3526             * @return the ordered range of d d l records
3527             * @throws SystemException if a system exception occurred
3528             */
3529            @Override
3530            public List<DDLRecord> findAll(int start, int end,
3531                    OrderByComparator orderByComparator) throws SystemException {
3532                    boolean pagination = true;
3533                    FinderPath finderPath = null;
3534                    Object[] finderArgs = null;
3535    
3536                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3537                                    (orderByComparator == null)) {
3538                            pagination = false;
3539                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3540                            finderArgs = FINDER_ARGS_EMPTY;
3541                    }
3542                    else {
3543                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3544                            finderArgs = new Object[] { start, end, orderByComparator };
3545                    }
3546    
3547                    List<DDLRecord> list = (List<DDLRecord>)FinderCacheUtil.getResult(finderPath,
3548                                    finderArgs, this);
3549    
3550                    if (list == null) {
3551                            StringBundler query = null;
3552                            String sql = null;
3553    
3554                            if (orderByComparator != null) {
3555                                    query = new StringBundler(2 +
3556                                                    (orderByComparator.getOrderByFields().length * 3));
3557    
3558                                    query.append(_SQL_SELECT_DDLRECORD);
3559    
3560                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3561                                            orderByComparator);
3562    
3563                                    sql = query.toString();
3564                            }
3565                            else {
3566                                    sql = _SQL_SELECT_DDLRECORD;
3567    
3568                                    if (pagination) {
3569                                            sql = sql.concat(DDLRecordModelImpl.ORDER_BY_JPQL);
3570                                    }
3571                            }
3572    
3573                            Session session = null;
3574    
3575                            try {
3576                                    session = openSession();
3577    
3578                                    Query q = session.createQuery(sql);
3579    
3580                                    if (!pagination) {
3581                                            list = (List<DDLRecord>)QueryUtil.list(q, getDialect(),
3582                                                            start, end, false);
3583    
3584                                            Collections.sort(list);
3585    
3586                                            list = new UnmodifiableList<DDLRecord>(list);
3587                                    }
3588                                    else {
3589                                            list = (List<DDLRecord>)QueryUtil.list(q, getDialect(),
3590                                                            start, end);
3591                                    }
3592    
3593                                    cacheResult(list);
3594    
3595                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3596                            }
3597                            catch (Exception e) {
3598                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3599    
3600                                    throw processException(e);
3601                            }
3602                            finally {
3603                                    closeSession(session);
3604                            }
3605                    }
3606    
3607                    return list;
3608            }
3609    
3610            /**
3611             * Removes all the d d l records from the database.
3612             *
3613             * @throws SystemException if a system exception occurred
3614             */
3615            @Override
3616            public void removeAll() throws SystemException {
3617                    for (DDLRecord ddlRecord : findAll()) {
3618                            remove(ddlRecord);
3619                    }
3620            }
3621    
3622            /**
3623             * Returns the number of d d l records.
3624             *
3625             * @return the number of d d l records
3626             * @throws SystemException if a system exception occurred
3627             */
3628            @Override
3629            public int countAll() throws SystemException {
3630                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3631                                    FINDER_ARGS_EMPTY, this);
3632    
3633                    if (count == null) {
3634                            Session session = null;
3635    
3636                            try {
3637                                    session = openSession();
3638    
3639                                    Query q = session.createQuery(_SQL_COUNT_DDLRECORD);
3640    
3641                                    count = (Long)q.uniqueResult();
3642    
3643                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3644                                            FINDER_ARGS_EMPTY, count);
3645                            }
3646                            catch (Exception e) {
3647                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
3648                                            FINDER_ARGS_EMPTY);
3649    
3650                                    throw processException(e);
3651                            }
3652                            finally {
3653                                    closeSession(session);
3654                            }
3655                    }
3656    
3657                    return count.intValue();
3658            }
3659    
3660            @Override
3661            protected Set<String> getBadColumnNames() {
3662                    return _badColumnNames;
3663            }
3664    
3665            /**
3666             * Initializes the d d l record persistence.
3667             */
3668            public void afterPropertiesSet() {
3669                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3670                                            com.liferay.portal.util.PropsUtil.get(
3671                                                    "value.object.listener.com.liferay.portlet.dynamicdatalists.model.DDLRecord")));
3672    
3673                    if (listenerClassNames.length > 0) {
3674                            try {
3675                                    List<ModelListener<DDLRecord>> listenersList = new ArrayList<ModelListener<DDLRecord>>();
3676    
3677                                    for (String listenerClassName : listenerClassNames) {
3678                                            listenersList.add((ModelListener<DDLRecord>)InstanceFactory.newInstance(
3679                                                            getClassLoader(), listenerClassName));
3680                                    }
3681    
3682                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3683                            }
3684                            catch (Exception e) {
3685                                    _log.error(e);
3686                            }
3687                    }
3688            }
3689    
3690            public void destroy() {
3691                    EntityCacheUtil.removeCache(DDLRecordImpl.class.getName());
3692                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3693                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3694                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3695            }
3696    
3697            private static final String _SQL_SELECT_DDLRECORD = "SELECT ddlRecord FROM DDLRecord ddlRecord";
3698            private static final String _SQL_SELECT_DDLRECORD_WHERE = "SELECT ddlRecord FROM DDLRecord ddlRecord WHERE ";
3699            private static final String _SQL_COUNT_DDLRECORD = "SELECT COUNT(ddlRecord) FROM DDLRecord ddlRecord";
3700            private static final String _SQL_COUNT_DDLRECORD_WHERE = "SELECT COUNT(ddlRecord) FROM DDLRecord ddlRecord WHERE ";
3701            private static final String _ORDER_BY_ENTITY_ALIAS = "ddlRecord.";
3702            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DDLRecord exists with the primary key ";
3703            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DDLRecord exists with the key {";
3704            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3705            private static Log _log = LogFactoryUtil.getLog(DDLRecordPersistenceImpl.class);
3706            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
3707                                    "uuid"
3708                            });
3709            private static DDLRecord _nullDDLRecord = new DDLRecordImpl() {
3710                            @Override
3711                            public Object clone() {
3712                                    return this;
3713                            }
3714    
3715                            @Override
3716                            public CacheModel<DDLRecord> toCacheModel() {
3717                                    return _nullDDLRecordCacheModel;
3718                            }
3719                    };
3720    
3721            private static CacheModel<DDLRecord> _nullDDLRecordCacheModel = new CacheModel<DDLRecord>() {
3722                            @Override
3723                            public DDLRecord toEntityModel() {
3724                                    return _nullDDLRecord;
3725                            }
3726                    };
3727    }