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