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