001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.dynamicdatamapping.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.CacheModel;
040    import com.liferay.portal.model.ModelListener;
041    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
042    import com.liferay.portal.service.persistence.UserPersistence;
043    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044    
045    import com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException;
046    import com.liferay.portlet.dynamicdatamapping.model.DDMTemplate;
047    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateImpl;
048    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl;
049    
050    import java.io.Serializable;
051    
052    import java.util.ArrayList;
053    import java.util.Collections;
054    import java.util.List;
055    
056    /**
057     * The persistence implementation for the d d m template service.
058     *
059     * <p>
060     * Caching information and settings can be found in <code>portal.properties</code>
061     * </p>
062     *
063     * @author Brian Wing Shun Chan
064     * @see DDMTemplatePersistence
065     * @see DDMTemplateUtil
066     * @generated
067     */
068    public class DDMTemplatePersistenceImpl extends BasePersistenceImpl<DDMTemplate>
069            implements DDMTemplatePersistence {
070            /*
071             * NOTE FOR DEVELOPERS:
072             *
073             * 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.
074             */
075            public static final String FINDER_CLASS_NAME_ENTITY = DDMTemplateImpl.class.getName();
076            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List1";
078            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079                    ".List2";
080            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
081                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
082                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
083                            new String[] {
084                                    String.class.getName(),
085                                    
086                            "java.lang.Integer", "java.lang.Integer",
087                                    "com.liferay.portal.kernel.util.OrderByComparator"
088                            });
089            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
090                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
091                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
092                            new String[] { String.class.getName() },
093                            DDMTemplateModelImpl.UUID_COLUMN_BITMASK);
094            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
095                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
096                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
097                            new String[] { String.class.getName() });
098            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
099                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
100                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
101                            new String[] { String.class.getName(), Long.class.getName() },
102                            DDMTemplateModelImpl.UUID_COLUMN_BITMASK |
103                            DDMTemplateModelImpl.GROUPID_COLUMN_BITMASK);
104            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
105                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
106                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
107                            new String[] { String.class.getName(), Long.class.getName() });
108            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
109                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
110                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
111                            new String[] {
112                                    String.class.getName(), Long.class.getName(),
113                                    
114                            "java.lang.Integer", "java.lang.Integer",
115                                    "com.liferay.portal.kernel.util.OrderByComparator"
116                            });
117            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
118                    new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
119                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
120                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
121                            new String[] { String.class.getName(), Long.class.getName() },
122                            DDMTemplateModelImpl.UUID_COLUMN_BITMASK |
123                            DDMTemplateModelImpl.COMPANYID_COLUMN_BITMASK);
124            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
125                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
126                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
127                            new String[] { String.class.getName(), Long.class.getName() });
128            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
129                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
130                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
131                            new String[] {
132                                    Long.class.getName(),
133                                    
134                            "java.lang.Integer", "java.lang.Integer",
135                                    "com.liferay.portal.kernel.util.OrderByComparator"
136                            });
137            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
138                    new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
139                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
140                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
141                            new String[] { Long.class.getName() },
142                            DDMTemplateModelImpl.GROUPID_COLUMN_BITMASK);
143            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
144                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
145                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
146                            new String[] { Long.class.getName() });
147            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSPK = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
148                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
149                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByClassPK",
150                            new String[] {
151                                    Long.class.getName(),
152                                    
153                            "java.lang.Integer", "java.lang.Integer",
154                                    "com.liferay.portal.kernel.util.OrderByComparator"
155                            });
156            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSPK =
157                    new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
158                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
159                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByClassPK",
160                            new String[] { Long.class.getName() },
161                            DDMTemplateModelImpl.CLASSPK_COLUMN_BITMASK);
162            public static final FinderPath FINDER_PATH_COUNT_BY_CLASSPK = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
163                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
164                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByClassPK",
165                            new String[] { Long.class.getName() });
166            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
167                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
168                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByType",
169                            new String[] {
170                                    String.class.getName(),
171                                    
172                            "java.lang.Integer", "java.lang.Integer",
173                                    "com.liferay.portal.kernel.util.OrderByComparator"
174                            });
175            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
176                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
177                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByType",
178                            new String[] { String.class.getName() },
179                            DDMTemplateModelImpl.TYPE_COLUMN_BITMASK);
180            public static final FinderPath FINDER_PATH_COUNT_BY_TYPE = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
181                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
182                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByType",
183                            new String[] { String.class.getName() });
184            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LANGUAGE = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
185                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
186                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByLanguage",
187                            new String[] {
188                                    String.class.getName(),
189                                    
190                            "java.lang.Integer", "java.lang.Integer",
191                                    "com.liferay.portal.kernel.util.OrderByComparator"
192                            });
193            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LANGUAGE =
194                    new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
195                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
196                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByLanguage",
197                            new String[] { String.class.getName() },
198                            DDMTemplateModelImpl.LANGUAGE_COLUMN_BITMASK);
199            public static final FinderPath FINDER_PATH_COUNT_BY_LANGUAGE = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
200                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
201                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByLanguage",
202                            new String[] { String.class.getName() });
203            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
204                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
205                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
206                            new String[] {
207                                    Long.class.getName(), Long.class.getName(),
208                                    
209                            "java.lang.Integer", "java.lang.Integer",
210                                    "com.liferay.portal.kernel.util.OrderByComparator"
211                            });
212            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
213                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
214                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
215                            new String[] { Long.class.getName(), Long.class.getName() },
216                            DDMTemplateModelImpl.GROUPID_COLUMN_BITMASK |
217                            DDMTemplateModelImpl.CLASSNAMEID_COLUMN_BITMASK);
218            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
219                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
220                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
221                            new String[] { Long.class.getName(), Long.class.getName() });
222            public static final FinderPath FINDER_PATH_FETCH_BY_G_T = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
223                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
224                            FINDER_CLASS_NAME_ENTITY, "fetchByG_T",
225                            new String[] { Long.class.getName(), String.class.getName() },
226                            DDMTemplateModelImpl.GROUPID_COLUMN_BITMASK |
227                            DDMTemplateModelImpl.TEMPLATEKEY_COLUMN_BITMASK);
228            public static final FinderPath FINDER_PATH_COUNT_BY_G_T = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
229                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
230                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_T",
231                            new String[] { Long.class.getName(), String.class.getName() });
232            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
233                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
234                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_C",
235                            new String[] {
236                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
237                                    
238                            "java.lang.Integer", "java.lang.Integer",
239                                    "com.liferay.portal.kernel.util.OrderByComparator"
240                            });
241            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
242                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
243                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_C",
244                            new String[] {
245                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
246                            },
247                            DDMTemplateModelImpl.GROUPID_COLUMN_BITMASK |
248                            DDMTemplateModelImpl.CLASSNAMEID_COLUMN_BITMASK |
249                            DDMTemplateModelImpl.CLASSPK_COLUMN_BITMASK);
250            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_C = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
251                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
252                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_C",
253                            new String[] {
254                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
255                            });
256            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_T = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
257                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
258                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_T",
259                            new String[] {
260                                    Long.class.getName(), Long.class.getName(),
261                                    String.class.getName(),
262                                    
263                            "java.lang.Integer", "java.lang.Integer",
264                                    "com.liferay.portal.kernel.util.OrderByComparator"
265                            });
266            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
267                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
268                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_T",
269                            new String[] {
270                                    Long.class.getName(), Long.class.getName(),
271                                    String.class.getName()
272                            },
273                            DDMTemplateModelImpl.CLASSNAMEID_COLUMN_BITMASK |
274                            DDMTemplateModelImpl.CLASSPK_COLUMN_BITMASK |
275                            DDMTemplateModelImpl.TYPE_COLUMN_BITMASK);
276            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_T = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
277                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
278                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_T",
279                            new String[] {
280                                    Long.class.getName(), Long.class.getName(),
281                                    String.class.getName()
282                            });
283            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_T_M = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
284                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
285                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_T_M",
286                            new String[] {
287                                    Long.class.getName(), Long.class.getName(),
288                                    String.class.getName(), String.class.getName(),
289                                    
290                            "java.lang.Integer", "java.lang.Integer",
291                                    "com.liferay.portal.kernel.util.OrderByComparator"
292                            });
293            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T_M =
294                    new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
295                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
296                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_T_M",
297                            new String[] {
298                                    Long.class.getName(), Long.class.getName(),
299                                    String.class.getName(), String.class.getName()
300                            },
301                            DDMTemplateModelImpl.CLASSNAMEID_COLUMN_BITMASK |
302                            DDMTemplateModelImpl.CLASSPK_COLUMN_BITMASK |
303                            DDMTemplateModelImpl.TYPE_COLUMN_BITMASK |
304                            DDMTemplateModelImpl.MODE_COLUMN_BITMASK);
305            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_T_M = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
306                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
307                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_T_M",
308                            new String[] {
309                                    Long.class.getName(), Long.class.getName(),
310                                    String.class.getName(), String.class.getName()
311                            });
312            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
313                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
314                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
315            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
316                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
317                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
318            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
319                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
320                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
321    
322            /**
323             * Caches the d d m template in the entity cache if it is enabled.
324             *
325             * @param ddmTemplate the d d m template
326             */
327            public void cacheResult(DDMTemplate ddmTemplate) {
328                    EntityCacheUtil.putResult(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
329                            DDMTemplateImpl.class, ddmTemplate.getPrimaryKey(), ddmTemplate);
330    
331                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
332                            new Object[] {
333                                    ddmTemplate.getUuid(), Long.valueOf(ddmTemplate.getGroupId())
334                            }, ddmTemplate);
335    
336                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_T,
337                            new Object[] {
338                                    Long.valueOf(ddmTemplate.getGroupId()),
339                                    
340                            ddmTemplate.getTemplateKey()
341                            }, ddmTemplate);
342    
343                    ddmTemplate.resetOriginalValues();
344            }
345    
346            /**
347             * Caches the d d m templates in the entity cache if it is enabled.
348             *
349             * @param ddmTemplates the d d m templates
350             */
351            public void cacheResult(List<DDMTemplate> ddmTemplates) {
352                    for (DDMTemplate ddmTemplate : ddmTemplates) {
353                            if (EntityCacheUtil.getResult(
354                                                    DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
355                                                    DDMTemplateImpl.class, ddmTemplate.getPrimaryKey()) == null) {
356                                    cacheResult(ddmTemplate);
357                            }
358                            else {
359                                    ddmTemplate.resetOriginalValues();
360                            }
361                    }
362            }
363    
364            /**
365             * Clears the cache for all d d m templates.
366             *
367             * <p>
368             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
369             * </p>
370             */
371            @Override
372            public void clearCache() {
373                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
374                            CacheRegistryUtil.clear(DDMTemplateImpl.class.getName());
375                    }
376    
377                    EntityCacheUtil.clearCache(DDMTemplateImpl.class.getName());
378    
379                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
380                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
381                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
382            }
383    
384            /**
385             * Clears the cache for the d d m template.
386             *
387             * <p>
388             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
389             * </p>
390             */
391            @Override
392            public void clearCache(DDMTemplate ddmTemplate) {
393                    EntityCacheUtil.removeResult(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
394                            DDMTemplateImpl.class, ddmTemplate.getPrimaryKey());
395    
396                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
397                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
398    
399                    clearUniqueFindersCache(ddmTemplate);
400            }
401    
402            @Override
403            public void clearCache(List<DDMTemplate> ddmTemplates) {
404                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
405                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
406    
407                    for (DDMTemplate ddmTemplate : ddmTemplates) {
408                            EntityCacheUtil.removeResult(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
409                                    DDMTemplateImpl.class, ddmTemplate.getPrimaryKey());
410    
411                            clearUniqueFindersCache(ddmTemplate);
412                    }
413            }
414    
415            protected void clearUniqueFindersCache(DDMTemplate ddmTemplate) {
416                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
417                            new Object[] {
418                                    ddmTemplate.getUuid(), Long.valueOf(ddmTemplate.getGroupId())
419                            });
420    
421                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_T,
422                            new Object[] {
423                                    Long.valueOf(ddmTemplate.getGroupId()),
424                                    
425                            ddmTemplate.getTemplateKey()
426                            });
427            }
428    
429            /**
430             * Creates a new d d m template with the primary key. Does not add the d d m template to the database.
431             *
432             * @param templateId the primary key for the new d d m template
433             * @return the new d d m template
434             */
435            public DDMTemplate create(long templateId) {
436                    DDMTemplate ddmTemplate = new DDMTemplateImpl();
437    
438                    ddmTemplate.setNew(true);
439                    ddmTemplate.setPrimaryKey(templateId);
440    
441                    String uuid = PortalUUIDUtil.generate();
442    
443                    ddmTemplate.setUuid(uuid);
444    
445                    return ddmTemplate;
446            }
447    
448            /**
449             * Removes the d d m template with the primary key from the database. Also notifies the appropriate model listeners.
450             *
451             * @param templateId the primary key of the d d m template
452             * @return the d d m template that was removed
453             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
454             * @throws SystemException if a system exception occurred
455             */
456            public DDMTemplate remove(long templateId)
457                    throws NoSuchTemplateException, SystemException {
458                    return remove(Long.valueOf(templateId));
459            }
460    
461            /**
462             * Removes the d d m template with the primary key from the database. Also notifies the appropriate model listeners.
463             *
464             * @param primaryKey the primary key of the d d m template
465             * @return the d d m template that was removed
466             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
467             * @throws SystemException if a system exception occurred
468             */
469            @Override
470            public DDMTemplate remove(Serializable primaryKey)
471                    throws NoSuchTemplateException, SystemException {
472                    Session session = null;
473    
474                    try {
475                            session = openSession();
476    
477                            DDMTemplate ddmTemplate = (DDMTemplate)session.get(DDMTemplateImpl.class,
478                                            primaryKey);
479    
480                            if (ddmTemplate == null) {
481                                    if (_log.isWarnEnabled()) {
482                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
483                                    }
484    
485                                    throw new NoSuchTemplateException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
486                                            primaryKey);
487                            }
488    
489                            return remove(ddmTemplate);
490                    }
491                    catch (NoSuchTemplateException nsee) {
492                            throw nsee;
493                    }
494                    catch (Exception e) {
495                            throw processException(e);
496                    }
497                    finally {
498                            closeSession(session);
499                    }
500            }
501    
502            @Override
503            protected DDMTemplate removeImpl(DDMTemplate ddmTemplate)
504                    throws SystemException {
505                    ddmTemplate = toUnwrappedModel(ddmTemplate);
506    
507                    Session session = null;
508    
509                    try {
510                            session = openSession();
511    
512                            if (ddmTemplate.isCachedModel()) {
513                                    ddmTemplate = (DDMTemplate)session.get(DDMTemplateImpl.class,
514                                                    ddmTemplate.getPrimaryKeyObj());
515                            }
516    
517                            session.delete(ddmTemplate);
518                    }
519                    catch (Exception e) {
520                            throw processException(e);
521                    }
522                    finally {
523                            closeSession(session);
524                    }
525    
526                    clearCache(ddmTemplate);
527    
528                    return ddmTemplate;
529            }
530    
531            @Override
532            public DDMTemplate updateImpl(
533                    com.liferay.portlet.dynamicdatamapping.model.DDMTemplate ddmTemplate)
534                    throws SystemException {
535                    ddmTemplate = toUnwrappedModel(ddmTemplate);
536    
537                    boolean isNew = ddmTemplate.isNew();
538    
539                    DDMTemplateModelImpl ddmTemplateModelImpl = (DDMTemplateModelImpl)ddmTemplate;
540    
541                    if (Validator.isNull(ddmTemplate.getUuid())) {
542                            String uuid = PortalUUIDUtil.generate();
543    
544                            ddmTemplate.setUuid(uuid);
545                    }
546    
547                    Session session = null;
548    
549                    try {
550                            session = openSession();
551    
552                            if (ddmTemplate.isNew()) {
553                                    session.save(ddmTemplate);
554    
555                                    ddmTemplate.setNew(false);
556                            }
557                            else {
558                                    session.merge(ddmTemplate);
559                            }
560                    }
561                    catch (Exception e) {
562                            throw processException(e);
563                    }
564                    finally {
565                            closeSession(session);
566                    }
567    
568                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
569    
570                    if (isNew || !DDMTemplateModelImpl.COLUMN_BITMASK_ENABLED) {
571                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
572                    }
573    
574                    else {
575                            if ((ddmTemplateModelImpl.getColumnBitmask() &
576                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
577                                    Object[] args = new Object[] {
578                                                    ddmTemplateModelImpl.getOriginalUuid()
579                                            };
580    
581                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
582                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
583                                            args);
584    
585                                    args = new Object[] { ddmTemplateModelImpl.getUuid() };
586    
587                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
588                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
589                                            args);
590                            }
591    
592                            if ((ddmTemplateModelImpl.getColumnBitmask() &
593                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
594                                    Object[] args = new Object[] {
595                                                    ddmTemplateModelImpl.getOriginalUuid(),
596                                                    Long.valueOf(ddmTemplateModelImpl.getOriginalCompanyId())
597                                            };
598    
599                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
600                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
601                                            args);
602    
603                                    args = new Object[] {
604                                                    ddmTemplateModelImpl.getUuid(),
605                                                    Long.valueOf(ddmTemplateModelImpl.getCompanyId())
606                                            };
607    
608                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
609                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
610                                            args);
611                            }
612    
613                            if ((ddmTemplateModelImpl.getColumnBitmask() &
614                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
615                                    Object[] args = new Object[] {
616                                                    Long.valueOf(ddmTemplateModelImpl.getOriginalGroupId())
617                                            };
618    
619                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
620                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
621                                            args);
622    
623                                    args = new Object[] {
624                                                    Long.valueOf(ddmTemplateModelImpl.getGroupId())
625                                            };
626    
627                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
628                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
629                                            args);
630                            }
631    
632                            if ((ddmTemplateModelImpl.getColumnBitmask() &
633                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSPK.getColumnBitmask()) != 0) {
634                                    Object[] args = new Object[] {
635                                                    Long.valueOf(ddmTemplateModelImpl.getOriginalClassPK())
636                                            };
637    
638                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSPK, args);
639                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSPK,
640                                            args);
641    
642                                    args = new Object[] {
643                                                    Long.valueOf(ddmTemplateModelImpl.getClassPK())
644                                            };
645    
646                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSPK, args);
647                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSPK,
648                                            args);
649                            }
650    
651                            if ((ddmTemplateModelImpl.getColumnBitmask() &
652                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE.getColumnBitmask()) != 0) {
653                                    Object[] args = new Object[] {
654                                                    ddmTemplateModelImpl.getOriginalType()
655                                            };
656    
657                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
658                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
659                                            args);
660    
661                                    args = new Object[] { ddmTemplateModelImpl.getType() };
662    
663                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
664                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
665                                            args);
666                            }
667    
668                            if ((ddmTemplateModelImpl.getColumnBitmask() &
669                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LANGUAGE.getColumnBitmask()) != 0) {
670                                    Object[] args = new Object[] {
671                                                    ddmTemplateModelImpl.getOriginalLanguage()
672                                            };
673    
674                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LANGUAGE, args);
675                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LANGUAGE,
676                                            args);
677    
678                                    args = new Object[] { ddmTemplateModelImpl.getLanguage() };
679    
680                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LANGUAGE, args);
681                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LANGUAGE,
682                                            args);
683                            }
684    
685                            if ((ddmTemplateModelImpl.getColumnBitmask() &
686                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
687                                    Object[] args = new Object[] {
688                                                    Long.valueOf(ddmTemplateModelImpl.getOriginalGroupId()),
689                                                    Long.valueOf(ddmTemplateModelImpl.getOriginalClassNameId())
690                                            };
691    
692                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
693                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
694                                            args);
695    
696                                    args = new Object[] {
697                                                    Long.valueOf(ddmTemplateModelImpl.getGroupId()),
698                                                    Long.valueOf(ddmTemplateModelImpl.getClassNameId())
699                                            };
700    
701                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
702                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
703                                            args);
704                            }
705    
706                            if ((ddmTemplateModelImpl.getColumnBitmask() &
707                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C.getColumnBitmask()) != 0) {
708                                    Object[] args = new Object[] {
709                                                    Long.valueOf(ddmTemplateModelImpl.getOriginalGroupId()),
710                                                    Long.valueOf(ddmTemplateModelImpl.getOriginalClassNameId()),
711                                                    Long.valueOf(ddmTemplateModelImpl.getOriginalClassPK())
712                                            };
713    
714                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C, args);
715                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C,
716                                            args);
717    
718                                    args = new Object[] {
719                                                    Long.valueOf(ddmTemplateModelImpl.getGroupId()),
720                                                    Long.valueOf(ddmTemplateModelImpl.getClassNameId()),
721                                                    Long.valueOf(ddmTemplateModelImpl.getClassPK())
722                                            };
723    
724                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C, args);
725                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C,
726                                            args);
727                            }
728    
729                            if ((ddmTemplateModelImpl.getColumnBitmask() &
730                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T.getColumnBitmask()) != 0) {
731                                    Object[] args = new Object[] {
732                                                    Long.valueOf(ddmTemplateModelImpl.getOriginalClassNameId()),
733                                                    Long.valueOf(ddmTemplateModelImpl.getOriginalClassPK()),
734                                                    
735                                                    ddmTemplateModelImpl.getOriginalType()
736                                            };
737    
738                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_T, args);
739                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T,
740                                            args);
741    
742                                    args = new Object[] {
743                                                    Long.valueOf(ddmTemplateModelImpl.getClassNameId()),
744                                                    Long.valueOf(ddmTemplateModelImpl.getClassPK()),
745                                                    
746                                                    ddmTemplateModelImpl.getType()
747                                            };
748    
749                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_T, args);
750                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T,
751                                            args);
752                            }
753    
754                            if ((ddmTemplateModelImpl.getColumnBitmask() &
755                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T_M.getColumnBitmask()) != 0) {
756                                    Object[] args = new Object[] {
757                                                    Long.valueOf(ddmTemplateModelImpl.getOriginalClassNameId()),
758                                                    Long.valueOf(ddmTemplateModelImpl.getOriginalClassPK()),
759                                                    
760                                                    ddmTemplateModelImpl.getOriginalType(),
761                                                    
762                                                    ddmTemplateModelImpl.getOriginalMode()
763                                            };
764    
765                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_T_M, args);
766                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T_M,
767                                            args);
768    
769                                    args = new Object[] {
770                                                    Long.valueOf(ddmTemplateModelImpl.getClassNameId()),
771                                                    Long.valueOf(ddmTemplateModelImpl.getClassPK()),
772                                                    
773                                                    ddmTemplateModelImpl.getType(),
774                                                    
775                                                    ddmTemplateModelImpl.getMode()
776                                            };
777    
778                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_T_M, args);
779                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T_M,
780                                            args);
781                            }
782                    }
783    
784                    EntityCacheUtil.putResult(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
785                            DDMTemplateImpl.class, ddmTemplate.getPrimaryKey(), ddmTemplate);
786    
787                    if (isNew) {
788                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
789                                    new Object[] {
790                                            ddmTemplate.getUuid(),
791                                            Long.valueOf(ddmTemplate.getGroupId())
792                                    }, ddmTemplate);
793    
794                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_T,
795                                    new Object[] {
796                                            Long.valueOf(ddmTemplate.getGroupId()),
797                                            
798                                    ddmTemplate.getTemplateKey()
799                                    }, ddmTemplate);
800                    }
801                    else {
802                            if ((ddmTemplateModelImpl.getColumnBitmask() &
803                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
804                                    Object[] args = new Object[] {
805                                                    ddmTemplateModelImpl.getOriginalUuid(),
806                                                    Long.valueOf(ddmTemplateModelImpl.getOriginalGroupId())
807                                            };
808    
809                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
810    
811                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
812    
813                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
814                                            new Object[] {
815                                                    ddmTemplate.getUuid(),
816                                                    Long.valueOf(ddmTemplate.getGroupId())
817                                            }, ddmTemplate);
818                            }
819    
820                            if ((ddmTemplateModelImpl.getColumnBitmask() &
821                                            FINDER_PATH_FETCH_BY_G_T.getColumnBitmask()) != 0) {
822                                    Object[] args = new Object[] {
823                                                    Long.valueOf(ddmTemplateModelImpl.getOriginalGroupId()),
824                                                    
825                                                    ddmTemplateModelImpl.getOriginalTemplateKey()
826                                            };
827    
828                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_T, args);
829    
830                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_T, args);
831    
832                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_T,
833                                            new Object[] {
834                                                    Long.valueOf(ddmTemplate.getGroupId()),
835                                                    
836                                            ddmTemplate.getTemplateKey()
837                                            }, ddmTemplate);
838                            }
839                    }
840    
841                    return ddmTemplate;
842            }
843    
844            protected DDMTemplate toUnwrappedModel(DDMTemplate ddmTemplate) {
845                    if (ddmTemplate instanceof DDMTemplateImpl) {
846                            return ddmTemplate;
847                    }
848    
849                    DDMTemplateImpl ddmTemplateImpl = new DDMTemplateImpl();
850    
851                    ddmTemplateImpl.setNew(ddmTemplate.isNew());
852                    ddmTemplateImpl.setPrimaryKey(ddmTemplate.getPrimaryKey());
853    
854                    ddmTemplateImpl.setUuid(ddmTemplate.getUuid());
855                    ddmTemplateImpl.setTemplateId(ddmTemplate.getTemplateId());
856                    ddmTemplateImpl.setGroupId(ddmTemplate.getGroupId());
857                    ddmTemplateImpl.setCompanyId(ddmTemplate.getCompanyId());
858                    ddmTemplateImpl.setUserId(ddmTemplate.getUserId());
859                    ddmTemplateImpl.setUserName(ddmTemplate.getUserName());
860                    ddmTemplateImpl.setCreateDate(ddmTemplate.getCreateDate());
861                    ddmTemplateImpl.setModifiedDate(ddmTemplate.getModifiedDate());
862                    ddmTemplateImpl.setClassNameId(ddmTemplate.getClassNameId());
863                    ddmTemplateImpl.setClassPK(ddmTemplate.getClassPK());
864                    ddmTemplateImpl.setTemplateKey(ddmTemplate.getTemplateKey());
865                    ddmTemplateImpl.setName(ddmTemplate.getName());
866                    ddmTemplateImpl.setDescription(ddmTemplate.getDescription());
867                    ddmTemplateImpl.setType(ddmTemplate.getType());
868                    ddmTemplateImpl.setMode(ddmTemplate.getMode());
869                    ddmTemplateImpl.setLanguage(ddmTemplate.getLanguage());
870                    ddmTemplateImpl.setScript(ddmTemplate.getScript());
871                    ddmTemplateImpl.setCacheable(ddmTemplate.isCacheable());
872    
873                    return ddmTemplateImpl;
874            }
875    
876            /**
877             * Returns the d d m template with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
878             *
879             * @param primaryKey the primary key of the d d m template
880             * @return the d d m template
881             * @throws com.liferay.portal.NoSuchModelException if a d d m template with the primary key could not be found
882             * @throws SystemException if a system exception occurred
883             */
884            @Override
885            public DDMTemplate findByPrimaryKey(Serializable primaryKey)
886                    throws NoSuchModelException, SystemException {
887                    return findByPrimaryKey(((Long)primaryKey).longValue());
888            }
889    
890            /**
891             * 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.
892             *
893             * @param templateId the primary key of the d d m template
894             * @return the d d m template
895             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
896             * @throws SystemException if a system exception occurred
897             */
898            public DDMTemplate findByPrimaryKey(long templateId)
899                    throws NoSuchTemplateException, SystemException {
900                    DDMTemplate ddmTemplate = fetchByPrimaryKey(templateId);
901    
902                    if (ddmTemplate == null) {
903                            if (_log.isWarnEnabled()) {
904                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + templateId);
905                            }
906    
907                            throw new NoSuchTemplateException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
908                                    templateId);
909                    }
910    
911                    return ddmTemplate;
912            }
913    
914            /**
915             * Returns the d d m template with the primary key or returns <code>null</code> if it could not be found.
916             *
917             * @param primaryKey the primary key of the d d m template
918             * @return the d d m template, or <code>null</code> if a d d m template with the primary key could not be found
919             * @throws SystemException if a system exception occurred
920             */
921            @Override
922            public DDMTemplate fetchByPrimaryKey(Serializable primaryKey)
923                    throws SystemException {
924                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
925            }
926    
927            /**
928             * Returns the d d m template with the primary key or returns <code>null</code> if it could not be found.
929             *
930             * @param templateId the primary key of the d d m template
931             * @return the d d m template, or <code>null</code> if a d d m template with the primary key could not be found
932             * @throws SystemException if a system exception occurred
933             */
934            public DDMTemplate fetchByPrimaryKey(long templateId)
935                    throws SystemException {
936                    DDMTemplate ddmTemplate = (DDMTemplate)EntityCacheUtil.getResult(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
937                                    DDMTemplateImpl.class, templateId);
938    
939                    if (ddmTemplate == _nullDDMTemplate) {
940                            return null;
941                    }
942    
943                    if (ddmTemplate == null) {
944                            Session session = null;
945    
946                            boolean hasException = false;
947    
948                            try {
949                                    session = openSession();
950    
951                                    ddmTemplate = (DDMTemplate)session.get(DDMTemplateImpl.class,
952                                                    Long.valueOf(templateId));
953                            }
954                            catch (Exception e) {
955                                    hasException = true;
956    
957                                    throw processException(e);
958                            }
959                            finally {
960                                    if (ddmTemplate != null) {
961                                            cacheResult(ddmTemplate);
962                                    }
963                                    else if (!hasException) {
964                                            EntityCacheUtil.putResult(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
965                                                    DDMTemplateImpl.class, templateId, _nullDDMTemplate);
966                                    }
967    
968                                    closeSession(session);
969                            }
970                    }
971    
972                    return ddmTemplate;
973            }
974    
975            /**
976             * Returns all the d d m templates where uuid = &#63;.
977             *
978             * @param uuid the uuid
979             * @return the matching d d m templates
980             * @throws SystemException if a system exception occurred
981             */
982            public List<DDMTemplate> findByUuid(String uuid) throws SystemException {
983                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
984            }
985    
986            /**
987             * Returns a range of all the d d m templates where uuid = &#63;.
988             *
989             * <p>
990             * 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.
991             * </p>
992             *
993             * @param uuid the uuid
994             * @param start the lower bound of the range of d d m templates
995             * @param end the upper bound of the range of d d m templates (not inclusive)
996             * @return the range of matching d d m templates
997             * @throws SystemException if a system exception occurred
998             */
999            public List<DDMTemplate> findByUuid(String uuid, int start, int end)
1000                    throws SystemException {
1001                    return findByUuid(uuid, start, end, null);
1002            }
1003    
1004            /**
1005             * Returns an ordered range of all the d d m templates where uuid = &#63;.
1006             *
1007             * <p>
1008             * 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.
1009             * </p>
1010             *
1011             * @param uuid the uuid
1012             * @param start the lower bound of the range of d d m templates
1013             * @param end the upper bound of the range of d d m templates (not inclusive)
1014             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1015             * @return the ordered range of matching d d m templates
1016             * @throws SystemException if a system exception occurred
1017             */
1018            public List<DDMTemplate> findByUuid(String uuid, int start, int end,
1019                    OrderByComparator orderByComparator) throws SystemException {
1020                    FinderPath finderPath = null;
1021                    Object[] finderArgs = null;
1022    
1023                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1024                                    (orderByComparator == null)) {
1025                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
1026                            finderArgs = new Object[] { uuid };
1027                    }
1028                    else {
1029                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
1030                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
1031                    }
1032    
1033                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
1034                                    finderArgs, this);
1035    
1036                    if ((list != null) && !list.isEmpty()) {
1037                            for (DDMTemplate ddmTemplate : list) {
1038                                    if (!Validator.equals(uuid, ddmTemplate.getUuid())) {
1039                                            list = null;
1040    
1041                                            break;
1042                                    }
1043                            }
1044                    }
1045    
1046                    if (list == null) {
1047                            StringBundler query = null;
1048    
1049                            if (orderByComparator != null) {
1050                                    query = new StringBundler(3 +
1051                                                    (orderByComparator.getOrderByFields().length * 3));
1052                            }
1053                            else {
1054                                    query = new StringBundler(2);
1055                            }
1056    
1057                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
1058    
1059                            if (uuid == null) {
1060                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
1061                            }
1062                            else {
1063                                    if (uuid.equals(StringPool.BLANK)) {
1064                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
1065                                    }
1066                                    else {
1067                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
1068                                    }
1069                            }
1070    
1071                            if (orderByComparator != null) {
1072                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1073                                            orderByComparator);
1074                            }
1075    
1076                            String sql = query.toString();
1077    
1078                            Session session = null;
1079    
1080                            try {
1081                                    session = openSession();
1082    
1083                                    Query q = session.createQuery(sql);
1084    
1085                                    QueryPos qPos = QueryPos.getInstance(q);
1086    
1087                                    if (uuid != null) {
1088                                            qPos.add(uuid);
1089                                    }
1090    
1091                                    list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
1092                                                    start, end);
1093                            }
1094                            catch (Exception e) {
1095                                    throw processException(e);
1096                            }
1097                            finally {
1098                                    if (list == null) {
1099                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1100                                    }
1101                                    else {
1102                                            cacheResult(list);
1103    
1104                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1105                                    }
1106    
1107                                    closeSession(session);
1108                            }
1109                    }
1110    
1111                    return list;
1112            }
1113    
1114            /**
1115             * Returns the first d d m template in the ordered set where uuid = &#63;.
1116             *
1117             * @param uuid the uuid
1118             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1119             * @return the first matching d d m template
1120             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
1121             * @throws SystemException if a system exception occurred
1122             */
1123            public DDMTemplate findByUuid_First(String uuid,
1124                    OrderByComparator orderByComparator)
1125                    throws NoSuchTemplateException, SystemException {
1126                    DDMTemplate ddmTemplate = fetchByUuid_First(uuid, orderByComparator);
1127    
1128                    if (ddmTemplate != null) {
1129                            return ddmTemplate;
1130                    }
1131    
1132                    StringBundler msg = new StringBundler(4);
1133    
1134                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1135    
1136                    msg.append("uuid=");
1137                    msg.append(uuid);
1138    
1139                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1140    
1141                    throw new NoSuchTemplateException(msg.toString());
1142            }
1143    
1144            /**
1145             * Returns the first d d m template in the ordered set where uuid = &#63;.
1146             *
1147             * @param uuid the uuid
1148             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1149             * @return the first matching d d m template, or <code>null</code> if a matching d d m template could not be found
1150             * @throws SystemException if a system exception occurred
1151             */
1152            public DDMTemplate fetchByUuid_First(String uuid,
1153                    OrderByComparator orderByComparator) throws SystemException {
1154                    List<DDMTemplate> list = findByUuid(uuid, 0, 1, orderByComparator);
1155    
1156                    if (!list.isEmpty()) {
1157                            return list.get(0);
1158                    }
1159    
1160                    return null;
1161            }
1162    
1163            /**
1164             * Returns the last d d m template in the ordered set where uuid = &#63;.
1165             *
1166             * @param uuid the uuid
1167             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1168             * @return the last matching d d m template
1169             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
1170             * @throws SystemException if a system exception occurred
1171             */
1172            public DDMTemplate findByUuid_Last(String uuid,
1173                    OrderByComparator orderByComparator)
1174                    throws NoSuchTemplateException, SystemException {
1175                    DDMTemplate ddmTemplate = fetchByUuid_Last(uuid, orderByComparator);
1176    
1177                    if (ddmTemplate != null) {
1178                            return ddmTemplate;
1179                    }
1180    
1181                    StringBundler msg = new StringBundler(4);
1182    
1183                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1184    
1185                    msg.append("uuid=");
1186                    msg.append(uuid);
1187    
1188                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1189    
1190                    throw new NoSuchTemplateException(msg.toString());
1191            }
1192    
1193            /**
1194             * Returns the last d d m template in the ordered set where uuid = &#63;.
1195             *
1196             * @param uuid the uuid
1197             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1198             * @return the last matching d d m template, or <code>null</code> if a matching d d m template could not be found
1199             * @throws SystemException if a system exception occurred
1200             */
1201            public DDMTemplate fetchByUuid_Last(String uuid,
1202                    OrderByComparator orderByComparator) throws SystemException {
1203                    int count = countByUuid(uuid);
1204    
1205                    List<DDMTemplate> list = findByUuid(uuid, count - 1, count,
1206                                    orderByComparator);
1207    
1208                    if (!list.isEmpty()) {
1209                            return list.get(0);
1210                    }
1211    
1212                    return null;
1213            }
1214    
1215            /**
1216             * Returns the d d m templates before and after the current d d m template in the ordered set where uuid = &#63;.
1217             *
1218             * @param templateId the primary key of the current d d m template
1219             * @param uuid the uuid
1220             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1221             * @return the previous, current, and next d d m template
1222             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
1223             * @throws SystemException if a system exception occurred
1224             */
1225            public DDMTemplate[] findByUuid_PrevAndNext(long templateId, String uuid,
1226                    OrderByComparator orderByComparator)
1227                    throws NoSuchTemplateException, SystemException {
1228                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
1229    
1230                    Session session = null;
1231    
1232                    try {
1233                            session = openSession();
1234    
1235                            DDMTemplate[] array = new DDMTemplateImpl[3];
1236    
1237                            array[0] = getByUuid_PrevAndNext(session, ddmTemplate, uuid,
1238                                            orderByComparator, true);
1239    
1240                            array[1] = ddmTemplate;
1241    
1242                            array[2] = getByUuid_PrevAndNext(session, ddmTemplate, uuid,
1243                                            orderByComparator, false);
1244    
1245                            return array;
1246                    }
1247                    catch (Exception e) {
1248                            throw processException(e);
1249                    }
1250                    finally {
1251                            closeSession(session);
1252                    }
1253            }
1254    
1255            protected DDMTemplate getByUuid_PrevAndNext(Session session,
1256                    DDMTemplate ddmTemplate, String uuid,
1257                    OrderByComparator orderByComparator, boolean previous) {
1258                    StringBundler query = null;
1259    
1260                    if (orderByComparator != null) {
1261                            query = new StringBundler(6 +
1262                                            (orderByComparator.getOrderByFields().length * 6));
1263                    }
1264                    else {
1265                            query = new StringBundler(3);
1266                    }
1267    
1268                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
1269    
1270                    if (uuid == null) {
1271                            query.append(_FINDER_COLUMN_UUID_UUID_1);
1272                    }
1273                    else {
1274                            if (uuid.equals(StringPool.BLANK)) {
1275                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
1276                            }
1277                            else {
1278                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
1279                            }
1280                    }
1281    
1282                    if (orderByComparator != null) {
1283                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1284    
1285                            if (orderByConditionFields.length > 0) {
1286                                    query.append(WHERE_AND);
1287                            }
1288    
1289                            for (int i = 0; i < orderByConditionFields.length; i++) {
1290                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1291                                    query.append(orderByConditionFields[i]);
1292    
1293                                    if ((i + 1) < orderByConditionFields.length) {
1294                                            if (orderByComparator.isAscending() ^ previous) {
1295                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1296                                            }
1297                                            else {
1298                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1299                                            }
1300                                    }
1301                                    else {
1302                                            if (orderByComparator.isAscending() ^ previous) {
1303                                                    query.append(WHERE_GREATER_THAN);
1304                                            }
1305                                            else {
1306                                                    query.append(WHERE_LESSER_THAN);
1307                                            }
1308                                    }
1309                            }
1310    
1311                            query.append(ORDER_BY_CLAUSE);
1312    
1313                            String[] orderByFields = orderByComparator.getOrderByFields();
1314    
1315                            for (int i = 0; i < orderByFields.length; i++) {
1316                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1317                                    query.append(orderByFields[i]);
1318    
1319                                    if ((i + 1) < orderByFields.length) {
1320                                            if (orderByComparator.isAscending() ^ previous) {
1321                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1322                                            }
1323                                            else {
1324                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1325                                            }
1326                                    }
1327                                    else {
1328                                            if (orderByComparator.isAscending() ^ previous) {
1329                                                    query.append(ORDER_BY_ASC);
1330                                            }
1331                                            else {
1332                                                    query.append(ORDER_BY_DESC);
1333                                            }
1334                                    }
1335                            }
1336                    }
1337    
1338                    String sql = query.toString();
1339    
1340                    Query q = session.createQuery(sql);
1341    
1342                    q.setFirstResult(0);
1343                    q.setMaxResults(2);
1344    
1345                    QueryPos qPos = QueryPos.getInstance(q);
1346    
1347                    if (uuid != null) {
1348                            qPos.add(uuid);
1349                    }
1350    
1351                    if (orderByComparator != null) {
1352                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
1353    
1354                            for (Object value : values) {
1355                                    qPos.add(value);
1356                            }
1357                    }
1358    
1359                    List<DDMTemplate> list = q.list();
1360    
1361                    if (list.size() == 2) {
1362                            return list.get(1);
1363                    }
1364                    else {
1365                            return null;
1366                    }
1367            }
1368    
1369            /**
1370             * 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.
1371             *
1372             * @param uuid the uuid
1373             * @param groupId the group ID
1374             * @return the matching d d m template
1375             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
1376             * @throws SystemException if a system exception occurred
1377             */
1378            public DDMTemplate findByUUID_G(String uuid, long groupId)
1379                    throws NoSuchTemplateException, SystemException {
1380                    DDMTemplate ddmTemplate = fetchByUUID_G(uuid, groupId);
1381    
1382                    if (ddmTemplate == null) {
1383                            StringBundler msg = new StringBundler(6);
1384    
1385                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1386    
1387                            msg.append("uuid=");
1388                            msg.append(uuid);
1389    
1390                            msg.append(", groupId=");
1391                            msg.append(groupId);
1392    
1393                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1394    
1395                            if (_log.isWarnEnabled()) {
1396                                    _log.warn(msg.toString());
1397                            }
1398    
1399                            throw new NoSuchTemplateException(msg.toString());
1400                    }
1401    
1402                    return ddmTemplate;
1403            }
1404    
1405            /**
1406             * 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.
1407             *
1408             * @param uuid the uuid
1409             * @param groupId the group ID
1410             * @return the matching d d m template, or <code>null</code> if a matching d d m template could not be found
1411             * @throws SystemException if a system exception occurred
1412             */
1413            public DDMTemplate fetchByUUID_G(String uuid, long groupId)
1414                    throws SystemException {
1415                    return fetchByUUID_G(uuid, groupId, true);
1416            }
1417    
1418            /**
1419             * 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.
1420             *
1421             * @param uuid the uuid
1422             * @param groupId the group ID
1423             * @param retrieveFromCache whether to use the finder cache
1424             * @return the matching d d m template, or <code>null</code> if a matching d d m template could not be found
1425             * @throws SystemException if a system exception occurred
1426             */
1427            public DDMTemplate fetchByUUID_G(String uuid, long groupId,
1428                    boolean retrieveFromCache) throws SystemException {
1429                    Object[] finderArgs = new Object[] { uuid, groupId };
1430    
1431                    Object result = null;
1432    
1433                    if (retrieveFromCache) {
1434                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1435                                            finderArgs, this);
1436                    }
1437    
1438                    if (result instanceof DDMTemplate) {
1439                            DDMTemplate ddmTemplate = (DDMTemplate)result;
1440    
1441                            if (!Validator.equals(uuid, ddmTemplate.getUuid()) ||
1442                                            (groupId != ddmTemplate.getGroupId())) {
1443                                    result = null;
1444                            }
1445                    }
1446    
1447                    if (result == null) {
1448                            StringBundler query = new StringBundler(3);
1449    
1450                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
1451    
1452                            if (uuid == null) {
1453                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1454                            }
1455                            else {
1456                                    if (uuid.equals(StringPool.BLANK)) {
1457                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1458                                    }
1459                                    else {
1460                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1461                                    }
1462                            }
1463    
1464                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1465    
1466                            String sql = query.toString();
1467    
1468                            Session session = null;
1469    
1470                            try {
1471                                    session = openSession();
1472    
1473                                    Query q = session.createQuery(sql);
1474    
1475                                    QueryPos qPos = QueryPos.getInstance(q);
1476    
1477                                    if (uuid != null) {
1478                                            qPos.add(uuid);
1479                                    }
1480    
1481                                    qPos.add(groupId);
1482    
1483                                    List<DDMTemplate> list = q.list();
1484    
1485                                    result = list;
1486    
1487                                    DDMTemplate ddmTemplate = null;
1488    
1489                                    if (list.isEmpty()) {
1490                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1491                                                    finderArgs, list);
1492                                    }
1493                                    else {
1494                                            ddmTemplate = list.get(0);
1495    
1496                                            cacheResult(ddmTemplate);
1497    
1498                                            if ((ddmTemplate.getUuid() == null) ||
1499                                                            !ddmTemplate.getUuid().equals(uuid) ||
1500                                                            (ddmTemplate.getGroupId() != groupId)) {
1501                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1502                                                            finderArgs, ddmTemplate);
1503                                            }
1504                                    }
1505    
1506                                    return ddmTemplate;
1507                            }
1508                            catch (Exception e) {
1509                                    throw processException(e);
1510                            }
1511                            finally {
1512                                    if (result == null) {
1513                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1514                                                    finderArgs);
1515                                    }
1516    
1517                                    closeSession(session);
1518                            }
1519                    }
1520                    else {
1521                            if (result instanceof List<?>) {
1522                                    return null;
1523                            }
1524                            else {
1525                                    return (DDMTemplate)result;
1526                            }
1527                    }
1528            }
1529    
1530            /**
1531             * Returns all the d d m templates where uuid = &#63; and companyId = &#63;.
1532             *
1533             * @param uuid the uuid
1534             * @param companyId the company ID
1535             * @return the matching d d m templates
1536             * @throws SystemException if a system exception occurred
1537             */
1538            public List<DDMTemplate> findByUuid_C(String uuid, long companyId)
1539                    throws SystemException {
1540                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1541                            QueryUtil.ALL_POS, null);
1542            }
1543    
1544            /**
1545             * Returns a range of all the d d m templates where uuid = &#63; and companyId = &#63;.
1546             *
1547             * <p>
1548             * 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.
1549             * </p>
1550             *
1551             * @param uuid the uuid
1552             * @param companyId the company ID
1553             * @param start the lower bound of the range of d d m templates
1554             * @param end the upper bound of the range of d d m templates (not inclusive)
1555             * @return the range of matching d d m templates
1556             * @throws SystemException if a system exception occurred
1557             */
1558            public List<DDMTemplate> findByUuid_C(String uuid, long companyId,
1559                    int start, int end) throws SystemException {
1560                    return findByUuid_C(uuid, companyId, start, end, null);
1561            }
1562    
1563            /**
1564             * Returns an ordered range of all the d d m templates where uuid = &#63; and companyId = &#63;.
1565             *
1566             * <p>
1567             * 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.
1568             * </p>
1569             *
1570             * @param uuid the uuid
1571             * @param companyId the company ID
1572             * @param start the lower bound of the range of d d m templates
1573             * @param end the upper bound of the range of d d m templates (not inclusive)
1574             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1575             * @return the ordered range of matching d d m templates
1576             * @throws SystemException if a system exception occurred
1577             */
1578            public List<DDMTemplate> findByUuid_C(String uuid, long companyId,
1579                    int start, int end, OrderByComparator orderByComparator)
1580                    throws SystemException {
1581                    FinderPath finderPath = null;
1582                    Object[] finderArgs = null;
1583    
1584                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1585                                    (orderByComparator == null)) {
1586                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1587                            finderArgs = new Object[] { uuid, companyId };
1588                    }
1589                    else {
1590                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1591                            finderArgs = new Object[] {
1592                                            uuid, companyId,
1593                                            
1594                                            start, end, orderByComparator
1595                                    };
1596                    }
1597    
1598                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
1599                                    finderArgs, this);
1600    
1601                    if ((list != null) && !list.isEmpty()) {
1602                            for (DDMTemplate ddmTemplate : list) {
1603                                    if (!Validator.equals(uuid, ddmTemplate.getUuid()) ||
1604                                                    (companyId != ddmTemplate.getCompanyId())) {
1605                                            list = null;
1606    
1607                                            break;
1608                                    }
1609                            }
1610                    }
1611    
1612                    if (list == null) {
1613                            StringBundler query = null;
1614    
1615                            if (orderByComparator != null) {
1616                                    query = new StringBundler(4 +
1617                                                    (orderByComparator.getOrderByFields().length * 3));
1618                            }
1619                            else {
1620                                    query = new StringBundler(3);
1621                            }
1622    
1623                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
1624    
1625                            if (uuid == null) {
1626                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1627                            }
1628                            else {
1629                                    if (uuid.equals(StringPool.BLANK)) {
1630                                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1631                                    }
1632                                    else {
1633                                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1634                                    }
1635                            }
1636    
1637                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1638    
1639                            if (orderByComparator != null) {
1640                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1641                                            orderByComparator);
1642                            }
1643    
1644                            String sql = query.toString();
1645    
1646                            Session session = null;
1647    
1648                            try {
1649                                    session = openSession();
1650    
1651                                    Query q = session.createQuery(sql);
1652    
1653                                    QueryPos qPos = QueryPos.getInstance(q);
1654    
1655                                    if (uuid != null) {
1656                                            qPos.add(uuid);
1657                                    }
1658    
1659                                    qPos.add(companyId);
1660    
1661                                    list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
1662                                                    start, end);
1663                            }
1664                            catch (Exception e) {
1665                                    throw processException(e);
1666                            }
1667                            finally {
1668                                    if (list == null) {
1669                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1670                                    }
1671                                    else {
1672                                            cacheResult(list);
1673    
1674                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1675                                    }
1676    
1677                                    closeSession(session);
1678                            }
1679                    }
1680    
1681                    return list;
1682            }
1683    
1684            /**
1685             * Returns the first d d m template in the ordered set where uuid = &#63; and companyId = &#63;.
1686             *
1687             * @param uuid the uuid
1688             * @param companyId the company ID
1689             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1690             * @return the first matching d d m template
1691             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
1692             * @throws SystemException if a system exception occurred
1693             */
1694            public DDMTemplate findByUuid_C_First(String uuid, long companyId,
1695                    OrderByComparator orderByComparator)
1696                    throws NoSuchTemplateException, SystemException {
1697                    DDMTemplate ddmTemplate = fetchByUuid_C_First(uuid, companyId,
1698                                    orderByComparator);
1699    
1700                    if (ddmTemplate != null) {
1701                            return ddmTemplate;
1702                    }
1703    
1704                    StringBundler msg = new StringBundler(6);
1705    
1706                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1707    
1708                    msg.append("uuid=");
1709                    msg.append(uuid);
1710    
1711                    msg.append(", companyId=");
1712                    msg.append(companyId);
1713    
1714                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1715    
1716                    throw new NoSuchTemplateException(msg.toString());
1717            }
1718    
1719            /**
1720             * Returns the first d d m template in the ordered set where uuid = &#63; and companyId = &#63;.
1721             *
1722             * @param uuid the uuid
1723             * @param companyId the company ID
1724             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1725             * @return the first matching d d m template, or <code>null</code> if a matching d d m template could not be found
1726             * @throws SystemException if a system exception occurred
1727             */
1728            public DDMTemplate fetchByUuid_C_First(String uuid, long companyId,
1729                    OrderByComparator orderByComparator) throws SystemException {
1730                    List<DDMTemplate> list = findByUuid_C(uuid, companyId, 0, 1,
1731                                    orderByComparator);
1732    
1733                    if (!list.isEmpty()) {
1734                            return list.get(0);
1735                    }
1736    
1737                    return null;
1738            }
1739    
1740            /**
1741             * Returns the last d d m template in the ordered set where uuid = &#63; and companyId = &#63;.
1742             *
1743             * @param uuid the uuid
1744             * @param companyId the company ID
1745             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1746             * @return the last matching d d m template
1747             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
1748             * @throws SystemException if a system exception occurred
1749             */
1750            public DDMTemplate findByUuid_C_Last(String uuid, long companyId,
1751                    OrderByComparator orderByComparator)
1752                    throws NoSuchTemplateException, SystemException {
1753                    DDMTemplate ddmTemplate = fetchByUuid_C_Last(uuid, companyId,
1754                                    orderByComparator);
1755    
1756                    if (ddmTemplate != null) {
1757                            return ddmTemplate;
1758                    }
1759    
1760                    StringBundler msg = new StringBundler(6);
1761    
1762                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1763    
1764                    msg.append("uuid=");
1765                    msg.append(uuid);
1766    
1767                    msg.append(", companyId=");
1768                    msg.append(companyId);
1769    
1770                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1771    
1772                    throw new NoSuchTemplateException(msg.toString());
1773            }
1774    
1775            /**
1776             * Returns the last d d m template in the ordered set where uuid = &#63; and companyId = &#63;.
1777             *
1778             * @param uuid the uuid
1779             * @param companyId the company ID
1780             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1781             * @return the last matching d d m template, or <code>null</code> if a matching d d m template could not be found
1782             * @throws SystemException if a system exception occurred
1783             */
1784            public DDMTemplate fetchByUuid_C_Last(String uuid, long companyId,
1785                    OrderByComparator orderByComparator) throws SystemException {
1786                    int count = countByUuid_C(uuid, companyId);
1787    
1788                    List<DDMTemplate> list = findByUuid_C(uuid, companyId, count - 1,
1789                                    count, orderByComparator);
1790    
1791                    if (!list.isEmpty()) {
1792                            return list.get(0);
1793                    }
1794    
1795                    return null;
1796            }
1797    
1798            /**
1799             * Returns the d d m templates before and after the current d d m template in the ordered set where uuid = &#63; and companyId = &#63;.
1800             *
1801             * @param templateId the primary key of the current d d m template
1802             * @param uuid the uuid
1803             * @param companyId the company ID
1804             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1805             * @return the previous, current, and next d d m template
1806             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
1807             * @throws SystemException if a system exception occurred
1808             */
1809            public DDMTemplate[] findByUuid_C_PrevAndNext(long templateId, String uuid,
1810                    long companyId, OrderByComparator orderByComparator)
1811                    throws NoSuchTemplateException, SystemException {
1812                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
1813    
1814                    Session session = null;
1815    
1816                    try {
1817                            session = openSession();
1818    
1819                            DDMTemplate[] array = new DDMTemplateImpl[3];
1820    
1821                            array[0] = getByUuid_C_PrevAndNext(session, ddmTemplate, uuid,
1822                                            companyId, orderByComparator, true);
1823    
1824                            array[1] = ddmTemplate;
1825    
1826                            array[2] = getByUuid_C_PrevAndNext(session, ddmTemplate, uuid,
1827                                            companyId, orderByComparator, false);
1828    
1829                            return array;
1830                    }
1831                    catch (Exception e) {
1832                            throw processException(e);
1833                    }
1834                    finally {
1835                            closeSession(session);
1836                    }
1837            }
1838    
1839            protected DDMTemplate getByUuid_C_PrevAndNext(Session session,
1840                    DDMTemplate ddmTemplate, String uuid, long companyId,
1841                    OrderByComparator orderByComparator, boolean previous) {
1842                    StringBundler query = null;
1843    
1844                    if (orderByComparator != null) {
1845                            query = new StringBundler(6 +
1846                                            (orderByComparator.getOrderByFields().length * 6));
1847                    }
1848                    else {
1849                            query = new StringBundler(3);
1850                    }
1851    
1852                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
1853    
1854                    if (uuid == null) {
1855                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1856                    }
1857                    else {
1858                            if (uuid.equals(StringPool.BLANK)) {
1859                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1860                            }
1861                            else {
1862                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1863                            }
1864                    }
1865    
1866                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1867    
1868                    if (orderByComparator != null) {
1869                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1870    
1871                            if (orderByConditionFields.length > 0) {
1872                                    query.append(WHERE_AND);
1873                            }
1874    
1875                            for (int i = 0; i < orderByConditionFields.length; i++) {
1876                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1877                                    query.append(orderByConditionFields[i]);
1878    
1879                                    if ((i + 1) < orderByConditionFields.length) {
1880                                            if (orderByComparator.isAscending() ^ previous) {
1881                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1882                                            }
1883                                            else {
1884                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1885                                            }
1886                                    }
1887                                    else {
1888                                            if (orderByComparator.isAscending() ^ previous) {
1889                                                    query.append(WHERE_GREATER_THAN);
1890                                            }
1891                                            else {
1892                                                    query.append(WHERE_LESSER_THAN);
1893                                            }
1894                                    }
1895                            }
1896    
1897                            query.append(ORDER_BY_CLAUSE);
1898    
1899                            String[] orderByFields = orderByComparator.getOrderByFields();
1900    
1901                            for (int i = 0; i < orderByFields.length; i++) {
1902                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1903                                    query.append(orderByFields[i]);
1904    
1905                                    if ((i + 1) < orderByFields.length) {
1906                                            if (orderByComparator.isAscending() ^ previous) {
1907                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1908                                            }
1909                                            else {
1910                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1911                                            }
1912                                    }
1913                                    else {
1914                                            if (orderByComparator.isAscending() ^ previous) {
1915                                                    query.append(ORDER_BY_ASC);
1916                                            }
1917                                            else {
1918                                                    query.append(ORDER_BY_DESC);
1919                                            }
1920                                    }
1921                            }
1922                    }
1923    
1924                    String sql = query.toString();
1925    
1926                    Query q = session.createQuery(sql);
1927    
1928                    q.setFirstResult(0);
1929                    q.setMaxResults(2);
1930    
1931                    QueryPos qPos = QueryPos.getInstance(q);
1932    
1933                    if (uuid != null) {
1934                            qPos.add(uuid);
1935                    }
1936    
1937                    qPos.add(companyId);
1938    
1939                    if (orderByComparator != null) {
1940                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
1941    
1942                            for (Object value : values) {
1943                                    qPos.add(value);
1944                            }
1945                    }
1946    
1947                    List<DDMTemplate> list = q.list();
1948    
1949                    if (list.size() == 2) {
1950                            return list.get(1);
1951                    }
1952                    else {
1953                            return null;
1954                    }
1955            }
1956    
1957            /**
1958             * Returns all the d d m templates where groupId = &#63;.
1959             *
1960             * @param groupId the group ID
1961             * @return the matching d d m templates
1962             * @throws SystemException if a system exception occurred
1963             */
1964            public List<DDMTemplate> findByGroupId(long groupId)
1965                    throws SystemException {
1966                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1967            }
1968    
1969            /**
1970             * Returns a range of all the d d m templates where groupId = &#63;.
1971             *
1972             * <p>
1973             * 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.
1974             * </p>
1975             *
1976             * @param groupId the group ID
1977             * @param start the lower bound of the range of d d m templates
1978             * @param end the upper bound of the range of d d m templates (not inclusive)
1979             * @return the range of matching d d m templates
1980             * @throws SystemException if a system exception occurred
1981             */
1982            public List<DDMTemplate> findByGroupId(long groupId, int start, int end)
1983                    throws SystemException {
1984                    return findByGroupId(groupId, start, end, null);
1985            }
1986    
1987            /**
1988             * Returns an ordered range of all the d d m templates where groupId = &#63;.
1989             *
1990             * <p>
1991             * 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.
1992             * </p>
1993             *
1994             * @param groupId the group ID
1995             * @param start the lower bound of the range of d d m templates
1996             * @param end the upper bound of the range of d d m templates (not inclusive)
1997             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1998             * @return the ordered range of matching d d m templates
1999             * @throws SystemException if a system exception occurred
2000             */
2001            public List<DDMTemplate> findByGroupId(long groupId, int start, int end,
2002                    OrderByComparator orderByComparator) throws SystemException {
2003                    FinderPath finderPath = null;
2004                    Object[] finderArgs = null;
2005    
2006                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2007                                    (orderByComparator == null)) {
2008                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
2009                            finderArgs = new Object[] { groupId };
2010                    }
2011                    else {
2012                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
2013                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
2014                    }
2015    
2016                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
2017                                    finderArgs, this);
2018    
2019                    if ((list != null) && !list.isEmpty()) {
2020                            for (DDMTemplate ddmTemplate : list) {
2021                                    if ((groupId != ddmTemplate.getGroupId())) {
2022                                            list = null;
2023    
2024                                            break;
2025                                    }
2026                            }
2027                    }
2028    
2029                    if (list == null) {
2030                            StringBundler query = null;
2031    
2032                            if (orderByComparator != null) {
2033                                    query = new StringBundler(3 +
2034                                                    (orderByComparator.getOrderByFields().length * 3));
2035                            }
2036                            else {
2037                                    query = new StringBundler(2);
2038                            }
2039    
2040                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
2041    
2042                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2043    
2044                            if (orderByComparator != null) {
2045                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2046                                            orderByComparator);
2047                            }
2048    
2049                            String sql = query.toString();
2050    
2051                            Session session = null;
2052    
2053                            try {
2054                                    session = openSession();
2055    
2056                                    Query q = session.createQuery(sql);
2057    
2058                                    QueryPos qPos = QueryPos.getInstance(q);
2059    
2060                                    qPos.add(groupId);
2061    
2062                                    list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
2063                                                    start, end);
2064                            }
2065                            catch (Exception e) {
2066                                    throw processException(e);
2067                            }
2068                            finally {
2069                                    if (list == null) {
2070                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2071                                    }
2072                                    else {
2073                                            cacheResult(list);
2074    
2075                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2076                                    }
2077    
2078                                    closeSession(session);
2079                            }
2080                    }
2081    
2082                    return list;
2083            }
2084    
2085            /**
2086             * Returns the first d d m template in the ordered set where groupId = &#63;.
2087             *
2088             * @param groupId the group ID
2089             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2090             * @return the first matching d d m template
2091             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
2092             * @throws SystemException if a system exception occurred
2093             */
2094            public DDMTemplate findByGroupId_First(long groupId,
2095                    OrderByComparator orderByComparator)
2096                    throws NoSuchTemplateException, SystemException {
2097                    DDMTemplate ddmTemplate = fetchByGroupId_First(groupId,
2098                                    orderByComparator);
2099    
2100                    if (ddmTemplate != null) {
2101                            return ddmTemplate;
2102                    }
2103    
2104                    StringBundler msg = new StringBundler(4);
2105    
2106                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2107    
2108                    msg.append("groupId=");
2109                    msg.append(groupId);
2110    
2111                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2112    
2113                    throw new NoSuchTemplateException(msg.toString());
2114            }
2115    
2116            /**
2117             * Returns the first d d m template in the ordered set where groupId = &#63;.
2118             *
2119             * @param groupId the group ID
2120             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2121             * @return the first matching d d m template, or <code>null</code> if a matching d d m template could not be found
2122             * @throws SystemException if a system exception occurred
2123             */
2124            public DDMTemplate fetchByGroupId_First(long groupId,
2125                    OrderByComparator orderByComparator) throws SystemException {
2126                    List<DDMTemplate> list = findByGroupId(groupId, 0, 1, orderByComparator);
2127    
2128                    if (!list.isEmpty()) {
2129                            return list.get(0);
2130                    }
2131    
2132                    return null;
2133            }
2134    
2135            /**
2136             * Returns the last d d m template in the ordered set where groupId = &#63;.
2137             *
2138             * @param groupId the group ID
2139             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2140             * @return the last matching d d m template
2141             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
2142             * @throws SystemException if a system exception occurred
2143             */
2144            public DDMTemplate findByGroupId_Last(long groupId,
2145                    OrderByComparator orderByComparator)
2146                    throws NoSuchTemplateException, SystemException {
2147                    DDMTemplate ddmTemplate = fetchByGroupId_Last(groupId, orderByComparator);
2148    
2149                    if (ddmTemplate != null) {
2150                            return ddmTemplate;
2151                    }
2152    
2153                    StringBundler msg = new StringBundler(4);
2154    
2155                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2156    
2157                    msg.append("groupId=");
2158                    msg.append(groupId);
2159    
2160                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2161    
2162                    throw new NoSuchTemplateException(msg.toString());
2163            }
2164    
2165            /**
2166             * Returns the last d d m template in the ordered set where groupId = &#63;.
2167             *
2168             * @param groupId the group ID
2169             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2170             * @return the last matching d d m template, or <code>null</code> if a matching d d m template could not be found
2171             * @throws SystemException if a system exception occurred
2172             */
2173            public DDMTemplate fetchByGroupId_Last(long groupId,
2174                    OrderByComparator orderByComparator) throws SystemException {
2175                    int count = countByGroupId(groupId);
2176    
2177                    List<DDMTemplate> list = findByGroupId(groupId, count - 1, count,
2178                                    orderByComparator);
2179    
2180                    if (!list.isEmpty()) {
2181                            return list.get(0);
2182                    }
2183    
2184                    return null;
2185            }
2186    
2187            /**
2188             * Returns the d d m templates before and after the current d d m template in the ordered set where groupId = &#63;.
2189             *
2190             * @param templateId the primary key of the current d d m template
2191             * @param groupId the group ID
2192             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2193             * @return the previous, current, and next d d m template
2194             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
2195             * @throws SystemException if a system exception occurred
2196             */
2197            public DDMTemplate[] findByGroupId_PrevAndNext(long templateId,
2198                    long groupId, OrderByComparator orderByComparator)
2199                    throws NoSuchTemplateException, SystemException {
2200                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
2201    
2202                    Session session = null;
2203    
2204                    try {
2205                            session = openSession();
2206    
2207                            DDMTemplate[] array = new DDMTemplateImpl[3];
2208    
2209                            array[0] = getByGroupId_PrevAndNext(session, ddmTemplate, groupId,
2210                                            orderByComparator, true);
2211    
2212                            array[1] = ddmTemplate;
2213    
2214                            array[2] = getByGroupId_PrevAndNext(session, ddmTemplate, groupId,
2215                                            orderByComparator, false);
2216    
2217                            return array;
2218                    }
2219                    catch (Exception e) {
2220                            throw processException(e);
2221                    }
2222                    finally {
2223                            closeSession(session);
2224                    }
2225            }
2226    
2227            protected DDMTemplate getByGroupId_PrevAndNext(Session session,
2228                    DDMTemplate ddmTemplate, long groupId,
2229                    OrderByComparator orderByComparator, boolean previous) {
2230                    StringBundler query = null;
2231    
2232                    if (orderByComparator != null) {
2233                            query = new StringBundler(6 +
2234                                            (orderByComparator.getOrderByFields().length * 6));
2235                    }
2236                    else {
2237                            query = new StringBundler(3);
2238                    }
2239    
2240                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
2241    
2242                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2243    
2244                    if (orderByComparator != null) {
2245                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2246    
2247                            if (orderByConditionFields.length > 0) {
2248                                    query.append(WHERE_AND);
2249                            }
2250    
2251                            for (int i = 0; i < orderByConditionFields.length; i++) {
2252                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2253                                    query.append(orderByConditionFields[i]);
2254    
2255                                    if ((i + 1) < orderByConditionFields.length) {
2256                                            if (orderByComparator.isAscending() ^ previous) {
2257                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2258                                            }
2259                                            else {
2260                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2261                                            }
2262                                    }
2263                                    else {
2264                                            if (orderByComparator.isAscending() ^ previous) {
2265                                                    query.append(WHERE_GREATER_THAN);
2266                                            }
2267                                            else {
2268                                                    query.append(WHERE_LESSER_THAN);
2269                                            }
2270                                    }
2271                            }
2272    
2273                            query.append(ORDER_BY_CLAUSE);
2274    
2275                            String[] orderByFields = orderByComparator.getOrderByFields();
2276    
2277                            for (int i = 0; i < orderByFields.length; i++) {
2278                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2279                                    query.append(orderByFields[i]);
2280    
2281                                    if ((i + 1) < orderByFields.length) {
2282                                            if (orderByComparator.isAscending() ^ previous) {
2283                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2284                                            }
2285                                            else {
2286                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2287                                            }
2288                                    }
2289                                    else {
2290                                            if (orderByComparator.isAscending() ^ previous) {
2291                                                    query.append(ORDER_BY_ASC);
2292                                            }
2293                                            else {
2294                                                    query.append(ORDER_BY_DESC);
2295                                            }
2296                                    }
2297                            }
2298                    }
2299    
2300                    String sql = query.toString();
2301    
2302                    Query q = session.createQuery(sql);
2303    
2304                    q.setFirstResult(0);
2305                    q.setMaxResults(2);
2306    
2307                    QueryPos qPos = QueryPos.getInstance(q);
2308    
2309                    qPos.add(groupId);
2310    
2311                    if (orderByComparator != null) {
2312                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
2313    
2314                            for (Object value : values) {
2315                                    qPos.add(value);
2316                            }
2317                    }
2318    
2319                    List<DDMTemplate> list = q.list();
2320    
2321                    if (list.size() == 2) {
2322                            return list.get(1);
2323                    }
2324                    else {
2325                            return null;
2326                    }
2327            }
2328    
2329            /**
2330             * Returns all the d d m templates that the user has permission to view where groupId = &#63;.
2331             *
2332             * @param groupId the group ID
2333             * @return the matching d d m templates that the user has permission to view
2334             * @throws SystemException if a system exception occurred
2335             */
2336            public List<DDMTemplate> filterFindByGroupId(long groupId)
2337                    throws SystemException {
2338                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
2339                            QueryUtil.ALL_POS, null);
2340            }
2341    
2342            /**
2343             * Returns a range of all the d d m templates that the user has permission to view where groupId = &#63;.
2344             *
2345             * <p>
2346             * 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.
2347             * </p>
2348             *
2349             * @param groupId the group ID
2350             * @param start the lower bound of the range of d d m templates
2351             * @param end the upper bound of the range of d d m templates (not inclusive)
2352             * @return the range of matching d d m templates that the user has permission to view
2353             * @throws SystemException if a system exception occurred
2354             */
2355            public List<DDMTemplate> filterFindByGroupId(long groupId, int start,
2356                    int end) throws SystemException {
2357                    return filterFindByGroupId(groupId, start, end, null);
2358            }
2359    
2360            /**
2361             * Returns an ordered range of all the d d m templates that the user has permissions to view where groupId = &#63;.
2362             *
2363             * <p>
2364             * 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.
2365             * </p>
2366             *
2367             * @param groupId the group ID
2368             * @param start the lower bound of the range of d d m templates
2369             * @param end the upper bound of the range of d d m templates (not inclusive)
2370             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2371             * @return the ordered range of matching d d m templates that the user has permission to view
2372             * @throws SystemException if a system exception occurred
2373             */
2374            public List<DDMTemplate> filterFindByGroupId(long groupId, int start,
2375                    int end, OrderByComparator orderByComparator) throws SystemException {
2376                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2377                            return findByGroupId(groupId, start, end, orderByComparator);
2378                    }
2379    
2380                    StringBundler query = null;
2381    
2382                    if (orderByComparator != null) {
2383                            query = new StringBundler(3 +
2384                                            (orderByComparator.getOrderByFields().length * 3));
2385                    }
2386                    else {
2387                            query = new StringBundler(2);
2388                    }
2389    
2390                    if (getDB().isSupportsInlineDistinct()) {
2391                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_WHERE);
2392                    }
2393                    else {
2394                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
2395                    }
2396    
2397                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2398    
2399                    if (!getDB().isSupportsInlineDistinct()) {
2400                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
2401                    }
2402    
2403                    if (orderByComparator != null) {
2404                            if (getDB().isSupportsInlineDistinct()) {
2405                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2406                                            orderByComparator);
2407                            }
2408                            else {
2409                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2410                                            orderByComparator);
2411                            }
2412                    }
2413    
2414                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2415                                    DDMTemplate.class.getName(),
2416                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2417    
2418                    Session session = null;
2419    
2420                    try {
2421                            session = openSession();
2422    
2423                            SQLQuery q = session.createSQLQuery(sql);
2424    
2425                            if (getDB().isSupportsInlineDistinct()) {
2426                                    q.addEntity(_FILTER_ENTITY_ALIAS, DDMTemplateImpl.class);
2427                            }
2428                            else {
2429                                    q.addEntity(_FILTER_ENTITY_TABLE, DDMTemplateImpl.class);
2430                            }
2431    
2432                            QueryPos qPos = QueryPos.getInstance(q);
2433    
2434                            qPos.add(groupId);
2435    
2436                            return (List<DDMTemplate>)QueryUtil.list(q, getDialect(), start, end);
2437                    }
2438                    catch (Exception e) {
2439                            throw processException(e);
2440                    }
2441                    finally {
2442                            closeSession(session);
2443                    }
2444            }
2445    
2446            /**
2447             * 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;.
2448             *
2449             * @param templateId the primary key of the current d d m template
2450             * @param groupId the group ID
2451             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2452             * @return the previous, current, and next d d m template
2453             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
2454             * @throws SystemException if a system exception occurred
2455             */
2456            public DDMTemplate[] filterFindByGroupId_PrevAndNext(long templateId,
2457                    long groupId, OrderByComparator orderByComparator)
2458                    throws NoSuchTemplateException, SystemException {
2459                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2460                            return findByGroupId_PrevAndNext(templateId, groupId,
2461                                    orderByComparator);
2462                    }
2463    
2464                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
2465    
2466                    Session session = null;
2467    
2468                    try {
2469                            session = openSession();
2470    
2471                            DDMTemplate[] array = new DDMTemplateImpl[3];
2472    
2473                            array[0] = filterGetByGroupId_PrevAndNext(session, ddmTemplate,
2474                                            groupId, orderByComparator, true);
2475    
2476                            array[1] = ddmTemplate;
2477    
2478                            array[2] = filterGetByGroupId_PrevAndNext(session, ddmTemplate,
2479                                            groupId, orderByComparator, false);
2480    
2481                            return array;
2482                    }
2483                    catch (Exception e) {
2484                            throw processException(e);
2485                    }
2486                    finally {
2487                            closeSession(session);
2488                    }
2489            }
2490    
2491            protected DDMTemplate filterGetByGroupId_PrevAndNext(Session session,
2492                    DDMTemplate ddmTemplate, long groupId,
2493                    OrderByComparator orderByComparator, boolean previous) {
2494                    StringBundler query = null;
2495    
2496                    if (orderByComparator != null) {
2497                            query = new StringBundler(6 +
2498                                            (orderByComparator.getOrderByFields().length * 6));
2499                    }
2500                    else {
2501                            query = new StringBundler(3);
2502                    }
2503    
2504                    if (getDB().isSupportsInlineDistinct()) {
2505                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_WHERE);
2506                    }
2507                    else {
2508                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
2509                    }
2510    
2511                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2512    
2513                    if (!getDB().isSupportsInlineDistinct()) {
2514                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
2515                    }
2516    
2517                    if (orderByComparator != null) {
2518                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2519    
2520                            if (orderByConditionFields.length > 0) {
2521                                    query.append(WHERE_AND);
2522                            }
2523    
2524                            for (int i = 0; i < orderByConditionFields.length; i++) {
2525                                    if (getDB().isSupportsInlineDistinct()) {
2526                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2527                                    }
2528                                    else {
2529                                            query.append(_ORDER_BY_ENTITY_TABLE);
2530                                    }
2531    
2532                                    query.append(orderByConditionFields[i]);
2533    
2534                                    if ((i + 1) < orderByConditionFields.length) {
2535                                            if (orderByComparator.isAscending() ^ previous) {
2536                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2537                                            }
2538                                            else {
2539                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2540                                            }
2541                                    }
2542                                    else {
2543                                            if (orderByComparator.isAscending() ^ previous) {
2544                                                    query.append(WHERE_GREATER_THAN);
2545                                            }
2546                                            else {
2547                                                    query.append(WHERE_LESSER_THAN);
2548                                            }
2549                                    }
2550                            }
2551    
2552                            query.append(ORDER_BY_CLAUSE);
2553    
2554                            String[] orderByFields = orderByComparator.getOrderByFields();
2555    
2556                            for (int i = 0; i < orderByFields.length; i++) {
2557                                    if (getDB().isSupportsInlineDistinct()) {
2558                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2559                                    }
2560                                    else {
2561                                            query.append(_ORDER_BY_ENTITY_TABLE);
2562                                    }
2563    
2564                                    query.append(orderByFields[i]);
2565    
2566                                    if ((i + 1) < orderByFields.length) {
2567                                            if (orderByComparator.isAscending() ^ previous) {
2568                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2569                                            }
2570                                            else {
2571                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2572                                            }
2573                                    }
2574                                    else {
2575                                            if (orderByComparator.isAscending() ^ previous) {
2576                                                    query.append(ORDER_BY_ASC);
2577                                            }
2578                                            else {
2579                                                    query.append(ORDER_BY_DESC);
2580                                            }
2581                                    }
2582                            }
2583                    }
2584    
2585                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2586                                    DDMTemplate.class.getName(),
2587                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2588    
2589                    SQLQuery q = session.createSQLQuery(sql);
2590    
2591                    q.setFirstResult(0);
2592                    q.setMaxResults(2);
2593    
2594                    if (getDB().isSupportsInlineDistinct()) {
2595                            q.addEntity(_FILTER_ENTITY_ALIAS, DDMTemplateImpl.class);
2596                    }
2597                    else {
2598                            q.addEntity(_FILTER_ENTITY_TABLE, DDMTemplateImpl.class);
2599                    }
2600    
2601                    QueryPos qPos = QueryPos.getInstance(q);
2602    
2603                    qPos.add(groupId);
2604    
2605                    if (orderByComparator != null) {
2606                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
2607    
2608                            for (Object value : values) {
2609                                    qPos.add(value);
2610                            }
2611                    }
2612    
2613                    List<DDMTemplate> list = q.list();
2614    
2615                    if (list.size() == 2) {
2616                            return list.get(1);
2617                    }
2618                    else {
2619                            return null;
2620                    }
2621            }
2622    
2623            /**
2624             * Returns all the d d m templates where classPK = &#63;.
2625             *
2626             * @param classPK the class p k
2627             * @return the matching d d m templates
2628             * @throws SystemException if a system exception occurred
2629             */
2630            public List<DDMTemplate> findByClassPK(long classPK)
2631                    throws SystemException {
2632                    return findByClassPK(classPK, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2633            }
2634    
2635            /**
2636             * Returns a range of all the d d m templates where classPK = &#63;.
2637             *
2638             * <p>
2639             * 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.
2640             * </p>
2641             *
2642             * @param classPK the class p k
2643             * @param start the lower bound of the range of d d m templates
2644             * @param end the upper bound of the range of d d m templates (not inclusive)
2645             * @return the range of matching d d m templates
2646             * @throws SystemException if a system exception occurred
2647             */
2648            public List<DDMTemplate> findByClassPK(long classPK, int start, int end)
2649                    throws SystemException {
2650                    return findByClassPK(classPK, start, end, null);
2651            }
2652    
2653            /**
2654             * Returns an ordered range of all the d d m templates where classPK = &#63;.
2655             *
2656             * <p>
2657             * 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.
2658             * </p>
2659             *
2660             * @param classPK the class p k
2661             * @param start the lower bound of the range of d d m templates
2662             * @param end the upper bound of the range of d d m templates (not inclusive)
2663             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2664             * @return the ordered range of matching d d m templates
2665             * @throws SystemException if a system exception occurred
2666             */
2667            public List<DDMTemplate> findByClassPK(long classPK, int start, int end,
2668                    OrderByComparator orderByComparator) throws SystemException {
2669                    FinderPath finderPath = null;
2670                    Object[] finderArgs = null;
2671    
2672                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2673                                    (orderByComparator == null)) {
2674                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSPK;
2675                            finderArgs = new Object[] { classPK };
2676                    }
2677                    else {
2678                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSPK;
2679                            finderArgs = new Object[] { classPK, start, end, orderByComparator };
2680                    }
2681    
2682                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
2683                                    finderArgs, this);
2684    
2685                    if ((list != null) && !list.isEmpty()) {
2686                            for (DDMTemplate ddmTemplate : list) {
2687                                    if ((classPK != ddmTemplate.getClassPK())) {
2688                                            list = null;
2689    
2690                                            break;
2691                                    }
2692                            }
2693                    }
2694    
2695                    if (list == null) {
2696                            StringBundler query = null;
2697    
2698                            if (orderByComparator != null) {
2699                                    query = new StringBundler(3 +
2700                                                    (orderByComparator.getOrderByFields().length * 3));
2701                            }
2702                            else {
2703                                    query = new StringBundler(2);
2704                            }
2705    
2706                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
2707    
2708                            query.append(_FINDER_COLUMN_CLASSPK_CLASSPK_2);
2709    
2710                            if (orderByComparator != null) {
2711                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2712                                            orderByComparator);
2713                            }
2714    
2715                            String sql = query.toString();
2716    
2717                            Session session = null;
2718    
2719                            try {
2720                                    session = openSession();
2721    
2722                                    Query q = session.createQuery(sql);
2723    
2724                                    QueryPos qPos = QueryPos.getInstance(q);
2725    
2726                                    qPos.add(classPK);
2727    
2728                                    list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
2729                                                    start, end);
2730                            }
2731                            catch (Exception e) {
2732                                    throw processException(e);
2733                            }
2734                            finally {
2735                                    if (list == null) {
2736                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2737                                    }
2738                                    else {
2739                                            cacheResult(list);
2740    
2741                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2742                                    }
2743    
2744                                    closeSession(session);
2745                            }
2746                    }
2747    
2748                    return list;
2749            }
2750    
2751            /**
2752             * Returns the first d d m template in the ordered set where classPK = &#63;.
2753             *
2754             * @param classPK the class p k
2755             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2756             * @return the first matching d d m template
2757             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
2758             * @throws SystemException if a system exception occurred
2759             */
2760            public DDMTemplate findByClassPK_First(long classPK,
2761                    OrderByComparator orderByComparator)
2762                    throws NoSuchTemplateException, SystemException {
2763                    DDMTemplate ddmTemplate = fetchByClassPK_First(classPK,
2764                                    orderByComparator);
2765    
2766                    if (ddmTemplate != null) {
2767                            return ddmTemplate;
2768                    }
2769    
2770                    StringBundler msg = new StringBundler(4);
2771    
2772                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2773    
2774                    msg.append("classPK=");
2775                    msg.append(classPK);
2776    
2777                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2778    
2779                    throw new NoSuchTemplateException(msg.toString());
2780            }
2781    
2782            /**
2783             * Returns the first d d m template in the ordered set where classPK = &#63;.
2784             *
2785             * @param classPK the class p k
2786             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2787             * @return the first matching d d m template, or <code>null</code> if a matching d d m template could not be found
2788             * @throws SystemException if a system exception occurred
2789             */
2790            public DDMTemplate fetchByClassPK_First(long classPK,
2791                    OrderByComparator orderByComparator) throws SystemException {
2792                    List<DDMTemplate> list = findByClassPK(classPK, 0, 1, orderByComparator);
2793    
2794                    if (!list.isEmpty()) {
2795                            return list.get(0);
2796                    }
2797    
2798                    return null;
2799            }
2800    
2801            /**
2802             * Returns the last d d m template in the ordered set where classPK = &#63;.
2803             *
2804             * @param classPK the class p k
2805             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2806             * @return the last matching d d m template
2807             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
2808             * @throws SystemException if a system exception occurred
2809             */
2810            public DDMTemplate findByClassPK_Last(long classPK,
2811                    OrderByComparator orderByComparator)
2812                    throws NoSuchTemplateException, SystemException {
2813                    DDMTemplate ddmTemplate = fetchByClassPK_Last(classPK, orderByComparator);
2814    
2815                    if (ddmTemplate != null) {
2816                            return ddmTemplate;
2817                    }
2818    
2819                    StringBundler msg = new StringBundler(4);
2820    
2821                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2822    
2823                    msg.append("classPK=");
2824                    msg.append(classPK);
2825    
2826                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2827    
2828                    throw new NoSuchTemplateException(msg.toString());
2829            }
2830    
2831            /**
2832             * Returns the last d d m template in the ordered set where classPK = &#63;.
2833             *
2834             * @param classPK the class p k
2835             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2836             * @return the last matching d d m template, or <code>null</code> if a matching d d m template could not be found
2837             * @throws SystemException if a system exception occurred
2838             */
2839            public DDMTemplate fetchByClassPK_Last(long classPK,
2840                    OrderByComparator orderByComparator) throws SystemException {
2841                    int count = countByClassPK(classPK);
2842    
2843                    List<DDMTemplate> list = findByClassPK(classPK, count - 1, count,
2844                                    orderByComparator);
2845    
2846                    if (!list.isEmpty()) {
2847                            return list.get(0);
2848                    }
2849    
2850                    return null;
2851            }
2852    
2853            /**
2854             * Returns the d d m templates before and after the current d d m template in the ordered set where classPK = &#63;.
2855             *
2856             * @param templateId the primary key of the current d d m template
2857             * @param classPK the class p k
2858             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2859             * @return the previous, current, and next d d m template
2860             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
2861             * @throws SystemException if a system exception occurred
2862             */
2863            public DDMTemplate[] findByClassPK_PrevAndNext(long templateId,
2864                    long classPK, OrderByComparator orderByComparator)
2865                    throws NoSuchTemplateException, SystemException {
2866                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
2867    
2868                    Session session = null;
2869    
2870                    try {
2871                            session = openSession();
2872    
2873                            DDMTemplate[] array = new DDMTemplateImpl[3];
2874    
2875                            array[0] = getByClassPK_PrevAndNext(session, ddmTemplate, classPK,
2876                                            orderByComparator, true);
2877    
2878                            array[1] = ddmTemplate;
2879    
2880                            array[2] = getByClassPK_PrevAndNext(session, ddmTemplate, classPK,
2881                                            orderByComparator, false);
2882    
2883                            return array;
2884                    }
2885                    catch (Exception e) {
2886                            throw processException(e);
2887                    }
2888                    finally {
2889                            closeSession(session);
2890                    }
2891            }
2892    
2893            protected DDMTemplate getByClassPK_PrevAndNext(Session session,
2894                    DDMTemplate ddmTemplate, long classPK,
2895                    OrderByComparator orderByComparator, boolean previous) {
2896                    StringBundler query = null;
2897    
2898                    if (orderByComparator != null) {
2899                            query = new StringBundler(6 +
2900                                            (orderByComparator.getOrderByFields().length * 6));
2901                    }
2902                    else {
2903                            query = new StringBundler(3);
2904                    }
2905    
2906                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
2907    
2908                    query.append(_FINDER_COLUMN_CLASSPK_CLASSPK_2);
2909    
2910                    if (orderByComparator != null) {
2911                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2912    
2913                            if (orderByConditionFields.length > 0) {
2914                                    query.append(WHERE_AND);
2915                            }
2916    
2917                            for (int i = 0; i < orderByConditionFields.length; i++) {
2918                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2919                                    query.append(orderByConditionFields[i]);
2920    
2921                                    if ((i + 1) < orderByConditionFields.length) {
2922                                            if (orderByComparator.isAscending() ^ previous) {
2923                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2924                                            }
2925                                            else {
2926                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2927                                            }
2928                                    }
2929                                    else {
2930                                            if (orderByComparator.isAscending() ^ previous) {
2931                                                    query.append(WHERE_GREATER_THAN);
2932                                            }
2933                                            else {
2934                                                    query.append(WHERE_LESSER_THAN);
2935                                            }
2936                                    }
2937                            }
2938    
2939                            query.append(ORDER_BY_CLAUSE);
2940    
2941                            String[] orderByFields = orderByComparator.getOrderByFields();
2942    
2943                            for (int i = 0; i < orderByFields.length; i++) {
2944                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2945                                    query.append(orderByFields[i]);
2946    
2947                                    if ((i + 1) < orderByFields.length) {
2948                                            if (orderByComparator.isAscending() ^ previous) {
2949                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2950                                            }
2951                                            else {
2952                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2953                                            }
2954                                    }
2955                                    else {
2956                                            if (orderByComparator.isAscending() ^ previous) {
2957                                                    query.append(ORDER_BY_ASC);
2958                                            }
2959                                            else {
2960                                                    query.append(ORDER_BY_DESC);
2961                                            }
2962                                    }
2963                            }
2964                    }
2965    
2966                    String sql = query.toString();
2967    
2968                    Query q = session.createQuery(sql);
2969    
2970                    q.setFirstResult(0);
2971                    q.setMaxResults(2);
2972    
2973                    QueryPos qPos = QueryPos.getInstance(q);
2974    
2975                    qPos.add(classPK);
2976    
2977                    if (orderByComparator != null) {
2978                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
2979    
2980                            for (Object value : values) {
2981                                    qPos.add(value);
2982                            }
2983                    }
2984    
2985                    List<DDMTemplate> list = q.list();
2986    
2987                    if (list.size() == 2) {
2988                            return list.get(1);
2989                    }
2990                    else {
2991                            return null;
2992                    }
2993            }
2994    
2995            /**
2996             * Returns all the d d m templates where type = &#63;.
2997             *
2998             * @param type the type
2999             * @return the matching d d m templates
3000             * @throws SystemException if a system exception occurred
3001             */
3002            public List<DDMTemplate> findByType(String type) throws SystemException {
3003                    return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3004            }
3005    
3006            /**
3007             * Returns a range of all the d d m templates where type = &#63;.
3008             *
3009             * <p>
3010             * 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.
3011             * </p>
3012             *
3013             * @param type the type
3014             * @param start the lower bound of the range of d d m templates
3015             * @param end the upper bound of the range of d d m templates (not inclusive)
3016             * @return the range of matching d d m templates
3017             * @throws SystemException if a system exception occurred
3018             */
3019            public List<DDMTemplate> findByType(String type, int start, int end)
3020                    throws SystemException {
3021                    return findByType(type, start, end, null);
3022            }
3023    
3024            /**
3025             * Returns an ordered range of all the d d m templates where type = &#63;.
3026             *
3027             * <p>
3028             * 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.
3029             * </p>
3030             *
3031             * @param type the type
3032             * @param start the lower bound of the range of d d m templates
3033             * @param end the upper bound of the range of d d m templates (not inclusive)
3034             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3035             * @return the ordered range of matching d d m templates
3036             * @throws SystemException if a system exception occurred
3037             */
3038            public List<DDMTemplate> findByType(String type, int start, int end,
3039                    OrderByComparator orderByComparator) throws SystemException {
3040                    FinderPath finderPath = null;
3041                    Object[] finderArgs = null;
3042    
3043                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3044                                    (orderByComparator == null)) {
3045                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE;
3046                            finderArgs = new Object[] { type };
3047                    }
3048                    else {
3049                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE;
3050                            finderArgs = new Object[] { type, start, end, orderByComparator };
3051                    }
3052    
3053                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
3054                                    finderArgs, this);
3055    
3056                    if ((list != null) && !list.isEmpty()) {
3057                            for (DDMTemplate ddmTemplate : list) {
3058                                    if (!Validator.equals(type, ddmTemplate.getType())) {
3059                                            list = null;
3060    
3061                                            break;
3062                                    }
3063                            }
3064                    }
3065    
3066                    if (list == null) {
3067                            StringBundler query = null;
3068    
3069                            if (orderByComparator != null) {
3070                                    query = new StringBundler(3 +
3071                                                    (orderByComparator.getOrderByFields().length * 3));
3072                            }
3073                            else {
3074                                    query = new StringBundler(2);
3075                            }
3076    
3077                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
3078    
3079                            if (type == null) {
3080                                    query.append(_FINDER_COLUMN_TYPE_TYPE_1);
3081                            }
3082                            else {
3083                                    if (type.equals(StringPool.BLANK)) {
3084                                            query.append(_FINDER_COLUMN_TYPE_TYPE_3);
3085                                    }
3086                                    else {
3087                                            query.append(_FINDER_COLUMN_TYPE_TYPE_2);
3088                                    }
3089                            }
3090    
3091                            if (orderByComparator != null) {
3092                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3093                                            orderByComparator);
3094                            }
3095    
3096                            String sql = query.toString();
3097    
3098                            Session session = null;
3099    
3100                            try {
3101                                    session = openSession();
3102    
3103                                    Query q = session.createQuery(sql);
3104    
3105                                    QueryPos qPos = QueryPos.getInstance(q);
3106    
3107                                    if (type != null) {
3108                                            qPos.add(type);
3109                                    }
3110    
3111                                    list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
3112                                                    start, end);
3113                            }
3114                            catch (Exception e) {
3115                                    throw processException(e);
3116                            }
3117                            finally {
3118                                    if (list == null) {
3119                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3120                                    }
3121                                    else {
3122                                            cacheResult(list);
3123    
3124                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3125                                    }
3126    
3127                                    closeSession(session);
3128                            }
3129                    }
3130    
3131                    return list;
3132            }
3133    
3134            /**
3135             * Returns the first d d m template in the ordered set where type = &#63;.
3136             *
3137             * @param type the type
3138             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3139             * @return the first matching d d m template
3140             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
3141             * @throws SystemException if a system exception occurred
3142             */
3143            public DDMTemplate findByType_First(String type,
3144                    OrderByComparator orderByComparator)
3145                    throws NoSuchTemplateException, SystemException {
3146                    DDMTemplate ddmTemplate = fetchByType_First(type, orderByComparator);
3147    
3148                    if (ddmTemplate != null) {
3149                            return ddmTemplate;
3150                    }
3151    
3152                    StringBundler msg = new StringBundler(4);
3153    
3154                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3155    
3156                    msg.append("type=");
3157                    msg.append(type);
3158    
3159                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3160    
3161                    throw new NoSuchTemplateException(msg.toString());
3162            }
3163    
3164            /**
3165             * Returns the first d d m template in the ordered set where type = &#63;.
3166             *
3167             * @param type the type
3168             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3169             * @return the first matching d d m template, or <code>null</code> if a matching d d m template could not be found
3170             * @throws SystemException if a system exception occurred
3171             */
3172            public DDMTemplate fetchByType_First(String type,
3173                    OrderByComparator orderByComparator) throws SystemException {
3174                    List<DDMTemplate> list = findByType(type, 0, 1, orderByComparator);
3175    
3176                    if (!list.isEmpty()) {
3177                            return list.get(0);
3178                    }
3179    
3180                    return null;
3181            }
3182    
3183            /**
3184             * Returns the last d d m template in the ordered set where type = &#63;.
3185             *
3186             * @param type the type
3187             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3188             * @return the last matching d d m template
3189             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
3190             * @throws SystemException if a system exception occurred
3191             */
3192            public DDMTemplate findByType_Last(String type,
3193                    OrderByComparator orderByComparator)
3194                    throws NoSuchTemplateException, SystemException {
3195                    DDMTemplate ddmTemplate = fetchByType_Last(type, orderByComparator);
3196    
3197                    if (ddmTemplate != null) {
3198                            return ddmTemplate;
3199                    }
3200    
3201                    StringBundler msg = new StringBundler(4);
3202    
3203                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3204    
3205                    msg.append("type=");
3206                    msg.append(type);
3207    
3208                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3209    
3210                    throw new NoSuchTemplateException(msg.toString());
3211            }
3212    
3213            /**
3214             * Returns the last d d m template in the ordered set where type = &#63;.
3215             *
3216             * @param type the type
3217             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3218             * @return the last matching d d m template, or <code>null</code> if a matching d d m template could not be found
3219             * @throws SystemException if a system exception occurred
3220             */
3221            public DDMTemplate fetchByType_Last(String type,
3222                    OrderByComparator orderByComparator) throws SystemException {
3223                    int count = countByType(type);
3224    
3225                    List<DDMTemplate> list = findByType(type, count - 1, count,
3226                                    orderByComparator);
3227    
3228                    if (!list.isEmpty()) {
3229                            return list.get(0);
3230                    }
3231    
3232                    return null;
3233            }
3234    
3235            /**
3236             * Returns the d d m templates before and after the current d d m template in the ordered set where type = &#63;.
3237             *
3238             * @param templateId the primary key of the current d d m template
3239             * @param type the type
3240             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3241             * @return the previous, current, and next d d m template
3242             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
3243             * @throws SystemException if a system exception occurred
3244             */
3245            public DDMTemplate[] findByType_PrevAndNext(long templateId, String type,
3246                    OrderByComparator orderByComparator)
3247                    throws NoSuchTemplateException, SystemException {
3248                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
3249    
3250                    Session session = null;
3251    
3252                    try {
3253                            session = openSession();
3254    
3255                            DDMTemplate[] array = new DDMTemplateImpl[3];
3256    
3257                            array[0] = getByType_PrevAndNext(session, ddmTemplate, type,
3258                                            orderByComparator, true);
3259    
3260                            array[1] = ddmTemplate;
3261    
3262                            array[2] = getByType_PrevAndNext(session, ddmTemplate, type,
3263                                            orderByComparator, false);
3264    
3265                            return array;
3266                    }
3267                    catch (Exception e) {
3268                            throw processException(e);
3269                    }
3270                    finally {
3271                            closeSession(session);
3272                    }
3273            }
3274    
3275            protected DDMTemplate getByType_PrevAndNext(Session session,
3276                    DDMTemplate ddmTemplate, String type,
3277                    OrderByComparator orderByComparator, boolean previous) {
3278                    StringBundler query = null;
3279    
3280                    if (orderByComparator != null) {
3281                            query = new StringBundler(6 +
3282                                            (orderByComparator.getOrderByFields().length * 6));
3283                    }
3284                    else {
3285                            query = new StringBundler(3);
3286                    }
3287    
3288                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
3289    
3290                    if (type == null) {
3291                            query.append(_FINDER_COLUMN_TYPE_TYPE_1);
3292                    }
3293                    else {
3294                            if (type.equals(StringPool.BLANK)) {
3295                                    query.append(_FINDER_COLUMN_TYPE_TYPE_3);
3296                            }
3297                            else {
3298                                    query.append(_FINDER_COLUMN_TYPE_TYPE_2);
3299                            }
3300                    }
3301    
3302                    if (orderByComparator != null) {
3303                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3304    
3305                            if (orderByConditionFields.length > 0) {
3306                                    query.append(WHERE_AND);
3307                            }
3308    
3309                            for (int i = 0; i < orderByConditionFields.length; i++) {
3310                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3311                                    query.append(orderByConditionFields[i]);
3312    
3313                                    if ((i + 1) < orderByConditionFields.length) {
3314                                            if (orderByComparator.isAscending() ^ previous) {
3315                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3316                                            }
3317                                            else {
3318                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3319                                            }
3320                                    }
3321                                    else {
3322                                            if (orderByComparator.isAscending() ^ previous) {
3323                                                    query.append(WHERE_GREATER_THAN);
3324                                            }
3325                                            else {
3326                                                    query.append(WHERE_LESSER_THAN);
3327                                            }
3328                                    }
3329                            }
3330    
3331                            query.append(ORDER_BY_CLAUSE);
3332    
3333                            String[] orderByFields = orderByComparator.getOrderByFields();
3334    
3335                            for (int i = 0; i < orderByFields.length; i++) {
3336                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3337                                    query.append(orderByFields[i]);
3338    
3339                                    if ((i + 1) < orderByFields.length) {
3340                                            if (orderByComparator.isAscending() ^ previous) {
3341                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3342                                            }
3343                                            else {
3344                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3345                                            }
3346                                    }
3347                                    else {
3348                                            if (orderByComparator.isAscending() ^ previous) {
3349                                                    query.append(ORDER_BY_ASC);
3350                                            }
3351                                            else {
3352                                                    query.append(ORDER_BY_DESC);
3353                                            }
3354                                    }
3355                            }
3356                    }
3357    
3358                    String sql = query.toString();
3359    
3360                    Query q = session.createQuery(sql);
3361    
3362                    q.setFirstResult(0);
3363                    q.setMaxResults(2);
3364    
3365                    QueryPos qPos = QueryPos.getInstance(q);
3366    
3367                    if (type != null) {
3368                            qPos.add(type);
3369                    }
3370    
3371                    if (orderByComparator != null) {
3372                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
3373    
3374                            for (Object value : values) {
3375                                    qPos.add(value);
3376                            }
3377                    }
3378    
3379                    List<DDMTemplate> list = q.list();
3380    
3381                    if (list.size() == 2) {
3382                            return list.get(1);
3383                    }
3384                    else {
3385                            return null;
3386                    }
3387            }
3388    
3389            /**
3390             * Returns all the d d m templates where language = &#63;.
3391             *
3392             * @param language the language
3393             * @return the matching d d m templates
3394             * @throws SystemException if a system exception occurred
3395             */
3396            public List<DDMTemplate> findByLanguage(String language)
3397                    throws SystemException {
3398                    return findByLanguage(language, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3399                            null);
3400            }
3401    
3402            /**
3403             * Returns a range of all the d d m templates where language = &#63;.
3404             *
3405             * <p>
3406             * 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.
3407             * </p>
3408             *
3409             * @param language the language
3410             * @param start the lower bound of the range of d d m templates
3411             * @param end the upper bound of the range of d d m templates (not inclusive)
3412             * @return the range of matching d d m templates
3413             * @throws SystemException if a system exception occurred
3414             */
3415            public List<DDMTemplate> findByLanguage(String language, int start, int end)
3416                    throws SystemException {
3417                    return findByLanguage(language, start, end, null);
3418            }
3419    
3420            /**
3421             * Returns an ordered range of all the d d m templates where language = &#63;.
3422             *
3423             * <p>
3424             * 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.
3425             * </p>
3426             *
3427             * @param language the language
3428             * @param start the lower bound of the range of d d m templates
3429             * @param end the upper bound of the range of d d m templates (not inclusive)
3430             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3431             * @return the ordered range of matching d d m templates
3432             * @throws SystemException if a system exception occurred
3433             */
3434            public List<DDMTemplate> findByLanguage(String language, int start,
3435                    int end, OrderByComparator orderByComparator) throws SystemException {
3436                    FinderPath finderPath = null;
3437                    Object[] finderArgs = null;
3438    
3439                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3440                                    (orderByComparator == null)) {
3441                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LANGUAGE;
3442                            finderArgs = new Object[] { language };
3443                    }
3444                    else {
3445                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LANGUAGE;
3446                            finderArgs = new Object[] { language, start, end, orderByComparator };
3447                    }
3448    
3449                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
3450                                    finderArgs, this);
3451    
3452                    if ((list != null) && !list.isEmpty()) {
3453                            for (DDMTemplate ddmTemplate : list) {
3454                                    if (!Validator.equals(language, ddmTemplate.getLanguage())) {
3455                                            list = null;
3456    
3457                                            break;
3458                                    }
3459                            }
3460                    }
3461    
3462                    if (list == null) {
3463                            StringBundler query = null;
3464    
3465                            if (orderByComparator != null) {
3466                                    query = new StringBundler(3 +
3467                                                    (orderByComparator.getOrderByFields().length * 3));
3468                            }
3469                            else {
3470                                    query = new StringBundler(2);
3471                            }
3472    
3473                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
3474    
3475                            if (language == null) {
3476                                    query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_1);
3477                            }
3478                            else {
3479                                    if (language.equals(StringPool.BLANK)) {
3480                                            query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_3);
3481                                    }
3482                                    else {
3483                                            query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_2);
3484                                    }
3485                            }
3486    
3487                            if (orderByComparator != null) {
3488                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3489                                            orderByComparator);
3490                            }
3491    
3492                            String sql = query.toString();
3493    
3494                            Session session = null;
3495    
3496                            try {
3497                                    session = openSession();
3498    
3499                                    Query q = session.createQuery(sql);
3500    
3501                                    QueryPos qPos = QueryPos.getInstance(q);
3502    
3503                                    if (language != null) {
3504                                            qPos.add(language);
3505                                    }
3506    
3507                                    list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
3508                                                    start, end);
3509                            }
3510                            catch (Exception e) {
3511                                    throw processException(e);
3512                            }
3513                            finally {
3514                                    if (list == null) {
3515                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3516                                    }
3517                                    else {
3518                                            cacheResult(list);
3519    
3520                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3521                                    }
3522    
3523                                    closeSession(session);
3524                            }
3525                    }
3526    
3527                    return list;
3528            }
3529    
3530            /**
3531             * Returns the first d d m template in the ordered set where language = &#63;.
3532             *
3533             * @param language the language
3534             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3535             * @return the first matching d d m template
3536             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
3537             * @throws SystemException if a system exception occurred
3538             */
3539            public DDMTemplate findByLanguage_First(String language,
3540                    OrderByComparator orderByComparator)
3541                    throws NoSuchTemplateException, SystemException {
3542                    DDMTemplate ddmTemplate = fetchByLanguage_First(language,
3543                                    orderByComparator);
3544    
3545                    if (ddmTemplate != null) {
3546                            return ddmTemplate;
3547                    }
3548    
3549                    StringBundler msg = new StringBundler(4);
3550    
3551                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3552    
3553                    msg.append("language=");
3554                    msg.append(language);
3555    
3556                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3557    
3558                    throw new NoSuchTemplateException(msg.toString());
3559            }
3560    
3561            /**
3562             * Returns the first d d m template in the ordered set where language = &#63;.
3563             *
3564             * @param language the language
3565             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3566             * @return the first matching d d m template, or <code>null</code> if a matching d d m template could not be found
3567             * @throws SystemException if a system exception occurred
3568             */
3569            public DDMTemplate fetchByLanguage_First(String language,
3570                    OrderByComparator orderByComparator) throws SystemException {
3571                    List<DDMTemplate> list = findByLanguage(language, 0, 1,
3572                                    orderByComparator);
3573    
3574                    if (!list.isEmpty()) {
3575                            return list.get(0);
3576                    }
3577    
3578                    return null;
3579            }
3580    
3581            /**
3582             * Returns the last d d m template in the ordered set where language = &#63;.
3583             *
3584             * @param language the language
3585             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3586             * @return the last matching d d m template
3587             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
3588             * @throws SystemException if a system exception occurred
3589             */
3590            public DDMTemplate findByLanguage_Last(String language,
3591                    OrderByComparator orderByComparator)
3592                    throws NoSuchTemplateException, SystemException {
3593                    DDMTemplate ddmTemplate = fetchByLanguage_Last(language,
3594                                    orderByComparator);
3595    
3596                    if (ddmTemplate != null) {
3597                            return ddmTemplate;
3598                    }
3599    
3600                    StringBundler msg = new StringBundler(4);
3601    
3602                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3603    
3604                    msg.append("language=");
3605                    msg.append(language);
3606    
3607                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3608    
3609                    throw new NoSuchTemplateException(msg.toString());
3610            }
3611    
3612            /**
3613             * Returns the last d d m template in the ordered set where language = &#63;.
3614             *
3615             * @param language the language
3616             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3617             * @return the last matching d d m template, or <code>null</code> if a matching d d m template could not be found
3618             * @throws SystemException if a system exception occurred
3619             */
3620            public DDMTemplate fetchByLanguage_Last(String language,
3621                    OrderByComparator orderByComparator) throws SystemException {
3622                    int count = countByLanguage(language);
3623    
3624                    List<DDMTemplate> list = findByLanguage(language, count - 1, count,
3625                                    orderByComparator);
3626    
3627                    if (!list.isEmpty()) {
3628                            return list.get(0);
3629                    }
3630    
3631                    return null;
3632            }
3633    
3634            /**
3635             * Returns the d d m templates before and after the current d d m template in the ordered set where language = &#63;.
3636             *
3637             * @param templateId the primary key of the current d d m template
3638             * @param language the language
3639             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3640             * @return the previous, current, and next d d m template
3641             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
3642             * @throws SystemException if a system exception occurred
3643             */
3644            public DDMTemplate[] findByLanguage_PrevAndNext(long templateId,
3645                    String language, OrderByComparator orderByComparator)
3646                    throws NoSuchTemplateException, SystemException {
3647                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
3648    
3649                    Session session = null;
3650    
3651                    try {
3652                            session = openSession();
3653    
3654                            DDMTemplate[] array = new DDMTemplateImpl[3];
3655    
3656                            array[0] = getByLanguage_PrevAndNext(session, ddmTemplate,
3657                                            language, orderByComparator, true);
3658    
3659                            array[1] = ddmTemplate;
3660    
3661                            array[2] = getByLanguage_PrevAndNext(session, ddmTemplate,
3662                                            language, orderByComparator, false);
3663    
3664                            return array;
3665                    }
3666                    catch (Exception e) {
3667                            throw processException(e);
3668                    }
3669                    finally {
3670                            closeSession(session);
3671                    }
3672            }
3673    
3674            protected DDMTemplate getByLanguage_PrevAndNext(Session session,
3675                    DDMTemplate ddmTemplate, String language,
3676                    OrderByComparator orderByComparator, boolean previous) {
3677                    StringBundler query = null;
3678    
3679                    if (orderByComparator != null) {
3680                            query = new StringBundler(6 +
3681                                            (orderByComparator.getOrderByFields().length * 6));
3682                    }
3683                    else {
3684                            query = new StringBundler(3);
3685                    }
3686    
3687                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
3688    
3689                    if (language == null) {
3690                            query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_1);
3691                    }
3692                    else {
3693                            if (language.equals(StringPool.BLANK)) {
3694                                    query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_3);
3695                            }
3696                            else {
3697                                    query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_2);
3698                            }
3699                    }
3700    
3701                    if (orderByComparator != null) {
3702                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3703    
3704                            if (orderByConditionFields.length > 0) {
3705                                    query.append(WHERE_AND);
3706                            }
3707    
3708                            for (int i = 0; i < orderByConditionFields.length; i++) {
3709                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3710                                    query.append(orderByConditionFields[i]);
3711    
3712                                    if ((i + 1) < orderByConditionFields.length) {
3713                                            if (orderByComparator.isAscending() ^ previous) {
3714                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3715                                            }
3716                                            else {
3717                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3718                                            }
3719                                    }
3720                                    else {
3721                                            if (orderByComparator.isAscending() ^ previous) {
3722                                                    query.append(WHERE_GREATER_THAN);
3723                                            }
3724                                            else {
3725                                                    query.append(WHERE_LESSER_THAN);
3726                                            }
3727                                    }
3728                            }
3729    
3730                            query.append(ORDER_BY_CLAUSE);
3731    
3732                            String[] orderByFields = orderByComparator.getOrderByFields();
3733    
3734                            for (int i = 0; i < orderByFields.length; i++) {
3735                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3736                                    query.append(orderByFields[i]);
3737    
3738                                    if ((i + 1) < orderByFields.length) {
3739                                            if (orderByComparator.isAscending() ^ previous) {
3740                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3741                                            }
3742                                            else {
3743                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3744                                            }
3745                                    }
3746                                    else {
3747                                            if (orderByComparator.isAscending() ^ previous) {
3748                                                    query.append(ORDER_BY_ASC);
3749                                            }
3750                                            else {
3751                                                    query.append(ORDER_BY_DESC);
3752                                            }
3753                                    }
3754                            }
3755                    }
3756    
3757                    String sql = query.toString();
3758    
3759                    Query q = session.createQuery(sql);
3760    
3761                    q.setFirstResult(0);
3762                    q.setMaxResults(2);
3763    
3764                    QueryPos qPos = QueryPos.getInstance(q);
3765    
3766                    if (language != null) {
3767                            qPos.add(language);
3768                    }
3769    
3770                    if (orderByComparator != null) {
3771                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
3772    
3773                            for (Object value : values) {
3774                                    qPos.add(value);
3775                            }
3776                    }
3777    
3778                    List<DDMTemplate> list = q.list();
3779    
3780                    if (list.size() == 2) {
3781                            return list.get(1);
3782                    }
3783                    else {
3784                            return null;
3785                    }
3786            }
3787    
3788            /**
3789             * Returns all the d d m templates where groupId = &#63; and classNameId = &#63;.
3790             *
3791             * @param groupId the group ID
3792             * @param classNameId the class name ID
3793             * @return the matching d d m templates
3794             * @throws SystemException if a system exception occurred
3795             */
3796            public List<DDMTemplate> findByG_C(long groupId, long classNameId)
3797                    throws SystemException {
3798                    return findByG_C(groupId, classNameId, QueryUtil.ALL_POS,
3799                            QueryUtil.ALL_POS, null);
3800            }
3801    
3802            /**
3803             * Returns a range of all the d d m templates where groupId = &#63; and classNameId = &#63;.
3804             *
3805             * <p>
3806             * 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.
3807             * </p>
3808             *
3809             * @param groupId the group ID
3810             * @param classNameId the class name ID
3811             * @param start the lower bound of the range of d d m templates
3812             * @param end the upper bound of the range of d d m templates (not inclusive)
3813             * @return the range of matching d d m templates
3814             * @throws SystemException if a system exception occurred
3815             */
3816            public List<DDMTemplate> findByG_C(long groupId, long classNameId,
3817                    int start, int end) throws SystemException {
3818                    return findByG_C(groupId, classNameId, start, end, null);
3819            }
3820    
3821            /**
3822             * Returns an ordered range of all the d d m templates where groupId = &#63; and classNameId = &#63;.
3823             *
3824             * <p>
3825             * 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.
3826             * </p>
3827             *
3828             * @param groupId the group ID
3829             * @param classNameId the class name ID
3830             * @param start the lower bound of the range of d d m templates
3831             * @param end the upper bound of the range of d d m templates (not inclusive)
3832             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3833             * @return the ordered range of matching d d m templates
3834             * @throws SystemException if a system exception occurred
3835             */
3836            public List<DDMTemplate> findByG_C(long groupId, long classNameId,
3837                    int start, int end, OrderByComparator orderByComparator)
3838                    throws SystemException {
3839                    FinderPath finderPath = null;
3840                    Object[] finderArgs = null;
3841    
3842                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3843                                    (orderByComparator == null)) {
3844                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
3845                            finderArgs = new Object[] { groupId, classNameId };
3846                    }
3847                    else {
3848                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
3849                            finderArgs = new Object[] {
3850                                            groupId, classNameId,
3851                                            
3852                                            start, end, orderByComparator
3853                                    };
3854                    }
3855    
3856                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
3857                                    finderArgs, this);
3858    
3859                    if ((list != null) && !list.isEmpty()) {
3860                            for (DDMTemplate ddmTemplate : list) {
3861                                    if ((groupId != ddmTemplate.getGroupId()) ||
3862                                                    (classNameId != ddmTemplate.getClassNameId())) {
3863                                            list = null;
3864    
3865                                            break;
3866                                    }
3867                            }
3868                    }
3869    
3870                    if (list == null) {
3871                            StringBundler query = null;
3872    
3873                            if (orderByComparator != null) {
3874                                    query = new StringBundler(4 +
3875                                                    (orderByComparator.getOrderByFields().length * 3));
3876                            }
3877                            else {
3878                                    query = new StringBundler(3);
3879                            }
3880    
3881                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
3882    
3883                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3884    
3885                            query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
3886    
3887                            if (orderByComparator != null) {
3888                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3889                                            orderByComparator);
3890                            }
3891    
3892                            String sql = query.toString();
3893    
3894                            Session session = null;
3895    
3896                            try {
3897                                    session = openSession();
3898    
3899                                    Query q = session.createQuery(sql);
3900    
3901                                    QueryPos qPos = QueryPos.getInstance(q);
3902    
3903                                    qPos.add(groupId);
3904    
3905                                    qPos.add(classNameId);
3906    
3907                                    list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
3908                                                    start, end);
3909                            }
3910                            catch (Exception e) {
3911                                    throw processException(e);
3912                            }
3913                            finally {
3914                                    if (list == null) {
3915                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3916                                    }
3917                                    else {
3918                                            cacheResult(list);
3919    
3920                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3921                                    }
3922    
3923                                    closeSession(session);
3924                            }
3925                    }
3926    
3927                    return list;
3928            }
3929    
3930            /**
3931             * Returns the first d d m template in the ordered set where groupId = &#63; and classNameId = &#63;.
3932             *
3933             * @param groupId the group ID
3934             * @param classNameId the class name ID
3935             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3936             * @return the first matching d d m template
3937             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
3938             * @throws SystemException if a system exception occurred
3939             */
3940            public DDMTemplate findByG_C_First(long groupId, long classNameId,
3941                    OrderByComparator orderByComparator)
3942                    throws NoSuchTemplateException, SystemException {
3943                    DDMTemplate ddmTemplate = fetchByG_C_First(groupId, classNameId,
3944                                    orderByComparator);
3945    
3946                    if (ddmTemplate != null) {
3947                            return ddmTemplate;
3948                    }
3949    
3950                    StringBundler msg = new StringBundler(6);
3951    
3952                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3953    
3954                    msg.append("groupId=");
3955                    msg.append(groupId);
3956    
3957                    msg.append(", classNameId=");
3958                    msg.append(classNameId);
3959    
3960                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3961    
3962                    throw new NoSuchTemplateException(msg.toString());
3963            }
3964    
3965            /**
3966             * Returns the first d d m template in the ordered set where groupId = &#63; and classNameId = &#63;.
3967             *
3968             * @param groupId the group ID
3969             * @param classNameId the class name ID
3970             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3971             * @return the first matching d d m template, or <code>null</code> if a matching d d m template could not be found
3972             * @throws SystemException if a system exception occurred
3973             */
3974            public DDMTemplate fetchByG_C_First(long groupId, long classNameId,
3975                    OrderByComparator orderByComparator) throws SystemException {
3976                    List<DDMTemplate> list = findByG_C(groupId, classNameId, 0, 1,
3977                                    orderByComparator);
3978    
3979                    if (!list.isEmpty()) {
3980                            return list.get(0);
3981                    }
3982    
3983                    return null;
3984            }
3985    
3986            /**
3987             * Returns the last d d m template in the ordered set where groupId = &#63; and classNameId = &#63;.
3988             *
3989             * @param groupId the group ID
3990             * @param classNameId the class name ID
3991             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3992             * @return the last matching d d m template
3993             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
3994             * @throws SystemException if a system exception occurred
3995             */
3996            public DDMTemplate findByG_C_Last(long groupId, long classNameId,
3997                    OrderByComparator orderByComparator)
3998                    throws NoSuchTemplateException, SystemException {
3999                    DDMTemplate ddmTemplate = fetchByG_C_Last(groupId, classNameId,
4000                                    orderByComparator);
4001    
4002                    if (ddmTemplate != null) {
4003                            return ddmTemplate;
4004                    }
4005    
4006                    StringBundler msg = new StringBundler(6);
4007    
4008                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4009    
4010                    msg.append("groupId=");
4011                    msg.append(groupId);
4012    
4013                    msg.append(", classNameId=");
4014                    msg.append(classNameId);
4015    
4016                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4017    
4018                    throw new NoSuchTemplateException(msg.toString());
4019            }
4020    
4021            /**
4022             * Returns the last d d m template in the ordered set where groupId = &#63; and classNameId = &#63;.
4023             *
4024             * @param groupId the group ID
4025             * @param classNameId the class name ID
4026             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4027             * @return the last matching d d m template, or <code>null</code> if a matching d d m template could not be found
4028             * @throws SystemException if a system exception occurred
4029             */
4030            public DDMTemplate fetchByG_C_Last(long groupId, long classNameId,
4031                    OrderByComparator orderByComparator) throws SystemException {
4032                    int count = countByG_C(groupId, classNameId);
4033    
4034                    List<DDMTemplate> list = findByG_C(groupId, classNameId, count - 1,
4035                                    count, orderByComparator);
4036    
4037                    if (!list.isEmpty()) {
4038                            return list.get(0);
4039                    }
4040    
4041                    return null;
4042            }
4043    
4044            /**
4045             * Returns the d d m templates before and after the current d d m template in the ordered set where groupId = &#63; and classNameId = &#63;.
4046             *
4047             * @param templateId the primary key of the current d d m template
4048             * @param groupId the group ID
4049             * @param classNameId the class name ID
4050             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4051             * @return the previous, current, and next d d m template
4052             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
4053             * @throws SystemException if a system exception occurred
4054             */
4055            public DDMTemplate[] findByG_C_PrevAndNext(long templateId, long groupId,
4056                    long classNameId, OrderByComparator orderByComparator)
4057                    throws NoSuchTemplateException, SystemException {
4058                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
4059    
4060                    Session session = null;
4061    
4062                    try {
4063                            session = openSession();
4064    
4065                            DDMTemplate[] array = new DDMTemplateImpl[3];
4066    
4067                            array[0] = getByG_C_PrevAndNext(session, ddmTemplate, groupId,
4068                                            classNameId, orderByComparator, true);
4069    
4070                            array[1] = ddmTemplate;
4071    
4072                            array[2] = getByG_C_PrevAndNext(session, ddmTemplate, groupId,
4073                                            classNameId, orderByComparator, false);
4074    
4075                            return array;
4076                    }
4077                    catch (Exception e) {
4078                            throw processException(e);
4079                    }
4080                    finally {
4081                            closeSession(session);
4082                    }
4083            }
4084    
4085            protected DDMTemplate getByG_C_PrevAndNext(Session session,
4086                    DDMTemplate ddmTemplate, long groupId, long classNameId,
4087                    OrderByComparator orderByComparator, boolean previous) {
4088                    StringBundler query = null;
4089    
4090                    if (orderByComparator != null) {
4091                            query = new StringBundler(6 +
4092                                            (orderByComparator.getOrderByFields().length * 6));
4093                    }
4094                    else {
4095                            query = new StringBundler(3);
4096                    }
4097    
4098                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
4099    
4100                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
4101    
4102                    query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
4103    
4104                    if (orderByComparator != null) {
4105                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4106    
4107                            if (orderByConditionFields.length > 0) {
4108                                    query.append(WHERE_AND);
4109                            }
4110    
4111                            for (int i = 0; i < orderByConditionFields.length; i++) {
4112                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4113                                    query.append(orderByConditionFields[i]);
4114    
4115                                    if ((i + 1) < orderByConditionFields.length) {
4116                                            if (orderByComparator.isAscending() ^ previous) {
4117                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4118                                            }
4119                                            else {
4120                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4121                                            }
4122                                    }
4123                                    else {
4124                                            if (orderByComparator.isAscending() ^ previous) {
4125                                                    query.append(WHERE_GREATER_THAN);
4126                                            }
4127                                            else {
4128                                                    query.append(WHERE_LESSER_THAN);
4129                                            }
4130                                    }
4131                            }
4132    
4133                            query.append(ORDER_BY_CLAUSE);
4134    
4135                            String[] orderByFields = orderByComparator.getOrderByFields();
4136    
4137                            for (int i = 0; i < orderByFields.length; i++) {
4138                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4139                                    query.append(orderByFields[i]);
4140    
4141                                    if ((i + 1) < orderByFields.length) {
4142                                            if (orderByComparator.isAscending() ^ previous) {
4143                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4144                                            }
4145                                            else {
4146                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4147                                            }
4148                                    }
4149                                    else {
4150                                            if (orderByComparator.isAscending() ^ previous) {
4151                                                    query.append(ORDER_BY_ASC);
4152                                            }
4153                                            else {
4154                                                    query.append(ORDER_BY_DESC);
4155                                            }
4156                                    }
4157                            }
4158                    }
4159    
4160                    String sql = query.toString();
4161    
4162                    Query q = session.createQuery(sql);
4163    
4164                    q.setFirstResult(0);
4165                    q.setMaxResults(2);
4166    
4167                    QueryPos qPos = QueryPos.getInstance(q);
4168    
4169                    qPos.add(groupId);
4170    
4171                    qPos.add(classNameId);
4172    
4173                    if (orderByComparator != null) {
4174                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
4175    
4176                            for (Object value : values) {
4177                                    qPos.add(value);
4178                            }
4179                    }
4180    
4181                    List<DDMTemplate> list = q.list();
4182    
4183                    if (list.size() == 2) {
4184                            return list.get(1);
4185                    }
4186                    else {
4187                            return null;
4188                    }
4189            }
4190    
4191            /**
4192             * Returns all the d d m templates that the user has permission to view where groupId = &#63; and classNameId = &#63;.
4193             *
4194             * @param groupId the group ID
4195             * @param classNameId the class name ID
4196             * @return the matching d d m templates that the user has permission to view
4197             * @throws SystemException if a system exception occurred
4198             */
4199            public List<DDMTemplate> filterFindByG_C(long groupId, long classNameId)
4200                    throws SystemException {
4201                    return filterFindByG_C(groupId, classNameId, QueryUtil.ALL_POS,
4202                            QueryUtil.ALL_POS, null);
4203            }
4204    
4205            /**
4206             * Returns a range of all the d d m templates that the user has permission to view where groupId = &#63; and classNameId = &#63;.
4207             *
4208             * <p>
4209             * 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.
4210             * </p>
4211             *
4212             * @param groupId the group ID
4213             * @param classNameId the class name ID
4214             * @param start the lower bound of the range of d d m templates
4215             * @param end the upper bound of the range of d d m templates (not inclusive)
4216             * @return the range of matching d d m templates that the user has permission to view
4217             * @throws SystemException if a system exception occurred
4218             */
4219            public List<DDMTemplate> filterFindByG_C(long groupId, long classNameId,
4220                    int start, int end) throws SystemException {
4221                    return filterFindByG_C(groupId, classNameId, start, end, null);
4222            }
4223    
4224            /**
4225             * Returns an ordered range of all the d d m templates that the user has permissions to view where groupId = &#63; and classNameId = &#63;.
4226             *
4227             * <p>
4228             * 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.
4229             * </p>
4230             *
4231             * @param groupId the group ID
4232             * @param classNameId the class name ID
4233             * @param start the lower bound of the range of d d m templates
4234             * @param end the upper bound of the range of d d m templates (not inclusive)
4235             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4236             * @return the ordered range of matching d d m templates that the user has permission to view
4237             * @throws SystemException if a system exception occurred
4238             */
4239            public List<DDMTemplate> filterFindByG_C(long groupId, long classNameId,
4240                    int start, int end, OrderByComparator orderByComparator)
4241                    throws SystemException {
4242                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4243                            return findByG_C(groupId, classNameId, start, end, orderByComparator);
4244                    }
4245    
4246                    StringBundler query = null;
4247    
4248                    if (orderByComparator != null) {
4249                            query = new StringBundler(4 +
4250                                            (orderByComparator.getOrderByFields().length * 3));
4251                    }
4252                    else {
4253                            query = new StringBundler(3);
4254                    }
4255    
4256                    if (getDB().isSupportsInlineDistinct()) {
4257                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_WHERE);
4258                    }
4259                    else {
4260                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
4261                    }
4262    
4263                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
4264    
4265                    query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
4266    
4267                    if (!getDB().isSupportsInlineDistinct()) {
4268                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
4269                    }
4270    
4271                    if (orderByComparator != null) {
4272                            if (getDB().isSupportsInlineDistinct()) {
4273                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4274                                            orderByComparator);
4275                            }
4276                            else {
4277                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4278                                            orderByComparator);
4279                            }
4280                    }
4281    
4282                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4283                                    DDMTemplate.class.getName(),
4284                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4285    
4286                    Session session = null;
4287    
4288                    try {
4289                            session = openSession();
4290    
4291                            SQLQuery q = session.createSQLQuery(sql);
4292    
4293                            if (getDB().isSupportsInlineDistinct()) {
4294                                    q.addEntity(_FILTER_ENTITY_ALIAS, DDMTemplateImpl.class);
4295                            }
4296                            else {
4297                                    q.addEntity(_FILTER_ENTITY_TABLE, DDMTemplateImpl.class);
4298                            }
4299    
4300                            QueryPos qPos = QueryPos.getInstance(q);
4301    
4302                            qPos.add(groupId);
4303    
4304                            qPos.add(classNameId);
4305    
4306                            return (List<DDMTemplate>)QueryUtil.list(q, getDialect(), start, end);
4307                    }
4308                    catch (Exception e) {
4309                            throw processException(e);
4310                    }
4311                    finally {
4312                            closeSession(session);
4313                    }
4314            }
4315    
4316            /**
4317             * 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; and classNameId = &#63;.
4318             *
4319             * @param templateId the primary key of the current d d m template
4320             * @param groupId the group ID
4321             * @param classNameId the class name ID
4322             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4323             * @return the previous, current, and next d d m template
4324             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
4325             * @throws SystemException if a system exception occurred
4326             */
4327            public DDMTemplate[] filterFindByG_C_PrevAndNext(long templateId,
4328                    long groupId, long classNameId, OrderByComparator orderByComparator)
4329                    throws NoSuchTemplateException, SystemException {
4330                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4331                            return findByG_C_PrevAndNext(templateId, groupId, classNameId,
4332                                    orderByComparator);
4333                    }
4334    
4335                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
4336    
4337                    Session session = null;
4338    
4339                    try {
4340                            session = openSession();
4341    
4342                            DDMTemplate[] array = new DDMTemplateImpl[3];
4343    
4344                            array[0] = filterGetByG_C_PrevAndNext(session, ddmTemplate,
4345                                            groupId, classNameId, orderByComparator, true);
4346    
4347                            array[1] = ddmTemplate;
4348    
4349                            array[2] = filterGetByG_C_PrevAndNext(session, ddmTemplate,
4350                                            groupId, classNameId, orderByComparator, false);
4351    
4352                            return array;
4353                    }
4354                    catch (Exception e) {
4355                            throw processException(e);
4356                    }
4357                    finally {
4358                            closeSession(session);
4359                    }
4360            }
4361    
4362            protected DDMTemplate filterGetByG_C_PrevAndNext(Session session,
4363                    DDMTemplate ddmTemplate, long groupId, long classNameId,
4364                    OrderByComparator orderByComparator, boolean previous) {
4365                    StringBundler query = null;
4366    
4367                    if (orderByComparator != null) {
4368                            query = new StringBundler(6 +
4369                                            (orderByComparator.getOrderByFields().length * 6));
4370                    }
4371                    else {
4372                            query = new StringBundler(3);
4373                    }
4374    
4375                    if (getDB().isSupportsInlineDistinct()) {
4376                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_WHERE);
4377                    }
4378                    else {
4379                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
4380                    }
4381    
4382                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
4383    
4384                    query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
4385    
4386                    if (!getDB().isSupportsInlineDistinct()) {
4387                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
4388                    }
4389    
4390                    if (orderByComparator != null) {
4391                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4392    
4393                            if (orderByConditionFields.length > 0) {
4394                                    query.append(WHERE_AND);
4395                            }
4396    
4397                            for (int i = 0; i < orderByConditionFields.length; i++) {
4398                                    if (getDB().isSupportsInlineDistinct()) {
4399                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4400                                    }
4401                                    else {
4402                                            query.append(_ORDER_BY_ENTITY_TABLE);
4403                                    }
4404    
4405                                    query.append(orderByConditionFields[i]);
4406    
4407                                    if ((i + 1) < orderByConditionFields.length) {
4408                                            if (orderByComparator.isAscending() ^ previous) {
4409                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4410                                            }
4411                                            else {
4412                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4413                                            }
4414                                    }
4415                                    else {
4416                                            if (orderByComparator.isAscending() ^ previous) {
4417                                                    query.append(WHERE_GREATER_THAN);
4418                                            }
4419                                            else {
4420                                                    query.append(WHERE_LESSER_THAN);
4421                                            }
4422                                    }
4423                            }
4424    
4425                            query.append(ORDER_BY_CLAUSE);
4426    
4427                            String[] orderByFields = orderByComparator.getOrderByFields();
4428    
4429                            for (int i = 0; i < orderByFields.length; i++) {
4430                                    if (getDB().isSupportsInlineDistinct()) {
4431                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4432                                    }
4433                                    else {
4434                                            query.append(_ORDER_BY_ENTITY_TABLE);
4435                                    }
4436    
4437                                    query.append(orderByFields[i]);
4438    
4439                                    if ((i + 1) < orderByFields.length) {
4440                                            if (orderByComparator.isAscending() ^ previous) {
4441                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4442                                            }
4443                                            else {
4444                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4445                                            }
4446                                    }
4447                                    else {
4448                                            if (orderByComparator.isAscending() ^ previous) {
4449                                                    query.append(ORDER_BY_ASC);
4450                                            }
4451                                            else {
4452                                                    query.append(ORDER_BY_DESC);
4453                                            }
4454                                    }
4455                            }
4456                    }
4457    
4458                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4459                                    DDMTemplate.class.getName(),
4460                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4461    
4462                    SQLQuery q = session.createSQLQuery(sql);
4463    
4464                    q.setFirstResult(0);
4465                    q.setMaxResults(2);
4466    
4467                    if (getDB().isSupportsInlineDistinct()) {
4468                            q.addEntity(_FILTER_ENTITY_ALIAS, DDMTemplateImpl.class);
4469                    }
4470                    else {
4471                            q.addEntity(_FILTER_ENTITY_TABLE, DDMTemplateImpl.class);
4472                    }
4473    
4474                    QueryPos qPos = QueryPos.getInstance(q);
4475    
4476                    qPos.add(groupId);
4477    
4478                    qPos.add(classNameId);
4479    
4480                    if (orderByComparator != null) {
4481                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
4482    
4483                            for (Object value : values) {
4484                                    qPos.add(value);
4485                            }
4486                    }
4487    
4488                    List<DDMTemplate> list = q.list();
4489    
4490                    if (list.size() == 2) {
4491                            return list.get(1);
4492                    }
4493                    else {
4494                            return null;
4495                    }
4496            }
4497    
4498            /**
4499             * Returns the d d m template where groupId = &#63; and templateKey = &#63; or throws a {@link com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException} if it could not be found.
4500             *
4501             * @param groupId the group ID
4502             * @param templateKey the template key
4503             * @return the matching d d m template
4504             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
4505             * @throws SystemException if a system exception occurred
4506             */
4507            public DDMTemplate findByG_T(long groupId, String templateKey)
4508                    throws NoSuchTemplateException, SystemException {
4509                    DDMTemplate ddmTemplate = fetchByG_T(groupId, templateKey);
4510    
4511                    if (ddmTemplate == null) {
4512                            StringBundler msg = new StringBundler(6);
4513    
4514                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4515    
4516                            msg.append("groupId=");
4517                            msg.append(groupId);
4518    
4519                            msg.append(", templateKey=");
4520                            msg.append(templateKey);
4521    
4522                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4523    
4524                            if (_log.isWarnEnabled()) {
4525                                    _log.warn(msg.toString());
4526                            }
4527    
4528                            throw new NoSuchTemplateException(msg.toString());
4529                    }
4530    
4531                    return ddmTemplate;
4532            }
4533    
4534            /**
4535             * Returns the d d m template where groupId = &#63; and templateKey = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
4536             *
4537             * @param groupId the group ID
4538             * @param templateKey the template key
4539             * @return the matching d d m template, or <code>null</code> if a matching d d m template could not be found
4540             * @throws SystemException if a system exception occurred
4541             */
4542            public DDMTemplate fetchByG_T(long groupId, String templateKey)
4543                    throws SystemException {
4544                    return fetchByG_T(groupId, templateKey, true);
4545            }
4546    
4547            /**
4548             * Returns the d d m template where groupId = &#63; and templateKey = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
4549             *
4550             * @param groupId the group ID
4551             * @param templateKey the template key
4552             * @param retrieveFromCache whether to use the finder cache
4553             * @return the matching d d m template, or <code>null</code> if a matching d d m template could not be found
4554             * @throws SystemException if a system exception occurred
4555             */
4556            public DDMTemplate fetchByG_T(long groupId, String templateKey,
4557                    boolean retrieveFromCache) throws SystemException {
4558                    Object[] finderArgs = new Object[] { groupId, templateKey };
4559    
4560                    Object result = null;
4561    
4562                    if (retrieveFromCache) {
4563                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_T,
4564                                            finderArgs, this);
4565                    }
4566    
4567                    if (result instanceof DDMTemplate) {
4568                            DDMTemplate ddmTemplate = (DDMTemplate)result;
4569    
4570                            if ((groupId != ddmTemplate.getGroupId()) ||
4571                                            !Validator.equals(templateKey, ddmTemplate.getTemplateKey())) {
4572                                    result = null;
4573                            }
4574                    }
4575    
4576                    if (result == null) {
4577                            StringBundler query = new StringBundler(3);
4578    
4579                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
4580    
4581                            query.append(_FINDER_COLUMN_G_T_GROUPID_2);
4582    
4583                            if (templateKey == null) {
4584                                    query.append(_FINDER_COLUMN_G_T_TEMPLATEKEY_1);
4585                            }
4586                            else {
4587                                    if (templateKey.equals(StringPool.BLANK)) {
4588                                            query.append(_FINDER_COLUMN_G_T_TEMPLATEKEY_3);
4589                                    }
4590                                    else {
4591                                            query.append(_FINDER_COLUMN_G_T_TEMPLATEKEY_2);
4592                                    }
4593                            }
4594    
4595                            String sql = query.toString();
4596    
4597                            Session session = null;
4598    
4599                            try {
4600                                    session = openSession();
4601    
4602                                    Query q = session.createQuery(sql);
4603    
4604                                    QueryPos qPos = QueryPos.getInstance(q);
4605    
4606                                    qPos.add(groupId);
4607    
4608                                    if (templateKey != null) {
4609                                            qPos.add(templateKey);
4610                                    }
4611    
4612                                    List<DDMTemplate> list = q.list();
4613    
4614                                    result = list;
4615    
4616                                    DDMTemplate ddmTemplate = null;
4617    
4618                                    if (list.isEmpty()) {
4619                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_T,
4620                                                    finderArgs, list);
4621                                    }
4622                                    else {
4623                                            ddmTemplate = list.get(0);
4624    
4625                                            cacheResult(ddmTemplate);
4626    
4627                                            if ((ddmTemplate.getGroupId() != groupId) ||
4628                                                            (ddmTemplate.getTemplateKey() == null) ||
4629                                                            !ddmTemplate.getTemplateKey().equals(templateKey)) {
4630                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_T,
4631                                                            finderArgs, ddmTemplate);
4632                                            }
4633                                    }
4634    
4635                                    return ddmTemplate;
4636                            }
4637                            catch (Exception e) {
4638                                    throw processException(e);
4639                            }
4640                            finally {
4641                                    if (result == null) {
4642                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_T,
4643                                                    finderArgs);
4644                                    }
4645    
4646                                    closeSession(session);
4647                            }
4648                    }
4649                    else {
4650                            if (result instanceof List<?>) {
4651                                    return null;
4652                            }
4653                            else {
4654                                    return (DDMTemplate)result;
4655                            }
4656                    }
4657            }
4658    
4659            /**
4660             * Returns all the d d m templates where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
4661             *
4662             * @param groupId the group ID
4663             * @param classNameId the class name ID
4664             * @param classPK the class p k
4665             * @return the matching d d m templates
4666             * @throws SystemException if a system exception occurred
4667             */
4668            public List<DDMTemplate> findByG_C_C(long groupId, long classNameId,
4669                    long classPK) throws SystemException {
4670                    return findByG_C_C(groupId, classNameId, classPK, QueryUtil.ALL_POS,
4671                            QueryUtil.ALL_POS, null);
4672            }
4673    
4674            /**
4675             * Returns a range of all the d d m templates where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
4676             *
4677             * <p>
4678             * 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.
4679             * </p>
4680             *
4681             * @param groupId the group ID
4682             * @param classNameId the class name ID
4683             * @param classPK the class p k
4684             * @param start the lower bound of the range of d d m templates
4685             * @param end the upper bound of the range of d d m templates (not inclusive)
4686             * @return the range of matching d d m templates
4687             * @throws SystemException if a system exception occurred
4688             */
4689            public List<DDMTemplate> findByG_C_C(long groupId, long classNameId,
4690                    long classPK, int start, int end) throws SystemException {
4691                    return findByG_C_C(groupId, classNameId, classPK, start, end, null);
4692            }
4693    
4694            /**
4695             * Returns an ordered range of all the d d m templates where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
4696             *
4697             * <p>
4698             * 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.
4699             * </p>
4700             *
4701             * @param groupId the group ID
4702             * @param classNameId the class name ID
4703             * @param classPK the class p k
4704             * @param start the lower bound of the range of d d m templates
4705             * @param end the upper bound of the range of d d m templates (not inclusive)
4706             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4707             * @return the ordered range of matching d d m templates
4708             * @throws SystemException if a system exception occurred
4709             */
4710            public List<DDMTemplate> findByG_C_C(long groupId, long classNameId,
4711                    long classPK, int start, int end, OrderByComparator orderByComparator)
4712                    throws SystemException {
4713                    FinderPath finderPath = null;
4714                    Object[] finderArgs = null;
4715    
4716                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4717                                    (orderByComparator == null)) {
4718                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C;
4719                            finderArgs = new Object[] { groupId, classNameId, classPK };
4720                    }
4721                    else {
4722                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C;
4723                            finderArgs = new Object[] {
4724                                            groupId, classNameId, classPK,
4725                                            
4726                                            start, end, orderByComparator
4727                                    };
4728                    }
4729    
4730                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
4731                                    finderArgs, this);
4732    
4733                    if ((list != null) && !list.isEmpty()) {
4734                            for (DDMTemplate ddmTemplate : list) {
4735                                    if ((groupId != ddmTemplate.getGroupId()) ||
4736                                                    (classNameId != ddmTemplate.getClassNameId()) ||
4737                                                    (classPK != ddmTemplate.getClassPK())) {
4738                                            list = null;
4739    
4740                                            break;
4741                                    }
4742                            }
4743                    }
4744    
4745                    if (list == null) {
4746                            StringBundler query = null;
4747    
4748                            if (orderByComparator != null) {
4749                                    query = new StringBundler(5 +
4750                                                    (orderByComparator.getOrderByFields().length * 3));
4751                            }
4752                            else {
4753                                    query = new StringBundler(4);
4754                            }
4755    
4756                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
4757    
4758                            query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
4759    
4760                            query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
4761    
4762                            query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
4763    
4764                            if (orderByComparator != null) {
4765                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4766                                            orderByComparator);
4767                            }
4768    
4769                            String sql = query.toString();
4770    
4771                            Session session = null;
4772    
4773                            try {
4774                                    session = openSession();
4775    
4776                                    Query q = session.createQuery(sql);
4777    
4778                                    QueryPos qPos = QueryPos.getInstance(q);
4779    
4780                                    qPos.add(groupId);
4781    
4782                                    qPos.add(classNameId);
4783    
4784                                    qPos.add(classPK);
4785    
4786                                    list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
4787                                                    start, end);
4788                            }
4789                            catch (Exception e) {
4790                                    throw processException(e);
4791                            }
4792                            finally {
4793                                    if (list == null) {
4794                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
4795                                    }
4796                                    else {
4797                                            cacheResult(list);
4798    
4799                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
4800                                    }
4801    
4802                                    closeSession(session);
4803                            }
4804                    }
4805    
4806                    return list;
4807            }
4808    
4809            /**
4810             * Returns the first d d m template in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
4811             *
4812             * @param groupId the group ID
4813             * @param classNameId the class name ID
4814             * @param classPK the class p k
4815             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4816             * @return the first matching d d m template
4817             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
4818             * @throws SystemException if a system exception occurred
4819             */
4820            public DDMTemplate findByG_C_C_First(long groupId, long classNameId,
4821                    long classPK, OrderByComparator orderByComparator)
4822                    throws NoSuchTemplateException, SystemException {
4823                    DDMTemplate ddmTemplate = fetchByG_C_C_First(groupId, classNameId,
4824                                    classPK, orderByComparator);
4825    
4826                    if (ddmTemplate != null) {
4827                            return ddmTemplate;
4828                    }
4829    
4830                    StringBundler msg = new StringBundler(8);
4831    
4832                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4833    
4834                    msg.append("groupId=");
4835                    msg.append(groupId);
4836    
4837                    msg.append(", classNameId=");
4838                    msg.append(classNameId);
4839    
4840                    msg.append(", classPK=");
4841                    msg.append(classPK);
4842    
4843                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4844    
4845                    throw new NoSuchTemplateException(msg.toString());
4846            }
4847    
4848            /**
4849             * Returns the first d d m template in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
4850             *
4851             * @param groupId the group ID
4852             * @param classNameId the class name ID
4853             * @param classPK the class p k
4854             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4855             * @return the first matching d d m template, or <code>null</code> if a matching d d m template could not be found
4856             * @throws SystemException if a system exception occurred
4857             */
4858            public DDMTemplate fetchByG_C_C_First(long groupId, long classNameId,
4859                    long classPK, OrderByComparator orderByComparator)
4860                    throws SystemException {
4861                    List<DDMTemplate> list = findByG_C_C(groupId, classNameId, classPK, 0,
4862                                    1, orderByComparator);
4863    
4864                    if (!list.isEmpty()) {
4865                            return list.get(0);
4866                    }
4867    
4868                    return null;
4869            }
4870    
4871            /**
4872             * Returns the last d d m template in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
4873             *
4874             * @param groupId the group ID
4875             * @param classNameId the class name ID
4876             * @param classPK the class p k
4877             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4878             * @return the last matching d d m template
4879             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
4880             * @throws SystemException if a system exception occurred
4881             */
4882            public DDMTemplate findByG_C_C_Last(long groupId, long classNameId,
4883                    long classPK, OrderByComparator orderByComparator)
4884                    throws NoSuchTemplateException, SystemException {
4885                    DDMTemplate ddmTemplate = fetchByG_C_C_Last(groupId, classNameId,
4886                                    classPK, orderByComparator);
4887    
4888                    if (ddmTemplate != null) {
4889                            return ddmTemplate;
4890                    }
4891    
4892                    StringBundler msg = new StringBundler(8);
4893    
4894                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4895    
4896                    msg.append("groupId=");
4897                    msg.append(groupId);
4898    
4899                    msg.append(", classNameId=");
4900                    msg.append(classNameId);
4901    
4902                    msg.append(", classPK=");
4903                    msg.append(classPK);
4904    
4905                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4906    
4907                    throw new NoSuchTemplateException(msg.toString());
4908            }
4909    
4910            /**
4911             * Returns the last d d m template in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
4912             *
4913             * @param groupId the group ID
4914             * @param classNameId the class name ID
4915             * @param classPK the class p k
4916             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4917             * @return the last matching d d m template, or <code>null</code> if a matching d d m template could not be found
4918             * @throws SystemException if a system exception occurred
4919             */
4920            public DDMTemplate fetchByG_C_C_Last(long groupId, long classNameId,
4921                    long classPK, OrderByComparator orderByComparator)
4922                    throws SystemException {
4923                    int count = countByG_C_C(groupId, classNameId, classPK);
4924    
4925                    List<DDMTemplate> list = findByG_C_C(groupId, classNameId, classPK,
4926                                    count - 1, count, orderByComparator);
4927    
4928                    if (!list.isEmpty()) {
4929                            return list.get(0);
4930                    }
4931    
4932                    return null;
4933            }
4934    
4935            /**
4936             * Returns the d d m templates before and after the current d d m template in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
4937             *
4938             * @param templateId the primary key of the current d d m template
4939             * @param groupId the group ID
4940             * @param classNameId the class name ID
4941             * @param classPK the class p k
4942             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4943             * @return the previous, current, and next d d m template
4944             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
4945             * @throws SystemException if a system exception occurred
4946             */
4947            public DDMTemplate[] findByG_C_C_PrevAndNext(long templateId, long groupId,
4948                    long classNameId, long classPK, OrderByComparator orderByComparator)
4949                    throws NoSuchTemplateException, SystemException {
4950                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
4951    
4952                    Session session = null;
4953    
4954                    try {
4955                            session = openSession();
4956    
4957                            DDMTemplate[] array = new DDMTemplateImpl[3];
4958    
4959                            array[0] = getByG_C_C_PrevAndNext(session, ddmTemplate, groupId,
4960                                            classNameId, classPK, orderByComparator, true);
4961    
4962                            array[1] = ddmTemplate;
4963    
4964                            array[2] = getByG_C_C_PrevAndNext(session, ddmTemplate, groupId,
4965                                            classNameId, classPK, orderByComparator, false);
4966    
4967                            return array;
4968                    }
4969                    catch (Exception e) {
4970                            throw processException(e);
4971                    }
4972                    finally {
4973                            closeSession(session);
4974                    }
4975            }
4976    
4977            protected DDMTemplate getByG_C_C_PrevAndNext(Session session,
4978                    DDMTemplate ddmTemplate, long groupId, long classNameId, long classPK,
4979                    OrderByComparator orderByComparator, boolean previous) {
4980                    StringBundler query = null;
4981    
4982                    if (orderByComparator != null) {
4983                            query = new StringBundler(6 +
4984                                            (orderByComparator.getOrderByFields().length * 6));
4985                    }
4986                    else {
4987                            query = new StringBundler(3);
4988                    }
4989    
4990                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
4991    
4992                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
4993    
4994                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
4995    
4996                    query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
4997    
4998                    if (orderByComparator != null) {
4999                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5000    
5001                            if (orderByConditionFields.length > 0) {
5002                                    query.append(WHERE_AND);
5003                            }
5004    
5005                            for (int i = 0; i < orderByConditionFields.length; i++) {
5006                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5007                                    query.append(orderByConditionFields[i]);
5008    
5009                                    if ((i + 1) < orderByConditionFields.length) {
5010                                            if (orderByComparator.isAscending() ^ previous) {
5011                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5012                                            }
5013                                            else {
5014                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5015                                            }
5016                                    }
5017                                    else {
5018                                            if (orderByComparator.isAscending() ^ previous) {
5019                                                    query.append(WHERE_GREATER_THAN);
5020                                            }
5021                                            else {
5022                                                    query.append(WHERE_LESSER_THAN);
5023                                            }
5024                                    }
5025                            }
5026    
5027                            query.append(ORDER_BY_CLAUSE);
5028    
5029                            String[] orderByFields = orderByComparator.getOrderByFields();
5030    
5031                            for (int i = 0; i < orderByFields.length; i++) {
5032                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5033                                    query.append(orderByFields[i]);
5034    
5035                                    if ((i + 1) < orderByFields.length) {
5036                                            if (orderByComparator.isAscending() ^ previous) {
5037                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5038                                            }
5039                                            else {
5040                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5041                                            }
5042                                    }
5043                                    else {
5044                                            if (orderByComparator.isAscending() ^ previous) {
5045                                                    query.append(ORDER_BY_ASC);
5046                                            }
5047                                            else {
5048                                                    query.append(ORDER_BY_DESC);
5049                                            }
5050                                    }
5051                            }
5052                    }
5053    
5054                    String sql = query.toString();
5055    
5056                    Query q = session.createQuery(sql);
5057    
5058                    q.setFirstResult(0);
5059                    q.setMaxResults(2);
5060    
5061                    QueryPos qPos = QueryPos.getInstance(q);
5062    
5063                    qPos.add(groupId);
5064    
5065                    qPos.add(classNameId);
5066    
5067                    qPos.add(classPK);
5068    
5069                    if (orderByComparator != null) {
5070                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
5071    
5072                            for (Object value : values) {
5073                                    qPos.add(value);
5074                            }
5075                    }
5076    
5077                    List<DDMTemplate> list = q.list();
5078    
5079                    if (list.size() == 2) {
5080                            return list.get(1);
5081                    }
5082                    else {
5083                            return null;
5084                    }
5085            }
5086    
5087            /**
5088             * Returns all the d d m templates that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
5089             *
5090             * @param groupId the group ID
5091             * @param classNameId the class name ID
5092             * @param classPK the class p k
5093             * @return the matching d d m templates that the user has permission to view
5094             * @throws SystemException if a system exception occurred
5095             */
5096            public List<DDMTemplate> filterFindByG_C_C(long groupId, long classNameId,
5097                    long classPK) throws SystemException {
5098                    return filterFindByG_C_C(groupId, classNameId, classPK,
5099                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5100            }
5101    
5102            /**
5103             * Returns a range of all the d d m templates that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
5104             *
5105             * <p>
5106             * 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.
5107             * </p>
5108             *
5109             * @param groupId the group ID
5110             * @param classNameId the class name ID
5111             * @param classPK the class p k
5112             * @param start the lower bound of the range of d d m templates
5113             * @param end the upper bound of the range of d d m templates (not inclusive)
5114             * @return the range of matching d d m templates that the user has permission to view
5115             * @throws SystemException if a system exception occurred
5116             */
5117            public List<DDMTemplate> filterFindByG_C_C(long groupId, long classNameId,
5118                    long classPK, int start, int end) throws SystemException {
5119                    return filterFindByG_C_C(groupId, classNameId, classPK, start, end, null);
5120            }
5121    
5122            /**
5123             * Returns an ordered range of all the d d m templates that the user has permissions to view where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
5124             *
5125             * <p>
5126             * 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.
5127             * </p>
5128             *
5129             * @param groupId the group ID
5130             * @param classNameId the class name ID
5131             * @param classPK the class p k
5132             * @param start the lower bound of the range of d d m templates
5133             * @param end the upper bound of the range of d d m templates (not inclusive)
5134             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5135             * @return the ordered range of matching d d m templates that the user has permission to view
5136             * @throws SystemException if a system exception occurred
5137             */
5138            public List<DDMTemplate> filterFindByG_C_C(long groupId, long classNameId,
5139                    long classPK, int start, int end, OrderByComparator orderByComparator)
5140                    throws SystemException {
5141                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5142                            return findByG_C_C(groupId, classNameId, classPK, start, end,
5143                                    orderByComparator);
5144                    }
5145    
5146                    StringBundler query = null;
5147    
5148                    if (orderByComparator != null) {
5149                            query = new StringBundler(5 +
5150                                            (orderByComparator.getOrderByFields().length * 3));
5151                    }
5152                    else {
5153                            query = new StringBundler(4);
5154                    }
5155    
5156                    if (getDB().isSupportsInlineDistinct()) {
5157                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_WHERE);
5158                    }
5159                    else {
5160                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
5161                    }
5162    
5163                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
5164    
5165                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
5166    
5167                    query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
5168    
5169                    if (!getDB().isSupportsInlineDistinct()) {
5170                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
5171                    }
5172    
5173                    if (orderByComparator != null) {
5174                            if (getDB().isSupportsInlineDistinct()) {
5175                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5176                                            orderByComparator);
5177                            }
5178                            else {
5179                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5180                                            orderByComparator);
5181                            }
5182                    }
5183    
5184                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5185                                    DDMTemplate.class.getName(),
5186                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5187    
5188                    Session session = null;
5189    
5190                    try {
5191                            session = openSession();
5192    
5193                            SQLQuery q = session.createSQLQuery(sql);
5194    
5195                            if (getDB().isSupportsInlineDistinct()) {
5196                                    q.addEntity(_FILTER_ENTITY_ALIAS, DDMTemplateImpl.class);
5197                            }
5198                            else {
5199                                    q.addEntity(_FILTER_ENTITY_TABLE, DDMTemplateImpl.class);
5200                            }
5201    
5202                            QueryPos qPos = QueryPos.getInstance(q);
5203    
5204                            qPos.add(groupId);
5205    
5206                            qPos.add(classNameId);
5207    
5208                            qPos.add(classPK);
5209    
5210                            return (List<DDMTemplate>)QueryUtil.list(q, getDialect(), start, end);
5211                    }
5212                    catch (Exception e) {
5213                            throw processException(e);
5214                    }
5215                    finally {
5216                            closeSession(session);
5217                    }
5218            }
5219    
5220            /**
5221             * 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; and classNameId = &#63; and classPK = &#63;.
5222             *
5223             * @param templateId the primary key of the current d d m template
5224             * @param groupId the group ID
5225             * @param classNameId the class name ID
5226             * @param classPK the class p k
5227             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5228             * @return the previous, current, and next d d m template
5229             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
5230             * @throws SystemException if a system exception occurred
5231             */
5232            public DDMTemplate[] filterFindByG_C_C_PrevAndNext(long templateId,
5233                    long groupId, long classNameId, long classPK,
5234                    OrderByComparator orderByComparator)
5235                    throws NoSuchTemplateException, SystemException {
5236                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5237                            return findByG_C_C_PrevAndNext(templateId, groupId, classNameId,
5238                                    classPK, orderByComparator);
5239                    }
5240    
5241                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
5242    
5243                    Session session = null;
5244    
5245                    try {
5246                            session = openSession();
5247    
5248                            DDMTemplate[] array = new DDMTemplateImpl[3];
5249    
5250                            array[0] = filterGetByG_C_C_PrevAndNext(session, ddmTemplate,
5251                                            groupId, classNameId, classPK, orderByComparator, true);
5252    
5253                            array[1] = ddmTemplate;
5254    
5255                            array[2] = filterGetByG_C_C_PrevAndNext(session, ddmTemplate,
5256                                            groupId, classNameId, classPK, orderByComparator, false);
5257    
5258                            return array;
5259                    }
5260                    catch (Exception e) {
5261                            throw processException(e);
5262                    }
5263                    finally {
5264                            closeSession(session);
5265                    }
5266            }
5267    
5268            protected DDMTemplate filterGetByG_C_C_PrevAndNext(Session session,
5269                    DDMTemplate ddmTemplate, long groupId, long classNameId, long classPK,
5270                    OrderByComparator orderByComparator, boolean previous) {
5271                    StringBundler query = null;
5272    
5273                    if (orderByComparator != null) {
5274                            query = new StringBundler(6 +
5275                                            (orderByComparator.getOrderByFields().length * 6));
5276                    }
5277                    else {
5278                            query = new StringBundler(3);
5279                    }
5280    
5281                    if (getDB().isSupportsInlineDistinct()) {
5282                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_WHERE);
5283                    }
5284                    else {
5285                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
5286                    }
5287    
5288                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
5289    
5290                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
5291    
5292                    query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
5293    
5294                    if (!getDB().isSupportsInlineDistinct()) {
5295                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
5296                    }
5297    
5298                    if (orderByComparator != null) {
5299                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5300    
5301                            if (orderByConditionFields.length > 0) {
5302                                    query.append(WHERE_AND);
5303                            }
5304    
5305                            for (int i = 0; i < orderByConditionFields.length; i++) {
5306                                    if (getDB().isSupportsInlineDistinct()) {
5307                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5308                                    }
5309                                    else {
5310                                            query.append(_ORDER_BY_ENTITY_TABLE);
5311                                    }
5312    
5313                                    query.append(orderByConditionFields[i]);
5314    
5315                                    if ((i + 1) < orderByConditionFields.length) {
5316                                            if (orderByComparator.isAscending() ^ previous) {
5317                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5318                                            }
5319                                            else {
5320                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5321                                            }
5322                                    }
5323                                    else {
5324                                            if (orderByComparator.isAscending() ^ previous) {
5325                                                    query.append(WHERE_GREATER_THAN);
5326                                            }
5327                                            else {
5328                                                    query.append(WHERE_LESSER_THAN);
5329                                            }
5330                                    }
5331                            }
5332    
5333                            query.append(ORDER_BY_CLAUSE);
5334    
5335                            String[] orderByFields = orderByComparator.getOrderByFields();
5336    
5337                            for (int i = 0; i < orderByFields.length; i++) {
5338                                    if (getDB().isSupportsInlineDistinct()) {
5339                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5340                                    }
5341                                    else {
5342                                            query.append(_ORDER_BY_ENTITY_TABLE);
5343                                    }
5344    
5345                                    query.append(orderByFields[i]);
5346    
5347                                    if ((i + 1) < orderByFields.length) {
5348                                            if (orderByComparator.isAscending() ^ previous) {
5349                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5350                                            }
5351                                            else {
5352                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5353                                            }
5354                                    }
5355                                    else {
5356                                            if (orderByComparator.isAscending() ^ previous) {
5357                                                    query.append(ORDER_BY_ASC);
5358                                            }
5359                                            else {
5360                                                    query.append(ORDER_BY_DESC);
5361                                            }
5362                                    }
5363                            }
5364                    }
5365    
5366                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5367                                    DDMTemplate.class.getName(),
5368                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5369    
5370                    SQLQuery q = session.createSQLQuery(sql);
5371    
5372                    q.setFirstResult(0);
5373                    q.setMaxResults(2);
5374    
5375                    if (getDB().isSupportsInlineDistinct()) {
5376                            q.addEntity(_FILTER_ENTITY_ALIAS, DDMTemplateImpl.class);
5377                    }
5378                    else {
5379                            q.addEntity(_FILTER_ENTITY_TABLE, DDMTemplateImpl.class);
5380                    }
5381    
5382                    QueryPos qPos = QueryPos.getInstance(q);
5383    
5384                    qPos.add(groupId);
5385    
5386                    qPos.add(classNameId);
5387    
5388                    qPos.add(classPK);
5389    
5390                    if (orderByComparator != null) {
5391                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
5392    
5393                            for (Object value : values) {
5394                                    qPos.add(value);
5395                            }
5396                    }
5397    
5398                    List<DDMTemplate> list = q.list();
5399    
5400                    if (list.size() == 2) {
5401                            return list.get(1);
5402                    }
5403                    else {
5404                            return null;
5405                    }
5406            }
5407    
5408            /**
5409             * Returns all the d d m templates where classNameId = &#63; and classPK = &#63; and type = &#63;.
5410             *
5411             * @param classNameId the class name ID
5412             * @param classPK the class p k
5413             * @param type the type
5414             * @return the matching d d m templates
5415             * @throws SystemException if a system exception occurred
5416             */
5417            public List<DDMTemplate> findByC_C_T(long classNameId, long classPK,
5418                    String type) throws SystemException {
5419                    return findByC_C_T(classNameId, classPK, type, QueryUtil.ALL_POS,
5420                            QueryUtil.ALL_POS, null);
5421            }
5422    
5423            /**
5424             * Returns a range of all the d d m templates where classNameId = &#63; and classPK = &#63; and type = &#63;.
5425             *
5426             * <p>
5427             * 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.
5428             * </p>
5429             *
5430             * @param classNameId the class name ID
5431             * @param classPK the class p k
5432             * @param type the type
5433             * @param start the lower bound of the range of d d m templates
5434             * @param end the upper bound of the range of d d m templates (not inclusive)
5435             * @return the range of matching d d m templates
5436             * @throws SystemException if a system exception occurred
5437             */
5438            public List<DDMTemplate> findByC_C_T(long classNameId, long classPK,
5439                    String type, int start, int end) throws SystemException {
5440                    return findByC_C_T(classNameId, classPK, type, start, end, null);
5441            }
5442    
5443            /**
5444             * Returns an ordered range of all the d d m templates where classNameId = &#63; and classPK = &#63; and type = &#63;.
5445             *
5446             * <p>
5447             * 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.
5448             * </p>
5449             *
5450             * @param classNameId the class name ID
5451             * @param classPK the class p k
5452             * @param type the type
5453             * @param start the lower bound of the range of d d m templates
5454             * @param end the upper bound of the range of d d m templates (not inclusive)
5455             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5456             * @return the ordered range of matching d d m templates
5457             * @throws SystemException if a system exception occurred
5458             */
5459            public List<DDMTemplate> findByC_C_T(long classNameId, long classPK,
5460                    String type, int start, int end, OrderByComparator orderByComparator)
5461                    throws SystemException {
5462                    FinderPath finderPath = null;
5463                    Object[] finderArgs = null;
5464    
5465                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5466                                    (orderByComparator == null)) {
5467                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T;
5468                            finderArgs = new Object[] { classNameId, classPK, type };
5469                    }
5470                    else {
5471                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_T;
5472                            finderArgs = new Object[] {
5473                                            classNameId, classPK, type,
5474                                            
5475                                            start, end, orderByComparator
5476                                    };
5477                    }
5478    
5479                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
5480                                    finderArgs, this);
5481    
5482                    if ((list != null) && !list.isEmpty()) {
5483                            for (DDMTemplate ddmTemplate : list) {
5484                                    if ((classNameId != ddmTemplate.getClassNameId()) ||
5485                                                    (classPK != ddmTemplate.getClassPK()) ||
5486                                                    !Validator.equals(type, ddmTemplate.getType())) {
5487                                            list = null;
5488    
5489                                            break;
5490                                    }
5491                            }
5492                    }
5493    
5494                    if (list == null) {
5495                            StringBundler query = null;
5496    
5497                            if (orderByComparator != null) {
5498                                    query = new StringBundler(5 +
5499                                                    (orderByComparator.getOrderByFields().length * 3));
5500                            }
5501                            else {
5502                                    query = new StringBundler(4);
5503                            }
5504    
5505                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
5506    
5507                            query.append(_FINDER_COLUMN_C_C_T_CLASSNAMEID_2);
5508    
5509                            query.append(_FINDER_COLUMN_C_C_T_CLASSPK_2);
5510    
5511                            if (type == null) {
5512                                    query.append(_FINDER_COLUMN_C_C_T_TYPE_1);
5513                            }
5514                            else {
5515                                    if (type.equals(StringPool.BLANK)) {
5516                                            query.append(_FINDER_COLUMN_C_C_T_TYPE_3);
5517                                    }
5518                                    else {
5519                                            query.append(_FINDER_COLUMN_C_C_T_TYPE_2);
5520                                    }
5521                            }
5522    
5523                            if (orderByComparator != null) {
5524                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5525                                            orderByComparator);
5526                            }
5527    
5528                            String sql = query.toString();
5529    
5530                            Session session = null;
5531    
5532                            try {
5533                                    session = openSession();
5534    
5535                                    Query q = session.createQuery(sql);
5536    
5537                                    QueryPos qPos = QueryPos.getInstance(q);
5538    
5539                                    qPos.add(classNameId);
5540    
5541                                    qPos.add(classPK);
5542    
5543                                    if (type != null) {
5544                                            qPos.add(type);
5545                                    }
5546    
5547                                    list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
5548                                                    start, end);
5549                            }
5550                            catch (Exception e) {
5551                                    throw processException(e);
5552                            }
5553                            finally {
5554                                    if (list == null) {
5555                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
5556                                    }
5557                                    else {
5558                                            cacheResult(list);
5559    
5560                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
5561                                    }
5562    
5563                                    closeSession(session);
5564                            }
5565                    }
5566    
5567                    return list;
5568            }
5569    
5570            /**
5571             * Returns the first d d m template in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63;.
5572             *
5573             * @param classNameId the class name ID
5574             * @param classPK the class p k
5575             * @param type the type
5576             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5577             * @return the first matching d d m template
5578             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
5579             * @throws SystemException if a system exception occurred
5580             */
5581            public DDMTemplate findByC_C_T_First(long classNameId, long classPK,
5582                    String type, OrderByComparator orderByComparator)
5583                    throws NoSuchTemplateException, SystemException {
5584                    DDMTemplate ddmTemplate = fetchByC_C_T_First(classNameId, classPK,
5585                                    type, orderByComparator);
5586    
5587                    if (ddmTemplate != null) {
5588                            return ddmTemplate;
5589                    }
5590    
5591                    StringBundler msg = new StringBundler(8);
5592    
5593                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5594    
5595                    msg.append("classNameId=");
5596                    msg.append(classNameId);
5597    
5598                    msg.append(", classPK=");
5599                    msg.append(classPK);
5600    
5601                    msg.append(", type=");
5602                    msg.append(type);
5603    
5604                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5605    
5606                    throw new NoSuchTemplateException(msg.toString());
5607            }
5608    
5609            /**
5610             * Returns the first d d m template in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63;.
5611             *
5612             * @param classNameId the class name ID
5613             * @param classPK the class p k
5614             * @param type the type
5615             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5616             * @return the first matching d d m template, or <code>null</code> if a matching d d m template could not be found
5617             * @throws SystemException if a system exception occurred
5618             */
5619            public DDMTemplate fetchByC_C_T_First(long classNameId, long classPK,
5620                    String type, OrderByComparator orderByComparator)
5621                    throws SystemException {
5622                    List<DDMTemplate> list = findByC_C_T(classNameId, classPK, type, 0, 1,
5623                                    orderByComparator);
5624    
5625                    if (!list.isEmpty()) {
5626                            return list.get(0);
5627                    }
5628    
5629                    return null;
5630            }
5631    
5632            /**
5633             * Returns the last d d m template in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63;.
5634             *
5635             * @param classNameId the class name ID
5636             * @param classPK the class p k
5637             * @param type the type
5638             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5639             * @return the last matching d d m template
5640             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
5641             * @throws SystemException if a system exception occurred
5642             */
5643            public DDMTemplate findByC_C_T_Last(long classNameId, long classPK,
5644                    String type, OrderByComparator orderByComparator)
5645                    throws NoSuchTemplateException, SystemException {
5646                    DDMTemplate ddmTemplate = fetchByC_C_T_Last(classNameId, classPK, type,
5647                                    orderByComparator);
5648    
5649                    if (ddmTemplate != null) {
5650                            return ddmTemplate;
5651                    }
5652    
5653                    StringBundler msg = new StringBundler(8);
5654    
5655                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5656    
5657                    msg.append("classNameId=");
5658                    msg.append(classNameId);
5659    
5660                    msg.append(", classPK=");
5661                    msg.append(classPK);
5662    
5663                    msg.append(", type=");
5664                    msg.append(type);
5665    
5666                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5667    
5668                    throw new NoSuchTemplateException(msg.toString());
5669            }
5670    
5671            /**
5672             * Returns the last d d m template in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63;.
5673             *
5674             * @param classNameId the class name ID
5675             * @param classPK the class p k
5676             * @param type the type
5677             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5678             * @return the last matching d d m template, or <code>null</code> if a matching d d m template could not be found
5679             * @throws SystemException if a system exception occurred
5680             */
5681            public DDMTemplate fetchByC_C_T_Last(long classNameId, long classPK,
5682                    String type, OrderByComparator orderByComparator)
5683                    throws SystemException {
5684                    int count = countByC_C_T(classNameId, classPK, type);
5685    
5686                    List<DDMTemplate> list = findByC_C_T(classNameId, classPK, type,
5687                                    count - 1, count, orderByComparator);
5688    
5689                    if (!list.isEmpty()) {
5690                            return list.get(0);
5691                    }
5692    
5693                    return null;
5694            }
5695    
5696            /**
5697             * Returns the d d m templates before and after the current d d m template in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63;.
5698             *
5699             * @param templateId the primary key of the current d d m template
5700             * @param classNameId the class name ID
5701             * @param classPK the class p k
5702             * @param type the type
5703             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5704             * @return the previous, current, and next d d m template
5705             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
5706             * @throws SystemException if a system exception occurred
5707             */
5708            public DDMTemplate[] findByC_C_T_PrevAndNext(long templateId,
5709                    long classNameId, long classPK, String type,
5710                    OrderByComparator orderByComparator)
5711                    throws NoSuchTemplateException, SystemException {
5712                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
5713    
5714                    Session session = null;
5715    
5716                    try {
5717                            session = openSession();
5718    
5719                            DDMTemplate[] array = new DDMTemplateImpl[3];
5720    
5721                            array[0] = getByC_C_T_PrevAndNext(session, ddmTemplate,
5722                                            classNameId, classPK, type, orderByComparator, true);
5723    
5724                            array[1] = ddmTemplate;
5725    
5726                            array[2] = getByC_C_T_PrevAndNext(session, ddmTemplate,
5727                                            classNameId, classPK, type, orderByComparator, false);
5728    
5729                            return array;
5730                    }
5731                    catch (Exception e) {
5732                            throw processException(e);
5733                    }
5734                    finally {
5735                            closeSession(session);
5736                    }
5737            }
5738    
5739            protected DDMTemplate getByC_C_T_PrevAndNext(Session session,
5740                    DDMTemplate ddmTemplate, long classNameId, long classPK, String type,
5741                    OrderByComparator orderByComparator, boolean previous) {
5742                    StringBundler query = null;
5743    
5744                    if (orderByComparator != null) {
5745                            query = new StringBundler(6 +
5746                                            (orderByComparator.getOrderByFields().length * 6));
5747                    }
5748                    else {
5749                            query = new StringBundler(3);
5750                    }
5751    
5752                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
5753    
5754                    query.append(_FINDER_COLUMN_C_C_T_CLASSNAMEID_2);
5755    
5756                    query.append(_FINDER_COLUMN_C_C_T_CLASSPK_2);
5757    
5758                    if (type == null) {
5759                            query.append(_FINDER_COLUMN_C_C_T_TYPE_1);
5760                    }
5761                    else {
5762                            if (type.equals(StringPool.BLANK)) {
5763                                    query.append(_FINDER_COLUMN_C_C_T_TYPE_3);
5764                            }
5765                            else {
5766                                    query.append(_FINDER_COLUMN_C_C_T_TYPE_2);
5767                            }
5768                    }
5769    
5770                    if (orderByComparator != null) {
5771                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5772    
5773                            if (orderByConditionFields.length > 0) {
5774                                    query.append(WHERE_AND);
5775                            }
5776    
5777                            for (int i = 0; i < orderByConditionFields.length; i++) {
5778                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5779                                    query.append(orderByConditionFields[i]);
5780    
5781                                    if ((i + 1) < orderByConditionFields.length) {
5782                                            if (orderByComparator.isAscending() ^ previous) {
5783                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5784                                            }
5785                                            else {
5786                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5787                                            }
5788                                    }
5789                                    else {
5790                                            if (orderByComparator.isAscending() ^ previous) {
5791                                                    query.append(WHERE_GREATER_THAN);
5792                                            }
5793                                            else {
5794                                                    query.append(WHERE_LESSER_THAN);
5795                                            }
5796                                    }
5797                            }
5798    
5799                            query.append(ORDER_BY_CLAUSE);
5800    
5801                            String[] orderByFields = orderByComparator.getOrderByFields();
5802    
5803                            for (int i = 0; i < orderByFields.length; i++) {
5804                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5805                                    query.append(orderByFields[i]);
5806    
5807                                    if ((i + 1) < orderByFields.length) {
5808                                            if (orderByComparator.isAscending() ^ previous) {
5809                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5810                                            }
5811                                            else {
5812                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5813                                            }
5814                                    }
5815                                    else {
5816                                            if (orderByComparator.isAscending() ^ previous) {
5817                                                    query.append(ORDER_BY_ASC);
5818                                            }
5819                                            else {
5820                                                    query.append(ORDER_BY_DESC);
5821                                            }
5822                                    }
5823                            }
5824                    }
5825    
5826                    String sql = query.toString();
5827    
5828                    Query q = session.createQuery(sql);
5829    
5830                    q.setFirstResult(0);
5831                    q.setMaxResults(2);
5832    
5833                    QueryPos qPos = QueryPos.getInstance(q);
5834    
5835                    qPos.add(classNameId);
5836    
5837                    qPos.add(classPK);
5838    
5839                    if (type != null) {
5840                            qPos.add(type);
5841                    }
5842    
5843                    if (orderByComparator != null) {
5844                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
5845    
5846                            for (Object value : values) {
5847                                    qPos.add(value);
5848                            }
5849                    }
5850    
5851                    List<DDMTemplate> list = q.list();
5852    
5853                    if (list.size() == 2) {
5854                            return list.get(1);
5855                    }
5856                    else {
5857                            return null;
5858                    }
5859            }
5860    
5861            /**
5862             * Returns all the d d m templates where classNameId = &#63; and classPK = &#63; and type = &#63; and mode = &#63;.
5863             *
5864             * @param classNameId the class name ID
5865             * @param classPK the class p k
5866             * @param type the type
5867             * @param mode the mode
5868             * @return the matching d d m templates
5869             * @throws SystemException if a system exception occurred
5870             */
5871            public List<DDMTemplate> findByC_C_T_M(long classNameId, long classPK,
5872                    String type, String mode) throws SystemException {
5873                    return findByC_C_T_M(classNameId, classPK, type, mode,
5874                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5875            }
5876    
5877            /**
5878             * Returns a range of all the d d m templates where classNameId = &#63; and classPK = &#63; and type = &#63; and mode = &#63;.
5879             *
5880             * <p>
5881             * 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.
5882             * </p>
5883             *
5884             * @param classNameId the class name ID
5885             * @param classPK the class p k
5886             * @param type the type
5887             * @param mode the mode
5888             * @param start the lower bound of the range of d d m templates
5889             * @param end the upper bound of the range of d d m templates (not inclusive)
5890             * @return the range of matching d d m templates
5891             * @throws SystemException if a system exception occurred
5892             */
5893            public List<DDMTemplate> findByC_C_T_M(long classNameId, long classPK,
5894                    String type, String mode, int start, int end) throws SystemException {
5895                    return findByC_C_T_M(classNameId, classPK, type, mode, start, end, null);
5896            }
5897    
5898            /**
5899             * Returns an ordered range of all the d d m templates where classNameId = &#63; and classPK = &#63; and type = &#63; and mode = &#63;.
5900             *
5901             * <p>
5902             * 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.
5903             * </p>
5904             *
5905             * @param classNameId the class name ID
5906             * @param classPK the class p k
5907             * @param type the type
5908             * @param mode the mode
5909             * @param start the lower bound of the range of d d m templates
5910             * @param end the upper bound of the range of d d m templates (not inclusive)
5911             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5912             * @return the ordered range of matching d d m templates
5913             * @throws SystemException if a system exception occurred
5914             */
5915            public List<DDMTemplate> findByC_C_T_M(long classNameId, long classPK,
5916                    String type, String mode, int start, int end,
5917                    OrderByComparator orderByComparator) throws SystemException {
5918                    FinderPath finderPath = null;
5919                    Object[] finderArgs = null;
5920    
5921                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5922                                    (orderByComparator == null)) {
5923                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T_M;
5924                            finderArgs = new Object[] { classNameId, classPK, type, mode };
5925                    }
5926                    else {
5927                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_T_M;
5928                            finderArgs = new Object[] {
5929                                            classNameId, classPK, type, mode,
5930                                            
5931                                            start, end, orderByComparator
5932                                    };
5933                    }
5934    
5935                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
5936                                    finderArgs, this);
5937    
5938                    if ((list != null) && !list.isEmpty()) {
5939                            for (DDMTemplate ddmTemplate : list) {
5940                                    if ((classNameId != ddmTemplate.getClassNameId()) ||
5941                                                    (classPK != ddmTemplate.getClassPK()) ||
5942                                                    !Validator.equals(type, ddmTemplate.getType()) ||
5943                                                    !Validator.equals(mode, ddmTemplate.getMode())) {
5944                                            list = null;
5945    
5946                                            break;
5947                                    }
5948                            }
5949                    }
5950    
5951                    if (list == null) {
5952                            StringBundler query = null;
5953    
5954                            if (orderByComparator != null) {
5955                                    query = new StringBundler(6 +
5956                                                    (orderByComparator.getOrderByFields().length * 3));
5957                            }
5958                            else {
5959                                    query = new StringBundler(5);
5960                            }
5961    
5962                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
5963    
5964                            query.append(_FINDER_COLUMN_C_C_T_M_CLASSNAMEID_2);
5965    
5966                            query.append(_FINDER_COLUMN_C_C_T_M_CLASSPK_2);
5967    
5968                            if (type == null) {
5969                                    query.append(_FINDER_COLUMN_C_C_T_M_TYPE_1);
5970                            }
5971                            else {
5972                                    if (type.equals(StringPool.BLANK)) {
5973                                            query.append(_FINDER_COLUMN_C_C_T_M_TYPE_3);
5974                                    }
5975                                    else {
5976                                            query.append(_FINDER_COLUMN_C_C_T_M_TYPE_2);
5977                                    }
5978                            }
5979    
5980                            if (mode == null) {
5981                                    query.append(_FINDER_COLUMN_C_C_T_M_MODE_1);
5982                            }
5983                            else {
5984                                    if (mode.equals(StringPool.BLANK)) {
5985                                            query.append(_FINDER_COLUMN_C_C_T_M_MODE_3);
5986                                    }
5987                                    else {
5988                                            query.append(_FINDER_COLUMN_C_C_T_M_MODE_2);
5989                                    }
5990                            }
5991    
5992                            if (orderByComparator != null) {
5993                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5994                                            orderByComparator);
5995                            }
5996    
5997                            String sql = query.toString();
5998    
5999                            Session session = null;
6000    
6001                            try {
6002                                    session = openSession();
6003    
6004                                    Query q = session.createQuery(sql);
6005    
6006                                    QueryPos qPos = QueryPos.getInstance(q);
6007    
6008                                    qPos.add(classNameId);
6009    
6010                                    qPos.add(classPK);
6011    
6012                                    if (type != null) {
6013                                            qPos.add(type);
6014                                    }
6015    
6016                                    if (mode != null) {
6017                                            qPos.add(mode);
6018                                    }
6019    
6020                                    list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
6021                                                    start, end);
6022                            }
6023                            catch (Exception e) {
6024                                    throw processException(e);
6025                            }
6026                            finally {
6027                                    if (list == null) {
6028                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
6029                                    }
6030                                    else {
6031                                            cacheResult(list);
6032    
6033                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
6034                                    }
6035    
6036                                    closeSession(session);
6037                            }
6038                    }
6039    
6040                    return list;
6041            }
6042    
6043            /**
6044             * Returns the first d d m template in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63; and mode = &#63;.
6045             *
6046             * @param classNameId the class name ID
6047             * @param classPK the class p k
6048             * @param type the type
6049             * @param mode the mode
6050             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6051             * @return the first matching d d m template
6052             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
6053             * @throws SystemException if a system exception occurred
6054             */
6055            public DDMTemplate findByC_C_T_M_First(long classNameId, long classPK,
6056                    String type, String mode, OrderByComparator orderByComparator)
6057                    throws NoSuchTemplateException, SystemException {
6058                    DDMTemplate ddmTemplate = fetchByC_C_T_M_First(classNameId, classPK,
6059                                    type, mode, orderByComparator);
6060    
6061                    if (ddmTemplate != null) {
6062                            return ddmTemplate;
6063                    }
6064    
6065                    StringBundler msg = new StringBundler(10);
6066    
6067                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6068    
6069                    msg.append("classNameId=");
6070                    msg.append(classNameId);
6071    
6072                    msg.append(", classPK=");
6073                    msg.append(classPK);
6074    
6075                    msg.append(", type=");
6076                    msg.append(type);
6077    
6078                    msg.append(", mode=");
6079                    msg.append(mode);
6080    
6081                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6082    
6083                    throw new NoSuchTemplateException(msg.toString());
6084            }
6085    
6086            /**
6087             * Returns the first d d m template in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63; and mode = &#63;.
6088             *
6089             * @param classNameId the class name ID
6090             * @param classPK the class p k
6091             * @param type the type
6092             * @param mode the mode
6093             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6094             * @return the first matching d d m template, or <code>null</code> if a matching d d m template could not be found
6095             * @throws SystemException if a system exception occurred
6096             */
6097            public DDMTemplate fetchByC_C_T_M_First(long classNameId, long classPK,
6098                    String type, String mode, OrderByComparator orderByComparator)
6099                    throws SystemException {
6100                    List<DDMTemplate> list = findByC_C_T_M(classNameId, classPK, type,
6101                                    mode, 0, 1, orderByComparator);
6102    
6103                    if (!list.isEmpty()) {
6104                            return list.get(0);
6105                    }
6106    
6107                    return null;
6108            }
6109    
6110            /**
6111             * Returns the last d d m template in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63; and mode = &#63;.
6112             *
6113             * @param classNameId the class name ID
6114             * @param classPK the class p k
6115             * @param type the type
6116             * @param mode the mode
6117             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6118             * @return the last matching d d m template
6119             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
6120             * @throws SystemException if a system exception occurred
6121             */
6122            public DDMTemplate findByC_C_T_M_Last(long classNameId, long classPK,
6123                    String type, String mode, OrderByComparator orderByComparator)
6124                    throws NoSuchTemplateException, SystemException {
6125                    DDMTemplate ddmTemplate = fetchByC_C_T_M_Last(classNameId, classPK,
6126                                    type, mode, orderByComparator);
6127    
6128                    if (ddmTemplate != null) {
6129                            return ddmTemplate;
6130                    }
6131    
6132                    StringBundler msg = new StringBundler(10);
6133    
6134                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6135    
6136                    msg.append("classNameId=");
6137                    msg.append(classNameId);
6138    
6139                    msg.append(", classPK=");
6140                    msg.append(classPK);
6141    
6142                    msg.append(", type=");
6143                    msg.append(type);
6144    
6145                    msg.append(", mode=");
6146                    msg.append(mode);
6147    
6148                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6149    
6150                    throw new NoSuchTemplateException(msg.toString());
6151            }
6152    
6153            /**
6154             * Returns the last d d m template in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63; and mode = &#63;.
6155             *
6156             * @param classNameId the class name ID
6157             * @param classPK the class p k
6158             * @param type the type
6159             * @param mode the mode
6160             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6161             * @return the last matching d d m template, or <code>null</code> if a matching d d m template could not be found
6162             * @throws SystemException if a system exception occurred
6163             */
6164            public DDMTemplate fetchByC_C_T_M_Last(long classNameId, long classPK,
6165                    String type, String mode, OrderByComparator orderByComparator)
6166                    throws SystemException {
6167                    int count = countByC_C_T_M(classNameId, classPK, type, mode);
6168    
6169                    List<DDMTemplate> list = findByC_C_T_M(classNameId, classPK, type,
6170                                    mode, count - 1, count, orderByComparator);
6171    
6172                    if (!list.isEmpty()) {
6173                            return list.get(0);
6174                    }
6175    
6176                    return null;
6177            }
6178    
6179            /**
6180             * Returns the d d m templates before and after the current d d m template in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63; and mode = &#63;.
6181             *
6182             * @param templateId the primary key of the current d d m template
6183             * @param classNameId the class name ID
6184             * @param classPK the class p k
6185             * @param type the type
6186             * @param mode the mode
6187             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6188             * @return the previous, current, and next d d m template
6189             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
6190             * @throws SystemException if a system exception occurred
6191             */
6192            public DDMTemplate[] findByC_C_T_M_PrevAndNext(long templateId,
6193                    long classNameId, long classPK, String type, String mode,
6194                    OrderByComparator orderByComparator)
6195                    throws NoSuchTemplateException, SystemException {
6196                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
6197    
6198                    Session session = null;
6199    
6200                    try {
6201                            session = openSession();
6202    
6203                            DDMTemplate[] array = new DDMTemplateImpl[3];
6204    
6205                            array[0] = getByC_C_T_M_PrevAndNext(session, ddmTemplate,
6206                                            classNameId, classPK, type, mode, orderByComparator, true);
6207    
6208                            array[1] = ddmTemplate;
6209    
6210                            array[2] = getByC_C_T_M_PrevAndNext(session, ddmTemplate,
6211                                            classNameId, classPK, type, mode, orderByComparator, false);
6212    
6213                            return array;
6214                    }
6215                    catch (Exception e) {
6216                            throw processException(e);
6217                    }
6218                    finally {
6219                            closeSession(session);
6220                    }
6221            }
6222    
6223            protected DDMTemplate getByC_C_T_M_PrevAndNext(Session session,
6224                    DDMTemplate ddmTemplate, long classNameId, long classPK, String type,
6225                    String mode, OrderByComparator orderByComparator, boolean previous) {
6226                    StringBundler query = null;
6227    
6228                    if (orderByComparator != null) {
6229                            query = new StringBundler(6 +
6230                                            (orderByComparator.getOrderByFields().length * 6));
6231                    }
6232                    else {
6233                            query = new StringBundler(3);
6234                    }
6235    
6236                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
6237    
6238                    query.append(_FINDER_COLUMN_C_C_T_M_CLASSNAMEID_2);
6239    
6240                    query.append(_FINDER_COLUMN_C_C_T_M_CLASSPK_2);
6241    
6242                    if (type == null) {
6243                            query.append(_FINDER_COLUMN_C_C_T_M_TYPE_1);
6244                    }
6245                    else {
6246                            if (type.equals(StringPool.BLANK)) {
6247                                    query.append(_FINDER_COLUMN_C_C_T_M_TYPE_3);
6248                            }
6249                            else {
6250                                    query.append(_FINDER_COLUMN_C_C_T_M_TYPE_2);
6251                            }
6252                    }
6253    
6254                    if (mode == null) {
6255                            query.append(_FINDER_COLUMN_C_C_T_M_MODE_1);
6256                    }
6257                    else {
6258                            if (mode.equals(StringPool.BLANK)) {
6259                                    query.append(_FINDER_COLUMN_C_C_T_M_MODE_3);
6260                            }
6261                            else {
6262                                    query.append(_FINDER_COLUMN_C_C_T_M_MODE_2);
6263                            }
6264                    }
6265    
6266                    if (orderByComparator != null) {
6267                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6268    
6269                            if (orderByConditionFields.length > 0) {
6270                                    query.append(WHERE_AND);
6271                            }
6272    
6273                            for (int i = 0; i < orderByConditionFields.length; i++) {
6274                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6275                                    query.append(orderByConditionFields[i]);
6276    
6277                                    if ((i + 1) < orderByConditionFields.length) {
6278                                            if (orderByComparator.isAscending() ^ previous) {
6279                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6280                                            }
6281                                            else {
6282                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6283                                            }
6284                                    }
6285                                    else {
6286                                            if (orderByComparator.isAscending() ^ previous) {
6287                                                    query.append(WHERE_GREATER_THAN);
6288                                            }
6289                                            else {
6290                                                    query.append(WHERE_LESSER_THAN);
6291                                            }
6292                                    }
6293                            }
6294    
6295                            query.append(ORDER_BY_CLAUSE);
6296    
6297                            String[] orderByFields = orderByComparator.getOrderByFields();
6298    
6299                            for (int i = 0; i < orderByFields.length; i++) {
6300                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6301                                    query.append(orderByFields[i]);
6302    
6303                                    if ((i + 1) < orderByFields.length) {
6304                                            if (orderByComparator.isAscending() ^ previous) {
6305                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6306                                            }
6307                                            else {
6308                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6309                                            }
6310                                    }
6311                                    else {
6312                                            if (orderByComparator.isAscending() ^ previous) {
6313                                                    query.append(ORDER_BY_ASC);
6314                                            }
6315                                            else {
6316                                                    query.append(ORDER_BY_DESC);
6317                                            }
6318                                    }
6319                            }
6320                    }
6321    
6322                    String sql = query.toString();
6323    
6324                    Query q = session.createQuery(sql);
6325    
6326                    q.setFirstResult(0);
6327                    q.setMaxResults(2);
6328    
6329                    QueryPos qPos = QueryPos.getInstance(q);
6330    
6331                    qPos.add(classNameId);
6332    
6333                    qPos.add(classPK);
6334    
6335                    if (type != null) {
6336                            qPos.add(type);
6337                    }
6338    
6339                    if (mode != null) {
6340                            qPos.add(mode);
6341                    }
6342    
6343                    if (orderByComparator != null) {
6344                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
6345    
6346                            for (Object value : values) {
6347                                    qPos.add(value);
6348                            }
6349                    }
6350    
6351                    List<DDMTemplate> list = q.list();
6352    
6353                    if (list.size() == 2) {
6354                            return list.get(1);
6355                    }
6356                    else {
6357                            return null;
6358                    }
6359            }
6360    
6361            /**
6362             * Returns all the d d m templates.
6363             *
6364             * @return the d d m templates
6365             * @throws SystemException if a system exception occurred
6366             */
6367            public List<DDMTemplate> findAll() throws SystemException {
6368                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6369            }
6370    
6371            /**
6372             * Returns a range of all the d d m templates.
6373             *
6374             * <p>
6375             * 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.
6376             * </p>
6377             *
6378             * @param start the lower bound of the range of d d m templates
6379             * @param end the upper bound of the range of d d m templates (not inclusive)
6380             * @return the range of d d m templates
6381             * @throws SystemException if a system exception occurred
6382             */
6383            public List<DDMTemplate> findAll(int start, int end)
6384                    throws SystemException {
6385                    return findAll(start, end, null);
6386            }
6387    
6388            /**
6389             * Returns an ordered range of all the d d m templates.
6390             *
6391             * <p>
6392             * 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.
6393             * </p>
6394             *
6395             * @param start the lower bound of the range of d d m templates
6396             * @param end the upper bound of the range of d d m templates (not inclusive)
6397             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6398             * @return the ordered range of d d m templates
6399             * @throws SystemException if a system exception occurred
6400             */
6401            public List<DDMTemplate> findAll(int start, int end,
6402                    OrderByComparator orderByComparator) throws SystemException {
6403                    FinderPath finderPath = null;
6404                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
6405    
6406                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6407                                    (orderByComparator == null)) {
6408                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
6409                            finderArgs = FINDER_ARGS_EMPTY;
6410                    }
6411                    else {
6412                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
6413                            finderArgs = new Object[] { start, end, orderByComparator };
6414                    }
6415    
6416                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
6417                                    finderArgs, this);
6418    
6419                    if (list == null) {
6420                            StringBundler query = null;
6421                            String sql = null;
6422    
6423                            if (orderByComparator != null) {
6424                                    query = new StringBundler(2 +
6425                                                    (orderByComparator.getOrderByFields().length * 3));
6426    
6427                                    query.append(_SQL_SELECT_DDMTEMPLATE);
6428    
6429                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6430                                            orderByComparator);
6431    
6432                                    sql = query.toString();
6433                            }
6434                            else {
6435                                    sql = _SQL_SELECT_DDMTEMPLATE;
6436                            }
6437    
6438                            Session session = null;
6439    
6440                            try {
6441                                    session = openSession();
6442    
6443                                    Query q = session.createQuery(sql);
6444    
6445                                    if (orderByComparator == null) {
6446                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
6447                                                            start, end, false);
6448    
6449                                            Collections.sort(list);
6450                                    }
6451                                    else {
6452                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
6453                                                            start, end);
6454                                    }
6455                            }
6456                            catch (Exception e) {
6457                                    throw processException(e);
6458                            }
6459                            finally {
6460                                    if (list == null) {
6461                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
6462                                    }
6463                                    else {
6464                                            cacheResult(list);
6465    
6466                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
6467                                    }
6468    
6469                                    closeSession(session);
6470                            }
6471                    }
6472    
6473                    return list;
6474            }
6475    
6476            /**
6477             * Removes all the d d m templates where uuid = &#63; from the database.
6478             *
6479             * @param uuid the uuid
6480             * @throws SystemException if a system exception occurred
6481             */
6482            public void removeByUuid(String uuid) throws SystemException {
6483                    for (DDMTemplate ddmTemplate : findByUuid(uuid)) {
6484                            remove(ddmTemplate);
6485                    }
6486            }
6487    
6488            /**
6489             * Removes the d d m template where uuid = &#63; and groupId = &#63; from the database.
6490             *
6491             * @param uuid the uuid
6492             * @param groupId the group ID
6493             * @return the d d m template that was removed
6494             * @throws SystemException if a system exception occurred
6495             */
6496            public DDMTemplate removeByUUID_G(String uuid, long groupId)
6497                    throws NoSuchTemplateException, SystemException {
6498                    DDMTemplate ddmTemplate = findByUUID_G(uuid, groupId);
6499    
6500                    return remove(ddmTemplate);
6501            }
6502    
6503            /**
6504             * Removes all the d d m templates where uuid = &#63; and companyId = &#63; from the database.
6505             *
6506             * @param uuid the uuid
6507             * @param companyId the company ID
6508             * @throws SystemException if a system exception occurred
6509             */
6510            public void removeByUuid_C(String uuid, long companyId)
6511                    throws SystemException {
6512                    for (DDMTemplate ddmTemplate : findByUuid_C(uuid, companyId)) {
6513                            remove(ddmTemplate);
6514                    }
6515            }
6516    
6517            /**
6518             * Removes all the d d m templates where groupId = &#63; from the database.
6519             *
6520             * @param groupId the group ID
6521             * @throws SystemException if a system exception occurred
6522             */
6523            public void removeByGroupId(long groupId) throws SystemException {
6524                    for (DDMTemplate ddmTemplate : findByGroupId(groupId)) {
6525                            remove(ddmTemplate);
6526                    }
6527            }
6528    
6529            /**
6530             * Removes all the d d m templates where classPK = &#63; from the database.
6531             *
6532             * @param classPK the class p k
6533             * @throws SystemException if a system exception occurred
6534             */
6535            public void removeByClassPK(long classPK) throws SystemException {
6536                    for (DDMTemplate ddmTemplate : findByClassPK(classPK)) {
6537                            remove(ddmTemplate);
6538                    }
6539            }
6540    
6541            /**
6542             * Removes all the d d m templates where type = &#63; from the database.
6543             *
6544             * @param type the type
6545             * @throws SystemException if a system exception occurred
6546             */
6547            public void removeByType(String type) throws SystemException {
6548                    for (DDMTemplate ddmTemplate : findByType(type)) {
6549                            remove(ddmTemplate);
6550                    }
6551            }
6552    
6553            /**
6554             * Removes all the d d m templates where language = &#63; from the database.
6555             *
6556             * @param language the language
6557             * @throws SystemException if a system exception occurred
6558             */
6559            public void removeByLanguage(String language) throws SystemException {
6560                    for (DDMTemplate ddmTemplate : findByLanguage(language)) {
6561                            remove(ddmTemplate);
6562                    }
6563            }
6564    
6565            /**
6566             * Removes all the d d m templates where groupId = &#63; and classNameId = &#63; from the database.
6567             *
6568             * @param groupId the group ID
6569             * @param classNameId the class name ID
6570             * @throws SystemException if a system exception occurred
6571             */
6572            public void removeByG_C(long groupId, long classNameId)
6573                    throws SystemException {
6574                    for (DDMTemplate ddmTemplate : findByG_C(groupId, classNameId)) {
6575                            remove(ddmTemplate);
6576                    }
6577            }
6578    
6579            /**
6580             * Removes the d d m template where groupId = &#63; and templateKey = &#63; from the database.
6581             *
6582             * @param groupId the group ID
6583             * @param templateKey the template key
6584             * @return the d d m template that was removed
6585             * @throws SystemException if a system exception occurred
6586             */
6587            public DDMTemplate removeByG_T(long groupId, String templateKey)
6588                    throws NoSuchTemplateException, SystemException {
6589                    DDMTemplate ddmTemplate = findByG_T(groupId, templateKey);
6590    
6591                    return remove(ddmTemplate);
6592            }
6593    
6594            /**
6595             * Removes all the d d m templates where groupId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
6596             *
6597             * @param groupId the group ID
6598             * @param classNameId the class name ID
6599             * @param classPK the class p k
6600             * @throws SystemException if a system exception occurred
6601             */
6602            public void removeByG_C_C(long groupId, long classNameId, long classPK)
6603                    throws SystemException {
6604                    for (DDMTemplate ddmTemplate : findByG_C_C(groupId, classNameId, classPK)) {
6605                            remove(ddmTemplate);
6606                    }
6607            }
6608    
6609            /**
6610             * Removes all the d d m templates where classNameId = &#63; and classPK = &#63; and type = &#63; from the database.
6611             *
6612             * @param classNameId the class name ID
6613             * @param classPK the class p k
6614             * @param type the type
6615             * @throws SystemException if a system exception occurred
6616             */
6617            public void removeByC_C_T(long classNameId, long classPK, String type)
6618                    throws SystemException {
6619                    for (DDMTemplate ddmTemplate : findByC_C_T(classNameId, classPK, type)) {
6620                            remove(ddmTemplate);
6621                    }
6622            }
6623    
6624            /**
6625             * Removes all the d d m templates where classNameId = &#63; and classPK = &#63; and type = &#63; and mode = &#63; from the database.
6626             *
6627             * @param classNameId the class name ID
6628             * @param classPK the class p k
6629             * @param type the type
6630             * @param mode the mode
6631             * @throws SystemException if a system exception occurred
6632             */
6633            public void removeByC_C_T_M(long classNameId, long classPK, String type,
6634                    String mode) throws SystemException {
6635                    for (DDMTemplate ddmTemplate : findByC_C_T_M(classNameId, classPK,
6636                                    type, mode)) {
6637                            remove(ddmTemplate);
6638                    }
6639            }
6640    
6641            /**
6642             * Removes all the d d m templates from the database.
6643             *
6644             * @throws SystemException if a system exception occurred
6645             */
6646            public void removeAll() throws SystemException {
6647                    for (DDMTemplate ddmTemplate : findAll()) {
6648                            remove(ddmTemplate);
6649                    }
6650            }
6651    
6652            /**
6653             * Returns the number of d d m templates where uuid = &#63;.
6654             *
6655             * @param uuid the uuid
6656             * @return the number of matching d d m templates
6657             * @throws SystemException if a system exception occurred
6658             */
6659            public int countByUuid(String uuid) throws SystemException {
6660                    Object[] finderArgs = new Object[] { uuid };
6661    
6662                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
6663                                    finderArgs, this);
6664    
6665                    if (count == null) {
6666                            StringBundler query = new StringBundler(2);
6667    
6668                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
6669    
6670                            if (uuid == null) {
6671                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
6672                            }
6673                            else {
6674                                    if (uuid.equals(StringPool.BLANK)) {
6675                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
6676                                    }
6677                                    else {
6678                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
6679                                    }
6680                            }
6681    
6682                            String sql = query.toString();
6683    
6684                            Session session = null;
6685    
6686                            try {
6687                                    session = openSession();
6688    
6689                                    Query q = session.createQuery(sql);
6690    
6691                                    QueryPos qPos = QueryPos.getInstance(q);
6692    
6693                                    if (uuid != null) {
6694                                            qPos.add(uuid);
6695                                    }
6696    
6697                                    count = (Long)q.uniqueResult();
6698                            }
6699                            catch (Exception e) {
6700                                    throw processException(e);
6701                            }
6702                            finally {
6703                                    if (count == null) {
6704                                            count = Long.valueOf(0);
6705                                    }
6706    
6707                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
6708                                            finderArgs, count);
6709    
6710                                    closeSession(session);
6711                            }
6712                    }
6713    
6714                    return count.intValue();
6715            }
6716    
6717            /**
6718             * Returns the number of d d m templates where uuid = &#63; and groupId = &#63;.
6719             *
6720             * @param uuid the uuid
6721             * @param groupId the group ID
6722             * @return the number of matching d d m templates
6723             * @throws SystemException if a system exception occurred
6724             */
6725            public int countByUUID_G(String uuid, long groupId)
6726                    throws SystemException {
6727                    Object[] finderArgs = new Object[] { uuid, groupId };
6728    
6729                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
6730                                    finderArgs, this);
6731    
6732                    if (count == null) {
6733                            StringBundler query = new StringBundler(3);
6734    
6735                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
6736    
6737                            if (uuid == null) {
6738                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
6739                            }
6740                            else {
6741                                    if (uuid.equals(StringPool.BLANK)) {
6742                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
6743                                    }
6744                                    else {
6745                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
6746                                    }
6747                            }
6748    
6749                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
6750    
6751                            String sql = query.toString();
6752    
6753                            Session session = null;
6754    
6755                            try {
6756                                    session = openSession();
6757    
6758                                    Query q = session.createQuery(sql);
6759    
6760                                    QueryPos qPos = QueryPos.getInstance(q);
6761    
6762                                    if (uuid != null) {
6763                                            qPos.add(uuid);
6764                                    }
6765    
6766                                    qPos.add(groupId);
6767    
6768                                    count = (Long)q.uniqueResult();
6769                            }
6770                            catch (Exception e) {
6771                                    throw processException(e);
6772                            }
6773                            finally {
6774                                    if (count == null) {
6775                                            count = Long.valueOf(0);
6776                                    }
6777    
6778                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
6779                                            finderArgs, count);
6780    
6781                                    closeSession(session);
6782                            }
6783                    }
6784    
6785                    return count.intValue();
6786            }
6787    
6788            /**
6789             * Returns the number of d d m templates where uuid = &#63; and companyId = &#63;.
6790             *
6791             * @param uuid the uuid
6792             * @param companyId the company ID
6793             * @return the number of matching d d m templates
6794             * @throws SystemException if a system exception occurred
6795             */
6796            public int countByUuid_C(String uuid, long companyId)
6797                    throws SystemException {
6798                    Object[] finderArgs = new Object[] { uuid, companyId };
6799    
6800                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_C,
6801                                    finderArgs, this);
6802    
6803                    if (count == null) {
6804                            StringBundler query = new StringBundler(3);
6805    
6806                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
6807    
6808                            if (uuid == null) {
6809                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
6810                            }
6811                            else {
6812                                    if (uuid.equals(StringPool.BLANK)) {
6813                                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
6814                                    }
6815                                    else {
6816                                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
6817                                    }
6818                            }
6819    
6820                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
6821    
6822                            String sql = query.toString();
6823    
6824                            Session session = null;
6825    
6826                            try {
6827                                    session = openSession();
6828    
6829                                    Query q = session.createQuery(sql);
6830    
6831                                    QueryPos qPos = QueryPos.getInstance(q);
6832    
6833                                    if (uuid != null) {
6834                                            qPos.add(uuid);
6835                                    }
6836    
6837                                    qPos.add(companyId);
6838    
6839                                    count = (Long)q.uniqueResult();
6840                            }
6841                            catch (Exception e) {
6842                                    throw processException(e);
6843                            }
6844                            finally {
6845                                    if (count == null) {
6846                                            count = Long.valueOf(0);
6847                                    }
6848    
6849                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_C,
6850                                            finderArgs, count);
6851    
6852                                    closeSession(session);
6853                            }
6854                    }
6855    
6856                    return count.intValue();
6857            }
6858    
6859            /**
6860             * Returns the number of d d m templates where groupId = &#63;.
6861             *
6862             * @param groupId the group ID
6863             * @return the number of matching d d m templates
6864             * @throws SystemException if a system exception occurred
6865             */
6866            public int countByGroupId(long groupId) throws SystemException {
6867                    Object[] finderArgs = new Object[] { groupId };
6868    
6869                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
6870                                    finderArgs, this);
6871    
6872                    if (count == null) {
6873                            StringBundler query = new StringBundler(2);
6874    
6875                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
6876    
6877                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
6878    
6879                            String sql = query.toString();
6880    
6881                            Session session = null;
6882    
6883                            try {
6884                                    session = openSession();
6885    
6886                                    Query q = session.createQuery(sql);
6887    
6888                                    QueryPos qPos = QueryPos.getInstance(q);
6889    
6890                                    qPos.add(groupId);
6891    
6892                                    count = (Long)q.uniqueResult();
6893                            }
6894                            catch (Exception e) {
6895                                    throw processException(e);
6896                            }
6897                            finally {
6898                                    if (count == null) {
6899                                            count = Long.valueOf(0);
6900                                    }
6901    
6902                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
6903                                            finderArgs, count);
6904    
6905                                    closeSession(session);
6906                            }
6907                    }
6908    
6909                    return count.intValue();
6910            }
6911    
6912            /**
6913             * Returns the number of d d m templates that the user has permission to view where groupId = &#63;.
6914             *
6915             * @param groupId the group ID
6916             * @return the number of matching d d m templates that the user has permission to view
6917             * @throws SystemException if a system exception occurred
6918             */
6919            public int filterCountByGroupId(long groupId) throws SystemException {
6920                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6921                            return countByGroupId(groupId);
6922                    }
6923    
6924                    StringBundler query = new StringBundler(2);
6925    
6926                    query.append(_FILTER_SQL_COUNT_DDMTEMPLATE_WHERE);
6927    
6928                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
6929    
6930                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6931                                    DDMTemplate.class.getName(),
6932                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6933    
6934                    Session session = null;
6935    
6936                    try {
6937                            session = openSession();
6938    
6939                            SQLQuery q = session.createSQLQuery(sql);
6940    
6941                            q.addScalar(COUNT_COLUMN_NAME,
6942                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6943    
6944                            QueryPos qPos = QueryPos.getInstance(q);
6945    
6946                            qPos.add(groupId);
6947    
6948                            Long count = (Long)q.uniqueResult();
6949    
6950                            return count.intValue();
6951                    }
6952                    catch (Exception e) {
6953                            throw processException(e);
6954                    }
6955                    finally {
6956                            closeSession(session);
6957                    }
6958            }
6959    
6960            /**
6961             * Returns the number of d d m templates where classPK = &#63;.
6962             *
6963             * @param classPK the class p k
6964             * @return the number of matching d d m templates
6965             * @throws SystemException if a system exception occurred
6966             */
6967            public int countByClassPK(long classPK) throws SystemException {
6968                    Object[] finderArgs = new Object[] { classPK };
6969    
6970                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CLASSPK,
6971                                    finderArgs, this);
6972    
6973                    if (count == null) {
6974                            StringBundler query = new StringBundler(2);
6975    
6976                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
6977    
6978                            query.append(_FINDER_COLUMN_CLASSPK_CLASSPK_2);
6979    
6980                            String sql = query.toString();
6981    
6982                            Session session = null;
6983    
6984                            try {
6985                                    session = openSession();
6986    
6987                                    Query q = session.createQuery(sql);
6988    
6989                                    QueryPos qPos = QueryPos.getInstance(q);
6990    
6991                                    qPos.add(classPK);
6992    
6993                                    count = (Long)q.uniqueResult();
6994                            }
6995                            catch (Exception e) {
6996                                    throw processException(e);
6997                            }
6998                            finally {
6999                                    if (count == null) {
7000                                            count = Long.valueOf(0);
7001                                    }
7002    
7003                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CLASSPK,
7004                                            finderArgs, count);
7005    
7006                                    closeSession(session);
7007                            }
7008                    }
7009    
7010                    return count.intValue();
7011            }
7012    
7013            /**
7014             * Returns the number of d d m templates where type = &#63;.
7015             *
7016             * @param type the type
7017             * @return the number of matching d d m templates
7018             * @throws SystemException if a system exception occurred
7019             */
7020            public int countByType(String type) throws SystemException {
7021                    Object[] finderArgs = new Object[] { type };
7022    
7023                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TYPE,
7024                                    finderArgs, this);
7025    
7026                    if (count == null) {
7027                            StringBundler query = new StringBundler(2);
7028    
7029                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
7030    
7031                            if (type == null) {
7032                                    query.append(_FINDER_COLUMN_TYPE_TYPE_1);
7033                            }
7034                            else {
7035                                    if (type.equals(StringPool.BLANK)) {
7036                                            query.append(_FINDER_COLUMN_TYPE_TYPE_3);
7037                                    }
7038                                    else {
7039                                            query.append(_FINDER_COLUMN_TYPE_TYPE_2);
7040                                    }
7041                            }
7042    
7043                            String sql = query.toString();
7044    
7045                            Session session = null;
7046    
7047                            try {
7048                                    session = openSession();
7049    
7050                                    Query q = session.createQuery(sql);
7051    
7052                                    QueryPos qPos = QueryPos.getInstance(q);
7053    
7054                                    if (type != null) {
7055                                            qPos.add(type);
7056                                    }
7057    
7058                                    count = (Long)q.uniqueResult();
7059                            }
7060                            catch (Exception e) {
7061                                    throw processException(e);
7062                            }
7063                            finally {
7064                                    if (count == null) {
7065                                            count = Long.valueOf(0);
7066                                    }
7067    
7068                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TYPE,
7069                                            finderArgs, count);
7070    
7071                                    closeSession(session);
7072                            }
7073                    }
7074    
7075                    return count.intValue();
7076            }
7077    
7078            /**
7079             * Returns the number of d d m templates where language = &#63;.
7080             *
7081             * @param language the language
7082             * @return the number of matching d d m templates
7083             * @throws SystemException if a system exception occurred
7084             */
7085            public int countByLanguage(String language) throws SystemException {
7086                    Object[] finderArgs = new Object[] { language };
7087    
7088                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_LANGUAGE,
7089                                    finderArgs, this);
7090    
7091                    if (count == null) {
7092                            StringBundler query = new StringBundler(2);
7093    
7094                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
7095    
7096                            if (language == null) {
7097                                    query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_1);
7098                            }
7099                            else {
7100                                    if (language.equals(StringPool.BLANK)) {
7101                                            query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_3);
7102                                    }
7103                                    else {
7104                                            query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_2);
7105                                    }
7106                            }
7107    
7108                            String sql = query.toString();
7109    
7110                            Session session = null;
7111    
7112                            try {
7113                                    session = openSession();
7114    
7115                                    Query q = session.createQuery(sql);
7116    
7117                                    QueryPos qPos = QueryPos.getInstance(q);
7118    
7119                                    if (language != null) {
7120                                            qPos.add(language);
7121                                    }
7122    
7123                                    count = (Long)q.uniqueResult();
7124                            }
7125                            catch (Exception e) {
7126                                    throw processException(e);
7127                            }
7128                            finally {
7129                                    if (count == null) {
7130                                            count = Long.valueOf(0);
7131                                    }
7132    
7133                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LANGUAGE,
7134                                            finderArgs, count);
7135    
7136                                    closeSession(session);
7137                            }
7138                    }
7139    
7140                    return count.intValue();
7141            }
7142    
7143            /**
7144             * Returns the number of d d m templates where groupId = &#63; and classNameId = &#63;.
7145             *
7146             * @param groupId the group ID
7147             * @param classNameId the class name ID
7148             * @return the number of matching d d m templates
7149             * @throws SystemException if a system exception occurred
7150             */
7151            public int countByG_C(long groupId, long classNameId)
7152                    throws SystemException {
7153                    Object[] finderArgs = new Object[] { groupId, classNameId };
7154    
7155                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C,
7156                                    finderArgs, this);
7157    
7158                    if (count == null) {
7159                            StringBundler query = new StringBundler(3);
7160    
7161                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
7162    
7163                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
7164    
7165                            query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
7166    
7167                            String sql = query.toString();
7168    
7169                            Session session = null;
7170    
7171                            try {
7172                                    session = openSession();
7173    
7174                                    Query q = session.createQuery(sql);
7175    
7176                                    QueryPos qPos = QueryPos.getInstance(q);
7177    
7178                                    qPos.add(groupId);
7179    
7180                                    qPos.add(classNameId);
7181    
7182                                    count = (Long)q.uniqueResult();
7183                            }
7184                            catch (Exception e) {
7185                                    throw processException(e);
7186                            }
7187                            finally {
7188                                    if (count == null) {
7189                                            count = Long.valueOf(0);
7190                                    }
7191    
7192                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, finderArgs,
7193                                            count);
7194    
7195                                    closeSession(session);
7196                            }
7197                    }
7198    
7199                    return count.intValue();
7200            }
7201    
7202            /**
7203             * Returns the number of d d m templates that the user has permission to view where groupId = &#63; and classNameId = &#63;.
7204             *
7205             * @param groupId the group ID
7206             * @param classNameId the class name ID
7207             * @return the number of matching d d m templates that the user has permission to view
7208             * @throws SystemException if a system exception occurred
7209             */
7210            public int filterCountByG_C(long groupId, long classNameId)
7211                    throws SystemException {
7212                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7213                            return countByG_C(groupId, classNameId);
7214                    }
7215    
7216                    StringBundler query = new StringBundler(3);
7217    
7218                    query.append(_FILTER_SQL_COUNT_DDMTEMPLATE_WHERE);
7219    
7220                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
7221    
7222                    query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
7223    
7224                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7225                                    DDMTemplate.class.getName(),
7226                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7227    
7228                    Session session = null;
7229    
7230                    try {
7231                            session = openSession();
7232    
7233                            SQLQuery q = session.createSQLQuery(sql);
7234    
7235                            q.addScalar(COUNT_COLUMN_NAME,
7236                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7237    
7238                            QueryPos qPos = QueryPos.getInstance(q);
7239    
7240                            qPos.add(groupId);
7241    
7242                            qPos.add(classNameId);
7243    
7244                            Long count = (Long)q.uniqueResult();
7245    
7246                            return count.intValue();
7247                    }
7248                    catch (Exception e) {
7249                            throw processException(e);
7250                    }
7251                    finally {
7252                            closeSession(session);
7253                    }
7254            }
7255    
7256            /**
7257             * Returns the number of d d m templates where groupId = &#63; and templateKey = &#63;.
7258             *
7259             * @param groupId the group ID
7260             * @param templateKey the template key
7261             * @return the number of matching d d m templates
7262             * @throws SystemException if a system exception occurred
7263             */
7264            public int countByG_T(long groupId, String templateKey)
7265                    throws SystemException {
7266                    Object[] finderArgs = new Object[] { groupId, templateKey };
7267    
7268                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_T,
7269                                    finderArgs, this);
7270    
7271                    if (count == null) {
7272                            StringBundler query = new StringBundler(3);
7273    
7274                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
7275    
7276                            query.append(_FINDER_COLUMN_G_T_GROUPID_2);
7277    
7278                            if (templateKey == null) {
7279                                    query.append(_FINDER_COLUMN_G_T_TEMPLATEKEY_1);
7280                            }
7281                            else {
7282                                    if (templateKey.equals(StringPool.BLANK)) {
7283                                            query.append(_FINDER_COLUMN_G_T_TEMPLATEKEY_3);
7284                                    }
7285                                    else {
7286                                            query.append(_FINDER_COLUMN_G_T_TEMPLATEKEY_2);
7287                                    }
7288                            }
7289    
7290                            String sql = query.toString();
7291    
7292                            Session session = null;
7293    
7294                            try {
7295                                    session = openSession();
7296    
7297                                    Query q = session.createQuery(sql);
7298    
7299                                    QueryPos qPos = QueryPos.getInstance(q);
7300    
7301                                    qPos.add(groupId);
7302    
7303                                    if (templateKey != null) {
7304                                            qPos.add(templateKey);
7305                                    }
7306    
7307                                    count = (Long)q.uniqueResult();
7308                            }
7309                            catch (Exception e) {
7310                                    throw processException(e);
7311                            }
7312                            finally {
7313                                    if (count == null) {
7314                                            count = Long.valueOf(0);
7315                                    }
7316    
7317                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_T, finderArgs,
7318                                            count);
7319    
7320                                    closeSession(session);
7321                            }
7322                    }
7323    
7324                    return count.intValue();
7325            }
7326    
7327            /**
7328             * Returns the number of d d m templates where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
7329             *
7330             * @param groupId the group ID
7331             * @param classNameId the class name ID
7332             * @param classPK the class p k
7333             * @return the number of matching d d m templates
7334             * @throws SystemException if a system exception occurred
7335             */
7336            public int countByG_C_C(long groupId, long classNameId, long classPK)
7337                    throws SystemException {
7338                    Object[] finderArgs = new Object[] { groupId, classNameId, classPK };
7339    
7340                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_C,
7341                                    finderArgs, this);
7342    
7343                    if (count == null) {
7344                            StringBundler query = new StringBundler(4);
7345    
7346                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
7347    
7348                            query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
7349    
7350                            query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
7351    
7352                            query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
7353    
7354                            String sql = query.toString();
7355    
7356                            Session session = null;
7357    
7358                            try {
7359                                    session = openSession();
7360    
7361                                    Query q = session.createQuery(sql);
7362    
7363                                    QueryPos qPos = QueryPos.getInstance(q);
7364    
7365                                    qPos.add(groupId);
7366    
7367                                    qPos.add(classNameId);
7368    
7369                                    qPos.add(classPK);
7370    
7371                                    count = (Long)q.uniqueResult();
7372                            }
7373                            catch (Exception e) {
7374                                    throw processException(e);
7375                            }
7376                            finally {
7377                                    if (count == null) {
7378                                            count = Long.valueOf(0);
7379                                    }
7380    
7381                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_C,
7382                                            finderArgs, count);
7383    
7384                                    closeSession(session);
7385                            }
7386                    }
7387    
7388                    return count.intValue();
7389            }
7390    
7391            /**
7392             * Returns the number of d d m templates that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
7393             *
7394             * @param groupId the group ID
7395             * @param classNameId the class name ID
7396             * @param classPK the class p k
7397             * @return the number of matching d d m templates that the user has permission to view
7398             * @throws SystemException if a system exception occurred
7399             */
7400            public int filterCountByG_C_C(long groupId, long classNameId, long classPK)
7401                    throws SystemException {
7402                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7403                            return countByG_C_C(groupId, classNameId, classPK);
7404                    }
7405    
7406                    StringBundler query = new StringBundler(4);
7407    
7408                    query.append(_FILTER_SQL_COUNT_DDMTEMPLATE_WHERE);
7409    
7410                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
7411    
7412                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
7413    
7414                    query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
7415    
7416                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7417                                    DDMTemplate.class.getName(),
7418                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7419    
7420                    Session session = null;
7421    
7422                    try {
7423                            session = openSession();
7424    
7425                            SQLQuery q = session.createSQLQuery(sql);
7426    
7427                            q.addScalar(COUNT_COLUMN_NAME,
7428                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7429    
7430                            QueryPos qPos = QueryPos.getInstance(q);
7431    
7432                            qPos.add(groupId);
7433    
7434                            qPos.add(classNameId);
7435    
7436                            qPos.add(classPK);
7437    
7438                            Long count = (Long)q.uniqueResult();
7439    
7440                            return count.intValue();
7441                    }
7442                    catch (Exception e) {
7443                            throw processException(e);
7444                    }
7445                    finally {
7446                            closeSession(session);
7447                    }
7448            }
7449    
7450            /**
7451             * Returns the number of d d m templates where classNameId = &#63; and classPK = &#63; and type = &#63;.
7452             *
7453             * @param classNameId the class name ID
7454             * @param classPK the class p k
7455             * @param type the type
7456             * @return the number of matching d d m templates
7457             * @throws SystemException if a system exception occurred
7458             */
7459            public int countByC_C_T(long classNameId, long classPK, String type)
7460                    throws SystemException {
7461                    Object[] finderArgs = new Object[] { classNameId, classPK, type };
7462    
7463                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_T,
7464                                    finderArgs, this);
7465    
7466                    if (count == null) {
7467                            StringBundler query = new StringBundler(4);
7468    
7469                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
7470    
7471                            query.append(_FINDER_COLUMN_C_C_T_CLASSNAMEID_2);
7472    
7473                            query.append(_FINDER_COLUMN_C_C_T_CLASSPK_2);
7474    
7475                            if (type == null) {
7476                                    query.append(_FINDER_COLUMN_C_C_T_TYPE_1);
7477                            }
7478                            else {
7479                                    if (type.equals(StringPool.BLANK)) {
7480                                            query.append(_FINDER_COLUMN_C_C_T_TYPE_3);
7481                                    }
7482                                    else {
7483                                            query.append(_FINDER_COLUMN_C_C_T_TYPE_2);
7484                                    }
7485                            }
7486    
7487                            String sql = query.toString();
7488    
7489                            Session session = null;
7490    
7491                            try {
7492                                    session = openSession();
7493    
7494                                    Query q = session.createQuery(sql);
7495    
7496                                    QueryPos qPos = QueryPos.getInstance(q);
7497    
7498                                    qPos.add(classNameId);
7499    
7500                                    qPos.add(classPK);
7501    
7502                                    if (type != null) {
7503                                            qPos.add(type);
7504                                    }
7505    
7506                                    count = (Long)q.uniqueResult();
7507                            }
7508                            catch (Exception e) {
7509                                    throw processException(e);
7510                            }
7511                            finally {
7512                                    if (count == null) {
7513                                            count = Long.valueOf(0);
7514                                    }
7515    
7516                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_T,
7517                                            finderArgs, count);
7518    
7519                                    closeSession(session);
7520                            }
7521                    }
7522    
7523                    return count.intValue();
7524            }
7525    
7526            /**
7527             * Returns the number of d d m templates where classNameId = &#63; and classPK = &#63; and type = &#63; and mode = &#63;.
7528             *
7529             * @param classNameId the class name ID
7530             * @param classPK the class p k
7531             * @param type the type
7532             * @param mode the mode
7533             * @return the number of matching d d m templates
7534             * @throws SystemException if a system exception occurred
7535             */
7536            public int countByC_C_T_M(long classNameId, long classPK, String type,
7537                    String mode) throws SystemException {
7538                    Object[] finderArgs = new Object[] { classNameId, classPK, type, mode };
7539    
7540                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_T_M,
7541                                    finderArgs, this);
7542    
7543                    if (count == null) {
7544                            StringBundler query = new StringBundler(5);
7545    
7546                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
7547    
7548                            query.append(_FINDER_COLUMN_C_C_T_M_CLASSNAMEID_2);
7549    
7550                            query.append(_FINDER_COLUMN_C_C_T_M_CLASSPK_2);
7551    
7552                            if (type == null) {
7553                                    query.append(_FINDER_COLUMN_C_C_T_M_TYPE_1);
7554                            }
7555                            else {
7556                                    if (type.equals(StringPool.BLANK)) {
7557                                            query.append(_FINDER_COLUMN_C_C_T_M_TYPE_3);
7558                                    }
7559                                    else {
7560                                            query.append(_FINDER_COLUMN_C_C_T_M_TYPE_2);
7561                                    }
7562                            }
7563    
7564                            if (mode == null) {
7565                                    query.append(_FINDER_COLUMN_C_C_T_M_MODE_1);
7566                            }
7567                            else {
7568                                    if (mode.equals(StringPool.BLANK)) {
7569                                            query.append(_FINDER_COLUMN_C_C_T_M_MODE_3);
7570                                    }
7571                                    else {
7572                                            query.append(_FINDER_COLUMN_C_C_T_M_MODE_2);
7573                                    }
7574                            }
7575    
7576                            String sql = query.toString();
7577    
7578                            Session session = null;
7579    
7580                            try {
7581                                    session = openSession();
7582    
7583                                    Query q = session.createQuery(sql);
7584    
7585                                    QueryPos qPos = QueryPos.getInstance(q);
7586    
7587                                    qPos.add(classNameId);
7588    
7589                                    qPos.add(classPK);
7590    
7591                                    if (type != null) {
7592                                            qPos.add(type);
7593                                    }
7594    
7595                                    if (mode != null) {
7596                                            qPos.add(mode);
7597                                    }
7598    
7599                                    count = (Long)q.uniqueResult();
7600                            }
7601                            catch (Exception e) {
7602                                    throw processException(e);
7603                            }
7604                            finally {
7605                                    if (count == null) {
7606                                            count = Long.valueOf(0);
7607                                    }
7608    
7609                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_T_M,
7610                                            finderArgs, count);
7611    
7612                                    closeSession(session);
7613                            }
7614                    }
7615    
7616                    return count.intValue();
7617            }
7618    
7619            /**
7620             * Returns the number of d d m templates.
7621             *
7622             * @return the number of d d m templates
7623             * @throws SystemException if a system exception occurred
7624             */
7625            public int countAll() throws SystemException {
7626                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
7627                                    FINDER_ARGS_EMPTY, this);
7628    
7629                    if (count == null) {
7630                            Session session = null;
7631    
7632                            try {
7633                                    session = openSession();
7634    
7635                                    Query q = session.createQuery(_SQL_COUNT_DDMTEMPLATE);
7636    
7637                                    count = (Long)q.uniqueResult();
7638                            }
7639                            catch (Exception e) {
7640                                    throw processException(e);
7641                            }
7642                            finally {
7643                                    if (count == null) {
7644                                            count = Long.valueOf(0);
7645                                    }
7646    
7647                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
7648                                            FINDER_ARGS_EMPTY, count);
7649    
7650                                    closeSession(session);
7651                            }
7652                    }
7653    
7654                    return count.intValue();
7655            }
7656    
7657            /**
7658             * Initializes the d d m template persistence.
7659             */
7660            public void afterPropertiesSet() {
7661                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
7662                                            com.liferay.portal.util.PropsUtil.get(
7663                                                    "value.object.listener.com.liferay.portlet.dynamicdatamapping.model.DDMTemplate")));
7664    
7665                    if (listenerClassNames.length > 0) {
7666                            try {
7667                                    List<ModelListener<DDMTemplate>> listenersList = new ArrayList<ModelListener<DDMTemplate>>();
7668    
7669                                    for (String listenerClassName : listenerClassNames) {
7670                                            listenersList.add((ModelListener<DDMTemplate>)InstanceFactory.newInstance(
7671                                                            listenerClassName));
7672                                    }
7673    
7674                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
7675                            }
7676                            catch (Exception e) {
7677                                    _log.error(e);
7678                            }
7679                    }
7680            }
7681    
7682            public void destroy() {
7683                    EntityCacheUtil.removeCache(DDMTemplateImpl.class.getName());
7684                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
7685                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7686            }
7687    
7688            @BeanReference(type = DDMContentPersistence.class)
7689            protected DDMContentPersistence ddmContentPersistence;
7690            @BeanReference(type = DDMStorageLinkPersistence.class)
7691            protected DDMStorageLinkPersistence ddmStorageLinkPersistence;
7692            @BeanReference(type = DDMStructurePersistence.class)
7693            protected DDMStructurePersistence ddmStructurePersistence;
7694            @BeanReference(type = DDMStructureLinkPersistence.class)
7695            protected DDMStructureLinkPersistence ddmStructureLinkPersistence;
7696            @BeanReference(type = DDMTemplatePersistence.class)
7697            protected DDMTemplatePersistence ddmTemplatePersistence;
7698            @BeanReference(type = UserPersistence.class)
7699            protected UserPersistence userPersistence;
7700            private static final String _SQL_SELECT_DDMTEMPLATE = "SELECT ddmTemplate FROM DDMTemplate ddmTemplate";
7701            private static final String _SQL_SELECT_DDMTEMPLATE_WHERE = "SELECT ddmTemplate FROM DDMTemplate ddmTemplate WHERE ";
7702            private static final String _SQL_COUNT_DDMTEMPLATE = "SELECT COUNT(ddmTemplate) FROM DDMTemplate ddmTemplate";
7703            private static final String _SQL_COUNT_DDMTEMPLATE_WHERE = "SELECT COUNT(ddmTemplate) FROM DDMTemplate ddmTemplate WHERE ";
7704            private static final String _FINDER_COLUMN_UUID_UUID_1 = "ddmTemplate.uuid IS NULL";
7705            private static final String _FINDER_COLUMN_UUID_UUID_2 = "ddmTemplate.uuid = ?";
7706            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(ddmTemplate.uuid IS NULL OR ddmTemplate.uuid = ?)";
7707            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "ddmTemplate.uuid IS NULL AND ";
7708            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "ddmTemplate.uuid = ? AND ";
7709            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(ddmTemplate.uuid IS NULL OR ddmTemplate.uuid = ?) AND ";
7710            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "ddmTemplate.groupId = ?";
7711            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "ddmTemplate.uuid IS NULL AND ";
7712            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "ddmTemplate.uuid = ? AND ";
7713            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(ddmTemplate.uuid IS NULL OR ddmTemplate.uuid = ?) AND ";
7714            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "ddmTemplate.companyId = ?";
7715            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "ddmTemplate.groupId = ?";
7716            private static final String _FINDER_COLUMN_CLASSPK_CLASSPK_2 = "ddmTemplate.classPK = ?";
7717            private static final String _FINDER_COLUMN_TYPE_TYPE_1 = "ddmTemplate.type IS NULL";
7718            private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "ddmTemplate.type = ?";
7719            private static final String _FINDER_COLUMN_TYPE_TYPE_3 = "(ddmTemplate.type IS NULL OR ddmTemplate.type = ?)";
7720            private static final String _FINDER_COLUMN_LANGUAGE_LANGUAGE_1 = "ddmTemplate.language IS NULL";
7721            private static final String _FINDER_COLUMN_LANGUAGE_LANGUAGE_2 = "ddmTemplate.language = ?";
7722            private static final String _FINDER_COLUMN_LANGUAGE_LANGUAGE_3 = "(ddmTemplate.language IS NULL OR ddmTemplate.language = ?)";
7723            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "ddmTemplate.groupId = ? AND ";
7724            private static final String _FINDER_COLUMN_G_C_CLASSNAMEID_2 = "ddmTemplate.classNameId = ?";
7725            private static final String _FINDER_COLUMN_G_T_GROUPID_2 = "ddmTemplate.groupId = ? AND ";
7726            private static final String _FINDER_COLUMN_G_T_TEMPLATEKEY_1 = "ddmTemplate.templateKey IS NULL";
7727            private static final String _FINDER_COLUMN_G_T_TEMPLATEKEY_2 = "ddmTemplate.templateKey = ?";
7728            private static final String _FINDER_COLUMN_G_T_TEMPLATEKEY_3 = "(ddmTemplate.templateKey IS NULL OR ddmTemplate.templateKey = ?)";
7729            private static final String _FINDER_COLUMN_G_C_C_GROUPID_2 = "ddmTemplate.groupId = ? AND ";
7730            private static final String _FINDER_COLUMN_G_C_C_CLASSNAMEID_2 = "ddmTemplate.classNameId = ? AND ";
7731            private static final String _FINDER_COLUMN_G_C_C_CLASSPK_2 = "ddmTemplate.classPK = ?";
7732            private static final String _FINDER_COLUMN_C_C_T_CLASSNAMEID_2 = "ddmTemplate.classNameId = ? AND ";
7733            private static final String _FINDER_COLUMN_C_C_T_CLASSPK_2 = "ddmTemplate.classPK = ? AND ";
7734            private static final String _FINDER_COLUMN_C_C_T_TYPE_1 = "ddmTemplate.type IS NULL";
7735            private static final String _FINDER_COLUMN_C_C_T_TYPE_2 = "ddmTemplate.type = ?";
7736            private static final String _FINDER_COLUMN_C_C_T_TYPE_3 = "(ddmTemplate.type IS NULL OR ddmTemplate.type = ?)";
7737            private static final String _FINDER_COLUMN_C_C_T_M_CLASSNAMEID_2 = "ddmTemplate.classNameId = ? AND ";
7738            private static final String _FINDER_COLUMN_C_C_T_M_CLASSPK_2 = "ddmTemplate.classPK = ? AND ";
7739            private static final String _FINDER_COLUMN_C_C_T_M_TYPE_1 = "ddmTemplate.type IS NULL AND ";
7740            private static final String _FINDER_COLUMN_C_C_T_M_TYPE_2 = "ddmTemplate.type = ? AND ";
7741            private static final String _FINDER_COLUMN_C_C_T_M_TYPE_3 = "(ddmTemplate.type IS NULL OR ddmTemplate.type = ?) AND ";
7742            private static final String _FINDER_COLUMN_C_C_T_M_MODE_1 = "ddmTemplate.mode IS NULL";
7743            private static final String _FINDER_COLUMN_C_C_T_M_MODE_2 = "ddmTemplate.mode = ?";
7744            private static final String _FINDER_COLUMN_C_C_T_M_MODE_3 = "(ddmTemplate.mode IS NULL OR ddmTemplate.mode = ?)";
7745            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "ddmTemplate.templateId";
7746            private static final String _FILTER_SQL_SELECT_DDMTEMPLATE_WHERE = "SELECT DISTINCT {ddmTemplate.*} FROM DDMTemplate ddmTemplate WHERE ";
7747            private static final String _FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_1 =
7748                    "SELECT {DDMTemplate.*} FROM (SELECT DISTINCT ddmTemplate.templateId FROM DDMTemplate ddmTemplate WHERE ";
7749            private static final String _FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_2 =
7750                    ") TEMP_TABLE INNER JOIN DDMTemplate ON TEMP_TABLE.templateId = DDMTemplate.templateId";
7751            private static final String _FILTER_SQL_COUNT_DDMTEMPLATE_WHERE = "SELECT COUNT(DISTINCT ddmTemplate.templateId) AS COUNT_VALUE FROM DDMTemplate ddmTemplate WHERE ";
7752            private static final String _FILTER_ENTITY_ALIAS = "ddmTemplate";
7753            private static final String _FILTER_ENTITY_TABLE = "DDMTemplate";
7754            private static final String _ORDER_BY_ENTITY_ALIAS = "ddmTemplate.";
7755            private static final String _ORDER_BY_ENTITY_TABLE = "DDMTemplate.";
7756            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DDMTemplate exists with the primary key ";
7757            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DDMTemplate exists with the key {";
7758            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
7759            private static Log _log = LogFactoryUtil.getLog(DDMTemplatePersistenceImpl.class);
7760            private static DDMTemplate _nullDDMTemplate = new DDMTemplateImpl() {
7761                            @Override
7762                            public Object clone() {
7763                                    return this;
7764                            }
7765    
7766                            @Override
7767                            public CacheModel<DDMTemplate> toCacheModel() {
7768                                    return _nullDDMTemplateCacheModel;
7769                            }
7770                    };
7771    
7772            private static CacheModel<DDMTemplate> _nullDDMTemplateCacheModel = new CacheModel<DDMTemplate>() {
7773                            public DDMTemplate toEntityModel() {
7774                                    return _nullDDMTemplate;
7775                            }
7776                    };
7777    }