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