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