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