001    /**
002     * Copyright (c) 2000-2011 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.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038    import com.liferay.portal.model.CacheModel;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.service.persistence.BatchSessionUtil;
041    import com.liferay.portal.service.persistence.ResourcePersistence;
042    import com.liferay.portal.service.persistence.UserPersistence;
043    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044    
045    import com.liferay.portlet.dynamicdatamapping.NoSuchContentException;
046    import com.liferay.portlet.dynamicdatamapping.model.DDMContent;
047    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMContentImpl;
048    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMContentModelImpl;
049    
050    import java.io.Serializable;
051    
052    import java.util.ArrayList;
053    import java.util.Collections;
054    import java.util.List;
055    
056    /**
057     * The persistence implementation for the d d m content service.
058     *
059     * <p>
060     * Caching information and settings can be found in <code>portal.properties</code>
061     * </p>
062     *
063     * @author Brian Wing Shun Chan
064     * @see DDMContentPersistence
065     * @see DDMContentUtil
066     * @generated
067     */
068    public class DDMContentPersistenceImpl extends BasePersistenceImpl<DDMContent>
069            implements DDMContentPersistence {
070            /*
071             * NOTE FOR DEVELOPERS:
072             *
073             * 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.
074             */
075            public static final String FINDER_CLASS_NAME_ENTITY = DDMContentImpl.class.getName();
076            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List1";
078            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079                    ".List2";
080            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
081                            DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
082                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
083                            new String[] {
084                                    String.class.getName(),
085                                    
086                            "java.lang.Integer", "java.lang.Integer",
087                                    "com.liferay.portal.kernel.util.OrderByComparator"
088                            });
089            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
090                            DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
091                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
092                            new String[] { String.class.getName() },
093                            DDMContentModelImpl.UUID_COLUMN_BITMASK);
094            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
095                            DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
096                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
097                            new String[] { String.class.getName() });
098            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
099                            DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
100                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
101                            new String[] { String.class.getName(), Long.class.getName() },
102                            DDMContentModelImpl.UUID_COLUMN_BITMASK |
103                            DDMContentModelImpl.GROUPID_COLUMN_BITMASK);
104            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
105                            DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
106                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
107                            new String[] { String.class.getName(), Long.class.getName() });
108            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
109                            DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
110                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
111                            new String[] {
112                                    Long.class.getName(),
113                                    
114                            "java.lang.Integer", "java.lang.Integer",
115                                    "com.liferay.portal.kernel.util.OrderByComparator"
116                            });
117            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
118                    new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
119                            DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
120                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
121                            new String[] { Long.class.getName() },
122                            DDMContentModelImpl.GROUPID_COLUMN_BITMASK);
123            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
124                            DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
125                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
126                            new String[] { Long.class.getName() });
127            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
128                    new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
129                            DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
130                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
131                            new String[] {
132                                    Long.class.getName(),
133                                    
134                            "java.lang.Integer", "java.lang.Integer",
135                                    "com.liferay.portal.kernel.util.OrderByComparator"
136                            });
137            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
138                    new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
139                            DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
140                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
141                            new String[] { Long.class.getName() },
142                            DDMContentModelImpl.COMPANYID_COLUMN_BITMASK);
143            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
144                            DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
145                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
146                            new String[] { Long.class.getName() });
147            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
148                            DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
149                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
150            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
151                            DDMContentModelImpl.FINDER_CACHE_ENABLED, DDMContentImpl.class,
152                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
153            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
154                            DDMContentModelImpl.FINDER_CACHE_ENABLED, Long.class,
155                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
156    
157            /**
158             * Caches the d d m content in the entity cache if it is enabled.
159             *
160             * @param ddmContent the d d m content
161             */
162            public void cacheResult(DDMContent ddmContent) {
163                    EntityCacheUtil.putResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
164                            DDMContentImpl.class, ddmContent.getPrimaryKey(), ddmContent);
165    
166                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
167                            new Object[] {
168                                    ddmContent.getUuid(), Long.valueOf(ddmContent.getGroupId())
169                            }, ddmContent);
170    
171                    ddmContent.resetOriginalValues();
172            }
173    
174            /**
175             * Caches the d d m contents in the entity cache if it is enabled.
176             *
177             * @param ddmContents the d d m contents
178             */
179            public void cacheResult(List<DDMContent> ddmContents) {
180                    for (DDMContent ddmContent : ddmContents) {
181                            if (EntityCacheUtil.getResult(
182                                                    DDMContentModelImpl.ENTITY_CACHE_ENABLED,
183                                                    DDMContentImpl.class, ddmContent.getPrimaryKey()) == null) {
184                                    cacheResult(ddmContent);
185                            }
186                            else {
187                                    ddmContent.resetOriginalValues();
188                            }
189                    }
190            }
191    
192            /**
193             * Clears the cache for all d d m contents.
194             *
195             * <p>
196             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
197             * </p>
198             */
199            @Override
200            public void clearCache() {
201                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
202                            CacheRegistryUtil.clear(DDMContentImpl.class.getName());
203                    }
204    
205                    EntityCacheUtil.clearCache(DDMContentImpl.class.getName());
206    
207                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
208                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
209                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
210            }
211    
212            /**
213             * Clears the cache for the d d m content.
214             *
215             * <p>
216             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
217             * </p>
218             */
219            @Override
220            public void clearCache(DDMContent ddmContent) {
221                    EntityCacheUtil.removeResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
222                            DDMContentImpl.class, ddmContent.getPrimaryKey());
223    
224                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
225                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
226    
227                    clearUniqueFindersCache(ddmContent);
228            }
229    
230            @Override
231            public void clearCache(List<DDMContent> ddmContents) {
232                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
233                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
234    
235                    for (DDMContent ddmContent : ddmContents) {
236                            EntityCacheUtil.removeResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
237                                    DDMContentImpl.class, ddmContent.getPrimaryKey());
238    
239                            clearUniqueFindersCache(ddmContent);
240                    }
241            }
242    
243            protected void clearUniqueFindersCache(DDMContent ddmContent) {
244                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
245                            new Object[] {
246                                    ddmContent.getUuid(), Long.valueOf(ddmContent.getGroupId())
247                            });
248            }
249    
250            /**
251             * Creates a new d d m content with the primary key. Does not add the d d m content to the database.
252             *
253             * @param contentId the primary key for the new d d m content
254             * @return the new d d m content
255             */
256            public DDMContent create(long contentId) {
257                    DDMContent ddmContent = new DDMContentImpl();
258    
259                    ddmContent.setNew(true);
260                    ddmContent.setPrimaryKey(contentId);
261    
262                    String uuid = PortalUUIDUtil.generate();
263    
264                    ddmContent.setUuid(uuid);
265    
266                    return ddmContent;
267            }
268    
269            /**
270             * Removes the d d m content with the primary key from the database. Also notifies the appropriate model listeners.
271             *
272             * @param contentId the primary key of the d d m content
273             * @return the d d m content that was removed
274             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchContentException if a d d m content with the primary key could not be found
275             * @throws SystemException if a system exception occurred
276             */
277            public DDMContent remove(long contentId)
278                    throws NoSuchContentException, SystemException {
279                    return remove(Long.valueOf(contentId));
280            }
281    
282            /**
283             * Removes the d d m content with the primary key from the database. Also notifies the appropriate model listeners.
284             *
285             * @param primaryKey the primary key of the d d m content
286             * @return the d d m content that was removed
287             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchContentException if a d d m content with the primary key could not be found
288             * @throws SystemException if a system exception occurred
289             */
290            @Override
291            public DDMContent remove(Serializable primaryKey)
292                    throws NoSuchContentException, SystemException {
293                    Session session = null;
294    
295                    try {
296                            session = openSession();
297    
298                            DDMContent ddmContent = (DDMContent)session.get(DDMContentImpl.class,
299                                            primaryKey);
300    
301                            if (ddmContent == null) {
302                                    if (_log.isWarnEnabled()) {
303                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
304                                    }
305    
306                                    throw new NoSuchContentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
307                                            primaryKey);
308                            }
309    
310                            return remove(ddmContent);
311                    }
312                    catch (NoSuchContentException nsee) {
313                            throw nsee;
314                    }
315                    catch (Exception e) {
316                            throw processException(e);
317                    }
318                    finally {
319                            closeSession(session);
320                    }
321            }
322    
323            @Override
324            protected DDMContent removeImpl(DDMContent ddmContent)
325                    throws SystemException {
326                    ddmContent = toUnwrappedModel(ddmContent);
327    
328                    Session session = null;
329    
330                    try {
331                            session = openSession();
332    
333                            BatchSessionUtil.delete(session, ddmContent);
334                    }
335                    catch (Exception e) {
336                            throw processException(e);
337                    }
338                    finally {
339                            closeSession(session);
340                    }
341    
342                    clearCache(ddmContent);
343    
344                    return ddmContent;
345            }
346    
347            @Override
348            public DDMContent updateImpl(
349                    com.liferay.portlet.dynamicdatamapping.model.DDMContent ddmContent,
350                    boolean merge) throws SystemException {
351                    ddmContent = toUnwrappedModel(ddmContent);
352    
353                    boolean isNew = ddmContent.isNew();
354    
355                    DDMContentModelImpl ddmContentModelImpl = (DDMContentModelImpl)ddmContent;
356    
357                    if (Validator.isNull(ddmContent.getUuid())) {
358                            String uuid = PortalUUIDUtil.generate();
359    
360                            ddmContent.setUuid(uuid);
361                    }
362    
363                    Session session = null;
364    
365                    try {
366                            session = openSession();
367    
368                            BatchSessionUtil.update(session, ddmContent, merge);
369    
370                            ddmContent.setNew(false);
371                    }
372                    catch (Exception e) {
373                            throw processException(e);
374                    }
375                    finally {
376                            closeSession(session);
377                    }
378    
379                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
380    
381                    if (isNew || !DDMContentModelImpl.COLUMN_BITMASK_ENABLED) {
382                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
383                    }
384    
385                    else {
386                            if ((ddmContentModelImpl.getColumnBitmask() &
387                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
388                                    Object[] args = new Object[] {
389                                                    ddmContentModelImpl.getOriginalUuid()
390                                            };
391    
392                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
393                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
394                                            args);
395    
396                                    args = new Object[] { ddmContentModelImpl.getUuid() };
397    
398                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
399                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
400                                            args);
401                            }
402    
403                            if ((ddmContentModelImpl.getColumnBitmask() &
404                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
405                                    Object[] args = new Object[] {
406                                                    Long.valueOf(ddmContentModelImpl.getOriginalGroupId())
407                                            };
408    
409                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
410                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
411                                            args);
412    
413                                    args = new Object[] {
414                                                    Long.valueOf(ddmContentModelImpl.getGroupId())
415                                            };
416    
417                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
418                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
419                                            args);
420                            }
421    
422                            if ((ddmContentModelImpl.getColumnBitmask() &
423                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
424                                    Object[] args = new Object[] {
425                                                    Long.valueOf(ddmContentModelImpl.getOriginalCompanyId())
426                                            };
427    
428                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
429                                            args);
430                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
431                                            args);
432    
433                                    args = new Object[] {
434                                                    Long.valueOf(ddmContentModelImpl.getCompanyId())
435                                            };
436    
437                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
438                                            args);
439                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
440                                            args);
441                            }
442                    }
443    
444                    EntityCacheUtil.putResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
445                            DDMContentImpl.class, ddmContent.getPrimaryKey(), ddmContent);
446    
447                    if (isNew) {
448                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
449                                    new Object[] {
450                                            ddmContent.getUuid(), Long.valueOf(ddmContent.getGroupId())
451                                    }, ddmContent);
452                    }
453                    else {
454                            if ((ddmContentModelImpl.getColumnBitmask() &
455                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
456                                    Object[] args = new Object[] {
457                                                    ddmContentModelImpl.getOriginalUuid(),
458                                                    Long.valueOf(ddmContentModelImpl.getOriginalGroupId())
459                                            };
460    
461                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
462                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
463    
464                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
465                                            new Object[] {
466                                                    ddmContent.getUuid(),
467                                                    Long.valueOf(ddmContent.getGroupId())
468                                            }, ddmContent);
469                            }
470                    }
471    
472                    return ddmContent;
473            }
474    
475            protected DDMContent toUnwrappedModel(DDMContent ddmContent) {
476                    if (ddmContent instanceof DDMContentImpl) {
477                            return ddmContent;
478                    }
479    
480                    DDMContentImpl ddmContentImpl = new DDMContentImpl();
481    
482                    ddmContentImpl.setNew(ddmContent.isNew());
483                    ddmContentImpl.setPrimaryKey(ddmContent.getPrimaryKey());
484    
485                    ddmContentImpl.setUuid(ddmContent.getUuid());
486                    ddmContentImpl.setContentId(ddmContent.getContentId());
487                    ddmContentImpl.setGroupId(ddmContent.getGroupId());
488                    ddmContentImpl.setCompanyId(ddmContent.getCompanyId());
489                    ddmContentImpl.setUserId(ddmContent.getUserId());
490                    ddmContentImpl.setUserName(ddmContent.getUserName());
491                    ddmContentImpl.setCreateDate(ddmContent.getCreateDate());
492                    ddmContentImpl.setModifiedDate(ddmContent.getModifiedDate());
493                    ddmContentImpl.setName(ddmContent.getName());
494                    ddmContentImpl.setDescription(ddmContent.getDescription());
495                    ddmContentImpl.setXml(ddmContent.getXml());
496    
497                    return ddmContentImpl;
498            }
499    
500            /**
501             * Returns the d d m content with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
502             *
503             * @param primaryKey the primary key of the d d m content
504             * @return the d d m content
505             * @throws com.liferay.portal.NoSuchModelException if a d d m content with the primary key could not be found
506             * @throws SystemException if a system exception occurred
507             */
508            @Override
509            public DDMContent findByPrimaryKey(Serializable primaryKey)
510                    throws NoSuchModelException, SystemException {
511                    return findByPrimaryKey(((Long)primaryKey).longValue());
512            }
513    
514            /**
515             * 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.
516             *
517             * @param contentId the primary key of the d d m content
518             * @return the d d m content
519             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchContentException if a d d m content with the primary key could not be found
520             * @throws SystemException if a system exception occurred
521             */
522            public DDMContent findByPrimaryKey(long contentId)
523                    throws NoSuchContentException, SystemException {
524                    DDMContent ddmContent = fetchByPrimaryKey(contentId);
525    
526                    if (ddmContent == null) {
527                            if (_log.isWarnEnabled()) {
528                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + contentId);
529                            }
530    
531                            throw new NoSuchContentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
532                                    contentId);
533                    }
534    
535                    return ddmContent;
536            }
537    
538            /**
539             * Returns the d d m content with the primary key or returns <code>null</code> if it could not be found.
540             *
541             * @param primaryKey the primary key of the d d m content
542             * @return the d d m content, or <code>null</code> if a d d m content with the primary key could not be found
543             * @throws SystemException if a system exception occurred
544             */
545            @Override
546            public DDMContent fetchByPrimaryKey(Serializable primaryKey)
547                    throws SystemException {
548                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
549            }
550    
551            /**
552             * Returns the d d m content with the primary key or returns <code>null</code> if it could not be found.
553             *
554             * @param contentId the primary key of the d d m content
555             * @return the d d m content, or <code>null</code> if a d d m content with the primary key could not be found
556             * @throws SystemException if a system exception occurred
557             */
558            public DDMContent fetchByPrimaryKey(long contentId)
559                    throws SystemException {
560                    DDMContent ddmContent = (DDMContent)EntityCacheUtil.getResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
561                                    DDMContentImpl.class, contentId);
562    
563                    if (ddmContent == _nullDDMContent) {
564                            return null;
565                    }
566    
567                    if (ddmContent == null) {
568                            Session session = null;
569    
570                            boolean hasException = false;
571    
572                            try {
573                                    session = openSession();
574    
575                                    ddmContent = (DDMContent)session.get(DDMContentImpl.class,
576                                                    Long.valueOf(contentId));
577                            }
578                            catch (Exception e) {
579                                    hasException = true;
580    
581                                    throw processException(e);
582                            }
583                            finally {
584                                    if (ddmContent != null) {
585                                            cacheResult(ddmContent);
586                                    }
587                                    else if (!hasException) {
588                                            EntityCacheUtil.putResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
589                                                    DDMContentImpl.class, contentId, _nullDDMContent);
590                                    }
591    
592                                    closeSession(session);
593                            }
594                    }
595    
596                    return ddmContent;
597            }
598    
599            /**
600             * Returns all the d d m contents where uuid = &#63;.
601             *
602             * @param uuid the uuid
603             * @return the matching d d m contents
604             * @throws SystemException if a system exception occurred
605             */
606            public List<DDMContent> findByUuid(String uuid) throws SystemException {
607                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
608            }
609    
610            /**
611             * Returns a range of all the d d m contents where uuid = &#63;.
612             *
613             * <p>
614             * 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.
615             * </p>
616             *
617             * @param uuid the uuid
618             * @param start the lower bound of the range of d d m contents
619             * @param end the upper bound of the range of d d m contents (not inclusive)
620             * @return the range of matching d d m contents
621             * @throws SystemException if a system exception occurred
622             */
623            public List<DDMContent> findByUuid(String uuid, int start, int end)
624                    throws SystemException {
625                    return findByUuid(uuid, start, end, null);
626            }
627    
628            /**
629             * Returns an ordered range of all the d d m contents where uuid = &#63;.
630             *
631             * <p>
632             * 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.
633             * </p>
634             *
635             * @param uuid the uuid
636             * @param start the lower bound of the range of d d m contents
637             * @param end the upper bound of the range of d d m contents (not inclusive)
638             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
639             * @return the ordered range of matching d d m contents
640             * @throws SystemException if a system exception occurred
641             */
642            public List<DDMContent> findByUuid(String uuid, int start, int end,
643                    OrderByComparator orderByComparator) throws SystemException {
644                    FinderPath finderPath = null;
645                    Object[] finderArgs = null;
646    
647                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
648                                    (orderByComparator == null)) {
649                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
650                            finderArgs = new Object[] { uuid };
651                    }
652                    else {
653                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
654                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
655                    }
656    
657                    List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
658                                    finderArgs, this);
659    
660                    if (list == null) {
661                            StringBundler query = null;
662    
663                            if (orderByComparator != null) {
664                                    query = new StringBundler(3 +
665                                                    (orderByComparator.getOrderByFields().length * 3));
666                            }
667                            else {
668                                    query = new StringBundler(2);
669                            }
670    
671                            query.append(_SQL_SELECT_DDMCONTENT_WHERE);
672    
673                            if (uuid == null) {
674                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
675                            }
676                            else {
677                                    if (uuid.equals(StringPool.BLANK)) {
678                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
679                                    }
680                                    else {
681                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
682                                    }
683                            }
684    
685                            if (orderByComparator != null) {
686                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
687                                            orderByComparator);
688                            }
689    
690                            String sql = query.toString();
691    
692                            Session session = null;
693    
694                            try {
695                                    session = openSession();
696    
697                                    Query q = session.createQuery(sql);
698    
699                                    QueryPos qPos = QueryPos.getInstance(q);
700    
701                                    if (uuid != null) {
702                                            qPos.add(uuid);
703                                    }
704    
705                                    list = (List<DDMContent>)QueryUtil.list(q, getDialect(), start,
706                                                    end);
707                            }
708                            catch (Exception e) {
709                                    throw processException(e);
710                            }
711                            finally {
712                                    if (list == null) {
713                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
714                                    }
715                                    else {
716                                            cacheResult(list);
717    
718                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
719                                    }
720    
721                                    closeSession(session);
722                            }
723                    }
724    
725                    return list;
726            }
727    
728            /**
729             * Returns the first d d m content in the ordered set where uuid = &#63;.
730             *
731             * <p>
732             * 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.
733             * </p>
734             *
735             * @param uuid the uuid
736             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
737             * @return the first matching d d m content
738             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchContentException if a matching d d m content could not be found
739             * @throws SystemException if a system exception occurred
740             */
741            public DDMContent findByUuid_First(String uuid,
742                    OrderByComparator orderByComparator)
743                    throws NoSuchContentException, SystemException {
744                    List<DDMContent> list = findByUuid(uuid, 0, 1, orderByComparator);
745    
746                    if (list.isEmpty()) {
747                            StringBundler msg = new StringBundler(4);
748    
749                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
750    
751                            msg.append("uuid=");
752                            msg.append(uuid);
753    
754                            msg.append(StringPool.CLOSE_CURLY_BRACE);
755    
756                            throw new NoSuchContentException(msg.toString());
757                    }
758                    else {
759                            return list.get(0);
760                    }
761            }
762    
763            /**
764             * Returns the last d d m content in the ordered set where uuid = &#63;.
765             *
766             * <p>
767             * 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.
768             * </p>
769             *
770             * @param uuid the uuid
771             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
772             * @return the last matching d d m content
773             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchContentException if a matching d d m content could not be found
774             * @throws SystemException if a system exception occurred
775             */
776            public DDMContent findByUuid_Last(String uuid,
777                    OrderByComparator orderByComparator)
778                    throws NoSuchContentException, SystemException {
779                    int count = countByUuid(uuid);
780    
781                    List<DDMContent> list = findByUuid(uuid, count - 1, count,
782                                    orderByComparator);
783    
784                    if (list.isEmpty()) {
785                            StringBundler msg = new StringBundler(4);
786    
787                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
788    
789                            msg.append("uuid=");
790                            msg.append(uuid);
791    
792                            msg.append(StringPool.CLOSE_CURLY_BRACE);
793    
794                            throw new NoSuchContentException(msg.toString());
795                    }
796                    else {
797                            return list.get(0);
798                    }
799            }
800    
801            /**
802             * Returns the d d m contents before and after the current d d m content in the ordered set where uuid = &#63;.
803             *
804             * <p>
805             * 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.
806             * </p>
807             *
808             * @param contentId the primary key of the current d d m content
809             * @param uuid the uuid
810             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
811             * @return the previous, current, and next d d m content
812             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchContentException if a d d m content with the primary key could not be found
813             * @throws SystemException if a system exception occurred
814             */
815            public DDMContent[] findByUuid_PrevAndNext(long contentId, String uuid,
816                    OrderByComparator orderByComparator)
817                    throws NoSuchContentException, SystemException {
818                    DDMContent ddmContent = findByPrimaryKey(contentId);
819    
820                    Session session = null;
821    
822                    try {
823                            session = openSession();
824    
825                            DDMContent[] array = new DDMContentImpl[3];
826    
827                            array[0] = getByUuid_PrevAndNext(session, ddmContent, uuid,
828                                            orderByComparator, true);
829    
830                            array[1] = ddmContent;
831    
832                            array[2] = getByUuid_PrevAndNext(session, ddmContent, uuid,
833                                            orderByComparator, false);
834    
835                            return array;
836                    }
837                    catch (Exception e) {
838                            throw processException(e);
839                    }
840                    finally {
841                            closeSession(session);
842                    }
843            }
844    
845            protected DDMContent getByUuid_PrevAndNext(Session session,
846                    DDMContent ddmContent, String uuid,
847                    OrderByComparator orderByComparator, boolean previous) {
848                    StringBundler query = null;
849    
850                    if (orderByComparator != null) {
851                            query = new StringBundler(6 +
852                                            (orderByComparator.getOrderByFields().length * 6));
853                    }
854                    else {
855                            query = new StringBundler(3);
856                    }
857    
858                    query.append(_SQL_SELECT_DDMCONTENT_WHERE);
859    
860                    if (uuid == null) {
861                            query.append(_FINDER_COLUMN_UUID_UUID_1);
862                    }
863                    else {
864                            if (uuid.equals(StringPool.BLANK)) {
865                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
866                            }
867                            else {
868                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
869                            }
870                    }
871    
872                    if (orderByComparator != null) {
873                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
874    
875                            if (orderByConditionFields.length > 0) {
876                                    query.append(WHERE_AND);
877                            }
878    
879                            for (int i = 0; i < orderByConditionFields.length; i++) {
880                                    query.append(_ORDER_BY_ENTITY_ALIAS);
881                                    query.append(orderByConditionFields[i]);
882    
883                                    if ((i + 1) < orderByConditionFields.length) {
884                                            if (orderByComparator.isAscending() ^ previous) {
885                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
886                                            }
887                                            else {
888                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
889                                            }
890                                    }
891                                    else {
892                                            if (orderByComparator.isAscending() ^ previous) {
893                                                    query.append(WHERE_GREATER_THAN);
894                                            }
895                                            else {
896                                                    query.append(WHERE_LESSER_THAN);
897                                            }
898                                    }
899                            }
900    
901                            query.append(ORDER_BY_CLAUSE);
902    
903                            String[] orderByFields = orderByComparator.getOrderByFields();
904    
905                            for (int i = 0; i < orderByFields.length; i++) {
906                                    query.append(_ORDER_BY_ENTITY_ALIAS);
907                                    query.append(orderByFields[i]);
908    
909                                    if ((i + 1) < orderByFields.length) {
910                                            if (orderByComparator.isAscending() ^ previous) {
911                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
912                                            }
913                                            else {
914                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
915                                            }
916                                    }
917                                    else {
918                                            if (orderByComparator.isAscending() ^ previous) {
919                                                    query.append(ORDER_BY_ASC);
920                                            }
921                                            else {
922                                                    query.append(ORDER_BY_DESC);
923                                            }
924                                    }
925                            }
926                    }
927    
928                    String sql = query.toString();
929    
930                    Query q = session.createQuery(sql);
931    
932                    q.setFirstResult(0);
933                    q.setMaxResults(2);
934    
935                    QueryPos qPos = QueryPos.getInstance(q);
936    
937                    if (uuid != null) {
938                            qPos.add(uuid);
939                    }
940    
941                    if (orderByComparator != null) {
942                            Object[] values = orderByComparator.getOrderByConditionValues(ddmContent);
943    
944                            for (Object value : values) {
945                                    qPos.add(value);
946                            }
947                    }
948    
949                    List<DDMContent> list = q.list();
950    
951                    if (list.size() == 2) {
952                            return list.get(1);
953                    }
954                    else {
955                            return null;
956                    }
957            }
958    
959            /**
960             * 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.
961             *
962             * @param uuid the uuid
963             * @param groupId the group ID
964             * @return the matching d d m content
965             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchContentException if a matching d d m content could not be found
966             * @throws SystemException if a system exception occurred
967             */
968            public DDMContent findByUUID_G(String uuid, long groupId)
969                    throws NoSuchContentException, SystemException {
970                    DDMContent ddmContent = fetchByUUID_G(uuid, groupId);
971    
972                    if (ddmContent == null) {
973                            StringBundler msg = new StringBundler(6);
974    
975                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
976    
977                            msg.append("uuid=");
978                            msg.append(uuid);
979    
980                            msg.append(", groupId=");
981                            msg.append(groupId);
982    
983                            msg.append(StringPool.CLOSE_CURLY_BRACE);
984    
985                            if (_log.isWarnEnabled()) {
986                                    _log.warn(msg.toString());
987                            }
988    
989                            throw new NoSuchContentException(msg.toString());
990                    }
991    
992                    return ddmContent;
993            }
994    
995            /**
996             * 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.
997             *
998             * @param uuid the uuid
999             * @param groupId the group ID
1000             * @return the matching d d m content, or <code>null</code> if a matching d d m content could not be found
1001             * @throws SystemException if a system exception occurred
1002             */
1003            public DDMContent fetchByUUID_G(String uuid, long groupId)
1004                    throws SystemException {
1005                    return fetchByUUID_G(uuid, groupId, true);
1006            }
1007    
1008            /**
1009             * 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.
1010             *
1011             * @param uuid the uuid
1012             * @param groupId the group ID
1013             * @param retrieveFromCache whether to use the finder cache
1014             * @return the matching d d m content, or <code>null</code> if a matching d d m content could not be found
1015             * @throws SystemException if a system exception occurred
1016             */
1017            public DDMContent fetchByUUID_G(String uuid, long groupId,
1018                    boolean retrieveFromCache) throws SystemException {
1019                    Object[] finderArgs = new Object[] { uuid, groupId };
1020    
1021                    Object result = null;
1022    
1023                    if (retrieveFromCache) {
1024                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1025                                            finderArgs, this);
1026                    }
1027    
1028                    if (result == null) {
1029                            StringBundler query = new StringBundler(3);
1030    
1031                            query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1032    
1033                            if (uuid == null) {
1034                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1035                            }
1036                            else {
1037                                    if (uuid.equals(StringPool.BLANK)) {
1038                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1039                                    }
1040                                    else {
1041                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1042                                    }
1043                            }
1044    
1045                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1046    
1047                            String sql = query.toString();
1048    
1049                            Session session = null;
1050    
1051                            try {
1052                                    session = openSession();
1053    
1054                                    Query q = session.createQuery(sql);
1055    
1056                                    QueryPos qPos = QueryPos.getInstance(q);
1057    
1058                                    if (uuid != null) {
1059                                            qPos.add(uuid);
1060                                    }
1061    
1062                                    qPos.add(groupId);
1063    
1064                                    List<DDMContent> list = q.list();
1065    
1066                                    result = list;
1067    
1068                                    DDMContent ddmContent = null;
1069    
1070                                    if (list.isEmpty()) {
1071                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1072                                                    finderArgs, list);
1073                                    }
1074                                    else {
1075                                            ddmContent = list.get(0);
1076    
1077                                            cacheResult(ddmContent);
1078    
1079                                            if ((ddmContent.getUuid() == null) ||
1080                                                            !ddmContent.getUuid().equals(uuid) ||
1081                                                            (ddmContent.getGroupId() != groupId)) {
1082                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1083                                                            finderArgs, ddmContent);
1084                                            }
1085                                    }
1086    
1087                                    return ddmContent;
1088                            }
1089                            catch (Exception e) {
1090                                    throw processException(e);
1091                            }
1092                            finally {
1093                                    if (result == null) {
1094                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1095                                                    finderArgs);
1096                                    }
1097    
1098                                    closeSession(session);
1099                            }
1100                    }
1101                    else {
1102                            if (result instanceof List<?>) {
1103                                    return null;
1104                            }
1105                            else {
1106                                    return (DDMContent)result;
1107                            }
1108                    }
1109            }
1110    
1111            /**
1112             * Returns all the d d m contents where groupId = &#63;.
1113             *
1114             * @param groupId the group ID
1115             * @return the matching d d m contents
1116             * @throws SystemException if a system exception occurred
1117             */
1118            public List<DDMContent> findByGroupId(long groupId)
1119                    throws SystemException {
1120                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1121            }
1122    
1123            /**
1124             * Returns a range of all the d d m contents where groupId = &#63;.
1125             *
1126             * <p>
1127             * 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.
1128             * </p>
1129             *
1130             * @param groupId the group ID
1131             * @param start the lower bound of the range of d d m contents
1132             * @param end the upper bound of the range of d d m contents (not inclusive)
1133             * @return the range of matching d d m contents
1134             * @throws SystemException if a system exception occurred
1135             */
1136            public List<DDMContent> findByGroupId(long groupId, int start, int end)
1137                    throws SystemException {
1138                    return findByGroupId(groupId, start, end, null);
1139            }
1140    
1141            /**
1142             * Returns an ordered range of all the d d m contents where groupId = &#63;.
1143             *
1144             * <p>
1145             * 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.
1146             * </p>
1147             *
1148             * @param groupId the group ID
1149             * @param start the lower bound of the range of d d m contents
1150             * @param end the upper bound of the range of d d m contents (not inclusive)
1151             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1152             * @return the ordered range of matching d d m contents
1153             * @throws SystemException if a system exception occurred
1154             */
1155            public List<DDMContent> findByGroupId(long groupId, int start, int end,
1156                    OrderByComparator orderByComparator) throws SystemException {
1157                    FinderPath finderPath = null;
1158                    Object[] finderArgs = null;
1159    
1160                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1161                                    (orderByComparator == null)) {
1162                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1163                            finderArgs = new Object[] { groupId };
1164                    }
1165                    else {
1166                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1167                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1168                    }
1169    
1170                    List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
1171                                    finderArgs, this);
1172    
1173                    if (list == null) {
1174                            StringBundler query = null;
1175    
1176                            if (orderByComparator != null) {
1177                                    query = new StringBundler(3 +
1178                                                    (orderByComparator.getOrderByFields().length * 3));
1179                            }
1180                            else {
1181                                    query = new StringBundler(2);
1182                            }
1183    
1184                            query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1185    
1186                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1187    
1188                            if (orderByComparator != null) {
1189                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1190                                            orderByComparator);
1191                            }
1192    
1193                            String sql = query.toString();
1194    
1195                            Session session = null;
1196    
1197                            try {
1198                                    session = openSession();
1199    
1200                                    Query q = session.createQuery(sql);
1201    
1202                                    QueryPos qPos = QueryPos.getInstance(q);
1203    
1204                                    qPos.add(groupId);
1205    
1206                                    list = (List<DDMContent>)QueryUtil.list(q, getDialect(), start,
1207                                                    end);
1208                            }
1209                            catch (Exception e) {
1210                                    throw processException(e);
1211                            }
1212                            finally {
1213                                    if (list == null) {
1214                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1215                                    }
1216                                    else {
1217                                            cacheResult(list);
1218    
1219                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1220                                    }
1221    
1222                                    closeSession(session);
1223                            }
1224                    }
1225    
1226                    return list;
1227            }
1228    
1229            /**
1230             * Returns the first d d m content in the ordered set where groupId = &#63;.
1231             *
1232             * <p>
1233             * 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.
1234             * </p>
1235             *
1236             * @param groupId the group ID
1237             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1238             * @return the first matching d d m content
1239             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchContentException if a matching d d m content could not be found
1240             * @throws SystemException if a system exception occurred
1241             */
1242            public DDMContent findByGroupId_First(long groupId,
1243                    OrderByComparator orderByComparator)
1244                    throws NoSuchContentException, SystemException {
1245                    List<DDMContent> list = findByGroupId(groupId, 0, 1, orderByComparator);
1246    
1247                    if (list.isEmpty()) {
1248                            StringBundler msg = new StringBundler(4);
1249    
1250                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1251    
1252                            msg.append("groupId=");
1253                            msg.append(groupId);
1254    
1255                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1256    
1257                            throw new NoSuchContentException(msg.toString());
1258                    }
1259                    else {
1260                            return list.get(0);
1261                    }
1262            }
1263    
1264            /**
1265             * Returns the last d d m content in the ordered set where groupId = &#63;.
1266             *
1267             * <p>
1268             * 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.
1269             * </p>
1270             *
1271             * @param groupId the group ID
1272             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1273             * @return the last matching d d m content
1274             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchContentException if a matching d d m content could not be found
1275             * @throws SystemException if a system exception occurred
1276             */
1277            public DDMContent findByGroupId_Last(long groupId,
1278                    OrderByComparator orderByComparator)
1279                    throws NoSuchContentException, SystemException {
1280                    int count = countByGroupId(groupId);
1281    
1282                    List<DDMContent> list = findByGroupId(groupId, count - 1, count,
1283                                    orderByComparator);
1284    
1285                    if (list.isEmpty()) {
1286                            StringBundler msg = new StringBundler(4);
1287    
1288                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1289    
1290                            msg.append("groupId=");
1291                            msg.append(groupId);
1292    
1293                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1294    
1295                            throw new NoSuchContentException(msg.toString());
1296                    }
1297                    else {
1298                            return list.get(0);
1299                    }
1300            }
1301    
1302            /**
1303             * Returns the d d m contents before and after the current d d m content in the ordered set where groupId = &#63;.
1304             *
1305             * <p>
1306             * 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.
1307             * </p>
1308             *
1309             * @param contentId the primary key of the current d d m content
1310             * @param groupId the group ID
1311             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1312             * @return the previous, current, and next d d m content
1313             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchContentException if a d d m content with the primary key could not be found
1314             * @throws SystemException if a system exception occurred
1315             */
1316            public DDMContent[] findByGroupId_PrevAndNext(long contentId, long groupId,
1317                    OrderByComparator orderByComparator)
1318                    throws NoSuchContentException, SystemException {
1319                    DDMContent ddmContent = findByPrimaryKey(contentId);
1320    
1321                    Session session = null;
1322    
1323                    try {
1324                            session = openSession();
1325    
1326                            DDMContent[] array = new DDMContentImpl[3];
1327    
1328                            array[0] = getByGroupId_PrevAndNext(session, ddmContent, groupId,
1329                                            orderByComparator, true);
1330    
1331                            array[1] = ddmContent;
1332    
1333                            array[2] = getByGroupId_PrevAndNext(session, ddmContent, groupId,
1334                                            orderByComparator, false);
1335    
1336                            return array;
1337                    }
1338                    catch (Exception e) {
1339                            throw processException(e);
1340                    }
1341                    finally {
1342                            closeSession(session);
1343                    }
1344            }
1345    
1346            protected DDMContent getByGroupId_PrevAndNext(Session session,
1347                    DDMContent ddmContent, long groupId,
1348                    OrderByComparator orderByComparator, boolean previous) {
1349                    StringBundler query = null;
1350    
1351                    if (orderByComparator != null) {
1352                            query = new StringBundler(6 +
1353                                            (orderByComparator.getOrderByFields().length * 6));
1354                    }
1355                    else {
1356                            query = new StringBundler(3);
1357                    }
1358    
1359                    query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1360    
1361                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1362    
1363                    if (orderByComparator != null) {
1364                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1365    
1366                            if (orderByConditionFields.length > 0) {
1367                                    query.append(WHERE_AND);
1368                            }
1369    
1370                            for (int i = 0; i < orderByConditionFields.length; i++) {
1371                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1372                                    query.append(orderByConditionFields[i]);
1373    
1374                                    if ((i + 1) < orderByConditionFields.length) {
1375                                            if (orderByComparator.isAscending() ^ previous) {
1376                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1377                                            }
1378                                            else {
1379                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1380                                            }
1381                                    }
1382                                    else {
1383                                            if (orderByComparator.isAscending() ^ previous) {
1384                                                    query.append(WHERE_GREATER_THAN);
1385                                            }
1386                                            else {
1387                                                    query.append(WHERE_LESSER_THAN);
1388                                            }
1389                                    }
1390                            }
1391    
1392                            query.append(ORDER_BY_CLAUSE);
1393    
1394                            String[] orderByFields = orderByComparator.getOrderByFields();
1395    
1396                            for (int i = 0; i < orderByFields.length; i++) {
1397                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1398                                    query.append(orderByFields[i]);
1399    
1400                                    if ((i + 1) < orderByFields.length) {
1401                                            if (orderByComparator.isAscending() ^ previous) {
1402                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1403                                            }
1404                                            else {
1405                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1406                                            }
1407                                    }
1408                                    else {
1409                                            if (orderByComparator.isAscending() ^ previous) {
1410                                                    query.append(ORDER_BY_ASC);
1411                                            }
1412                                            else {
1413                                                    query.append(ORDER_BY_DESC);
1414                                            }
1415                                    }
1416                            }
1417                    }
1418    
1419                    String sql = query.toString();
1420    
1421                    Query q = session.createQuery(sql);
1422    
1423                    q.setFirstResult(0);
1424                    q.setMaxResults(2);
1425    
1426                    QueryPos qPos = QueryPos.getInstance(q);
1427    
1428                    qPos.add(groupId);
1429    
1430                    if (orderByComparator != null) {
1431                            Object[] values = orderByComparator.getOrderByConditionValues(ddmContent);
1432    
1433                            for (Object value : values) {
1434                                    qPos.add(value);
1435                            }
1436                    }
1437    
1438                    List<DDMContent> list = q.list();
1439    
1440                    if (list.size() == 2) {
1441                            return list.get(1);
1442                    }
1443                    else {
1444                            return null;
1445                    }
1446            }
1447    
1448            /**
1449             * Returns all the d d m contents where companyId = &#63;.
1450             *
1451             * @param companyId the company ID
1452             * @return the matching d d m contents
1453             * @throws SystemException if a system exception occurred
1454             */
1455            public List<DDMContent> findByCompanyId(long companyId)
1456                    throws SystemException {
1457                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1458                            null);
1459            }
1460    
1461            /**
1462             * Returns a range of all the d d m contents where companyId = &#63;.
1463             *
1464             * <p>
1465             * 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.
1466             * </p>
1467             *
1468             * @param companyId the company ID
1469             * @param start the lower bound of the range of d d m contents
1470             * @param end the upper bound of the range of d d m contents (not inclusive)
1471             * @return the range of matching d d m contents
1472             * @throws SystemException if a system exception occurred
1473             */
1474            public List<DDMContent> findByCompanyId(long companyId, int start, int end)
1475                    throws SystemException {
1476                    return findByCompanyId(companyId, start, end, null);
1477            }
1478    
1479            /**
1480             * Returns an ordered range of all the d d m contents where companyId = &#63;.
1481             *
1482             * <p>
1483             * 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.
1484             * </p>
1485             *
1486             * @param companyId the company ID
1487             * @param start the lower bound of the range of d d m contents
1488             * @param end the upper bound of the range of d d m contents (not inclusive)
1489             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1490             * @return the ordered range of matching d d m contents
1491             * @throws SystemException if a system exception occurred
1492             */
1493            public List<DDMContent> findByCompanyId(long companyId, int start, int end,
1494                    OrderByComparator orderByComparator) throws SystemException {
1495                    FinderPath finderPath = null;
1496                    Object[] finderArgs = null;
1497    
1498                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1499                                    (orderByComparator == null)) {
1500                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1501                            finderArgs = new Object[] { companyId };
1502                    }
1503                    else {
1504                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1505                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
1506                    }
1507    
1508                    List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
1509                                    finderArgs, this);
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(2);
1520                            }
1521    
1522                            query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1523    
1524                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1525    
1526                            if (orderByComparator != null) {
1527                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1528                                            orderByComparator);
1529                            }
1530    
1531                            String sql = query.toString();
1532    
1533                            Session session = null;
1534    
1535                            try {
1536                                    session = openSession();
1537    
1538                                    Query q = session.createQuery(sql);
1539    
1540                                    QueryPos qPos = QueryPos.getInstance(q);
1541    
1542                                    qPos.add(companyId);
1543    
1544                                    list = (List<DDMContent>)QueryUtil.list(q, getDialect(), start,
1545                                                    end);
1546                            }
1547                            catch (Exception e) {
1548                                    throw processException(e);
1549                            }
1550                            finally {
1551                                    if (list == null) {
1552                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1553                                    }
1554                                    else {
1555                                            cacheResult(list);
1556    
1557                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1558                                    }
1559    
1560                                    closeSession(session);
1561                            }
1562                    }
1563    
1564                    return list;
1565            }
1566    
1567            /**
1568             * Returns the first d d m content in the ordered set where companyId = &#63;.
1569             *
1570             * <p>
1571             * 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.
1572             * </p>
1573             *
1574             * @param companyId the company ID
1575             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1576             * @return the first matching d d m content
1577             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchContentException if a matching d d m content could not be found
1578             * @throws SystemException if a system exception occurred
1579             */
1580            public DDMContent findByCompanyId_First(long companyId,
1581                    OrderByComparator orderByComparator)
1582                    throws NoSuchContentException, SystemException {
1583                    List<DDMContent> list = findByCompanyId(companyId, 0, 1,
1584                                    orderByComparator);
1585    
1586                    if (list.isEmpty()) {
1587                            StringBundler msg = new StringBundler(4);
1588    
1589                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1590    
1591                            msg.append("companyId=");
1592                            msg.append(companyId);
1593    
1594                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1595    
1596                            throw new NoSuchContentException(msg.toString());
1597                    }
1598                    else {
1599                            return list.get(0);
1600                    }
1601            }
1602    
1603            /**
1604             * Returns the last d d m content in the ordered set where companyId = &#63;.
1605             *
1606             * <p>
1607             * 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.
1608             * </p>
1609             *
1610             * @param companyId the company ID
1611             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1612             * @return the last matching d d m content
1613             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchContentException if a matching d d m content could not be found
1614             * @throws SystemException if a system exception occurred
1615             */
1616            public DDMContent findByCompanyId_Last(long companyId,
1617                    OrderByComparator orderByComparator)
1618                    throws NoSuchContentException, SystemException {
1619                    int count = countByCompanyId(companyId);
1620    
1621                    List<DDMContent> list = findByCompanyId(companyId, count - 1, count,
1622                                    orderByComparator);
1623    
1624                    if (list.isEmpty()) {
1625                            StringBundler msg = new StringBundler(4);
1626    
1627                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1628    
1629                            msg.append("companyId=");
1630                            msg.append(companyId);
1631    
1632                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1633    
1634                            throw new NoSuchContentException(msg.toString());
1635                    }
1636                    else {
1637                            return list.get(0);
1638                    }
1639            }
1640    
1641            /**
1642             * Returns the d d m contents before and after the current d d m content in the ordered set where companyId = &#63;.
1643             *
1644             * <p>
1645             * 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.
1646             * </p>
1647             *
1648             * @param contentId the primary key of the current d d m content
1649             * @param companyId the company ID
1650             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1651             * @return the previous, current, and next d d m content
1652             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchContentException if a d d m content with the primary key could not be found
1653             * @throws SystemException if a system exception occurred
1654             */
1655            public DDMContent[] findByCompanyId_PrevAndNext(long contentId,
1656                    long companyId, OrderByComparator orderByComparator)
1657                    throws NoSuchContentException, SystemException {
1658                    DDMContent ddmContent = findByPrimaryKey(contentId);
1659    
1660                    Session session = null;
1661    
1662                    try {
1663                            session = openSession();
1664    
1665                            DDMContent[] array = new DDMContentImpl[3];
1666    
1667                            array[0] = getByCompanyId_PrevAndNext(session, ddmContent,
1668                                            companyId, orderByComparator, true);
1669    
1670                            array[1] = ddmContent;
1671    
1672                            array[2] = getByCompanyId_PrevAndNext(session, ddmContent,
1673                                            companyId, orderByComparator, false);
1674    
1675                            return array;
1676                    }
1677                    catch (Exception e) {
1678                            throw processException(e);
1679                    }
1680                    finally {
1681                            closeSession(session);
1682                    }
1683            }
1684    
1685            protected DDMContent getByCompanyId_PrevAndNext(Session session,
1686                    DDMContent ddmContent, long companyId,
1687                    OrderByComparator orderByComparator, boolean previous) {
1688                    StringBundler query = null;
1689    
1690                    if (orderByComparator != null) {
1691                            query = new StringBundler(6 +
1692                                            (orderByComparator.getOrderByFields().length * 6));
1693                    }
1694                    else {
1695                            query = new StringBundler(3);
1696                    }
1697    
1698                    query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1699    
1700                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1701    
1702                    if (orderByComparator != null) {
1703                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1704    
1705                            if (orderByConditionFields.length > 0) {
1706                                    query.append(WHERE_AND);
1707                            }
1708    
1709                            for (int i = 0; i < orderByConditionFields.length; i++) {
1710                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1711                                    query.append(orderByConditionFields[i]);
1712    
1713                                    if ((i + 1) < orderByConditionFields.length) {
1714                                            if (orderByComparator.isAscending() ^ previous) {
1715                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1716                                            }
1717                                            else {
1718                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1719                                            }
1720                                    }
1721                                    else {
1722                                            if (orderByComparator.isAscending() ^ previous) {
1723                                                    query.append(WHERE_GREATER_THAN);
1724                                            }
1725                                            else {
1726                                                    query.append(WHERE_LESSER_THAN);
1727                                            }
1728                                    }
1729                            }
1730    
1731                            query.append(ORDER_BY_CLAUSE);
1732    
1733                            String[] orderByFields = orderByComparator.getOrderByFields();
1734    
1735                            for (int i = 0; i < orderByFields.length; i++) {
1736                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1737                                    query.append(orderByFields[i]);
1738    
1739                                    if ((i + 1) < orderByFields.length) {
1740                                            if (orderByComparator.isAscending() ^ previous) {
1741                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1742                                            }
1743                                            else {
1744                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1745                                            }
1746                                    }
1747                                    else {
1748                                            if (orderByComparator.isAscending() ^ previous) {
1749                                                    query.append(ORDER_BY_ASC);
1750                                            }
1751                                            else {
1752                                                    query.append(ORDER_BY_DESC);
1753                                            }
1754                                    }
1755                            }
1756                    }
1757    
1758                    String sql = query.toString();
1759    
1760                    Query q = session.createQuery(sql);
1761    
1762                    q.setFirstResult(0);
1763                    q.setMaxResults(2);
1764    
1765                    QueryPos qPos = QueryPos.getInstance(q);
1766    
1767                    qPos.add(companyId);
1768    
1769                    if (orderByComparator != null) {
1770                            Object[] values = orderByComparator.getOrderByConditionValues(ddmContent);
1771    
1772                            for (Object value : values) {
1773                                    qPos.add(value);
1774                            }
1775                    }
1776    
1777                    List<DDMContent> list = q.list();
1778    
1779                    if (list.size() == 2) {
1780                            return list.get(1);
1781                    }
1782                    else {
1783                            return null;
1784                    }
1785            }
1786    
1787            /**
1788             * Returns all the d d m contents.
1789             *
1790             * @return the d d m contents
1791             * @throws SystemException if a system exception occurred
1792             */
1793            public List<DDMContent> findAll() throws SystemException {
1794                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1795            }
1796    
1797            /**
1798             * Returns a range of all the d d m contents.
1799             *
1800             * <p>
1801             * 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.
1802             * </p>
1803             *
1804             * @param start the lower bound of the range of d d m contents
1805             * @param end the upper bound of the range of d d m contents (not inclusive)
1806             * @return the range of d d m contents
1807             * @throws SystemException if a system exception occurred
1808             */
1809            public List<DDMContent> findAll(int start, int end)
1810                    throws SystemException {
1811                    return findAll(start, end, null);
1812            }
1813    
1814            /**
1815             * Returns an ordered range of all the d d m contents.
1816             *
1817             * <p>
1818             * 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.
1819             * </p>
1820             *
1821             * @param start the lower bound of the range of d d m contents
1822             * @param end the upper bound of the range of d d m contents (not inclusive)
1823             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1824             * @return the ordered range of d d m contents
1825             * @throws SystemException if a system exception occurred
1826             */
1827            public List<DDMContent> findAll(int start, int end,
1828                    OrderByComparator orderByComparator) throws SystemException {
1829                    FinderPath finderPath = null;
1830                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1831    
1832                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1833                                    (orderByComparator == null)) {
1834                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1835                            finderArgs = FINDER_ARGS_EMPTY;
1836                    }
1837                    else {
1838                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1839                            finderArgs = new Object[] { start, end, orderByComparator };
1840                    }
1841    
1842                    List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
1843                                    finderArgs, this);
1844    
1845                    if (list == null) {
1846                            StringBundler query = null;
1847                            String sql = null;
1848    
1849                            if (orderByComparator != null) {
1850                                    query = new StringBundler(2 +
1851                                                    (orderByComparator.getOrderByFields().length * 3));
1852    
1853                                    query.append(_SQL_SELECT_DDMCONTENT);
1854    
1855                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1856                                            orderByComparator);
1857    
1858                                    sql = query.toString();
1859                            }
1860                            else {
1861                                    sql = _SQL_SELECT_DDMCONTENT;
1862                            }
1863    
1864                            Session session = null;
1865    
1866                            try {
1867                                    session = openSession();
1868    
1869                                    Query q = session.createQuery(sql);
1870    
1871                                    if (orderByComparator == null) {
1872                                            list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
1873                                                            start, end, false);
1874    
1875                                            Collections.sort(list);
1876                                    }
1877                                    else {
1878                                            list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
1879                                                            start, end);
1880                                    }
1881                            }
1882                            catch (Exception e) {
1883                                    throw processException(e);
1884                            }
1885                            finally {
1886                                    if (list == null) {
1887                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1888                                    }
1889                                    else {
1890                                            cacheResult(list);
1891    
1892                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1893                                    }
1894    
1895                                    closeSession(session);
1896                            }
1897                    }
1898    
1899                    return list;
1900            }
1901    
1902            /**
1903             * Removes all the d d m contents where uuid = &#63; from the database.
1904             *
1905             * @param uuid the uuid
1906             * @throws SystemException if a system exception occurred
1907             */
1908            public void removeByUuid(String uuid) throws SystemException {
1909                    for (DDMContent ddmContent : findByUuid(uuid)) {
1910                            remove(ddmContent);
1911                    }
1912            }
1913    
1914            /**
1915             * Removes the d d m content where uuid = &#63; and groupId = &#63; from the database.
1916             *
1917             * @param uuid the uuid
1918             * @param groupId the group ID
1919             * @throws SystemException if a system exception occurred
1920             */
1921            public void removeByUUID_G(String uuid, long groupId)
1922                    throws NoSuchContentException, SystemException {
1923                    DDMContent ddmContent = findByUUID_G(uuid, groupId);
1924    
1925                    remove(ddmContent);
1926            }
1927    
1928            /**
1929             * Removes all the d d m contents where groupId = &#63; from the database.
1930             *
1931             * @param groupId the group ID
1932             * @throws SystemException if a system exception occurred
1933             */
1934            public void removeByGroupId(long groupId) throws SystemException {
1935                    for (DDMContent ddmContent : findByGroupId(groupId)) {
1936                            remove(ddmContent);
1937                    }
1938            }
1939    
1940            /**
1941             * Removes all the d d m contents where companyId = &#63; from the database.
1942             *
1943             * @param companyId the company ID
1944             * @throws SystemException if a system exception occurred
1945             */
1946            public void removeByCompanyId(long companyId) throws SystemException {
1947                    for (DDMContent ddmContent : findByCompanyId(companyId)) {
1948                            remove(ddmContent);
1949                    }
1950            }
1951    
1952            /**
1953             * Removes all the d d m contents from the database.
1954             *
1955             * @throws SystemException if a system exception occurred
1956             */
1957            public void removeAll() throws SystemException {
1958                    for (DDMContent ddmContent : findAll()) {
1959                            remove(ddmContent);
1960                    }
1961            }
1962    
1963            /**
1964             * Returns the number of d d m contents where uuid = &#63;.
1965             *
1966             * @param uuid the uuid
1967             * @return the number of matching d d m contents
1968             * @throws SystemException if a system exception occurred
1969             */
1970            public int countByUuid(String uuid) throws SystemException {
1971                    Object[] finderArgs = new Object[] { uuid };
1972    
1973                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1974                                    finderArgs, this);
1975    
1976                    if (count == null) {
1977                            StringBundler query = new StringBundler(2);
1978    
1979                            query.append(_SQL_COUNT_DDMCONTENT_WHERE);
1980    
1981                            if (uuid == null) {
1982                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
1983                            }
1984                            else {
1985                                    if (uuid.equals(StringPool.BLANK)) {
1986                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
1987                                    }
1988                                    else {
1989                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
1990                                    }
1991                            }
1992    
1993                            String sql = query.toString();
1994    
1995                            Session session = null;
1996    
1997                            try {
1998                                    session = openSession();
1999    
2000                                    Query q = session.createQuery(sql);
2001    
2002                                    QueryPos qPos = QueryPos.getInstance(q);
2003    
2004                                    if (uuid != null) {
2005                                            qPos.add(uuid);
2006                                    }
2007    
2008                                    count = (Long)q.uniqueResult();
2009                            }
2010                            catch (Exception e) {
2011                                    throw processException(e);
2012                            }
2013                            finally {
2014                                    if (count == null) {
2015                                            count = Long.valueOf(0);
2016                                    }
2017    
2018                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2019                                            finderArgs, count);
2020    
2021                                    closeSession(session);
2022                            }
2023                    }
2024    
2025                    return count.intValue();
2026            }
2027    
2028            /**
2029             * Returns the number of d d m contents where uuid = &#63; and groupId = &#63;.
2030             *
2031             * @param uuid the uuid
2032             * @param groupId the group ID
2033             * @return the number of matching d d m contents
2034             * @throws SystemException if a system exception occurred
2035             */
2036            public int countByUUID_G(String uuid, long groupId)
2037                    throws SystemException {
2038                    Object[] finderArgs = new Object[] { uuid, groupId };
2039    
2040                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2041                                    finderArgs, this);
2042    
2043                    if (count == null) {
2044                            StringBundler query = new StringBundler(3);
2045    
2046                            query.append(_SQL_COUNT_DDMCONTENT_WHERE);
2047    
2048                            if (uuid == null) {
2049                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2050                            }
2051                            else {
2052                                    if (uuid.equals(StringPool.BLANK)) {
2053                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2054                                    }
2055                                    else {
2056                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2057                                    }
2058                            }
2059    
2060                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2061    
2062                            String sql = query.toString();
2063    
2064                            Session session = null;
2065    
2066                            try {
2067                                    session = openSession();
2068    
2069                                    Query q = session.createQuery(sql);
2070    
2071                                    QueryPos qPos = QueryPos.getInstance(q);
2072    
2073                                    if (uuid != null) {
2074                                            qPos.add(uuid);
2075                                    }
2076    
2077                                    qPos.add(groupId);
2078    
2079                                    count = (Long)q.uniqueResult();
2080                            }
2081                            catch (Exception e) {
2082                                    throw processException(e);
2083                            }
2084                            finally {
2085                                    if (count == null) {
2086                                            count = Long.valueOf(0);
2087                                    }
2088    
2089                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2090                                            finderArgs, count);
2091    
2092                                    closeSession(session);
2093                            }
2094                    }
2095    
2096                    return count.intValue();
2097            }
2098    
2099            /**
2100             * Returns the number of d d m contents where groupId = &#63;.
2101             *
2102             * @param groupId the group ID
2103             * @return the number of matching d d m contents
2104             * @throws SystemException if a system exception occurred
2105             */
2106            public int countByGroupId(long groupId) throws SystemException {
2107                    Object[] finderArgs = new Object[] { groupId };
2108    
2109                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2110                                    finderArgs, this);
2111    
2112                    if (count == null) {
2113                            StringBundler query = new StringBundler(2);
2114    
2115                            query.append(_SQL_COUNT_DDMCONTENT_WHERE);
2116    
2117                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2118    
2119                            String sql = query.toString();
2120    
2121                            Session session = null;
2122    
2123                            try {
2124                                    session = openSession();
2125    
2126                                    Query q = session.createQuery(sql);
2127    
2128                                    QueryPos qPos = QueryPos.getInstance(q);
2129    
2130                                    qPos.add(groupId);
2131    
2132                                    count = (Long)q.uniqueResult();
2133                            }
2134                            catch (Exception e) {
2135                                    throw processException(e);
2136                            }
2137                            finally {
2138                                    if (count == null) {
2139                                            count = Long.valueOf(0);
2140                                    }
2141    
2142                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2143                                            finderArgs, count);
2144    
2145                                    closeSession(session);
2146                            }
2147                    }
2148    
2149                    return count.intValue();
2150            }
2151    
2152            /**
2153             * Returns the number of d d m contents where companyId = &#63;.
2154             *
2155             * @param companyId the company ID
2156             * @return the number of matching d d m contents
2157             * @throws SystemException if a system exception occurred
2158             */
2159            public int countByCompanyId(long companyId) throws SystemException {
2160                    Object[] finderArgs = new Object[] { companyId };
2161    
2162                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2163                                    finderArgs, this);
2164    
2165                    if (count == null) {
2166                            StringBundler query = new StringBundler(2);
2167    
2168                            query.append(_SQL_COUNT_DDMCONTENT_WHERE);
2169    
2170                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2171    
2172                            String sql = query.toString();
2173    
2174                            Session session = null;
2175    
2176                            try {
2177                                    session = openSession();
2178    
2179                                    Query q = session.createQuery(sql);
2180    
2181                                    QueryPos qPos = QueryPos.getInstance(q);
2182    
2183                                    qPos.add(companyId);
2184    
2185                                    count = (Long)q.uniqueResult();
2186                            }
2187                            catch (Exception e) {
2188                                    throw processException(e);
2189                            }
2190                            finally {
2191                                    if (count == null) {
2192                                            count = Long.valueOf(0);
2193                                    }
2194    
2195                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2196                                            finderArgs, count);
2197    
2198                                    closeSession(session);
2199                            }
2200                    }
2201    
2202                    return count.intValue();
2203            }
2204    
2205            /**
2206             * Returns the number of d d m contents.
2207             *
2208             * @return the number of d d m contents
2209             * @throws SystemException if a system exception occurred
2210             */
2211            public int countAll() throws SystemException {
2212                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2213                                    FINDER_ARGS_EMPTY, this);
2214    
2215                    if (count == null) {
2216                            Session session = null;
2217    
2218                            try {
2219                                    session = openSession();
2220    
2221                                    Query q = session.createQuery(_SQL_COUNT_DDMCONTENT);
2222    
2223                                    count = (Long)q.uniqueResult();
2224                            }
2225                            catch (Exception e) {
2226                                    throw processException(e);
2227                            }
2228                            finally {
2229                                    if (count == null) {
2230                                            count = Long.valueOf(0);
2231                                    }
2232    
2233                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2234                                            FINDER_ARGS_EMPTY, count);
2235    
2236                                    closeSession(session);
2237                            }
2238                    }
2239    
2240                    return count.intValue();
2241            }
2242    
2243            /**
2244             * Initializes the d d m content persistence.
2245             */
2246            public void afterPropertiesSet() {
2247                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2248                                            com.liferay.portal.util.PropsUtil.get(
2249                                                    "value.object.listener.com.liferay.portlet.dynamicdatamapping.model.DDMContent")));
2250    
2251                    if (listenerClassNames.length > 0) {
2252                            try {
2253                                    List<ModelListener<DDMContent>> listenersList = new ArrayList<ModelListener<DDMContent>>();
2254    
2255                                    for (String listenerClassName : listenerClassNames) {
2256                                            listenersList.add((ModelListener<DDMContent>)InstanceFactory.newInstance(
2257                                                            listenerClassName));
2258                                    }
2259    
2260                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2261                            }
2262                            catch (Exception e) {
2263                                    _log.error(e);
2264                            }
2265                    }
2266            }
2267    
2268            public void destroy() {
2269                    EntityCacheUtil.removeCache(DDMContentImpl.class.getName());
2270                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2271                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2272            }
2273    
2274            @BeanReference(type = DDMContentPersistence.class)
2275            protected DDMContentPersistence ddmContentPersistence;
2276            @BeanReference(type = DDMStorageLinkPersistence.class)
2277            protected DDMStorageLinkPersistence ddmStorageLinkPersistence;
2278            @BeanReference(type = DDMStructurePersistence.class)
2279            protected DDMStructurePersistence ddmStructurePersistence;
2280            @BeanReference(type = DDMStructureLinkPersistence.class)
2281            protected DDMStructureLinkPersistence ddmStructureLinkPersistence;
2282            @BeanReference(type = DDMTemplatePersistence.class)
2283            protected DDMTemplatePersistence ddmTemplatePersistence;
2284            @BeanReference(type = ResourcePersistence.class)
2285            protected ResourcePersistence resourcePersistence;
2286            @BeanReference(type = UserPersistence.class)
2287            protected UserPersistence userPersistence;
2288            private static final String _SQL_SELECT_DDMCONTENT = "SELECT ddmContent FROM DDMContent ddmContent";
2289            private static final String _SQL_SELECT_DDMCONTENT_WHERE = "SELECT ddmContent FROM DDMContent ddmContent WHERE ";
2290            private static final String _SQL_COUNT_DDMCONTENT = "SELECT COUNT(ddmContent) FROM DDMContent ddmContent";
2291            private static final String _SQL_COUNT_DDMCONTENT_WHERE = "SELECT COUNT(ddmContent) FROM DDMContent ddmContent WHERE ";
2292            private static final String _FINDER_COLUMN_UUID_UUID_1 = "ddmContent.uuid IS NULL";
2293            private static final String _FINDER_COLUMN_UUID_UUID_2 = "ddmContent.uuid = ?";
2294            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(ddmContent.uuid IS NULL OR ddmContent.uuid = ?)";
2295            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "ddmContent.uuid IS NULL AND ";
2296            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "ddmContent.uuid = ? AND ";
2297            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(ddmContent.uuid IS NULL OR ddmContent.uuid = ?) AND ";
2298            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "ddmContent.groupId = ?";
2299            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "ddmContent.groupId = ?";
2300            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "ddmContent.companyId = ?";
2301            private static final String _ORDER_BY_ENTITY_ALIAS = "ddmContent.";
2302            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DDMContent exists with the primary key ";
2303            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DDMContent exists with the key {";
2304            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2305            private static Log _log = LogFactoryUtil.getLog(DDMContentPersistenceImpl.class);
2306            private static DDMContent _nullDDMContent = new DDMContentImpl() {
2307                            @Override
2308                            public Object clone() {
2309                                    return this;
2310                            }
2311    
2312                            @Override
2313                            public CacheModel<DDMContent> toCacheModel() {
2314                                    return _nullDDMContentCacheModel;
2315                            }
2316                    };
2317    
2318            private static CacheModel<DDMContent> _nullDDMContentCacheModel = new CacheModel<DDMContent>() {
2319                            public DDMContent toEntityModel() {
2320                                    return _nullDDMContent;
2321                            }
2322                    };
2323    }