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