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