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