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