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