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