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