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