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