001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.dynamicdatamapping.service.persistence;
016    
017    import com.liferay.portal.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_WITH_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_WITHOUT_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                    else {
385                            if ((ddmContentModelImpl.getColumnBitmask() &
386                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
387                                    Object[] args = new Object[] {
388                                                    ddmContentModelImpl.getOriginalUuid()
389                                            };
390    
391                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
392                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
393                                            args);
394    
395                                    args = new Object[] { ddmContentModelImpl.getUuid() };
396    
397                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
398                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
399                                            args);
400                            }
401    
402                            if ((ddmContentModelImpl.getColumnBitmask() &
403                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
404                                    Object[] args = new Object[] {
405                                                    Long.valueOf(ddmContentModelImpl.getOriginalGroupId())
406                                            };
407    
408                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
409                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
410                                            args);
411    
412                                    args = new Object[] {
413                                                    Long.valueOf(ddmContentModelImpl.getGroupId())
414                                            };
415    
416                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
417                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
418                                            args);
419                            }
420    
421                            if ((ddmContentModelImpl.getColumnBitmask() &
422                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
423                                    Object[] args = new Object[] {
424                                                    Long.valueOf(ddmContentModelImpl.getOriginalCompanyId())
425                                            };
426    
427                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
428                                            args);
429                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
430                                            args);
431    
432                                    args = new Object[] {
433                                                    Long.valueOf(ddmContentModelImpl.getCompanyId())
434                                            };
435    
436                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
437                                            args);
438                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
439                                            args);
440                            }
441                    }
442    
443                    EntityCacheUtil.putResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
444                            DDMContentImpl.class, ddmContent.getPrimaryKey(), ddmContent);
445    
446                    if (isNew) {
447                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
448                                    new Object[] {
449                                            ddmContent.getUuid(), Long.valueOf(ddmContent.getGroupId())
450                                    }, ddmContent);
451                    }
452                    else {
453                            if ((ddmContentModelImpl.getColumnBitmask() &
454                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
455                                    Object[] args = new Object[] {
456                                                    ddmContentModelImpl.getOriginalUuid(),
457                                                    Long.valueOf(ddmContentModelImpl.getOriginalGroupId())
458                                            };
459    
460                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
461                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
462    
463                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
464                                            new Object[] {
465                                                    ddmContent.getUuid(),
466                                                    Long.valueOf(ddmContent.getGroupId())
467                                            }, ddmContent);
468                            }
469                    }
470    
471                    return ddmContent;
472            }
473    
474            protected DDMContent toUnwrappedModel(DDMContent ddmContent) {
475                    if (ddmContent instanceof DDMContentImpl) {
476                            return ddmContent;
477                    }
478    
479                    DDMContentImpl ddmContentImpl = new DDMContentImpl();
480    
481                    ddmContentImpl.setNew(ddmContent.isNew());
482                    ddmContentImpl.setPrimaryKey(ddmContent.getPrimaryKey());
483    
484                    ddmContentImpl.setUuid(ddmContent.getUuid());
485                    ddmContentImpl.setContentId(ddmContent.getContentId());
486                    ddmContentImpl.setGroupId(ddmContent.getGroupId());
487                    ddmContentImpl.setCompanyId(ddmContent.getCompanyId());
488                    ddmContentImpl.setUserId(ddmContent.getUserId());
489                    ddmContentImpl.setUserName(ddmContent.getUserName());
490                    ddmContentImpl.setCreateDate(ddmContent.getCreateDate());
491                    ddmContentImpl.setModifiedDate(ddmContent.getModifiedDate());
492                    ddmContentImpl.setName(ddmContent.getName());
493                    ddmContentImpl.setDescription(ddmContent.getDescription());
494                    ddmContentImpl.setXml(ddmContent.getXml());
495    
496                    return ddmContentImpl;
497            }
498    
499            /**
500             * Returns the d d m content with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
501             *
502             * @param primaryKey the primary key of the d d m content
503             * @return the d d m content
504             * @throws com.liferay.portal.NoSuchModelException if a d d m content with the primary key could not be found
505             * @throws SystemException if a system exception occurred
506             */
507            @Override
508            public DDMContent findByPrimaryKey(Serializable primaryKey)
509                    throws NoSuchModelException, SystemException {
510                    return findByPrimaryKey(((Long)primaryKey).longValue());
511            }
512    
513            /**
514             * 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.
515             *
516             * @param contentId the primary key of the d d m content
517             * @return the d d m content
518             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchContentException if a d d m content with the primary key could not be found
519             * @throws SystemException if a system exception occurred
520             */
521            public DDMContent findByPrimaryKey(long contentId)
522                    throws NoSuchContentException, SystemException {
523                    DDMContent ddmContent = fetchByPrimaryKey(contentId);
524    
525                    if (ddmContent == null) {
526                            if (_log.isWarnEnabled()) {
527                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + contentId);
528                            }
529    
530                            throw new NoSuchContentException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
531                                    contentId);
532                    }
533    
534                    return ddmContent;
535            }
536    
537            /**
538             * Returns the d d m content with the primary key or returns <code>null</code> if it could not be found.
539             *
540             * @param primaryKey the primary key of the d d m content
541             * @return the d d m content, or <code>null</code> if a d d m content with the primary key could not be found
542             * @throws SystemException if a system exception occurred
543             */
544            @Override
545            public DDMContent fetchByPrimaryKey(Serializable primaryKey)
546                    throws SystemException {
547                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
548            }
549    
550            /**
551             * Returns the d d m content with the primary key or returns <code>null</code> if it could not be found.
552             *
553             * @param contentId the primary key of the d d m content
554             * @return the d d m content, or <code>null</code> if a d d m content with the primary key could not be found
555             * @throws SystemException if a system exception occurred
556             */
557            public DDMContent fetchByPrimaryKey(long contentId)
558                    throws SystemException {
559                    DDMContent ddmContent = (DDMContent)EntityCacheUtil.getResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
560                                    DDMContentImpl.class, contentId);
561    
562                    if (ddmContent == _nullDDMContent) {
563                            return null;
564                    }
565    
566                    if (ddmContent == null) {
567                            Session session = null;
568    
569                            boolean hasException = false;
570    
571                            try {
572                                    session = openSession();
573    
574                                    ddmContent = (DDMContent)session.get(DDMContentImpl.class,
575                                                    Long.valueOf(contentId));
576                            }
577                            catch (Exception e) {
578                                    hasException = true;
579    
580                                    throw processException(e);
581                            }
582                            finally {
583                                    if (ddmContent != null) {
584                                            cacheResult(ddmContent);
585                                    }
586                                    else if (!hasException) {
587                                            EntityCacheUtil.putResult(DDMContentModelImpl.ENTITY_CACHE_ENABLED,
588                                                    DDMContentImpl.class, contentId, _nullDDMContent);
589                                    }
590    
591                                    closeSession(session);
592                            }
593                    }
594    
595                    return ddmContent;
596            }
597    
598            /**
599             * Returns all the d d m contents where uuid = &#63;.
600             *
601             * @param uuid the uuid
602             * @return the matching d d m contents
603             * @throws SystemException if a system exception occurred
604             */
605            public List<DDMContent> findByUuid(String uuid) throws SystemException {
606                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
607            }
608    
609            /**
610             * Returns a range of all the d d m contents where uuid = &#63;.
611             *
612             * <p>
613             * 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.
614             * </p>
615             *
616             * @param uuid the uuid
617             * @param start the lower bound of the range of d d m contents
618             * @param end the upper bound of the range of d d m contents (not inclusive)
619             * @return the range of matching d d m contents
620             * @throws SystemException if a system exception occurred
621             */
622            public List<DDMContent> findByUuid(String uuid, int start, int end)
623                    throws SystemException {
624                    return findByUuid(uuid, start, end, null);
625            }
626    
627            /**
628             * Returns an ordered range of all the d d m contents where uuid = &#63;.
629             *
630             * <p>
631             * 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.
632             * </p>
633             *
634             * @param uuid the uuid
635             * @param start the lower bound of the range of d d m contents
636             * @param end the upper bound of the range of d d m contents (not inclusive)
637             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
638             * @return the ordered range of matching d d m contents
639             * @throws SystemException if a system exception occurred
640             */
641            public List<DDMContent> findByUuid(String uuid, int start, int end,
642                    OrderByComparator orderByComparator) throws SystemException {
643                    FinderPath finderPath = null;
644                    Object[] finderArgs = null;
645    
646                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
647                                    (orderByComparator == null)) {
648                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
649                            finderArgs = new Object[] { uuid };
650                    }
651                    else {
652                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
653                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
654                    }
655    
656                    List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
657                                    finderArgs, this);
658    
659                    if ((list != null) && !list.isEmpty()) {
660                            for (DDMContent ddmContent : list) {
661                                    if (!Validator.equals(uuid, ddmContent.getUuid())) {
662                                            list = null;
663    
664                                            break;
665                                    }
666                            }
667                    }
668    
669                    if (list == null) {
670                            StringBundler query = null;
671    
672                            if (orderByComparator != null) {
673                                    query = new StringBundler(3 +
674                                                    (orderByComparator.getOrderByFields().length * 3));
675                            }
676                            else {
677                                    query = new StringBundler(2);
678                            }
679    
680                            query.append(_SQL_SELECT_DDMCONTENT_WHERE);
681    
682                            if (uuid == null) {
683                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
684                            }
685                            else {
686                                    if (uuid.equals(StringPool.BLANK)) {
687                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
688                                    }
689                                    else {
690                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
691                                    }
692                            }
693    
694                            if (orderByComparator != null) {
695                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
696                                            orderByComparator);
697                            }
698    
699                            String sql = query.toString();
700    
701                            Session session = null;
702    
703                            try {
704                                    session = openSession();
705    
706                                    Query q = session.createQuery(sql);
707    
708                                    QueryPos qPos = QueryPos.getInstance(q);
709    
710                                    if (uuid != null) {
711                                            qPos.add(uuid);
712                                    }
713    
714                                    list = (List<DDMContent>)QueryUtil.list(q, getDialect(), start,
715                                                    end);
716                            }
717                            catch (Exception e) {
718                                    throw processException(e);
719                            }
720                            finally {
721                                    if (list == null) {
722                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
723                                    }
724                                    else {
725                                            cacheResult(list);
726    
727                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
728                                    }
729    
730                                    closeSession(session);
731                            }
732                    }
733    
734                    return list;
735            }
736    
737            /**
738             * Returns the first d d m content in the ordered set where uuid = &#63;.
739             *
740             * <p>
741             * 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.
742             * </p>
743             *
744             * @param uuid the uuid
745             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
746             * @return the first matching d d m content
747             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchContentException if a matching d d m content could not be found
748             * @throws SystemException if a system exception occurred
749             */
750            public DDMContent findByUuid_First(String uuid,
751                    OrderByComparator orderByComparator)
752                    throws NoSuchContentException, SystemException {
753                    List<DDMContent> list = findByUuid(uuid, 0, 1, orderByComparator);
754    
755                    if (list.isEmpty()) {
756                            StringBundler msg = new StringBundler(4);
757    
758                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
759    
760                            msg.append("uuid=");
761                            msg.append(uuid);
762    
763                            msg.append(StringPool.CLOSE_CURLY_BRACE);
764    
765                            throw new NoSuchContentException(msg.toString());
766                    }
767                    else {
768                            return list.get(0);
769                    }
770            }
771    
772            /**
773             * Returns the last d d m content in the ordered set where uuid = &#63;.
774             *
775             * <p>
776             * 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.
777             * </p>
778             *
779             * @param uuid the uuid
780             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
781             * @return the last matching d d m content
782             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchContentException if a matching d d m content could not be found
783             * @throws SystemException if a system exception occurred
784             */
785            public DDMContent findByUuid_Last(String uuid,
786                    OrderByComparator orderByComparator)
787                    throws NoSuchContentException, SystemException {
788                    int count = countByUuid(uuid);
789    
790                    List<DDMContent> list = findByUuid(uuid, count - 1, count,
791                                    orderByComparator);
792    
793                    if (list.isEmpty()) {
794                            StringBundler msg = new StringBundler(4);
795    
796                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
797    
798                            msg.append("uuid=");
799                            msg.append(uuid);
800    
801                            msg.append(StringPool.CLOSE_CURLY_BRACE);
802    
803                            throw new NoSuchContentException(msg.toString());
804                    }
805                    else {
806                            return list.get(0);
807                    }
808            }
809    
810            /**
811             * Returns the d d m contents before and after the current d d m content in the ordered set where uuid = &#63;.
812             *
813             * <p>
814             * 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.
815             * </p>
816             *
817             * @param contentId the primary key of the current d d m content
818             * @param uuid the uuid
819             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
820             * @return the previous, current, and next d d m content
821             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchContentException if a d d m content with the primary key could not be found
822             * @throws SystemException if a system exception occurred
823             */
824            public DDMContent[] findByUuid_PrevAndNext(long contentId, String uuid,
825                    OrderByComparator orderByComparator)
826                    throws NoSuchContentException, SystemException {
827                    DDMContent ddmContent = findByPrimaryKey(contentId);
828    
829                    Session session = null;
830    
831                    try {
832                            session = openSession();
833    
834                            DDMContent[] array = new DDMContentImpl[3];
835    
836                            array[0] = getByUuid_PrevAndNext(session, ddmContent, uuid,
837                                            orderByComparator, true);
838    
839                            array[1] = ddmContent;
840    
841                            array[2] = getByUuid_PrevAndNext(session, ddmContent, uuid,
842                                            orderByComparator, false);
843    
844                            return array;
845                    }
846                    catch (Exception e) {
847                            throw processException(e);
848                    }
849                    finally {
850                            closeSession(session);
851                    }
852            }
853    
854            protected DDMContent getByUuid_PrevAndNext(Session session,
855                    DDMContent ddmContent, String uuid,
856                    OrderByComparator orderByComparator, boolean previous) {
857                    StringBundler query = null;
858    
859                    if (orderByComparator != null) {
860                            query = new StringBundler(6 +
861                                            (orderByComparator.getOrderByFields().length * 6));
862                    }
863                    else {
864                            query = new StringBundler(3);
865                    }
866    
867                    query.append(_SQL_SELECT_DDMCONTENT_WHERE);
868    
869                    if (uuid == null) {
870                            query.append(_FINDER_COLUMN_UUID_UUID_1);
871                    }
872                    else {
873                            if (uuid.equals(StringPool.BLANK)) {
874                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
875                            }
876                            else {
877                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
878                            }
879                    }
880    
881                    if (orderByComparator != null) {
882                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
883    
884                            if (orderByConditionFields.length > 0) {
885                                    query.append(WHERE_AND);
886                            }
887    
888                            for (int i = 0; i < orderByConditionFields.length; i++) {
889                                    query.append(_ORDER_BY_ENTITY_ALIAS);
890                                    query.append(orderByConditionFields[i]);
891    
892                                    if ((i + 1) < orderByConditionFields.length) {
893                                            if (orderByComparator.isAscending() ^ previous) {
894                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
895                                            }
896                                            else {
897                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
898                                            }
899                                    }
900                                    else {
901                                            if (orderByComparator.isAscending() ^ previous) {
902                                                    query.append(WHERE_GREATER_THAN);
903                                            }
904                                            else {
905                                                    query.append(WHERE_LESSER_THAN);
906                                            }
907                                    }
908                            }
909    
910                            query.append(ORDER_BY_CLAUSE);
911    
912                            String[] orderByFields = orderByComparator.getOrderByFields();
913    
914                            for (int i = 0; i < orderByFields.length; i++) {
915                                    query.append(_ORDER_BY_ENTITY_ALIAS);
916                                    query.append(orderByFields[i]);
917    
918                                    if ((i + 1) < orderByFields.length) {
919                                            if (orderByComparator.isAscending() ^ previous) {
920                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
921                                            }
922                                            else {
923                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
924                                            }
925                                    }
926                                    else {
927                                            if (orderByComparator.isAscending() ^ previous) {
928                                                    query.append(ORDER_BY_ASC);
929                                            }
930                                            else {
931                                                    query.append(ORDER_BY_DESC);
932                                            }
933                                    }
934                            }
935                    }
936    
937                    String sql = query.toString();
938    
939                    Query q = session.createQuery(sql);
940    
941                    q.setFirstResult(0);
942                    q.setMaxResults(2);
943    
944                    QueryPos qPos = QueryPos.getInstance(q);
945    
946                    if (uuid != null) {
947                            qPos.add(uuid);
948                    }
949    
950                    if (orderByComparator != null) {
951                            Object[] values = orderByComparator.getOrderByConditionValues(ddmContent);
952    
953                            for (Object value : values) {
954                                    qPos.add(value);
955                            }
956                    }
957    
958                    List<DDMContent> list = q.list();
959    
960                    if (list.size() == 2) {
961                            return list.get(1);
962                    }
963                    else {
964                            return null;
965                    }
966            }
967    
968            /**
969             * 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.
970             *
971             * @param uuid the uuid
972             * @param groupId the group ID
973             * @return the matching d d m content
974             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchContentException if a matching d d m content could not be found
975             * @throws SystemException if a system exception occurred
976             */
977            public DDMContent findByUUID_G(String uuid, long groupId)
978                    throws NoSuchContentException, SystemException {
979                    DDMContent ddmContent = fetchByUUID_G(uuid, groupId);
980    
981                    if (ddmContent == null) {
982                            StringBundler msg = new StringBundler(6);
983    
984                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
985    
986                            msg.append("uuid=");
987                            msg.append(uuid);
988    
989                            msg.append(", groupId=");
990                            msg.append(groupId);
991    
992                            msg.append(StringPool.CLOSE_CURLY_BRACE);
993    
994                            if (_log.isWarnEnabled()) {
995                                    _log.warn(msg.toString());
996                            }
997    
998                            throw new NoSuchContentException(msg.toString());
999                    }
1000    
1001                    return ddmContent;
1002            }
1003    
1004            /**
1005             * 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.
1006             *
1007             * @param uuid the uuid
1008             * @param groupId the group ID
1009             * @return the matching d d m content, or <code>null</code> if a matching d d m content could not be found
1010             * @throws SystemException if a system exception occurred
1011             */
1012            public DDMContent fetchByUUID_G(String uuid, long groupId)
1013                    throws SystemException {
1014                    return fetchByUUID_G(uuid, groupId, true);
1015            }
1016    
1017            /**
1018             * 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.
1019             *
1020             * @param uuid the uuid
1021             * @param groupId the group ID
1022             * @param retrieveFromCache whether to use the finder cache
1023             * @return the matching d d m content, or <code>null</code> if a matching d d m content could not be found
1024             * @throws SystemException if a system exception occurred
1025             */
1026            public DDMContent fetchByUUID_G(String uuid, long groupId,
1027                    boolean retrieveFromCache) throws SystemException {
1028                    Object[] finderArgs = new Object[] { uuid, groupId };
1029    
1030                    Object result = null;
1031    
1032                    if (retrieveFromCache) {
1033                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1034                                            finderArgs, this);
1035                    }
1036    
1037                    if (result instanceof DDMContent) {
1038                            DDMContent ddmContent = (DDMContent)result;
1039    
1040                            if (!Validator.equals(uuid, ddmContent.getUuid()) ||
1041                                            (groupId != ddmContent.getGroupId())) {
1042                                    result = null;
1043                            }
1044                    }
1045    
1046                    if (result == null) {
1047                            StringBundler query = new StringBundler(3);
1048    
1049                            query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1050    
1051                            if (uuid == null) {
1052                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1053                            }
1054                            else {
1055                                    if (uuid.equals(StringPool.BLANK)) {
1056                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1057                                    }
1058                                    else {
1059                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1060                                    }
1061                            }
1062    
1063                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1064    
1065                            String sql = query.toString();
1066    
1067                            Session session = null;
1068    
1069                            try {
1070                                    session = openSession();
1071    
1072                                    Query q = session.createQuery(sql);
1073    
1074                                    QueryPos qPos = QueryPos.getInstance(q);
1075    
1076                                    if (uuid != null) {
1077                                            qPos.add(uuid);
1078                                    }
1079    
1080                                    qPos.add(groupId);
1081    
1082                                    List<DDMContent> list = q.list();
1083    
1084                                    result = list;
1085    
1086                                    DDMContent ddmContent = null;
1087    
1088                                    if (list.isEmpty()) {
1089                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1090                                                    finderArgs, list);
1091                                    }
1092                                    else {
1093                                            ddmContent = list.get(0);
1094    
1095                                            cacheResult(ddmContent);
1096    
1097                                            if ((ddmContent.getUuid() == null) ||
1098                                                            !ddmContent.getUuid().equals(uuid) ||
1099                                                            (ddmContent.getGroupId() != groupId)) {
1100                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1101                                                            finderArgs, ddmContent);
1102                                            }
1103                                    }
1104    
1105                                    return ddmContent;
1106                            }
1107                            catch (Exception e) {
1108                                    throw processException(e);
1109                            }
1110                            finally {
1111                                    if (result == null) {
1112                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1113                                                    finderArgs);
1114                                    }
1115    
1116                                    closeSession(session);
1117                            }
1118                    }
1119                    else {
1120                            if (result instanceof List<?>) {
1121                                    return null;
1122                            }
1123                            else {
1124                                    return (DDMContent)result;
1125                            }
1126                    }
1127            }
1128    
1129            /**
1130             * Returns all the d d m contents where groupId = &#63;.
1131             *
1132             * @param groupId the group ID
1133             * @return the matching d d m contents
1134             * @throws SystemException if a system exception occurred
1135             */
1136            public List<DDMContent> findByGroupId(long groupId)
1137                    throws SystemException {
1138                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1139            }
1140    
1141            /**
1142             * Returns a 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             * @return the range of matching d d m contents
1152             * @throws SystemException if a system exception occurred
1153             */
1154            public List<DDMContent> findByGroupId(long groupId, int start, int end)
1155                    throws SystemException {
1156                    return findByGroupId(groupId, start, end, null);
1157            }
1158    
1159            /**
1160             * Returns an ordered range of all the d d m contents where groupId = &#63;.
1161             *
1162             * <p>
1163             * 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.
1164             * </p>
1165             *
1166             * @param groupId the group ID
1167             * @param start the lower bound of the range of d d m contents
1168             * @param end the upper bound of the range of d d m contents (not inclusive)
1169             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1170             * @return the ordered range of matching d d m contents
1171             * @throws SystemException if a system exception occurred
1172             */
1173            public List<DDMContent> findByGroupId(long groupId, int start, int end,
1174                    OrderByComparator orderByComparator) throws SystemException {
1175                    FinderPath finderPath = null;
1176                    Object[] finderArgs = null;
1177    
1178                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1179                                    (orderByComparator == null)) {
1180                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1181                            finderArgs = new Object[] { groupId };
1182                    }
1183                    else {
1184                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1185                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1186                    }
1187    
1188                    List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
1189                                    finderArgs, this);
1190    
1191                    if ((list != null) && !list.isEmpty()) {
1192                            for (DDMContent ddmContent : list) {
1193                                    if ((groupId != ddmContent.getGroupId())) {
1194                                            list = null;
1195    
1196                                            break;
1197                                    }
1198                            }
1199                    }
1200    
1201                    if (list == null) {
1202                            StringBundler query = null;
1203    
1204                            if (orderByComparator != null) {
1205                                    query = new StringBundler(3 +
1206                                                    (orderByComparator.getOrderByFields().length * 3));
1207                            }
1208                            else {
1209                                    query = new StringBundler(2);
1210                            }
1211    
1212                            query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1213    
1214                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1215    
1216                            if (orderByComparator != null) {
1217                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1218                                            orderByComparator);
1219                            }
1220    
1221                            String sql = query.toString();
1222    
1223                            Session session = null;
1224    
1225                            try {
1226                                    session = openSession();
1227    
1228                                    Query q = session.createQuery(sql);
1229    
1230                                    QueryPos qPos = QueryPos.getInstance(q);
1231    
1232                                    qPos.add(groupId);
1233    
1234                                    list = (List<DDMContent>)QueryUtil.list(q, getDialect(), start,
1235                                                    end);
1236                            }
1237                            catch (Exception e) {
1238                                    throw processException(e);
1239                            }
1240                            finally {
1241                                    if (list == null) {
1242                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1243                                    }
1244                                    else {
1245                                            cacheResult(list);
1246    
1247                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1248                                    }
1249    
1250                                    closeSession(session);
1251                            }
1252                    }
1253    
1254                    return list;
1255            }
1256    
1257            /**
1258             * Returns the first d d m content in the ordered set where groupId = &#63;.
1259             *
1260             * <p>
1261             * 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.
1262             * </p>
1263             *
1264             * @param groupId the group ID
1265             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1266             * @return the first matching d d m content
1267             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchContentException if a matching d d m content could not be found
1268             * @throws SystemException if a system exception occurred
1269             */
1270            public DDMContent findByGroupId_First(long groupId,
1271                    OrderByComparator orderByComparator)
1272                    throws NoSuchContentException, SystemException {
1273                    List<DDMContent> list = findByGroupId(groupId, 0, 1, orderByComparator);
1274    
1275                    if (list.isEmpty()) {
1276                            StringBundler msg = new StringBundler(4);
1277    
1278                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1279    
1280                            msg.append("groupId=");
1281                            msg.append(groupId);
1282    
1283                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1284    
1285                            throw new NoSuchContentException(msg.toString());
1286                    }
1287                    else {
1288                            return list.get(0);
1289                    }
1290            }
1291    
1292            /**
1293             * Returns the last d d m content in the ordered set where groupId = &#63;.
1294             *
1295             * <p>
1296             * 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.
1297             * </p>
1298             *
1299             * @param groupId the group ID
1300             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1301             * @return the last matching d d m content
1302             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchContentException if a matching d d m content could not be found
1303             * @throws SystemException if a system exception occurred
1304             */
1305            public DDMContent findByGroupId_Last(long groupId,
1306                    OrderByComparator orderByComparator)
1307                    throws NoSuchContentException, SystemException {
1308                    int count = countByGroupId(groupId);
1309    
1310                    List<DDMContent> list = findByGroupId(groupId, count - 1, count,
1311                                    orderByComparator);
1312    
1313                    if (list.isEmpty()) {
1314                            StringBundler msg = new StringBundler(4);
1315    
1316                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1317    
1318                            msg.append("groupId=");
1319                            msg.append(groupId);
1320    
1321                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1322    
1323                            throw new NoSuchContentException(msg.toString());
1324                    }
1325                    else {
1326                            return list.get(0);
1327                    }
1328            }
1329    
1330            /**
1331             * Returns the d d m contents before and after the current d d m content in the ordered set where groupId = &#63;.
1332             *
1333             * <p>
1334             * 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.
1335             * </p>
1336             *
1337             * @param contentId the primary key of the current d d m content
1338             * @param groupId the group ID
1339             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1340             * @return the previous, current, and next d d m content
1341             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchContentException if a d d m content with the primary key could not be found
1342             * @throws SystemException if a system exception occurred
1343             */
1344            public DDMContent[] findByGroupId_PrevAndNext(long contentId, long groupId,
1345                    OrderByComparator orderByComparator)
1346                    throws NoSuchContentException, SystemException {
1347                    DDMContent ddmContent = findByPrimaryKey(contentId);
1348    
1349                    Session session = null;
1350    
1351                    try {
1352                            session = openSession();
1353    
1354                            DDMContent[] array = new DDMContentImpl[3];
1355    
1356                            array[0] = getByGroupId_PrevAndNext(session, ddmContent, groupId,
1357                                            orderByComparator, true);
1358    
1359                            array[1] = ddmContent;
1360    
1361                            array[2] = getByGroupId_PrevAndNext(session, ddmContent, groupId,
1362                                            orderByComparator, false);
1363    
1364                            return array;
1365                    }
1366                    catch (Exception e) {
1367                            throw processException(e);
1368                    }
1369                    finally {
1370                            closeSession(session);
1371                    }
1372            }
1373    
1374            protected DDMContent getByGroupId_PrevAndNext(Session session,
1375                    DDMContent ddmContent, long groupId,
1376                    OrderByComparator orderByComparator, boolean previous) {
1377                    StringBundler query = null;
1378    
1379                    if (orderByComparator != null) {
1380                            query = new StringBundler(6 +
1381                                            (orderByComparator.getOrderByFields().length * 6));
1382                    }
1383                    else {
1384                            query = new StringBundler(3);
1385                    }
1386    
1387                    query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1388    
1389                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1390    
1391                    if (orderByComparator != null) {
1392                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1393    
1394                            if (orderByConditionFields.length > 0) {
1395                                    query.append(WHERE_AND);
1396                            }
1397    
1398                            for (int i = 0; i < orderByConditionFields.length; i++) {
1399                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1400                                    query.append(orderByConditionFields[i]);
1401    
1402                                    if ((i + 1) < orderByConditionFields.length) {
1403                                            if (orderByComparator.isAscending() ^ previous) {
1404                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1405                                            }
1406                                            else {
1407                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1408                                            }
1409                                    }
1410                                    else {
1411                                            if (orderByComparator.isAscending() ^ previous) {
1412                                                    query.append(WHERE_GREATER_THAN);
1413                                            }
1414                                            else {
1415                                                    query.append(WHERE_LESSER_THAN);
1416                                            }
1417                                    }
1418                            }
1419    
1420                            query.append(ORDER_BY_CLAUSE);
1421    
1422                            String[] orderByFields = orderByComparator.getOrderByFields();
1423    
1424                            for (int i = 0; i < orderByFields.length; i++) {
1425                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1426                                    query.append(orderByFields[i]);
1427    
1428                                    if ((i + 1) < orderByFields.length) {
1429                                            if (orderByComparator.isAscending() ^ previous) {
1430                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1431                                            }
1432                                            else {
1433                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1434                                            }
1435                                    }
1436                                    else {
1437                                            if (orderByComparator.isAscending() ^ previous) {
1438                                                    query.append(ORDER_BY_ASC);
1439                                            }
1440                                            else {
1441                                                    query.append(ORDER_BY_DESC);
1442                                            }
1443                                    }
1444                            }
1445                    }
1446    
1447                    String sql = query.toString();
1448    
1449                    Query q = session.createQuery(sql);
1450    
1451                    q.setFirstResult(0);
1452                    q.setMaxResults(2);
1453    
1454                    QueryPos qPos = QueryPos.getInstance(q);
1455    
1456                    qPos.add(groupId);
1457    
1458                    if (orderByComparator != null) {
1459                            Object[] values = orderByComparator.getOrderByConditionValues(ddmContent);
1460    
1461                            for (Object value : values) {
1462                                    qPos.add(value);
1463                            }
1464                    }
1465    
1466                    List<DDMContent> list = q.list();
1467    
1468                    if (list.size() == 2) {
1469                            return list.get(1);
1470                    }
1471                    else {
1472                            return null;
1473                    }
1474            }
1475    
1476            /**
1477             * Returns all the d d m contents where companyId = &#63;.
1478             *
1479             * @param companyId the company ID
1480             * @return the matching d d m contents
1481             * @throws SystemException if a system exception occurred
1482             */
1483            public List<DDMContent> findByCompanyId(long companyId)
1484                    throws SystemException {
1485                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1486                            null);
1487            }
1488    
1489            /**
1490             * Returns a range of all the d d m contents where companyId = &#63;.
1491             *
1492             * <p>
1493             * 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.
1494             * </p>
1495             *
1496             * @param companyId the company ID
1497             * @param start the lower bound of the range of d d m contents
1498             * @param end the upper bound of the range of d d m contents (not inclusive)
1499             * @return the range of matching d d m contents
1500             * @throws SystemException if a system exception occurred
1501             */
1502            public List<DDMContent> findByCompanyId(long companyId, int start, int end)
1503                    throws SystemException {
1504                    return findByCompanyId(companyId, start, end, null);
1505            }
1506    
1507            /**
1508             * Returns an ordered range of all the d d m contents where companyId = &#63;.
1509             *
1510             * <p>
1511             * 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.
1512             * </p>
1513             *
1514             * @param companyId the company ID
1515             * @param start the lower bound of the range of d d m contents
1516             * @param end the upper bound of the range of d d m contents (not inclusive)
1517             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1518             * @return the ordered range of matching d d m contents
1519             * @throws SystemException if a system exception occurred
1520             */
1521            public List<DDMContent> findByCompanyId(long companyId, int start, int end,
1522                    OrderByComparator orderByComparator) throws SystemException {
1523                    FinderPath finderPath = null;
1524                    Object[] finderArgs = null;
1525    
1526                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1527                                    (orderByComparator == null)) {
1528                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1529                            finderArgs = new Object[] { companyId };
1530                    }
1531                    else {
1532                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1533                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
1534                    }
1535    
1536                    List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
1537                                    finderArgs, this);
1538    
1539                    if ((list != null) && !list.isEmpty()) {
1540                            for (DDMContent ddmContent : list) {
1541                                    if ((companyId != ddmContent.getCompanyId())) {
1542                                            list = null;
1543    
1544                                            break;
1545                                    }
1546                            }
1547                    }
1548    
1549                    if (list == null) {
1550                            StringBundler query = null;
1551    
1552                            if (orderByComparator != null) {
1553                                    query = new StringBundler(3 +
1554                                                    (orderByComparator.getOrderByFields().length * 3));
1555                            }
1556                            else {
1557                                    query = new StringBundler(2);
1558                            }
1559    
1560                            query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1561    
1562                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1563    
1564                            if (orderByComparator != null) {
1565                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1566                                            orderByComparator);
1567                            }
1568    
1569                            String sql = query.toString();
1570    
1571                            Session session = null;
1572    
1573                            try {
1574                                    session = openSession();
1575    
1576                                    Query q = session.createQuery(sql);
1577    
1578                                    QueryPos qPos = QueryPos.getInstance(q);
1579    
1580                                    qPos.add(companyId);
1581    
1582                                    list = (List<DDMContent>)QueryUtil.list(q, getDialect(), start,
1583                                                    end);
1584                            }
1585                            catch (Exception e) {
1586                                    throw processException(e);
1587                            }
1588                            finally {
1589                                    if (list == null) {
1590                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1591                                    }
1592                                    else {
1593                                            cacheResult(list);
1594    
1595                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1596                                    }
1597    
1598                                    closeSession(session);
1599                            }
1600                    }
1601    
1602                    return list;
1603            }
1604    
1605            /**
1606             * Returns the first d d m content in the ordered set where companyId = &#63;.
1607             *
1608             * <p>
1609             * 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.
1610             * </p>
1611             *
1612             * @param companyId the company ID
1613             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1614             * @return the first matching d d m content
1615             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchContentException if a matching d d m content could not be found
1616             * @throws SystemException if a system exception occurred
1617             */
1618            public DDMContent findByCompanyId_First(long companyId,
1619                    OrderByComparator orderByComparator)
1620                    throws NoSuchContentException, SystemException {
1621                    List<DDMContent> list = findByCompanyId(companyId, 0, 1,
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 last 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 companyId the company ID
1649             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1650             * @return the last matching d d m content
1651             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchContentException if a matching d d m content could not be found
1652             * @throws SystemException if a system exception occurred
1653             */
1654            public DDMContent findByCompanyId_Last(long companyId,
1655                    OrderByComparator orderByComparator)
1656                    throws NoSuchContentException, SystemException {
1657                    int count = countByCompanyId(companyId);
1658    
1659                    List<DDMContent> list = findByCompanyId(companyId, count - 1, count,
1660                                    orderByComparator);
1661    
1662                    if (list.isEmpty()) {
1663                            StringBundler msg = new StringBundler(4);
1664    
1665                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1666    
1667                            msg.append("companyId=");
1668                            msg.append(companyId);
1669    
1670                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1671    
1672                            throw new NoSuchContentException(msg.toString());
1673                    }
1674                    else {
1675                            return list.get(0);
1676                    }
1677            }
1678    
1679            /**
1680             * Returns the d d m contents before and after the current d d m content in the ordered set where companyId = &#63;.
1681             *
1682             * <p>
1683             * 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.
1684             * </p>
1685             *
1686             * @param contentId the primary key of the current d d m content
1687             * @param companyId the company ID
1688             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1689             * @return the previous, current, and next d d m content
1690             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchContentException if a d d m content with the primary key could not be found
1691             * @throws SystemException if a system exception occurred
1692             */
1693            public DDMContent[] findByCompanyId_PrevAndNext(long contentId,
1694                    long companyId, OrderByComparator orderByComparator)
1695                    throws NoSuchContentException, SystemException {
1696                    DDMContent ddmContent = findByPrimaryKey(contentId);
1697    
1698                    Session session = null;
1699    
1700                    try {
1701                            session = openSession();
1702    
1703                            DDMContent[] array = new DDMContentImpl[3];
1704    
1705                            array[0] = getByCompanyId_PrevAndNext(session, ddmContent,
1706                                            companyId, orderByComparator, true);
1707    
1708                            array[1] = ddmContent;
1709    
1710                            array[2] = getByCompanyId_PrevAndNext(session, ddmContent,
1711                                            companyId, orderByComparator, false);
1712    
1713                            return array;
1714                    }
1715                    catch (Exception e) {
1716                            throw processException(e);
1717                    }
1718                    finally {
1719                            closeSession(session);
1720                    }
1721            }
1722    
1723            protected DDMContent getByCompanyId_PrevAndNext(Session session,
1724                    DDMContent ddmContent, long companyId,
1725                    OrderByComparator orderByComparator, boolean previous) {
1726                    StringBundler query = null;
1727    
1728                    if (orderByComparator != null) {
1729                            query = new StringBundler(6 +
1730                                            (orderByComparator.getOrderByFields().length * 6));
1731                    }
1732                    else {
1733                            query = new StringBundler(3);
1734                    }
1735    
1736                    query.append(_SQL_SELECT_DDMCONTENT_WHERE);
1737    
1738                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1739    
1740                    if (orderByComparator != null) {
1741                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1742    
1743                            if (orderByConditionFields.length > 0) {
1744                                    query.append(WHERE_AND);
1745                            }
1746    
1747                            for (int i = 0; i < orderByConditionFields.length; i++) {
1748                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1749                                    query.append(orderByConditionFields[i]);
1750    
1751                                    if ((i + 1) < orderByConditionFields.length) {
1752                                            if (orderByComparator.isAscending() ^ previous) {
1753                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1754                                            }
1755                                            else {
1756                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1757                                            }
1758                                    }
1759                                    else {
1760                                            if (orderByComparator.isAscending() ^ previous) {
1761                                                    query.append(WHERE_GREATER_THAN);
1762                                            }
1763                                            else {
1764                                                    query.append(WHERE_LESSER_THAN);
1765                                            }
1766                                    }
1767                            }
1768    
1769                            query.append(ORDER_BY_CLAUSE);
1770    
1771                            String[] orderByFields = orderByComparator.getOrderByFields();
1772    
1773                            for (int i = 0; i < orderByFields.length; i++) {
1774                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1775                                    query.append(orderByFields[i]);
1776    
1777                                    if ((i + 1) < orderByFields.length) {
1778                                            if (orderByComparator.isAscending() ^ previous) {
1779                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1780                                            }
1781                                            else {
1782                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1783                                            }
1784                                    }
1785                                    else {
1786                                            if (orderByComparator.isAscending() ^ previous) {
1787                                                    query.append(ORDER_BY_ASC);
1788                                            }
1789                                            else {
1790                                                    query.append(ORDER_BY_DESC);
1791                                            }
1792                                    }
1793                            }
1794                    }
1795    
1796                    String sql = query.toString();
1797    
1798                    Query q = session.createQuery(sql);
1799    
1800                    q.setFirstResult(0);
1801                    q.setMaxResults(2);
1802    
1803                    QueryPos qPos = QueryPos.getInstance(q);
1804    
1805                    qPos.add(companyId);
1806    
1807                    if (orderByComparator != null) {
1808                            Object[] values = orderByComparator.getOrderByConditionValues(ddmContent);
1809    
1810                            for (Object value : values) {
1811                                    qPos.add(value);
1812                            }
1813                    }
1814    
1815                    List<DDMContent> list = q.list();
1816    
1817                    if (list.size() == 2) {
1818                            return list.get(1);
1819                    }
1820                    else {
1821                            return null;
1822                    }
1823            }
1824    
1825            /**
1826             * Returns all the d d m contents.
1827             *
1828             * @return the d d m contents
1829             * @throws SystemException if a system exception occurred
1830             */
1831            public List<DDMContent> findAll() throws SystemException {
1832                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1833            }
1834    
1835            /**
1836             * Returns a range of all the d d m contents.
1837             *
1838             * <p>
1839             * 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.
1840             * </p>
1841             *
1842             * @param start the lower bound of the range of d d m contents
1843             * @param end the upper bound of the range of d d m contents (not inclusive)
1844             * @return the range of d d m contents
1845             * @throws SystemException if a system exception occurred
1846             */
1847            public List<DDMContent> findAll(int start, int end)
1848                    throws SystemException {
1849                    return findAll(start, end, null);
1850            }
1851    
1852            /**
1853             * Returns an ordered range of all the d d m contents.
1854             *
1855             * <p>
1856             * 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.
1857             * </p>
1858             *
1859             * @param start the lower bound of the range of d d m contents
1860             * @param end the upper bound of the range of d d m contents (not inclusive)
1861             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1862             * @return the ordered range of d d m contents
1863             * @throws SystemException if a system exception occurred
1864             */
1865            public List<DDMContent> findAll(int start, int end,
1866                    OrderByComparator orderByComparator) throws SystemException {
1867                    FinderPath finderPath = null;
1868                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1869    
1870                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1871                                    (orderByComparator == null)) {
1872                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1873                            finderArgs = FINDER_ARGS_EMPTY;
1874                    }
1875                    else {
1876                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1877                            finderArgs = new Object[] { start, end, orderByComparator };
1878                    }
1879    
1880                    List<DDMContent> list = (List<DDMContent>)FinderCacheUtil.getResult(finderPath,
1881                                    finderArgs, this);
1882    
1883                    if (list == null) {
1884                            StringBundler query = null;
1885                            String sql = null;
1886    
1887                            if (orderByComparator != null) {
1888                                    query = new StringBundler(2 +
1889                                                    (orderByComparator.getOrderByFields().length * 3));
1890    
1891                                    query.append(_SQL_SELECT_DDMCONTENT);
1892    
1893                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1894                                            orderByComparator);
1895    
1896                                    sql = query.toString();
1897                            }
1898                            else {
1899                                    sql = _SQL_SELECT_DDMCONTENT;
1900                            }
1901    
1902                            Session session = null;
1903    
1904                            try {
1905                                    session = openSession();
1906    
1907                                    Query q = session.createQuery(sql);
1908    
1909                                    if (orderByComparator == null) {
1910                                            list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
1911                                                            start, end, false);
1912    
1913                                            Collections.sort(list);
1914                                    }
1915                                    else {
1916                                            list = (List<DDMContent>)QueryUtil.list(q, getDialect(),
1917                                                            start, end);
1918                                    }
1919                            }
1920                            catch (Exception e) {
1921                                    throw processException(e);
1922                            }
1923                            finally {
1924                                    if (list == null) {
1925                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1926                                    }
1927                                    else {
1928                                            cacheResult(list);
1929    
1930                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1931                                    }
1932    
1933                                    closeSession(session);
1934                            }
1935                    }
1936    
1937                    return list;
1938            }
1939    
1940            /**
1941             * Removes all the d d m contents where uuid = &#63; from the database.
1942             *
1943             * @param uuid the uuid
1944             * @throws SystemException if a system exception occurred
1945             */
1946            public void removeByUuid(String uuid) throws SystemException {
1947                    for (DDMContent ddmContent : findByUuid(uuid)) {
1948                            remove(ddmContent);
1949                    }
1950            }
1951    
1952            /**
1953             * Removes the d d m content where uuid = &#63; and groupId = &#63; from the database.
1954             *
1955             * @param uuid the uuid
1956             * @param groupId the group ID
1957             * @throws SystemException if a system exception occurred
1958             */
1959            public void removeByUUID_G(String uuid, long groupId)
1960                    throws NoSuchContentException, SystemException {
1961                    DDMContent ddmContent = findByUUID_G(uuid, groupId);
1962    
1963                    remove(ddmContent);
1964            }
1965    
1966            /**
1967             * Removes all the d d m contents where groupId = &#63; from the database.
1968             *
1969             * @param groupId the group ID
1970             * @throws SystemException if a system exception occurred
1971             */
1972            public void removeByGroupId(long groupId) throws SystemException {
1973                    for (DDMContent ddmContent : findByGroupId(groupId)) {
1974                            remove(ddmContent);
1975                    }
1976            }
1977    
1978            /**
1979             * Removes all the d d m contents where companyId = &#63; from the database.
1980             *
1981             * @param companyId the company ID
1982             * @throws SystemException if a system exception occurred
1983             */
1984            public void removeByCompanyId(long companyId) throws SystemException {
1985                    for (DDMContent ddmContent : findByCompanyId(companyId)) {
1986                            remove(ddmContent);
1987                    }
1988            }
1989    
1990            /**
1991             * Removes all the d d m contents from the database.
1992             *
1993             * @throws SystemException if a system exception occurred
1994             */
1995            public void removeAll() throws SystemException {
1996                    for (DDMContent ddmContent : findAll()) {
1997                            remove(ddmContent);
1998                    }
1999            }
2000    
2001            /**
2002             * Returns the number of d d m contents where uuid = &#63;.
2003             *
2004             * @param uuid the uuid
2005             * @return the number of matching d d m contents
2006             * @throws SystemException if a system exception occurred
2007             */
2008            public int countByUuid(String uuid) throws SystemException {
2009                    Object[] finderArgs = new Object[] { uuid };
2010    
2011                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2012                                    finderArgs, this);
2013    
2014                    if (count == null) {
2015                            StringBundler query = new StringBundler(2);
2016    
2017                            query.append(_SQL_COUNT_DDMCONTENT_WHERE);
2018    
2019                            if (uuid == null) {
2020                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
2021                            }
2022                            else {
2023                                    if (uuid.equals(StringPool.BLANK)) {
2024                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
2025                                    }
2026                                    else {
2027                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
2028                                    }
2029                            }
2030    
2031                            String sql = query.toString();
2032    
2033                            Session session = null;
2034    
2035                            try {
2036                                    session = openSession();
2037    
2038                                    Query q = session.createQuery(sql);
2039    
2040                                    QueryPos qPos = QueryPos.getInstance(q);
2041    
2042                                    if (uuid != null) {
2043                                            qPos.add(uuid);
2044                                    }
2045    
2046                                    count = (Long)q.uniqueResult();
2047                            }
2048                            catch (Exception e) {
2049                                    throw processException(e);
2050                            }
2051                            finally {
2052                                    if (count == null) {
2053                                            count = Long.valueOf(0);
2054                                    }
2055    
2056                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2057                                            finderArgs, count);
2058    
2059                                    closeSession(session);
2060                            }
2061                    }
2062    
2063                    return count.intValue();
2064            }
2065    
2066            /**
2067             * Returns the number of d d m contents where uuid = &#63; and groupId = &#63;.
2068             *
2069             * @param uuid the uuid
2070             * @param groupId the group ID
2071             * @return the number of matching d d m contents
2072             * @throws SystemException if a system exception occurred
2073             */
2074            public int countByUUID_G(String uuid, long groupId)
2075                    throws SystemException {
2076                    Object[] finderArgs = new Object[] { uuid, groupId };
2077    
2078                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2079                                    finderArgs, this);
2080    
2081                    if (count == null) {
2082                            StringBundler query = new StringBundler(3);
2083    
2084                            query.append(_SQL_COUNT_DDMCONTENT_WHERE);
2085    
2086                            if (uuid == null) {
2087                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2088                            }
2089                            else {
2090                                    if (uuid.equals(StringPool.BLANK)) {
2091                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2092                                    }
2093                                    else {
2094                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2095                                    }
2096                            }
2097    
2098                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2099    
2100                            String sql = query.toString();
2101    
2102                            Session session = null;
2103    
2104                            try {
2105                                    session = openSession();
2106    
2107                                    Query q = session.createQuery(sql);
2108    
2109                                    QueryPos qPos = QueryPos.getInstance(q);
2110    
2111                                    if (uuid != null) {
2112                                            qPos.add(uuid);
2113                                    }
2114    
2115                                    qPos.add(groupId);
2116    
2117                                    count = (Long)q.uniqueResult();
2118                            }
2119                            catch (Exception e) {
2120                                    throw processException(e);
2121                            }
2122                            finally {
2123                                    if (count == null) {
2124                                            count = Long.valueOf(0);
2125                                    }
2126    
2127                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2128                                            finderArgs, count);
2129    
2130                                    closeSession(session);
2131                            }
2132                    }
2133    
2134                    return count.intValue();
2135            }
2136    
2137            /**
2138             * Returns the number of d d m contents where groupId = &#63;.
2139             *
2140             * @param groupId the group ID
2141             * @return the number of matching d d m contents
2142             * @throws SystemException if a system exception occurred
2143             */
2144            public int countByGroupId(long groupId) throws SystemException {
2145                    Object[] finderArgs = new Object[] { groupId };
2146    
2147                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2148                                    finderArgs, this);
2149    
2150                    if (count == null) {
2151                            StringBundler query = new StringBundler(2);
2152    
2153                            query.append(_SQL_COUNT_DDMCONTENT_WHERE);
2154    
2155                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2156    
2157                            String sql = query.toString();
2158    
2159                            Session session = null;
2160    
2161                            try {
2162                                    session = openSession();
2163    
2164                                    Query q = session.createQuery(sql);
2165    
2166                                    QueryPos qPos = QueryPos.getInstance(q);
2167    
2168                                    qPos.add(groupId);
2169    
2170                                    count = (Long)q.uniqueResult();
2171                            }
2172                            catch (Exception e) {
2173                                    throw processException(e);
2174                            }
2175                            finally {
2176                                    if (count == null) {
2177                                            count = Long.valueOf(0);
2178                                    }
2179    
2180                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2181                                            finderArgs, count);
2182    
2183                                    closeSession(session);
2184                            }
2185                    }
2186    
2187                    return count.intValue();
2188            }
2189    
2190            /**
2191             * Returns the number of d d m contents where companyId = &#63;.
2192             *
2193             * @param companyId the company ID
2194             * @return the number of matching d d m contents
2195             * @throws SystemException if a system exception occurred
2196             */
2197            public int countByCompanyId(long companyId) throws SystemException {
2198                    Object[] finderArgs = new Object[] { companyId };
2199    
2200                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2201                                    finderArgs, this);
2202    
2203                    if (count == null) {
2204                            StringBundler query = new StringBundler(2);
2205    
2206                            query.append(_SQL_COUNT_DDMCONTENT_WHERE);
2207    
2208                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2209    
2210                            String sql = query.toString();
2211    
2212                            Session session = null;
2213    
2214                            try {
2215                                    session = openSession();
2216    
2217                                    Query q = session.createQuery(sql);
2218    
2219                                    QueryPos qPos = QueryPos.getInstance(q);
2220    
2221                                    qPos.add(companyId);
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_BY_COMPANYID,
2234                                            finderArgs, count);
2235    
2236                                    closeSession(session);
2237                            }
2238                    }
2239    
2240                    return count.intValue();
2241            }
2242    
2243            /**
2244             * Returns the number of d d m contents.
2245             *
2246             * @return the number of d d m contents
2247             * @throws SystemException if a system exception occurred
2248             */
2249            public int countAll() throws SystemException {
2250                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2251                                    FINDER_ARGS_EMPTY, this);
2252    
2253                    if (count == null) {
2254                            Session session = null;
2255    
2256                            try {
2257                                    session = openSession();
2258    
2259                                    Query q = session.createQuery(_SQL_COUNT_DDMCONTENT);
2260    
2261                                    count = (Long)q.uniqueResult();
2262                            }
2263                            catch (Exception e) {
2264                                    throw processException(e);
2265                            }
2266                            finally {
2267                                    if (count == null) {
2268                                            count = Long.valueOf(0);
2269                                    }
2270    
2271                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2272                                            FINDER_ARGS_EMPTY, count);
2273    
2274                                    closeSession(session);
2275                            }
2276                    }
2277    
2278                    return count.intValue();
2279            }
2280    
2281            /**
2282             * Initializes the d d m content persistence.
2283             */
2284            public void afterPropertiesSet() {
2285                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2286                                            com.liferay.portal.util.PropsUtil.get(
2287                                                    "value.object.listener.com.liferay.portlet.dynamicdatamapping.model.DDMContent")));
2288    
2289                    if (listenerClassNames.length > 0) {
2290                            try {
2291                                    List<ModelListener<DDMContent>> listenersList = new ArrayList<ModelListener<DDMContent>>();
2292    
2293                                    for (String listenerClassName : listenerClassNames) {
2294                                            listenersList.add((ModelListener<DDMContent>)InstanceFactory.newInstance(
2295                                                            listenerClassName));
2296                                    }
2297    
2298                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2299                            }
2300                            catch (Exception e) {
2301                                    _log.error(e);
2302                            }
2303                    }
2304            }
2305    
2306            public void destroy() {
2307                    EntityCacheUtil.removeCache(DDMContentImpl.class.getName());
2308                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2309                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2310            }
2311    
2312            @BeanReference(type = DDMContentPersistence.class)
2313            protected DDMContentPersistence ddmContentPersistence;
2314            @BeanReference(type = DDMStorageLinkPersistence.class)
2315            protected DDMStorageLinkPersistence ddmStorageLinkPersistence;
2316            @BeanReference(type = DDMStructurePersistence.class)
2317            protected DDMStructurePersistence ddmStructurePersistence;
2318            @BeanReference(type = DDMStructureLinkPersistence.class)
2319            protected DDMStructureLinkPersistence ddmStructureLinkPersistence;
2320            @BeanReference(type = DDMTemplatePersistence.class)
2321            protected DDMTemplatePersistence ddmTemplatePersistence;
2322            @BeanReference(type = ResourcePersistence.class)
2323            protected ResourcePersistence resourcePersistence;
2324            @BeanReference(type = UserPersistence.class)
2325            protected UserPersistence userPersistence;
2326            private static final String _SQL_SELECT_DDMCONTENT = "SELECT ddmContent FROM DDMContent ddmContent";
2327            private static final String _SQL_SELECT_DDMCONTENT_WHERE = "SELECT ddmContent FROM DDMContent ddmContent WHERE ";
2328            private static final String _SQL_COUNT_DDMCONTENT = "SELECT COUNT(ddmContent) FROM DDMContent ddmContent";
2329            private static final String _SQL_COUNT_DDMCONTENT_WHERE = "SELECT COUNT(ddmContent) FROM DDMContent ddmContent WHERE ";
2330            private static final String _FINDER_COLUMN_UUID_UUID_1 = "ddmContent.uuid IS NULL";
2331            private static final String _FINDER_COLUMN_UUID_UUID_2 = "ddmContent.uuid = ?";
2332            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(ddmContent.uuid IS NULL OR ddmContent.uuid = ?)";
2333            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "ddmContent.uuid IS NULL AND ";
2334            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "ddmContent.uuid = ? AND ";
2335            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(ddmContent.uuid IS NULL OR ddmContent.uuid = ?) AND ";
2336            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "ddmContent.groupId = ?";
2337            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "ddmContent.groupId = ?";
2338            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "ddmContent.companyId = ?";
2339            private static final String _ORDER_BY_ENTITY_ALIAS = "ddmContent.";
2340            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DDMContent exists with the primary key ";
2341            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DDMContent exists with the key {";
2342            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2343            private static Log _log = LogFactoryUtil.getLog(DDMContentPersistenceImpl.class);
2344            private static DDMContent _nullDDMContent = new DDMContentImpl() {
2345                            @Override
2346                            public Object clone() {
2347                                    return this;
2348                            }
2349    
2350                            @Override
2351                            public CacheModel<DDMContent> toCacheModel() {
2352                                    return _nullDDMContentCacheModel;
2353                            }
2354                    };
2355    
2356            private static CacheModel<DDMContent> _nullDDMContentCacheModel = new CacheModel<DDMContent>() {
2357                            public DDMContent toEntityModel() {
2358                                    return _nullDDMContent;
2359                            }
2360                    };
2361    }