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