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