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