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