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