001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.dynamicdatamapping.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.CacheModel;
040    import com.liferay.portal.model.ModelListener;
041    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
042    import com.liferay.portal.service.persistence.BatchSessionUtil;
043    import com.liferay.portal.service.persistence.ResourcePersistence;
044    import com.liferay.portal.service.persistence.UserPersistence;
045    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
046    
047    import com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException;
048    import com.liferay.portlet.dynamicdatamapping.model.DDMTemplate;
049    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateImpl;
050    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl;
051    
052    import java.io.Serializable;
053    
054    import java.util.ArrayList;
055    import java.util.Collections;
056    import java.util.List;
057    
058    /**
059     * The persistence implementation for the d d m template service.
060     *
061     * <p>
062     * Caching information and settings can be found in <code>portal.properties</code>
063     * </p>
064     *
065     * @author Brian Wing Shun Chan
066     * @see DDMTemplatePersistence
067     * @see DDMTemplateUtil
068     * @generated
069     */
070    public class DDMTemplatePersistenceImpl extends BasePersistenceImpl<DDMTemplate>
071            implements DDMTemplatePersistence {
072            /*
073             * NOTE FOR DEVELOPERS:
074             *
075             * Never modify or reference this class directly. Always use {@link DDMTemplateUtil} to access the d d m template persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
076             */
077            public static final String FINDER_CLASS_NAME_ENTITY = DDMTemplateImpl.class.getName();
078            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079                    ".List1";
080            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081                    ".List2";
082            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
083                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
084                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
085                            new String[] {
086                                    String.class.getName(),
087                                    
088                            "java.lang.Integer", "java.lang.Integer",
089                                    "com.liferay.portal.kernel.util.OrderByComparator"
090                            });
091            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
092                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
093                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
094                            new String[] { String.class.getName() },
095                            DDMTemplateModelImpl.UUID_COLUMN_BITMASK);
096            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
097                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
098                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
099                            new String[] { String.class.getName() });
100            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
101                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
102                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
103                            new String[] { String.class.getName(), Long.class.getName() },
104                            DDMTemplateModelImpl.UUID_COLUMN_BITMASK |
105                            DDMTemplateModelImpl.GROUPID_COLUMN_BITMASK);
106            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
107                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
108                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
109                            new String[] { String.class.getName(), Long.class.getName() });
110            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
111                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
112                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
113                            new String[] {
114                                    Long.class.getName(),
115                                    
116                            "java.lang.Integer", "java.lang.Integer",
117                                    "com.liferay.portal.kernel.util.OrderByComparator"
118                            });
119            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
120                    new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
121                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
122                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
123                            new String[] { Long.class.getName() },
124                            DDMTemplateModelImpl.GROUPID_COLUMN_BITMASK);
125            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
126                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
127                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
128                            new String[] { Long.class.getName() });
129            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREID =
130                    new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
131                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
132                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByStructureId",
133                            new String[] {
134                                    Long.class.getName(),
135                                    
136                            "java.lang.Integer", "java.lang.Integer",
137                                    "com.liferay.portal.kernel.util.OrderByComparator"
138                            });
139            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID =
140                    new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
141                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
142                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByStructureId",
143                            new String[] { Long.class.getName() },
144                            DDMTemplateModelImpl.STRUCTUREID_COLUMN_BITMASK);
145            public static final FinderPath FINDER_PATH_COUNT_BY_STRUCTUREID = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
146                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
147                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByStructureId",
148                            new String[] { Long.class.getName() });
149            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
150                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
151                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByType",
152                            new String[] {
153                                    String.class.getName(),
154                                    
155                            "java.lang.Integer", "java.lang.Integer",
156                                    "com.liferay.portal.kernel.util.OrderByComparator"
157                            });
158            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
159                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
160                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByType",
161                            new String[] { String.class.getName() },
162                            DDMTemplateModelImpl.TYPE_COLUMN_BITMASK);
163            public static final FinderPath FINDER_PATH_COUNT_BY_TYPE = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
164                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
165                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByType",
166                            new String[] { String.class.getName() });
167            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LANGUAGE = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
168                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
169                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByLanguage",
170                            new String[] {
171                                    String.class.getName(),
172                                    
173                            "java.lang.Integer", "java.lang.Integer",
174                                    "com.liferay.portal.kernel.util.OrderByComparator"
175                            });
176            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LANGUAGE =
177                    new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
178                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
179                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByLanguage",
180                            new String[] { String.class.getName() },
181                            DDMTemplateModelImpl.LANGUAGE_COLUMN_BITMASK);
182            public static final FinderPath FINDER_PATH_COUNT_BY_LANGUAGE = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
183                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
184                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByLanguage",
185                            new String[] { String.class.getName() });
186            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_S_T = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
187                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
188                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByS_T",
189                            new String[] {
190                                    Long.class.getName(), String.class.getName(),
191                                    
192                            "java.lang.Integer", "java.lang.Integer",
193                                    "com.liferay.portal.kernel.util.OrderByComparator"
194                            });
195            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_S_T = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
196                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
197                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByS_T",
198                            new String[] { Long.class.getName(), String.class.getName() },
199                            DDMTemplateModelImpl.STRUCTUREID_COLUMN_BITMASK |
200                            DDMTemplateModelImpl.TYPE_COLUMN_BITMASK);
201            public static final FinderPath FINDER_PATH_COUNT_BY_S_T = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
202                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
203                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByS_T",
204                            new String[] { Long.class.getName(), String.class.getName() });
205            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_S_T_M = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
206                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
207                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByS_T_M",
208                            new String[] {
209                                    Long.class.getName(), String.class.getName(),
210                                    String.class.getName(),
211                                    
212                            "java.lang.Integer", "java.lang.Integer",
213                                    "com.liferay.portal.kernel.util.OrderByComparator"
214                            });
215            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_S_T_M = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
216                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
217                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByS_T_M",
218                            new String[] {
219                                    Long.class.getName(), String.class.getName(),
220                                    String.class.getName()
221                            },
222                            DDMTemplateModelImpl.STRUCTUREID_COLUMN_BITMASK |
223                            DDMTemplateModelImpl.TYPE_COLUMN_BITMASK |
224                            DDMTemplateModelImpl.MODE_COLUMN_BITMASK);
225            public static final FinderPath FINDER_PATH_COUNT_BY_S_T_M = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
226                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
227                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByS_T_M",
228                            new String[] {
229                                    Long.class.getName(), String.class.getName(),
230                                    String.class.getName()
231                            });
232            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
233                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
234                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
235            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
236                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
237                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
238            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
239                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
240                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
241    
242            /**
243             * Caches the d d m template in the entity cache if it is enabled.
244             *
245             * @param ddmTemplate the d d m template
246             */
247            public void cacheResult(DDMTemplate ddmTemplate) {
248                    EntityCacheUtil.putResult(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
249                            DDMTemplateImpl.class, ddmTemplate.getPrimaryKey(), ddmTemplate);
250    
251                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
252                            new Object[] {
253                                    ddmTemplate.getUuid(), Long.valueOf(ddmTemplate.getGroupId())
254                            }, ddmTemplate);
255    
256                    ddmTemplate.resetOriginalValues();
257            }
258    
259            /**
260             * Caches the d d m templates in the entity cache if it is enabled.
261             *
262             * @param ddmTemplates the d d m templates
263             */
264            public void cacheResult(List<DDMTemplate> ddmTemplates) {
265                    for (DDMTemplate ddmTemplate : ddmTemplates) {
266                            if (EntityCacheUtil.getResult(
267                                                    DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
268                                                    DDMTemplateImpl.class, ddmTemplate.getPrimaryKey()) == null) {
269                                    cacheResult(ddmTemplate);
270                            }
271                            else {
272                                    ddmTemplate.resetOriginalValues();
273                            }
274                    }
275            }
276    
277            /**
278             * Clears the cache for all d d m templates.
279             *
280             * <p>
281             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
282             * </p>
283             */
284            @Override
285            public void clearCache() {
286                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
287                            CacheRegistryUtil.clear(DDMTemplateImpl.class.getName());
288                    }
289    
290                    EntityCacheUtil.clearCache(DDMTemplateImpl.class.getName());
291    
292                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
293                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
294                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
295            }
296    
297            /**
298             * Clears the cache for the d d m template.
299             *
300             * <p>
301             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
302             * </p>
303             */
304            @Override
305            public void clearCache(DDMTemplate ddmTemplate) {
306                    EntityCacheUtil.removeResult(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
307                            DDMTemplateImpl.class, ddmTemplate.getPrimaryKey());
308    
309                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
310                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
311    
312                    clearUniqueFindersCache(ddmTemplate);
313            }
314    
315            @Override
316            public void clearCache(List<DDMTemplate> ddmTemplates) {
317                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
318                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
319    
320                    for (DDMTemplate ddmTemplate : ddmTemplates) {
321                            EntityCacheUtil.removeResult(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
322                                    DDMTemplateImpl.class, ddmTemplate.getPrimaryKey());
323    
324                            clearUniqueFindersCache(ddmTemplate);
325                    }
326            }
327    
328            protected void clearUniqueFindersCache(DDMTemplate ddmTemplate) {
329                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
330                            new Object[] {
331                                    ddmTemplate.getUuid(), Long.valueOf(ddmTemplate.getGroupId())
332                            });
333            }
334    
335            /**
336             * Creates a new d d m template with the primary key. Does not add the d d m template to the database.
337             *
338             * @param templateId the primary key for the new d d m template
339             * @return the new d d m template
340             */
341            public DDMTemplate create(long templateId) {
342                    DDMTemplate ddmTemplate = new DDMTemplateImpl();
343    
344                    ddmTemplate.setNew(true);
345                    ddmTemplate.setPrimaryKey(templateId);
346    
347                    String uuid = PortalUUIDUtil.generate();
348    
349                    ddmTemplate.setUuid(uuid);
350    
351                    return ddmTemplate;
352            }
353    
354            /**
355             * Removes the d d m template with the primary key from the database. Also notifies the appropriate model listeners.
356             *
357             * @param templateId the primary key of the d d m template
358             * @return the d d m template that was removed
359             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
360             * @throws SystemException if a system exception occurred
361             */
362            public DDMTemplate remove(long templateId)
363                    throws NoSuchTemplateException, SystemException {
364                    return remove(Long.valueOf(templateId));
365            }
366    
367            /**
368             * Removes the d d m template with the primary key from the database. Also notifies the appropriate model listeners.
369             *
370             * @param primaryKey the primary key of the d d m template
371             * @return the d d m template that was removed
372             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
373             * @throws SystemException if a system exception occurred
374             */
375            @Override
376            public DDMTemplate remove(Serializable primaryKey)
377                    throws NoSuchTemplateException, SystemException {
378                    Session session = null;
379    
380                    try {
381                            session = openSession();
382    
383                            DDMTemplate ddmTemplate = (DDMTemplate)session.get(DDMTemplateImpl.class,
384                                            primaryKey);
385    
386                            if (ddmTemplate == null) {
387                                    if (_log.isWarnEnabled()) {
388                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
389                                    }
390    
391                                    throw new NoSuchTemplateException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
392                                            primaryKey);
393                            }
394    
395                            return remove(ddmTemplate);
396                    }
397                    catch (NoSuchTemplateException nsee) {
398                            throw nsee;
399                    }
400                    catch (Exception e) {
401                            throw processException(e);
402                    }
403                    finally {
404                            closeSession(session);
405                    }
406            }
407    
408            @Override
409            protected DDMTemplate removeImpl(DDMTemplate ddmTemplate)
410                    throws SystemException {
411                    ddmTemplate = toUnwrappedModel(ddmTemplate);
412    
413                    Session session = null;
414    
415                    try {
416                            session = openSession();
417    
418                            BatchSessionUtil.delete(session, ddmTemplate);
419                    }
420                    catch (Exception e) {
421                            throw processException(e);
422                    }
423                    finally {
424                            closeSession(session);
425                    }
426    
427                    clearCache(ddmTemplate);
428    
429                    return ddmTemplate;
430            }
431    
432            @Override
433            public DDMTemplate updateImpl(
434                    com.liferay.portlet.dynamicdatamapping.model.DDMTemplate ddmTemplate,
435                    boolean merge) throws SystemException {
436                    ddmTemplate = toUnwrappedModel(ddmTemplate);
437    
438                    boolean isNew = ddmTemplate.isNew();
439    
440                    DDMTemplateModelImpl ddmTemplateModelImpl = (DDMTemplateModelImpl)ddmTemplate;
441    
442                    if (Validator.isNull(ddmTemplate.getUuid())) {
443                            String uuid = PortalUUIDUtil.generate();
444    
445                            ddmTemplate.setUuid(uuid);
446                    }
447    
448                    Session session = null;
449    
450                    try {
451                            session = openSession();
452    
453                            BatchSessionUtil.update(session, ddmTemplate, merge);
454    
455                            ddmTemplate.setNew(false);
456                    }
457                    catch (Exception e) {
458                            throw processException(e);
459                    }
460                    finally {
461                            closeSession(session);
462                    }
463    
464                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
465    
466                    if (isNew || !DDMTemplateModelImpl.COLUMN_BITMASK_ENABLED) {
467                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
468                    }
469    
470                    else {
471                            if ((ddmTemplateModelImpl.getColumnBitmask() &
472                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
473                                    Object[] args = new Object[] {
474                                                    ddmTemplateModelImpl.getOriginalUuid()
475                                            };
476    
477                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
478                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
479                                            args);
480    
481                                    args = new Object[] { ddmTemplateModelImpl.getUuid() };
482    
483                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
484                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
485                                            args);
486                            }
487    
488                            if ((ddmTemplateModelImpl.getColumnBitmask() &
489                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
490                                    Object[] args = new Object[] {
491                                                    Long.valueOf(ddmTemplateModelImpl.getOriginalGroupId())
492                                            };
493    
494                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
495                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
496                                            args);
497    
498                                    args = new Object[] {
499                                                    Long.valueOf(ddmTemplateModelImpl.getGroupId())
500                                            };
501    
502                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
503                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
504                                            args);
505                            }
506    
507                            if ((ddmTemplateModelImpl.getColumnBitmask() &
508                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID.getColumnBitmask()) != 0) {
509                                    Object[] args = new Object[] {
510                                                    Long.valueOf(ddmTemplateModelImpl.getOriginalStructureId())
511                                            };
512    
513                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_STRUCTUREID,
514                                            args);
515                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID,
516                                            args);
517    
518                                    args = new Object[] {
519                                                    Long.valueOf(ddmTemplateModelImpl.getStructureId())
520                                            };
521    
522                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_STRUCTUREID,
523                                            args);
524                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID,
525                                            args);
526                            }
527    
528                            if ((ddmTemplateModelImpl.getColumnBitmask() &
529                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE.getColumnBitmask()) != 0) {
530                                    Object[] args = new Object[] {
531                                                    ddmTemplateModelImpl.getOriginalType()
532                                            };
533    
534                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
535                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
536                                            args);
537    
538                                    args = new Object[] { ddmTemplateModelImpl.getType() };
539    
540                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
541                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
542                                            args);
543                            }
544    
545                            if ((ddmTemplateModelImpl.getColumnBitmask() &
546                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LANGUAGE.getColumnBitmask()) != 0) {
547                                    Object[] args = new Object[] {
548                                                    ddmTemplateModelImpl.getOriginalLanguage()
549                                            };
550    
551                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LANGUAGE, args);
552                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LANGUAGE,
553                                            args);
554    
555                                    args = new Object[] { ddmTemplateModelImpl.getLanguage() };
556    
557                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LANGUAGE, args);
558                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LANGUAGE,
559                                            args);
560                            }
561    
562                            if ((ddmTemplateModelImpl.getColumnBitmask() &
563                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_S_T.getColumnBitmask()) != 0) {
564                                    Object[] args = new Object[] {
565                                                    Long.valueOf(ddmTemplateModelImpl.getOriginalStructureId()),
566                                                    
567                                                    ddmTemplateModelImpl.getOriginalType()
568                                            };
569    
570                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_S_T, args);
571                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_S_T,
572                                            args);
573    
574                                    args = new Object[] {
575                                                    Long.valueOf(ddmTemplateModelImpl.getStructureId()),
576                                                    
577                                                    ddmTemplateModelImpl.getType()
578                                            };
579    
580                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_S_T, args);
581                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_S_T,
582                                            args);
583                            }
584    
585                            if ((ddmTemplateModelImpl.getColumnBitmask() &
586                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_S_T_M.getColumnBitmask()) != 0) {
587                                    Object[] args = new Object[] {
588                                                    Long.valueOf(ddmTemplateModelImpl.getOriginalStructureId()),
589                                                    
590                                                    ddmTemplateModelImpl.getOriginalType(),
591                                                    
592                                                    ddmTemplateModelImpl.getOriginalMode()
593                                            };
594    
595                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_S_T_M, args);
596                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_S_T_M,
597                                            args);
598    
599                                    args = new Object[] {
600                                                    Long.valueOf(ddmTemplateModelImpl.getStructureId()),
601                                                    
602                                                    ddmTemplateModelImpl.getType(),
603                                                    
604                                                    ddmTemplateModelImpl.getMode()
605                                            };
606    
607                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_S_T_M, args);
608                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_S_T_M,
609                                            args);
610                            }
611                    }
612    
613                    EntityCacheUtil.putResult(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
614                            DDMTemplateImpl.class, ddmTemplate.getPrimaryKey(), ddmTemplate);
615    
616                    if (isNew) {
617                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
618                                    new Object[] {
619                                            ddmTemplate.getUuid(),
620                                            Long.valueOf(ddmTemplate.getGroupId())
621                                    }, ddmTemplate);
622                    }
623                    else {
624                            if ((ddmTemplateModelImpl.getColumnBitmask() &
625                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
626                                    Object[] args = new Object[] {
627                                                    ddmTemplateModelImpl.getOriginalUuid(),
628                                                    Long.valueOf(ddmTemplateModelImpl.getOriginalGroupId())
629                                            };
630    
631                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
632                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
633    
634                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
635                                            new Object[] {
636                                                    ddmTemplate.getUuid(),
637                                                    Long.valueOf(ddmTemplate.getGroupId())
638                                            }, ddmTemplate);
639                            }
640                    }
641    
642                    return ddmTemplate;
643            }
644    
645            protected DDMTemplate toUnwrappedModel(DDMTemplate ddmTemplate) {
646                    if (ddmTemplate instanceof DDMTemplateImpl) {
647                            return ddmTemplate;
648                    }
649    
650                    DDMTemplateImpl ddmTemplateImpl = new DDMTemplateImpl();
651    
652                    ddmTemplateImpl.setNew(ddmTemplate.isNew());
653                    ddmTemplateImpl.setPrimaryKey(ddmTemplate.getPrimaryKey());
654    
655                    ddmTemplateImpl.setUuid(ddmTemplate.getUuid());
656                    ddmTemplateImpl.setTemplateId(ddmTemplate.getTemplateId());
657                    ddmTemplateImpl.setGroupId(ddmTemplate.getGroupId());
658                    ddmTemplateImpl.setCompanyId(ddmTemplate.getCompanyId());
659                    ddmTemplateImpl.setUserId(ddmTemplate.getUserId());
660                    ddmTemplateImpl.setUserName(ddmTemplate.getUserName());
661                    ddmTemplateImpl.setCreateDate(ddmTemplate.getCreateDate());
662                    ddmTemplateImpl.setModifiedDate(ddmTemplate.getModifiedDate());
663                    ddmTemplateImpl.setStructureId(ddmTemplate.getStructureId());
664                    ddmTemplateImpl.setName(ddmTemplate.getName());
665                    ddmTemplateImpl.setDescription(ddmTemplate.getDescription());
666                    ddmTemplateImpl.setType(ddmTemplate.getType());
667                    ddmTemplateImpl.setMode(ddmTemplate.getMode());
668                    ddmTemplateImpl.setLanguage(ddmTemplate.getLanguage());
669                    ddmTemplateImpl.setScript(ddmTemplate.getScript());
670    
671                    return ddmTemplateImpl;
672            }
673    
674            /**
675             * Returns the d d m template with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
676             *
677             * @param primaryKey the primary key of the d d m template
678             * @return the d d m template
679             * @throws com.liferay.portal.NoSuchModelException if a d d m template with the primary key could not be found
680             * @throws SystemException if a system exception occurred
681             */
682            @Override
683            public DDMTemplate findByPrimaryKey(Serializable primaryKey)
684                    throws NoSuchModelException, SystemException {
685                    return findByPrimaryKey(((Long)primaryKey).longValue());
686            }
687    
688            /**
689             * Returns the d d m template with the primary key or throws a {@link com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException} if it could not be found.
690             *
691             * @param templateId the primary key of the d d m template
692             * @return the d d m template
693             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
694             * @throws SystemException if a system exception occurred
695             */
696            public DDMTemplate findByPrimaryKey(long templateId)
697                    throws NoSuchTemplateException, SystemException {
698                    DDMTemplate ddmTemplate = fetchByPrimaryKey(templateId);
699    
700                    if (ddmTemplate == null) {
701                            if (_log.isWarnEnabled()) {
702                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + templateId);
703                            }
704    
705                            throw new NoSuchTemplateException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
706                                    templateId);
707                    }
708    
709                    return ddmTemplate;
710            }
711    
712            /**
713             * Returns the d d m template with the primary key or returns <code>null</code> if it could not be found.
714             *
715             * @param primaryKey the primary key of the d d m template
716             * @return the d d m template, or <code>null</code> if a d d m template with the primary key could not be found
717             * @throws SystemException if a system exception occurred
718             */
719            @Override
720            public DDMTemplate fetchByPrimaryKey(Serializable primaryKey)
721                    throws SystemException {
722                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
723            }
724    
725            /**
726             * Returns the d d m template with the primary key or returns <code>null</code> if it could not be found.
727             *
728             * @param templateId the primary key of the d d m template
729             * @return the d d m template, or <code>null</code> if a d d m template with the primary key could not be found
730             * @throws SystemException if a system exception occurred
731             */
732            public DDMTemplate fetchByPrimaryKey(long templateId)
733                    throws SystemException {
734                    DDMTemplate ddmTemplate = (DDMTemplate)EntityCacheUtil.getResult(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
735                                    DDMTemplateImpl.class, templateId);
736    
737                    if (ddmTemplate == _nullDDMTemplate) {
738                            return null;
739                    }
740    
741                    if (ddmTemplate == null) {
742                            Session session = null;
743    
744                            boolean hasException = false;
745    
746                            try {
747                                    session = openSession();
748    
749                                    ddmTemplate = (DDMTemplate)session.get(DDMTemplateImpl.class,
750                                                    Long.valueOf(templateId));
751                            }
752                            catch (Exception e) {
753                                    hasException = true;
754    
755                                    throw processException(e);
756                            }
757                            finally {
758                                    if (ddmTemplate != null) {
759                                            cacheResult(ddmTemplate);
760                                    }
761                                    else if (!hasException) {
762                                            EntityCacheUtil.putResult(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
763                                                    DDMTemplateImpl.class, templateId, _nullDDMTemplate);
764                                    }
765    
766                                    closeSession(session);
767                            }
768                    }
769    
770                    return ddmTemplate;
771            }
772    
773            /**
774             * Returns all the d d m templates where uuid = &#63;.
775             *
776             * @param uuid the uuid
777             * @return the matching d d m templates
778             * @throws SystemException if a system exception occurred
779             */
780            public List<DDMTemplate> findByUuid(String uuid) throws SystemException {
781                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
782            }
783    
784            /**
785             * Returns a range of all the d d m templates where uuid = &#63;.
786             *
787             * <p>
788             * 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.
789             * </p>
790             *
791             * @param uuid the uuid
792             * @param start the lower bound of the range of d d m templates
793             * @param end the upper bound of the range of d d m templates (not inclusive)
794             * @return the range of matching d d m templates
795             * @throws SystemException if a system exception occurred
796             */
797            public List<DDMTemplate> findByUuid(String uuid, int start, int end)
798                    throws SystemException {
799                    return findByUuid(uuid, start, end, null);
800            }
801    
802            /**
803             * Returns an ordered range of all the d d m templates where uuid = &#63;.
804             *
805             * <p>
806             * 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.
807             * </p>
808             *
809             * @param uuid the uuid
810             * @param start the lower bound of the range of d d m templates
811             * @param end the upper bound of the range of d d m templates (not inclusive)
812             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
813             * @return the ordered range of matching d d m templates
814             * @throws SystemException if a system exception occurred
815             */
816            public List<DDMTemplate> findByUuid(String uuid, int start, int end,
817                    OrderByComparator orderByComparator) throws SystemException {
818                    FinderPath finderPath = null;
819                    Object[] finderArgs = null;
820    
821                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
822                                    (orderByComparator == null)) {
823                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
824                            finderArgs = new Object[] { uuid };
825                    }
826                    else {
827                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
828                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
829                    }
830    
831                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
832                                    finderArgs, this);
833    
834                    if (list == null) {
835                            StringBundler query = null;
836    
837                            if (orderByComparator != null) {
838                                    query = new StringBundler(3 +
839                                                    (orderByComparator.getOrderByFields().length * 3));
840                            }
841                            else {
842                                    query = new StringBundler(2);
843                            }
844    
845                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
846    
847                            if (uuid == null) {
848                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
849                            }
850                            else {
851                                    if (uuid.equals(StringPool.BLANK)) {
852                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
853                                    }
854                                    else {
855                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
856                                    }
857                            }
858    
859                            if (orderByComparator != null) {
860                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
861                                            orderByComparator);
862                            }
863    
864                            String sql = query.toString();
865    
866                            Session session = null;
867    
868                            try {
869                                    session = openSession();
870    
871                                    Query q = session.createQuery(sql);
872    
873                                    QueryPos qPos = QueryPos.getInstance(q);
874    
875                                    if (uuid != null) {
876                                            qPos.add(uuid);
877                                    }
878    
879                                    list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
880                                                    start, end);
881                            }
882                            catch (Exception e) {
883                                    throw processException(e);
884                            }
885                            finally {
886                                    if (list == null) {
887                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
888                                    }
889                                    else {
890                                            cacheResult(list);
891    
892                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
893                                    }
894    
895                                    closeSession(session);
896                            }
897                    }
898    
899                    return list;
900            }
901    
902            /**
903             * Returns the first d d m template in the ordered set where uuid = &#63;.
904             *
905             * <p>
906             * 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.
907             * </p>
908             *
909             * @param uuid the uuid
910             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
911             * @return the first matching d d m template
912             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
913             * @throws SystemException if a system exception occurred
914             */
915            public DDMTemplate findByUuid_First(String uuid,
916                    OrderByComparator orderByComparator)
917                    throws NoSuchTemplateException, SystemException {
918                    List<DDMTemplate> list = findByUuid(uuid, 0, 1, orderByComparator);
919    
920                    if (list.isEmpty()) {
921                            StringBundler msg = new StringBundler(4);
922    
923                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
924    
925                            msg.append("uuid=");
926                            msg.append(uuid);
927    
928                            msg.append(StringPool.CLOSE_CURLY_BRACE);
929    
930                            throw new NoSuchTemplateException(msg.toString());
931                    }
932                    else {
933                            return list.get(0);
934                    }
935            }
936    
937            /**
938             * Returns the last d d m template in the ordered set where uuid = &#63;.
939             *
940             * <p>
941             * 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.
942             * </p>
943             *
944             * @param uuid the uuid
945             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
946             * @return the last matching d d m template
947             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
948             * @throws SystemException if a system exception occurred
949             */
950            public DDMTemplate findByUuid_Last(String uuid,
951                    OrderByComparator orderByComparator)
952                    throws NoSuchTemplateException, SystemException {
953                    int count = countByUuid(uuid);
954    
955                    List<DDMTemplate> list = findByUuid(uuid, count - 1, count,
956                                    orderByComparator);
957    
958                    if (list.isEmpty()) {
959                            StringBundler msg = new StringBundler(4);
960    
961                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
962    
963                            msg.append("uuid=");
964                            msg.append(uuid);
965    
966                            msg.append(StringPool.CLOSE_CURLY_BRACE);
967    
968                            throw new NoSuchTemplateException(msg.toString());
969                    }
970                    else {
971                            return list.get(0);
972                    }
973            }
974    
975            /**
976             * Returns the d d m templates before and after the current d d m template in the ordered set where uuid = &#63;.
977             *
978             * <p>
979             * 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.
980             * </p>
981             *
982             * @param templateId the primary key of the current d d m template
983             * @param uuid the uuid
984             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
985             * @return the previous, current, and next d d m template
986             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
987             * @throws SystemException if a system exception occurred
988             */
989            public DDMTemplate[] findByUuid_PrevAndNext(long templateId, String uuid,
990                    OrderByComparator orderByComparator)
991                    throws NoSuchTemplateException, SystemException {
992                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
993    
994                    Session session = null;
995    
996                    try {
997                            session = openSession();
998    
999                            DDMTemplate[] array = new DDMTemplateImpl[3];
1000    
1001                            array[0] = getByUuid_PrevAndNext(session, ddmTemplate, uuid,
1002                                            orderByComparator, true);
1003    
1004                            array[1] = ddmTemplate;
1005    
1006                            array[2] = getByUuid_PrevAndNext(session, ddmTemplate, uuid,
1007                                            orderByComparator, false);
1008    
1009                            return array;
1010                    }
1011                    catch (Exception e) {
1012                            throw processException(e);
1013                    }
1014                    finally {
1015                            closeSession(session);
1016                    }
1017            }
1018    
1019            protected DDMTemplate getByUuid_PrevAndNext(Session session,
1020                    DDMTemplate ddmTemplate, String uuid,
1021                    OrderByComparator orderByComparator, boolean previous) {
1022                    StringBundler query = null;
1023    
1024                    if (orderByComparator != null) {
1025                            query = new StringBundler(6 +
1026                                            (orderByComparator.getOrderByFields().length * 6));
1027                    }
1028                    else {
1029                            query = new StringBundler(3);
1030                    }
1031    
1032                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
1033    
1034                    if (uuid == null) {
1035                            query.append(_FINDER_COLUMN_UUID_UUID_1);
1036                    }
1037                    else {
1038                            if (uuid.equals(StringPool.BLANK)) {
1039                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
1040                            }
1041                            else {
1042                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
1043                            }
1044                    }
1045    
1046                    if (orderByComparator != null) {
1047                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1048    
1049                            if (orderByConditionFields.length > 0) {
1050                                    query.append(WHERE_AND);
1051                            }
1052    
1053                            for (int i = 0; i < orderByConditionFields.length; i++) {
1054                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1055                                    query.append(orderByConditionFields[i]);
1056    
1057                                    if ((i + 1) < orderByConditionFields.length) {
1058                                            if (orderByComparator.isAscending() ^ previous) {
1059                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1060                                            }
1061                                            else {
1062                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1063                                            }
1064                                    }
1065                                    else {
1066                                            if (orderByComparator.isAscending() ^ previous) {
1067                                                    query.append(WHERE_GREATER_THAN);
1068                                            }
1069                                            else {
1070                                                    query.append(WHERE_LESSER_THAN);
1071                                            }
1072                                    }
1073                            }
1074    
1075                            query.append(ORDER_BY_CLAUSE);
1076    
1077                            String[] orderByFields = orderByComparator.getOrderByFields();
1078    
1079                            for (int i = 0; i < orderByFields.length; i++) {
1080                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1081                                    query.append(orderByFields[i]);
1082    
1083                                    if ((i + 1) < orderByFields.length) {
1084                                            if (orderByComparator.isAscending() ^ previous) {
1085                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1086                                            }
1087                                            else {
1088                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1089                                            }
1090                                    }
1091                                    else {
1092                                            if (orderByComparator.isAscending() ^ previous) {
1093                                                    query.append(ORDER_BY_ASC);
1094                                            }
1095                                            else {
1096                                                    query.append(ORDER_BY_DESC);
1097                                            }
1098                                    }
1099                            }
1100                    }
1101    
1102                    String sql = query.toString();
1103    
1104                    Query q = session.createQuery(sql);
1105    
1106                    q.setFirstResult(0);
1107                    q.setMaxResults(2);
1108    
1109                    QueryPos qPos = QueryPos.getInstance(q);
1110    
1111                    if (uuid != null) {
1112                            qPos.add(uuid);
1113                    }
1114    
1115                    if (orderByComparator != null) {
1116                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
1117    
1118                            for (Object value : values) {
1119                                    qPos.add(value);
1120                            }
1121                    }
1122    
1123                    List<DDMTemplate> list = q.list();
1124    
1125                    if (list.size() == 2) {
1126                            return list.get(1);
1127                    }
1128                    else {
1129                            return null;
1130                    }
1131            }
1132    
1133            /**
1134             * Returns the d d m template where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException} if it could not be found.
1135             *
1136             * @param uuid the uuid
1137             * @param groupId the group ID
1138             * @return the matching d d m template
1139             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
1140             * @throws SystemException if a system exception occurred
1141             */
1142            public DDMTemplate findByUUID_G(String uuid, long groupId)
1143                    throws NoSuchTemplateException, SystemException {
1144                    DDMTemplate ddmTemplate = fetchByUUID_G(uuid, groupId);
1145    
1146                    if (ddmTemplate == null) {
1147                            StringBundler msg = new StringBundler(6);
1148    
1149                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1150    
1151                            msg.append("uuid=");
1152                            msg.append(uuid);
1153    
1154                            msg.append(", groupId=");
1155                            msg.append(groupId);
1156    
1157                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1158    
1159                            if (_log.isWarnEnabled()) {
1160                                    _log.warn(msg.toString());
1161                            }
1162    
1163                            throw new NoSuchTemplateException(msg.toString());
1164                    }
1165    
1166                    return ddmTemplate;
1167            }
1168    
1169            /**
1170             * Returns the d d m template where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1171             *
1172             * @param uuid the uuid
1173             * @param groupId the group ID
1174             * @return the matching d d m template, or <code>null</code> if a matching d d m template could not be found
1175             * @throws SystemException if a system exception occurred
1176             */
1177            public DDMTemplate fetchByUUID_G(String uuid, long groupId)
1178                    throws SystemException {
1179                    return fetchByUUID_G(uuid, groupId, true);
1180            }
1181    
1182            /**
1183             * Returns the d d m template where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1184             *
1185             * @param uuid the uuid
1186             * @param groupId the group ID
1187             * @param retrieveFromCache whether to use the finder cache
1188             * @return the matching d d m template, or <code>null</code> if a matching d d m template could not be found
1189             * @throws SystemException if a system exception occurred
1190             */
1191            public DDMTemplate fetchByUUID_G(String uuid, long groupId,
1192                    boolean retrieveFromCache) throws SystemException {
1193                    Object[] finderArgs = new Object[] { uuid, groupId };
1194    
1195                    Object result = null;
1196    
1197                    if (retrieveFromCache) {
1198                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1199                                            finderArgs, this);
1200                    }
1201    
1202                    if (result == null) {
1203                            StringBundler query = new StringBundler(3);
1204    
1205                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
1206    
1207                            if (uuid == null) {
1208                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1209                            }
1210                            else {
1211                                    if (uuid.equals(StringPool.BLANK)) {
1212                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1213                                    }
1214                                    else {
1215                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1216                                    }
1217                            }
1218    
1219                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1220    
1221                            String sql = query.toString();
1222    
1223                            Session session = null;
1224    
1225                            try {
1226                                    session = openSession();
1227    
1228                                    Query q = session.createQuery(sql);
1229    
1230                                    QueryPos qPos = QueryPos.getInstance(q);
1231    
1232                                    if (uuid != null) {
1233                                            qPos.add(uuid);
1234                                    }
1235    
1236                                    qPos.add(groupId);
1237    
1238                                    List<DDMTemplate> list = q.list();
1239    
1240                                    result = list;
1241    
1242                                    DDMTemplate ddmTemplate = null;
1243    
1244                                    if (list.isEmpty()) {
1245                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1246                                                    finderArgs, list);
1247                                    }
1248                                    else {
1249                                            ddmTemplate = list.get(0);
1250    
1251                                            cacheResult(ddmTemplate);
1252    
1253                                            if ((ddmTemplate.getUuid() == null) ||
1254                                                            !ddmTemplate.getUuid().equals(uuid) ||
1255                                                            (ddmTemplate.getGroupId() != groupId)) {
1256                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1257                                                            finderArgs, ddmTemplate);
1258                                            }
1259                                    }
1260    
1261                                    return ddmTemplate;
1262                            }
1263                            catch (Exception e) {
1264                                    throw processException(e);
1265                            }
1266                            finally {
1267                                    if (result == null) {
1268                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1269                                                    finderArgs);
1270                                    }
1271    
1272                                    closeSession(session);
1273                            }
1274                    }
1275                    else {
1276                            if (result instanceof List<?>) {
1277                                    return null;
1278                            }
1279                            else {
1280                                    return (DDMTemplate)result;
1281                            }
1282                    }
1283            }
1284    
1285            /**
1286             * Returns all the d d m templates where groupId = &#63;.
1287             *
1288             * @param groupId the group ID
1289             * @return the matching d d m templates
1290             * @throws SystemException if a system exception occurred
1291             */
1292            public List<DDMTemplate> findByGroupId(long groupId)
1293                    throws SystemException {
1294                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1295            }
1296    
1297            /**
1298             * Returns a range of all the d d m templates where groupId = &#63;.
1299             *
1300             * <p>
1301             * 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.
1302             * </p>
1303             *
1304             * @param groupId the group ID
1305             * @param start the lower bound of the range of d d m templates
1306             * @param end the upper bound of the range of d d m templates (not inclusive)
1307             * @return the range of matching d d m templates
1308             * @throws SystemException if a system exception occurred
1309             */
1310            public List<DDMTemplate> findByGroupId(long groupId, int start, int end)
1311                    throws SystemException {
1312                    return findByGroupId(groupId, start, end, null);
1313            }
1314    
1315            /**
1316             * Returns an ordered range of all the d d m templates where groupId = &#63;.
1317             *
1318             * <p>
1319             * 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.
1320             * </p>
1321             *
1322             * @param groupId the group ID
1323             * @param start the lower bound of the range of d d m templates
1324             * @param end the upper bound of the range of d d m templates (not inclusive)
1325             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1326             * @return the ordered range of matching d d m templates
1327             * @throws SystemException if a system exception occurred
1328             */
1329            public List<DDMTemplate> findByGroupId(long groupId, int start, int end,
1330                    OrderByComparator orderByComparator) throws SystemException {
1331                    FinderPath finderPath = null;
1332                    Object[] finderArgs = null;
1333    
1334                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1335                                    (orderByComparator == null)) {
1336                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1337                            finderArgs = new Object[] { groupId };
1338                    }
1339                    else {
1340                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1341                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1342                    }
1343    
1344                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
1345                                    finderArgs, this);
1346    
1347                    if (list == null) {
1348                            StringBundler query = null;
1349    
1350                            if (orderByComparator != null) {
1351                                    query = new StringBundler(3 +
1352                                                    (orderByComparator.getOrderByFields().length * 3));
1353                            }
1354                            else {
1355                                    query = new StringBundler(2);
1356                            }
1357    
1358                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
1359    
1360                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1361    
1362                            if (orderByComparator != null) {
1363                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1364                                            orderByComparator);
1365                            }
1366    
1367                            String sql = query.toString();
1368    
1369                            Session session = null;
1370    
1371                            try {
1372                                    session = openSession();
1373    
1374                                    Query q = session.createQuery(sql);
1375    
1376                                    QueryPos qPos = QueryPos.getInstance(q);
1377    
1378                                    qPos.add(groupId);
1379    
1380                                    list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
1381                                                    start, end);
1382                            }
1383                            catch (Exception e) {
1384                                    throw processException(e);
1385                            }
1386                            finally {
1387                                    if (list == null) {
1388                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1389                                    }
1390                                    else {
1391                                            cacheResult(list);
1392    
1393                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1394                                    }
1395    
1396                                    closeSession(session);
1397                            }
1398                    }
1399    
1400                    return list;
1401            }
1402    
1403            /**
1404             * Returns the first d d m template in the ordered set where groupId = &#63;.
1405             *
1406             * <p>
1407             * 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.
1408             * </p>
1409             *
1410             * @param groupId the group ID
1411             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1412             * @return the first matching d d m template
1413             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
1414             * @throws SystemException if a system exception occurred
1415             */
1416            public DDMTemplate findByGroupId_First(long groupId,
1417                    OrderByComparator orderByComparator)
1418                    throws NoSuchTemplateException, SystemException {
1419                    List<DDMTemplate> list = findByGroupId(groupId, 0, 1, orderByComparator);
1420    
1421                    if (list.isEmpty()) {
1422                            StringBundler msg = new StringBundler(4);
1423    
1424                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1425    
1426                            msg.append("groupId=");
1427                            msg.append(groupId);
1428    
1429                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1430    
1431                            throw new NoSuchTemplateException(msg.toString());
1432                    }
1433                    else {
1434                            return list.get(0);
1435                    }
1436            }
1437    
1438            /**
1439             * Returns the last d d m template in the ordered set where groupId = &#63;.
1440             *
1441             * <p>
1442             * 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.
1443             * </p>
1444             *
1445             * @param groupId the group ID
1446             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1447             * @return the last matching d d m template
1448             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
1449             * @throws SystemException if a system exception occurred
1450             */
1451            public DDMTemplate findByGroupId_Last(long groupId,
1452                    OrderByComparator orderByComparator)
1453                    throws NoSuchTemplateException, SystemException {
1454                    int count = countByGroupId(groupId);
1455    
1456                    List<DDMTemplate> list = findByGroupId(groupId, count - 1, count,
1457                                    orderByComparator);
1458    
1459                    if (list.isEmpty()) {
1460                            StringBundler msg = new StringBundler(4);
1461    
1462                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1463    
1464                            msg.append("groupId=");
1465                            msg.append(groupId);
1466    
1467                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1468    
1469                            throw new NoSuchTemplateException(msg.toString());
1470                    }
1471                    else {
1472                            return list.get(0);
1473                    }
1474            }
1475    
1476            /**
1477             * Returns the d d m templates before and after the current d d m template in the ordered set where groupId = &#63;.
1478             *
1479             * <p>
1480             * 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.
1481             * </p>
1482             *
1483             * @param templateId the primary key of the current d d m template
1484             * @param groupId the group ID
1485             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1486             * @return the previous, current, and next d d m template
1487             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
1488             * @throws SystemException if a system exception occurred
1489             */
1490            public DDMTemplate[] findByGroupId_PrevAndNext(long templateId,
1491                    long groupId, OrderByComparator orderByComparator)
1492                    throws NoSuchTemplateException, SystemException {
1493                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
1494    
1495                    Session session = null;
1496    
1497                    try {
1498                            session = openSession();
1499    
1500                            DDMTemplate[] array = new DDMTemplateImpl[3];
1501    
1502                            array[0] = getByGroupId_PrevAndNext(session, ddmTemplate, groupId,
1503                                            orderByComparator, true);
1504    
1505                            array[1] = ddmTemplate;
1506    
1507                            array[2] = getByGroupId_PrevAndNext(session, ddmTemplate, groupId,
1508                                            orderByComparator, false);
1509    
1510                            return array;
1511                    }
1512                    catch (Exception e) {
1513                            throw processException(e);
1514                    }
1515                    finally {
1516                            closeSession(session);
1517                    }
1518            }
1519    
1520            protected DDMTemplate getByGroupId_PrevAndNext(Session session,
1521                    DDMTemplate ddmTemplate, long groupId,
1522                    OrderByComparator orderByComparator, boolean previous) {
1523                    StringBundler query = null;
1524    
1525                    if (orderByComparator != null) {
1526                            query = new StringBundler(6 +
1527                                            (orderByComparator.getOrderByFields().length * 6));
1528                    }
1529                    else {
1530                            query = new StringBundler(3);
1531                    }
1532    
1533                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
1534    
1535                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1536    
1537                    if (orderByComparator != null) {
1538                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1539    
1540                            if (orderByConditionFields.length > 0) {
1541                                    query.append(WHERE_AND);
1542                            }
1543    
1544                            for (int i = 0; i < orderByConditionFields.length; i++) {
1545                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1546                                    query.append(orderByConditionFields[i]);
1547    
1548                                    if ((i + 1) < orderByConditionFields.length) {
1549                                            if (orderByComparator.isAscending() ^ previous) {
1550                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1551                                            }
1552                                            else {
1553                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1554                                            }
1555                                    }
1556                                    else {
1557                                            if (orderByComparator.isAscending() ^ previous) {
1558                                                    query.append(WHERE_GREATER_THAN);
1559                                            }
1560                                            else {
1561                                                    query.append(WHERE_LESSER_THAN);
1562                                            }
1563                                    }
1564                            }
1565    
1566                            query.append(ORDER_BY_CLAUSE);
1567    
1568                            String[] orderByFields = orderByComparator.getOrderByFields();
1569    
1570                            for (int i = 0; i < orderByFields.length; i++) {
1571                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1572                                    query.append(orderByFields[i]);
1573    
1574                                    if ((i + 1) < orderByFields.length) {
1575                                            if (orderByComparator.isAscending() ^ previous) {
1576                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1577                                            }
1578                                            else {
1579                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1580                                            }
1581                                    }
1582                                    else {
1583                                            if (orderByComparator.isAscending() ^ previous) {
1584                                                    query.append(ORDER_BY_ASC);
1585                                            }
1586                                            else {
1587                                                    query.append(ORDER_BY_DESC);
1588                                            }
1589                                    }
1590                            }
1591                    }
1592    
1593                    String sql = query.toString();
1594    
1595                    Query q = session.createQuery(sql);
1596    
1597                    q.setFirstResult(0);
1598                    q.setMaxResults(2);
1599    
1600                    QueryPos qPos = QueryPos.getInstance(q);
1601    
1602                    qPos.add(groupId);
1603    
1604                    if (orderByComparator != null) {
1605                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
1606    
1607                            for (Object value : values) {
1608                                    qPos.add(value);
1609                            }
1610                    }
1611    
1612                    List<DDMTemplate> list = q.list();
1613    
1614                    if (list.size() == 2) {
1615                            return list.get(1);
1616                    }
1617                    else {
1618                            return null;
1619                    }
1620            }
1621    
1622            /**
1623             * Returns all the d d m templates that the user has permission to view where groupId = &#63;.
1624             *
1625             * @param groupId the group ID
1626             * @return the matching d d m templates that the user has permission to view
1627             * @throws SystemException if a system exception occurred
1628             */
1629            public List<DDMTemplate> filterFindByGroupId(long groupId)
1630                    throws SystemException {
1631                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1632                            QueryUtil.ALL_POS, null);
1633            }
1634    
1635            /**
1636             * Returns a range of all the d d m templates that the user has permission to view where groupId = &#63;.
1637             *
1638             * <p>
1639             * 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.
1640             * </p>
1641             *
1642             * @param groupId the group ID
1643             * @param start the lower bound of the range of d d m templates
1644             * @param end the upper bound of the range of d d m templates (not inclusive)
1645             * @return the range of matching d d m templates that the user has permission to view
1646             * @throws SystemException if a system exception occurred
1647             */
1648            public List<DDMTemplate> filterFindByGroupId(long groupId, int start,
1649                    int end) throws SystemException {
1650                    return filterFindByGroupId(groupId, start, end, null);
1651            }
1652    
1653            /**
1654             * Returns an ordered range of all the d d m templates that the user has permissions to view where groupId = &#63;.
1655             *
1656             * <p>
1657             * 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.
1658             * </p>
1659             *
1660             * @param groupId the group ID
1661             * @param start the lower bound of the range of d d m templates
1662             * @param end the upper bound of the range of d d m templates (not inclusive)
1663             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1664             * @return the ordered range of matching d d m templates that the user has permission to view
1665             * @throws SystemException if a system exception occurred
1666             */
1667            public List<DDMTemplate> filterFindByGroupId(long groupId, int start,
1668                    int end, OrderByComparator orderByComparator) throws SystemException {
1669                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1670                            return findByGroupId(groupId, start, end, orderByComparator);
1671                    }
1672    
1673                    StringBundler query = null;
1674    
1675                    if (orderByComparator != null) {
1676                            query = new StringBundler(3 +
1677                                            (orderByComparator.getOrderByFields().length * 3));
1678                    }
1679                    else {
1680                            query = new StringBundler(2);
1681                    }
1682    
1683                    if (getDB().isSupportsInlineDistinct()) {
1684                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_WHERE);
1685                    }
1686                    else {
1687                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
1688                    }
1689    
1690                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1691    
1692                    if (!getDB().isSupportsInlineDistinct()) {
1693                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
1694                    }
1695    
1696                    if (orderByComparator != null) {
1697                            if (getDB().isSupportsInlineDistinct()) {
1698                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1699                                            orderByComparator);
1700                            }
1701                            else {
1702                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1703                                            orderByComparator);
1704                            }
1705                    }
1706    
1707                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1708                                    DDMTemplate.class.getName(),
1709                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1710    
1711                    Session session = null;
1712    
1713                    try {
1714                            session = openSession();
1715    
1716                            SQLQuery q = session.createSQLQuery(sql);
1717    
1718                            if (getDB().isSupportsInlineDistinct()) {
1719                                    q.addEntity(_FILTER_ENTITY_ALIAS, DDMTemplateImpl.class);
1720                            }
1721                            else {
1722                                    q.addEntity(_FILTER_ENTITY_TABLE, DDMTemplateImpl.class);
1723                            }
1724    
1725                            QueryPos qPos = QueryPos.getInstance(q);
1726    
1727                            qPos.add(groupId);
1728    
1729                            return (List<DDMTemplate>)QueryUtil.list(q, getDialect(), start, end);
1730                    }
1731                    catch (Exception e) {
1732                            throw processException(e);
1733                    }
1734                    finally {
1735                            closeSession(session);
1736                    }
1737            }
1738    
1739            /**
1740             * Returns the d d m templates before and after the current d d m template in the ordered set of d d m templates that the user has permission to view where groupId = &#63;.
1741             *
1742             * @param templateId the primary key of the current d d m template
1743             * @param groupId the group ID
1744             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1745             * @return the previous, current, and next d d m template
1746             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
1747             * @throws SystemException if a system exception occurred
1748             */
1749            public DDMTemplate[] filterFindByGroupId_PrevAndNext(long templateId,
1750                    long groupId, OrderByComparator orderByComparator)
1751                    throws NoSuchTemplateException, SystemException {
1752                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1753                            return findByGroupId_PrevAndNext(templateId, groupId,
1754                                    orderByComparator);
1755                    }
1756    
1757                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
1758    
1759                    Session session = null;
1760    
1761                    try {
1762                            session = openSession();
1763    
1764                            DDMTemplate[] array = new DDMTemplateImpl[3];
1765    
1766                            array[0] = filterGetByGroupId_PrevAndNext(session, ddmTemplate,
1767                                            groupId, orderByComparator, true);
1768    
1769                            array[1] = ddmTemplate;
1770    
1771                            array[2] = filterGetByGroupId_PrevAndNext(session, ddmTemplate,
1772                                            groupId, orderByComparator, false);
1773    
1774                            return array;
1775                    }
1776                    catch (Exception e) {
1777                            throw processException(e);
1778                    }
1779                    finally {
1780                            closeSession(session);
1781                    }
1782            }
1783    
1784            protected DDMTemplate filterGetByGroupId_PrevAndNext(Session session,
1785                    DDMTemplate ddmTemplate, long groupId,
1786                    OrderByComparator orderByComparator, boolean previous) {
1787                    StringBundler query = null;
1788    
1789                    if (orderByComparator != null) {
1790                            query = new StringBundler(6 +
1791                                            (orderByComparator.getOrderByFields().length * 6));
1792                    }
1793                    else {
1794                            query = new StringBundler(3);
1795                    }
1796    
1797                    if (getDB().isSupportsInlineDistinct()) {
1798                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_WHERE);
1799                    }
1800                    else {
1801                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
1802                    }
1803    
1804                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1805    
1806                    if (!getDB().isSupportsInlineDistinct()) {
1807                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
1808                    }
1809    
1810                    if (orderByComparator != null) {
1811                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1812    
1813                            if (orderByConditionFields.length > 0) {
1814                                    query.append(WHERE_AND);
1815                            }
1816    
1817                            for (int i = 0; i < orderByConditionFields.length; i++) {
1818                                    if (getDB().isSupportsInlineDistinct()) {
1819                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1820                                    }
1821                                    else {
1822                                            query.append(_ORDER_BY_ENTITY_TABLE);
1823                                    }
1824    
1825                                    query.append(orderByConditionFields[i]);
1826    
1827                                    if ((i + 1) < orderByConditionFields.length) {
1828                                            if (orderByComparator.isAscending() ^ previous) {
1829                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1830                                            }
1831                                            else {
1832                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1833                                            }
1834                                    }
1835                                    else {
1836                                            if (orderByComparator.isAscending() ^ previous) {
1837                                                    query.append(WHERE_GREATER_THAN);
1838                                            }
1839                                            else {
1840                                                    query.append(WHERE_LESSER_THAN);
1841                                            }
1842                                    }
1843                            }
1844    
1845                            query.append(ORDER_BY_CLAUSE);
1846    
1847                            String[] orderByFields = orderByComparator.getOrderByFields();
1848    
1849                            for (int i = 0; i < orderByFields.length; i++) {
1850                                    if (getDB().isSupportsInlineDistinct()) {
1851                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1852                                    }
1853                                    else {
1854                                            query.append(_ORDER_BY_ENTITY_TABLE);
1855                                    }
1856    
1857                                    query.append(orderByFields[i]);
1858    
1859                                    if ((i + 1) < orderByFields.length) {
1860                                            if (orderByComparator.isAscending() ^ previous) {
1861                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1862                                            }
1863                                            else {
1864                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1865                                            }
1866                                    }
1867                                    else {
1868                                            if (orderByComparator.isAscending() ^ previous) {
1869                                                    query.append(ORDER_BY_ASC);
1870                                            }
1871                                            else {
1872                                                    query.append(ORDER_BY_DESC);
1873                                            }
1874                                    }
1875                            }
1876                    }
1877    
1878                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1879                                    DDMTemplate.class.getName(),
1880                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1881    
1882                    SQLQuery q = session.createSQLQuery(sql);
1883    
1884                    q.setFirstResult(0);
1885                    q.setMaxResults(2);
1886    
1887                    if (getDB().isSupportsInlineDistinct()) {
1888                            q.addEntity(_FILTER_ENTITY_ALIAS, DDMTemplateImpl.class);
1889                    }
1890                    else {
1891                            q.addEntity(_FILTER_ENTITY_TABLE, DDMTemplateImpl.class);
1892                    }
1893    
1894                    QueryPos qPos = QueryPos.getInstance(q);
1895    
1896                    qPos.add(groupId);
1897    
1898                    if (orderByComparator != null) {
1899                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
1900    
1901                            for (Object value : values) {
1902                                    qPos.add(value);
1903                            }
1904                    }
1905    
1906                    List<DDMTemplate> list = q.list();
1907    
1908                    if (list.size() == 2) {
1909                            return list.get(1);
1910                    }
1911                    else {
1912                            return null;
1913                    }
1914            }
1915    
1916            /**
1917             * Returns all the d d m templates where structureId = &#63;.
1918             *
1919             * @param structureId the structure ID
1920             * @return the matching d d m templates
1921             * @throws SystemException if a system exception occurred
1922             */
1923            public List<DDMTemplate> findByStructureId(long structureId)
1924                    throws SystemException {
1925                    return findByStructureId(structureId, QueryUtil.ALL_POS,
1926                            QueryUtil.ALL_POS, null);
1927            }
1928    
1929            /**
1930             * Returns a range of all the d d m templates where structureId = &#63;.
1931             *
1932             * <p>
1933             * 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.
1934             * </p>
1935             *
1936             * @param structureId the structure ID
1937             * @param start the lower bound of the range of d d m templates
1938             * @param end the upper bound of the range of d d m templates (not inclusive)
1939             * @return the range of matching d d m templates
1940             * @throws SystemException if a system exception occurred
1941             */
1942            public List<DDMTemplate> findByStructureId(long structureId, int start,
1943                    int end) throws SystemException {
1944                    return findByStructureId(structureId, start, end, null);
1945            }
1946    
1947            /**
1948             * Returns an ordered range of all the d d m templates where structureId = &#63;.
1949             *
1950             * <p>
1951             * 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.
1952             * </p>
1953             *
1954             * @param structureId the structure ID
1955             * @param start the lower bound of the range of d d m templates
1956             * @param end the upper bound of the range of d d m templates (not inclusive)
1957             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1958             * @return the ordered range of matching d d m templates
1959             * @throws SystemException if a system exception occurred
1960             */
1961            public List<DDMTemplate> findByStructureId(long structureId, int start,
1962                    int end, OrderByComparator orderByComparator) throws SystemException {
1963                    FinderPath finderPath = null;
1964                    Object[] finderArgs = null;
1965    
1966                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1967                                    (orderByComparator == null)) {
1968                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID;
1969                            finderArgs = new Object[] { structureId };
1970                    }
1971                    else {
1972                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREID;
1973                            finderArgs = new Object[] { structureId, start, end, orderByComparator };
1974                    }
1975    
1976                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
1977                                    finderArgs, this);
1978    
1979                    if (list == null) {
1980                            StringBundler query = null;
1981    
1982                            if (orderByComparator != null) {
1983                                    query = new StringBundler(3 +
1984                                                    (orderByComparator.getOrderByFields().length * 3));
1985                            }
1986                            else {
1987                                    query = new StringBundler(2);
1988                            }
1989    
1990                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
1991    
1992                            query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
1993    
1994                            if (orderByComparator != null) {
1995                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1996                                            orderByComparator);
1997                            }
1998    
1999                            String sql = query.toString();
2000    
2001                            Session session = null;
2002    
2003                            try {
2004                                    session = openSession();
2005    
2006                                    Query q = session.createQuery(sql);
2007    
2008                                    QueryPos qPos = QueryPos.getInstance(q);
2009    
2010                                    qPos.add(structureId);
2011    
2012                                    list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
2013                                                    start, end);
2014                            }
2015                            catch (Exception e) {
2016                                    throw processException(e);
2017                            }
2018                            finally {
2019                                    if (list == null) {
2020                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2021                                    }
2022                                    else {
2023                                            cacheResult(list);
2024    
2025                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2026                                    }
2027    
2028                                    closeSession(session);
2029                            }
2030                    }
2031    
2032                    return list;
2033            }
2034    
2035            /**
2036             * Returns the first d d m template in the ordered set where structureId = &#63;.
2037             *
2038             * <p>
2039             * 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.
2040             * </p>
2041             *
2042             * @param structureId the structure ID
2043             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2044             * @return the first matching d d m template
2045             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
2046             * @throws SystemException if a system exception occurred
2047             */
2048            public DDMTemplate findByStructureId_First(long structureId,
2049                    OrderByComparator orderByComparator)
2050                    throws NoSuchTemplateException, SystemException {
2051                    List<DDMTemplate> list = findByStructureId(structureId, 0, 1,
2052                                    orderByComparator);
2053    
2054                    if (list.isEmpty()) {
2055                            StringBundler msg = new StringBundler(4);
2056    
2057                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2058    
2059                            msg.append("structureId=");
2060                            msg.append(structureId);
2061    
2062                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2063    
2064                            throw new NoSuchTemplateException(msg.toString());
2065                    }
2066                    else {
2067                            return list.get(0);
2068                    }
2069            }
2070    
2071            /**
2072             * Returns the last d d m template in the ordered set where structureId = &#63;.
2073             *
2074             * <p>
2075             * 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.
2076             * </p>
2077             *
2078             * @param structureId the structure ID
2079             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2080             * @return the last matching d d m template
2081             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
2082             * @throws SystemException if a system exception occurred
2083             */
2084            public DDMTemplate findByStructureId_Last(long structureId,
2085                    OrderByComparator orderByComparator)
2086                    throws NoSuchTemplateException, SystemException {
2087                    int count = countByStructureId(structureId);
2088    
2089                    List<DDMTemplate> list = findByStructureId(structureId, count - 1,
2090                                    count, orderByComparator);
2091    
2092                    if (list.isEmpty()) {
2093                            StringBundler msg = new StringBundler(4);
2094    
2095                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2096    
2097                            msg.append("structureId=");
2098                            msg.append(structureId);
2099    
2100                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2101    
2102                            throw new NoSuchTemplateException(msg.toString());
2103                    }
2104                    else {
2105                            return list.get(0);
2106                    }
2107            }
2108    
2109            /**
2110             * Returns the d d m templates before and after the current d d m template in the ordered set where structureId = &#63;.
2111             *
2112             * <p>
2113             * 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.
2114             * </p>
2115             *
2116             * @param templateId the primary key of the current d d m template
2117             * @param structureId the structure ID
2118             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2119             * @return the previous, current, and next d d m template
2120             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
2121             * @throws SystemException if a system exception occurred
2122             */
2123            public DDMTemplate[] findByStructureId_PrevAndNext(long templateId,
2124                    long structureId, OrderByComparator orderByComparator)
2125                    throws NoSuchTemplateException, SystemException {
2126                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
2127    
2128                    Session session = null;
2129    
2130                    try {
2131                            session = openSession();
2132    
2133                            DDMTemplate[] array = new DDMTemplateImpl[3];
2134    
2135                            array[0] = getByStructureId_PrevAndNext(session, ddmTemplate,
2136                                            structureId, orderByComparator, true);
2137    
2138                            array[1] = ddmTemplate;
2139    
2140                            array[2] = getByStructureId_PrevAndNext(session, ddmTemplate,
2141                                            structureId, orderByComparator, false);
2142    
2143                            return array;
2144                    }
2145                    catch (Exception e) {
2146                            throw processException(e);
2147                    }
2148                    finally {
2149                            closeSession(session);
2150                    }
2151            }
2152    
2153            protected DDMTemplate getByStructureId_PrevAndNext(Session session,
2154                    DDMTemplate ddmTemplate, long structureId,
2155                    OrderByComparator orderByComparator, boolean previous) {
2156                    StringBundler query = null;
2157    
2158                    if (orderByComparator != null) {
2159                            query = new StringBundler(6 +
2160                                            (orderByComparator.getOrderByFields().length * 6));
2161                    }
2162                    else {
2163                            query = new StringBundler(3);
2164                    }
2165    
2166                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
2167    
2168                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
2169    
2170                    if (orderByComparator != null) {
2171                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2172    
2173                            if (orderByConditionFields.length > 0) {
2174                                    query.append(WHERE_AND);
2175                            }
2176    
2177                            for (int i = 0; i < orderByConditionFields.length; i++) {
2178                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2179                                    query.append(orderByConditionFields[i]);
2180    
2181                                    if ((i + 1) < orderByConditionFields.length) {
2182                                            if (orderByComparator.isAscending() ^ previous) {
2183                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2184                                            }
2185                                            else {
2186                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2187                                            }
2188                                    }
2189                                    else {
2190                                            if (orderByComparator.isAscending() ^ previous) {
2191                                                    query.append(WHERE_GREATER_THAN);
2192                                            }
2193                                            else {
2194                                                    query.append(WHERE_LESSER_THAN);
2195                                            }
2196                                    }
2197                            }
2198    
2199                            query.append(ORDER_BY_CLAUSE);
2200    
2201                            String[] orderByFields = orderByComparator.getOrderByFields();
2202    
2203                            for (int i = 0; i < orderByFields.length; i++) {
2204                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2205                                    query.append(orderByFields[i]);
2206    
2207                                    if ((i + 1) < orderByFields.length) {
2208                                            if (orderByComparator.isAscending() ^ previous) {
2209                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2210                                            }
2211                                            else {
2212                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2213                                            }
2214                                    }
2215                                    else {
2216                                            if (orderByComparator.isAscending() ^ previous) {
2217                                                    query.append(ORDER_BY_ASC);
2218                                            }
2219                                            else {
2220                                                    query.append(ORDER_BY_DESC);
2221                                            }
2222                                    }
2223                            }
2224                    }
2225    
2226                    String sql = query.toString();
2227    
2228                    Query q = session.createQuery(sql);
2229    
2230                    q.setFirstResult(0);
2231                    q.setMaxResults(2);
2232    
2233                    QueryPos qPos = QueryPos.getInstance(q);
2234    
2235                    qPos.add(structureId);
2236    
2237                    if (orderByComparator != null) {
2238                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
2239    
2240                            for (Object value : values) {
2241                                    qPos.add(value);
2242                            }
2243                    }
2244    
2245                    List<DDMTemplate> list = q.list();
2246    
2247                    if (list.size() == 2) {
2248                            return list.get(1);
2249                    }
2250                    else {
2251                            return null;
2252                    }
2253            }
2254    
2255            /**
2256             * Returns all the d d m templates where type = &#63;.
2257             *
2258             * @param type the type
2259             * @return the matching d d m templates
2260             * @throws SystemException if a system exception occurred
2261             */
2262            public List<DDMTemplate> findByType(String type) throws SystemException {
2263                    return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2264            }
2265    
2266            /**
2267             * Returns a range of all the d d m templates where type = &#63;.
2268             *
2269             * <p>
2270             * 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.
2271             * </p>
2272             *
2273             * @param type the type
2274             * @param start the lower bound of the range of d d m templates
2275             * @param end the upper bound of the range of d d m templates (not inclusive)
2276             * @return the range of matching d d m templates
2277             * @throws SystemException if a system exception occurred
2278             */
2279            public List<DDMTemplate> findByType(String type, int start, int end)
2280                    throws SystemException {
2281                    return findByType(type, start, end, null);
2282            }
2283    
2284            /**
2285             * Returns an ordered range of all the d d m templates where type = &#63;.
2286             *
2287             * <p>
2288             * 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.
2289             * </p>
2290             *
2291             * @param type the type
2292             * @param start the lower bound of the range of d d m templates
2293             * @param end the upper bound of the range of d d m templates (not inclusive)
2294             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2295             * @return the ordered range of matching d d m templates
2296             * @throws SystemException if a system exception occurred
2297             */
2298            public List<DDMTemplate> findByType(String type, int start, int end,
2299                    OrderByComparator orderByComparator) throws SystemException {
2300                    FinderPath finderPath = null;
2301                    Object[] finderArgs = null;
2302    
2303                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2304                                    (orderByComparator == null)) {
2305                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE;
2306                            finderArgs = new Object[] { type };
2307                    }
2308                    else {
2309                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE;
2310                            finderArgs = new Object[] { type, start, end, orderByComparator };
2311                    }
2312    
2313                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
2314                                    finderArgs, this);
2315    
2316                    if (list == null) {
2317                            StringBundler query = null;
2318    
2319                            if (orderByComparator != null) {
2320                                    query = new StringBundler(3 +
2321                                                    (orderByComparator.getOrderByFields().length * 3));
2322                            }
2323                            else {
2324                                    query = new StringBundler(2);
2325                            }
2326    
2327                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
2328    
2329                            if (type == null) {
2330                                    query.append(_FINDER_COLUMN_TYPE_TYPE_1);
2331                            }
2332                            else {
2333                                    if (type.equals(StringPool.BLANK)) {
2334                                            query.append(_FINDER_COLUMN_TYPE_TYPE_3);
2335                                    }
2336                                    else {
2337                                            query.append(_FINDER_COLUMN_TYPE_TYPE_2);
2338                                    }
2339                            }
2340    
2341                            if (orderByComparator != null) {
2342                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2343                                            orderByComparator);
2344                            }
2345    
2346                            String sql = query.toString();
2347    
2348                            Session session = null;
2349    
2350                            try {
2351                                    session = openSession();
2352    
2353                                    Query q = session.createQuery(sql);
2354    
2355                                    QueryPos qPos = QueryPos.getInstance(q);
2356    
2357                                    if (type != null) {
2358                                            qPos.add(type);
2359                                    }
2360    
2361                                    list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
2362                                                    start, end);
2363                            }
2364                            catch (Exception e) {
2365                                    throw processException(e);
2366                            }
2367                            finally {
2368                                    if (list == null) {
2369                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2370                                    }
2371                                    else {
2372                                            cacheResult(list);
2373    
2374                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2375                                    }
2376    
2377                                    closeSession(session);
2378                            }
2379                    }
2380    
2381                    return list;
2382            }
2383    
2384            /**
2385             * Returns the first d d m template in the ordered set where type = &#63;.
2386             *
2387             * <p>
2388             * 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.
2389             * </p>
2390             *
2391             * @param type the type
2392             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2393             * @return the first matching d d m template
2394             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
2395             * @throws SystemException if a system exception occurred
2396             */
2397            public DDMTemplate findByType_First(String type,
2398                    OrderByComparator orderByComparator)
2399                    throws NoSuchTemplateException, SystemException {
2400                    List<DDMTemplate> list = findByType(type, 0, 1, orderByComparator);
2401    
2402                    if (list.isEmpty()) {
2403                            StringBundler msg = new StringBundler(4);
2404    
2405                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2406    
2407                            msg.append("type=");
2408                            msg.append(type);
2409    
2410                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2411    
2412                            throw new NoSuchTemplateException(msg.toString());
2413                    }
2414                    else {
2415                            return list.get(0);
2416                    }
2417            }
2418    
2419            /**
2420             * Returns the last d d m template in the ordered set where type = &#63;.
2421             *
2422             * <p>
2423             * 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.
2424             * </p>
2425             *
2426             * @param type the type
2427             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2428             * @return the last matching d d m template
2429             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
2430             * @throws SystemException if a system exception occurred
2431             */
2432            public DDMTemplate findByType_Last(String type,
2433                    OrderByComparator orderByComparator)
2434                    throws NoSuchTemplateException, SystemException {
2435                    int count = countByType(type);
2436    
2437                    List<DDMTemplate> list = findByType(type, count - 1, count,
2438                                    orderByComparator);
2439    
2440                    if (list.isEmpty()) {
2441                            StringBundler msg = new StringBundler(4);
2442    
2443                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2444    
2445                            msg.append("type=");
2446                            msg.append(type);
2447    
2448                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2449    
2450                            throw new NoSuchTemplateException(msg.toString());
2451                    }
2452                    else {
2453                            return list.get(0);
2454                    }
2455            }
2456    
2457            /**
2458             * Returns the d d m templates before and after the current d d m template in the ordered set where type = &#63;.
2459             *
2460             * <p>
2461             * 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.
2462             * </p>
2463             *
2464             * @param templateId the primary key of the current d d m template
2465             * @param type the type
2466             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2467             * @return the previous, current, and next d d m template
2468             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
2469             * @throws SystemException if a system exception occurred
2470             */
2471            public DDMTemplate[] findByType_PrevAndNext(long templateId, String type,
2472                    OrderByComparator orderByComparator)
2473                    throws NoSuchTemplateException, SystemException {
2474                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
2475    
2476                    Session session = null;
2477    
2478                    try {
2479                            session = openSession();
2480    
2481                            DDMTemplate[] array = new DDMTemplateImpl[3];
2482    
2483                            array[0] = getByType_PrevAndNext(session, ddmTemplate, type,
2484                                            orderByComparator, true);
2485    
2486                            array[1] = ddmTemplate;
2487    
2488                            array[2] = getByType_PrevAndNext(session, ddmTemplate, type,
2489                                            orderByComparator, false);
2490    
2491                            return array;
2492                    }
2493                    catch (Exception e) {
2494                            throw processException(e);
2495                    }
2496                    finally {
2497                            closeSession(session);
2498                    }
2499            }
2500    
2501            protected DDMTemplate getByType_PrevAndNext(Session session,
2502                    DDMTemplate ddmTemplate, String type,
2503                    OrderByComparator orderByComparator, boolean previous) {
2504                    StringBundler query = null;
2505    
2506                    if (orderByComparator != null) {
2507                            query = new StringBundler(6 +
2508                                            (orderByComparator.getOrderByFields().length * 6));
2509                    }
2510                    else {
2511                            query = new StringBundler(3);
2512                    }
2513    
2514                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
2515    
2516                    if (type == null) {
2517                            query.append(_FINDER_COLUMN_TYPE_TYPE_1);
2518                    }
2519                    else {
2520                            if (type.equals(StringPool.BLANK)) {
2521                                    query.append(_FINDER_COLUMN_TYPE_TYPE_3);
2522                            }
2523                            else {
2524                                    query.append(_FINDER_COLUMN_TYPE_TYPE_2);
2525                            }
2526                    }
2527    
2528                    if (orderByComparator != null) {
2529                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2530    
2531                            if (orderByConditionFields.length > 0) {
2532                                    query.append(WHERE_AND);
2533                            }
2534    
2535                            for (int i = 0; i < orderByConditionFields.length; i++) {
2536                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2537                                    query.append(orderByConditionFields[i]);
2538    
2539                                    if ((i + 1) < orderByConditionFields.length) {
2540                                            if (orderByComparator.isAscending() ^ previous) {
2541                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2542                                            }
2543                                            else {
2544                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2545                                            }
2546                                    }
2547                                    else {
2548                                            if (orderByComparator.isAscending() ^ previous) {
2549                                                    query.append(WHERE_GREATER_THAN);
2550                                            }
2551                                            else {
2552                                                    query.append(WHERE_LESSER_THAN);
2553                                            }
2554                                    }
2555                            }
2556    
2557                            query.append(ORDER_BY_CLAUSE);
2558    
2559                            String[] orderByFields = orderByComparator.getOrderByFields();
2560    
2561                            for (int i = 0; i < orderByFields.length; i++) {
2562                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2563                                    query.append(orderByFields[i]);
2564    
2565                                    if ((i + 1) < orderByFields.length) {
2566                                            if (orderByComparator.isAscending() ^ previous) {
2567                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2568                                            }
2569                                            else {
2570                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2571                                            }
2572                                    }
2573                                    else {
2574                                            if (orderByComparator.isAscending() ^ previous) {
2575                                                    query.append(ORDER_BY_ASC);
2576                                            }
2577                                            else {
2578                                                    query.append(ORDER_BY_DESC);
2579                                            }
2580                                    }
2581                            }
2582                    }
2583    
2584                    String sql = query.toString();
2585    
2586                    Query q = session.createQuery(sql);
2587    
2588                    q.setFirstResult(0);
2589                    q.setMaxResults(2);
2590    
2591                    QueryPos qPos = QueryPos.getInstance(q);
2592    
2593                    if (type != null) {
2594                            qPos.add(type);
2595                    }
2596    
2597                    if (orderByComparator != null) {
2598                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
2599    
2600                            for (Object value : values) {
2601                                    qPos.add(value);
2602                            }
2603                    }
2604    
2605                    List<DDMTemplate> list = q.list();
2606    
2607                    if (list.size() == 2) {
2608                            return list.get(1);
2609                    }
2610                    else {
2611                            return null;
2612                    }
2613            }
2614    
2615            /**
2616             * Returns all the d d m templates where language = &#63;.
2617             *
2618             * @param language the language
2619             * @return the matching d d m templates
2620             * @throws SystemException if a system exception occurred
2621             */
2622            public List<DDMTemplate> findByLanguage(String language)
2623                    throws SystemException {
2624                    return findByLanguage(language, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2625                            null);
2626            }
2627    
2628            /**
2629             * Returns a range of all the d d m templates where language = &#63;.
2630             *
2631             * <p>
2632             * 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.
2633             * </p>
2634             *
2635             * @param language the language
2636             * @param start the lower bound of the range of d d m templates
2637             * @param end the upper bound of the range of d d m templates (not inclusive)
2638             * @return the range of matching d d m templates
2639             * @throws SystemException if a system exception occurred
2640             */
2641            public List<DDMTemplate> findByLanguage(String language, int start, int end)
2642                    throws SystemException {
2643                    return findByLanguage(language, start, end, null);
2644            }
2645    
2646            /**
2647             * Returns an ordered range of all the d d m templates where language = &#63;.
2648             *
2649             * <p>
2650             * 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.
2651             * </p>
2652             *
2653             * @param language the language
2654             * @param start the lower bound of the range of d d m templates
2655             * @param end the upper bound of the range of d d m templates (not inclusive)
2656             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2657             * @return the ordered range of matching d d m templates
2658             * @throws SystemException if a system exception occurred
2659             */
2660            public List<DDMTemplate> findByLanguage(String language, int start,
2661                    int end, OrderByComparator orderByComparator) throws SystemException {
2662                    FinderPath finderPath = null;
2663                    Object[] finderArgs = null;
2664    
2665                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2666                                    (orderByComparator == null)) {
2667                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LANGUAGE;
2668                            finderArgs = new Object[] { language };
2669                    }
2670                    else {
2671                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LANGUAGE;
2672                            finderArgs = new Object[] { language, start, end, orderByComparator };
2673                    }
2674    
2675                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
2676                                    finderArgs, this);
2677    
2678                    if (list == null) {
2679                            StringBundler query = null;
2680    
2681                            if (orderByComparator != null) {
2682                                    query = new StringBundler(3 +
2683                                                    (orderByComparator.getOrderByFields().length * 3));
2684                            }
2685                            else {
2686                                    query = new StringBundler(2);
2687                            }
2688    
2689                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
2690    
2691                            if (language == null) {
2692                                    query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_1);
2693                            }
2694                            else {
2695                                    if (language.equals(StringPool.BLANK)) {
2696                                            query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_3);
2697                                    }
2698                                    else {
2699                                            query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_2);
2700                                    }
2701                            }
2702    
2703                            if (orderByComparator != null) {
2704                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2705                                            orderByComparator);
2706                            }
2707    
2708                            String sql = query.toString();
2709    
2710                            Session session = null;
2711    
2712                            try {
2713                                    session = openSession();
2714    
2715                                    Query q = session.createQuery(sql);
2716    
2717                                    QueryPos qPos = QueryPos.getInstance(q);
2718    
2719                                    if (language != null) {
2720                                            qPos.add(language);
2721                                    }
2722    
2723                                    list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
2724                                                    start, end);
2725                            }
2726                            catch (Exception e) {
2727                                    throw processException(e);
2728                            }
2729                            finally {
2730                                    if (list == null) {
2731                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2732                                    }
2733                                    else {
2734                                            cacheResult(list);
2735    
2736                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2737                                    }
2738    
2739                                    closeSession(session);
2740                            }
2741                    }
2742    
2743                    return list;
2744            }
2745    
2746            /**
2747             * Returns the first d d m template in the ordered set where language = &#63;.
2748             *
2749             * <p>
2750             * 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.
2751             * </p>
2752             *
2753             * @param language the language
2754             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2755             * @return the first matching d d m template
2756             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
2757             * @throws SystemException if a system exception occurred
2758             */
2759            public DDMTemplate findByLanguage_First(String language,
2760                    OrderByComparator orderByComparator)
2761                    throws NoSuchTemplateException, SystemException {
2762                    List<DDMTemplate> list = findByLanguage(language, 0, 1,
2763                                    orderByComparator);
2764    
2765                    if (list.isEmpty()) {
2766                            StringBundler msg = new StringBundler(4);
2767    
2768                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2769    
2770                            msg.append("language=");
2771                            msg.append(language);
2772    
2773                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2774    
2775                            throw new NoSuchTemplateException(msg.toString());
2776                    }
2777                    else {
2778                            return list.get(0);
2779                    }
2780            }
2781    
2782            /**
2783             * Returns the last d d m template in the ordered set where language = &#63;.
2784             *
2785             * <p>
2786             * 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.
2787             * </p>
2788             *
2789             * @param language the language
2790             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2791             * @return the last matching d d m template
2792             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
2793             * @throws SystemException if a system exception occurred
2794             */
2795            public DDMTemplate findByLanguage_Last(String language,
2796                    OrderByComparator orderByComparator)
2797                    throws NoSuchTemplateException, SystemException {
2798                    int count = countByLanguage(language);
2799    
2800                    List<DDMTemplate> list = findByLanguage(language, count - 1, count,
2801                                    orderByComparator);
2802    
2803                    if (list.isEmpty()) {
2804                            StringBundler msg = new StringBundler(4);
2805    
2806                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2807    
2808                            msg.append("language=");
2809                            msg.append(language);
2810    
2811                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2812    
2813                            throw new NoSuchTemplateException(msg.toString());
2814                    }
2815                    else {
2816                            return list.get(0);
2817                    }
2818            }
2819    
2820            /**
2821             * Returns the d d m templates before and after the current d d m template in the ordered set where language = &#63;.
2822             *
2823             * <p>
2824             * 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.
2825             * </p>
2826             *
2827             * @param templateId the primary key of the current d d m template
2828             * @param language the language
2829             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2830             * @return the previous, current, and next d d m template
2831             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
2832             * @throws SystemException if a system exception occurred
2833             */
2834            public DDMTemplate[] findByLanguage_PrevAndNext(long templateId,
2835                    String language, OrderByComparator orderByComparator)
2836                    throws NoSuchTemplateException, SystemException {
2837                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
2838    
2839                    Session session = null;
2840    
2841                    try {
2842                            session = openSession();
2843    
2844                            DDMTemplate[] array = new DDMTemplateImpl[3];
2845    
2846                            array[0] = getByLanguage_PrevAndNext(session, ddmTemplate,
2847                                            language, orderByComparator, true);
2848    
2849                            array[1] = ddmTemplate;
2850    
2851                            array[2] = getByLanguage_PrevAndNext(session, ddmTemplate,
2852                                            language, orderByComparator, false);
2853    
2854                            return array;
2855                    }
2856                    catch (Exception e) {
2857                            throw processException(e);
2858                    }
2859                    finally {
2860                            closeSession(session);
2861                    }
2862            }
2863    
2864            protected DDMTemplate getByLanguage_PrevAndNext(Session session,
2865                    DDMTemplate ddmTemplate, String language,
2866                    OrderByComparator orderByComparator, boolean previous) {
2867                    StringBundler query = null;
2868    
2869                    if (orderByComparator != null) {
2870                            query = new StringBundler(6 +
2871                                            (orderByComparator.getOrderByFields().length * 6));
2872                    }
2873                    else {
2874                            query = new StringBundler(3);
2875                    }
2876    
2877                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
2878    
2879                    if (language == null) {
2880                            query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_1);
2881                    }
2882                    else {
2883                            if (language.equals(StringPool.BLANK)) {
2884                                    query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_3);
2885                            }
2886                            else {
2887                                    query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_2);
2888                            }
2889                    }
2890    
2891                    if (orderByComparator != null) {
2892                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2893    
2894                            if (orderByConditionFields.length > 0) {
2895                                    query.append(WHERE_AND);
2896                            }
2897    
2898                            for (int i = 0; i < orderByConditionFields.length; i++) {
2899                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2900                                    query.append(orderByConditionFields[i]);
2901    
2902                                    if ((i + 1) < orderByConditionFields.length) {
2903                                            if (orderByComparator.isAscending() ^ previous) {
2904                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2905                                            }
2906                                            else {
2907                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2908                                            }
2909                                    }
2910                                    else {
2911                                            if (orderByComparator.isAscending() ^ previous) {
2912                                                    query.append(WHERE_GREATER_THAN);
2913                                            }
2914                                            else {
2915                                                    query.append(WHERE_LESSER_THAN);
2916                                            }
2917                                    }
2918                            }
2919    
2920                            query.append(ORDER_BY_CLAUSE);
2921    
2922                            String[] orderByFields = orderByComparator.getOrderByFields();
2923    
2924                            for (int i = 0; i < orderByFields.length; i++) {
2925                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2926                                    query.append(orderByFields[i]);
2927    
2928                                    if ((i + 1) < orderByFields.length) {
2929                                            if (orderByComparator.isAscending() ^ previous) {
2930                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2931                                            }
2932                                            else {
2933                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2934                                            }
2935                                    }
2936                                    else {
2937                                            if (orderByComparator.isAscending() ^ previous) {
2938                                                    query.append(ORDER_BY_ASC);
2939                                            }
2940                                            else {
2941                                                    query.append(ORDER_BY_DESC);
2942                                            }
2943                                    }
2944                            }
2945                    }
2946    
2947                    String sql = query.toString();
2948    
2949                    Query q = session.createQuery(sql);
2950    
2951                    q.setFirstResult(0);
2952                    q.setMaxResults(2);
2953    
2954                    QueryPos qPos = QueryPos.getInstance(q);
2955    
2956                    if (language != null) {
2957                            qPos.add(language);
2958                    }
2959    
2960                    if (orderByComparator != null) {
2961                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
2962    
2963                            for (Object value : values) {
2964                                    qPos.add(value);
2965                            }
2966                    }
2967    
2968                    List<DDMTemplate> list = q.list();
2969    
2970                    if (list.size() == 2) {
2971                            return list.get(1);
2972                    }
2973                    else {
2974                            return null;
2975                    }
2976            }
2977    
2978            /**
2979             * Returns all the d d m templates where structureId = &#63; and type = &#63;.
2980             *
2981             * @param structureId the structure ID
2982             * @param type the type
2983             * @return the matching d d m templates
2984             * @throws SystemException if a system exception occurred
2985             */
2986            public List<DDMTemplate> findByS_T(long structureId, String type)
2987                    throws SystemException {
2988                    return findByS_T(structureId, type, QueryUtil.ALL_POS,
2989                            QueryUtil.ALL_POS, null);
2990            }
2991    
2992            /**
2993             * Returns a range of all the d d m templates where structureId = &#63; and type = &#63;.
2994             *
2995             * <p>
2996             * 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.
2997             * </p>
2998             *
2999             * @param structureId the structure ID
3000             * @param type the type
3001             * @param start the lower bound of the range of d d m templates
3002             * @param end the upper bound of the range of d d m templates (not inclusive)
3003             * @return the range of matching d d m templates
3004             * @throws SystemException if a system exception occurred
3005             */
3006            public List<DDMTemplate> findByS_T(long structureId, String type,
3007                    int start, int end) throws SystemException {
3008                    return findByS_T(structureId, type, start, end, null);
3009            }
3010    
3011            /**
3012             * Returns an ordered range of all the d d m templates where structureId = &#63; and type = &#63;.
3013             *
3014             * <p>
3015             * 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.
3016             * </p>
3017             *
3018             * @param structureId the structure ID
3019             * @param type the type
3020             * @param start the lower bound of the range of d d m templates
3021             * @param end the upper bound of the range of d d m templates (not inclusive)
3022             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3023             * @return the ordered range of matching d d m templates
3024             * @throws SystemException if a system exception occurred
3025             */
3026            public List<DDMTemplate> findByS_T(long structureId, String type,
3027                    int start, int end, OrderByComparator orderByComparator)
3028                    throws SystemException {
3029                    FinderPath finderPath = null;
3030                    Object[] finderArgs = null;
3031    
3032                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3033                                    (orderByComparator == null)) {
3034                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_S_T;
3035                            finderArgs = new Object[] { structureId, type };
3036                    }
3037                    else {
3038                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_S_T;
3039                            finderArgs = new Object[] {
3040                                            structureId, type,
3041                                            
3042                                            start, end, orderByComparator
3043                                    };
3044                    }
3045    
3046                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
3047                                    finderArgs, this);
3048    
3049                    if (list == null) {
3050                            StringBundler query = null;
3051    
3052                            if (orderByComparator != null) {
3053                                    query = new StringBundler(4 +
3054                                                    (orderByComparator.getOrderByFields().length * 3));
3055                            }
3056                            else {
3057                                    query = new StringBundler(3);
3058                            }
3059    
3060                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
3061    
3062                            query.append(_FINDER_COLUMN_S_T_STRUCTUREID_2);
3063    
3064                            if (type == null) {
3065                                    query.append(_FINDER_COLUMN_S_T_TYPE_1);
3066                            }
3067                            else {
3068                                    if (type.equals(StringPool.BLANK)) {
3069                                            query.append(_FINDER_COLUMN_S_T_TYPE_3);
3070                                    }
3071                                    else {
3072                                            query.append(_FINDER_COLUMN_S_T_TYPE_2);
3073                                    }
3074                            }
3075    
3076                            if (orderByComparator != null) {
3077                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3078                                            orderByComparator);
3079                            }
3080    
3081                            String sql = query.toString();
3082    
3083                            Session session = null;
3084    
3085                            try {
3086                                    session = openSession();
3087    
3088                                    Query q = session.createQuery(sql);
3089    
3090                                    QueryPos qPos = QueryPos.getInstance(q);
3091    
3092                                    qPos.add(structureId);
3093    
3094                                    if (type != null) {
3095                                            qPos.add(type);
3096                                    }
3097    
3098                                    list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
3099                                                    start, end);
3100                            }
3101                            catch (Exception e) {
3102                                    throw processException(e);
3103                            }
3104                            finally {
3105                                    if (list == null) {
3106                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3107                                    }
3108                                    else {
3109                                            cacheResult(list);
3110    
3111                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3112                                    }
3113    
3114                                    closeSession(session);
3115                            }
3116                    }
3117    
3118                    return list;
3119            }
3120    
3121            /**
3122             * Returns the first d d m template in the ordered set where structureId = &#63; and type = &#63;.
3123             *
3124             * <p>
3125             * 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.
3126             * </p>
3127             *
3128             * @param structureId the structure ID
3129             * @param type the type
3130             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3131             * @return the first matching d d m template
3132             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
3133             * @throws SystemException if a system exception occurred
3134             */
3135            public DDMTemplate findByS_T_First(long structureId, String type,
3136                    OrderByComparator orderByComparator)
3137                    throws NoSuchTemplateException, SystemException {
3138                    List<DDMTemplate> list = findByS_T(structureId, type, 0, 1,
3139                                    orderByComparator);
3140    
3141                    if (list.isEmpty()) {
3142                            StringBundler msg = new StringBundler(6);
3143    
3144                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3145    
3146                            msg.append("structureId=");
3147                            msg.append(structureId);
3148    
3149                            msg.append(", type=");
3150                            msg.append(type);
3151    
3152                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3153    
3154                            throw new NoSuchTemplateException(msg.toString());
3155                    }
3156                    else {
3157                            return list.get(0);
3158                    }
3159            }
3160    
3161            /**
3162             * Returns the last d d m template in the ordered set where structureId = &#63; and type = &#63;.
3163             *
3164             * <p>
3165             * 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.
3166             * </p>
3167             *
3168             * @param structureId the structure ID
3169             * @param type the type
3170             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3171             * @return the last matching d d m template
3172             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
3173             * @throws SystemException if a system exception occurred
3174             */
3175            public DDMTemplate findByS_T_Last(long structureId, String type,
3176                    OrderByComparator orderByComparator)
3177                    throws NoSuchTemplateException, SystemException {
3178                    int count = countByS_T(structureId, type);
3179    
3180                    List<DDMTemplate> list = findByS_T(structureId, type, count - 1, count,
3181                                    orderByComparator);
3182    
3183                    if (list.isEmpty()) {
3184                            StringBundler msg = new StringBundler(6);
3185    
3186                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3187    
3188                            msg.append("structureId=");
3189                            msg.append(structureId);
3190    
3191                            msg.append(", type=");
3192                            msg.append(type);
3193    
3194                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3195    
3196                            throw new NoSuchTemplateException(msg.toString());
3197                    }
3198                    else {
3199                            return list.get(0);
3200                    }
3201            }
3202    
3203            /**
3204             * Returns the d d m templates before and after the current d d m template in the ordered set where structureId = &#63; and type = &#63;.
3205             *
3206             * <p>
3207             * 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.
3208             * </p>
3209             *
3210             * @param templateId the primary key of the current d d m template
3211             * @param structureId the structure ID
3212             * @param type the type
3213             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3214             * @return the previous, current, and next d d m template
3215             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
3216             * @throws SystemException if a system exception occurred
3217             */
3218            public DDMTemplate[] findByS_T_PrevAndNext(long templateId,
3219                    long structureId, String type, OrderByComparator orderByComparator)
3220                    throws NoSuchTemplateException, SystemException {
3221                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
3222    
3223                    Session session = null;
3224    
3225                    try {
3226                            session = openSession();
3227    
3228                            DDMTemplate[] array = new DDMTemplateImpl[3];
3229    
3230                            array[0] = getByS_T_PrevAndNext(session, ddmTemplate, structureId,
3231                                            type, orderByComparator, true);
3232    
3233                            array[1] = ddmTemplate;
3234    
3235                            array[2] = getByS_T_PrevAndNext(session, ddmTemplate, structureId,
3236                                            type, orderByComparator, false);
3237    
3238                            return array;
3239                    }
3240                    catch (Exception e) {
3241                            throw processException(e);
3242                    }
3243                    finally {
3244                            closeSession(session);
3245                    }
3246            }
3247    
3248            protected DDMTemplate getByS_T_PrevAndNext(Session session,
3249                    DDMTemplate ddmTemplate, long structureId, String type,
3250                    OrderByComparator orderByComparator, boolean previous) {
3251                    StringBundler query = null;
3252    
3253                    if (orderByComparator != null) {
3254                            query = new StringBundler(6 +
3255                                            (orderByComparator.getOrderByFields().length * 6));
3256                    }
3257                    else {
3258                            query = new StringBundler(3);
3259                    }
3260    
3261                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
3262    
3263                    query.append(_FINDER_COLUMN_S_T_STRUCTUREID_2);
3264    
3265                    if (type == null) {
3266                            query.append(_FINDER_COLUMN_S_T_TYPE_1);
3267                    }
3268                    else {
3269                            if (type.equals(StringPool.BLANK)) {
3270                                    query.append(_FINDER_COLUMN_S_T_TYPE_3);
3271                            }
3272                            else {
3273                                    query.append(_FINDER_COLUMN_S_T_TYPE_2);
3274                            }
3275                    }
3276    
3277                    if (orderByComparator != null) {
3278                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3279    
3280                            if (orderByConditionFields.length > 0) {
3281                                    query.append(WHERE_AND);
3282                            }
3283    
3284                            for (int i = 0; i < orderByConditionFields.length; i++) {
3285                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3286                                    query.append(orderByConditionFields[i]);
3287    
3288                                    if ((i + 1) < orderByConditionFields.length) {
3289                                            if (orderByComparator.isAscending() ^ previous) {
3290                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3291                                            }
3292                                            else {
3293                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3294                                            }
3295                                    }
3296                                    else {
3297                                            if (orderByComparator.isAscending() ^ previous) {
3298                                                    query.append(WHERE_GREATER_THAN);
3299                                            }
3300                                            else {
3301                                                    query.append(WHERE_LESSER_THAN);
3302                                            }
3303                                    }
3304                            }
3305    
3306                            query.append(ORDER_BY_CLAUSE);
3307    
3308                            String[] orderByFields = orderByComparator.getOrderByFields();
3309    
3310                            for (int i = 0; i < orderByFields.length; i++) {
3311                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3312                                    query.append(orderByFields[i]);
3313    
3314                                    if ((i + 1) < orderByFields.length) {
3315                                            if (orderByComparator.isAscending() ^ previous) {
3316                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3317                                            }
3318                                            else {
3319                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3320                                            }
3321                                    }
3322                                    else {
3323                                            if (orderByComparator.isAscending() ^ previous) {
3324                                                    query.append(ORDER_BY_ASC);
3325                                            }
3326                                            else {
3327                                                    query.append(ORDER_BY_DESC);
3328                                            }
3329                                    }
3330                            }
3331                    }
3332    
3333                    String sql = query.toString();
3334    
3335                    Query q = session.createQuery(sql);
3336    
3337                    q.setFirstResult(0);
3338                    q.setMaxResults(2);
3339    
3340                    QueryPos qPos = QueryPos.getInstance(q);
3341    
3342                    qPos.add(structureId);
3343    
3344                    if (type != null) {
3345                            qPos.add(type);
3346                    }
3347    
3348                    if (orderByComparator != null) {
3349                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
3350    
3351                            for (Object value : values) {
3352                                    qPos.add(value);
3353                            }
3354                    }
3355    
3356                    List<DDMTemplate> list = q.list();
3357    
3358                    if (list.size() == 2) {
3359                            return list.get(1);
3360                    }
3361                    else {
3362                            return null;
3363                    }
3364            }
3365    
3366            /**
3367             * Returns all the d d m templates where structureId = &#63; and type = &#63; and mode = &#63;.
3368             *
3369             * @param structureId the structure ID
3370             * @param type the type
3371             * @param mode the mode
3372             * @return the matching d d m templates
3373             * @throws SystemException if a system exception occurred
3374             */
3375            public List<DDMTemplate> findByS_T_M(long structureId, String type,
3376                    String mode) throws SystemException {
3377                    return findByS_T_M(structureId, type, mode, QueryUtil.ALL_POS,
3378                            QueryUtil.ALL_POS, null);
3379            }
3380    
3381            /**
3382             * Returns a range of all the d d m templates where structureId = &#63; and type = &#63; and mode = &#63;.
3383             *
3384             * <p>
3385             * 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.
3386             * </p>
3387             *
3388             * @param structureId the structure ID
3389             * @param type the type
3390             * @param mode the mode
3391             * @param start the lower bound of the range of d d m templates
3392             * @param end the upper bound of the range of d d m templates (not inclusive)
3393             * @return the range of matching d d m templates
3394             * @throws SystemException if a system exception occurred
3395             */
3396            public List<DDMTemplate> findByS_T_M(long structureId, String type,
3397                    String mode, int start, int end) throws SystemException {
3398                    return findByS_T_M(structureId, type, mode, start, end, null);
3399            }
3400    
3401            /**
3402             * Returns an ordered range of all the d d m templates where structureId = &#63; and type = &#63; and mode = &#63;.
3403             *
3404             * <p>
3405             * 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.
3406             * </p>
3407             *
3408             * @param structureId the structure ID
3409             * @param type the type
3410             * @param mode the mode
3411             * @param start the lower bound of the range of d d m templates
3412             * @param end the upper bound of the range of d d m templates (not inclusive)
3413             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3414             * @return the ordered range of matching d d m templates
3415             * @throws SystemException if a system exception occurred
3416             */
3417            public List<DDMTemplate> findByS_T_M(long structureId, String type,
3418                    String mode, int start, int end, OrderByComparator orderByComparator)
3419                    throws SystemException {
3420                    FinderPath finderPath = null;
3421                    Object[] finderArgs = null;
3422    
3423                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3424                                    (orderByComparator == null)) {
3425                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_S_T_M;
3426                            finderArgs = new Object[] { structureId, type, mode };
3427                    }
3428                    else {
3429                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_S_T_M;
3430                            finderArgs = new Object[] {
3431                                            structureId, type, mode,
3432                                            
3433                                            start, end, orderByComparator
3434                                    };
3435                    }
3436    
3437                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
3438                                    finderArgs, this);
3439    
3440                    if (list == null) {
3441                            StringBundler query = null;
3442    
3443                            if (orderByComparator != null) {
3444                                    query = new StringBundler(5 +
3445                                                    (orderByComparator.getOrderByFields().length * 3));
3446                            }
3447                            else {
3448                                    query = new StringBundler(4);
3449                            }
3450    
3451                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
3452    
3453                            query.append(_FINDER_COLUMN_S_T_M_STRUCTUREID_2);
3454    
3455                            if (type == null) {
3456                                    query.append(_FINDER_COLUMN_S_T_M_TYPE_1);
3457                            }
3458                            else {
3459                                    if (type.equals(StringPool.BLANK)) {
3460                                            query.append(_FINDER_COLUMN_S_T_M_TYPE_3);
3461                                    }
3462                                    else {
3463                                            query.append(_FINDER_COLUMN_S_T_M_TYPE_2);
3464                                    }
3465                            }
3466    
3467                            if (mode == null) {
3468                                    query.append(_FINDER_COLUMN_S_T_M_MODE_1);
3469                            }
3470                            else {
3471                                    if (mode.equals(StringPool.BLANK)) {
3472                                            query.append(_FINDER_COLUMN_S_T_M_MODE_3);
3473                                    }
3474                                    else {
3475                                            query.append(_FINDER_COLUMN_S_T_M_MODE_2);
3476                                    }
3477                            }
3478    
3479                            if (orderByComparator != null) {
3480                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3481                                            orderByComparator);
3482                            }
3483    
3484                            String sql = query.toString();
3485    
3486                            Session session = null;
3487    
3488                            try {
3489                                    session = openSession();
3490    
3491                                    Query q = session.createQuery(sql);
3492    
3493                                    QueryPos qPos = QueryPos.getInstance(q);
3494    
3495                                    qPos.add(structureId);
3496    
3497                                    if (type != null) {
3498                                            qPos.add(type);
3499                                    }
3500    
3501                                    if (mode != null) {
3502                                            qPos.add(mode);
3503                                    }
3504    
3505                                    list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
3506                                                    start, end);
3507                            }
3508                            catch (Exception e) {
3509                                    throw processException(e);
3510                            }
3511                            finally {
3512                                    if (list == null) {
3513                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3514                                    }
3515                                    else {
3516                                            cacheResult(list);
3517    
3518                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3519                                    }
3520    
3521                                    closeSession(session);
3522                            }
3523                    }
3524    
3525                    return list;
3526            }
3527    
3528            /**
3529             * Returns the first d d m template in the ordered set where structureId = &#63; and type = &#63; and mode = &#63;.
3530             *
3531             * <p>
3532             * 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.
3533             * </p>
3534             *
3535             * @param structureId the structure ID
3536             * @param type the type
3537             * @param mode the mode
3538             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3539             * @return the first matching d d m template
3540             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
3541             * @throws SystemException if a system exception occurred
3542             */
3543            public DDMTemplate findByS_T_M_First(long structureId, String type,
3544                    String mode, OrderByComparator orderByComparator)
3545                    throws NoSuchTemplateException, SystemException {
3546                    List<DDMTemplate> list = findByS_T_M(structureId, type, mode, 0, 1,
3547                                    orderByComparator);
3548    
3549                    if (list.isEmpty()) {
3550                            StringBundler msg = new StringBundler(8);
3551    
3552                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3553    
3554                            msg.append("structureId=");
3555                            msg.append(structureId);
3556    
3557                            msg.append(", type=");
3558                            msg.append(type);
3559    
3560                            msg.append(", mode=");
3561                            msg.append(mode);
3562    
3563                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3564    
3565                            throw new NoSuchTemplateException(msg.toString());
3566                    }
3567                    else {
3568                            return list.get(0);
3569                    }
3570            }
3571    
3572            /**
3573             * Returns the last d d m template in the ordered set where structureId = &#63; and type = &#63; and mode = &#63;.
3574             *
3575             * <p>
3576             * 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.
3577             * </p>
3578             *
3579             * @param structureId the structure ID
3580             * @param type the type
3581             * @param mode the mode
3582             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3583             * @return the last matching d d m template
3584             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
3585             * @throws SystemException if a system exception occurred
3586             */
3587            public DDMTemplate findByS_T_M_Last(long structureId, String type,
3588                    String mode, OrderByComparator orderByComparator)
3589                    throws NoSuchTemplateException, SystemException {
3590                    int count = countByS_T_M(structureId, type, mode);
3591    
3592                    List<DDMTemplate> list = findByS_T_M(structureId, type, mode,
3593                                    count - 1, count, orderByComparator);
3594    
3595                    if (list.isEmpty()) {
3596                            StringBundler msg = new StringBundler(8);
3597    
3598                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3599    
3600                            msg.append("structureId=");
3601                            msg.append(structureId);
3602    
3603                            msg.append(", type=");
3604                            msg.append(type);
3605    
3606                            msg.append(", mode=");
3607                            msg.append(mode);
3608    
3609                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3610    
3611                            throw new NoSuchTemplateException(msg.toString());
3612                    }
3613                    else {
3614                            return list.get(0);
3615                    }
3616            }
3617    
3618            /**
3619             * Returns the d d m templates before and after the current d d m template in the ordered set where structureId = &#63; and type = &#63; and mode = &#63;.
3620             *
3621             * <p>
3622             * 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.
3623             * </p>
3624             *
3625             * @param templateId the primary key of the current d d m template
3626             * @param structureId the structure ID
3627             * @param type the type
3628             * @param mode the mode
3629             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3630             * @return the previous, current, and next d d m template
3631             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
3632             * @throws SystemException if a system exception occurred
3633             */
3634            public DDMTemplate[] findByS_T_M_PrevAndNext(long templateId,
3635                    long structureId, String type, String mode,
3636                    OrderByComparator orderByComparator)
3637                    throws NoSuchTemplateException, SystemException {
3638                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
3639    
3640                    Session session = null;
3641    
3642                    try {
3643                            session = openSession();
3644    
3645                            DDMTemplate[] array = new DDMTemplateImpl[3];
3646    
3647                            array[0] = getByS_T_M_PrevAndNext(session, ddmTemplate,
3648                                            structureId, type, mode, orderByComparator, true);
3649    
3650                            array[1] = ddmTemplate;
3651    
3652                            array[2] = getByS_T_M_PrevAndNext(session, ddmTemplate,
3653                                            structureId, type, mode, orderByComparator, false);
3654    
3655                            return array;
3656                    }
3657                    catch (Exception e) {
3658                            throw processException(e);
3659                    }
3660                    finally {
3661                            closeSession(session);
3662                    }
3663            }
3664    
3665            protected DDMTemplate getByS_T_M_PrevAndNext(Session session,
3666                    DDMTemplate ddmTemplate, long structureId, String type, String mode,
3667                    OrderByComparator orderByComparator, boolean previous) {
3668                    StringBundler query = null;
3669    
3670                    if (orderByComparator != null) {
3671                            query = new StringBundler(6 +
3672                                            (orderByComparator.getOrderByFields().length * 6));
3673                    }
3674                    else {
3675                            query = new StringBundler(3);
3676                    }
3677    
3678                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
3679    
3680                    query.append(_FINDER_COLUMN_S_T_M_STRUCTUREID_2);
3681    
3682                    if (type == null) {
3683                            query.append(_FINDER_COLUMN_S_T_M_TYPE_1);
3684                    }
3685                    else {
3686                            if (type.equals(StringPool.BLANK)) {
3687                                    query.append(_FINDER_COLUMN_S_T_M_TYPE_3);
3688                            }
3689                            else {
3690                                    query.append(_FINDER_COLUMN_S_T_M_TYPE_2);
3691                            }
3692                    }
3693    
3694                    if (mode == null) {
3695                            query.append(_FINDER_COLUMN_S_T_M_MODE_1);
3696                    }
3697                    else {
3698                            if (mode.equals(StringPool.BLANK)) {
3699                                    query.append(_FINDER_COLUMN_S_T_M_MODE_3);
3700                            }
3701                            else {
3702                                    query.append(_FINDER_COLUMN_S_T_M_MODE_2);
3703                            }
3704                    }
3705    
3706                    if (orderByComparator != null) {
3707                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3708    
3709                            if (orderByConditionFields.length > 0) {
3710                                    query.append(WHERE_AND);
3711                            }
3712    
3713                            for (int i = 0; i < orderByConditionFields.length; i++) {
3714                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3715                                    query.append(orderByConditionFields[i]);
3716    
3717                                    if ((i + 1) < orderByConditionFields.length) {
3718                                            if (orderByComparator.isAscending() ^ previous) {
3719                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3720                                            }
3721                                            else {
3722                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3723                                            }
3724                                    }
3725                                    else {
3726                                            if (orderByComparator.isAscending() ^ previous) {
3727                                                    query.append(WHERE_GREATER_THAN);
3728                                            }
3729                                            else {
3730                                                    query.append(WHERE_LESSER_THAN);
3731                                            }
3732                                    }
3733                            }
3734    
3735                            query.append(ORDER_BY_CLAUSE);
3736    
3737                            String[] orderByFields = orderByComparator.getOrderByFields();
3738    
3739                            for (int i = 0; i < orderByFields.length; i++) {
3740                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3741                                    query.append(orderByFields[i]);
3742    
3743                                    if ((i + 1) < orderByFields.length) {
3744                                            if (orderByComparator.isAscending() ^ previous) {
3745                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3746                                            }
3747                                            else {
3748                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3749                                            }
3750                                    }
3751                                    else {
3752                                            if (orderByComparator.isAscending() ^ previous) {
3753                                                    query.append(ORDER_BY_ASC);
3754                                            }
3755                                            else {
3756                                                    query.append(ORDER_BY_DESC);
3757                                            }
3758                                    }
3759                            }
3760                    }
3761    
3762                    String sql = query.toString();
3763    
3764                    Query q = session.createQuery(sql);
3765    
3766                    q.setFirstResult(0);
3767                    q.setMaxResults(2);
3768    
3769                    QueryPos qPos = QueryPos.getInstance(q);
3770    
3771                    qPos.add(structureId);
3772    
3773                    if (type != null) {
3774                            qPos.add(type);
3775                    }
3776    
3777                    if (mode != null) {
3778                            qPos.add(mode);
3779                    }
3780    
3781                    if (orderByComparator != null) {
3782                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
3783    
3784                            for (Object value : values) {
3785                                    qPos.add(value);
3786                            }
3787                    }
3788    
3789                    List<DDMTemplate> list = q.list();
3790    
3791                    if (list.size() == 2) {
3792                            return list.get(1);
3793                    }
3794                    else {
3795                            return null;
3796                    }
3797            }
3798    
3799            /**
3800             * Returns all the d d m templates.
3801             *
3802             * @return the d d m templates
3803             * @throws SystemException if a system exception occurred
3804             */
3805            public List<DDMTemplate> findAll() throws SystemException {
3806                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3807            }
3808    
3809            /**
3810             * Returns a range of all the d d m templates.
3811             *
3812             * <p>
3813             * 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.
3814             * </p>
3815             *
3816             * @param start the lower bound of the range of d d m templates
3817             * @param end the upper bound of the range of d d m templates (not inclusive)
3818             * @return the range of d d m templates
3819             * @throws SystemException if a system exception occurred
3820             */
3821            public List<DDMTemplate> findAll(int start, int end)
3822                    throws SystemException {
3823                    return findAll(start, end, null);
3824            }
3825    
3826            /**
3827             * Returns an ordered range of all the d d m templates.
3828             *
3829             * <p>
3830             * 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.
3831             * </p>
3832             *
3833             * @param start the lower bound of the range of d d m templates
3834             * @param end the upper bound of the range of d d m templates (not inclusive)
3835             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3836             * @return the ordered range of d d m templates
3837             * @throws SystemException if a system exception occurred
3838             */
3839            public List<DDMTemplate> findAll(int start, int end,
3840                    OrderByComparator orderByComparator) throws SystemException {
3841                    FinderPath finderPath = null;
3842                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
3843    
3844                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3845                                    (orderByComparator == null)) {
3846                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3847                            finderArgs = FINDER_ARGS_EMPTY;
3848                    }
3849                    else {
3850                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3851                            finderArgs = new Object[] { start, end, orderByComparator };
3852                    }
3853    
3854                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
3855                                    finderArgs, this);
3856    
3857                    if (list == null) {
3858                            StringBundler query = null;
3859                            String sql = null;
3860    
3861                            if (orderByComparator != null) {
3862                                    query = new StringBundler(2 +
3863                                                    (orderByComparator.getOrderByFields().length * 3));
3864    
3865                                    query.append(_SQL_SELECT_DDMTEMPLATE);
3866    
3867                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3868                                            orderByComparator);
3869    
3870                                    sql = query.toString();
3871                            }
3872                            else {
3873                                    sql = _SQL_SELECT_DDMTEMPLATE;
3874                            }
3875    
3876                            Session session = null;
3877    
3878                            try {
3879                                    session = openSession();
3880    
3881                                    Query q = session.createQuery(sql);
3882    
3883                                    if (orderByComparator == null) {
3884                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
3885                                                            start, end, false);
3886    
3887                                            Collections.sort(list);
3888                                    }
3889                                    else {
3890                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
3891                                                            start, end);
3892                                    }
3893                            }
3894                            catch (Exception e) {
3895                                    throw processException(e);
3896                            }
3897                            finally {
3898                                    if (list == null) {
3899                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3900                                    }
3901                                    else {
3902                                            cacheResult(list);
3903    
3904                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3905                                    }
3906    
3907                                    closeSession(session);
3908                            }
3909                    }
3910    
3911                    return list;
3912            }
3913    
3914            /**
3915             * Removes all the d d m templates where uuid = &#63; from the database.
3916             *
3917             * @param uuid the uuid
3918             * @throws SystemException if a system exception occurred
3919             */
3920            public void removeByUuid(String uuid) throws SystemException {
3921                    for (DDMTemplate ddmTemplate : findByUuid(uuid)) {
3922                            remove(ddmTemplate);
3923                    }
3924            }
3925    
3926            /**
3927             * Removes the d d m template where uuid = &#63; and groupId = &#63; from the database.
3928             *
3929             * @param uuid the uuid
3930             * @param groupId the group ID
3931             * @throws SystemException if a system exception occurred
3932             */
3933            public void removeByUUID_G(String uuid, long groupId)
3934                    throws NoSuchTemplateException, SystemException {
3935                    DDMTemplate ddmTemplate = findByUUID_G(uuid, groupId);
3936    
3937                    remove(ddmTemplate);
3938            }
3939    
3940            /**
3941             * Removes all the d d m templates where groupId = &#63; from the database.
3942             *
3943             * @param groupId the group ID
3944             * @throws SystemException if a system exception occurred
3945             */
3946            public void removeByGroupId(long groupId) throws SystemException {
3947                    for (DDMTemplate ddmTemplate : findByGroupId(groupId)) {
3948                            remove(ddmTemplate);
3949                    }
3950            }
3951    
3952            /**
3953             * Removes all the d d m templates where structureId = &#63; from the database.
3954             *
3955             * @param structureId the structure ID
3956             * @throws SystemException if a system exception occurred
3957             */
3958            public void removeByStructureId(long structureId) throws SystemException {
3959                    for (DDMTemplate ddmTemplate : findByStructureId(structureId)) {
3960                            remove(ddmTemplate);
3961                    }
3962            }
3963    
3964            /**
3965             * Removes all the d d m templates where type = &#63; from the database.
3966             *
3967             * @param type the type
3968             * @throws SystemException if a system exception occurred
3969             */
3970            public void removeByType(String type) throws SystemException {
3971                    for (DDMTemplate ddmTemplate : findByType(type)) {
3972                            remove(ddmTemplate);
3973                    }
3974            }
3975    
3976            /**
3977             * Removes all the d d m templates where language = &#63; from the database.
3978             *
3979             * @param language the language
3980             * @throws SystemException if a system exception occurred
3981             */
3982            public void removeByLanguage(String language) throws SystemException {
3983                    for (DDMTemplate ddmTemplate : findByLanguage(language)) {
3984                            remove(ddmTemplate);
3985                    }
3986            }
3987    
3988            /**
3989             * Removes all the d d m templates where structureId = &#63; and type = &#63; from the database.
3990             *
3991             * @param structureId the structure ID
3992             * @param type the type
3993             * @throws SystemException if a system exception occurred
3994             */
3995            public void removeByS_T(long structureId, String type)
3996                    throws SystemException {
3997                    for (DDMTemplate ddmTemplate : findByS_T(structureId, type)) {
3998                            remove(ddmTemplate);
3999                    }
4000            }
4001    
4002            /**
4003             * Removes all the d d m templates where structureId = &#63; and type = &#63; and mode = &#63; from the database.
4004             *
4005             * @param structureId the structure ID
4006             * @param type the type
4007             * @param mode the mode
4008             * @throws SystemException if a system exception occurred
4009             */
4010            public void removeByS_T_M(long structureId, String type, String mode)
4011                    throws SystemException {
4012                    for (DDMTemplate ddmTemplate : findByS_T_M(structureId, type, mode)) {
4013                            remove(ddmTemplate);
4014                    }
4015            }
4016    
4017            /**
4018             * Removes all the d d m templates from the database.
4019             *
4020             * @throws SystemException if a system exception occurred
4021             */
4022            public void removeAll() throws SystemException {
4023                    for (DDMTemplate ddmTemplate : findAll()) {
4024                            remove(ddmTemplate);
4025                    }
4026            }
4027    
4028            /**
4029             * Returns the number of d d m templates where uuid = &#63;.
4030             *
4031             * @param uuid the uuid
4032             * @return the number of matching d d m templates
4033             * @throws SystemException if a system exception occurred
4034             */
4035            public int countByUuid(String uuid) throws SystemException {
4036                    Object[] finderArgs = new Object[] { uuid };
4037    
4038                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
4039                                    finderArgs, this);
4040    
4041                    if (count == null) {
4042                            StringBundler query = new StringBundler(2);
4043    
4044                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
4045    
4046                            if (uuid == null) {
4047                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
4048                            }
4049                            else {
4050                                    if (uuid.equals(StringPool.BLANK)) {
4051                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
4052                                    }
4053                                    else {
4054                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
4055                                    }
4056                            }
4057    
4058                            String sql = query.toString();
4059    
4060                            Session session = null;
4061    
4062                            try {
4063                                    session = openSession();
4064    
4065                                    Query q = session.createQuery(sql);
4066    
4067                                    QueryPos qPos = QueryPos.getInstance(q);
4068    
4069                                    if (uuid != null) {
4070                                            qPos.add(uuid);
4071                                    }
4072    
4073                                    count = (Long)q.uniqueResult();
4074                            }
4075                            catch (Exception e) {
4076                                    throw processException(e);
4077                            }
4078                            finally {
4079                                    if (count == null) {
4080                                            count = Long.valueOf(0);
4081                                    }
4082    
4083                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
4084                                            finderArgs, count);
4085    
4086                                    closeSession(session);
4087                            }
4088                    }
4089    
4090                    return count.intValue();
4091            }
4092    
4093            /**
4094             * Returns the number of d d m templates where uuid = &#63; and groupId = &#63;.
4095             *
4096             * @param uuid the uuid
4097             * @param groupId the group ID
4098             * @return the number of matching d d m templates
4099             * @throws SystemException if a system exception occurred
4100             */
4101            public int countByUUID_G(String uuid, long groupId)
4102                    throws SystemException {
4103                    Object[] finderArgs = new Object[] { uuid, groupId };
4104    
4105                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
4106                                    finderArgs, this);
4107    
4108                    if (count == null) {
4109                            StringBundler query = new StringBundler(3);
4110    
4111                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
4112    
4113                            if (uuid == null) {
4114                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
4115                            }
4116                            else {
4117                                    if (uuid.equals(StringPool.BLANK)) {
4118                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
4119                                    }
4120                                    else {
4121                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
4122                                    }
4123                            }
4124    
4125                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
4126    
4127                            String sql = query.toString();
4128    
4129                            Session session = null;
4130    
4131                            try {
4132                                    session = openSession();
4133    
4134                                    Query q = session.createQuery(sql);
4135    
4136                                    QueryPos qPos = QueryPos.getInstance(q);
4137    
4138                                    if (uuid != null) {
4139                                            qPos.add(uuid);
4140                                    }
4141    
4142                                    qPos.add(groupId);
4143    
4144                                    count = (Long)q.uniqueResult();
4145                            }
4146                            catch (Exception e) {
4147                                    throw processException(e);
4148                            }
4149                            finally {
4150                                    if (count == null) {
4151                                            count = Long.valueOf(0);
4152                                    }
4153    
4154                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
4155                                            finderArgs, count);
4156    
4157                                    closeSession(session);
4158                            }
4159                    }
4160    
4161                    return count.intValue();
4162            }
4163    
4164            /**
4165             * Returns the number of d d m templates where groupId = &#63;.
4166             *
4167             * @param groupId the group ID
4168             * @return the number of matching d d m templates
4169             * @throws SystemException if a system exception occurred
4170             */
4171            public int countByGroupId(long groupId) throws SystemException {
4172                    Object[] finderArgs = new Object[] { groupId };
4173    
4174                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
4175                                    finderArgs, this);
4176    
4177                    if (count == null) {
4178                            StringBundler query = new StringBundler(2);
4179    
4180                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
4181    
4182                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
4183    
4184                            String sql = query.toString();
4185    
4186                            Session session = null;
4187    
4188                            try {
4189                                    session = openSession();
4190    
4191                                    Query q = session.createQuery(sql);
4192    
4193                                    QueryPos qPos = QueryPos.getInstance(q);
4194    
4195                                    qPos.add(groupId);
4196    
4197                                    count = (Long)q.uniqueResult();
4198                            }
4199                            catch (Exception e) {
4200                                    throw processException(e);
4201                            }
4202                            finally {
4203                                    if (count == null) {
4204                                            count = Long.valueOf(0);
4205                                    }
4206    
4207                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
4208                                            finderArgs, count);
4209    
4210                                    closeSession(session);
4211                            }
4212                    }
4213    
4214                    return count.intValue();
4215            }
4216    
4217            /**
4218             * Returns the number of d d m templates that the user has permission to view where groupId = &#63;.
4219             *
4220             * @param groupId the group ID
4221             * @return the number of matching d d m templates that the user has permission to view
4222             * @throws SystemException if a system exception occurred
4223             */
4224            public int filterCountByGroupId(long groupId) throws SystemException {
4225                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4226                            return countByGroupId(groupId);
4227                    }
4228    
4229                    StringBundler query = new StringBundler(2);
4230    
4231                    query.append(_FILTER_SQL_COUNT_DDMTEMPLATE_WHERE);
4232    
4233                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
4234    
4235                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4236                                    DDMTemplate.class.getName(),
4237                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4238    
4239                    Session session = null;
4240    
4241                    try {
4242                            session = openSession();
4243    
4244                            SQLQuery q = session.createSQLQuery(sql);
4245    
4246                            q.addScalar(COUNT_COLUMN_NAME,
4247                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4248    
4249                            QueryPos qPos = QueryPos.getInstance(q);
4250    
4251                            qPos.add(groupId);
4252    
4253                            Long count = (Long)q.uniqueResult();
4254    
4255                            return count.intValue();
4256                    }
4257                    catch (Exception e) {
4258                            throw processException(e);
4259                    }
4260                    finally {
4261                            closeSession(session);
4262                    }
4263            }
4264    
4265            /**
4266             * Returns the number of d d m templates where structureId = &#63;.
4267             *
4268             * @param structureId the structure ID
4269             * @return the number of matching d d m templates
4270             * @throws SystemException if a system exception occurred
4271             */
4272            public int countByStructureId(long structureId) throws SystemException {
4273                    Object[] finderArgs = new Object[] { structureId };
4274    
4275                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_STRUCTUREID,
4276                                    finderArgs, this);
4277    
4278                    if (count == null) {
4279                            StringBundler query = new StringBundler(2);
4280    
4281                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
4282    
4283                            query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
4284    
4285                            String sql = query.toString();
4286    
4287                            Session session = null;
4288    
4289                            try {
4290                                    session = openSession();
4291    
4292                                    Query q = session.createQuery(sql);
4293    
4294                                    QueryPos qPos = QueryPos.getInstance(q);
4295    
4296                                    qPos.add(structureId);
4297    
4298                                    count = (Long)q.uniqueResult();
4299                            }
4300                            catch (Exception e) {
4301                                    throw processException(e);
4302                            }
4303                            finally {
4304                                    if (count == null) {
4305                                            count = Long.valueOf(0);
4306                                    }
4307    
4308                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_STRUCTUREID,
4309                                            finderArgs, count);
4310    
4311                                    closeSession(session);
4312                            }
4313                    }
4314    
4315                    return count.intValue();
4316            }
4317    
4318            /**
4319             * Returns the number of d d m templates where type = &#63;.
4320             *
4321             * @param type the type
4322             * @return the number of matching d d m templates
4323             * @throws SystemException if a system exception occurred
4324             */
4325            public int countByType(String type) throws SystemException {
4326                    Object[] finderArgs = new Object[] { type };
4327    
4328                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TYPE,
4329                                    finderArgs, this);
4330    
4331                    if (count == null) {
4332                            StringBundler query = new StringBundler(2);
4333    
4334                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
4335    
4336                            if (type == null) {
4337                                    query.append(_FINDER_COLUMN_TYPE_TYPE_1);
4338                            }
4339                            else {
4340                                    if (type.equals(StringPool.BLANK)) {
4341                                            query.append(_FINDER_COLUMN_TYPE_TYPE_3);
4342                                    }
4343                                    else {
4344                                            query.append(_FINDER_COLUMN_TYPE_TYPE_2);
4345                                    }
4346                            }
4347    
4348                            String sql = query.toString();
4349    
4350                            Session session = null;
4351    
4352                            try {
4353                                    session = openSession();
4354    
4355                                    Query q = session.createQuery(sql);
4356    
4357                                    QueryPos qPos = QueryPos.getInstance(q);
4358    
4359                                    if (type != null) {
4360                                            qPos.add(type);
4361                                    }
4362    
4363                                    count = (Long)q.uniqueResult();
4364                            }
4365                            catch (Exception e) {
4366                                    throw processException(e);
4367                            }
4368                            finally {
4369                                    if (count == null) {
4370                                            count = Long.valueOf(0);
4371                                    }
4372    
4373                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TYPE,
4374                                            finderArgs, count);
4375    
4376                                    closeSession(session);
4377                            }
4378                    }
4379    
4380                    return count.intValue();
4381            }
4382    
4383            /**
4384             * Returns the number of d d m templates where language = &#63;.
4385             *
4386             * @param language the language
4387             * @return the number of matching d d m templates
4388             * @throws SystemException if a system exception occurred
4389             */
4390            public int countByLanguage(String language) throws SystemException {
4391                    Object[] finderArgs = new Object[] { language };
4392    
4393                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_LANGUAGE,
4394                                    finderArgs, this);
4395    
4396                    if (count == null) {
4397                            StringBundler query = new StringBundler(2);
4398    
4399                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
4400    
4401                            if (language == null) {
4402                                    query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_1);
4403                            }
4404                            else {
4405                                    if (language.equals(StringPool.BLANK)) {
4406                                            query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_3);
4407                                    }
4408                                    else {
4409                                            query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_2);
4410                                    }
4411                            }
4412    
4413                            String sql = query.toString();
4414    
4415                            Session session = null;
4416    
4417                            try {
4418                                    session = openSession();
4419    
4420                                    Query q = session.createQuery(sql);
4421    
4422                                    QueryPos qPos = QueryPos.getInstance(q);
4423    
4424                                    if (language != null) {
4425                                            qPos.add(language);
4426                                    }
4427    
4428                                    count = (Long)q.uniqueResult();
4429                            }
4430                            catch (Exception e) {
4431                                    throw processException(e);
4432                            }
4433                            finally {
4434                                    if (count == null) {
4435                                            count = Long.valueOf(0);
4436                                    }
4437    
4438                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LANGUAGE,
4439                                            finderArgs, count);
4440    
4441                                    closeSession(session);
4442                            }
4443                    }
4444    
4445                    return count.intValue();
4446            }
4447    
4448            /**
4449             * Returns the number of d d m templates where structureId = &#63; and type = &#63;.
4450             *
4451             * @param structureId the structure ID
4452             * @param type the type
4453             * @return the number of matching d d m templates
4454             * @throws SystemException if a system exception occurred
4455             */
4456            public int countByS_T(long structureId, String type)
4457                    throws SystemException {
4458                    Object[] finderArgs = new Object[] { structureId, type };
4459    
4460                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_S_T,
4461                                    finderArgs, this);
4462    
4463                    if (count == null) {
4464                            StringBundler query = new StringBundler(3);
4465    
4466                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
4467    
4468                            query.append(_FINDER_COLUMN_S_T_STRUCTUREID_2);
4469    
4470                            if (type == null) {
4471                                    query.append(_FINDER_COLUMN_S_T_TYPE_1);
4472                            }
4473                            else {
4474                                    if (type.equals(StringPool.BLANK)) {
4475                                            query.append(_FINDER_COLUMN_S_T_TYPE_3);
4476                                    }
4477                                    else {
4478                                            query.append(_FINDER_COLUMN_S_T_TYPE_2);
4479                                    }
4480                            }
4481    
4482                            String sql = query.toString();
4483    
4484                            Session session = null;
4485    
4486                            try {
4487                                    session = openSession();
4488    
4489                                    Query q = session.createQuery(sql);
4490    
4491                                    QueryPos qPos = QueryPos.getInstance(q);
4492    
4493                                    qPos.add(structureId);
4494    
4495                                    if (type != null) {
4496                                            qPos.add(type);
4497                                    }
4498    
4499                                    count = (Long)q.uniqueResult();
4500                            }
4501                            catch (Exception e) {
4502                                    throw processException(e);
4503                            }
4504                            finally {
4505                                    if (count == null) {
4506                                            count = Long.valueOf(0);
4507                                    }
4508    
4509                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_S_T, finderArgs,
4510                                            count);
4511    
4512                                    closeSession(session);
4513                            }
4514                    }
4515    
4516                    return count.intValue();
4517            }
4518    
4519            /**
4520             * Returns the number of d d m templates where structureId = &#63; and type = &#63; and mode = &#63;.
4521             *
4522             * @param structureId the structure ID
4523             * @param type the type
4524             * @param mode the mode
4525             * @return the number of matching d d m templates
4526             * @throws SystemException if a system exception occurred
4527             */
4528            public int countByS_T_M(long structureId, String type, String mode)
4529                    throws SystemException {
4530                    Object[] finderArgs = new Object[] { structureId, type, mode };
4531    
4532                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_S_T_M,
4533                                    finderArgs, this);
4534    
4535                    if (count == null) {
4536                            StringBundler query = new StringBundler(4);
4537    
4538                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
4539    
4540                            query.append(_FINDER_COLUMN_S_T_M_STRUCTUREID_2);
4541    
4542                            if (type == null) {
4543                                    query.append(_FINDER_COLUMN_S_T_M_TYPE_1);
4544                            }
4545                            else {
4546                                    if (type.equals(StringPool.BLANK)) {
4547                                            query.append(_FINDER_COLUMN_S_T_M_TYPE_3);
4548                                    }
4549                                    else {
4550                                            query.append(_FINDER_COLUMN_S_T_M_TYPE_2);
4551                                    }
4552                            }
4553    
4554                            if (mode == null) {
4555                                    query.append(_FINDER_COLUMN_S_T_M_MODE_1);
4556                            }
4557                            else {
4558                                    if (mode.equals(StringPool.BLANK)) {
4559                                            query.append(_FINDER_COLUMN_S_T_M_MODE_3);
4560                                    }
4561                                    else {
4562                                            query.append(_FINDER_COLUMN_S_T_M_MODE_2);
4563                                    }
4564                            }
4565    
4566                            String sql = query.toString();
4567    
4568                            Session session = null;
4569    
4570                            try {
4571                                    session = openSession();
4572    
4573                                    Query q = session.createQuery(sql);
4574    
4575                                    QueryPos qPos = QueryPos.getInstance(q);
4576    
4577                                    qPos.add(structureId);
4578    
4579                                    if (type != null) {
4580                                            qPos.add(type);
4581                                    }
4582    
4583                                    if (mode != null) {
4584                                            qPos.add(mode);
4585                                    }
4586    
4587                                    count = (Long)q.uniqueResult();
4588                            }
4589                            catch (Exception e) {
4590                                    throw processException(e);
4591                            }
4592                            finally {
4593                                    if (count == null) {
4594                                            count = Long.valueOf(0);
4595                                    }
4596    
4597                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_S_T_M,
4598                                            finderArgs, count);
4599    
4600                                    closeSession(session);
4601                            }
4602                    }
4603    
4604                    return count.intValue();
4605            }
4606    
4607            /**
4608             * Returns the number of d d m templates.
4609             *
4610             * @return the number of d d m templates
4611             * @throws SystemException if a system exception occurred
4612             */
4613            public int countAll() throws SystemException {
4614                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
4615                                    FINDER_ARGS_EMPTY, this);
4616    
4617                    if (count == null) {
4618                            Session session = null;
4619    
4620                            try {
4621                                    session = openSession();
4622    
4623                                    Query q = session.createQuery(_SQL_COUNT_DDMTEMPLATE);
4624    
4625                                    count = (Long)q.uniqueResult();
4626                            }
4627                            catch (Exception e) {
4628                                    throw processException(e);
4629                            }
4630                            finally {
4631                                    if (count == null) {
4632                                            count = Long.valueOf(0);
4633                                    }
4634    
4635                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
4636                                            FINDER_ARGS_EMPTY, count);
4637    
4638                                    closeSession(session);
4639                            }
4640                    }
4641    
4642                    return count.intValue();
4643            }
4644    
4645            /**
4646             * Initializes the d d m template persistence.
4647             */
4648            public void afterPropertiesSet() {
4649                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
4650                                            com.liferay.portal.util.PropsUtil.get(
4651                                                    "value.object.listener.com.liferay.portlet.dynamicdatamapping.model.DDMTemplate")));
4652    
4653                    if (listenerClassNames.length > 0) {
4654                            try {
4655                                    List<ModelListener<DDMTemplate>> listenersList = new ArrayList<ModelListener<DDMTemplate>>();
4656    
4657                                    for (String listenerClassName : listenerClassNames) {
4658                                            listenersList.add((ModelListener<DDMTemplate>)InstanceFactory.newInstance(
4659                                                            listenerClassName));
4660                                    }
4661    
4662                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
4663                            }
4664                            catch (Exception e) {
4665                                    _log.error(e);
4666                            }
4667                    }
4668            }
4669    
4670            public void destroy() {
4671                    EntityCacheUtil.removeCache(DDMTemplateImpl.class.getName());
4672                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
4673                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4674            }
4675    
4676            @BeanReference(type = DDMContentPersistence.class)
4677            protected DDMContentPersistence ddmContentPersistence;
4678            @BeanReference(type = DDMStorageLinkPersistence.class)
4679            protected DDMStorageLinkPersistence ddmStorageLinkPersistence;
4680            @BeanReference(type = DDMStructurePersistence.class)
4681            protected DDMStructurePersistence ddmStructurePersistence;
4682            @BeanReference(type = DDMStructureLinkPersistence.class)
4683            protected DDMStructureLinkPersistence ddmStructureLinkPersistence;
4684            @BeanReference(type = DDMTemplatePersistence.class)
4685            protected DDMTemplatePersistence ddmTemplatePersistence;
4686            @BeanReference(type = ResourcePersistence.class)
4687            protected ResourcePersistence resourcePersistence;
4688            @BeanReference(type = UserPersistence.class)
4689            protected UserPersistence userPersistence;
4690            private static final String _SQL_SELECT_DDMTEMPLATE = "SELECT ddmTemplate FROM DDMTemplate ddmTemplate";
4691            private static final String _SQL_SELECT_DDMTEMPLATE_WHERE = "SELECT ddmTemplate FROM DDMTemplate ddmTemplate WHERE ";
4692            private static final String _SQL_COUNT_DDMTEMPLATE = "SELECT COUNT(ddmTemplate) FROM DDMTemplate ddmTemplate";
4693            private static final String _SQL_COUNT_DDMTEMPLATE_WHERE = "SELECT COUNT(ddmTemplate) FROM DDMTemplate ddmTemplate WHERE ";
4694            private static final String _FINDER_COLUMN_UUID_UUID_1 = "ddmTemplate.uuid IS NULL";
4695            private static final String _FINDER_COLUMN_UUID_UUID_2 = "ddmTemplate.uuid = ?";
4696            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(ddmTemplate.uuid IS NULL OR ddmTemplate.uuid = ?)";
4697            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "ddmTemplate.uuid IS NULL AND ";
4698            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "ddmTemplate.uuid = ? AND ";
4699            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(ddmTemplate.uuid IS NULL OR ddmTemplate.uuid = ?) AND ";
4700            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "ddmTemplate.groupId = ?";
4701            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "ddmTemplate.groupId = ?";
4702            private static final String _FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2 = "ddmTemplate.structureId = ?";
4703            private static final String _FINDER_COLUMN_TYPE_TYPE_1 = "ddmTemplate.type IS NULL";
4704            private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "ddmTemplate.type = ?";
4705            private static final String _FINDER_COLUMN_TYPE_TYPE_3 = "(ddmTemplate.type IS NULL OR ddmTemplate.type = ?)";
4706            private static final String _FINDER_COLUMN_LANGUAGE_LANGUAGE_1 = "ddmTemplate.language IS NULL";
4707            private static final String _FINDER_COLUMN_LANGUAGE_LANGUAGE_2 = "ddmTemplate.language = ?";
4708            private static final String _FINDER_COLUMN_LANGUAGE_LANGUAGE_3 = "(ddmTemplate.language IS NULL OR ddmTemplate.language = ?)";
4709            private static final String _FINDER_COLUMN_S_T_STRUCTUREID_2 = "ddmTemplate.structureId = ? AND ";
4710            private static final String _FINDER_COLUMN_S_T_TYPE_1 = "ddmTemplate.type IS NULL";
4711            private static final String _FINDER_COLUMN_S_T_TYPE_2 = "ddmTemplate.type = ?";
4712            private static final String _FINDER_COLUMN_S_T_TYPE_3 = "(ddmTemplate.type IS NULL OR ddmTemplate.type = ?)";
4713            private static final String _FINDER_COLUMN_S_T_M_STRUCTUREID_2 = "ddmTemplate.structureId = ? AND ";
4714            private static final String _FINDER_COLUMN_S_T_M_TYPE_1 = "ddmTemplate.type IS NULL AND ";
4715            private static final String _FINDER_COLUMN_S_T_M_TYPE_2 = "ddmTemplate.type = ? AND ";
4716            private static final String _FINDER_COLUMN_S_T_M_TYPE_3 = "(ddmTemplate.type IS NULL OR ddmTemplate.type = ?) AND ";
4717            private static final String _FINDER_COLUMN_S_T_M_MODE_1 = "ddmTemplate.mode IS NULL";
4718            private static final String _FINDER_COLUMN_S_T_M_MODE_2 = "ddmTemplate.mode = ?";
4719            private static final String _FINDER_COLUMN_S_T_M_MODE_3 = "(ddmTemplate.mode IS NULL OR ddmTemplate.mode = ?)";
4720            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "ddmTemplate.templateId";
4721            private static final String _FILTER_SQL_SELECT_DDMTEMPLATE_WHERE = "SELECT DISTINCT {ddmTemplate.*} FROM DDMTemplate ddmTemplate WHERE ";
4722            private static final String _FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_1 =
4723                    "SELECT {DDMTemplate.*} FROM (SELECT DISTINCT ddmTemplate.templateId FROM DDMTemplate ddmTemplate WHERE ";
4724            private static final String _FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_2 =
4725                    ") TEMP_TABLE INNER JOIN DDMTemplate ON TEMP_TABLE.templateId = DDMTemplate.templateId";
4726            private static final String _FILTER_SQL_COUNT_DDMTEMPLATE_WHERE = "SELECT COUNT(DISTINCT ddmTemplate.templateId) AS COUNT_VALUE FROM DDMTemplate ddmTemplate WHERE ";
4727            private static final String _FILTER_ENTITY_ALIAS = "ddmTemplate";
4728            private static final String _FILTER_ENTITY_TABLE = "DDMTemplate";
4729            private static final String _ORDER_BY_ENTITY_ALIAS = "ddmTemplate.";
4730            private static final String _ORDER_BY_ENTITY_TABLE = "DDMTemplate.";
4731            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DDMTemplate exists with the primary key ";
4732            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DDMTemplate exists with the key {";
4733            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
4734            private static Log _log = LogFactoryUtil.getLog(DDMTemplatePersistenceImpl.class);
4735            private static DDMTemplate _nullDDMTemplate = new DDMTemplateImpl() {
4736                            @Override
4737                            public Object clone() {
4738                                    return this;
4739                            }
4740    
4741                            @Override
4742                            public CacheModel<DDMTemplate> toCacheModel() {
4743                                    return _nullDDMTemplateCacheModel;
4744                            }
4745                    };
4746    
4747            private static CacheModel<DDMTemplate> _nullDDMTemplateCacheModel = new CacheModel<DDMTemplate>() {
4748                            public DDMTemplate toEntityModel() {
4749                                    return _nullDDMTemplate;
4750                            }
4751                    };
4752    }