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