001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.dynamicdatamapping.service.persistence;
016    
017    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderPath;
021    import com.liferay.portal.kernel.dao.orm.Query;
022    import com.liferay.portal.kernel.dao.orm.QueryPos;
023    import com.liferay.portal.kernel.dao.orm.QueryUtil;
024    import com.liferay.portal.kernel.dao.orm.SQLQuery;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.ArrayUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.SetUtil;
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.UnmodifiableList;
038    import com.liferay.portal.kernel.util.Validator;
039    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
040    import com.liferay.portal.model.CacheModel;
041    import com.liferay.portal.model.ModelListener;
042    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
043    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044    
045    import com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException;
046    import com.liferay.portlet.dynamicdatamapping.model.DDMTemplate;
047    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateImpl;
048    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl;
049    
050    import java.io.Serializable;
051    
052    import java.util.ArrayList;
053    import java.util.Collections;
054    import java.util.List;
055    import java.util.Set;
056    
057    /**
058     * The persistence implementation for the d d m template service.
059     *
060     * <p>
061     * Caching information and settings can be found in <code>portal.properties</code>
062     * </p>
063     *
064     * @author Brian Wing Shun Chan
065     * @see DDMTemplatePersistence
066     * @see DDMTemplateUtil
067     * @generated
068     */
069    public class DDMTemplatePersistenceImpl extends BasePersistenceImpl<DDMTemplate>
070            implements DDMTemplatePersistence {
071            /*
072             * NOTE FOR DEVELOPERS:
073             *
074             * 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.
075             */
076            public static final String FINDER_CLASS_NAME_ENTITY = DDMTemplateImpl.class.getName();
077            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List1";
079            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080                    ".List2";
081            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
082                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
084            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
085                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
087            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
088                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
089                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
090            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
091                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
092                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
093                            new String[] {
094                                    String.class.getName(),
095                                    
096                            Integer.class.getName(), Integer.class.getName(),
097                                    OrderByComparator.class.getName()
098                            });
099            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
100                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
101                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
102                            new String[] { String.class.getName() },
103                            DDMTemplateModelImpl.UUID_COLUMN_BITMASK);
104            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
105                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
106                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
107                            new String[] { String.class.getName() });
108    
109            /**
110             * Returns all the d d m templates where uuid = &#63;.
111             *
112             * @param uuid the uuid
113             * @return the matching d d m templates
114             * @throws SystemException if a system exception occurred
115             */
116            @Override
117            public List<DDMTemplate> findByUuid(String uuid) throws SystemException {
118                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
119            }
120    
121            /**
122             * Returns a range of all the d d m templates where uuid = &#63;.
123             *
124             * <p>
125             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
126             * </p>
127             *
128             * @param uuid the uuid
129             * @param start the lower bound of the range of d d m templates
130             * @param end the upper bound of the range of d d m templates (not inclusive)
131             * @return the range of matching d d m templates
132             * @throws SystemException if a system exception occurred
133             */
134            @Override
135            public List<DDMTemplate> findByUuid(String uuid, int start, int end)
136                    throws SystemException {
137                    return findByUuid(uuid, start, end, null);
138            }
139    
140            /**
141             * Returns an ordered range of all the d d m templates where uuid = &#63;.
142             *
143             * <p>
144             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
145             * </p>
146             *
147             * @param uuid the uuid
148             * @param start the lower bound of the range of d d m templates
149             * @param end the upper bound of the range of d d m templates (not inclusive)
150             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
151             * @return the ordered range of matching d d m templates
152             * @throws SystemException if a system exception occurred
153             */
154            @Override
155            public List<DDMTemplate> findByUuid(String uuid, int start, int end,
156                    OrderByComparator orderByComparator) throws SystemException {
157                    boolean pagination = true;
158                    FinderPath finderPath = null;
159                    Object[] finderArgs = null;
160    
161                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
162                                    (orderByComparator == null)) {
163                            pagination = false;
164                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
165                            finderArgs = new Object[] { uuid };
166                    }
167                    else {
168                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
169                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
170                    }
171    
172                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
173                                    finderArgs, this);
174    
175                    if ((list != null) && !list.isEmpty()) {
176                            for (DDMTemplate ddmTemplate : list) {
177                                    if (!Validator.equals(uuid, ddmTemplate.getUuid())) {
178                                            list = null;
179    
180                                            break;
181                                    }
182                            }
183                    }
184    
185                    if (list == null) {
186                            StringBundler query = null;
187    
188                            if (orderByComparator != null) {
189                                    query = new StringBundler(3 +
190                                                    (orderByComparator.getOrderByFields().length * 3));
191                            }
192                            else {
193                                    query = new StringBundler(3);
194                            }
195    
196                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
197    
198                            boolean bindUuid = false;
199    
200                            if (uuid == null) {
201                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
202                            }
203                            else if (uuid.equals(StringPool.BLANK)) {
204                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
205                            }
206                            else {
207                                    bindUuid = true;
208    
209                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
210                            }
211    
212                            if (orderByComparator != null) {
213                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
214                                            orderByComparator);
215                            }
216                            else
217                             if (pagination) {
218                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
219                            }
220    
221                            String sql = query.toString();
222    
223                            Session session = null;
224    
225                            try {
226                                    session = openSession();
227    
228                                    Query q = session.createQuery(sql);
229    
230                                    QueryPos qPos = QueryPos.getInstance(q);
231    
232                                    if (bindUuid) {
233                                            qPos.add(uuid);
234                                    }
235    
236                                    if (!pagination) {
237                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
238                                                            start, end, false);
239    
240                                            Collections.sort(list);
241    
242                                            list = new UnmodifiableList<DDMTemplate>(list);
243                                    }
244                                    else {
245                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
246                                                            start, end);
247                                    }
248    
249                                    cacheResult(list);
250    
251                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
252                            }
253                            catch (Exception e) {
254                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
255    
256                                    throw processException(e);
257                            }
258                            finally {
259                                    closeSession(session);
260                            }
261                    }
262    
263                    return list;
264            }
265    
266            /**
267             * Returns the first d d m template in the ordered set where uuid = &#63;.
268             *
269             * @param uuid the uuid
270             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
271             * @return the first matching d d m template
272             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
273             * @throws SystemException if a system exception occurred
274             */
275            @Override
276            public DDMTemplate findByUuid_First(String uuid,
277                    OrderByComparator orderByComparator)
278                    throws NoSuchTemplateException, SystemException {
279                    DDMTemplate ddmTemplate = fetchByUuid_First(uuid, orderByComparator);
280    
281                    if (ddmTemplate != null) {
282                            return ddmTemplate;
283                    }
284    
285                    StringBundler msg = new StringBundler(4);
286    
287                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
288    
289                    msg.append("uuid=");
290                    msg.append(uuid);
291    
292                    msg.append(StringPool.CLOSE_CURLY_BRACE);
293    
294                    throw new NoSuchTemplateException(msg.toString());
295            }
296    
297            /**
298             * Returns the first d d m template in the ordered set where uuid = &#63;.
299             *
300             * @param uuid the uuid
301             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
302             * @return the first matching d d m template, or <code>null</code> if a matching d d m template could not be found
303             * @throws SystemException if a system exception occurred
304             */
305            @Override
306            public DDMTemplate fetchByUuid_First(String uuid,
307                    OrderByComparator orderByComparator) throws SystemException {
308                    List<DDMTemplate> list = findByUuid(uuid, 0, 1, orderByComparator);
309    
310                    if (!list.isEmpty()) {
311                            return list.get(0);
312                    }
313    
314                    return null;
315            }
316    
317            /**
318             * Returns the last d d m template in the ordered set where uuid = &#63;.
319             *
320             * @param uuid the uuid
321             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
322             * @return the last matching d d m template
323             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
324             * @throws SystemException if a system exception occurred
325             */
326            @Override
327            public DDMTemplate findByUuid_Last(String uuid,
328                    OrderByComparator orderByComparator)
329                    throws NoSuchTemplateException, SystemException {
330                    DDMTemplate ddmTemplate = fetchByUuid_Last(uuid, orderByComparator);
331    
332                    if (ddmTemplate != null) {
333                            return ddmTemplate;
334                    }
335    
336                    StringBundler msg = new StringBundler(4);
337    
338                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
339    
340                    msg.append("uuid=");
341                    msg.append(uuid);
342    
343                    msg.append(StringPool.CLOSE_CURLY_BRACE);
344    
345                    throw new NoSuchTemplateException(msg.toString());
346            }
347    
348            /**
349             * Returns the last d d m template in the ordered set where uuid = &#63;.
350             *
351             * @param uuid the uuid
352             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
353             * @return the last matching d d m template, or <code>null</code> if a matching d d m template could not be found
354             * @throws SystemException if a system exception occurred
355             */
356            @Override
357            public DDMTemplate fetchByUuid_Last(String uuid,
358                    OrderByComparator orderByComparator) throws SystemException {
359                    int count = countByUuid(uuid);
360    
361                    if (count == 0) {
362                            return null;
363                    }
364    
365                    List<DDMTemplate> list = findByUuid(uuid, count - 1, count,
366                                    orderByComparator);
367    
368                    if (!list.isEmpty()) {
369                            return list.get(0);
370                    }
371    
372                    return null;
373            }
374    
375            /**
376             * Returns the d d m templates before and after the current d d m template in the ordered set where uuid = &#63;.
377             *
378             * @param templateId the primary key of the current d d m template
379             * @param uuid the uuid
380             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
381             * @return the previous, current, and next d d m template
382             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
383             * @throws SystemException if a system exception occurred
384             */
385            @Override
386            public DDMTemplate[] findByUuid_PrevAndNext(long templateId, String uuid,
387                    OrderByComparator orderByComparator)
388                    throws NoSuchTemplateException, SystemException {
389                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
390    
391                    Session session = null;
392    
393                    try {
394                            session = openSession();
395    
396                            DDMTemplate[] array = new DDMTemplateImpl[3];
397    
398                            array[0] = getByUuid_PrevAndNext(session, ddmTemplate, uuid,
399                                            orderByComparator, true);
400    
401                            array[1] = ddmTemplate;
402    
403                            array[2] = getByUuid_PrevAndNext(session, ddmTemplate, uuid,
404                                            orderByComparator, false);
405    
406                            return array;
407                    }
408                    catch (Exception e) {
409                            throw processException(e);
410                    }
411                    finally {
412                            closeSession(session);
413                    }
414            }
415    
416            protected DDMTemplate getByUuid_PrevAndNext(Session session,
417                    DDMTemplate ddmTemplate, String uuid,
418                    OrderByComparator orderByComparator, boolean previous) {
419                    StringBundler query = null;
420    
421                    if (orderByComparator != null) {
422                            query = new StringBundler(6 +
423                                            (orderByComparator.getOrderByFields().length * 6));
424                    }
425                    else {
426                            query = new StringBundler(3);
427                    }
428    
429                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
430    
431                    boolean bindUuid = false;
432    
433                    if (uuid == null) {
434                            query.append(_FINDER_COLUMN_UUID_UUID_1);
435                    }
436                    else if (uuid.equals(StringPool.BLANK)) {
437                            query.append(_FINDER_COLUMN_UUID_UUID_3);
438                    }
439                    else {
440                            bindUuid = true;
441    
442                            query.append(_FINDER_COLUMN_UUID_UUID_2);
443                    }
444    
445                    if (orderByComparator != null) {
446                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
447    
448                            if (orderByConditionFields.length > 0) {
449                                    query.append(WHERE_AND);
450                            }
451    
452                            for (int i = 0; i < orderByConditionFields.length; i++) {
453                                    query.append(_ORDER_BY_ENTITY_ALIAS);
454                                    query.append(orderByConditionFields[i]);
455    
456                                    if ((i + 1) < orderByConditionFields.length) {
457                                            if (orderByComparator.isAscending() ^ previous) {
458                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
459                                            }
460                                            else {
461                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
462                                            }
463                                    }
464                                    else {
465                                            if (orderByComparator.isAscending() ^ previous) {
466                                                    query.append(WHERE_GREATER_THAN);
467                                            }
468                                            else {
469                                                    query.append(WHERE_LESSER_THAN);
470                                            }
471                                    }
472                            }
473    
474                            query.append(ORDER_BY_CLAUSE);
475    
476                            String[] orderByFields = orderByComparator.getOrderByFields();
477    
478                            for (int i = 0; i < orderByFields.length; i++) {
479                                    query.append(_ORDER_BY_ENTITY_ALIAS);
480                                    query.append(orderByFields[i]);
481    
482                                    if ((i + 1) < orderByFields.length) {
483                                            if (orderByComparator.isAscending() ^ previous) {
484                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
485                                            }
486                                            else {
487                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
488                                            }
489                                    }
490                                    else {
491                                            if (orderByComparator.isAscending() ^ previous) {
492                                                    query.append(ORDER_BY_ASC);
493                                            }
494                                            else {
495                                                    query.append(ORDER_BY_DESC);
496                                            }
497                                    }
498                            }
499                    }
500                    else {
501                            query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
502                    }
503    
504                    String sql = query.toString();
505    
506                    Query q = session.createQuery(sql);
507    
508                    q.setFirstResult(0);
509                    q.setMaxResults(2);
510    
511                    QueryPos qPos = QueryPos.getInstance(q);
512    
513                    if (bindUuid) {
514                            qPos.add(uuid);
515                    }
516    
517                    if (orderByComparator != null) {
518                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
519    
520                            for (Object value : values) {
521                                    qPos.add(value);
522                            }
523                    }
524    
525                    List<DDMTemplate> list = q.list();
526    
527                    if (list.size() == 2) {
528                            return list.get(1);
529                    }
530                    else {
531                            return null;
532                    }
533            }
534    
535            /**
536             * Removes all the d d m templates where uuid = &#63; from the database.
537             *
538             * @param uuid the uuid
539             * @throws SystemException if a system exception occurred
540             */
541            @Override
542            public void removeByUuid(String uuid) throws SystemException {
543                    for (DDMTemplate ddmTemplate : findByUuid(uuid, QueryUtil.ALL_POS,
544                                    QueryUtil.ALL_POS, null)) {
545                            remove(ddmTemplate);
546                    }
547            }
548    
549            /**
550             * Returns the number of d d m templates where uuid = &#63;.
551             *
552             * @param uuid the uuid
553             * @return the number of matching d d m templates
554             * @throws SystemException if a system exception occurred
555             */
556            @Override
557            public int countByUuid(String uuid) throws SystemException {
558                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
559    
560                    Object[] finderArgs = new Object[] { uuid };
561    
562                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
563                                    this);
564    
565                    if (count == null) {
566                            StringBundler query = new StringBundler(2);
567    
568                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
569    
570                            boolean bindUuid = false;
571    
572                            if (uuid == null) {
573                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
574                            }
575                            else if (uuid.equals(StringPool.BLANK)) {
576                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
577                            }
578                            else {
579                                    bindUuid = true;
580    
581                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
582                            }
583    
584                            String sql = query.toString();
585    
586                            Session session = null;
587    
588                            try {
589                                    session = openSession();
590    
591                                    Query q = session.createQuery(sql);
592    
593                                    QueryPos qPos = QueryPos.getInstance(q);
594    
595                                    if (bindUuid) {
596                                            qPos.add(uuid);
597                                    }
598    
599                                    count = (Long)q.uniqueResult();
600    
601                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
602                            }
603                            catch (Exception e) {
604                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
605    
606                                    throw processException(e);
607                            }
608                            finally {
609                                    closeSession(session);
610                            }
611                    }
612    
613                    return count.intValue();
614            }
615    
616            private static final String _FINDER_COLUMN_UUID_UUID_1 = "ddmTemplate.uuid IS NULL";
617            private static final String _FINDER_COLUMN_UUID_UUID_2 = "ddmTemplate.uuid = ?";
618            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(ddmTemplate.uuid IS NULL OR ddmTemplate.uuid = '')";
619            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
620                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
621                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
622                            new String[] { String.class.getName(), Long.class.getName() },
623                            DDMTemplateModelImpl.UUID_COLUMN_BITMASK |
624                            DDMTemplateModelImpl.GROUPID_COLUMN_BITMASK);
625            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
626                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
627                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
628                            new String[] { String.class.getName(), Long.class.getName() });
629    
630            /**
631             * 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.
632             *
633             * @param uuid the uuid
634             * @param groupId the group ID
635             * @return the matching d d m template
636             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
637             * @throws SystemException if a system exception occurred
638             */
639            @Override
640            public DDMTemplate findByUUID_G(String uuid, long groupId)
641                    throws NoSuchTemplateException, SystemException {
642                    DDMTemplate ddmTemplate = fetchByUUID_G(uuid, groupId);
643    
644                    if (ddmTemplate == null) {
645                            StringBundler msg = new StringBundler(6);
646    
647                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
648    
649                            msg.append("uuid=");
650                            msg.append(uuid);
651    
652                            msg.append(", groupId=");
653                            msg.append(groupId);
654    
655                            msg.append(StringPool.CLOSE_CURLY_BRACE);
656    
657                            if (_log.isWarnEnabled()) {
658                                    _log.warn(msg.toString());
659                            }
660    
661                            throw new NoSuchTemplateException(msg.toString());
662                    }
663    
664                    return ddmTemplate;
665            }
666    
667            /**
668             * 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.
669             *
670             * @param uuid the uuid
671             * @param groupId the group ID
672             * @return the matching d d m template, or <code>null</code> if a matching d d m template could not be found
673             * @throws SystemException if a system exception occurred
674             */
675            @Override
676            public DDMTemplate fetchByUUID_G(String uuid, long groupId)
677                    throws SystemException {
678                    return fetchByUUID_G(uuid, groupId, true);
679            }
680    
681            /**
682             * 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.
683             *
684             * @param uuid the uuid
685             * @param groupId the group ID
686             * @param retrieveFromCache whether to use the finder cache
687             * @return the matching d d m template, or <code>null</code> if a matching d d m template could not be found
688             * @throws SystemException if a system exception occurred
689             */
690            @Override
691            public DDMTemplate fetchByUUID_G(String uuid, long groupId,
692                    boolean retrieveFromCache) throws SystemException {
693                    Object[] finderArgs = new Object[] { uuid, groupId };
694    
695                    Object result = null;
696    
697                    if (retrieveFromCache) {
698                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
699                                            finderArgs, this);
700                    }
701    
702                    if (result instanceof DDMTemplate) {
703                            DDMTemplate ddmTemplate = (DDMTemplate)result;
704    
705                            if (!Validator.equals(uuid, ddmTemplate.getUuid()) ||
706                                            (groupId != ddmTemplate.getGroupId())) {
707                                    result = null;
708                            }
709                    }
710    
711                    if (result == null) {
712                            StringBundler query = new StringBundler(4);
713    
714                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
715    
716                            boolean bindUuid = false;
717    
718                            if (uuid == null) {
719                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
720                            }
721                            else if (uuid.equals(StringPool.BLANK)) {
722                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
723                            }
724                            else {
725                                    bindUuid = true;
726    
727                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
728                            }
729    
730                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
731    
732                            String sql = query.toString();
733    
734                            Session session = null;
735    
736                            try {
737                                    session = openSession();
738    
739                                    Query q = session.createQuery(sql);
740    
741                                    QueryPos qPos = QueryPos.getInstance(q);
742    
743                                    if (bindUuid) {
744                                            qPos.add(uuid);
745                                    }
746    
747                                    qPos.add(groupId);
748    
749                                    List<DDMTemplate> list = q.list();
750    
751                                    if (list.isEmpty()) {
752                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
753                                                    finderArgs, list);
754                                    }
755                                    else {
756                                            DDMTemplate ddmTemplate = list.get(0);
757    
758                                            result = ddmTemplate;
759    
760                                            cacheResult(ddmTemplate);
761    
762                                            if ((ddmTemplate.getUuid() == null) ||
763                                                            !ddmTemplate.getUuid().equals(uuid) ||
764                                                            (ddmTemplate.getGroupId() != groupId)) {
765                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
766                                                            finderArgs, ddmTemplate);
767                                            }
768                                    }
769                            }
770                            catch (Exception e) {
771                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
772                                            finderArgs);
773    
774                                    throw processException(e);
775                            }
776                            finally {
777                                    closeSession(session);
778                            }
779                    }
780    
781                    if (result instanceof List<?>) {
782                            return null;
783                    }
784                    else {
785                            return (DDMTemplate)result;
786                    }
787            }
788    
789            /**
790             * Removes the d d m template where uuid = &#63; and groupId = &#63; from the database.
791             *
792             * @param uuid the uuid
793             * @param groupId the group ID
794             * @return the d d m template that was removed
795             * @throws SystemException if a system exception occurred
796             */
797            @Override
798            public DDMTemplate removeByUUID_G(String uuid, long groupId)
799                    throws NoSuchTemplateException, SystemException {
800                    DDMTemplate ddmTemplate = findByUUID_G(uuid, groupId);
801    
802                    return remove(ddmTemplate);
803            }
804    
805            /**
806             * Returns the number of d d m templates where uuid = &#63; and groupId = &#63;.
807             *
808             * @param uuid the uuid
809             * @param groupId the group ID
810             * @return the number of matching d d m templates
811             * @throws SystemException if a system exception occurred
812             */
813            @Override
814            public int countByUUID_G(String uuid, long groupId)
815                    throws SystemException {
816                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
817    
818                    Object[] finderArgs = new Object[] { uuid, groupId };
819    
820                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
821                                    this);
822    
823                    if (count == null) {
824                            StringBundler query = new StringBundler(3);
825    
826                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
827    
828                            boolean bindUuid = false;
829    
830                            if (uuid == null) {
831                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
832                            }
833                            else if (uuid.equals(StringPool.BLANK)) {
834                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
835                            }
836                            else {
837                                    bindUuid = true;
838    
839                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
840                            }
841    
842                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
843    
844                            String sql = query.toString();
845    
846                            Session session = null;
847    
848                            try {
849                                    session = openSession();
850    
851                                    Query q = session.createQuery(sql);
852    
853                                    QueryPos qPos = QueryPos.getInstance(q);
854    
855                                    if (bindUuid) {
856                                            qPos.add(uuid);
857                                    }
858    
859                                    qPos.add(groupId);
860    
861                                    count = (Long)q.uniqueResult();
862    
863                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
864                            }
865                            catch (Exception e) {
866                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
867    
868                                    throw processException(e);
869                            }
870                            finally {
871                                    closeSession(session);
872                            }
873                    }
874    
875                    return count.intValue();
876            }
877    
878            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "ddmTemplate.uuid IS NULL AND ";
879            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "ddmTemplate.uuid = ? AND ";
880            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(ddmTemplate.uuid IS NULL OR ddmTemplate.uuid = '') AND ";
881            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "ddmTemplate.groupId = ?";
882            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
883                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
884                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
885                            new String[] {
886                                    String.class.getName(), Long.class.getName(),
887                                    
888                            Integer.class.getName(), Integer.class.getName(),
889                                    OrderByComparator.class.getName()
890                            });
891            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
892                    new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
893                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
894                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
895                            new String[] { String.class.getName(), Long.class.getName() },
896                            DDMTemplateModelImpl.UUID_COLUMN_BITMASK |
897                            DDMTemplateModelImpl.COMPANYID_COLUMN_BITMASK);
898            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
899                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
900                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
901                            new String[] { String.class.getName(), Long.class.getName() });
902    
903            /**
904             * Returns all the d d m templates where uuid = &#63; and companyId = &#63;.
905             *
906             * @param uuid the uuid
907             * @param companyId the company ID
908             * @return the matching d d m templates
909             * @throws SystemException if a system exception occurred
910             */
911            @Override
912            public List<DDMTemplate> findByUuid_C(String uuid, long companyId)
913                    throws SystemException {
914                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
915                            QueryUtil.ALL_POS, null);
916            }
917    
918            /**
919             * Returns a range of all the d d m templates where uuid = &#63; and companyId = &#63;.
920             *
921             * <p>
922             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
923             * </p>
924             *
925             * @param uuid the uuid
926             * @param companyId the company ID
927             * @param start the lower bound of the range of d d m templates
928             * @param end the upper bound of the range of d d m templates (not inclusive)
929             * @return the range of matching d d m templates
930             * @throws SystemException if a system exception occurred
931             */
932            @Override
933            public List<DDMTemplate> findByUuid_C(String uuid, long companyId,
934                    int start, int end) throws SystemException {
935                    return findByUuid_C(uuid, companyId, start, end, null);
936            }
937    
938            /**
939             * Returns an ordered range of all the d d m templates where uuid = &#63; and companyId = &#63;.
940             *
941             * <p>
942             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
943             * </p>
944             *
945             * @param uuid the uuid
946             * @param companyId the company ID
947             * @param start the lower bound of the range of d d m templates
948             * @param end the upper bound of the range of d d m templates (not inclusive)
949             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
950             * @return the ordered range of matching d d m templates
951             * @throws SystemException if a system exception occurred
952             */
953            @Override
954            public List<DDMTemplate> findByUuid_C(String uuid, long companyId,
955                    int start, int end, OrderByComparator orderByComparator)
956                    throws SystemException {
957                    boolean pagination = true;
958                    FinderPath finderPath = null;
959                    Object[] finderArgs = null;
960    
961                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
962                                    (orderByComparator == null)) {
963                            pagination = false;
964                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
965                            finderArgs = new Object[] { uuid, companyId };
966                    }
967                    else {
968                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
969                            finderArgs = new Object[] {
970                                            uuid, companyId,
971                                            
972                                            start, end, orderByComparator
973                                    };
974                    }
975    
976                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
977                                    finderArgs, this);
978    
979                    if ((list != null) && !list.isEmpty()) {
980                            for (DDMTemplate ddmTemplate : list) {
981                                    if (!Validator.equals(uuid, ddmTemplate.getUuid()) ||
982                                                    (companyId != ddmTemplate.getCompanyId())) {
983                                            list = null;
984    
985                                            break;
986                                    }
987                            }
988                    }
989    
990                    if (list == null) {
991                            StringBundler query = null;
992    
993                            if (orderByComparator != null) {
994                                    query = new StringBundler(4 +
995                                                    (orderByComparator.getOrderByFields().length * 3));
996                            }
997                            else {
998                                    query = new StringBundler(4);
999                            }
1000    
1001                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
1002    
1003                            boolean bindUuid = false;
1004    
1005                            if (uuid == null) {
1006                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1007                            }
1008                            else if (uuid.equals(StringPool.BLANK)) {
1009                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1010                            }
1011                            else {
1012                                    bindUuid = true;
1013    
1014                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1015                            }
1016    
1017                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1018    
1019                            if (orderByComparator != null) {
1020                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1021                                            orderByComparator);
1022                            }
1023                            else
1024                             if (pagination) {
1025                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
1026                            }
1027    
1028                            String sql = query.toString();
1029    
1030                            Session session = null;
1031    
1032                            try {
1033                                    session = openSession();
1034    
1035                                    Query q = session.createQuery(sql);
1036    
1037                                    QueryPos qPos = QueryPos.getInstance(q);
1038    
1039                                    if (bindUuid) {
1040                                            qPos.add(uuid);
1041                                    }
1042    
1043                                    qPos.add(companyId);
1044    
1045                                    if (!pagination) {
1046                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
1047                                                            start, end, false);
1048    
1049                                            Collections.sort(list);
1050    
1051                                            list = new UnmodifiableList<DDMTemplate>(list);
1052                                    }
1053                                    else {
1054                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
1055                                                            start, end);
1056                                    }
1057    
1058                                    cacheResult(list);
1059    
1060                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1061                            }
1062                            catch (Exception e) {
1063                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1064    
1065                                    throw processException(e);
1066                            }
1067                            finally {
1068                                    closeSession(session);
1069                            }
1070                    }
1071    
1072                    return list;
1073            }
1074    
1075            /**
1076             * Returns the first d d m template in the ordered set where uuid = &#63; and companyId = &#63;.
1077             *
1078             * @param uuid the uuid
1079             * @param companyId the company ID
1080             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1081             * @return the first matching d d m template
1082             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
1083             * @throws SystemException if a system exception occurred
1084             */
1085            @Override
1086            public DDMTemplate findByUuid_C_First(String uuid, long companyId,
1087                    OrderByComparator orderByComparator)
1088                    throws NoSuchTemplateException, SystemException {
1089                    DDMTemplate ddmTemplate = fetchByUuid_C_First(uuid, companyId,
1090                                    orderByComparator);
1091    
1092                    if (ddmTemplate != null) {
1093                            return ddmTemplate;
1094                    }
1095    
1096                    StringBundler msg = new StringBundler(6);
1097    
1098                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1099    
1100                    msg.append("uuid=");
1101                    msg.append(uuid);
1102    
1103                    msg.append(", companyId=");
1104                    msg.append(companyId);
1105    
1106                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1107    
1108                    throw new NoSuchTemplateException(msg.toString());
1109            }
1110    
1111            /**
1112             * Returns the first d d m template in the ordered set where uuid = &#63; and companyId = &#63;.
1113             *
1114             * @param uuid the uuid
1115             * @param companyId the company ID
1116             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1117             * @return the first matching d d m template, or <code>null</code> if a matching d d m template could not be found
1118             * @throws SystemException if a system exception occurred
1119             */
1120            @Override
1121            public DDMTemplate fetchByUuid_C_First(String uuid, long companyId,
1122                    OrderByComparator orderByComparator) throws SystemException {
1123                    List<DDMTemplate> list = findByUuid_C(uuid, companyId, 0, 1,
1124                                    orderByComparator);
1125    
1126                    if (!list.isEmpty()) {
1127                            return list.get(0);
1128                    }
1129    
1130                    return null;
1131            }
1132    
1133            /**
1134             * Returns the last d d m template in the ordered set where uuid = &#63; and companyId = &#63;.
1135             *
1136             * @param uuid the uuid
1137             * @param companyId the company ID
1138             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1139             * @return the last matching d d m template
1140             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
1141             * @throws SystemException if a system exception occurred
1142             */
1143            @Override
1144            public DDMTemplate findByUuid_C_Last(String uuid, long companyId,
1145                    OrderByComparator orderByComparator)
1146                    throws NoSuchTemplateException, SystemException {
1147                    DDMTemplate ddmTemplate = fetchByUuid_C_Last(uuid, companyId,
1148                                    orderByComparator);
1149    
1150                    if (ddmTemplate != null) {
1151                            return ddmTemplate;
1152                    }
1153    
1154                    StringBundler msg = new StringBundler(6);
1155    
1156                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1157    
1158                    msg.append("uuid=");
1159                    msg.append(uuid);
1160    
1161                    msg.append(", companyId=");
1162                    msg.append(companyId);
1163    
1164                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1165    
1166                    throw new NoSuchTemplateException(msg.toString());
1167            }
1168    
1169            /**
1170             * Returns the last d d m template in the ordered set where uuid = &#63; and companyId = &#63;.
1171             *
1172             * @param uuid the uuid
1173             * @param companyId the company ID
1174             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1175             * @return the last matching d d m template, or <code>null</code> if a matching d d m template could not be found
1176             * @throws SystemException if a system exception occurred
1177             */
1178            @Override
1179            public DDMTemplate fetchByUuid_C_Last(String uuid, long companyId,
1180                    OrderByComparator orderByComparator) throws SystemException {
1181                    int count = countByUuid_C(uuid, companyId);
1182    
1183                    if (count == 0) {
1184                            return null;
1185                    }
1186    
1187                    List<DDMTemplate> list = findByUuid_C(uuid, companyId, count - 1,
1188                                    count, orderByComparator);
1189    
1190                    if (!list.isEmpty()) {
1191                            return list.get(0);
1192                    }
1193    
1194                    return null;
1195            }
1196    
1197            /**
1198             * Returns the d d m templates before and after the current d d m template in the ordered set where uuid = &#63; and companyId = &#63;.
1199             *
1200             * @param templateId the primary key of the current d d m template
1201             * @param uuid the uuid
1202             * @param companyId the company ID
1203             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1204             * @return the previous, current, and next d d m template
1205             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
1206             * @throws SystemException if a system exception occurred
1207             */
1208            @Override
1209            public DDMTemplate[] findByUuid_C_PrevAndNext(long templateId, String uuid,
1210                    long companyId, OrderByComparator orderByComparator)
1211                    throws NoSuchTemplateException, SystemException {
1212                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
1213    
1214                    Session session = null;
1215    
1216                    try {
1217                            session = openSession();
1218    
1219                            DDMTemplate[] array = new DDMTemplateImpl[3];
1220    
1221                            array[0] = getByUuid_C_PrevAndNext(session, ddmTemplate, uuid,
1222                                            companyId, orderByComparator, true);
1223    
1224                            array[1] = ddmTemplate;
1225    
1226                            array[2] = getByUuid_C_PrevAndNext(session, ddmTemplate, uuid,
1227                                            companyId, orderByComparator, false);
1228    
1229                            return array;
1230                    }
1231                    catch (Exception e) {
1232                            throw processException(e);
1233                    }
1234                    finally {
1235                            closeSession(session);
1236                    }
1237            }
1238    
1239            protected DDMTemplate getByUuid_C_PrevAndNext(Session session,
1240                    DDMTemplate ddmTemplate, String uuid, long companyId,
1241                    OrderByComparator orderByComparator, boolean previous) {
1242                    StringBundler query = null;
1243    
1244                    if (orderByComparator != null) {
1245                            query = new StringBundler(6 +
1246                                            (orderByComparator.getOrderByFields().length * 6));
1247                    }
1248                    else {
1249                            query = new StringBundler(3);
1250                    }
1251    
1252                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
1253    
1254                    boolean bindUuid = false;
1255    
1256                    if (uuid == null) {
1257                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1258                    }
1259                    else if (uuid.equals(StringPool.BLANK)) {
1260                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1261                    }
1262                    else {
1263                            bindUuid = true;
1264    
1265                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1266                    }
1267    
1268                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1269    
1270                    if (orderByComparator != null) {
1271                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1272    
1273                            if (orderByConditionFields.length > 0) {
1274                                    query.append(WHERE_AND);
1275                            }
1276    
1277                            for (int i = 0; i < orderByConditionFields.length; i++) {
1278                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1279                                    query.append(orderByConditionFields[i]);
1280    
1281                                    if ((i + 1) < orderByConditionFields.length) {
1282                                            if (orderByComparator.isAscending() ^ previous) {
1283                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1284                                            }
1285                                            else {
1286                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1287                                            }
1288                                    }
1289                                    else {
1290                                            if (orderByComparator.isAscending() ^ previous) {
1291                                                    query.append(WHERE_GREATER_THAN);
1292                                            }
1293                                            else {
1294                                                    query.append(WHERE_LESSER_THAN);
1295                                            }
1296                                    }
1297                            }
1298    
1299                            query.append(ORDER_BY_CLAUSE);
1300    
1301                            String[] orderByFields = orderByComparator.getOrderByFields();
1302    
1303                            for (int i = 0; i < orderByFields.length; i++) {
1304                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1305                                    query.append(orderByFields[i]);
1306    
1307                                    if ((i + 1) < orderByFields.length) {
1308                                            if (orderByComparator.isAscending() ^ previous) {
1309                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1310                                            }
1311                                            else {
1312                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1313                                            }
1314                                    }
1315                                    else {
1316                                            if (orderByComparator.isAscending() ^ previous) {
1317                                                    query.append(ORDER_BY_ASC);
1318                                            }
1319                                            else {
1320                                                    query.append(ORDER_BY_DESC);
1321                                            }
1322                                    }
1323                            }
1324                    }
1325                    else {
1326                            query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
1327                    }
1328    
1329                    String sql = query.toString();
1330    
1331                    Query q = session.createQuery(sql);
1332    
1333                    q.setFirstResult(0);
1334                    q.setMaxResults(2);
1335    
1336                    QueryPos qPos = QueryPos.getInstance(q);
1337    
1338                    if (bindUuid) {
1339                            qPos.add(uuid);
1340                    }
1341    
1342                    qPos.add(companyId);
1343    
1344                    if (orderByComparator != null) {
1345                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
1346    
1347                            for (Object value : values) {
1348                                    qPos.add(value);
1349                            }
1350                    }
1351    
1352                    List<DDMTemplate> list = q.list();
1353    
1354                    if (list.size() == 2) {
1355                            return list.get(1);
1356                    }
1357                    else {
1358                            return null;
1359                    }
1360            }
1361    
1362            /**
1363             * Removes all the d d m templates where uuid = &#63; and companyId = &#63; from the database.
1364             *
1365             * @param uuid the uuid
1366             * @param companyId the company ID
1367             * @throws SystemException if a system exception occurred
1368             */
1369            @Override
1370            public void removeByUuid_C(String uuid, long companyId)
1371                    throws SystemException {
1372                    for (DDMTemplate ddmTemplate : findByUuid_C(uuid, companyId,
1373                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1374                            remove(ddmTemplate);
1375                    }
1376            }
1377    
1378            /**
1379             * Returns the number of d d m templates where uuid = &#63; and companyId = &#63;.
1380             *
1381             * @param uuid the uuid
1382             * @param companyId the company ID
1383             * @return the number of matching d d m templates
1384             * @throws SystemException if a system exception occurred
1385             */
1386            @Override
1387            public int countByUuid_C(String uuid, long companyId)
1388                    throws SystemException {
1389                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1390    
1391                    Object[] finderArgs = new Object[] { uuid, companyId };
1392    
1393                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1394                                    this);
1395    
1396                    if (count == null) {
1397                            StringBundler query = new StringBundler(3);
1398    
1399                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
1400    
1401                            boolean bindUuid = false;
1402    
1403                            if (uuid == null) {
1404                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1405                            }
1406                            else if (uuid.equals(StringPool.BLANK)) {
1407                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1408                            }
1409                            else {
1410                                    bindUuid = true;
1411    
1412                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1413                            }
1414    
1415                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1416    
1417                            String sql = query.toString();
1418    
1419                            Session session = null;
1420    
1421                            try {
1422                                    session = openSession();
1423    
1424                                    Query q = session.createQuery(sql);
1425    
1426                                    QueryPos qPos = QueryPos.getInstance(q);
1427    
1428                                    if (bindUuid) {
1429                                            qPos.add(uuid);
1430                                    }
1431    
1432                                    qPos.add(companyId);
1433    
1434                                    count = (Long)q.uniqueResult();
1435    
1436                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1437                            }
1438                            catch (Exception e) {
1439                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1440    
1441                                    throw processException(e);
1442                            }
1443                            finally {
1444                                    closeSession(session);
1445                            }
1446                    }
1447    
1448                    return count.intValue();
1449            }
1450    
1451            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "ddmTemplate.uuid IS NULL AND ";
1452            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "ddmTemplate.uuid = ? AND ";
1453            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(ddmTemplate.uuid IS NULL OR ddmTemplate.uuid = '') AND ";
1454            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "ddmTemplate.companyId = ?";
1455            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
1456                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
1457                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1458                            new String[] {
1459                                    Long.class.getName(),
1460                                    
1461                            Integer.class.getName(), Integer.class.getName(),
1462                                    OrderByComparator.class.getName()
1463                            });
1464            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1465                    new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
1466                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
1467                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1468                            new String[] { Long.class.getName() },
1469                            DDMTemplateModelImpl.GROUPID_COLUMN_BITMASK);
1470            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
1471                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
1472                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1473                            new String[] { Long.class.getName() });
1474    
1475            /**
1476             * Returns all the d d m templates where groupId = &#63;.
1477             *
1478             * @param groupId the group ID
1479             * @return the matching d d m templates
1480             * @throws SystemException if a system exception occurred
1481             */
1482            @Override
1483            public List<DDMTemplate> findByGroupId(long groupId)
1484                    throws SystemException {
1485                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1486            }
1487    
1488            /**
1489             * Returns a range of all the d d m templates where groupId = &#63;.
1490             *
1491             * <p>
1492             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1493             * </p>
1494             *
1495             * @param groupId the group ID
1496             * @param start the lower bound of the range of d d m templates
1497             * @param end the upper bound of the range of d d m templates (not inclusive)
1498             * @return the range of matching d d m templates
1499             * @throws SystemException if a system exception occurred
1500             */
1501            @Override
1502            public List<DDMTemplate> findByGroupId(long groupId, int start, int end)
1503                    throws SystemException {
1504                    return findByGroupId(groupId, start, end, null);
1505            }
1506    
1507            /**
1508             * Returns an ordered range of all the d d m templates where groupId = &#63;.
1509             *
1510             * <p>
1511             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1512             * </p>
1513             *
1514             * @param groupId the group ID
1515             * @param start the lower bound of the range of d d m templates
1516             * @param end the upper bound of the range of d d m templates (not inclusive)
1517             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1518             * @return the ordered range of matching d d m templates
1519             * @throws SystemException if a system exception occurred
1520             */
1521            @Override
1522            public List<DDMTemplate> findByGroupId(long groupId, int start, int end,
1523                    OrderByComparator orderByComparator) throws SystemException {
1524                    boolean pagination = true;
1525                    FinderPath finderPath = null;
1526                    Object[] finderArgs = null;
1527    
1528                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1529                                    (orderByComparator == null)) {
1530                            pagination = false;
1531                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1532                            finderArgs = new Object[] { groupId };
1533                    }
1534                    else {
1535                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1536                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1537                    }
1538    
1539                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
1540                                    finderArgs, this);
1541    
1542                    if ((list != null) && !list.isEmpty()) {
1543                            for (DDMTemplate ddmTemplate : list) {
1544                                    if ((groupId != ddmTemplate.getGroupId())) {
1545                                            list = null;
1546    
1547                                            break;
1548                                    }
1549                            }
1550                    }
1551    
1552                    if (list == null) {
1553                            StringBundler query = null;
1554    
1555                            if (orderByComparator != null) {
1556                                    query = new StringBundler(3 +
1557                                                    (orderByComparator.getOrderByFields().length * 3));
1558                            }
1559                            else {
1560                                    query = new StringBundler(3);
1561                            }
1562    
1563                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
1564    
1565                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1566    
1567                            if (orderByComparator != null) {
1568                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1569                                            orderByComparator);
1570                            }
1571                            else
1572                             if (pagination) {
1573                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
1574                            }
1575    
1576                            String sql = query.toString();
1577    
1578                            Session session = null;
1579    
1580                            try {
1581                                    session = openSession();
1582    
1583                                    Query q = session.createQuery(sql);
1584    
1585                                    QueryPos qPos = QueryPos.getInstance(q);
1586    
1587                                    qPos.add(groupId);
1588    
1589                                    if (!pagination) {
1590                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
1591                                                            start, end, false);
1592    
1593                                            Collections.sort(list);
1594    
1595                                            list = new UnmodifiableList<DDMTemplate>(list);
1596                                    }
1597                                    else {
1598                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
1599                                                            start, end);
1600                                    }
1601    
1602                                    cacheResult(list);
1603    
1604                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1605                            }
1606                            catch (Exception e) {
1607                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1608    
1609                                    throw processException(e);
1610                            }
1611                            finally {
1612                                    closeSession(session);
1613                            }
1614                    }
1615    
1616                    return list;
1617            }
1618    
1619            /**
1620             * Returns the first d d m template in the ordered set where groupId = &#63;.
1621             *
1622             * @param groupId the group ID
1623             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1624             * @return the first matching d d m template
1625             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
1626             * @throws SystemException if a system exception occurred
1627             */
1628            @Override
1629            public DDMTemplate findByGroupId_First(long groupId,
1630                    OrderByComparator orderByComparator)
1631                    throws NoSuchTemplateException, SystemException {
1632                    DDMTemplate ddmTemplate = fetchByGroupId_First(groupId,
1633                                    orderByComparator);
1634    
1635                    if (ddmTemplate != null) {
1636                            return ddmTemplate;
1637                    }
1638    
1639                    StringBundler msg = new StringBundler(4);
1640    
1641                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1642    
1643                    msg.append("groupId=");
1644                    msg.append(groupId);
1645    
1646                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1647    
1648                    throw new NoSuchTemplateException(msg.toString());
1649            }
1650    
1651            /**
1652             * Returns the first d d m template in the ordered set where groupId = &#63;.
1653             *
1654             * @param groupId the group ID
1655             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1656             * @return the first matching d d m template, or <code>null</code> if a matching d d m template could not be found
1657             * @throws SystemException if a system exception occurred
1658             */
1659            @Override
1660            public DDMTemplate fetchByGroupId_First(long groupId,
1661                    OrderByComparator orderByComparator) throws SystemException {
1662                    List<DDMTemplate> list = findByGroupId(groupId, 0, 1, orderByComparator);
1663    
1664                    if (!list.isEmpty()) {
1665                            return list.get(0);
1666                    }
1667    
1668                    return null;
1669            }
1670    
1671            /**
1672             * Returns the last d d m template in the ordered set where groupId = &#63;.
1673             *
1674             * @param groupId the group ID
1675             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1676             * @return the last matching d d m template
1677             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
1678             * @throws SystemException if a system exception occurred
1679             */
1680            @Override
1681            public DDMTemplate findByGroupId_Last(long groupId,
1682                    OrderByComparator orderByComparator)
1683                    throws NoSuchTemplateException, SystemException {
1684                    DDMTemplate ddmTemplate = fetchByGroupId_Last(groupId, orderByComparator);
1685    
1686                    if (ddmTemplate != null) {
1687                            return ddmTemplate;
1688                    }
1689    
1690                    StringBundler msg = new StringBundler(4);
1691    
1692                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1693    
1694                    msg.append("groupId=");
1695                    msg.append(groupId);
1696    
1697                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1698    
1699                    throw new NoSuchTemplateException(msg.toString());
1700            }
1701    
1702            /**
1703             * Returns the last d d m template in the ordered set where groupId = &#63;.
1704             *
1705             * @param groupId the group ID
1706             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1707             * @return the last matching d d m template, or <code>null</code> if a matching d d m template could not be found
1708             * @throws SystemException if a system exception occurred
1709             */
1710            @Override
1711            public DDMTemplate fetchByGroupId_Last(long groupId,
1712                    OrderByComparator orderByComparator) throws SystemException {
1713                    int count = countByGroupId(groupId);
1714    
1715                    if (count == 0) {
1716                            return null;
1717                    }
1718    
1719                    List<DDMTemplate> list = findByGroupId(groupId, count - 1, count,
1720                                    orderByComparator);
1721    
1722                    if (!list.isEmpty()) {
1723                            return list.get(0);
1724                    }
1725    
1726                    return null;
1727            }
1728    
1729            /**
1730             * Returns the d d m templates before and after the current d d m template in the ordered set where groupId = &#63;.
1731             *
1732             * @param templateId the primary key of the current d d m template
1733             * @param groupId the group ID
1734             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1735             * @return the previous, current, and next d d m template
1736             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
1737             * @throws SystemException if a system exception occurred
1738             */
1739            @Override
1740            public DDMTemplate[] findByGroupId_PrevAndNext(long templateId,
1741                    long groupId, OrderByComparator orderByComparator)
1742                    throws NoSuchTemplateException, SystemException {
1743                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
1744    
1745                    Session session = null;
1746    
1747                    try {
1748                            session = openSession();
1749    
1750                            DDMTemplate[] array = new DDMTemplateImpl[3];
1751    
1752                            array[0] = getByGroupId_PrevAndNext(session, ddmTemplate, groupId,
1753                                            orderByComparator, true);
1754    
1755                            array[1] = ddmTemplate;
1756    
1757                            array[2] = getByGroupId_PrevAndNext(session, ddmTemplate, groupId,
1758                                            orderByComparator, false);
1759    
1760                            return array;
1761                    }
1762                    catch (Exception e) {
1763                            throw processException(e);
1764                    }
1765                    finally {
1766                            closeSession(session);
1767                    }
1768            }
1769    
1770            protected DDMTemplate getByGroupId_PrevAndNext(Session session,
1771                    DDMTemplate ddmTemplate, long groupId,
1772                    OrderByComparator orderByComparator, boolean previous) {
1773                    StringBundler query = null;
1774    
1775                    if (orderByComparator != null) {
1776                            query = new StringBundler(6 +
1777                                            (orderByComparator.getOrderByFields().length * 6));
1778                    }
1779                    else {
1780                            query = new StringBundler(3);
1781                    }
1782    
1783                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
1784    
1785                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1786    
1787                    if (orderByComparator != null) {
1788                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1789    
1790                            if (orderByConditionFields.length > 0) {
1791                                    query.append(WHERE_AND);
1792                            }
1793    
1794                            for (int i = 0; i < orderByConditionFields.length; i++) {
1795                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1796                                    query.append(orderByConditionFields[i]);
1797    
1798                                    if ((i + 1) < orderByConditionFields.length) {
1799                                            if (orderByComparator.isAscending() ^ previous) {
1800                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1801                                            }
1802                                            else {
1803                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1804                                            }
1805                                    }
1806                                    else {
1807                                            if (orderByComparator.isAscending() ^ previous) {
1808                                                    query.append(WHERE_GREATER_THAN);
1809                                            }
1810                                            else {
1811                                                    query.append(WHERE_LESSER_THAN);
1812                                            }
1813                                    }
1814                            }
1815    
1816                            query.append(ORDER_BY_CLAUSE);
1817    
1818                            String[] orderByFields = orderByComparator.getOrderByFields();
1819    
1820                            for (int i = 0; i < orderByFields.length; i++) {
1821                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1822                                    query.append(orderByFields[i]);
1823    
1824                                    if ((i + 1) < orderByFields.length) {
1825                                            if (orderByComparator.isAscending() ^ previous) {
1826                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1827                                            }
1828                                            else {
1829                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1830                                            }
1831                                    }
1832                                    else {
1833                                            if (orderByComparator.isAscending() ^ previous) {
1834                                                    query.append(ORDER_BY_ASC);
1835                                            }
1836                                            else {
1837                                                    query.append(ORDER_BY_DESC);
1838                                            }
1839                                    }
1840                            }
1841                    }
1842                    else {
1843                            query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
1844                    }
1845    
1846                    String sql = query.toString();
1847    
1848                    Query q = session.createQuery(sql);
1849    
1850                    q.setFirstResult(0);
1851                    q.setMaxResults(2);
1852    
1853                    QueryPos qPos = QueryPos.getInstance(q);
1854    
1855                    qPos.add(groupId);
1856    
1857                    if (orderByComparator != null) {
1858                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
1859    
1860                            for (Object value : values) {
1861                                    qPos.add(value);
1862                            }
1863                    }
1864    
1865                    List<DDMTemplate> list = q.list();
1866    
1867                    if (list.size() == 2) {
1868                            return list.get(1);
1869                    }
1870                    else {
1871                            return null;
1872                    }
1873            }
1874    
1875            /**
1876             * Returns all the d d m templates that the user has permission to view where groupId = &#63;.
1877             *
1878             * @param groupId the group ID
1879             * @return the matching d d m templates that the user has permission to view
1880             * @throws SystemException if a system exception occurred
1881             */
1882            @Override
1883            public List<DDMTemplate> filterFindByGroupId(long groupId)
1884                    throws SystemException {
1885                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1886                            QueryUtil.ALL_POS, null);
1887            }
1888    
1889            /**
1890             * Returns a range of all the d d m templates that the user has permission to view where groupId = &#63;.
1891             *
1892             * <p>
1893             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1894             * </p>
1895             *
1896             * @param groupId the group ID
1897             * @param start the lower bound of the range of d d m templates
1898             * @param end the upper bound of the range of d d m templates (not inclusive)
1899             * @return the range of matching d d m templates that the user has permission to view
1900             * @throws SystemException if a system exception occurred
1901             */
1902            @Override
1903            public List<DDMTemplate> filterFindByGroupId(long groupId, int start,
1904                    int end) throws SystemException {
1905                    return filterFindByGroupId(groupId, start, end, null);
1906            }
1907    
1908            /**
1909             * Returns an ordered range of all the d d m templates that the user has permissions to view where groupId = &#63;.
1910             *
1911             * <p>
1912             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1913             * </p>
1914             *
1915             * @param groupId the group ID
1916             * @param start the lower bound of the range of d d m templates
1917             * @param end the upper bound of the range of d d m templates (not inclusive)
1918             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1919             * @return the ordered range of matching d d m templates that the user has permission to view
1920             * @throws SystemException if a system exception occurred
1921             */
1922            @Override
1923            public List<DDMTemplate> filterFindByGroupId(long groupId, int start,
1924                    int end, OrderByComparator orderByComparator) throws SystemException {
1925                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1926                            return findByGroupId(groupId, start, end, orderByComparator);
1927                    }
1928    
1929                    StringBundler query = null;
1930    
1931                    if (orderByComparator != null) {
1932                            query = new StringBundler(3 +
1933                                            (orderByComparator.getOrderByFields().length * 3));
1934                    }
1935                    else {
1936                            query = new StringBundler(3);
1937                    }
1938    
1939                    if (getDB().isSupportsInlineDistinct()) {
1940                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_WHERE);
1941                    }
1942                    else {
1943                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
1944                    }
1945    
1946                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1947    
1948                    if (!getDB().isSupportsInlineDistinct()) {
1949                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
1950                    }
1951    
1952                    if (orderByComparator != null) {
1953                            if (getDB().isSupportsInlineDistinct()) {
1954                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1955                                            orderByComparator, true);
1956                            }
1957                            else {
1958                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1959                                            orderByComparator, true);
1960                            }
1961                    }
1962                    else {
1963                            if (getDB().isSupportsInlineDistinct()) {
1964                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
1965                            }
1966                            else {
1967                                    query.append(DDMTemplateModelImpl.ORDER_BY_SQL);
1968                            }
1969                    }
1970    
1971                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1972                                    DDMTemplate.class.getName(),
1973                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1974    
1975                    Session session = null;
1976    
1977                    try {
1978                            session = openSession();
1979    
1980                            SQLQuery q = session.createSQLQuery(sql);
1981    
1982                            if (getDB().isSupportsInlineDistinct()) {
1983                                    q.addEntity(_FILTER_ENTITY_ALIAS, DDMTemplateImpl.class);
1984                            }
1985                            else {
1986                                    q.addEntity(_FILTER_ENTITY_TABLE, DDMTemplateImpl.class);
1987                            }
1988    
1989                            QueryPos qPos = QueryPos.getInstance(q);
1990    
1991                            qPos.add(groupId);
1992    
1993                            return (List<DDMTemplate>)QueryUtil.list(q, getDialect(), start, end);
1994                    }
1995                    catch (Exception e) {
1996                            throw processException(e);
1997                    }
1998                    finally {
1999                            closeSession(session);
2000                    }
2001            }
2002    
2003            /**
2004             * 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;.
2005             *
2006             * @param templateId the primary key of the current d d m template
2007             * @param groupId the group ID
2008             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2009             * @return the previous, current, and next d d m template
2010             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
2011             * @throws SystemException if a system exception occurred
2012             */
2013            @Override
2014            public DDMTemplate[] filterFindByGroupId_PrevAndNext(long templateId,
2015                    long groupId, OrderByComparator orderByComparator)
2016                    throws NoSuchTemplateException, SystemException {
2017                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2018                            return findByGroupId_PrevAndNext(templateId, groupId,
2019                                    orderByComparator);
2020                    }
2021    
2022                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
2023    
2024                    Session session = null;
2025    
2026                    try {
2027                            session = openSession();
2028    
2029                            DDMTemplate[] array = new DDMTemplateImpl[3];
2030    
2031                            array[0] = filterGetByGroupId_PrevAndNext(session, ddmTemplate,
2032                                            groupId, orderByComparator, true);
2033    
2034                            array[1] = ddmTemplate;
2035    
2036                            array[2] = filterGetByGroupId_PrevAndNext(session, ddmTemplate,
2037                                            groupId, orderByComparator, false);
2038    
2039                            return array;
2040                    }
2041                    catch (Exception e) {
2042                            throw processException(e);
2043                    }
2044                    finally {
2045                            closeSession(session);
2046                    }
2047            }
2048    
2049            protected DDMTemplate filterGetByGroupId_PrevAndNext(Session session,
2050                    DDMTemplate ddmTemplate, long groupId,
2051                    OrderByComparator orderByComparator, boolean previous) {
2052                    StringBundler query = null;
2053    
2054                    if (orderByComparator != null) {
2055                            query = new StringBundler(6 +
2056                                            (orderByComparator.getOrderByFields().length * 6));
2057                    }
2058                    else {
2059                            query = new StringBundler(3);
2060                    }
2061    
2062                    if (getDB().isSupportsInlineDistinct()) {
2063                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_WHERE);
2064                    }
2065                    else {
2066                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
2067                    }
2068    
2069                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2070    
2071                    if (!getDB().isSupportsInlineDistinct()) {
2072                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
2073                    }
2074    
2075                    if (orderByComparator != null) {
2076                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2077    
2078                            if (orderByConditionFields.length > 0) {
2079                                    query.append(WHERE_AND);
2080                            }
2081    
2082                            for (int i = 0; i < orderByConditionFields.length; i++) {
2083                                    if (getDB().isSupportsInlineDistinct()) {
2084                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2085                                    }
2086                                    else {
2087                                            query.append(_ORDER_BY_ENTITY_TABLE);
2088                                    }
2089    
2090                                    query.append(orderByConditionFields[i]);
2091    
2092                                    if ((i + 1) < orderByConditionFields.length) {
2093                                            if (orderByComparator.isAscending() ^ previous) {
2094                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2095                                            }
2096                                            else {
2097                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2098                                            }
2099                                    }
2100                                    else {
2101                                            if (orderByComparator.isAscending() ^ previous) {
2102                                                    query.append(WHERE_GREATER_THAN);
2103                                            }
2104                                            else {
2105                                                    query.append(WHERE_LESSER_THAN);
2106                                            }
2107                                    }
2108                            }
2109    
2110                            query.append(ORDER_BY_CLAUSE);
2111    
2112                            String[] orderByFields = orderByComparator.getOrderByFields();
2113    
2114                            for (int i = 0; i < orderByFields.length; i++) {
2115                                    if (getDB().isSupportsInlineDistinct()) {
2116                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2117                                    }
2118                                    else {
2119                                            query.append(_ORDER_BY_ENTITY_TABLE);
2120                                    }
2121    
2122                                    query.append(orderByFields[i]);
2123    
2124                                    if ((i + 1) < orderByFields.length) {
2125                                            if (orderByComparator.isAscending() ^ previous) {
2126                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2127                                            }
2128                                            else {
2129                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2130                                            }
2131                                    }
2132                                    else {
2133                                            if (orderByComparator.isAscending() ^ previous) {
2134                                                    query.append(ORDER_BY_ASC);
2135                                            }
2136                                            else {
2137                                                    query.append(ORDER_BY_DESC);
2138                                            }
2139                                    }
2140                            }
2141                    }
2142                    else {
2143                            if (getDB().isSupportsInlineDistinct()) {
2144                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
2145                            }
2146                            else {
2147                                    query.append(DDMTemplateModelImpl.ORDER_BY_SQL);
2148                            }
2149                    }
2150    
2151                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2152                                    DDMTemplate.class.getName(),
2153                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2154    
2155                    SQLQuery q = session.createSQLQuery(sql);
2156    
2157                    q.setFirstResult(0);
2158                    q.setMaxResults(2);
2159    
2160                    if (getDB().isSupportsInlineDistinct()) {
2161                            q.addEntity(_FILTER_ENTITY_ALIAS, DDMTemplateImpl.class);
2162                    }
2163                    else {
2164                            q.addEntity(_FILTER_ENTITY_TABLE, DDMTemplateImpl.class);
2165                    }
2166    
2167                    QueryPos qPos = QueryPos.getInstance(q);
2168    
2169                    qPos.add(groupId);
2170    
2171                    if (orderByComparator != null) {
2172                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
2173    
2174                            for (Object value : values) {
2175                                    qPos.add(value);
2176                            }
2177                    }
2178    
2179                    List<DDMTemplate> list = q.list();
2180    
2181                    if (list.size() == 2) {
2182                            return list.get(1);
2183                    }
2184                    else {
2185                            return null;
2186                    }
2187            }
2188    
2189            /**
2190             * Removes all the d d m templates where groupId = &#63; from the database.
2191             *
2192             * @param groupId the group ID
2193             * @throws SystemException if a system exception occurred
2194             */
2195            @Override
2196            public void removeByGroupId(long groupId) throws SystemException {
2197                    for (DDMTemplate ddmTemplate : findByGroupId(groupId,
2198                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2199                            remove(ddmTemplate);
2200                    }
2201            }
2202    
2203            /**
2204             * Returns the number of d d m templates where groupId = &#63;.
2205             *
2206             * @param groupId the group ID
2207             * @return the number of matching d d m templates
2208             * @throws SystemException if a system exception occurred
2209             */
2210            @Override
2211            public int countByGroupId(long groupId) throws SystemException {
2212                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2213    
2214                    Object[] finderArgs = new Object[] { groupId };
2215    
2216                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2217                                    this);
2218    
2219                    if (count == null) {
2220                            StringBundler query = new StringBundler(2);
2221    
2222                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
2223    
2224                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2225    
2226                            String sql = query.toString();
2227    
2228                            Session session = null;
2229    
2230                            try {
2231                                    session = openSession();
2232    
2233                                    Query q = session.createQuery(sql);
2234    
2235                                    QueryPos qPos = QueryPos.getInstance(q);
2236    
2237                                    qPos.add(groupId);
2238    
2239                                    count = (Long)q.uniqueResult();
2240    
2241                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2242                            }
2243                            catch (Exception e) {
2244                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2245    
2246                                    throw processException(e);
2247                            }
2248                            finally {
2249                                    closeSession(session);
2250                            }
2251                    }
2252    
2253                    return count.intValue();
2254            }
2255    
2256            /**
2257             * Returns the number of d d m templates that the user has permission to view where groupId = &#63;.
2258             *
2259             * @param groupId the group ID
2260             * @return the number of matching d d m templates that the user has permission to view
2261             * @throws SystemException if a system exception occurred
2262             */
2263            @Override
2264            public int filterCountByGroupId(long groupId) throws SystemException {
2265                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2266                            return countByGroupId(groupId);
2267                    }
2268    
2269                    StringBundler query = new StringBundler(2);
2270    
2271                    query.append(_FILTER_SQL_COUNT_DDMTEMPLATE_WHERE);
2272    
2273                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2274    
2275                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2276                                    DDMTemplate.class.getName(),
2277                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2278    
2279                    Session session = null;
2280    
2281                    try {
2282                            session = openSession();
2283    
2284                            SQLQuery q = session.createSQLQuery(sql);
2285    
2286                            q.addScalar(COUNT_COLUMN_NAME,
2287                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2288    
2289                            QueryPos qPos = QueryPos.getInstance(q);
2290    
2291                            qPos.add(groupId);
2292    
2293                            Long count = (Long)q.uniqueResult();
2294    
2295                            return count.intValue();
2296                    }
2297                    catch (Exception e) {
2298                            throw processException(e);
2299                    }
2300                    finally {
2301                            closeSession(session);
2302                    }
2303            }
2304    
2305            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "ddmTemplate.groupId = ?";
2306            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSPK = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
2307                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
2308                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByClassPK",
2309                            new String[] {
2310                                    Long.class.getName(),
2311                                    
2312                            Integer.class.getName(), Integer.class.getName(),
2313                                    OrderByComparator.class.getName()
2314                            });
2315            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSPK =
2316                    new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
2317                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
2318                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByClassPK",
2319                            new String[] { Long.class.getName() },
2320                            DDMTemplateModelImpl.CLASSPK_COLUMN_BITMASK);
2321            public static final FinderPath FINDER_PATH_COUNT_BY_CLASSPK = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
2322                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
2323                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByClassPK",
2324                            new String[] { Long.class.getName() });
2325    
2326            /**
2327             * Returns all the d d m templates where classPK = &#63;.
2328             *
2329             * @param classPK the class p k
2330             * @return the matching d d m templates
2331             * @throws SystemException if a system exception occurred
2332             */
2333            @Override
2334            public List<DDMTemplate> findByClassPK(long classPK)
2335                    throws SystemException {
2336                    return findByClassPK(classPK, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2337            }
2338    
2339            /**
2340             * Returns a range of all the d d m templates where classPK = &#63;.
2341             *
2342             * <p>
2343             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2344             * </p>
2345             *
2346             * @param classPK the class p k
2347             * @param start the lower bound of the range of d d m templates
2348             * @param end the upper bound of the range of d d m templates (not inclusive)
2349             * @return the range of matching d d m templates
2350             * @throws SystemException if a system exception occurred
2351             */
2352            @Override
2353            public List<DDMTemplate> findByClassPK(long classPK, int start, int end)
2354                    throws SystemException {
2355                    return findByClassPK(classPK, start, end, null);
2356            }
2357    
2358            /**
2359             * Returns an ordered range of all the d d m templates where classPK = &#63;.
2360             *
2361             * <p>
2362             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2363             * </p>
2364             *
2365             * @param classPK the class p k
2366             * @param start the lower bound of the range of d d m templates
2367             * @param end the upper bound of the range of d d m templates (not inclusive)
2368             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2369             * @return the ordered range of matching d d m templates
2370             * @throws SystemException if a system exception occurred
2371             */
2372            @Override
2373            public List<DDMTemplate> findByClassPK(long classPK, int start, int end,
2374                    OrderByComparator orderByComparator) throws SystemException {
2375                    boolean pagination = true;
2376                    FinderPath finderPath = null;
2377                    Object[] finderArgs = null;
2378    
2379                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2380                                    (orderByComparator == null)) {
2381                            pagination = false;
2382                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSPK;
2383                            finderArgs = new Object[] { classPK };
2384                    }
2385                    else {
2386                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSPK;
2387                            finderArgs = new Object[] { classPK, start, end, orderByComparator };
2388                    }
2389    
2390                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
2391                                    finderArgs, this);
2392    
2393                    if ((list != null) && !list.isEmpty()) {
2394                            for (DDMTemplate ddmTemplate : list) {
2395                                    if ((classPK != ddmTemplate.getClassPK())) {
2396                                            list = null;
2397    
2398                                            break;
2399                                    }
2400                            }
2401                    }
2402    
2403                    if (list == null) {
2404                            StringBundler query = null;
2405    
2406                            if (orderByComparator != null) {
2407                                    query = new StringBundler(3 +
2408                                                    (orderByComparator.getOrderByFields().length * 3));
2409                            }
2410                            else {
2411                                    query = new StringBundler(3);
2412                            }
2413    
2414                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
2415    
2416                            query.append(_FINDER_COLUMN_CLASSPK_CLASSPK_2);
2417    
2418                            if (orderByComparator != null) {
2419                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2420                                            orderByComparator);
2421                            }
2422                            else
2423                             if (pagination) {
2424                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
2425                            }
2426    
2427                            String sql = query.toString();
2428    
2429                            Session session = null;
2430    
2431                            try {
2432                                    session = openSession();
2433    
2434                                    Query q = session.createQuery(sql);
2435    
2436                                    QueryPos qPos = QueryPos.getInstance(q);
2437    
2438                                    qPos.add(classPK);
2439    
2440                                    if (!pagination) {
2441                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
2442                                                            start, end, false);
2443    
2444                                            Collections.sort(list);
2445    
2446                                            list = new UnmodifiableList<DDMTemplate>(list);
2447                                    }
2448                                    else {
2449                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
2450                                                            start, end);
2451                                    }
2452    
2453                                    cacheResult(list);
2454    
2455                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2456                            }
2457                            catch (Exception e) {
2458                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2459    
2460                                    throw processException(e);
2461                            }
2462                            finally {
2463                                    closeSession(session);
2464                            }
2465                    }
2466    
2467                    return list;
2468            }
2469    
2470            /**
2471             * Returns the first d d m template in the ordered set where classPK = &#63;.
2472             *
2473             * @param classPK the class p k
2474             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2475             * @return the first matching d d m template
2476             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
2477             * @throws SystemException if a system exception occurred
2478             */
2479            @Override
2480            public DDMTemplate findByClassPK_First(long classPK,
2481                    OrderByComparator orderByComparator)
2482                    throws NoSuchTemplateException, SystemException {
2483                    DDMTemplate ddmTemplate = fetchByClassPK_First(classPK,
2484                                    orderByComparator);
2485    
2486                    if (ddmTemplate != null) {
2487                            return ddmTemplate;
2488                    }
2489    
2490                    StringBundler msg = new StringBundler(4);
2491    
2492                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2493    
2494                    msg.append("classPK=");
2495                    msg.append(classPK);
2496    
2497                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2498    
2499                    throw new NoSuchTemplateException(msg.toString());
2500            }
2501    
2502            /**
2503             * Returns the first d d m template in the ordered set where classPK = &#63;.
2504             *
2505             * @param classPK the class p k
2506             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2507             * @return the first matching d d m template, or <code>null</code> if a matching d d m template could not be found
2508             * @throws SystemException if a system exception occurred
2509             */
2510            @Override
2511            public DDMTemplate fetchByClassPK_First(long classPK,
2512                    OrderByComparator orderByComparator) throws SystemException {
2513                    List<DDMTemplate> list = findByClassPK(classPK, 0, 1, orderByComparator);
2514    
2515                    if (!list.isEmpty()) {
2516                            return list.get(0);
2517                    }
2518    
2519                    return null;
2520            }
2521    
2522            /**
2523             * Returns the last d d m template in the ordered set where classPK = &#63;.
2524             *
2525             * @param classPK the class p k
2526             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2527             * @return the last matching d d m template
2528             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
2529             * @throws SystemException if a system exception occurred
2530             */
2531            @Override
2532            public DDMTemplate findByClassPK_Last(long classPK,
2533                    OrderByComparator orderByComparator)
2534                    throws NoSuchTemplateException, SystemException {
2535                    DDMTemplate ddmTemplate = fetchByClassPK_Last(classPK, orderByComparator);
2536    
2537                    if (ddmTemplate != null) {
2538                            return ddmTemplate;
2539                    }
2540    
2541                    StringBundler msg = new StringBundler(4);
2542    
2543                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2544    
2545                    msg.append("classPK=");
2546                    msg.append(classPK);
2547    
2548                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2549    
2550                    throw new NoSuchTemplateException(msg.toString());
2551            }
2552    
2553            /**
2554             * Returns the last d d m template in the ordered set where classPK = &#63;.
2555             *
2556             * @param classPK the class p k
2557             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2558             * @return the last matching d d m template, or <code>null</code> if a matching d d m template could not be found
2559             * @throws SystemException if a system exception occurred
2560             */
2561            @Override
2562            public DDMTemplate fetchByClassPK_Last(long classPK,
2563                    OrderByComparator orderByComparator) throws SystemException {
2564                    int count = countByClassPK(classPK);
2565    
2566                    if (count == 0) {
2567                            return null;
2568                    }
2569    
2570                    List<DDMTemplate> list = findByClassPK(classPK, count - 1, count,
2571                                    orderByComparator);
2572    
2573                    if (!list.isEmpty()) {
2574                            return list.get(0);
2575                    }
2576    
2577                    return null;
2578            }
2579    
2580            /**
2581             * Returns the d d m templates before and after the current d d m template in the ordered set where classPK = &#63;.
2582             *
2583             * @param templateId the primary key of the current d d m template
2584             * @param classPK the class p k
2585             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2586             * @return the previous, current, and next d d m template
2587             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
2588             * @throws SystemException if a system exception occurred
2589             */
2590            @Override
2591            public DDMTemplate[] findByClassPK_PrevAndNext(long templateId,
2592                    long classPK, OrderByComparator orderByComparator)
2593                    throws NoSuchTemplateException, SystemException {
2594                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
2595    
2596                    Session session = null;
2597    
2598                    try {
2599                            session = openSession();
2600    
2601                            DDMTemplate[] array = new DDMTemplateImpl[3];
2602    
2603                            array[0] = getByClassPK_PrevAndNext(session, ddmTemplate, classPK,
2604                                            orderByComparator, true);
2605    
2606                            array[1] = ddmTemplate;
2607    
2608                            array[2] = getByClassPK_PrevAndNext(session, ddmTemplate, classPK,
2609                                            orderByComparator, false);
2610    
2611                            return array;
2612                    }
2613                    catch (Exception e) {
2614                            throw processException(e);
2615                    }
2616                    finally {
2617                            closeSession(session);
2618                    }
2619            }
2620    
2621            protected DDMTemplate getByClassPK_PrevAndNext(Session session,
2622                    DDMTemplate ddmTemplate, long classPK,
2623                    OrderByComparator orderByComparator, boolean previous) {
2624                    StringBundler query = null;
2625    
2626                    if (orderByComparator != null) {
2627                            query = new StringBundler(6 +
2628                                            (orderByComparator.getOrderByFields().length * 6));
2629                    }
2630                    else {
2631                            query = new StringBundler(3);
2632                    }
2633    
2634                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
2635    
2636                    query.append(_FINDER_COLUMN_CLASSPK_CLASSPK_2);
2637    
2638                    if (orderByComparator != null) {
2639                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2640    
2641                            if (orderByConditionFields.length > 0) {
2642                                    query.append(WHERE_AND);
2643                            }
2644    
2645                            for (int i = 0; i < orderByConditionFields.length; i++) {
2646                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2647                                    query.append(orderByConditionFields[i]);
2648    
2649                                    if ((i + 1) < orderByConditionFields.length) {
2650                                            if (orderByComparator.isAscending() ^ previous) {
2651                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2652                                            }
2653                                            else {
2654                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2655                                            }
2656                                    }
2657                                    else {
2658                                            if (orderByComparator.isAscending() ^ previous) {
2659                                                    query.append(WHERE_GREATER_THAN);
2660                                            }
2661                                            else {
2662                                                    query.append(WHERE_LESSER_THAN);
2663                                            }
2664                                    }
2665                            }
2666    
2667                            query.append(ORDER_BY_CLAUSE);
2668    
2669                            String[] orderByFields = orderByComparator.getOrderByFields();
2670    
2671                            for (int i = 0; i < orderByFields.length; i++) {
2672                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2673                                    query.append(orderByFields[i]);
2674    
2675                                    if ((i + 1) < orderByFields.length) {
2676                                            if (orderByComparator.isAscending() ^ previous) {
2677                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2678                                            }
2679                                            else {
2680                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2681                                            }
2682                                    }
2683                                    else {
2684                                            if (orderByComparator.isAscending() ^ previous) {
2685                                                    query.append(ORDER_BY_ASC);
2686                                            }
2687                                            else {
2688                                                    query.append(ORDER_BY_DESC);
2689                                            }
2690                                    }
2691                            }
2692                    }
2693                    else {
2694                            query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
2695                    }
2696    
2697                    String sql = query.toString();
2698    
2699                    Query q = session.createQuery(sql);
2700    
2701                    q.setFirstResult(0);
2702                    q.setMaxResults(2);
2703    
2704                    QueryPos qPos = QueryPos.getInstance(q);
2705    
2706                    qPos.add(classPK);
2707    
2708                    if (orderByComparator != null) {
2709                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
2710    
2711                            for (Object value : values) {
2712                                    qPos.add(value);
2713                            }
2714                    }
2715    
2716                    List<DDMTemplate> list = q.list();
2717    
2718                    if (list.size() == 2) {
2719                            return list.get(1);
2720                    }
2721                    else {
2722                            return null;
2723                    }
2724            }
2725    
2726            /**
2727             * Removes all the d d m templates where classPK = &#63; from the database.
2728             *
2729             * @param classPK the class p k
2730             * @throws SystemException if a system exception occurred
2731             */
2732            @Override
2733            public void removeByClassPK(long classPK) throws SystemException {
2734                    for (DDMTemplate ddmTemplate : findByClassPK(classPK,
2735                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2736                            remove(ddmTemplate);
2737                    }
2738            }
2739    
2740            /**
2741             * Returns the number of d d m templates where classPK = &#63;.
2742             *
2743             * @param classPK the class p k
2744             * @return the number of matching d d m templates
2745             * @throws SystemException if a system exception occurred
2746             */
2747            @Override
2748            public int countByClassPK(long classPK) throws SystemException {
2749                    FinderPath finderPath = FINDER_PATH_COUNT_BY_CLASSPK;
2750    
2751                    Object[] finderArgs = new Object[] { classPK };
2752    
2753                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2754                                    this);
2755    
2756                    if (count == null) {
2757                            StringBundler query = new StringBundler(2);
2758    
2759                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
2760    
2761                            query.append(_FINDER_COLUMN_CLASSPK_CLASSPK_2);
2762    
2763                            String sql = query.toString();
2764    
2765                            Session session = null;
2766    
2767                            try {
2768                                    session = openSession();
2769    
2770                                    Query q = session.createQuery(sql);
2771    
2772                                    QueryPos qPos = QueryPos.getInstance(q);
2773    
2774                                    qPos.add(classPK);
2775    
2776                                    count = (Long)q.uniqueResult();
2777    
2778                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2779                            }
2780                            catch (Exception e) {
2781                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2782    
2783                                    throw processException(e);
2784                            }
2785                            finally {
2786                                    closeSession(session);
2787                            }
2788                    }
2789    
2790                    return count.intValue();
2791            }
2792    
2793            private static final String _FINDER_COLUMN_CLASSPK_CLASSPK_2 = "ddmTemplate.classPK = ?";
2794            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TEMPLATEKEY =
2795                    new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
2796                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
2797                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByTemplateKey",
2798                            new String[] {
2799                                    String.class.getName(),
2800                                    
2801                            Integer.class.getName(), Integer.class.getName(),
2802                                    OrderByComparator.class.getName()
2803                            });
2804            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEKEY =
2805                    new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
2806                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
2807                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTemplateKey",
2808                            new String[] { String.class.getName() },
2809                            DDMTemplateModelImpl.TEMPLATEKEY_COLUMN_BITMASK);
2810            public static final FinderPath FINDER_PATH_COUNT_BY_TEMPLATEKEY = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
2811                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
2812                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTemplateKey",
2813                            new String[] { String.class.getName() });
2814    
2815            /**
2816             * Returns all the d d m templates where templateKey = &#63;.
2817             *
2818             * @param templateKey the template key
2819             * @return the matching d d m templates
2820             * @throws SystemException if a system exception occurred
2821             */
2822            @Override
2823            public List<DDMTemplate> findByTemplateKey(String templateKey)
2824                    throws SystemException {
2825                    return findByTemplateKey(templateKey, QueryUtil.ALL_POS,
2826                            QueryUtil.ALL_POS, null);
2827            }
2828    
2829            /**
2830             * Returns a range of all the d d m templates where templateKey = &#63;.
2831             *
2832             * <p>
2833             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2834             * </p>
2835             *
2836             * @param templateKey the template key
2837             * @param start the lower bound of the range of d d m templates
2838             * @param end the upper bound of the range of d d m templates (not inclusive)
2839             * @return the range of matching d d m templates
2840             * @throws SystemException if a system exception occurred
2841             */
2842            @Override
2843            public List<DDMTemplate> findByTemplateKey(String templateKey, int start,
2844                    int end) throws SystemException {
2845                    return findByTemplateKey(templateKey, start, end, null);
2846            }
2847    
2848            /**
2849             * Returns an ordered range of all the d d m templates where templateKey = &#63;.
2850             *
2851             * <p>
2852             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2853             * </p>
2854             *
2855             * @param templateKey the template key
2856             * @param start the lower bound of the range of d d m templates
2857             * @param end the upper bound of the range of d d m templates (not inclusive)
2858             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2859             * @return the ordered range of matching d d m templates
2860             * @throws SystemException if a system exception occurred
2861             */
2862            @Override
2863            public List<DDMTemplate> findByTemplateKey(String templateKey, int start,
2864                    int end, OrderByComparator orderByComparator) throws SystemException {
2865                    boolean pagination = true;
2866                    FinderPath finderPath = null;
2867                    Object[] finderArgs = null;
2868    
2869                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2870                                    (orderByComparator == null)) {
2871                            pagination = false;
2872                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEKEY;
2873                            finderArgs = new Object[] { templateKey };
2874                    }
2875                    else {
2876                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TEMPLATEKEY;
2877                            finderArgs = new Object[] { templateKey, start, end, orderByComparator };
2878                    }
2879    
2880                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
2881                                    finderArgs, this);
2882    
2883                    if ((list != null) && !list.isEmpty()) {
2884                            for (DDMTemplate ddmTemplate : list) {
2885                                    if (!Validator.equals(templateKey, ddmTemplate.getTemplateKey())) {
2886                                            list = null;
2887    
2888                                            break;
2889                                    }
2890                            }
2891                    }
2892    
2893                    if (list == null) {
2894                            StringBundler query = null;
2895    
2896                            if (orderByComparator != null) {
2897                                    query = new StringBundler(3 +
2898                                                    (orderByComparator.getOrderByFields().length * 3));
2899                            }
2900                            else {
2901                                    query = new StringBundler(3);
2902                            }
2903    
2904                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
2905    
2906                            boolean bindTemplateKey = false;
2907    
2908                            if (templateKey == null) {
2909                                    query.append(_FINDER_COLUMN_TEMPLATEKEY_TEMPLATEKEY_1);
2910                            }
2911                            else if (templateKey.equals(StringPool.BLANK)) {
2912                                    query.append(_FINDER_COLUMN_TEMPLATEKEY_TEMPLATEKEY_3);
2913                            }
2914                            else {
2915                                    bindTemplateKey = true;
2916    
2917                                    query.append(_FINDER_COLUMN_TEMPLATEKEY_TEMPLATEKEY_2);
2918                            }
2919    
2920                            if (orderByComparator != null) {
2921                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2922                                            orderByComparator);
2923                            }
2924                            else
2925                             if (pagination) {
2926                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
2927                            }
2928    
2929                            String sql = query.toString();
2930    
2931                            Session session = null;
2932    
2933                            try {
2934                                    session = openSession();
2935    
2936                                    Query q = session.createQuery(sql);
2937    
2938                                    QueryPos qPos = QueryPos.getInstance(q);
2939    
2940                                    if (bindTemplateKey) {
2941                                            qPos.add(templateKey);
2942                                    }
2943    
2944                                    if (!pagination) {
2945                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
2946                                                            start, end, false);
2947    
2948                                            Collections.sort(list);
2949    
2950                                            list = new UnmodifiableList<DDMTemplate>(list);
2951                                    }
2952                                    else {
2953                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
2954                                                            start, end);
2955                                    }
2956    
2957                                    cacheResult(list);
2958    
2959                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2960                            }
2961                            catch (Exception e) {
2962                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2963    
2964                                    throw processException(e);
2965                            }
2966                            finally {
2967                                    closeSession(session);
2968                            }
2969                    }
2970    
2971                    return list;
2972            }
2973    
2974            /**
2975             * Returns the first d d m template in the ordered set where templateKey = &#63;.
2976             *
2977             * @param templateKey the template key
2978             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2979             * @return the first matching d d m template
2980             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
2981             * @throws SystemException if a system exception occurred
2982             */
2983            @Override
2984            public DDMTemplate findByTemplateKey_First(String templateKey,
2985                    OrderByComparator orderByComparator)
2986                    throws NoSuchTemplateException, SystemException {
2987                    DDMTemplate ddmTemplate = fetchByTemplateKey_First(templateKey,
2988                                    orderByComparator);
2989    
2990                    if (ddmTemplate != null) {
2991                            return ddmTemplate;
2992                    }
2993    
2994                    StringBundler msg = new StringBundler(4);
2995    
2996                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2997    
2998                    msg.append("templateKey=");
2999                    msg.append(templateKey);
3000    
3001                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3002    
3003                    throw new NoSuchTemplateException(msg.toString());
3004            }
3005    
3006            /**
3007             * Returns the first d d m template in the ordered set where templateKey = &#63;.
3008             *
3009             * @param templateKey the template key
3010             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3011             * @return the first matching d d m template, or <code>null</code> if a matching d d m template could not be found
3012             * @throws SystemException if a system exception occurred
3013             */
3014            @Override
3015            public DDMTemplate fetchByTemplateKey_First(String templateKey,
3016                    OrderByComparator orderByComparator) throws SystemException {
3017                    List<DDMTemplate> list = findByTemplateKey(templateKey, 0, 1,
3018                                    orderByComparator);
3019    
3020                    if (!list.isEmpty()) {
3021                            return list.get(0);
3022                    }
3023    
3024                    return null;
3025            }
3026    
3027            /**
3028             * Returns the last d d m template in the ordered set where templateKey = &#63;.
3029             *
3030             * @param templateKey the template key
3031             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3032             * @return the last matching d d m template
3033             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
3034             * @throws SystemException if a system exception occurred
3035             */
3036            @Override
3037            public DDMTemplate findByTemplateKey_Last(String templateKey,
3038                    OrderByComparator orderByComparator)
3039                    throws NoSuchTemplateException, SystemException {
3040                    DDMTemplate ddmTemplate = fetchByTemplateKey_Last(templateKey,
3041                                    orderByComparator);
3042    
3043                    if (ddmTemplate != null) {
3044                            return ddmTemplate;
3045                    }
3046    
3047                    StringBundler msg = new StringBundler(4);
3048    
3049                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3050    
3051                    msg.append("templateKey=");
3052                    msg.append(templateKey);
3053    
3054                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3055    
3056                    throw new NoSuchTemplateException(msg.toString());
3057            }
3058    
3059            /**
3060             * Returns the last d d m template in the ordered set where templateKey = &#63;.
3061             *
3062             * @param templateKey the template key
3063             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3064             * @return the last matching d d m template, or <code>null</code> if a matching d d m template could not be found
3065             * @throws SystemException if a system exception occurred
3066             */
3067            @Override
3068            public DDMTemplate fetchByTemplateKey_Last(String templateKey,
3069                    OrderByComparator orderByComparator) throws SystemException {
3070                    int count = countByTemplateKey(templateKey);
3071    
3072                    if (count == 0) {
3073                            return null;
3074                    }
3075    
3076                    List<DDMTemplate> list = findByTemplateKey(templateKey, count - 1,
3077                                    count, orderByComparator);
3078    
3079                    if (!list.isEmpty()) {
3080                            return list.get(0);
3081                    }
3082    
3083                    return null;
3084            }
3085    
3086            /**
3087             * Returns the d d m templates before and after the current d d m template in the ordered set where templateKey = &#63;.
3088             *
3089             * @param templateId the primary key of the current d d m template
3090             * @param templateKey the template key
3091             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3092             * @return the previous, current, and next d d m template
3093             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
3094             * @throws SystemException if a system exception occurred
3095             */
3096            @Override
3097            public DDMTemplate[] findByTemplateKey_PrevAndNext(long templateId,
3098                    String templateKey, OrderByComparator orderByComparator)
3099                    throws NoSuchTemplateException, SystemException {
3100                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
3101    
3102                    Session session = null;
3103    
3104                    try {
3105                            session = openSession();
3106    
3107                            DDMTemplate[] array = new DDMTemplateImpl[3];
3108    
3109                            array[0] = getByTemplateKey_PrevAndNext(session, ddmTemplate,
3110                                            templateKey, orderByComparator, true);
3111    
3112                            array[1] = ddmTemplate;
3113    
3114                            array[2] = getByTemplateKey_PrevAndNext(session, ddmTemplate,
3115                                            templateKey, orderByComparator, false);
3116    
3117                            return array;
3118                    }
3119                    catch (Exception e) {
3120                            throw processException(e);
3121                    }
3122                    finally {
3123                            closeSession(session);
3124                    }
3125            }
3126    
3127            protected DDMTemplate getByTemplateKey_PrevAndNext(Session session,
3128                    DDMTemplate ddmTemplate, String templateKey,
3129                    OrderByComparator orderByComparator, boolean previous) {
3130                    StringBundler query = null;
3131    
3132                    if (orderByComparator != null) {
3133                            query = new StringBundler(6 +
3134                                            (orderByComparator.getOrderByFields().length * 6));
3135                    }
3136                    else {
3137                            query = new StringBundler(3);
3138                    }
3139    
3140                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
3141    
3142                    boolean bindTemplateKey = false;
3143    
3144                    if (templateKey == null) {
3145                            query.append(_FINDER_COLUMN_TEMPLATEKEY_TEMPLATEKEY_1);
3146                    }
3147                    else if (templateKey.equals(StringPool.BLANK)) {
3148                            query.append(_FINDER_COLUMN_TEMPLATEKEY_TEMPLATEKEY_3);
3149                    }
3150                    else {
3151                            bindTemplateKey = true;
3152    
3153                            query.append(_FINDER_COLUMN_TEMPLATEKEY_TEMPLATEKEY_2);
3154                    }
3155    
3156                    if (orderByComparator != null) {
3157                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3158    
3159                            if (orderByConditionFields.length > 0) {
3160                                    query.append(WHERE_AND);
3161                            }
3162    
3163                            for (int i = 0; i < orderByConditionFields.length; i++) {
3164                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3165                                    query.append(orderByConditionFields[i]);
3166    
3167                                    if ((i + 1) < orderByConditionFields.length) {
3168                                            if (orderByComparator.isAscending() ^ previous) {
3169                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3170                                            }
3171                                            else {
3172                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3173                                            }
3174                                    }
3175                                    else {
3176                                            if (orderByComparator.isAscending() ^ previous) {
3177                                                    query.append(WHERE_GREATER_THAN);
3178                                            }
3179                                            else {
3180                                                    query.append(WHERE_LESSER_THAN);
3181                                            }
3182                                    }
3183                            }
3184    
3185                            query.append(ORDER_BY_CLAUSE);
3186    
3187                            String[] orderByFields = orderByComparator.getOrderByFields();
3188    
3189                            for (int i = 0; i < orderByFields.length; i++) {
3190                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3191                                    query.append(orderByFields[i]);
3192    
3193                                    if ((i + 1) < orderByFields.length) {
3194                                            if (orderByComparator.isAscending() ^ previous) {
3195                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3196                                            }
3197                                            else {
3198                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3199                                            }
3200                                    }
3201                                    else {
3202                                            if (orderByComparator.isAscending() ^ previous) {
3203                                                    query.append(ORDER_BY_ASC);
3204                                            }
3205                                            else {
3206                                                    query.append(ORDER_BY_DESC);
3207                                            }
3208                                    }
3209                            }
3210                    }
3211                    else {
3212                            query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
3213                    }
3214    
3215                    String sql = query.toString();
3216    
3217                    Query q = session.createQuery(sql);
3218    
3219                    q.setFirstResult(0);
3220                    q.setMaxResults(2);
3221    
3222                    QueryPos qPos = QueryPos.getInstance(q);
3223    
3224                    if (bindTemplateKey) {
3225                            qPos.add(templateKey);
3226                    }
3227    
3228                    if (orderByComparator != null) {
3229                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
3230    
3231                            for (Object value : values) {
3232                                    qPos.add(value);
3233                            }
3234                    }
3235    
3236                    List<DDMTemplate> list = q.list();
3237    
3238                    if (list.size() == 2) {
3239                            return list.get(1);
3240                    }
3241                    else {
3242                            return null;
3243                    }
3244            }
3245    
3246            /**
3247             * Removes all the d d m templates where templateKey = &#63; from the database.
3248             *
3249             * @param templateKey the template key
3250             * @throws SystemException if a system exception occurred
3251             */
3252            @Override
3253            public void removeByTemplateKey(String templateKey)
3254                    throws SystemException {
3255                    for (DDMTemplate ddmTemplate : findByTemplateKey(templateKey,
3256                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3257                            remove(ddmTemplate);
3258                    }
3259            }
3260    
3261            /**
3262             * Returns the number of d d m templates where templateKey = &#63;.
3263             *
3264             * @param templateKey the template key
3265             * @return the number of matching d d m templates
3266             * @throws SystemException if a system exception occurred
3267             */
3268            @Override
3269            public int countByTemplateKey(String templateKey) throws SystemException {
3270                    FinderPath finderPath = FINDER_PATH_COUNT_BY_TEMPLATEKEY;
3271    
3272                    Object[] finderArgs = new Object[] { templateKey };
3273    
3274                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3275                                    this);
3276    
3277                    if (count == null) {
3278                            StringBundler query = new StringBundler(2);
3279    
3280                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
3281    
3282                            boolean bindTemplateKey = false;
3283    
3284                            if (templateKey == null) {
3285                                    query.append(_FINDER_COLUMN_TEMPLATEKEY_TEMPLATEKEY_1);
3286                            }
3287                            else if (templateKey.equals(StringPool.BLANK)) {
3288                                    query.append(_FINDER_COLUMN_TEMPLATEKEY_TEMPLATEKEY_3);
3289                            }
3290                            else {
3291                                    bindTemplateKey = true;
3292    
3293                                    query.append(_FINDER_COLUMN_TEMPLATEKEY_TEMPLATEKEY_2);
3294                            }
3295    
3296                            String sql = query.toString();
3297    
3298                            Session session = null;
3299    
3300                            try {
3301                                    session = openSession();
3302    
3303                                    Query q = session.createQuery(sql);
3304    
3305                                    QueryPos qPos = QueryPos.getInstance(q);
3306    
3307                                    if (bindTemplateKey) {
3308                                            qPos.add(templateKey);
3309                                    }
3310    
3311                                    count = (Long)q.uniqueResult();
3312    
3313                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3314                            }
3315                            catch (Exception e) {
3316                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3317    
3318                                    throw processException(e);
3319                            }
3320                            finally {
3321                                    closeSession(session);
3322                            }
3323                    }
3324    
3325                    return count.intValue();
3326            }
3327    
3328            private static final String _FINDER_COLUMN_TEMPLATEKEY_TEMPLATEKEY_1 = "ddmTemplate.templateKey IS NULL";
3329            private static final String _FINDER_COLUMN_TEMPLATEKEY_TEMPLATEKEY_2 = "ddmTemplate.templateKey = ?";
3330            private static final String _FINDER_COLUMN_TEMPLATEKEY_TEMPLATEKEY_3 = "(ddmTemplate.templateKey IS NULL OR ddmTemplate.templateKey = '')";
3331            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
3332                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
3333                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByType",
3334                            new String[] {
3335                                    String.class.getName(),
3336                                    
3337                            Integer.class.getName(), Integer.class.getName(),
3338                                    OrderByComparator.class.getName()
3339                            });
3340            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
3341                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
3342                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByType",
3343                            new String[] { String.class.getName() },
3344                            DDMTemplateModelImpl.TYPE_COLUMN_BITMASK);
3345            public static final FinderPath FINDER_PATH_COUNT_BY_TYPE = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
3346                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
3347                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByType",
3348                            new String[] { String.class.getName() });
3349    
3350            /**
3351             * Returns all the d d m templates where type = &#63;.
3352             *
3353             * @param type the type
3354             * @return the matching d d m templates
3355             * @throws SystemException if a system exception occurred
3356             */
3357            @Override
3358            public List<DDMTemplate> findByType(String type) throws SystemException {
3359                    return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3360            }
3361    
3362            /**
3363             * Returns a range of all the d d m templates where type = &#63;.
3364             *
3365             * <p>
3366             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3367             * </p>
3368             *
3369             * @param type the type
3370             * @param start the lower bound of the range of d d m templates
3371             * @param end the upper bound of the range of d d m templates (not inclusive)
3372             * @return the range of matching d d m templates
3373             * @throws SystemException if a system exception occurred
3374             */
3375            @Override
3376            public List<DDMTemplate> findByType(String type, int start, int end)
3377                    throws SystemException {
3378                    return findByType(type, start, end, null);
3379            }
3380    
3381            /**
3382             * Returns an ordered range of all the d d m templates where type = &#63;.
3383             *
3384             * <p>
3385             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3386             * </p>
3387             *
3388             * @param type the type
3389             * @param start the lower bound of the range of d d m templates
3390             * @param end the upper bound of the range of d d m templates (not inclusive)
3391             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3392             * @return the ordered range of matching d d m templates
3393             * @throws SystemException if a system exception occurred
3394             */
3395            @Override
3396            public List<DDMTemplate> findByType(String type, int start, int end,
3397                    OrderByComparator orderByComparator) throws SystemException {
3398                    boolean pagination = true;
3399                    FinderPath finderPath = null;
3400                    Object[] finderArgs = null;
3401    
3402                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3403                                    (orderByComparator == null)) {
3404                            pagination = false;
3405                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE;
3406                            finderArgs = new Object[] { type };
3407                    }
3408                    else {
3409                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE;
3410                            finderArgs = new Object[] { type, start, end, orderByComparator };
3411                    }
3412    
3413                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
3414                                    finderArgs, this);
3415    
3416                    if ((list != null) && !list.isEmpty()) {
3417                            for (DDMTemplate ddmTemplate : list) {
3418                                    if (!Validator.equals(type, ddmTemplate.getType())) {
3419                                            list = null;
3420    
3421                                            break;
3422                                    }
3423                            }
3424                    }
3425    
3426                    if (list == null) {
3427                            StringBundler query = null;
3428    
3429                            if (orderByComparator != null) {
3430                                    query = new StringBundler(3 +
3431                                                    (orderByComparator.getOrderByFields().length * 3));
3432                            }
3433                            else {
3434                                    query = new StringBundler(3);
3435                            }
3436    
3437                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
3438    
3439                            boolean bindType = false;
3440    
3441                            if (type == null) {
3442                                    query.append(_FINDER_COLUMN_TYPE_TYPE_1);
3443                            }
3444                            else if (type.equals(StringPool.BLANK)) {
3445                                    query.append(_FINDER_COLUMN_TYPE_TYPE_3);
3446                            }
3447                            else {
3448                                    bindType = true;
3449    
3450                                    query.append(_FINDER_COLUMN_TYPE_TYPE_2);
3451                            }
3452    
3453                            if (orderByComparator != null) {
3454                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3455                                            orderByComparator);
3456                            }
3457                            else
3458                             if (pagination) {
3459                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
3460                            }
3461    
3462                            String sql = query.toString();
3463    
3464                            Session session = null;
3465    
3466                            try {
3467                                    session = openSession();
3468    
3469                                    Query q = session.createQuery(sql);
3470    
3471                                    QueryPos qPos = QueryPos.getInstance(q);
3472    
3473                                    if (bindType) {
3474                                            qPos.add(type);
3475                                    }
3476    
3477                                    if (!pagination) {
3478                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
3479                                                            start, end, false);
3480    
3481                                            Collections.sort(list);
3482    
3483                                            list = new UnmodifiableList<DDMTemplate>(list);
3484                                    }
3485                                    else {
3486                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
3487                                                            start, end);
3488                                    }
3489    
3490                                    cacheResult(list);
3491    
3492                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3493                            }
3494                            catch (Exception e) {
3495                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3496    
3497                                    throw processException(e);
3498                            }
3499                            finally {
3500                                    closeSession(session);
3501                            }
3502                    }
3503    
3504                    return list;
3505            }
3506    
3507            /**
3508             * Returns the first d d m template in the ordered set where type = &#63;.
3509             *
3510             * @param type the type
3511             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3512             * @return the first matching d d m template
3513             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
3514             * @throws SystemException if a system exception occurred
3515             */
3516            @Override
3517            public DDMTemplate findByType_First(String type,
3518                    OrderByComparator orderByComparator)
3519                    throws NoSuchTemplateException, SystemException {
3520                    DDMTemplate ddmTemplate = fetchByType_First(type, orderByComparator);
3521    
3522                    if (ddmTemplate != null) {
3523                            return ddmTemplate;
3524                    }
3525    
3526                    StringBundler msg = new StringBundler(4);
3527    
3528                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3529    
3530                    msg.append("type=");
3531                    msg.append(type);
3532    
3533                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3534    
3535                    throw new NoSuchTemplateException(msg.toString());
3536            }
3537    
3538            /**
3539             * Returns the first d d m template in the ordered set where type = &#63;.
3540             *
3541             * @param type the type
3542             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3543             * @return the first matching d d m template, or <code>null</code> if a matching d d m template could not be found
3544             * @throws SystemException if a system exception occurred
3545             */
3546            @Override
3547            public DDMTemplate fetchByType_First(String type,
3548                    OrderByComparator orderByComparator) throws SystemException {
3549                    List<DDMTemplate> list = findByType(type, 0, 1, orderByComparator);
3550    
3551                    if (!list.isEmpty()) {
3552                            return list.get(0);
3553                    }
3554    
3555                    return null;
3556            }
3557    
3558            /**
3559             * Returns the last d d m template in the ordered set where type = &#63;.
3560             *
3561             * @param type the type
3562             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3563             * @return the last matching d d m template
3564             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
3565             * @throws SystemException if a system exception occurred
3566             */
3567            @Override
3568            public DDMTemplate findByType_Last(String type,
3569                    OrderByComparator orderByComparator)
3570                    throws NoSuchTemplateException, SystemException {
3571                    DDMTemplate ddmTemplate = fetchByType_Last(type, orderByComparator);
3572    
3573                    if (ddmTemplate != null) {
3574                            return ddmTemplate;
3575                    }
3576    
3577                    StringBundler msg = new StringBundler(4);
3578    
3579                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3580    
3581                    msg.append("type=");
3582                    msg.append(type);
3583    
3584                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3585    
3586                    throw new NoSuchTemplateException(msg.toString());
3587            }
3588    
3589            /**
3590             * Returns the last d d m template in the ordered set where type = &#63;.
3591             *
3592             * @param type the type
3593             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3594             * @return the last matching d d m template, or <code>null</code> if a matching d d m template could not be found
3595             * @throws SystemException if a system exception occurred
3596             */
3597            @Override
3598            public DDMTemplate fetchByType_Last(String type,
3599                    OrderByComparator orderByComparator) throws SystemException {
3600                    int count = countByType(type);
3601    
3602                    if (count == 0) {
3603                            return null;
3604                    }
3605    
3606                    List<DDMTemplate> list = findByType(type, count - 1, count,
3607                                    orderByComparator);
3608    
3609                    if (!list.isEmpty()) {
3610                            return list.get(0);
3611                    }
3612    
3613                    return null;
3614            }
3615    
3616            /**
3617             * Returns the d d m templates before and after the current d d m template in the ordered set where type = &#63;.
3618             *
3619             * @param templateId the primary key of the current d d m template
3620             * @param type the type
3621             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3622             * @return the previous, current, and next d d m template
3623             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
3624             * @throws SystemException if a system exception occurred
3625             */
3626            @Override
3627            public DDMTemplate[] findByType_PrevAndNext(long templateId, String type,
3628                    OrderByComparator orderByComparator)
3629                    throws NoSuchTemplateException, SystemException {
3630                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
3631    
3632                    Session session = null;
3633    
3634                    try {
3635                            session = openSession();
3636    
3637                            DDMTemplate[] array = new DDMTemplateImpl[3];
3638    
3639                            array[0] = getByType_PrevAndNext(session, ddmTemplate, type,
3640                                            orderByComparator, true);
3641    
3642                            array[1] = ddmTemplate;
3643    
3644                            array[2] = getByType_PrevAndNext(session, ddmTemplate, type,
3645                                            orderByComparator, false);
3646    
3647                            return array;
3648                    }
3649                    catch (Exception e) {
3650                            throw processException(e);
3651                    }
3652                    finally {
3653                            closeSession(session);
3654                    }
3655            }
3656    
3657            protected DDMTemplate getByType_PrevAndNext(Session session,
3658                    DDMTemplate ddmTemplate, String type,
3659                    OrderByComparator orderByComparator, boolean previous) {
3660                    StringBundler query = null;
3661    
3662                    if (orderByComparator != null) {
3663                            query = new StringBundler(6 +
3664                                            (orderByComparator.getOrderByFields().length * 6));
3665                    }
3666                    else {
3667                            query = new StringBundler(3);
3668                    }
3669    
3670                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
3671    
3672                    boolean bindType = false;
3673    
3674                    if (type == null) {
3675                            query.append(_FINDER_COLUMN_TYPE_TYPE_1);
3676                    }
3677                    else if (type.equals(StringPool.BLANK)) {
3678                            query.append(_FINDER_COLUMN_TYPE_TYPE_3);
3679                    }
3680                    else {
3681                            bindType = true;
3682    
3683                            query.append(_FINDER_COLUMN_TYPE_TYPE_2);
3684                    }
3685    
3686                    if (orderByComparator != null) {
3687                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3688    
3689                            if (orderByConditionFields.length > 0) {
3690                                    query.append(WHERE_AND);
3691                            }
3692    
3693                            for (int i = 0; i < orderByConditionFields.length; i++) {
3694                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3695                                    query.append(orderByConditionFields[i]);
3696    
3697                                    if ((i + 1) < orderByConditionFields.length) {
3698                                            if (orderByComparator.isAscending() ^ previous) {
3699                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3700                                            }
3701                                            else {
3702                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3703                                            }
3704                                    }
3705                                    else {
3706                                            if (orderByComparator.isAscending() ^ previous) {
3707                                                    query.append(WHERE_GREATER_THAN);
3708                                            }
3709                                            else {
3710                                                    query.append(WHERE_LESSER_THAN);
3711                                            }
3712                                    }
3713                            }
3714    
3715                            query.append(ORDER_BY_CLAUSE);
3716    
3717                            String[] orderByFields = orderByComparator.getOrderByFields();
3718    
3719                            for (int i = 0; i < orderByFields.length; i++) {
3720                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3721                                    query.append(orderByFields[i]);
3722    
3723                                    if ((i + 1) < orderByFields.length) {
3724                                            if (orderByComparator.isAscending() ^ previous) {
3725                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3726                                            }
3727                                            else {
3728                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3729                                            }
3730                                    }
3731                                    else {
3732                                            if (orderByComparator.isAscending() ^ previous) {
3733                                                    query.append(ORDER_BY_ASC);
3734                                            }
3735                                            else {
3736                                                    query.append(ORDER_BY_DESC);
3737                                            }
3738                                    }
3739                            }
3740                    }
3741                    else {
3742                            query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
3743                    }
3744    
3745                    String sql = query.toString();
3746    
3747                    Query q = session.createQuery(sql);
3748    
3749                    q.setFirstResult(0);
3750                    q.setMaxResults(2);
3751    
3752                    QueryPos qPos = QueryPos.getInstance(q);
3753    
3754                    if (bindType) {
3755                            qPos.add(type);
3756                    }
3757    
3758                    if (orderByComparator != null) {
3759                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
3760    
3761                            for (Object value : values) {
3762                                    qPos.add(value);
3763                            }
3764                    }
3765    
3766                    List<DDMTemplate> list = q.list();
3767    
3768                    if (list.size() == 2) {
3769                            return list.get(1);
3770                    }
3771                    else {
3772                            return null;
3773                    }
3774            }
3775    
3776            /**
3777             * Removes all the d d m templates where type = &#63; from the database.
3778             *
3779             * @param type the type
3780             * @throws SystemException if a system exception occurred
3781             */
3782            @Override
3783            public void removeByType(String type) throws SystemException {
3784                    for (DDMTemplate ddmTemplate : findByType(type, QueryUtil.ALL_POS,
3785                                    QueryUtil.ALL_POS, null)) {
3786                            remove(ddmTemplate);
3787                    }
3788            }
3789    
3790            /**
3791             * Returns the number of d d m templates where type = &#63;.
3792             *
3793             * @param type the type
3794             * @return the number of matching d d m templates
3795             * @throws SystemException if a system exception occurred
3796             */
3797            @Override
3798            public int countByType(String type) throws SystemException {
3799                    FinderPath finderPath = FINDER_PATH_COUNT_BY_TYPE;
3800    
3801                    Object[] finderArgs = new Object[] { type };
3802    
3803                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3804                                    this);
3805    
3806                    if (count == null) {
3807                            StringBundler query = new StringBundler(2);
3808    
3809                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
3810    
3811                            boolean bindType = false;
3812    
3813                            if (type == null) {
3814                                    query.append(_FINDER_COLUMN_TYPE_TYPE_1);
3815                            }
3816                            else if (type.equals(StringPool.BLANK)) {
3817                                    query.append(_FINDER_COLUMN_TYPE_TYPE_3);
3818                            }
3819                            else {
3820                                    bindType = true;
3821    
3822                                    query.append(_FINDER_COLUMN_TYPE_TYPE_2);
3823                            }
3824    
3825                            String sql = query.toString();
3826    
3827                            Session session = null;
3828    
3829                            try {
3830                                    session = openSession();
3831    
3832                                    Query q = session.createQuery(sql);
3833    
3834                                    QueryPos qPos = QueryPos.getInstance(q);
3835    
3836                                    if (bindType) {
3837                                            qPos.add(type);
3838                                    }
3839    
3840                                    count = (Long)q.uniqueResult();
3841    
3842                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3843                            }
3844                            catch (Exception e) {
3845                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3846    
3847                                    throw processException(e);
3848                            }
3849                            finally {
3850                                    closeSession(session);
3851                            }
3852                    }
3853    
3854                    return count.intValue();
3855            }
3856    
3857            private static final String _FINDER_COLUMN_TYPE_TYPE_1 = "ddmTemplate.type IS NULL";
3858            private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "ddmTemplate.type = ?";
3859            private static final String _FINDER_COLUMN_TYPE_TYPE_3 = "(ddmTemplate.type IS NULL OR ddmTemplate.type = '')";
3860            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LANGUAGE = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
3861                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
3862                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByLanguage",
3863                            new String[] {
3864                                    String.class.getName(),
3865                                    
3866                            Integer.class.getName(), Integer.class.getName(),
3867                                    OrderByComparator.class.getName()
3868                            });
3869            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LANGUAGE =
3870                    new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
3871                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
3872                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByLanguage",
3873                            new String[] { String.class.getName() },
3874                            DDMTemplateModelImpl.LANGUAGE_COLUMN_BITMASK);
3875            public static final FinderPath FINDER_PATH_COUNT_BY_LANGUAGE = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
3876                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
3877                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByLanguage",
3878                            new String[] { String.class.getName() });
3879    
3880            /**
3881             * Returns all the d d m templates where language = &#63;.
3882             *
3883             * @param language the language
3884             * @return the matching d d m templates
3885             * @throws SystemException if a system exception occurred
3886             */
3887            @Override
3888            public List<DDMTemplate> findByLanguage(String language)
3889                    throws SystemException {
3890                    return findByLanguage(language, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3891                            null);
3892            }
3893    
3894            /**
3895             * Returns a range of all the d d m templates where language = &#63;.
3896             *
3897             * <p>
3898             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3899             * </p>
3900             *
3901             * @param language the language
3902             * @param start the lower bound of the range of d d m templates
3903             * @param end the upper bound of the range of d d m templates (not inclusive)
3904             * @return the range of matching d d m templates
3905             * @throws SystemException if a system exception occurred
3906             */
3907            @Override
3908            public List<DDMTemplate> findByLanguage(String language, int start, int end)
3909                    throws SystemException {
3910                    return findByLanguage(language, start, end, null);
3911            }
3912    
3913            /**
3914             * Returns an ordered range of all the d d m templates where language = &#63;.
3915             *
3916             * <p>
3917             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3918             * </p>
3919             *
3920             * @param language the language
3921             * @param start the lower bound of the range of d d m templates
3922             * @param end the upper bound of the range of d d m templates (not inclusive)
3923             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3924             * @return the ordered range of matching d d m templates
3925             * @throws SystemException if a system exception occurred
3926             */
3927            @Override
3928            public List<DDMTemplate> findByLanguage(String language, int start,
3929                    int end, OrderByComparator orderByComparator) throws SystemException {
3930                    boolean pagination = true;
3931                    FinderPath finderPath = null;
3932                    Object[] finderArgs = null;
3933    
3934                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3935                                    (orderByComparator == null)) {
3936                            pagination = false;
3937                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LANGUAGE;
3938                            finderArgs = new Object[] { language };
3939                    }
3940                    else {
3941                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LANGUAGE;
3942                            finderArgs = new Object[] { language, start, end, orderByComparator };
3943                    }
3944    
3945                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
3946                                    finderArgs, this);
3947    
3948                    if ((list != null) && !list.isEmpty()) {
3949                            for (DDMTemplate ddmTemplate : list) {
3950                                    if (!Validator.equals(language, ddmTemplate.getLanguage())) {
3951                                            list = null;
3952    
3953                                            break;
3954                                    }
3955                            }
3956                    }
3957    
3958                    if (list == null) {
3959                            StringBundler query = null;
3960    
3961                            if (orderByComparator != null) {
3962                                    query = new StringBundler(3 +
3963                                                    (orderByComparator.getOrderByFields().length * 3));
3964                            }
3965                            else {
3966                                    query = new StringBundler(3);
3967                            }
3968    
3969                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
3970    
3971                            boolean bindLanguage = false;
3972    
3973                            if (language == null) {
3974                                    query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_1);
3975                            }
3976                            else if (language.equals(StringPool.BLANK)) {
3977                                    query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_3);
3978                            }
3979                            else {
3980                                    bindLanguage = true;
3981    
3982                                    query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_2);
3983                            }
3984    
3985                            if (orderByComparator != null) {
3986                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3987                                            orderByComparator);
3988                            }
3989                            else
3990                             if (pagination) {
3991                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
3992                            }
3993    
3994                            String sql = query.toString();
3995    
3996                            Session session = null;
3997    
3998                            try {
3999                                    session = openSession();
4000    
4001                                    Query q = session.createQuery(sql);
4002    
4003                                    QueryPos qPos = QueryPos.getInstance(q);
4004    
4005                                    if (bindLanguage) {
4006                                            qPos.add(language);
4007                                    }
4008    
4009                                    if (!pagination) {
4010                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
4011                                                            start, end, false);
4012    
4013                                            Collections.sort(list);
4014    
4015                                            list = new UnmodifiableList<DDMTemplate>(list);
4016                                    }
4017                                    else {
4018                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
4019                                                            start, end);
4020                                    }
4021    
4022                                    cacheResult(list);
4023    
4024                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4025                            }
4026                            catch (Exception e) {
4027                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4028    
4029                                    throw processException(e);
4030                            }
4031                            finally {
4032                                    closeSession(session);
4033                            }
4034                    }
4035    
4036                    return list;
4037            }
4038    
4039            /**
4040             * Returns the first d d m template in the ordered set where language = &#63;.
4041             *
4042             * @param language the language
4043             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4044             * @return the first matching d d m template
4045             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
4046             * @throws SystemException if a system exception occurred
4047             */
4048            @Override
4049            public DDMTemplate findByLanguage_First(String language,
4050                    OrderByComparator orderByComparator)
4051                    throws NoSuchTemplateException, SystemException {
4052                    DDMTemplate ddmTemplate = fetchByLanguage_First(language,
4053                                    orderByComparator);
4054    
4055                    if (ddmTemplate != null) {
4056                            return ddmTemplate;
4057                    }
4058    
4059                    StringBundler msg = new StringBundler(4);
4060    
4061                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4062    
4063                    msg.append("language=");
4064                    msg.append(language);
4065    
4066                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4067    
4068                    throw new NoSuchTemplateException(msg.toString());
4069            }
4070    
4071            /**
4072             * Returns the first d d m template in the ordered set where language = &#63;.
4073             *
4074             * @param language the language
4075             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4076             * @return the first matching d d m template, or <code>null</code> if a matching d d m template could not be found
4077             * @throws SystemException if a system exception occurred
4078             */
4079            @Override
4080            public DDMTemplate fetchByLanguage_First(String language,
4081                    OrderByComparator orderByComparator) throws SystemException {
4082                    List<DDMTemplate> list = findByLanguage(language, 0, 1,
4083                                    orderByComparator);
4084    
4085                    if (!list.isEmpty()) {
4086                            return list.get(0);
4087                    }
4088    
4089                    return null;
4090            }
4091    
4092            /**
4093             * Returns the last d d m template in the ordered set where language = &#63;.
4094             *
4095             * @param language the language
4096             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4097             * @return the last matching d d m template
4098             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
4099             * @throws SystemException if a system exception occurred
4100             */
4101            @Override
4102            public DDMTemplate findByLanguage_Last(String language,
4103                    OrderByComparator orderByComparator)
4104                    throws NoSuchTemplateException, SystemException {
4105                    DDMTemplate ddmTemplate = fetchByLanguage_Last(language,
4106                                    orderByComparator);
4107    
4108                    if (ddmTemplate != null) {
4109                            return ddmTemplate;
4110                    }
4111    
4112                    StringBundler msg = new StringBundler(4);
4113    
4114                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4115    
4116                    msg.append("language=");
4117                    msg.append(language);
4118    
4119                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4120    
4121                    throw new NoSuchTemplateException(msg.toString());
4122            }
4123    
4124            /**
4125             * Returns the last d d m template in the ordered set where language = &#63;.
4126             *
4127             * @param language the language
4128             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4129             * @return the last matching d d m template, or <code>null</code> if a matching d d m template could not be found
4130             * @throws SystemException if a system exception occurred
4131             */
4132            @Override
4133            public DDMTemplate fetchByLanguage_Last(String language,
4134                    OrderByComparator orderByComparator) throws SystemException {
4135                    int count = countByLanguage(language);
4136    
4137                    if (count == 0) {
4138                            return null;
4139                    }
4140    
4141                    List<DDMTemplate> list = findByLanguage(language, count - 1, count,
4142                                    orderByComparator);
4143    
4144                    if (!list.isEmpty()) {
4145                            return list.get(0);
4146                    }
4147    
4148                    return null;
4149            }
4150    
4151            /**
4152             * Returns the d d m templates before and after the current d d m template in the ordered set where language = &#63;.
4153             *
4154             * @param templateId the primary key of the current d d m template
4155             * @param language the language
4156             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4157             * @return the previous, current, and next d d m template
4158             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
4159             * @throws SystemException if a system exception occurred
4160             */
4161            @Override
4162            public DDMTemplate[] findByLanguage_PrevAndNext(long templateId,
4163                    String language, OrderByComparator orderByComparator)
4164                    throws NoSuchTemplateException, SystemException {
4165                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
4166    
4167                    Session session = null;
4168    
4169                    try {
4170                            session = openSession();
4171    
4172                            DDMTemplate[] array = new DDMTemplateImpl[3];
4173    
4174                            array[0] = getByLanguage_PrevAndNext(session, ddmTemplate,
4175                                            language, orderByComparator, true);
4176    
4177                            array[1] = ddmTemplate;
4178    
4179                            array[2] = getByLanguage_PrevAndNext(session, ddmTemplate,
4180                                            language, orderByComparator, false);
4181    
4182                            return array;
4183                    }
4184                    catch (Exception e) {
4185                            throw processException(e);
4186                    }
4187                    finally {
4188                            closeSession(session);
4189                    }
4190            }
4191    
4192            protected DDMTemplate getByLanguage_PrevAndNext(Session session,
4193                    DDMTemplate ddmTemplate, String language,
4194                    OrderByComparator orderByComparator, boolean previous) {
4195                    StringBundler query = null;
4196    
4197                    if (orderByComparator != null) {
4198                            query = new StringBundler(6 +
4199                                            (orderByComparator.getOrderByFields().length * 6));
4200                    }
4201                    else {
4202                            query = new StringBundler(3);
4203                    }
4204    
4205                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
4206    
4207                    boolean bindLanguage = false;
4208    
4209                    if (language == null) {
4210                            query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_1);
4211                    }
4212                    else if (language.equals(StringPool.BLANK)) {
4213                            query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_3);
4214                    }
4215                    else {
4216                            bindLanguage = true;
4217    
4218                            query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_2);
4219                    }
4220    
4221                    if (orderByComparator != null) {
4222                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4223    
4224                            if (orderByConditionFields.length > 0) {
4225                                    query.append(WHERE_AND);
4226                            }
4227    
4228                            for (int i = 0; i < orderByConditionFields.length; i++) {
4229                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4230                                    query.append(orderByConditionFields[i]);
4231    
4232                                    if ((i + 1) < orderByConditionFields.length) {
4233                                            if (orderByComparator.isAscending() ^ previous) {
4234                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4235                                            }
4236                                            else {
4237                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4238                                            }
4239                                    }
4240                                    else {
4241                                            if (orderByComparator.isAscending() ^ previous) {
4242                                                    query.append(WHERE_GREATER_THAN);
4243                                            }
4244                                            else {
4245                                                    query.append(WHERE_LESSER_THAN);
4246                                            }
4247                                    }
4248                            }
4249    
4250                            query.append(ORDER_BY_CLAUSE);
4251    
4252                            String[] orderByFields = orderByComparator.getOrderByFields();
4253    
4254                            for (int i = 0; i < orderByFields.length; i++) {
4255                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4256                                    query.append(orderByFields[i]);
4257    
4258                                    if ((i + 1) < orderByFields.length) {
4259                                            if (orderByComparator.isAscending() ^ previous) {
4260                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4261                                            }
4262                                            else {
4263                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4264                                            }
4265                                    }
4266                                    else {
4267                                            if (orderByComparator.isAscending() ^ previous) {
4268                                                    query.append(ORDER_BY_ASC);
4269                                            }
4270                                            else {
4271                                                    query.append(ORDER_BY_DESC);
4272                                            }
4273                                    }
4274                            }
4275                    }
4276                    else {
4277                            query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
4278                    }
4279    
4280                    String sql = query.toString();
4281    
4282                    Query q = session.createQuery(sql);
4283    
4284                    q.setFirstResult(0);
4285                    q.setMaxResults(2);
4286    
4287                    QueryPos qPos = QueryPos.getInstance(q);
4288    
4289                    if (bindLanguage) {
4290                            qPos.add(language);
4291                    }
4292    
4293                    if (orderByComparator != null) {
4294                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
4295    
4296                            for (Object value : values) {
4297                                    qPos.add(value);
4298                            }
4299                    }
4300    
4301                    List<DDMTemplate> list = q.list();
4302    
4303                    if (list.size() == 2) {
4304                            return list.get(1);
4305                    }
4306                    else {
4307                            return null;
4308                    }
4309            }
4310    
4311            /**
4312             * Removes all the d d m templates where language = &#63; from the database.
4313             *
4314             * @param language the language
4315             * @throws SystemException if a system exception occurred
4316             */
4317            @Override
4318            public void removeByLanguage(String language) throws SystemException {
4319                    for (DDMTemplate ddmTemplate : findByLanguage(language,
4320                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4321                            remove(ddmTemplate);
4322                    }
4323            }
4324    
4325            /**
4326             * Returns the number of d d m templates where language = &#63;.
4327             *
4328             * @param language the language
4329             * @return the number of matching d d m templates
4330             * @throws SystemException if a system exception occurred
4331             */
4332            @Override
4333            public int countByLanguage(String language) throws SystemException {
4334                    FinderPath finderPath = FINDER_PATH_COUNT_BY_LANGUAGE;
4335    
4336                    Object[] finderArgs = new Object[] { language };
4337    
4338                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4339                                    this);
4340    
4341                    if (count == null) {
4342                            StringBundler query = new StringBundler(2);
4343    
4344                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
4345    
4346                            boolean bindLanguage = false;
4347    
4348                            if (language == null) {
4349                                    query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_1);
4350                            }
4351                            else if (language.equals(StringPool.BLANK)) {
4352                                    query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_3);
4353                            }
4354                            else {
4355                                    bindLanguage = true;
4356    
4357                                    query.append(_FINDER_COLUMN_LANGUAGE_LANGUAGE_2);
4358                            }
4359    
4360                            String sql = query.toString();
4361    
4362                            Session session = null;
4363    
4364                            try {
4365                                    session = openSession();
4366    
4367                                    Query q = session.createQuery(sql);
4368    
4369                                    QueryPos qPos = QueryPos.getInstance(q);
4370    
4371                                    if (bindLanguage) {
4372                                            qPos.add(language);
4373                                    }
4374    
4375                                    count = (Long)q.uniqueResult();
4376    
4377                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4378                            }
4379                            catch (Exception e) {
4380                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4381    
4382                                    throw processException(e);
4383                            }
4384                            finally {
4385                                    closeSession(session);
4386                            }
4387                    }
4388    
4389                    return count.intValue();
4390            }
4391    
4392            private static final String _FINDER_COLUMN_LANGUAGE_LANGUAGE_1 = "ddmTemplate.language IS NULL";
4393            private static final String _FINDER_COLUMN_LANGUAGE_LANGUAGE_2 = "ddmTemplate.language = ?";
4394            private static final String _FINDER_COLUMN_LANGUAGE_LANGUAGE_3 = "(ddmTemplate.language IS NULL OR ddmTemplate.language = '')";
4395            public static final FinderPath FINDER_PATH_FETCH_BY_SMALLIMAGEID = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
4396                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
4397                            FINDER_CLASS_NAME_ENTITY, "fetchBySmallImageId",
4398                            new String[] { Long.class.getName() },
4399                            DDMTemplateModelImpl.SMALLIMAGEID_COLUMN_BITMASK);
4400            public static final FinderPath FINDER_PATH_COUNT_BY_SMALLIMAGEID = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
4401                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
4402                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBySmallImageId",
4403                            new String[] { Long.class.getName() });
4404    
4405            /**
4406             * Returns the d d m template where smallImageId = &#63; or throws a {@link com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException} if it could not be found.
4407             *
4408             * @param smallImageId the small image ID
4409             * @return the matching d d m template
4410             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
4411             * @throws SystemException if a system exception occurred
4412             */
4413            @Override
4414            public DDMTemplate findBySmallImageId(long smallImageId)
4415                    throws NoSuchTemplateException, SystemException {
4416                    DDMTemplate ddmTemplate = fetchBySmallImageId(smallImageId);
4417    
4418                    if (ddmTemplate == null) {
4419                            StringBundler msg = new StringBundler(4);
4420    
4421                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4422    
4423                            msg.append("smallImageId=");
4424                            msg.append(smallImageId);
4425    
4426                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4427    
4428                            if (_log.isWarnEnabled()) {
4429                                    _log.warn(msg.toString());
4430                            }
4431    
4432                            throw new NoSuchTemplateException(msg.toString());
4433                    }
4434    
4435                    return ddmTemplate;
4436            }
4437    
4438            /**
4439             * Returns the d d m template where smallImageId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
4440             *
4441             * @param smallImageId the small image ID
4442             * @return the matching d d m template, or <code>null</code> if a matching d d m template could not be found
4443             * @throws SystemException if a system exception occurred
4444             */
4445            @Override
4446            public DDMTemplate fetchBySmallImageId(long smallImageId)
4447                    throws SystemException {
4448                    return fetchBySmallImageId(smallImageId, true);
4449            }
4450    
4451            /**
4452             * Returns the d d m template where smallImageId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
4453             *
4454             * @param smallImageId the small image ID
4455             * @param retrieveFromCache whether to use the finder cache
4456             * @return the matching d d m template, or <code>null</code> if a matching d d m template could not be found
4457             * @throws SystemException if a system exception occurred
4458             */
4459            @Override
4460            public DDMTemplate fetchBySmallImageId(long smallImageId,
4461                    boolean retrieveFromCache) throws SystemException {
4462                    Object[] finderArgs = new Object[] { smallImageId };
4463    
4464                    Object result = null;
4465    
4466                    if (retrieveFromCache) {
4467                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
4468                                            finderArgs, this);
4469                    }
4470    
4471                    if (result instanceof DDMTemplate) {
4472                            DDMTemplate ddmTemplate = (DDMTemplate)result;
4473    
4474                            if ((smallImageId != ddmTemplate.getSmallImageId())) {
4475                                    result = null;
4476                            }
4477                    }
4478    
4479                    if (result == null) {
4480                            StringBundler query = new StringBundler(3);
4481    
4482                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
4483    
4484                            query.append(_FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2);
4485    
4486                            String sql = query.toString();
4487    
4488                            Session session = null;
4489    
4490                            try {
4491                                    session = openSession();
4492    
4493                                    Query q = session.createQuery(sql);
4494    
4495                                    QueryPos qPos = QueryPos.getInstance(q);
4496    
4497                                    qPos.add(smallImageId);
4498    
4499                                    List<DDMTemplate> list = q.list();
4500    
4501                                    if (list.isEmpty()) {
4502                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
4503                                                    finderArgs, list);
4504                                    }
4505                                    else {
4506                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
4507                                                    _log.warn(
4508                                                            "DDMTemplatePersistenceImpl.fetchBySmallImageId(long, boolean) with parameters (" +
4509                                                            StringUtil.merge(finderArgs) +
4510                                                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
4511                                            }
4512    
4513                                            DDMTemplate ddmTemplate = list.get(0);
4514    
4515                                            result = ddmTemplate;
4516    
4517                                            cacheResult(ddmTemplate);
4518    
4519                                            if ((ddmTemplate.getSmallImageId() != smallImageId)) {
4520                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
4521                                                            finderArgs, ddmTemplate);
4522                                            }
4523                                    }
4524                            }
4525                            catch (Exception e) {
4526                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
4527                                            finderArgs);
4528    
4529                                    throw processException(e);
4530                            }
4531                            finally {
4532                                    closeSession(session);
4533                            }
4534                    }
4535    
4536                    if (result instanceof List<?>) {
4537                            return null;
4538                    }
4539                    else {
4540                            return (DDMTemplate)result;
4541                    }
4542            }
4543    
4544            /**
4545             * Removes the d d m template where smallImageId = &#63; from the database.
4546             *
4547             * @param smallImageId the small image ID
4548             * @return the d d m template that was removed
4549             * @throws SystemException if a system exception occurred
4550             */
4551            @Override
4552            public DDMTemplate removeBySmallImageId(long smallImageId)
4553                    throws NoSuchTemplateException, SystemException {
4554                    DDMTemplate ddmTemplate = findBySmallImageId(smallImageId);
4555    
4556                    return remove(ddmTemplate);
4557            }
4558    
4559            /**
4560             * Returns the number of d d m templates where smallImageId = &#63;.
4561             *
4562             * @param smallImageId the small image ID
4563             * @return the number of matching d d m templates
4564             * @throws SystemException if a system exception occurred
4565             */
4566            @Override
4567            public int countBySmallImageId(long smallImageId) throws SystemException {
4568                    FinderPath finderPath = FINDER_PATH_COUNT_BY_SMALLIMAGEID;
4569    
4570                    Object[] finderArgs = new Object[] { smallImageId };
4571    
4572                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4573                                    this);
4574    
4575                    if (count == null) {
4576                            StringBundler query = new StringBundler(2);
4577    
4578                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
4579    
4580                            query.append(_FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2);
4581    
4582                            String sql = query.toString();
4583    
4584                            Session session = null;
4585    
4586                            try {
4587                                    session = openSession();
4588    
4589                                    Query q = session.createQuery(sql);
4590    
4591                                    QueryPos qPos = QueryPos.getInstance(q);
4592    
4593                                    qPos.add(smallImageId);
4594    
4595                                    count = (Long)q.uniqueResult();
4596    
4597                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4598                            }
4599                            catch (Exception e) {
4600                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4601    
4602                                    throw processException(e);
4603                            }
4604                            finally {
4605                                    closeSession(session);
4606                            }
4607                    }
4608    
4609                    return count.intValue();
4610            }
4611    
4612            private static final String _FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2 = "ddmTemplate.smallImageId = ?";
4613            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
4614                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
4615                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
4616                            new String[] {
4617                                    Long.class.getName(), Long.class.getName(),
4618                                    
4619                            Integer.class.getName(), Integer.class.getName(),
4620                                    OrderByComparator.class.getName()
4621                            });
4622            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
4623                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
4624                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
4625                            new String[] { Long.class.getName(), Long.class.getName() },
4626                            DDMTemplateModelImpl.GROUPID_COLUMN_BITMASK |
4627                            DDMTemplateModelImpl.CLASSNAMEID_COLUMN_BITMASK);
4628            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
4629                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
4630                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
4631                            new String[] { Long.class.getName(), Long.class.getName() });
4632    
4633            /**
4634             * Returns all the d d m templates where groupId = &#63; and classNameId = &#63;.
4635             *
4636             * @param groupId the group ID
4637             * @param classNameId the class name ID
4638             * @return the matching d d m templates
4639             * @throws SystemException if a system exception occurred
4640             */
4641            @Override
4642            public List<DDMTemplate> findByG_C(long groupId, long classNameId)
4643                    throws SystemException {
4644                    return findByG_C(groupId, classNameId, QueryUtil.ALL_POS,
4645                            QueryUtil.ALL_POS, null);
4646            }
4647    
4648            /**
4649             * Returns a range of all the d d m templates where groupId = &#63; and classNameId = &#63;.
4650             *
4651             * <p>
4652             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4653             * </p>
4654             *
4655             * @param groupId the group ID
4656             * @param classNameId the class name ID
4657             * @param start the lower bound of the range of d d m templates
4658             * @param end the upper bound of the range of d d m templates (not inclusive)
4659             * @return the range of matching d d m templates
4660             * @throws SystemException if a system exception occurred
4661             */
4662            @Override
4663            public List<DDMTemplate> findByG_C(long groupId, long classNameId,
4664                    int start, int end) throws SystemException {
4665                    return findByG_C(groupId, classNameId, start, end, null);
4666            }
4667    
4668            /**
4669             * Returns an ordered range of all the d d m templates where groupId = &#63; and classNameId = &#63;.
4670             *
4671             * <p>
4672             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4673             * </p>
4674             *
4675             * @param groupId the group ID
4676             * @param classNameId the class name ID
4677             * @param start the lower bound of the range of d d m templates
4678             * @param end the upper bound of the range of d d m templates (not inclusive)
4679             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4680             * @return the ordered range of matching d d m templates
4681             * @throws SystemException if a system exception occurred
4682             */
4683            @Override
4684            public List<DDMTemplate> findByG_C(long groupId, long classNameId,
4685                    int start, int end, OrderByComparator orderByComparator)
4686                    throws SystemException {
4687                    boolean pagination = true;
4688                    FinderPath finderPath = null;
4689                    Object[] finderArgs = null;
4690    
4691                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4692                                    (orderByComparator == null)) {
4693                            pagination = false;
4694                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
4695                            finderArgs = new Object[] { groupId, classNameId };
4696                    }
4697                    else {
4698                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
4699                            finderArgs = new Object[] {
4700                                            groupId, classNameId,
4701                                            
4702                                            start, end, orderByComparator
4703                                    };
4704                    }
4705    
4706                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
4707                                    finderArgs, this);
4708    
4709                    if ((list != null) && !list.isEmpty()) {
4710                            for (DDMTemplate ddmTemplate : list) {
4711                                    if ((groupId != ddmTemplate.getGroupId()) ||
4712                                                    (classNameId != ddmTemplate.getClassNameId())) {
4713                                            list = null;
4714    
4715                                            break;
4716                                    }
4717                            }
4718                    }
4719    
4720                    if (list == null) {
4721                            StringBundler query = null;
4722    
4723                            if (orderByComparator != null) {
4724                                    query = new StringBundler(4 +
4725                                                    (orderByComparator.getOrderByFields().length * 3));
4726                            }
4727                            else {
4728                                    query = new StringBundler(4);
4729                            }
4730    
4731                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
4732    
4733                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
4734    
4735                            query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
4736    
4737                            if (orderByComparator != null) {
4738                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4739                                            orderByComparator);
4740                            }
4741                            else
4742                             if (pagination) {
4743                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
4744                            }
4745    
4746                            String sql = query.toString();
4747    
4748                            Session session = null;
4749    
4750                            try {
4751                                    session = openSession();
4752    
4753                                    Query q = session.createQuery(sql);
4754    
4755                                    QueryPos qPos = QueryPos.getInstance(q);
4756    
4757                                    qPos.add(groupId);
4758    
4759                                    qPos.add(classNameId);
4760    
4761                                    if (!pagination) {
4762                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
4763                                                            start, end, false);
4764    
4765                                            Collections.sort(list);
4766    
4767                                            list = new UnmodifiableList<DDMTemplate>(list);
4768                                    }
4769                                    else {
4770                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
4771                                                            start, end);
4772                                    }
4773    
4774                                    cacheResult(list);
4775    
4776                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4777                            }
4778                            catch (Exception e) {
4779                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4780    
4781                                    throw processException(e);
4782                            }
4783                            finally {
4784                                    closeSession(session);
4785                            }
4786                    }
4787    
4788                    return list;
4789            }
4790    
4791            /**
4792             * Returns the first d d m template in the ordered set where groupId = &#63; and classNameId = &#63;.
4793             *
4794             * @param groupId the group ID
4795             * @param classNameId the class name ID
4796             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4797             * @return the first matching d d m template
4798             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
4799             * @throws SystemException if a system exception occurred
4800             */
4801            @Override
4802            public DDMTemplate findByG_C_First(long groupId, long classNameId,
4803                    OrderByComparator orderByComparator)
4804                    throws NoSuchTemplateException, SystemException {
4805                    DDMTemplate ddmTemplate = fetchByG_C_First(groupId, classNameId,
4806                                    orderByComparator);
4807    
4808                    if (ddmTemplate != null) {
4809                            return ddmTemplate;
4810                    }
4811    
4812                    StringBundler msg = new StringBundler(6);
4813    
4814                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4815    
4816                    msg.append("groupId=");
4817                    msg.append(groupId);
4818    
4819                    msg.append(", classNameId=");
4820                    msg.append(classNameId);
4821    
4822                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4823    
4824                    throw new NoSuchTemplateException(msg.toString());
4825            }
4826    
4827            /**
4828             * Returns the first d d m template in the ordered set where groupId = &#63; and classNameId = &#63;.
4829             *
4830             * @param groupId the group ID
4831             * @param classNameId the class name ID
4832             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4833             * @return the first matching d d m template, or <code>null</code> if a matching d d m template could not be found
4834             * @throws SystemException if a system exception occurred
4835             */
4836            @Override
4837            public DDMTemplate fetchByG_C_First(long groupId, long classNameId,
4838                    OrderByComparator orderByComparator) throws SystemException {
4839                    List<DDMTemplate> list = findByG_C(groupId, classNameId, 0, 1,
4840                                    orderByComparator);
4841    
4842                    if (!list.isEmpty()) {
4843                            return list.get(0);
4844                    }
4845    
4846                    return null;
4847            }
4848    
4849            /**
4850             * Returns the last d d m template in the ordered set where groupId = &#63; and classNameId = &#63;.
4851             *
4852             * @param groupId the group ID
4853             * @param classNameId the class name ID
4854             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4855             * @return the last matching d d m template
4856             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
4857             * @throws SystemException if a system exception occurred
4858             */
4859            @Override
4860            public DDMTemplate findByG_C_Last(long groupId, long classNameId,
4861                    OrderByComparator orderByComparator)
4862                    throws NoSuchTemplateException, SystemException {
4863                    DDMTemplate ddmTemplate = fetchByG_C_Last(groupId, classNameId,
4864                                    orderByComparator);
4865    
4866                    if (ddmTemplate != null) {
4867                            return ddmTemplate;
4868                    }
4869    
4870                    StringBundler msg = new StringBundler(6);
4871    
4872                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4873    
4874                    msg.append("groupId=");
4875                    msg.append(groupId);
4876    
4877                    msg.append(", classNameId=");
4878                    msg.append(classNameId);
4879    
4880                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4881    
4882                    throw new NoSuchTemplateException(msg.toString());
4883            }
4884    
4885            /**
4886             * Returns the last d d m template in the ordered set where groupId = &#63; and classNameId = &#63;.
4887             *
4888             * @param groupId the group ID
4889             * @param classNameId the class name ID
4890             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4891             * @return the last matching d d m template, or <code>null</code> if a matching d d m template could not be found
4892             * @throws SystemException if a system exception occurred
4893             */
4894            @Override
4895            public DDMTemplate fetchByG_C_Last(long groupId, long classNameId,
4896                    OrderByComparator orderByComparator) throws SystemException {
4897                    int count = countByG_C(groupId, classNameId);
4898    
4899                    if (count == 0) {
4900                            return null;
4901                    }
4902    
4903                    List<DDMTemplate> list = findByG_C(groupId, classNameId, count - 1,
4904                                    count, orderByComparator);
4905    
4906                    if (!list.isEmpty()) {
4907                            return list.get(0);
4908                    }
4909    
4910                    return null;
4911            }
4912    
4913            /**
4914             * Returns the d d m templates before and after the current d d m template in the ordered set where groupId = &#63; and classNameId = &#63;.
4915             *
4916             * @param templateId the primary key of the current d d m template
4917             * @param groupId the group ID
4918             * @param classNameId the class name ID
4919             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4920             * @return the previous, current, and next d d m template
4921             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
4922             * @throws SystemException if a system exception occurred
4923             */
4924            @Override
4925            public DDMTemplate[] findByG_C_PrevAndNext(long templateId, long groupId,
4926                    long classNameId, OrderByComparator orderByComparator)
4927                    throws NoSuchTemplateException, SystemException {
4928                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
4929    
4930                    Session session = null;
4931    
4932                    try {
4933                            session = openSession();
4934    
4935                            DDMTemplate[] array = new DDMTemplateImpl[3];
4936    
4937                            array[0] = getByG_C_PrevAndNext(session, ddmTemplate, groupId,
4938                                            classNameId, orderByComparator, true);
4939    
4940                            array[1] = ddmTemplate;
4941    
4942                            array[2] = getByG_C_PrevAndNext(session, ddmTemplate, groupId,
4943                                            classNameId, orderByComparator, false);
4944    
4945                            return array;
4946                    }
4947                    catch (Exception e) {
4948                            throw processException(e);
4949                    }
4950                    finally {
4951                            closeSession(session);
4952                    }
4953            }
4954    
4955            protected DDMTemplate getByG_C_PrevAndNext(Session session,
4956                    DDMTemplate ddmTemplate, long groupId, long classNameId,
4957                    OrderByComparator orderByComparator, boolean previous) {
4958                    StringBundler query = null;
4959    
4960                    if (orderByComparator != null) {
4961                            query = new StringBundler(6 +
4962                                            (orderByComparator.getOrderByFields().length * 6));
4963                    }
4964                    else {
4965                            query = new StringBundler(3);
4966                    }
4967    
4968                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
4969    
4970                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
4971    
4972                    query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
4973    
4974                    if (orderByComparator != null) {
4975                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4976    
4977                            if (orderByConditionFields.length > 0) {
4978                                    query.append(WHERE_AND);
4979                            }
4980    
4981                            for (int i = 0; i < orderByConditionFields.length; i++) {
4982                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4983                                    query.append(orderByConditionFields[i]);
4984    
4985                                    if ((i + 1) < orderByConditionFields.length) {
4986                                            if (orderByComparator.isAscending() ^ previous) {
4987                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4988                                            }
4989                                            else {
4990                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4991                                            }
4992                                    }
4993                                    else {
4994                                            if (orderByComparator.isAscending() ^ previous) {
4995                                                    query.append(WHERE_GREATER_THAN);
4996                                            }
4997                                            else {
4998                                                    query.append(WHERE_LESSER_THAN);
4999                                            }
5000                                    }
5001                            }
5002    
5003                            query.append(ORDER_BY_CLAUSE);
5004    
5005                            String[] orderByFields = orderByComparator.getOrderByFields();
5006    
5007                            for (int i = 0; i < orderByFields.length; i++) {
5008                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5009                                    query.append(orderByFields[i]);
5010    
5011                                    if ((i + 1) < orderByFields.length) {
5012                                            if (orderByComparator.isAscending() ^ previous) {
5013                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5014                                            }
5015                                            else {
5016                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5017                                            }
5018                                    }
5019                                    else {
5020                                            if (orderByComparator.isAscending() ^ previous) {
5021                                                    query.append(ORDER_BY_ASC);
5022                                            }
5023                                            else {
5024                                                    query.append(ORDER_BY_DESC);
5025                                            }
5026                                    }
5027                            }
5028                    }
5029                    else {
5030                            query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
5031                    }
5032    
5033                    String sql = query.toString();
5034    
5035                    Query q = session.createQuery(sql);
5036    
5037                    q.setFirstResult(0);
5038                    q.setMaxResults(2);
5039    
5040                    QueryPos qPos = QueryPos.getInstance(q);
5041    
5042                    qPos.add(groupId);
5043    
5044                    qPos.add(classNameId);
5045    
5046                    if (orderByComparator != null) {
5047                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
5048    
5049                            for (Object value : values) {
5050                                    qPos.add(value);
5051                            }
5052                    }
5053    
5054                    List<DDMTemplate> list = q.list();
5055    
5056                    if (list.size() == 2) {
5057                            return list.get(1);
5058                    }
5059                    else {
5060                            return null;
5061                    }
5062            }
5063    
5064            /**
5065             * Returns all the d d m templates that the user has permission to view where groupId = &#63; and classNameId = &#63;.
5066             *
5067             * @param groupId the group ID
5068             * @param classNameId the class name ID
5069             * @return the matching d d m templates that the user has permission to view
5070             * @throws SystemException if a system exception occurred
5071             */
5072            @Override
5073            public List<DDMTemplate> filterFindByG_C(long groupId, long classNameId)
5074                    throws SystemException {
5075                    return filterFindByG_C(groupId, classNameId, QueryUtil.ALL_POS,
5076                            QueryUtil.ALL_POS, null);
5077            }
5078    
5079            /**
5080             * Returns a range of all the d d m templates that the user has permission to view where groupId = &#63; and classNameId = &#63;.
5081             *
5082             * <p>
5083             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5084             * </p>
5085             *
5086             * @param groupId the group ID
5087             * @param classNameId the class name ID
5088             * @param start the lower bound of the range of d d m templates
5089             * @param end the upper bound of the range of d d m templates (not inclusive)
5090             * @return the range of matching d d m templates that the user has permission to view
5091             * @throws SystemException if a system exception occurred
5092             */
5093            @Override
5094            public List<DDMTemplate> filterFindByG_C(long groupId, long classNameId,
5095                    int start, int end) throws SystemException {
5096                    return filterFindByG_C(groupId, classNameId, start, end, null);
5097            }
5098    
5099            /**
5100             * Returns an ordered range of all the d d m templates that the user has permissions to view where groupId = &#63; and classNameId = &#63;.
5101             *
5102             * <p>
5103             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5104             * </p>
5105             *
5106             * @param groupId the group ID
5107             * @param classNameId the class name ID
5108             * @param start the lower bound of the range of d d m templates
5109             * @param end the upper bound of the range of d d m templates (not inclusive)
5110             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5111             * @return the ordered range of matching d d m templates that the user has permission to view
5112             * @throws SystemException if a system exception occurred
5113             */
5114            @Override
5115            public List<DDMTemplate> filterFindByG_C(long groupId, long classNameId,
5116                    int start, int end, OrderByComparator orderByComparator)
5117                    throws SystemException {
5118                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5119                            return findByG_C(groupId, classNameId, start, end, orderByComparator);
5120                    }
5121    
5122                    StringBundler query = null;
5123    
5124                    if (orderByComparator != null) {
5125                            query = new StringBundler(4 +
5126                                            (orderByComparator.getOrderByFields().length * 3));
5127                    }
5128                    else {
5129                            query = new StringBundler(4);
5130                    }
5131    
5132                    if (getDB().isSupportsInlineDistinct()) {
5133                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_WHERE);
5134                    }
5135                    else {
5136                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
5137                    }
5138    
5139                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5140    
5141                    query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
5142    
5143                    if (!getDB().isSupportsInlineDistinct()) {
5144                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
5145                    }
5146    
5147                    if (orderByComparator != null) {
5148                            if (getDB().isSupportsInlineDistinct()) {
5149                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5150                                            orderByComparator, true);
5151                            }
5152                            else {
5153                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5154                                            orderByComparator, true);
5155                            }
5156                    }
5157                    else {
5158                            if (getDB().isSupportsInlineDistinct()) {
5159                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
5160                            }
5161                            else {
5162                                    query.append(DDMTemplateModelImpl.ORDER_BY_SQL);
5163                            }
5164                    }
5165    
5166                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5167                                    DDMTemplate.class.getName(),
5168                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5169    
5170                    Session session = null;
5171    
5172                    try {
5173                            session = openSession();
5174    
5175                            SQLQuery q = session.createSQLQuery(sql);
5176    
5177                            if (getDB().isSupportsInlineDistinct()) {
5178                                    q.addEntity(_FILTER_ENTITY_ALIAS, DDMTemplateImpl.class);
5179                            }
5180                            else {
5181                                    q.addEntity(_FILTER_ENTITY_TABLE, DDMTemplateImpl.class);
5182                            }
5183    
5184                            QueryPos qPos = QueryPos.getInstance(q);
5185    
5186                            qPos.add(groupId);
5187    
5188                            qPos.add(classNameId);
5189    
5190                            return (List<DDMTemplate>)QueryUtil.list(q, getDialect(), start, end);
5191                    }
5192                    catch (Exception e) {
5193                            throw processException(e);
5194                    }
5195                    finally {
5196                            closeSession(session);
5197                    }
5198            }
5199    
5200            /**
5201             * Returns the d d m templates before and after the current d d m template in the ordered set of d d m templates that the user has permission to view where groupId = &#63; and classNameId = &#63;.
5202             *
5203             * @param templateId the primary key of the current d d m template
5204             * @param groupId the group ID
5205             * @param classNameId the class name ID
5206             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5207             * @return the previous, current, and next d d m template
5208             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
5209             * @throws SystemException if a system exception occurred
5210             */
5211            @Override
5212            public DDMTemplate[] filterFindByG_C_PrevAndNext(long templateId,
5213                    long groupId, long classNameId, OrderByComparator orderByComparator)
5214                    throws NoSuchTemplateException, SystemException {
5215                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5216                            return findByG_C_PrevAndNext(templateId, groupId, classNameId,
5217                                    orderByComparator);
5218                    }
5219    
5220                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
5221    
5222                    Session session = null;
5223    
5224                    try {
5225                            session = openSession();
5226    
5227                            DDMTemplate[] array = new DDMTemplateImpl[3];
5228    
5229                            array[0] = filterGetByG_C_PrevAndNext(session, ddmTemplate,
5230                                            groupId, classNameId, orderByComparator, true);
5231    
5232                            array[1] = ddmTemplate;
5233    
5234                            array[2] = filterGetByG_C_PrevAndNext(session, ddmTemplate,
5235                                            groupId, classNameId, orderByComparator, false);
5236    
5237                            return array;
5238                    }
5239                    catch (Exception e) {
5240                            throw processException(e);
5241                    }
5242                    finally {
5243                            closeSession(session);
5244                    }
5245            }
5246    
5247            protected DDMTemplate filterGetByG_C_PrevAndNext(Session session,
5248                    DDMTemplate ddmTemplate, long groupId, long classNameId,
5249                    OrderByComparator orderByComparator, boolean previous) {
5250                    StringBundler query = null;
5251    
5252                    if (orderByComparator != null) {
5253                            query = new StringBundler(6 +
5254                                            (orderByComparator.getOrderByFields().length * 6));
5255                    }
5256                    else {
5257                            query = new StringBundler(3);
5258                    }
5259    
5260                    if (getDB().isSupportsInlineDistinct()) {
5261                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_WHERE);
5262                    }
5263                    else {
5264                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
5265                    }
5266    
5267                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5268    
5269                    query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
5270    
5271                    if (!getDB().isSupportsInlineDistinct()) {
5272                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
5273                    }
5274    
5275                    if (orderByComparator != null) {
5276                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5277    
5278                            if (orderByConditionFields.length > 0) {
5279                                    query.append(WHERE_AND);
5280                            }
5281    
5282                            for (int i = 0; i < orderByConditionFields.length; i++) {
5283                                    if (getDB().isSupportsInlineDistinct()) {
5284                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5285                                    }
5286                                    else {
5287                                            query.append(_ORDER_BY_ENTITY_TABLE);
5288                                    }
5289    
5290                                    query.append(orderByConditionFields[i]);
5291    
5292                                    if ((i + 1) < orderByConditionFields.length) {
5293                                            if (orderByComparator.isAscending() ^ previous) {
5294                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5295                                            }
5296                                            else {
5297                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5298                                            }
5299                                    }
5300                                    else {
5301                                            if (orderByComparator.isAscending() ^ previous) {
5302                                                    query.append(WHERE_GREATER_THAN);
5303                                            }
5304                                            else {
5305                                                    query.append(WHERE_LESSER_THAN);
5306                                            }
5307                                    }
5308                            }
5309    
5310                            query.append(ORDER_BY_CLAUSE);
5311    
5312                            String[] orderByFields = orderByComparator.getOrderByFields();
5313    
5314                            for (int i = 0; i < orderByFields.length; i++) {
5315                                    if (getDB().isSupportsInlineDistinct()) {
5316                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5317                                    }
5318                                    else {
5319                                            query.append(_ORDER_BY_ENTITY_TABLE);
5320                                    }
5321    
5322                                    query.append(orderByFields[i]);
5323    
5324                                    if ((i + 1) < orderByFields.length) {
5325                                            if (orderByComparator.isAscending() ^ previous) {
5326                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5327                                            }
5328                                            else {
5329                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5330                                            }
5331                                    }
5332                                    else {
5333                                            if (orderByComparator.isAscending() ^ previous) {
5334                                                    query.append(ORDER_BY_ASC);
5335                                            }
5336                                            else {
5337                                                    query.append(ORDER_BY_DESC);
5338                                            }
5339                                    }
5340                            }
5341                    }
5342                    else {
5343                            if (getDB().isSupportsInlineDistinct()) {
5344                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
5345                            }
5346                            else {
5347                                    query.append(DDMTemplateModelImpl.ORDER_BY_SQL);
5348                            }
5349                    }
5350    
5351                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5352                                    DDMTemplate.class.getName(),
5353                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5354    
5355                    SQLQuery q = session.createSQLQuery(sql);
5356    
5357                    q.setFirstResult(0);
5358                    q.setMaxResults(2);
5359    
5360                    if (getDB().isSupportsInlineDistinct()) {
5361                            q.addEntity(_FILTER_ENTITY_ALIAS, DDMTemplateImpl.class);
5362                    }
5363                    else {
5364                            q.addEntity(_FILTER_ENTITY_TABLE, DDMTemplateImpl.class);
5365                    }
5366    
5367                    QueryPos qPos = QueryPos.getInstance(q);
5368    
5369                    qPos.add(groupId);
5370    
5371                    qPos.add(classNameId);
5372    
5373                    if (orderByComparator != null) {
5374                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
5375    
5376                            for (Object value : values) {
5377                                    qPos.add(value);
5378                            }
5379                    }
5380    
5381                    List<DDMTemplate> list = q.list();
5382    
5383                    if (list.size() == 2) {
5384                            return list.get(1);
5385                    }
5386                    else {
5387                            return null;
5388                    }
5389            }
5390    
5391            /**
5392             * Removes all the d d m templates where groupId = &#63; and classNameId = &#63; from the database.
5393             *
5394             * @param groupId the group ID
5395             * @param classNameId the class name ID
5396             * @throws SystemException if a system exception occurred
5397             */
5398            @Override
5399            public void removeByG_C(long groupId, long classNameId)
5400                    throws SystemException {
5401                    for (DDMTemplate ddmTemplate : findByG_C(groupId, classNameId,
5402                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5403                            remove(ddmTemplate);
5404                    }
5405            }
5406    
5407            /**
5408             * Returns the number of d d m templates where groupId = &#63; and classNameId = &#63;.
5409             *
5410             * @param groupId the group ID
5411             * @param classNameId the class name ID
5412             * @return the number of matching d d m templates
5413             * @throws SystemException if a system exception occurred
5414             */
5415            @Override
5416            public int countByG_C(long groupId, long classNameId)
5417                    throws SystemException {
5418                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
5419    
5420                    Object[] finderArgs = new Object[] { groupId, classNameId };
5421    
5422                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5423                                    this);
5424    
5425                    if (count == null) {
5426                            StringBundler query = new StringBundler(3);
5427    
5428                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
5429    
5430                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5431    
5432                            query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
5433    
5434                            String sql = query.toString();
5435    
5436                            Session session = null;
5437    
5438                            try {
5439                                    session = openSession();
5440    
5441                                    Query q = session.createQuery(sql);
5442    
5443                                    QueryPos qPos = QueryPos.getInstance(q);
5444    
5445                                    qPos.add(groupId);
5446    
5447                                    qPos.add(classNameId);
5448    
5449                                    count = (Long)q.uniqueResult();
5450    
5451                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5452                            }
5453                            catch (Exception e) {
5454                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5455    
5456                                    throw processException(e);
5457                            }
5458                            finally {
5459                                    closeSession(session);
5460                            }
5461                    }
5462    
5463                    return count.intValue();
5464            }
5465    
5466            /**
5467             * Returns the number of d d m templates that the user has permission to view where groupId = &#63; and classNameId = &#63;.
5468             *
5469             * @param groupId the group ID
5470             * @param classNameId the class name ID
5471             * @return the number of matching d d m templates that the user has permission to view
5472             * @throws SystemException if a system exception occurred
5473             */
5474            @Override
5475            public int filterCountByG_C(long groupId, long classNameId)
5476                    throws SystemException {
5477                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5478                            return countByG_C(groupId, classNameId);
5479                    }
5480    
5481                    StringBundler query = new StringBundler(3);
5482    
5483                    query.append(_FILTER_SQL_COUNT_DDMTEMPLATE_WHERE);
5484    
5485                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5486    
5487                    query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
5488    
5489                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5490                                    DDMTemplate.class.getName(),
5491                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5492    
5493                    Session session = null;
5494    
5495                    try {
5496                            session = openSession();
5497    
5498                            SQLQuery q = session.createSQLQuery(sql);
5499    
5500                            q.addScalar(COUNT_COLUMN_NAME,
5501                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5502    
5503                            QueryPos qPos = QueryPos.getInstance(q);
5504    
5505                            qPos.add(groupId);
5506    
5507                            qPos.add(classNameId);
5508    
5509                            Long count = (Long)q.uniqueResult();
5510    
5511                            return count.intValue();
5512                    }
5513                    catch (Exception e) {
5514                            throw processException(e);
5515                    }
5516                    finally {
5517                            closeSession(session);
5518                    }
5519            }
5520    
5521            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "ddmTemplate.groupId = ? AND ";
5522            private static final String _FINDER_COLUMN_G_C_CLASSNAMEID_2 = "ddmTemplate.classNameId = ?";
5523            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_CPK = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
5524                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
5525                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_CPK",
5526                            new String[] {
5527                                    Long.class.getName(), Long.class.getName(),
5528                                    
5529                            Integer.class.getName(), Integer.class.getName(),
5530                                    OrderByComparator.class.getName()
5531                            });
5532            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_CPK = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
5533                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
5534                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_CPK",
5535                            new String[] { Long.class.getName(), Long.class.getName() },
5536                            DDMTemplateModelImpl.GROUPID_COLUMN_BITMASK |
5537                            DDMTemplateModelImpl.CLASSPK_COLUMN_BITMASK);
5538            public static final FinderPath FINDER_PATH_COUNT_BY_G_CPK = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
5539                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
5540                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_CPK",
5541                            new String[] { Long.class.getName(), Long.class.getName() });
5542            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_CPK = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
5543                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
5544                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_CPK",
5545                            new String[] { Long.class.getName(), Long.class.getName() });
5546    
5547            /**
5548             * Returns all the d d m templates where groupId = &#63; and classPK = &#63;.
5549             *
5550             * @param groupId the group ID
5551             * @param classPK the class p k
5552             * @return the matching d d m templates
5553             * @throws SystemException if a system exception occurred
5554             */
5555            @Override
5556            public List<DDMTemplate> findByG_CPK(long groupId, long classPK)
5557                    throws SystemException {
5558                    return findByG_CPK(groupId, classPK, QueryUtil.ALL_POS,
5559                            QueryUtil.ALL_POS, null);
5560            }
5561    
5562            /**
5563             * Returns a range of all the d d m templates where groupId = &#63; and classPK = &#63;.
5564             *
5565             * <p>
5566             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5567             * </p>
5568             *
5569             * @param groupId the group ID
5570             * @param classPK the class p k
5571             * @param start the lower bound of the range of d d m templates
5572             * @param end the upper bound of the range of d d m templates (not inclusive)
5573             * @return the range of matching d d m templates
5574             * @throws SystemException if a system exception occurred
5575             */
5576            @Override
5577            public List<DDMTemplate> findByG_CPK(long groupId, long classPK, int start,
5578                    int end) throws SystemException {
5579                    return findByG_CPK(groupId, classPK, start, end, null);
5580            }
5581    
5582            /**
5583             * Returns an ordered range of all the d d m templates where groupId = &#63; and classPK = &#63;.
5584             *
5585             * <p>
5586             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5587             * </p>
5588             *
5589             * @param groupId the group ID
5590             * @param classPK the class p k
5591             * @param start the lower bound of the range of d d m templates
5592             * @param end the upper bound of the range of d d m templates (not inclusive)
5593             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5594             * @return the ordered range of matching d d m templates
5595             * @throws SystemException if a system exception occurred
5596             */
5597            @Override
5598            public List<DDMTemplate> findByG_CPK(long groupId, long classPK, int start,
5599                    int end, OrderByComparator orderByComparator) throws SystemException {
5600                    boolean pagination = true;
5601                    FinderPath finderPath = null;
5602                    Object[] finderArgs = null;
5603    
5604                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5605                                    (orderByComparator == null)) {
5606                            pagination = false;
5607                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_CPK;
5608                            finderArgs = new Object[] { groupId, classPK };
5609                    }
5610                    else {
5611                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_CPK;
5612                            finderArgs = new Object[] {
5613                                            groupId, classPK,
5614                                            
5615                                            start, end, orderByComparator
5616                                    };
5617                    }
5618    
5619                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
5620                                    finderArgs, this);
5621    
5622                    if ((list != null) && !list.isEmpty()) {
5623                            for (DDMTemplate ddmTemplate : list) {
5624                                    if ((groupId != ddmTemplate.getGroupId()) ||
5625                                                    (classPK != ddmTemplate.getClassPK())) {
5626                                            list = null;
5627    
5628                                            break;
5629                                    }
5630                            }
5631                    }
5632    
5633                    if (list == null) {
5634                            StringBundler query = null;
5635    
5636                            if (orderByComparator != null) {
5637                                    query = new StringBundler(4 +
5638                                                    (orderByComparator.getOrderByFields().length * 3));
5639                            }
5640                            else {
5641                                    query = new StringBundler(4);
5642                            }
5643    
5644                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
5645    
5646                            query.append(_FINDER_COLUMN_G_CPK_GROUPID_2);
5647    
5648                            query.append(_FINDER_COLUMN_G_CPK_CLASSPK_2);
5649    
5650                            if (orderByComparator != null) {
5651                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5652                                            orderByComparator);
5653                            }
5654                            else
5655                             if (pagination) {
5656                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
5657                            }
5658    
5659                            String sql = query.toString();
5660    
5661                            Session session = null;
5662    
5663                            try {
5664                                    session = openSession();
5665    
5666                                    Query q = session.createQuery(sql);
5667    
5668                                    QueryPos qPos = QueryPos.getInstance(q);
5669    
5670                                    qPos.add(groupId);
5671    
5672                                    qPos.add(classPK);
5673    
5674                                    if (!pagination) {
5675                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
5676                                                            start, end, false);
5677    
5678                                            Collections.sort(list);
5679    
5680                                            list = new UnmodifiableList<DDMTemplate>(list);
5681                                    }
5682                                    else {
5683                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
5684                                                            start, end);
5685                                    }
5686    
5687                                    cacheResult(list);
5688    
5689                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5690                            }
5691                            catch (Exception e) {
5692                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5693    
5694                                    throw processException(e);
5695                            }
5696                            finally {
5697                                    closeSession(session);
5698                            }
5699                    }
5700    
5701                    return list;
5702            }
5703    
5704            /**
5705             * Returns the first d d m template in the ordered set where groupId = &#63; and classPK = &#63;.
5706             *
5707             * @param groupId the group ID
5708             * @param classPK the class p k
5709             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5710             * @return the first matching d d m template
5711             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
5712             * @throws SystemException if a system exception occurred
5713             */
5714            @Override
5715            public DDMTemplate findByG_CPK_First(long groupId, long classPK,
5716                    OrderByComparator orderByComparator)
5717                    throws NoSuchTemplateException, SystemException {
5718                    DDMTemplate ddmTemplate = fetchByG_CPK_First(groupId, classPK,
5719                                    orderByComparator);
5720    
5721                    if (ddmTemplate != null) {
5722                            return ddmTemplate;
5723                    }
5724    
5725                    StringBundler msg = new StringBundler(6);
5726    
5727                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5728    
5729                    msg.append("groupId=");
5730                    msg.append(groupId);
5731    
5732                    msg.append(", classPK=");
5733                    msg.append(classPK);
5734    
5735                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5736    
5737                    throw new NoSuchTemplateException(msg.toString());
5738            }
5739    
5740            /**
5741             * Returns the first d d m template in the ordered set where groupId = &#63; and classPK = &#63;.
5742             *
5743             * @param groupId the group ID
5744             * @param classPK the class p k
5745             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5746             * @return the first matching d d m template, or <code>null</code> if a matching d d m template could not be found
5747             * @throws SystemException if a system exception occurred
5748             */
5749            @Override
5750            public DDMTemplate fetchByG_CPK_First(long groupId, long classPK,
5751                    OrderByComparator orderByComparator) throws SystemException {
5752                    List<DDMTemplate> list = findByG_CPK(groupId, classPK, 0, 1,
5753                                    orderByComparator);
5754    
5755                    if (!list.isEmpty()) {
5756                            return list.get(0);
5757                    }
5758    
5759                    return null;
5760            }
5761    
5762            /**
5763             * Returns the last d d m template in the ordered set where groupId = &#63; and classPK = &#63;.
5764             *
5765             * @param groupId the group ID
5766             * @param classPK the class p k
5767             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5768             * @return the last matching d d m template
5769             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
5770             * @throws SystemException if a system exception occurred
5771             */
5772            @Override
5773            public DDMTemplate findByG_CPK_Last(long groupId, long classPK,
5774                    OrderByComparator orderByComparator)
5775                    throws NoSuchTemplateException, SystemException {
5776                    DDMTemplate ddmTemplate = fetchByG_CPK_Last(groupId, classPK,
5777                                    orderByComparator);
5778    
5779                    if (ddmTemplate != null) {
5780                            return ddmTemplate;
5781                    }
5782    
5783                    StringBundler msg = new StringBundler(6);
5784    
5785                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5786    
5787                    msg.append("groupId=");
5788                    msg.append(groupId);
5789    
5790                    msg.append(", classPK=");
5791                    msg.append(classPK);
5792    
5793                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5794    
5795                    throw new NoSuchTemplateException(msg.toString());
5796            }
5797    
5798            /**
5799             * Returns the last d d m template in the ordered set where groupId = &#63; and classPK = &#63;.
5800             *
5801             * @param groupId the group ID
5802             * @param classPK the class p k
5803             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5804             * @return the last matching d d m template, or <code>null</code> if a matching d d m template could not be found
5805             * @throws SystemException if a system exception occurred
5806             */
5807            @Override
5808            public DDMTemplate fetchByG_CPK_Last(long groupId, long classPK,
5809                    OrderByComparator orderByComparator) throws SystemException {
5810                    int count = countByG_CPK(groupId, classPK);
5811    
5812                    if (count == 0) {
5813                            return null;
5814                    }
5815    
5816                    List<DDMTemplate> list = findByG_CPK(groupId, classPK, count - 1,
5817                                    count, orderByComparator);
5818    
5819                    if (!list.isEmpty()) {
5820                            return list.get(0);
5821                    }
5822    
5823                    return null;
5824            }
5825    
5826            /**
5827             * Returns the d d m templates before and after the current d d m template in the ordered set where groupId = &#63; and classPK = &#63;.
5828             *
5829             * @param templateId the primary key of the current d d m template
5830             * @param groupId the group ID
5831             * @param classPK the class p k
5832             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5833             * @return the previous, current, and next d d m template
5834             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
5835             * @throws SystemException if a system exception occurred
5836             */
5837            @Override
5838            public DDMTemplate[] findByG_CPK_PrevAndNext(long templateId, long groupId,
5839                    long classPK, OrderByComparator orderByComparator)
5840                    throws NoSuchTemplateException, SystemException {
5841                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
5842    
5843                    Session session = null;
5844    
5845                    try {
5846                            session = openSession();
5847    
5848                            DDMTemplate[] array = new DDMTemplateImpl[3];
5849    
5850                            array[0] = getByG_CPK_PrevAndNext(session, ddmTemplate, groupId,
5851                                            classPK, orderByComparator, true);
5852    
5853                            array[1] = ddmTemplate;
5854    
5855                            array[2] = getByG_CPK_PrevAndNext(session, ddmTemplate, groupId,
5856                                            classPK, orderByComparator, false);
5857    
5858                            return array;
5859                    }
5860                    catch (Exception e) {
5861                            throw processException(e);
5862                    }
5863                    finally {
5864                            closeSession(session);
5865                    }
5866            }
5867    
5868            protected DDMTemplate getByG_CPK_PrevAndNext(Session session,
5869                    DDMTemplate ddmTemplate, long groupId, long classPK,
5870                    OrderByComparator orderByComparator, boolean previous) {
5871                    StringBundler query = null;
5872    
5873                    if (orderByComparator != null) {
5874                            query = new StringBundler(6 +
5875                                            (orderByComparator.getOrderByFields().length * 6));
5876                    }
5877                    else {
5878                            query = new StringBundler(3);
5879                    }
5880    
5881                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
5882    
5883                    query.append(_FINDER_COLUMN_G_CPK_GROUPID_2);
5884    
5885                    query.append(_FINDER_COLUMN_G_CPK_CLASSPK_2);
5886    
5887                    if (orderByComparator != null) {
5888                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5889    
5890                            if (orderByConditionFields.length > 0) {
5891                                    query.append(WHERE_AND);
5892                            }
5893    
5894                            for (int i = 0; i < orderByConditionFields.length; i++) {
5895                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5896                                    query.append(orderByConditionFields[i]);
5897    
5898                                    if ((i + 1) < orderByConditionFields.length) {
5899                                            if (orderByComparator.isAscending() ^ previous) {
5900                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5901                                            }
5902                                            else {
5903                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5904                                            }
5905                                    }
5906                                    else {
5907                                            if (orderByComparator.isAscending() ^ previous) {
5908                                                    query.append(WHERE_GREATER_THAN);
5909                                            }
5910                                            else {
5911                                                    query.append(WHERE_LESSER_THAN);
5912                                            }
5913                                    }
5914                            }
5915    
5916                            query.append(ORDER_BY_CLAUSE);
5917    
5918                            String[] orderByFields = orderByComparator.getOrderByFields();
5919    
5920                            for (int i = 0; i < orderByFields.length; i++) {
5921                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5922                                    query.append(orderByFields[i]);
5923    
5924                                    if ((i + 1) < orderByFields.length) {
5925                                            if (orderByComparator.isAscending() ^ previous) {
5926                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5927                                            }
5928                                            else {
5929                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5930                                            }
5931                                    }
5932                                    else {
5933                                            if (orderByComparator.isAscending() ^ previous) {
5934                                                    query.append(ORDER_BY_ASC);
5935                                            }
5936                                            else {
5937                                                    query.append(ORDER_BY_DESC);
5938                                            }
5939                                    }
5940                            }
5941                    }
5942                    else {
5943                            query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
5944                    }
5945    
5946                    String sql = query.toString();
5947    
5948                    Query q = session.createQuery(sql);
5949    
5950                    q.setFirstResult(0);
5951                    q.setMaxResults(2);
5952    
5953                    QueryPos qPos = QueryPos.getInstance(q);
5954    
5955                    qPos.add(groupId);
5956    
5957                    qPos.add(classPK);
5958    
5959                    if (orderByComparator != null) {
5960                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
5961    
5962                            for (Object value : values) {
5963                                    qPos.add(value);
5964                            }
5965                    }
5966    
5967                    List<DDMTemplate> list = q.list();
5968    
5969                    if (list.size() == 2) {
5970                            return list.get(1);
5971                    }
5972                    else {
5973                            return null;
5974                    }
5975            }
5976    
5977            /**
5978             * Returns all the d d m templates that the user has permission to view where groupId = &#63; and classPK = &#63;.
5979             *
5980             * @param groupId the group ID
5981             * @param classPK the class p k
5982             * @return the matching d d m templates that the user has permission to view
5983             * @throws SystemException if a system exception occurred
5984             */
5985            @Override
5986            public List<DDMTemplate> filterFindByG_CPK(long groupId, long classPK)
5987                    throws SystemException {
5988                    return filterFindByG_CPK(groupId, classPK, QueryUtil.ALL_POS,
5989                            QueryUtil.ALL_POS, null);
5990            }
5991    
5992            /**
5993             * Returns a range of all the d d m templates that the user has permission to view where groupId = &#63; and classPK = &#63;.
5994             *
5995             * <p>
5996             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5997             * </p>
5998             *
5999             * @param groupId the group ID
6000             * @param classPK the class p k
6001             * @param start the lower bound of the range of d d m templates
6002             * @param end the upper bound of the range of d d m templates (not inclusive)
6003             * @return the range of matching d d m templates that the user has permission to view
6004             * @throws SystemException if a system exception occurred
6005             */
6006            @Override
6007            public List<DDMTemplate> filterFindByG_CPK(long groupId, long classPK,
6008                    int start, int end) throws SystemException {
6009                    return filterFindByG_CPK(groupId, classPK, start, end, null);
6010            }
6011    
6012            /**
6013             * Returns an ordered range of all the d d m templates that the user has permissions to view where groupId = &#63; and classPK = &#63;.
6014             *
6015             * <p>
6016             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6017             * </p>
6018             *
6019             * @param groupId the group ID
6020             * @param classPK the class p k
6021             * @param start the lower bound of the range of d d m templates
6022             * @param end the upper bound of the range of d d m templates (not inclusive)
6023             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6024             * @return the ordered range of matching d d m templates that the user has permission to view
6025             * @throws SystemException if a system exception occurred
6026             */
6027            @Override
6028            public List<DDMTemplate> filterFindByG_CPK(long groupId, long classPK,
6029                    int start, int end, OrderByComparator orderByComparator)
6030                    throws SystemException {
6031                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6032                            return findByG_CPK(groupId, classPK, start, end, orderByComparator);
6033                    }
6034    
6035                    StringBundler query = null;
6036    
6037                    if (orderByComparator != null) {
6038                            query = new StringBundler(4 +
6039                                            (orderByComparator.getOrderByFields().length * 3));
6040                    }
6041                    else {
6042                            query = new StringBundler(4);
6043                    }
6044    
6045                    if (getDB().isSupportsInlineDistinct()) {
6046                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_WHERE);
6047                    }
6048                    else {
6049                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
6050                    }
6051    
6052                    query.append(_FINDER_COLUMN_G_CPK_GROUPID_2);
6053    
6054                    query.append(_FINDER_COLUMN_G_CPK_CLASSPK_2);
6055    
6056                    if (!getDB().isSupportsInlineDistinct()) {
6057                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
6058                    }
6059    
6060                    if (orderByComparator != null) {
6061                            if (getDB().isSupportsInlineDistinct()) {
6062                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6063                                            orderByComparator, true);
6064                            }
6065                            else {
6066                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6067                                            orderByComparator, true);
6068                            }
6069                    }
6070                    else {
6071                            if (getDB().isSupportsInlineDistinct()) {
6072                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
6073                            }
6074                            else {
6075                                    query.append(DDMTemplateModelImpl.ORDER_BY_SQL);
6076                            }
6077                    }
6078    
6079                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6080                                    DDMTemplate.class.getName(),
6081                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6082    
6083                    Session session = null;
6084    
6085                    try {
6086                            session = openSession();
6087    
6088                            SQLQuery q = session.createSQLQuery(sql);
6089    
6090                            if (getDB().isSupportsInlineDistinct()) {
6091                                    q.addEntity(_FILTER_ENTITY_ALIAS, DDMTemplateImpl.class);
6092                            }
6093                            else {
6094                                    q.addEntity(_FILTER_ENTITY_TABLE, DDMTemplateImpl.class);
6095                            }
6096    
6097                            QueryPos qPos = QueryPos.getInstance(q);
6098    
6099                            qPos.add(groupId);
6100    
6101                            qPos.add(classPK);
6102    
6103                            return (List<DDMTemplate>)QueryUtil.list(q, getDialect(), start, end);
6104                    }
6105                    catch (Exception e) {
6106                            throw processException(e);
6107                    }
6108                    finally {
6109                            closeSession(session);
6110                    }
6111            }
6112    
6113            /**
6114             * Returns the d d m templates before and after the current d d m template in the ordered set of d d m templates that the user has permission to view where groupId = &#63; and classPK = &#63;.
6115             *
6116             * @param templateId the primary key of the current d d m template
6117             * @param groupId the group ID
6118             * @param classPK the class p k
6119             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6120             * @return the previous, current, and next d d m template
6121             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
6122             * @throws SystemException if a system exception occurred
6123             */
6124            @Override
6125            public DDMTemplate[] filterFindByG_CPK_PrevAndNext(long templateId,
6126                    long groupId, long classPK, OrderByComparator orderByComparator)
6127                    throws NoSuchTemplateException, SystemException {
6128                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6129                            return findByG_CPK_PrevAndNext(templateId, groupId, classPK,
6130                                    orderByComparator);
6131                    }
6132    
6133                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
6134    
6135                    Session session = null;
6136    
6137                    try {
6138                            session = openSession();
6139    
6140                            DDMTemplate[] array = new DDMTemplateImpl[3];
6141    
6142                            array[0] = filterGetByG_CPK_PrevAndNext(session, ddmTemplate,
6143                                            groupId, classPK, orderByComparator, true);
6144    
6145                            array[1] = ddmTemplate;
6146    
6147                            array[2] = filterGetByG_CPK_PrevAndNext(session, ddmTemplate,
6148                                            groupId, classPK, orderByComparator, false);
6149    
6150                            return array;
6151                    }
6152                    catch (Exception e) {
6153                            throw processException(e);
6154                    }
6155                    finally {
6156                            closeSession(session);
6157                    }
6158            }
6159    
6160            protected DDMTemplate filterGetByG_CPK_PrevAndNext(Session session,
6161                    DDMTemplate ddmTemplate, long groupId, long classPK,
6162                    OrderByComparator orderByComparator, boolean previous) {
6163                    StringBundler query = null;
6164    
6165                    if (orderByComparator != null) {
6166                            query = new StringBundler(6 +
6167                                            (orderByComparator.getOrderByFields().length * 6));
6168                    }
6169                    else {
6170                            query = new StringBundler(3);
6171                    }
6172    
6173                    if (getDB().isSupportsInlineDistinct()) {
6174                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_WHERE);
6175                    }
6176                    else {
6177                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
6178                    }
6179    
6180                    query.append(_FINDER_COLUMN_G_CPK_GROUPID_2);
6181    
6182                    query.append(_FINDER_COLUMN_G_CPK_CLASSPK_2);
6183    
6184                    if (!getDB().isSupportsInlineDistinct()) {
6185                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
6186                    }
6187    
6188                    if (orderByComparator != null) {
6189                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6190    
6191                            if (orderByConditionFields.length > 0) {
6192                                    query.append(WHERE_AND);
6193                            }
6194    
6195                            for (int i = 0; i < orderByConditionFields.length; i++) {
6196                                    if (getDB().isSupportsInlineDistinct()) {
6197                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6198                                    }
6199                                    else {
6200                                            query.append(_ORDER_BY_ENTITY_TABLE);
6201                                    }
6202    
6203                                    query.append(orderByConditionFields[i]);
6204    
6205                                    if ((i + 1) < orderByConditionFields.length) {
6206                                            if (orderByComparator.isAscending() ^ previous) {
6207                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6208                                            }
6209                                            else {
6210                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6211                                            }
6212                                    }
6213                                    else {
6214                                            if (orderByComparator.isAscending() ^ previous) {
6215                                                    query.append(WHERE_GREATER_THAN);
6216                                            }
6217                                            else {
6218                                                    query.append(WHERE_LESSER_THAN);
6219                                            }
6220                                    }
6221                            }
6222    
6223                            query.append(ORDER_BY_CLAUSE);
6224    
6225                            String[] orderByFields = orderByComparator.getOrderByFields();
6226    
6227                            for (int i = 0; i < orderByFields.length; i++) {
6228                                    if (getDB().isSupportsInlineDistinct()) {
6229                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6230                                    }
6231                                    else {
6232                                            query.append(_ORDER_BY_ENTITY_TABLE);
6233                                    }
6234    
6235                                    query.append(orderByFields[i]);
6236    
6237                                    if ((i + 1) < orderByFields.length) {
6238                                            if (orderByComparator.isAscending() ^ previous) {
6239                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6240                                            }
6241                                            else {
6242                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6243                                            }
6244                                    }
6245                                    else {
6246                                            if (orderByComparator.isAscending() ^ previous) {
6247                                                    query.append(ORDER_BY_ASC);
6248                                            }
6249                                            else {
6250                                                    query.append(ORDER_BY_DESC);
6251                                            }
6252                                    }
6253                            }
6254                    }
6255                    else {
6256                            if (getDB().isSupportsInlineDistinct()) {
6257                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
6258                            }
6259                            else {
6260                                    query.append(DDMTemplateModelImpl.ORDER_BY_SQL);
6261                            }
6262                    }
6263    
6264                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6265                                    DDMTemplate.class.getName(),
6266                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6267    
6268                    SQLQuery q = session.createSQLQuery(sql);
6269    
6270                    q.setFirstResult(0);
6271                    q.setMaxResults(2);
6272    
6273                    if (getDB().isSupportsInlineDistinct()) {
6274                            q.addEntity(_FILTER_ENTITY_ALIAS, DDMTemplateImpl.class);
6275                    }
6276                    else {
6277                            q.addEntity(_FILTER_ENTITY_TABLE, DDMTemplateImpl.class);
6278                    }
6279    
6280                    QueryPos qPos = QueryPos.getInstance(q);
6281    
6282                    qPos.add(groupId);
6283    
6284                    qPos.add(classPK);
6285    
6286                    if (orderByComparator != null) {
6287                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
6288    
6289                            for (Object value : values) {
6290                                    qPos.add(value);
6291                            }
6292                    }
6293    
6294                    List<DDMTemplate> list = q.list();
6295    
6296                    if (list.size() == 2) {
6297                            return list.get(1);
6298                    }
6299                    else {
6300                            return null;
6301                    }
6302            }
6303    
6304            /**
6305             * Returns all the d d m templates that the user has permission to view where groupId = any &#63; and classPK = &#63;.
6306             *
6307             * @param groupIds the group IDs
6308             * @param classPK the class p k
6309             * @return the matching d d m templates that the user has permission to view
6310             * @throws SystemException if a system exception occurred
6311             */
6312            @Override
6313            public List<DDMTemplate> filterFindByG_CPK(long[] groupIds, long classPK)
6314                    throws SystemException {
6315                    return filterFindByG_CPK(groupIds, classPK, QueryUtil.ALL_POS,
6316                            QueryUtil.ALL_POS, null);
6317            }
6318    
6319            /**
6320             * Returns a range of all the d d m templates that the user has permission to view where groupId = any &#63; and classPK = &#63;.
6321             *
6322             * <p>
6323             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6324             * </p>
6325             *
6326             * @param groupIds the group IDs
6327             * @param classPK the class p k
6328             * @param start the lower bound of the range of d d m templates
6329             * @param end the upper bound of the range of d d m templates (not inclusive)
6330             * @return the range of matching d d m templates that the user has permission to view
6331             * @throws SystemException if a system exception occurred
6332             */
6333            @Override
6334            public List<DDMTemplate> filterFindByG_CPK(long[] groupIds, long classPK,
6335                    int start, int end) throws SystemException {
6336                    return filterFindByG_CPK(groupIds, classPK, start, end, null);
6337            }
6338    
6339            /**
6340             * Returns an ordered range of all the d d m templates that the user has permission to view where groupId = any &#63; and classPK = &#63;.
6341             *
6342             * <p>
6343             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6344             * </p>
6345             *
6346             * @param groupIds the group IDs
6347             * @param classPK the class p k
6348             * @param start the lower bound of the range of d d m templates
6349             * @param end the upper bound of the range of d d m templates (not inclusive)
6350             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6351             * @return the ordered range of matching d d m templates that the user has permission to view
6352             * @throws SystemException if a system exception occurred
6353             */
6354            @Override
6355            public List<DDMTemplate> filterFindByG_CPK(long[] groupIds, long classPK,
6356                    int start, int end, OrderByComparator orderByComparator)
6357                    throws SystemException {
6358                    if (!InlineSQLHelperUtil.isEnabled(groupIds)) {
6359                            return findByG_CPK(groupIds, classPK, start, end, orderByComparator);
6360                    }
6361    
6362                    StringBundler query = new StringBundler();
6363    
6364                    if (getDB().isSupportsInlineDistinct()) {
6365                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_WHERE);
6366                    }
6367                    else {
6368                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
6369                    }
6370    
6371                    boolean conjunctionable = false;
6372    
6373                    if ((groupIds == null) || (groupIds.length > 0)) {
6374                            if (conjunctionable) {
6375                                    query.append(WHERE_AND);
6376                            }
6377    
6378                            query.append(StringPool.OPEN_PARENTHESIS);
6379    
6380                            for (int i = 0; i < groupIds.length; i++) {
6381                                    query.append(_FINDER_COLUMN_G_CPK_GROUPID_5);
6382    
6383                                    if ((i + 1) < groupIds.length) {
6384                                            query.append(WHERE_OR);
6385                                    }
6386                            }
6387    
6388                            query.append(StringPool.CLOSE_PARENTHESIS);
6389    
6390                            conjunctionable = true;
6391                    }
6392    
6393                    if (conjunctionable) {
6394                            query.append(WHERE_AND);
6395                    }
6396    
6397                    query.append(_FINDER_COLUMN_G_CPK_CLASSPK_5);
6398    
6399                    conjunctionable = true;
6400    
6401                    if (!getDB().isSupportsInlineDistinct()) {
6402                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
6403                    }
6404    
6405                    if (orderByComparator != null) {
6406                            if (getDB().isSupportsInlineDistinct()) {
6407                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6408                                            orderByComparator, true);
6409                            }
6410                            else {
6411                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6412                                            orderByComparator, true);
6413                            }
6414                    }
6415                    else {
6416                            if (getDB().isSupportsInlineDistinct()) {
6417                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
6418                            }
6419                            else {
6420                                    query.append(DDMTemplateModelImpl.ORDER_BY_SQL);
6421                            }
6422                    }
6423    
6424                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6425                                    DDMTemplate.class.getName(),
6426                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupIds);
6427    
6428                    Session session = null;
6429    
6430                    try {
6431                            session = openSession();
6432    
6433                            SQLQuery q = session.createSQLQuery(sql);
6434    
6435                            if (getDB().isSupportsInlineDistinct()) {
6436                                    q.addEntity(_FILTER_ENTITY_ALIAS, DDMTemplateImpl.class);
6437                            }
6438                            else {
6439                                    q.addEntity(_FILTER_ENTITY_TABLE, DDMTemplateImpl.class);
6440                            }
6441    
6442                            QueryPos qPos = QueryPos.getInstance(q);
6443    
6444                            if (groupIds != null) {
6445                                    qPos.add(groupIds);
6446                            }
6447    
6448                            qPos.add(classPK);
6449    
6450                            return (List<DDMTemplate>)QueryUtil.list(q, getDialect(), start, end);
6451                    }
6452                    catch (Exception e) {
6453                            throw processException(e);
6454                    }
6455                    finally {
6456                            closeSession(session);
6457                    }
6458            }
6459    
6460            /**
6461             * Returns all the d d m templates where groupId = any &#63; and classPK = &#63;.
6462             *
6463             * <p>
6464             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6465             * </p>
6466             *
6467             * @param groupIds the group IDs
6468             * @param classPK the class p k
6469             * @return the matching d d m templates
6470             * @throws SystemException if a system exception occurred
6471             */
6472            @Override
6473            public List<DDMTemplate> findByG_CPK(long[] groupIds, long classPK)
6474                    throws SystemException {
6475                    return findByG_CPK(groupIds, classPK, QueryUtil.ALL_POS,
6476                            QueryUtil.ALL_POS, null);
6477            }
6478    
6479            /**
6480             * Returns a range of all the d d m templates where groupId = any &#63; and classPK = &#63;.
6481             *
6482             * <p>
6483             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6484             * </p>
6485             *
6486             * @param groupIds the group IDs
6487             * @param classPK the class p k
6488             * @param start the lower bound of the range of d d m templates
6489             * @param end the upper bound of the range of d d m templates (not inclusive)
6490             * @return the range of matching d d m templates
6491             * @throws SystemException if a system exception occurred
6492             */
6493            @Override
6494            public List<DDMTemplate> findByG_CPK(long[] groupIds, long classPK,
6495                    int start, int end) throws SystemException {
6496                    return findByG_CPK(groupIds, classPK, start, end, null);
6497            }
6498    
6499            /**
6500             * Returns an ordered range of all the d d m templates where groupId = any &#63; and classPK = &#63;.
6501             *
6502             * <p>
6503             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6504             * </p>
6505             *
6506             * @param groupIds the group IDs
6507             * @param classPK the class p k
6508             * @param start the lower bound of the range of d d m templates
6509             * @param end the upper bound of the range of d d m templates (not inclusive)
6510             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6511             * @return the ordered range of matching d d m templates
6512             * @throws SystemException if a system exception occurred
6513             */
6514            @Override
6515            public List<DDMTemplate> findByG_CPK(long[] groupIds, long classPK,
6516                    int start, int end, OrderByComparator orderByComparator)
6517                    throws SystemException {
6518                    if ((groupIds != null) && (groupIds.length == 1)) {
6519                            return findByG_CPK(groupIds[0], classPK, start, end,
6520                                    orderByComparator);
6521                    }
6522    
6523                    boolean pagination = true;
6524                    Object[] finderArgs = null;
6525    
6526                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6527                                    (orderByComparator == null)) {
6528                            pagination = false;
6529                            finderArgs = new Object[] { StringUtil.merge(groupIds), classPK };
6530                    }
6531                    else {
6532                            finderArgs = new Object[] {
6533                                            StringUtil.merge(groupIds), classPK,
6534                                            
6535                                            start, end, orderByComparator
6536                                    };
6537                    }
6538    
6539                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_CPK,
6540                                    finderArgs, this);
6541    
6542                    if ((list != null) && !list.isEmpty()) {
6543                            for (DDMTemplate ddmTemplate : list) {
6544                                    if (!ArrayUtil.contains(groupIds, ddmTemplate.getGroupId()) ||
6545                                                    (classPK != ddmTemplate.getClassPK())) {
6546                                            list = null;
6547    
6548                                            break;
6549                                    }
6550                            }
6551                    }
6552    
6553                    if (list == null) {
6554                            StringBundler query = new StringBundler();
6555    
6556                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
6557    
6558                            boolean conjunctionable = false;
6559    
6560                            if ((groupIds == null) || (groupIds.length > 0)) {
6561                                    if (conjunctionable) {
6562                                            query.append(WHERE_AND);
6563                                    }
6564    
6565                                    query.append(StringPool.OPEN_PARENTHESIS);
6566    
6567                                    for (int i = 0; i < groupIds.length; i++) {
6568                                            query.append(_FINDER_COLUMN_G_CPK_GROUPID_5);
6569    
6570                                            if ((i + 1) < groupIds.length) {
6571                                                    query.append(WHERE_OR);
6572                                            }
6573                                    }
6574    
6575                                    query.append(StringPool.CLOSE_PARENTHESIS);
6576    
6577                                    conjunctionable = true;
6578                            }
6579    
6580                            if (conjunctionable) {
6581                                    query.append(WHERE_AND);
6582                            }
6583    
6584                            query.append(_FINDER_COLUMN_G_CPK_CLASSPK_5);
6585    
6586                            conjunctionable = true;
6587    
6588                            if (orderByComparator != null) {
6589                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6590                                            orderByComparator);
6591                            }
6592                            else
6593                             if (pagination) {
6594                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
6595                            }
6596    
6597                            String sql = query.toString();
6598    
6599                            Session session = null;
6600    
6601                            try {
6602                                    session = openSession();
6603    
6604                                    Query q = session.createQuery(sql);
6605    
6606                                    QueryPos qPos = QueryPos.getInstance(q);
6607    
6608                                    if (groupIds != null) {
6609                                            qPos.add(groupIds);
6610                                    }
6611    
6612                                    qPos.add(classPK);
6613    
6614                                    if (!pagination) {
6615                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
6616                                                            start, end, false);
6617    
6618                                            Collections.sort(list);
6619    
6620                                            list = new UnmodifiableList<DDMTemplate>(list);
6621                                    }
6622                                    else {
6623                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
6624                                                            start, end);
6625                                    }
6626    
6627                                    cacheResult(list);
6628    
6629                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_CPK,
6630                                            finderArgs, list);
6631                            }
6632                            catch (Exception e) {
6633                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_CPK,
6634                                            finderArgs);
6635    
6636                                    throw processException(e);
6637                            }
6638                            finally {
6639                                    closeSession(session);
6640                            }
6641                    }
6642    
6643                    return list;
6644            }
6645    
6646            /**
6647             * Removes all the d d m templates where groupId = &#63; and classPK = &#63; from the database.
6648             *
6649             * @param groupId the group ID
6650             * @param classPK the class p k
6651             * @throws SystemException if a system exception occurred
6652             */
6653            @Override
6654            public void removeByG_CPK(long groupId, long classPK)
6655                    throws SystemException {
6656                    for (DDMTemplate ddmTemplate : findByG_CPK(groupId, classPK,
6657                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6658                            remove(ddmTemplate);
6659                    }
6660            }
6661    
6662            /**
6663             * Returns the number of d d m templates where groupId = &#63; and classPK = &#63;.
6664             *
6665             * @param groupId the group ID
6666             * @param classPK the class p k
6667             * @return the number of matching d d m templates
6668             * @throws SystemException if a system exception occurred
6669             */
6670            @Override
6671            public int countByG_CPK(long groupId, long classPK)
6672                    throws SystemException {
6673                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_CPK;
6674    
6675                    Object[] finderArgs = new Object[] { groupId, classPK };
6676    
6677                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6678                                    this);
6679    
6680                    if (count == null) {
6681                            StringBundler query = new StringBundler(3);
6682    
6683                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
6684    
6685                            query.append(_FINDER_COLUMN_G_CPK_GROUPID_2);
6686    
6687                            query.append(_FINDER_COLUMN_G_CPK_CLASSPK_2);
6688    
6689                            String sql = query.toString();
6690    
6691                            Session session = null;
6692    
6693                            try {
6694                                    session = openSession();
6695    
6696                                    Query q = session.createQuery(sql);
6697    
6698                                    QueryPos qPos = QueryPos.getInstance(q);
6699    
6700                                    qPos.add(groupId);
6701    
6702                                    qPos.add(classPK);
6703    
6704                                    count = (Long)q.uniqueResult();
6705    
6706                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6707                            }
6708                            catch (Exception e) {
6709                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6710    
6711                                    throw processException(e);
6712                            }
6713                            finally {
6714                                    closeSession(session);
6715                            }
6716                    }
6717    
6718                    return count.intValue();
6719            }
6720    
6721            /**
6722             * Returns the number of d d m templates where groupId = any &#63; and classPK = &#63;.
6723             *
6724             * @param groupIds the group IDs
6725             * @param classPK the class p k
6726             * @return the number of matching d d m templates
6727             * @throws SystemException if a system exception occurred
6728             */
6729            @Override
6730            public int countByG_CPK(long[] groupIds, long classPK)
6731                    throws SystemException {
6732                    Object[] finderArgs = new Object[] { StringUtil.merge(groupIds), classPK };
6733    
6734                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_CPK,
6735                                    finderArgs, this);
6736    
6737                    if (count == null) {
6738                            StringBundler query = new StringBundler();
6739    
6740                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
6741    
6742                            boolean conjunctionable = false;
6743    
6744                            if ((groupIds == null) || (groupIds.length > 0)) {
6745                                    if (conjunctionable) {
6746                                            query.append(WHERE_AND);
6747                                    }
6748    
6749                                    query.append(StringPool.OPEN_PARENTHESIS);
6750    
6751                                    for (int i = 0; i < groupIds.length; i++) {
6752                                            query.append(_FINDER_COLUMN_G_CPK_GROUPID_5);
6753    
6754                                            if ((i + 1) < groupIds.length) {
6755                                                    query.append(WHERE_OR);
6756                                            }
6757                                    }
6758    
6759                                    query.append(StringPool.CLOSE_PARENTHESIS);
6760    
6761                                    conjunctionable = true;
6762                            }
6763    
6764                            if (conjunctionable) {
6765                                    query.append(WHERE_AND);
6766                            }
6767    
6768                            query.append(_FINDER_COLUMN_G_CPK_CLASSPK_5);
6769    
6770                            conjunctionable = true;
6771    
6772                            String sql = query.toString();
6773    
6774                            Session session = null;
6775    
6776                            try {
6777                                    session = openSession();
6778    
6779                                    Query q = session.createQuery(sql);
6780    
6781                                    QueryPos qPos = QueryPos.getInstance(q);
6782    
6783                                    if (groupIds != null) {
6784                                            qPos.add(groupIds);
6785                                    }
6786    
6787                                    qPos.add(classPK);
6788    
6789                                    count = (Long)q.uniqueResult();
6790    
6791                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_CPK,
6792                                            finderArgs, count);
6793                            }
6794                            catch (Exception e) {
6795                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_CPK,
6796                                            finderArgs);
6797    
6798                                    throw processException(e);
6799                            }
6800                            finally {
6801                                    closeSession(session);
6802                            }
6803                    }
6804    
6805                    return count.intValue();
6806            }
6807    
6808            /**
6809             * Returns the number of d d m templates that the user has permission to view where groupId = &#63; and classPK = &#63;.
6810             *
6811             * @param groupId the group ID
6812             * @param classPK the class p k
6813             * @return the number of matching d d m templates that the user has permission to view
6814             * @throws SystemException if a system exception occurred
6815             */
6816            @Override
6817            public int filterCountByG_CPK(long groupId, long classPK)
6818                    throws SystemException {
6819                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6820                            return countByG_CPK(groupId, classPK);
6821                    }
6822    
6823                    StringBundler query = new StringBundler(3);
6824    
6825                    query.append(_FILTER_SQL_COUNT_DDMTEMPLATE_WHERE);
6826    
6827                    query.append(_FINDER_COLUMN_G_CPK_GROUPID_2);
6828    
6829                    query.append(_FINDER_COLUMN_G_CPK_CLASSPK_2);
6830    
6831                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6832                                    DDMTemplate.class.getName(),
6833                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6834    
6835                    Session session = null;
6836    
6837                    try {
6838                            session = openSession();
6839    
6840                            SQLQuery q = session.createSQLQuery(sql);
6841    
6842                            q.addScalar(COUNT_COLUMN_NAME,
6843                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6844    
6845                            QueryPos qPos = QueryPos.getInstance(q);
6846    
6847                            qPos.add(groupId);
6848    
6849                            qPos.add(classPK);
6850    
6851                            Long count = (Long)q.uniqueResult();
6852    
6853                            return count.intValue();
6854                    }
6855                    catch (Exception e) {
6856                            throw processException(e);
6857                    }
6858                    finally {
6859                            closeSession(session);
6860                    }
6861            }
6862    
6863            /**
6864             * Returns the number of d d m templates that the user has permission to view where groupId = any &#63; and classPK = &#63;.
6865             *
6866             * @param groupIds the group IDs
6867             * @param classPK the class p k
6868             * @return the number of matching d d m templates that the user has permission to view
6869             * @throws SystemException if a system exception occurred
6870             */
6871            @Override
6872            public int filterCountByG_CPK(long[] groupIds, long classPK)
6873                    throws SystemException {
6874                    if (!InlineSQLHelperUtil.isEnabled(groupIds)) {
6875                            return countByG_CPK(groupIds, classPK);
6876                    }
6877    
6878                    StringBundler query = new StringBundler();
6879    
6880                    query.append(_FILTER_SQL_COUNT_DDMTEMPLATE_WHERE);
6881    
6882                    boolean conjunctionable = false;
6883    
6884                    if ((groupIds == null) || (groupIds.length > 0)) {
6885                            if (conjunctionable) {
6886                                    query.append(WHERE_AND);
6887                            }
6888    
6889                            query.append(StringPool.OPEN_PARENTHESIS);
6890    
6891                            for (int i = 0; i < groupIds.length; i++) {
6892                                    query.append(_FINDER_COLUMN_G_CPK_GROUPID_5);
6893    
6894                                    if ((i + 1) < groupIds.length) {
6895                                            query.append(WHERE_OR);
6896                                    }
6897                            }
6898    
6899                            query.append(StringPool.CLOSE_PARENTHESIS);
6900    
6901                            conjunctionable = true;
6902                    }
6903    
6904                    if (conjunctionable) {
6905                            query.append(WHERE_AND);
6906                    }
6907    
6908                    query.append(_FINDER_COLUMN_G_CPK_CLASSPK_5);
6909    
6910                    conjunctionable = true;
6911    
6912                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6913                                    DDMTemplate.class.getName(),
6914                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupIds);
6915    
6916                    Session session = null;
6917    
6918                    try {
6919                            session = openSession();
6920    
6921                            SQLQuery q = session.createSQLQuery(sql);
6922    
6923                            q.addScalar(COUNT_COLUMN_NAME,
6924                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6925    
6926                            QueryPos qPos = QueryPos.getInstance(q);
6927    
6928                            if (groupIds != null) {
6929                                    qPos.add(groupIds);
6930                            }
6931    
6932                            qPos.add(classPK);
6933    
6934                            Long count = (Long)q.uniqueResult();
6935    
6936                            return count.intValue();
6937                    }
6938                    catch (Exception e) {
6939                            throw processException(e);
6940                    }
6941                    finally {
6942                            closeSession(session);
6943                    }
6944            }
6945    
6946            private static final String _FINDER_COLUMN_G_CPK_GROUPID_2 = "ddmTemplate.groupId = ? AND ";
6947            private static final String _FINDER_COLUMN_G_CPK_GROUPID_5 = "(" +
6948                    removeConjunction(_FINDER_COLUMN_G_CPK_GROUPID_2) + ")";
6949            private static final String _FINDER_COLUMN_G_CPK_CLASSPK_2 = "ddmTemplate.classPK = ?";
6950            private static final String _FINDER_COLUMN_G_CPK_CLASSPK_5 = "(" +
6951                    removeConjunction(_FINDER_COLUMN_G_CPK_CLASSPK_2) + ")";
6952            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
6953                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
6954                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_C",
6955                            new String[] {
6956                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
6957                                    
6958                            Integer.class.getName(), Integer.class.getName(),
6959                                    OrderByComparator.class.getName()
6960                            });
6961            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
6962                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
6963                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_C",
6964                            new String[] {
6965                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
6966                            },
6967                            DDMTemplateModelImpl.GROUPID_COLUMN_BITMASK |
6968                            DDMTemplateModelImpl.CLASSNAMEID_COLUMN_BITMASK |
6969                            DDMTemplateModelImpl.CLASSPK_COLUMN_BITMASK);
6970            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_C = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
6971                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
6972                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_C",
6973                            new String[] {
6974                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
6975                            });
6976    
6977            /**
6978             * Returns all the d d m templates where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
6979             *
6980             * @param groupId the group ID
6981             * @param classNameId the class name ID
6982             * @param classPK the class p k
6983             * @return the matching d d m templates
6984             * @throws SystemException if a system exception occurred
6985             */
6986            @Override
6987            public List<DDMTemplate> findByG_C_C(long groupId, long classNameId,
6988                    long classPK) throws SystemException {
6989                    return findByG_C_C(groupId, classNameId, classPK, QueryUtil.ALL_POS,
6990                            QueryUtil.ALL_POS, null);
6991            }
6992    
6993            /**
6994             * Returns a range of all the d d m templates where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
6995             *
6996             * <p>
6997             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6998             * </p>
6999             *
7000             * @param groupId the group ID
7001             * @param classNameId the class name ID
7002             * @param classPK the class p k
7003             * @param start the lower bound of the range of d d m templates
7004             * @param end the upper bound of the range of d d m templates (not inclusive)
7005             * @return the range of matching d d m templates
7006             * @throws SystemException if a system exception occurred
7007             */
7008            @Override
7009            public List<DDMTemplate> findByG_C_C(long groupId, long classNameId,
7010                    long classPK, int start, int end) throws SystemException {
7011                    return findByG_C_C(groupId, classNameId, classPK, start, end, null);
7012            }
7013    
7014            /**
7015             * Returns an ordered range of all the d d m templates where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
7016             *
7017             * <p>
7018             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7019             * </p>
7020             *
7021             * @param groupId the group ID
7022             * @param classNameId the class name ID
7023             * @param classPK the class p k
7024             * @param start the lower bound of the range of d d m templates
7025             * @param end the upper bound of the range of d d m templates (not inclusive)
7026             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7027             * @return the ordered range of matching d d m templates
7028             * @throws SystemException if a system exception occurred
7029             */
7030            @Override
7031            public List<DDMTemplate> findByG_C_C(long groupId, long classNameId,
7032                    long classPK, int start, int end, OrderByComparator orderByComparator)
7033                    throws SystemException {
7034                    boolean pagination = true;
7035                    FinderPath finderPath = null;
7036                    Object[] finderArgs = null;
7037    
7038                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7039                                    (orderByComparator == null)) {
7040                            pagination = false;
7041                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C;
7042                            finderArgs = new Object[] { groupId, classNameId, classPK };
7043                    }
7044                    else {
7045                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C;
7046                            finderArgs = new Object[] {
7047                                            groupId, classNameId, classPK,
7048                                            
7049                                            start, end, orderByComparator
7050                                    };
7051                    }
7052    
7053                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
7054                                    finderArgs, this);
7055    
7056                    if ((list != null) && !list.isEmpty()) {
7057                            for (DDMTemplate ddmTemplate : list) {
7058                                    if ((groupId != ddmTemplate.getGroupId()) ||
7059                                                    (classNameId != ddmTemplate.getClassNameId()) ||
7060                                                    (classPK != ddmTemplate.getClassPK())) {
7061                                            list = null;
7062    
7063                                            break;
7064                                    }
7065                            }
7066                    }
7067    
7068                    if (list == null) {
7069                            StringBundler query = null;
7070    
7071                            if (orderByComparator != null) {
7072                                    query = new StringBundler(5 +
7073                                                    (orderByComparator.getOrderByFields().length * 3));
7074                            }
7075                            else {
7076                                    query = new StringBundler(5);
7077                            }
7078    
7079                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
7080    
7081                            query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
7082    
7083                            query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
7084    
7085                            query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
7086    
7087                            if (orderByComparator != null) {
7088                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7089                                            orderByComparator);
7090                            }
7091                            else
7092                             if (pagination) {
7093                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
7094                            }
7095    
7096                            String sql = query.toString();
7097    
7098                            Session session = null;
7099    
7100                            try {
7101                                    session = openSession();
7102    
7103                                    Query q = session.createQuery(sql);
7104    
7105                                    QueryPos qPos = QueryPos.getInstance(q);
7106    
7107                                    qPos.add(groupId);
7108    
7109                                    qPos.add(classNameId);
7110    
7111                                    qPos.add(classPK);
7112    
7113                                    if (!pagination) {
7114                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
7115                                                            start, end, false);
7116    
7117                                            Collections.sort(list);
7118    
7119                                            list = new UnmodifiableList<DDMTemplate>(list);
7120                                    }
7121                                    else {
7122                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
7123                                                            start, end);
7124                                    }
7125    
7126                                    cacheResult(list);
7127    
7128                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7129                            }
7130                            catch (Exception e) {
7131                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7132    
7133                                    throw processException(e);
7134                            }
7135                            finally {
7136                                    closeSession(session);
7137                            }
7138                    }
7139    
7140                    return list;
7141            }
7142    
7143            /**
7144             * Returns the first d d m template in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
7145             *
7146             * @param groupId the group ID
7147             * @param classNameId the class name ID
7148             * @param classPK the class p k
7149             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7150             * @return the first matching d d m template
7151             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
7152             * @throws SystemException if a system exception occurred
7153             */
7154            @Override
7155            public DDMTemplate findByG_C_C_First(long groupId, long classNameId,
7156                    long classPK, OrderByComparator orderByComparator)
7157                    throws NoSuchTemplateException, SystemException {
7158                    DDMTemplate ddmTemplate = fetchByG_C_C_First(groupId, classNameId,
7159                                    classPK, orderByComparator);
7160    
7161                    if (ddmTemplate != null) {
7162                            return ddmTemplate;
7163                    }
7164    
7165                    StringBundler msg = new StringBundler(8);
7166    
7167                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7168    
7169                    msg.append("groupId=");
7170                    msg.append(groupId);
7171    
7172                    msg.append(", classNameId=");
7173                    msg.append(classNameId);
7174    
7175                    msg.append(", classPK=");
7176                    msg.append(classPK);
7177    
7178                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7179    
7180                    throw new NoSuchTemplateException(msg.toString());
7181            }
7182    
7183            /**
7184             * Returns the first d d m template in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
7185             *
7186             * @param groupId the group ID
7187             * @param classNameId the class name ID
7188             * @param classPK the class p k
7189             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7190             * @return the first matching d d m template, or <code>null</code> if a matching d d m template could not be found
7191             * @throws SystemException if a system exception occurred
7192             */
7193            @Override
7194            public DDMTemplate fetchByG_C_C_First(long groupId, long classNameId,
7195                    long classPK, OrderByComparator orderByComparator)
7196                    throws SystemException {
7197                    List<DDMTemplate> list = findByG_C_C(groupId, classNameId, classPK, 0,
7198                                    1, orderByComparator);
7199    
7200                    if (!list.isEmpty()) {
7201                            return list.get(0);
7202                    }
7203    
7204                    return null;
7205            }
7206    
7207            /**
7208             * Returns the last d d m template in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
7209             *
7210             * @param groupId the group ID
7211             * @param classNameId the class name ID
7212             * @param classPK the class p k
7213             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7214             * @return the last matching d d m template
7215             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
7216             * @throws SystemException if a system exception occurred
7217             */
7218            @Override
7219            public DDMTemplate findByG_C_C_Last(long groupId, long classNameId,
7220                    long classPK, OrderByComparator orderByComparator)
7221                    throws NoSuchTemplateException, SystemException {
7222                    DDMTemplate ddmTemplate = fetchByG_C_C_Last(groupId, classNameId,
7223                                    classPK, orderByComparator);
7224    
7225                    if (ddmTemplate != null) {
7226                            return ddmTemplate;
7227                    }
7228    
7229                    StringBundler msg = new StringBundler(8);
7230    
7231                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7232    
7233                    msg.append("groupId=");
7234                    msg.append(groupId);
7235    
7236                    msg.append(", classNameId=");
7237                    msg.append(classNameId);
7238    
7239                    msg.append(", classPK=");
7240                    msg.append(classPK);
7241    
7242                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7243    
7244                    throw new NoSuchTemplateException(msg.toString());
7245            }
7246    
7247            /**
7248             * Returns the last d d m template in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
7249             *
7250             * @param groupId the group ID
7251             * @param classNameId the class name ID
7252             * @param classPK the class p k
7253             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7254             * @return the last matching d d m template, or <code>null</code> if a matching d d m template could not be found
7255             * @throws SystemException if a system exception occurred
7256             */
7257            @Override
7258            public DDMTemplate fetchByG_C_C_Last(long groupId, long classNameId,
7259                    long classPK, OrderByComparator orderByComparator)
7260                    throws SystemException {
7261                    int count = countByG_C_C(groupId, classNameId, classPK);
7262    
7263                    if (count == 0) {
7264                            return null;
7265                    }
7266    
7267                    List<DDMTemplate> list = findByG_C_C(groupId, classNameId, classPK,
7268                                    count - 1, count, orderByComparator);
7269    
7270                    if (!list.isEmpty()) {
7271                            return list.get(0);
7272                    }
7273    
7274                    return null;
7275            }
7276    
7277            /**
7278             * Returns the d d m templates before and after the current d d m template in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
7279             *
7280             * @param templateId the primary key of the current d d m template
7281             * @param groupId the group ID
7282             * @param classNameId the class name ID
7283             * @param classPK the class p k
7284             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7285             * @return the previous, current, and next d d m template
7286             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
7287             * @throws SystemException if a system exception occurred
7288             */
7289            @Override
7290            public DDMTemplate[] findByG_C_C_PrevAndNext(long templateId, long groupId,
7291                    long classNameId, long classPK, OrderByComparator orderByComparator)
7292                    throws NoSuchTemplateException, SystemException {
7293                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
7294    
7295                    Session session = null;
7296    
7297                    try {
7298                            session = openSession();
7299    
7300                            DDMTemplate[] array = new DDMTemplateImpl[3];
7301    
7302                            array[0] = getByG_C_C_PrevAndNext(session, ddmTemplate, groupId,
7303                                            classNameId, classPK, orderByComparator, true);
7304    
7305                            array[1] = ddmTemplate;
7306    
7307                            array[2] = getByG_C_C_PrevAndNext(session, ddmTemplate, groupId,
7308                                            classNameId, classPK, orderByComparator, false);
7309    
7310                            return array;
7311                    }
7312                    catch (Exception e) {
7313                            throw processException(e);
7314                    }
7315                    finally {
7316                            closeSession(session);
7317                    }
7318            }
7319    
7320            protected DDMTemplate getByG_C_C_PrevAndNext(Session session,
7321                    DDMTemplate ddmTemplate, long groupId, long classNameId, long classPK,
7322                    OrderByComparator orderByComparator, boolean previous) {
7323                    StringBundler query = null;
7324    
7325                    if (orderByComparator != null) {
7326                            query = new StringBundler(6 +
7327                                            (orderByComparator.getOrderByFields().length * 6));
7328                    }
7329                    else {
7330                            query = new StringBundler(3);
7331                    }
7332    
7333                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
7334    
7335                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
7336    
7337                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
7338    
7339                    query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
7340    
7341                    if (orderByComparator != null) {
7342                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7343    
7344                            if (orderByConditionFields.length > 0) {
7345                                    query.append(WHERE_AND);
7346                            }
7347    
7348                            for (int i = 0; i < orderByConditionFields.length; i++) {
7349                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7350                                    query.append(orderByConditionFields[i]);
7351    
7352                                    if ((i + 1) < orderByConditionFields.length) {
7353                                            if (orderByComparator.isAscending() ^ previous) {
7354                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7355                                            }
7356                                            else {
7357                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7358                                            }
7359                                    }
7360                                    else {
7361                                            if (orderByComparator.isAscending() ^ previous) {
7362                                                    query.append(WHERE_GREATER_THAN);
7363                                            }
7364                                            else {
7365                                                    query.append(WHERE_LESSER_THAN);
7366                                            }
7367                                    }
7368                            }
7369    
7370                            query.append(ORDER_BY_CLAUSE);
7371    
7372                            String[] orderByFields = orderByComparator.getOrderByFields();
7373    
7374                            for (int i = 0; i < orderByFields.length; i++) {
7375                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7376                                    query.append(orderByFields[i]);
7377    
7378                                    if ((i + 1) < orderByFields.length) {
7379                                            if (orderByComparator.isAscending() ^ previous) {
7380                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7381                                            }
7382                                            else {
7383                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7384                                            }
7385                                    }
7386                                    else {
7387                                            if (orderByComparator.isAscending() ^ previous) {
7388                                                    query.append(ORDER_BY_ASC);
7389                                            }
7390                                            else {
7391                                                    query.append(ORDER_BY_DESC);
7392                                            }
7393                                    }
7394                            }
7395                    }
7396                    else {
7397                            query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
7398                    }
7399    
7400                    String sql = query.toString();
7401    
7402                    Query q = session.createQuery(sql);
7403    
7404                    q.setFirstResult(0);
7405                    q.setMaxResults(2);
7406    
7407                    QueryPos qPos = QueryPos.getInstance(q);
7408    
7409                    qPos.add(groupId);
7410    
7411                    qPos.add(classNameId);
7412    
7413                    qPos.add(classPK);
7414    
7415                    if (orderByComparator != null) {
7416                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
7417    
7418                            for (Object value : values) {
7419                                    qPos.add(value);
7420                            }
7421                    }
7422    
7423                    List<DDMTemplate> list = q.list();
7424    
7425                    if (list.size() == 2) {
7426                            return list.get(1);
7427                    }
7428                    else {
7429                            return null;
7430                    }
7431            }
7432    
7433            /**
7434             * Returns all the d d m templates that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
7435             *
7436             * @param groupId the group ID
7437             * @param classNameId the class name ID
7438             * @param classPK the class p k
7439             * @return the matching d d m templates that the user has permission to view
7440             * @throws SystemException if a system exception occurred
7441             */
7442            @Override
7443            public List<DDMTemplate> filterFindByG_C_C(long groupId, long classNameId,
7444                    long classPK) throws SystemException {
7445                    return filterFindByG_C_C(groupId, classNameId, classPK,
7446                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7447            }
7448    
7449            /**
7450             * Returns a range of all the d d m templates that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
7451             *
7452             * <p>
7453             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7454             * </p>
7455             *
7456             * @param groupId the group ID
7457             * @param classNameId the class name ID
7458             * @param classPK the class p k
7459             * @param start the lower bound of the range of d d m templates
7460             * @param end the upper bound of the range of d d m templates (not inclusive)
7461             * @return the range of matching d d m templates that the user has permission to view
7462             * @throws SystemException if a system exception occurred
7463             */
7464            @Override
7465            public List<DDMTemplate> filterFindByG_C_C(long groupId, long classNameId,
7466                    long classPK, int start, int end) throws SystemException {
7467                    return filterFindByG_C_C(groupId, classNameId, classPK, start, end, null);
7468            }
7469    
7470            /**
7471             * Returns an ordered range of all the d d m templates that the user has permissions to view where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
7472             *
7473             * <p>
7474             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7475             * </p>
7476             *
7477             * @param groupId the group ID
7478             * @param classNameId the class name ID
7479             * @param classPK the class p k
7480             * @param start the lower bound of the range of d d m templates
7481             * @param end the upper bound of the range of d d m templates (not inclusive)
7482             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7483             * @return the ordered range of matching d d m templates that the user has permission to view
7484             * @throws SystemException if a system exception occurred
7485             */
7486            @Override
7487            public List<DDMTemplate> filterFindByG_C_C(long groupId, long classNameId,
7488                    long classPK, int start, int end, OrderByComparator orderByComparator)
7489                    throws SystemException {
7490                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7491                            return findByG_C_C(groupId, classNameId, classPK, start, end,
7492                                    orderByComparator);
7493                    }
7494    
7495                    StringBundler query = null;
7496    
7497                    if (orderByComparator != null) {
7498                            query = new StringBundler(5 +
7499                                            (orderByComparator.getOrderByFields().length * 3));
7500                    }
7501                    else {
7502                            query = new StringBundler(5);
7503                    }
7504    
7505                    if (getDB().isSupportsInlineDistinct()) {
7506                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_WHERE);
7507                    }
7508                    else {
7509                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
7510                    }
7511    
7512                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
7513    
7514                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
7515    
7516                    query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
7517    
7518                    if (!getDB().isSupportsInlineDistinct()) {
7519                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
7520                    }
7521    
7522                    if (orderByComparator != null) {
7523                            if (getDB().isSupportsInlineDistinct()) {
7524                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7525                                            orderByComparator, true);
7526                            }
7527                            else {
7528                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7529                                            orderByComparator, true);
7530                            }
7531                    }
7532                    else {
7533                            if (getDB().isSupportsInlineDistinct()) {
7534                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
7535                            }
7536                            else {
7537                                    query.append(DDMTemplateModelImpl.ORDER_BY_SQL);
7538                            }
7539                    }
7540    
7541                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7542                                    DDMTemplate.class.getName(),
7543                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7544    
7545                    Session session = null;
7546    
7547                    try {
7548                            session = openSession();
7549    
7550                            SQLQuery q = session.createSQLQuery(sql);
7551    
7552                            if (getDB().isSupportsInlineDistinct()) {
7553                                    q.addEntity(_FILTER_ENTITY_ALIAS, DDMTemplateImpl.class);
7554                            }
7555                            else {
7556                                    q.addEntity(_FILTER_ENTITY_TABLE, DDMTemplateImpl.class);
7557                            }
7558    
7559                            QueryPos qPos = QueryPos.getInstance(q);
7560    
7561                            qPos.add(groupId);
7562    
7563                            qPos.add(classNameId);
7564    
7565                            qPos.add(classPK);
7566    
7567                            return (List<DDMTemplate>)QueryUtil.list(q, getDialect(), start, end);
7568                    }
7569                    catch (Exception e) {
7570                            throw processException(e);
7571                    }
7572                    finally {
7573                            closeSession(session);
7574                    }
7575            }
7576    
7577            /**
7578             * Returns the d d m templates before and after the current d d m template in the ordered set of d d m templates that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
7579             *
7580             * @param templateId the primary key of the current d d m template
7581             * @param groupId the group ID
7582             * @param classNameId the class name ID
7583             * @param classPK the class p k
7584             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7585             * @return the previous, current, and next d d m template
7586             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
7587             * @throws SystemException if a system exception occurred
7588             */
7589            @Override
7590            public DDMTemplate[] filterFindByG_C_C_PrevAndNext(long templateId,
7591                    long groupId, long classNameId, long classPK,
7592                    OrderByComparator orderByComparator)
7593                    throws NoSuchTemplateException, SystemException {
7594                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7595                            return findByG_C_C_PrevAndNext(templateId, groupId, classNameId,
7596                                    classPK, orderByComparator);
7597                    }
7598    
7599                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
7600    
7601                    Session session = null;
7602    
7603                    try {
7604                            session = openSession();
7605    
7606                            DDMTemplate[] array = new DDMTemplateImpl[3];
7607    
7608                            array[0] = filterGetByG_C_C_PrevAndNext(session, ddmTemplate,
7609                                            groupId, classNameId, classPK, orderByComparator, true);
7610    
7611                            array[1] = ddmTemplate;
7612    
7613                            array[2] = filterGetByG_C_C_PrevAndNext(session, ddmTemplate,
7614                                            groupId, classNameId, classPK, orderByComparator, false);
7615    
7616                            return array;
7617                    }
7618                    catch (Exception e) {
7619                            throw processException(e);
7620                    }
7621                    finally {
7622                            closeSession(session);
7623                    }
7624            }
7625    
7626            protected DDMTemplate filterGetByG_C_C_PrevAndNext(Session session,
7627                    DDMTemplate ddmTemplate, long groupId, long classNameId, long classPK,
7628                    OrderByComparator orderByComparator, boolean previous) {
7629                    StringBundler query = null;
7630    
7631                    if (orderByComparator != null) {
7632                            query = new StringBundler(6 +
7633                                            (orderByComparator.getOrderByFields().length * 6));
7634                    }
7635                    else {
7636                            query = new StringBundler(3);
7637                    }
7638    
7639                    if (getDB().isSupportsInlineDistinct()) {
7640                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_WHERE);
7641                    }
7642                    else {
7643                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
7644                    }
7645    
7646                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
7647    
7648                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
7649    
7650                    query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
7651    
7652                    if (!getDB().isSupportsInlineDistinct()) {
7653                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
7654                    }
7655    
7656                    if (orderByComparator != null) {
7657                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7658    
7659                            if (orderByConditionFields.length > 0) {
7660                                    query.append(WHERE_AND);
7661                            }
7662    
7663                            for (int i = 0; i < orderByConditionFields.length; i++) {
7664                                    if (getDB().isSupportsInlineDistinct()) {
7665                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7666                                    }
7667                                    else {
7668                                            query.append(_ORDER_BY_ENTITY_TABLE);
7669                                    }
7670    
7671                                    query.append(orderByConditionFields[i]);
7672    
7673                                    if ((i + 1) < orderByConditionFields.length) {
7674                                            if (orderByComparator.isAscending() ^ previous) {
7675                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7676                                            }
7677                                            else {
7678                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7679                                            }
7680                                    }
7681                                    else {
7682                                            if (orderByComparator.isAscending() ^ previous) {
7683                                                    query.append(WHERE_GREATER_THAN);
7684                                            }
7685                                            else {
7686                                                    query.append(WHERE_LESSER_THAN);
7687                                            }
7688                                    }
7689                            }
7690    
7691                            query.append(ORDER_BY_CLAUSE);
7692    
7693                            String[] orderByFields = orderByComparator.getOrderByFields();
7694    
7695                            for (int i = 0; i < orderByFields.length; i++) {
7696                                    if (getDB().isSupportsInlineDistinct()) {
7697                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7698                                    }
7699                                    else {
7700                                            query.append(_ORDER_BY_ENTITY_TABLE);
7701                                    }
7702    
7703                                    query.append(orderByFields[i]);
7704    
7705                                    if ((i + 1) < orderByFields.length) {
7706                                            if (orderByComparator.isAscending() ^ previous) {
7707                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7708                                            }
7709                                            else {
7710                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7711                                            }
7712                                    }
7713                                    else {
7714                                            if (orderByComparator.isAscending() ^ previous) {
7715                                                    query.append(ORDER_BY_ASC);
7716                                            }
7717                                            else {
7718                                                    query.append(ORDER_BY_DESC);
7719                                            }
7720                                    }
7721                            }
7722                    }
7723                    else {
7724                            if (getDB().isSupportsInlineDistinct()) {
7725                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
7726                            }
7727                            else {
7728                                    query.append(DDMTemplateModelImpl.ORDER_BY_SQL);
7729                            }
7730                    }
7731    
7732                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7733                                    DDMTemplate.class.getName(),
7734                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7735    
7736                    SQLQuery q = session.createSQLQuery(sql);
7737    
7738                    q.setFirstResult(0);
7739                    q.setMaxResults(2);
7740    
7741                    if (getDB().isSupportsInlineDistinct()) {
7742                            q.addEntity(_FILTER_ENTITY_ALIAS, DDMTemplateImpl.class);
7743                    }
7744                    else {
7745                            q.addEntity(_FILTER_ENTITY_TABLE, DDMTemplateImpl.class);
7746                    }
7747    
7748                    QueryPos qPos = QueryPos.getInstance(q);
7749    
7750                    qPos.add(groupId);
7751    
7752                    qPos.add(classNameId);
7753    
7754                    qPos.add(classPK);
7755    
7756                    if (orderByComparator != null) {
7757                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
7758    
7759                            for (Object value : values) {
7760                                    qPos.add(value);
7761                            }
7762                    }
7763    
7764                    List<DDMTemplate> list = q.list();
7765    
7766                    if (list.size() == 2) {
7767                            return list.get(1);
7768                    }
7769                    else {
7770                            return null;
7771                    }
7772            }
7773    
7774            /**
7775             * Removes all the d d m templates where groupId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
7776             *
7777             * @param groupId the group ID
7778             * @param classNameId the class name ID
7779             * @param classPK the class p k
7780             * @throws SystemException if a system exception occurred
7781             */
7782            @Override
7783            public void removeByG_C_C(long groupId, long classNameId, long classPK)
7784                    throws SystemException {
7785                    for (DDMTemplate ddmTemplate : findByG_C_C(groupId, classNameId,
7786                                    classPK, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7787                            remove(ddmTemplate);
7788                    }
7789            }
7790    
7791            /**
7792             * Returns the number of d d m templates where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
7793             *
7794             * @param groupId the group ID
7795             * @param classNameId the class name ID
7796             * @param classPK the class p k
7797             * @return the number of matching d d m templates
7798             * @throws SystemException if a system exception occurred
7799             */
7800            @Override
7801            public int countByG_C_C(long groupId, long classNameId, long classPK)
7802                    throws SystemException {
7803                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_C;
7804    
7805                    Object[] finderArgs = new Object[] { groupId, classNameId, classPK };
7806    
7807                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7808                                    this);
7809    
7810                    if (count == null) {
7811                            StringBundler query = new StringBundler(4);
7812    
7813                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
7814    
7815                            query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
7816    
7817                            query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
7818    
7819                            query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
7820    
7821                            String sql = query.toString();
7822    
7823                            Session session = null;
7824    
7825                            try {
7826                                    session = openSession();
7827    
7828                                    Query q = session.createQuery(sql);
7829    
7830                                    QueryPos qPos = QueryPos.getInstance(q);
7831    
7832                                    qPos.add(groupId);
7833    
7834                                    qPos.add(classNameId);
7835    
7836                                    qPos.add(classPK);
7837    
7838                                    count = (Long)q.uniqueResult();
7839    
7840                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7841                            }
7842                            catch (Exception e) {
7843                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7844    
7845                                    throw processException(e);
7846                            }
7847                            finally {
7848                                    closeSession(session);
7849                            }
7850                    }
7851    
7852                    return count.intValue();
7853            }
7854    
7855            /**
7856             * Returns the number of d d m templates that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
7857             *
7858             * @param groupId the group ID
7859             * @param classNameId the class name ID
7860             * @param classPK the class p k
7861             * @return the number of matching d d m templates that the user has permission to view
7862             * @throws SystemException if a system exception occurred
7863             */
7864            @Override
7865            public int filterCountByG_C_C(long groupId, long classNameId, long classPK)
7866                    throws SystemException {
7867                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7868                            return countByG_C_C(groupId, classNameId, classPK);
7869                    }
7870    
7871                    StringBundler query = new StringBundler(4);
7872    
7873                    query.append(_FILTER_SQL_COUNT_DDMTEMPLATE_WHERE);
7874    
7875                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
7876    
7877                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
7878    
7879                    query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
7880    
7881                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7882                                    DDMTemplate.class.getName(),
7883                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7884    
7885                    Session session = null;
7886    
7887                    try {
7888                            session = openSession();
7889    
7890                            SQLQuery q = session.createSQLQuery(sql);
7891    
7892                            q.addScalar(COUNT_COLUMN_NAME,
7893                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7894    
7895                            QueryPos qPos = QueryPos.getInstance(q);
7896    
7897                            qPos.add(groupId);
7898    
7899                            qPos.add(classNameId);
7900    
7901                            qPos.add(classPK);
7902    
7903                            Long count = (Long)q.uniqueResult();
7904    
7905                            return count.intValue();
7906                    }
7907                    catch (Exception e) {
7908                            throw processException(e);
7909                    }
7910                    finally {
7911                            closeSession(session);
7912                    }
7913            }
7914    
7915            private static final String _FINDER_COLUMN_G_C_C_GROUPID_2 = "ddmTemplate.groupId = ? AND ";
7916            private static final String _FINDER_COLUMN_G_C_C_CLASSNAMEID_2 = "ddmTemplate.classNameId = ? AND ";
7917            private static final String _FINDER_COLUMN_G_C_C_CLASSPK_2 = "ddmTemplate.classPK = ?";
7918            public static final FinderPath FINDER_PATH_FETCH_BY_G_C_T = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
7919                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
7920                            FINDER_CLASS_NAME_ENTITY, "fetchByG_C_T",
7921                            new String[] {
7922                                    Long.class.getName(), Long.class.getName(),
7923                                    String.class.getName()
7924                            },
7925                            DDMTemplateModelImpl.GROUPID_COLUMN_BITMASK |
7926                            DDMTemplateModelImpl.CLASSNAMEID_COLUMN_BITMASK |
7927                            DDMTemplateModelImpl.TEMPLATEKEY_COLUMN_BITMASK);
7928            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
7929                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
7930                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T",
7931                            new String[] {
7932                                    Long.class.getName(), Long.class.getName(),
7933                                    String.class.getName()
7934                            });
7935    
7936            /**
7937             * Returns the d d m template where groupId = &#63; and classNameId = &#63; and templateKey = &#63; or throws a {@link com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException} if it could not be found.
7938             *
7939             * @param groupId the group ID
7940             * @param classNameId the class name ID
7941             * @param templateKey the template key
7942             * @return the matching d d m template
7943             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
7944             * @throws SystemException if a system exception occurred
7945             */
7946            @Override
7947            public DDMTemplate findByG_C_T(long groupId, long classNameId,
7948                    String templateKey) throws NoSuchTemplateException, SystemException {
7949                    DDMTemplate ddmTemplate = fetchByG_C_T(groupId, classNameId, templateKey);
7950    
7951                    if (ddmTemplate == null) {
7952                            StringBundler msg = new StringBundler(8);
7953    
7954                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7955    
7956                            msg.append("groupId=");
7957                            msg.append(groupId);
7958    
7959                            msg.append(", classNameId=");
7960                            msg.append(classNameId);
7961    
7962                            msg.append(", templateKey=");
7963                            msg.append(templateKey);
7964    
7965                            msg.append(StringPool.CLOSE_CURLY_BRACE);
7966    
7967                            if (_log.isWarnEnabled()) {
7968                                    _log.warn(msg.toString());
7969                            }
7970    
7971                            throw new NoSuchTemplateException(msg.toString());
7972                    }
7973    
7974                    return ddmTemplate;
7975            }
7976    
7977            /**
7978             * Returns the d d m template where groupId = &#63; and classNameId = &#63; and templateKey = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
7979             *
7980             * @param groupId the group ID
7981             * @param classNameId the class name ID
7982             * @param templateKey the template key
7983             * @return the matching d d m template, or <code>null</code> if a matching d d m template could not be found
7984             * @throws SystemException if a system exception occurred
7985             */
7986            @Override
7987            public DDMTemplate fetchByG_C_T(long groupId, long classNameId,
7988                    String templateKey) throws SystemException {
7989                    return fetchByG_C_T(groupId, classNameId, templateKey, true);
7990            }
7991    
7992            /**
7993             * Returns the d d m template where groupId = &#63; and classNameId = &#63; and templateKey = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
7994             *
7995             * @param groupId the group ID
7996             * @param classNameId the class name ID
7997             * @param templateKey the template key
7998             * @param retrieveFromCache whether to use the finder cache
7999             * @return the matching d d m template, or <code>null</code> if a matching d d m template could not be found
8000             * @throws SystemException if a system exception occurred
8001             */
8002            @Override
8003            public DDMTemplate fetchByG_C_T(long groupId, long classNameId,
8004                    String templateKey, boolean retrieveFromCache)
8005                    throws SystemException {
8006                    Object[] finderArgs = new Object[] { groupId, classNameId, templateKey };
8007    
8008                    Object result = null;
8009    
8010                    if (retrieveFromCache) {
8011                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_C_T,
8012                                            finderArgs, this);
8013                    }
8014    
8015                    if (result instanceof DDMTemplate) {
8016                            DDMTemplate ddmTemplate = (DDMTemplate)result;
8017    
8018                            if ((groupId != ddmTemplate.getGroupId()) ||
8019                                            (classNameId != ddmTemplate.getClassNameId()) ||
8020                                            !Validator.equals(templateKey, ddmTemplate.getTemplateKey())) {
8021                                    result = null;
8022                            }
8023                    }
8024    
8025                    if (result == null) {
8026                            StringBundler query = new StringBundler(5);
8027    
8028                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
8029    
8030                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
8031    
8032                            query.append(_FINDER_COLUMN_G_C_T_CLASSNAMEID_2);
8033    
8034                            boolean bindTemplateKey = false;
8035    
8036                            if (templateKey == null) {
8037                                    query.append(_FINDER_COLUMN_G_C_T_TEMPLATEKEY_1);
8038                            }
8039                            else if (templateKey.equals(StringPool.BLANK)) {
8040                                    query.append(_FINDER_COLUMN_G_C_T_TEMPLATEKEY_3);
8041                            }
8042                            else {
8043                                    bindTemplateKey = true;
8044    
8045                                    query.append(_FINDER_COLUMN_G_C_T_TEMPLATEKEY_2);
8046                            }
8047    
8048                            String sql = query.toString();
8049    
8050                            Session session = null;
8051    
8052                            try {
8053                                    session = openSession();
8054    
8055                                    Query q = session.createQuery(sql);
8056    
8057                                    QueryPos qPos = QueryPos.getInstance(q);
8058    
8059                                    qPos.add(groupId);
8060    
8061                                    qPos.add(classNameId);
8062    
8063                                    if (bindTemplateKey) {
8064                                            qPos.add(templateKey);
8065                                    }
8066    
8067                                    List<DDMTemplate> list = q.list();
8068    
8069                                    if (list.isEmpty()) {
8070                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_T,
8071                                                    finderArgs, list);
8072                                    }
8073                                    else {
8074                                            DDMTemplate ddmTemplate = list.get(0);
8075    
8076                                            result = ddmTemplate;
8077    
8078                                            cacheResult(ddmTemplate);
8079    
8080                                            if ((ddmTemplate.getGroupId() != groupId) ||
8081                                                            (ddmTemplate.getClassNameId() != classNameId) ||
8082                                                            (ddmTemplate.getTemplateKey() == null) ||
8083                                                            !ddmTemplate.getTemplateKey().equals(templateKey)) {
8084                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_T,
8085                                                            finderArgs, ddmTemplate);
8086                                            }
8087                                    }
8088                            }
8089                            catch (Exception e) {
8090                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_T,
8091                                            finderArgs);
8092    
8093                                    throw processException(e);
8094                            }
8095                            finally {
8096                                    closeSession(session);
8097                            }
8098                    }
8099    
8100                    if (result instanceof List<?>) {
8101                            return null;
8102                    }
8103                    else {
8104                            return (DDMTemplate)result;
8105                    }
8106            }
8107    
8108            /**
8109             * Removes the d d m template where groupId = &#63; and classNameId = &#63; and templateKey = &#63; from the database.
8110             *
8111             * @param groupId the group ID
8112             * @param classNameId the class name ID
8113             * @param templateKey the template key
8114             * @return the d d m template that was removed
8115             * @throws SystemException if a system exception occurred
8116             */
8117            @Override
8118            public DDMTemplate removeByG_C_T(long groupId, long classNameId,
8119                    String templateKey) throws NoSuchTemplateException, SystemException {
8120                    DDMTemplate ddmTemplate = findByG_C_T(groupId, classNameId, templateKey);
8121    
8122                    return remove(ddmTemplate);
8123            }
8124    
8125            /**
8126             * Returns the number of d d m templates where groupId = &#63; and classNameId = &#63; and templateKey = &#63;.
8127             *
8128             * @param groupId the group ID
8129             * @param classNameId the class name ID
8130             * @param templateKey the template key
8131             * @return the number of matching d d m templates
8132             * @throws SystemException if a system exception occurred
8133             */
8134            @Override
8135            public int countByG_C_T(long groupId, long classNameId, String templateKey)
8136                    throws SystemException {
8137                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T;
8138    
8139                    Object[] finderArgs = new Object[] { groupId, classNameId, templateKey };
8140    
8141                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8142                                    this);
8143    
8144                    if (count == null) {
8145                            StringBundler query = new StringBundler(4);
8146    
8147                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
8148    
8149                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
8150    
8151                            query.append(_FINDER_COLUMN_G_C_T_CLASSNAMEID_2);
8152    
8153                            boolean bindTemplateKey = false;
8154    
8155                            if (templateKey == null) {
8156                                    query.append(_FINDER_COLUMN_G_C_T_TEMPLATEKEY_1);
8157                            }
8158                            else if (templateKey.equals(StringPool.BLANK)) {
8159                                    query.append(_FINDER_COLUMN_G_C_T_TEMPLATEKEY_3);
8160                            }
8161                            else {
8162                                    bindTemplateKey = true;
8163    
8164                                    query.append(_FINDER_COLUMN_G_C_T_TEMPLATEKEY_2);
8165                            }
8166    
8167                            String sql = query.toString();
8168    
8169                            Session session = null;
8170    
8171                            try {
8172                                    session = openSession();
8173    
8174                                    Query q = session.createQuery(sql);
8175    
8176                                    QueryPos qPos = QueryPos.getInstance(q);
8177    
8178                                    qPos.add(groupId);
8179    
8180                                    qPos.add(classNameId);
8181    
8182                                    if (bindTemplateKey) {
8183                                            qPos.add(templateKey);
8184                                    }
8185    
8186                                    count = (Long)q.uniqueResult();
8187    
8188                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8189                            }
8190                            catch (Exception e) {
8191                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8192    
8193                                    throw processException(e);
8194                            }
8195                            finally {
8196                                    closeSession(session);
8197                            }
8198                    }
8199    
8200                    return count.intValue();
8201            }
8202    
8203            private static final String _FINDER_COLUMN_G_C_T_GROUPID_2 = "ddmTemplate.groupId = ? AND ";
8204            private static final String _FINDER_COLUMN_G_C_T_CLASSNAMEID_2 = "ddmTemplate.classNameId = ? AND ";
8205            private static final String _FINDER_COLUMN_G_C_T_TEMPLATEKEY_1 = "ddmTemplate.templateKey IS NULL";
8206            private static final String _FINDER_COLUMN_G_C_T_TEMPLATEKEY_2 = "ddmTemplate.templateKey = ?";
8207            private static final String _FINDER_COLUMN_G_C_T_TEMPLATEKEY_3 = "(ddmTemplate.templateKey IS NULL OR ddmTemplate.templateKey = '')";
8208            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_T = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
8209                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
8210                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_T",
8211                            new String[] {
8212                                    Long.class.getName(), Long.class.getName(),
8213                                    String.class.getName(),
8214                                    
8215                            Integer.class.getName(), Integer.class.getName(),
8216                                    OrderByComparator.class.getName()
8217                            });
8218            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
8219                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
8220                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_T",
8221                            new String[] {
8222                                    Long.class.getName(), Long.class.getName(),
8223                                    String.class.getName()
8224                            },
8225                            DDMTemplateModelImpl.CLASSNAMEID_COLUMN_BITMASK |
8226                            DDMTemplateModelImpl.CLASSPK_COLUMN_BITMASK |
8227                            DDMTemplateModelImpl.TYPE_COLUMN_BITMASK);
8228            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_T = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
8229                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
8230                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_T",
8231                            new String[] {
8232                                    Long.class.getName(), Long.class.getName(),
8233                                    String.class.getName()
8234                            });
8235    
8236            /**
8237             * Returns all the d d m templates where classNameId = &#63; and classPK = &#63; and type = &#63;.
8238             *
8239             * @param classNameId the class name ID
8240             * @param classPK the class p k
8241             * @param type the type
8242             * @return the matching d d m templates
8243             * @throws SystemException if a system exception occurred
8244             */
8245            @Override
8246            public List<DDMTemplate> findByC_C_T(long classNameId, long classPK,
8247                    String type) throws SystemException {
8248                    return findByC_C_T(classNameId, classPK, type, QueryUtil.ALL_POS,
8249                            QueryUtil.ALL_POS, null);
8250            }
8251    
8252            /**
8253             * Returns a range of all the d d m templates where classNameId = &#63; and classPK = &#63; and type = &#63;.
8254             *
8255             * <p>
8256             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8257             * </p>
8258             *
8259             * @param classNameId the class name ID
8260             * @param classPK the class p k
8261             * @param type the type
8262             * @param start the lower bound of the range of d d m templates
8263             * @param end the upper bound of the range of d d m templates (not inclusive)
8264             * @return the range of matching d d m templates
8265             * @throws SystemException if a system exception occurred
8266             */
8267            @Override
8268            public List<DDMTemplate> findByC_C_T(long classNameId, long classPK,
8269                    String type, int start, int end) throws SystemException {
8270                    return findByC_C_T(classNameId, classPK, type, start, end, null);
8271            }
8272    
8273            /**
8274             * Returns an ordered range of all the d d m templates where classNameId = &#63; and classPK = &#63; and type = &#63;.
8275             *
8276             * <p>
8277             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8278             * </p>
8279             *
8280             * @param classNameId the class name ID
8281             * @param classPK the class p k
8282             * @param type the type
8283             * @param start the lower bound of the range of d d m templates
8284             * @param end the upper bound of the range of d d m templates (not inclusive)
8285             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8286             * @return the ordered range of matching d d m templates
8287             * @throws SystemException if a system exception occurred
8288             */
8289            @Override
8290            public List<DDMTemplate> findByC_C_T(long classNameId, long classPK,
8291                    String type, int start, int end, OrderByComparator orderByComparator)
8292                    throws SystemException {
8293                    boolean pagination = true;
8294                    FinderPath finderPath = null;
8295                    Object[] finderArgs = null;
8296    
8297                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8298                                    (orderByComparator == null)) {
8299                            pagination = false;
8300                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T;
8301                            finderArgs = new Object[] { classNameId, classPK, type };
8302                    }
8303                    else {
8304                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_T;
8305                            finderArgs = new Object[] {
8306                                            classNameId, classPK, type,
8307                                            
8308                                            start, end, orderByComparator
8309                                    };
8310                    }
8311    
8312                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
8313                                    finderArgs, this);
8314    
8315                    if ((list != null) && !list.isEmpty()) {
8316                            for (DDMTemplate ddmTemplate : list) {
8317                                    if ((classNameId != ddmTemplate.getClassNameId()) ||
8318                                                    (classPK != ddmTemplate.getClassPK()) ||
8319                                                    !Validator.equals(type, ddmTemplate.getType())) {
8320                                            list = null;
8321    
8322                                            break;
8323                                    }
8324                            }
8325                    }
8326    
8327                    if (list == null) {
8328                            StringBundler query = null;
8329    
8330                            if (orderByComparator != null) {
8331                                    query = new StringBundler(5 +
8332                                                    (orderByComparator.getOrderByFields().length * 3));
8333                            }
8334                            else {
8335                                    query = new StringBundler(5);
8336                            }
8337    
8338                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
8339    
8340                            query.append(_FINDER_COLUMN_C_C_T_CLASSNAMEID_2);
8341    
8342                            query.append(_FINDER_COLUMN_C_C_T_CLASSPK_2);
8343    
8344                            boolean bindType = false;
8345    
8346                            if (type == null) {
8347                                    query.append(_FINDER_COLUMN_C_C_T_TYPE_1);
8348                            }
8349                            else if (type.equals(StringPool.BLANK)) {
8350                                    query.append(_FINDER_COLUMN_C_C_T_TYPE_3);
8351                            }
8352                            else {
8353                                    bindType = true;
8354    
8355                                    query.append(_FINDER_COLUMN_C_C_T_TYPE_2);
8356                            }
8357    
8358                            if (orderByComparator != null) {
8359                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8360                                            orderByComparator);
8361                            }
8362                            else
8363                             if (pagination) {
8364                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
8365                            }
8366    
8367                            String sql = query.toString();
8368    
8369                            Session session = null;
8370    
8371                            try {
8372                                    session = openSession();
8373    
8374                                    Query q = session.createQuery(sql);
8375    
8376                                    QueryPos qPos = QueryPos.getInstance(q);
8377    
8378                                    qPos.add(classNameId);
8379    
8380                                    qPos.add(classPK);
8381    
8382                                    if (bindType) {
8383                                            qPos.add(type);
8384                                    }
8385    
8386                                    if (!pagination) {
8387                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
8388                                                            start, end, false);
8389    
8390                                            Collections.sort(list);
8391    
8392                                            list = new UnmodifiableList<DDMTemplate>(list);
8393                                    }
8394                                    else {
8395                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
8396                                                            start, end);
8397                                    }
8398    
8399                                    cacheResult(list);
8400    
8401                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
8402                            }
8403                            catch (Exception e) {
8404                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8405    
8406                                    throw processException(e);
8407                            }
8408                            finally {
8409                                    closeSession(session);
8410                            }
8411                    }
8412    
8413                    return list;
8414            }
8415    
8416            /**
8417             * Returns the first d d m template in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63;.
8418             *
8419             * @param classNameId the class name ID
8420             * @param classPK the class p k
8421             * @param type the type
8422             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8423             * @return the first matching d d m template
8424             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
8425             * @throws SystemException if a system exception occurred
8426             */
8427            @Override
8428            public DDMTemplate findByC_C_T_First(long classNameId, long classPK,
8429                    String type, OrderByComparator orderByComparator)
8430                    throws NoSuchTemplateException, SystemException {
8431                    DDMTemplate ddmTemplate = fetchByC_C_T_First(classNameId, classPK,
8432                                    type, orderByComparator);
8433    
8434                    if (ddmTemplate != null) {
8435                            return ddmTemplate;
8436                    }
8437    
8438                    StringBundler msg = new StringBundler(8);
8439    
8440                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8441    
8442                    msg.append("classNameId=");
8443                    msg.append(classNameId);
8444    
8445                    msg.append(", classPK=");
8446                    msg.append(classPK);
8447    
8448                    msg.append(", type=");
8449                    msg.append(type);
8450    
8451                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8452    
8453                    throw new NoSuchTemplateException(msg.toString());
8454            }
8455    
8456            /**
8457             * Returns the first d d m template in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63;.
8458             *
8459             * @param classNameId the class name ID
8460             * @param classPK the class p k
8461             * @param type the type
8462             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8463             * @return the first matching d d m template, or <code>null</code> if a matching d d m template could not be found
8464             * @throws SystemException if a system exception occurred
8465             */
8466            @Override
8467            public DDMTemplate fetchByC_C_T_First(long classNameId, long classPK,
8468                    String type, OrderByComparator orderByComparator)
8469                    throws SystemException {
8470                    List<DDMTemplate> list = findByC_C_T(classNameId, classPK, type, 0, 1,
8471                                    orderByComparator);
8472    
8473                    if (!list.isEmpty()) {
8474                            return list.get(0);
8475                    }
8476    
8477                    return null;
8478            }
8479    
8480            /**
8481             * Returns the last d d m template in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63;.
8482             *
8483             * @param classNameId the class name ID
8484             * @param classPK the class p k
8485             * @param type the type
8486             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8487             * @return the last matching d d m template
8488             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
8489             * @throws SystemException if a system exception occurred
8490             */
8491            @Override
8492            public DDMTemplate findByC_C_T_Last(long classNameId, long classPK,
8493                    String type, OrderByComparator orderByComparator)
8494                    throws NoSuchTemplateException, SystemException {
8495                    DDMTemplate ddmTemplate = fetchByC_C_T_Last(classNameId, classPK, type,
8496                                    orderByComparator);
8497    
8498                    if (ddmTemplate != null) {
8499                            return ddmTemplate;
8500                    }
8501    
8502                    StringBundler msg = new StringBundler(8);
8503    
8504                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8505    
8506                    msg.append("classNameId=");
8507                    msg.append(classNameId);
8508    
8509                    msg.append(", classPK=");
8510                    msg.append(classPK);
8511    
8512                    msg.append(", type=");
8513                    msg.append(type);
8514    
8515                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8516    
8517                    throw new NoSuchTemplateException(msg.toString());
8518            }
8519    
8520            /**
8521             * Returns the last d d m template in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63;.
8522             *
8523             * @param classNameId the class name ID
8524             * @param classPK the class p k
8525             * @param type the type
8526             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8527             * @return the last matching d d m template, or <code>null</code> if a matching d d m template could not be found
8528             * @throws SystemException if a system exception occurred
8529             */
8530            @Override
8531            public DDMTemplate fetchByC_C_T_Last(long classNameId, long classPK,
8532                    String type, OrderByComparator orderByComparator)
8533                    throws SystemException {
8534                    int count = countByC_C_T(classNameId, classPK, type);
8535    
8536                    if (count == 0) {
8537                            return null;
8538                    }
8539    
8540                    List<DDMTemplate> list = findByC_C_T(classNameId, classPK, type,
8541                                    count - 1, count, orderByComparator);
8542    
8543                    if (!list.isEmpty()) {
8544                            return list.get(0);
8545                    }
8546    
8547                    return null;
8548            }
8549    
8550            /**
8551             * Returns the d d m templates before and after the current d d m template in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63;.
8552             *
8553             * @param templateId the primary key of the current d d m template
8554             * @param classNameId the class name ID
8555             * @param classPK the class p k
8556             * @param type the type
8557             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8558             * @return the previous, current, and next d d m template
8559             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
8560             * @throws SystemException if a system exception occurred
8561             */
8562            @Override
8563            public DDMTemplate[] findByC_C_T_PrevAndNext(long templateId,
8564                    long classNameId, long classPK, String type,
8565                    OrderByComparator orderByComparator)
8566                    throws NoSuchTemplateException, SystemException {
8567                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
8568    
8569                    Session session = null;
8570    
8571                    try {
8572                            session = openSession();
8573    
8574                            DDMTemplate[] array = new DDMTemplateImpl[3];
8575    
8576                            array[0] = getByC_C_T_PrevAndNext(session, ddmTemplate,
8577                                            classNameId, classPK, type, orderByComparator, true);
8578    
8579                            array[1] = ddmTemplate;
8580    
8581                            array[2] = getByC_C_T_PrevAndNext(session, ddmTemplate,
8582                                            classNameId, classPK, type, orderByComparator, false);
8583    
8584                            return array;
8585                    }
8586                    catch (Exception e) {
8587                            throw processException(e);
8588                    }
8589                    finally {
8590                            closeSession(session);
8591                    }
8592            }
8593    
8594            protected DDMTemplate getByC_C_T_PrevAndNext(Session session,
8595                    DDMTemplate ddmTemplate, long classNameId, long classPK, String type,
8596                    OrderByComparator orderByComparator, boolean previous) {
8597                    StringBundler query = null;
8598    
8599                    if (orderByComparator != null) {
8600                            query = new StringBundler(6 +
8601                                            (orderByComparator.getOrderByFields().length * 6));
8602                    }
8603                    else {
8604                            query = new StringBundler(3);
8605                    }
8606    
8607                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
8608    
8609                    query.append(_FINDER_COLUMN_C_C_T_CLASSNAMEID_2);
8610    
8611                    query.append(_FINDER_COLUMN_C_C_T_CLASSPK_2);
8612    
8613                    boolean bindType = false;
8614    
8615                    if (type == null) {
8616                            query.append(_FINDER_COLUMN_C_C_T_TYPE_1);
8617                    }
8618                    else if (type.equals(StringPool.BLANK)) {
8619                            query.append(_FINDER_COLUMN_C_C_T_TYPE_3);
8620                    }
8621                    else {
8622                            bindType = true;
8623    
8624                            query.append(_FINDER_COLUMN_C_C_T_TYPE_2);
8625                    }
8626    
8627                    if (orderByComparator != null) {
8628                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8629    
8630                            if (orderByConditionFields.length > 0) {
8631                                    query.append(WHERE_AND);
8632                            }
8633    
8634                            for (int i = 0; i < orderByConditionFields.length; i++) {
8635                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8636                                    query.append(orderByConditionFields[i]);
8637    
8638                                    if ((i + 1) < orderByConditionFields.length) {
8639                                            if (orderByComparator.isAscending() ^ previous) {
8640                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8641                                            }
8642                                            else {
8643                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8644                                            }
8645                                    }
8646                                    else {
8647                                            if (orderByComparator.isAscending() ^ previous) {
8648                                                    query.append(WHERE_GREATER_THAN);
8649                                            }
8650                                            else {
8651                                                    query.append(WHERE_LESSER_THAN);
8652                                            }
8653                                    }
8654                            }
8655    
8656                            query.append(ORDER_BY_CLAUSE);
8657    
8658                            String[] orderByFields = orderByComparator.getOrderByFields();
8659    
8660                            for (int i = 0; i < orderByFields.length; i++) {
8661                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8662                                    query.append(orderByFields[i]);
8663    
8664                                    if ((i + 1) < orderByFields.length) {
8665                                            if (orderByComparator.isAscending() ^ previous) {
8666                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8667                                            }
8668                                            else {
8669                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8670                                            }
8671                                    }
8672                                    else {
8673                                            if (orderByComparator.isAscending() ^ previous) {
8674                                                    query.append(ORDER_BY_ASC);
8675                                            }
8676                                            else {
8677                                                    query.append(ORDER_BY_DESC);
8678                                            }
8679                                    }
8680                            }
8681                    }
8682                    else {
8683                            query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
8684                    }
8685    
8686                    String sql = query.toString();
8687    
8688                    Query q = session.createQuery(sql);
8689    
8690                    q.setFirstResult(0);
8691                    q.setMaxResults(2);
8692    
8693                    QueryPos qPos = QueryPos.getInstance(q);
8694    
8695                    qPos.add(classNameId);
8696    
8697                    qPos.add(classPK);
8698    
8699                    if (bindType) {
8700                            qPos.add(type);
8701                    }
8702    
8703                    if (orderByComparator != null) {
8704                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
8705    
8706                            for (Object value : values) {
8707                                    qPos.add(value);
8708                            }
8709                    }
8710    
8711                    List<DDMTemplate> list = q.list();
8712    
8713                    if (list.size() == 2) {
8714                            return list.get(1);
8715                    }
8716                    else {
8717                            return null;
8718                    }
8719            }
8720    
8721            /**
8722             * Removes all the d d m templates where classNameId = &#63; and classPK = &#63; and type = &#63; from the database.
8723             *
8724             * @param classNameId the class name ID
8725             * @param classPK the class p k
8726             * @param type the type
8727             * @throws SystemException if a system exception occurred
8728             */
8729            @Override
8730            public void removeByC_C_T(long classNameId, long classPK, String type)
8731                    throws SystemException {
8732                    for (DDMTemplate ddmTemplate : findByC_C_T(classNameId, classPK, type,
8733                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8734                            remove(ddmTemplate);
8735                    }
8736            }
8737    
8738            /**
8739             * Returns the number of d d m templates where classNameId = &#63; and classPK = &#63; and type = &#63;.
8740             *
8741             * @param classNameId the class name ID
8742             * @param classPK the class p k
8743             * @param type the type
8744             * @return the number of matching d d m templates
8745             * @throws SystemException if a system exception occurred
8746             */
8747            @Override
8748            public int countByC_C_T(long classNameId, long classPK, String type)
8749                    throws SystemException {
8750                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_T;
8751    
8752                    Object[] finderArgs = new Object[] { classNameId, classPK, type };
8753    
8754                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8755                                    this);
8756    
8757                    if (count == null) {
8758                            StringBundler query = new StringBundler(4);
8759    
8760                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
8761    
8762                            query.append(_FINDER_COLUMN_C_C_T_CLASSNAMEID_2);
8763    
8764                            query.append(_FINDER_COLUMN_C_C_T_CLASSPK_2);
8765    
8766                            boolean bindType = false;
8767    
8768                            if (type == null) {
8769                                    query.append(_FINDER_COLUMN_C_C_T_TYPE_1);
8770                            }
8771                            else if (type.equals(StringPool.BLANK)) {
8772                                    query.append(_FINDER_COLUMN_C_C_T_TYPE_3);
8773                            }
8774                            else {
8775                                    bindType = true;
8776    
8777                                    query.append(_FINDER_COLUMN_C_C_T_TYPE_2);
8778                            }
8779    
8780                            String sql = query.toString();
8781    
8782                            Session session = null;
8783    
8784                            try {
8785                                    session = openSession();
8786    
8787                                    Query q = session.createQuery(sql);
8788    
8789                                    QueryPos qPos = QueryPos.getInstance(q);
8790    
8791                                    qPos.add(classNameId);
8792    
8793                                    qPos.add(classPK);
8794    
8795                                    if (bindType) {
8796                                            qPos.add(type);
8797                                    }
8798    
8799                                    count = (Long)q.uniqueResult();
8800    
8801                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8802                            }
8803                            catch (Exception e) {
8804                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8805    
8806                                    throw processException(e);
8807                            }
8808                            finally {
8809                                    closeSession(session);
8810                            }
8811                    }
8812    
8813                    return count.intValue();
8814            }
8815    
8816            private static final String _FINDER_COLUMN_C_C_T_CLASSNAMEID_2 = "ddmTemplate.classNameId = ? AND ";
8817            private static final String _FINDER_COLUMN_C_C_T_CLASSPK_2 = "ddmTemplate.classPK = ? AND ";
8818            private static final String _FINDER_COLUMN_C_C_T_TYPE_1 = "ddmTemplate.type IS NULL";
8819            private static final String _FINDER_COLUMN_C_C_T_TYPE_2 = "ddmTemplate.type = ?";
8820            private static final String _FINDER_COLUMN_C_C_T_TYPE_3 = "(ddmTemplate.type IS NULL OR ddmTemplate.type = '')";
8821            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C_T = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
8822                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
8823                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_C_T",
8824                            new String[] {
8825                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
8826                                    String.class.getName(),
8827                                    
8828                            Integer.class.getName(), Integer.class.getName(),
8829                                    OrderByComparator.class.getName()
8830                            });
8831            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_T =
8832                    new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
8833                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
8834                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_C_T",
8835                            new String[] {
8836                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
8837                                    String.class.getName()
8838                            },
8839                            DDMTemplateModelImpl.GROUPID_COLUMN_BITMASK |
8840                            DDMTemplateModelImpl.CLASSNAMEID_COLUMN_BITMASK |
8841                            DDMTemplateModelImpl.CLASSPK_COLUMN_BITMASK |
8842                            DDMTemplateModelImpl.TYPE_COLUMN_BITMASK);
8843            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_C_T = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
8844                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
8845                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_C_T",
8846                            new String[] {
8847                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
8848                                    String.class.getName()
8849                            });
8850    
8851            /**
8852             * Returns all the d d m templates where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
8853             *
8854             * @param groupId the group ID
8855             * @param classNameId the class name ID
8856             * @param classPK the class p k
8857             * @param type the type
8858             * @return the matching d d m templates
8859             * @throws SystemException if a system exception occurred
8860             */
8861            @Override
8862            public List<DDMTemplate> findByG_C_C_T(long groupId, long classNameId,
8863                    long classPK, String type) throws SystemException {
8864                    return findByG_C_C_T(groupId, classNameId, classPK, type,
8865                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8866            }
8867    
8868            /**
8869             * Returns a range of all the d d m templates where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
8870             *
8871             * <p>
8872             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8873             * </p>
8874             *
8875             * @param groupId the group ID
8876             * @param classNameId the class name ID
8877             * @param classPK the class p k
8878             * @param type the type
8879             * @param start the lower bound of the range of d d m templates
8880             * @param end the upper bound of the range of d d m templates (not inclusive)
8881             * @return the range of matching d d m templates
8882             * @throws SystemException if a system exception occurred
8883             */
8884            @Override
8885            public List<DDMTemplate> findByG_C_C_T(long groupId, long classNameId,
8886                    long classPK, String type, int start, int end)
8887                    throws SystemException {
8888                    return findByG_C_C_T(groupId, classNameId, classPK, type, start, end,
8889                            null);
8890            }
8891    
8892            /**
8893             * Returns an ordered range of all the d d m templates where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
8894             *
8895             * <p>
8896             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8897             * </p>
8898             *
8899             * @param groupId the group ID
8900             * @param classNameId the class name ID
8901             * @param classPK the class p k
8902             * @param type the type
8903             * @param start the lower bound of the range of d d m templates
8904             * @param end the upper bound of the range of d d m templates (not inclusive)
8905             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8906             * @return the ordered range of matching d d m templates
8907             * @throws SystemException if a system exception occurred
8908             */
8909            @Override
8910            public List<DDMTemplate> findByG_C_C_T(long groupId, long classNameId,
8911                    long classPK, String type, int start, int end,
8912                    OrderByComparator orderByComparator) throws SystemException {
8913                    boolean pagination = true;
8914                    FinderPath finderPath = null;
8915                    Object[] finderArgs = null;
8916    
8917                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8918                                    (orderByComparator == null)) {
8919                            pagination = false;
8920                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_T;
8921                            finderArgs = new Object[] { groupId, classNameId, classPK, type };
8922                    }
8923                    else {
8924                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C_T;
8925                            finderArgs = new Object[] {
8926                                            groupId, classNameId, classPK, type,
8927                                            
8928                                            start, end, orderByComparator
8929                                    };
8930                    }
8931    
8932                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
8933                                    finderArgs, this);
8934    
8935                    if ((list != null) && !list.isEmpty()) {
8936                            for (DDMTemplate ddmTemplate : list) {
8937                                    if ((groupId != ddmTemplate.getGroupId()) ||
8938                                                    (classNameId != ddmTemplate.getClassNameId()) ||
8939                                                    (classPK != ddmTemplate.getClassPK()) ||
8940                                                    !Validator.equals(type, ddmTemplate.getType())) {
8941                                            list = null;
8942    
8943                                            break;
8944                                    }
8945                            }
8946                    }
8947    
8948                    if (list == null) {
8949                            StringBundler query = null;
8950    
8951                            if (orderByComparator != null) {
8952                                    query = new StringBundler(6 +
8953                                                    (orderByComparator.getOrderByFields().length * 3));
8954                            }
8955                            else {
8956                                    query = new StringBundler(6);
8957                            }
8958    
8959                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
8960    
8961                            query.append(_FINDER_COLUMN_G_C_C_T_GROUPID_2);
8962    
8963                            query.append(_FINDER_COLUMN_G_C_C_T_CLASSNAMEID_2);
8964    
8965                            query.append(_FINDER_COLUMN_G_C_C_T_CLASSPK_2);
8966    
8967                            boolean bindType = false;
8968    
8969                            if (type == null) {
8970                                    query.append(_FINDER_COLUMN_G_C_C_T_TYPE_1);
8971                            }
8972                            else if (type.equals(StringPool.BLANK)) {
8973                                    query.append(_FINDER_COLUMN_G_C_C_T_TYPE_3);
8974                            }
8975                            else {
8976                                    bindType = true;
8977    
8978                                    query.append(_FINDER_COLUMN_G_C_C_T_TYPE_2);
8979                            }
8980    
8981                            if (orderByComparator != null) {
8982                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8983                                            orderByComparator);
8984                            }
8985                            else
8986                             if (pagination) {
8987                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
8988                            }
8989    
8990                            String sql = query.toString();
8991    
8992                            Session session = null;
8993    
8994                            try {
8995                                    session = openSession();
8996    
8997                                    Query q = session.createQuery(sql);
8998    
8999                                    QueryPos qPos = QueryPos.getInstance(q);
9000    
9001                                    qPos.add(groupId);
9002    
9003                                    qPos.add(classNameId);
9004    
9005                                    qPos.add(classPK);
9006    
9007                                    if (bindType) {
9008                                            qPos.add(type);
9009                                    }
9010    
9011                                    if (!pagination) {
9012                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
9013                                                            start, end, false);
9014    
9015                                            Collections.sort(list);
9016    
9017                                            list = new UnmodifiableList<DDMTemplate>(list);
9018                                    }
9019                                    else {
9020                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
9021                                                            start, end);
9022                                    }
9023    
9024                                    cacheResult(list);
9025    
9026                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
9027                            }
9028                            catch (Exception e) {
9029                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9030    
9031                                    throw processException(e);
9032                            }
9033                            finally {
9034                                    closeSession(session);
9035                            }
9036                    }
9037    
9038                    return list;
9039            }
9040    
9041            /**
9042             * Returns the first d d m template in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
9043             *
9044             * @param groupId the group ID
9045             * @param classNameId the class name ID
9046             * @param classPK the class p k
9047             * @param type the type
9048             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9049             * @return the first matching d d m template
9050             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
9051             * @throws SystemException if a system exception occurred
9052             */
9053            @Override
9054            public DDMTemplate findByG_C_C_T_First(long groupId, long classNameId,
9055                    long classPK, String type, OrderByComparator orderByComparator)
9056                    throws NoSuchTemplateException, SystemException {
9057                    DDMTemplate ddmTemplate = fetchByG_C_C_T_First(groupId, classNameId,
9058                                    classPK, type, orderByComparator);
9059    
9060                    if (ddmTemplate != null) {
9061                            return ddmTemplate;
9062                    }
9063    
9064                    StringBundler msg = new StringBundler(10);
9065    
9066                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9067    
9068                    msg.append("groupId=");
9069                    msg.append(groupId);
9070    
9071                    msg.append(", classNameId=");
9072                    msg.append(classNameId);
9073    
9074                    msg.append(", classPK=");
9075                    msg.append(classPK);
9076    
9077                    msg.append(", type=");
9078                    msg.append(type);
9079    
9080                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9081    
9082                    throw new NoSuchTemplateException(msg.toString());
9083            }
9084    
9085            /**
9086             * Returns the first d d m template in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
9087             *
9088             * @param groupId the group ID
9089             * @param classNameId the class name ID
9090             * @param classPK the class p k
9091             * @param type the type
9092             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9093             * @return the first matching d d m template, or <code>null</code> if a matching d d m template could not be found
9094             * @throws SystemException if a system exception occurred
9095             */
9096            @Override
9097            public DDMTemplate fetchByG_C_C_T_First(long groupId, long classNameId,
9098                    long classPK, String type, OrderByComparator orderByComparator)
9099                    throws SystemException {
9100                    List<DDMTemplate> list = findByG_C_C_T(groupId, classNameId, classPK,
9101                                    type, 0, 1, orderByComparator);
9102    
9103                    if (!list.isEmpty()) {
9104                            return list.get(0);
9105                    }
9106    
9107                    return null;
9108            }
9109    
9110            /**
9111             * Returns the last d d m template in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
9112             *
9113             * @param groupId the group ID
9114             * @param classNameId the class name ID
9115             * @param classPK the class p k
9116             * @param type the type
9117             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9118             * @return the last matching d d m template
9119             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
9120             * @throws SystemException if a system exception occurred
9121             */
9122            @Override
9123            public DDMTemplate findByG_C_C_T_Last(long groupId, long classNameId,
9124                    long classPK, String type, OrderByComparator orderByComparator)
9125                    throws NoSuchTemplateException, SystemException {
9126                    DDMTemplate ddmTemplate = fetchByG_C_C_T_Last(groupId, classNameId,
9127                                    classPK, type, orderByComparator);
9128    
9129                    if (ddmTemplate != null) {
9130                            return ddmTemplate;
9131                    }
9132    
9133                    StringBundler msg = new StringBundler(10);
9134    
9135                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9136    
9137                    msg.append("groupId=");
9138                    msg.append(groupId);
9139    
9140                    msg.append(", classNameId=");
9141                    msg.append(classNameId);
9142    
9143                    msg.append(", classPK=");
9144                    msg.append(classPK);
9145    
9146                    msg.append(", type=");
9147                    msg.append(type);
9148    
9149                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9150    
9151                    throw new NoSuchTemplateException(msg.toString());
9152            }
9153    
9154            /**
9155             * Returns the last d d m template in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
9156             *
9157             * @param groupId the group ID
9158             * @param classNameId the class name ID
9159             * @param classPK the class p k
9160             * @param type the type
9161             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9162             * @return the last matching d d m template, or <code>null</code> if a matching d d m template could not be found
9163             * @throws SystemException if a system exception occurred
9164             */
9165            @Override
9166            public DDMTemplate fetchByG_C_C_T_Last(long groupId, long classNameId,
9167                    long classPK, String type, OrderByComparator orderByComparator)
9168                    throws SystemException {
9169                    int count = countByG_C_C_T(groupId, classNameId, classPK, type);
9170    
9171                    if (count == 0) {
9172                            return null;
9173                    }
9174    
9175                    List<DDMTemplate> list = findByG_C_C_T(groupId, classNameId, classPK,
9176                                    type, count - 1, count, orderByComparator);
9177    
9178                    if (!list.isEmpty()) {
9179                            return list.get(0);
9180                    }
9181    
9182                    return null;
9183            }
9184    
9185            /**
9186             * Returns the d d m templates before and after the current d d m template in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
9187             *
9188             * @param templateId the primary key of the current d d m template
9189             * @param groupId the group ID
9190             * @param classNameId the class name ID
9191             * @param classPK the class p k
9192             * @param type the type
9193             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9194             * @return the previous, current, and next d d m template
9195             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
9196             * @throws SystemException if a system exception occurred
9197             */
9198            @Override
9199            public DDMTemplate[] findByG_C_C_T_PrevAndNext(long templateId,
9200                    long groupId, long classNameId, long classPK, String type,
9201                    OrderByComparator orderByComparator)
9202                    throws NoSuchTemplateException, SystemException {
9203                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
9204    
9205                    Session session = null;
9206    
9207                    try {
9208                            session = openSession();
9209    
9210                            DDMTemplate[] array = new DDMTemplateImpl[3];
9211    
9212                            array[0] = getByG_C_C_T_PrevAndNext(session, ddmTemplate, groupId,
9213                                            classNameId, classPK, type, orderByComparator, true);
9214    
9215                            array[1] = ddmTemplate;
9216    
9217                            array[2] = getByG_C_C_T_PrevAndNext(session, ddmTemplate, groupId,
9218                                            classNameId, classPK, type, orderByComparator, false);
9219    
9220                            return array;
9221                    }
9222                    catch (Exception e) {
9223                            throw processException(e);
9224                    }
9225                    finally {
9226                            closeSession(session);
9227                    }
9228            }
9229    
9230            protected DDMTemplate getByG_C_C_T_PrevAndNext(Session session,
9231                    DDMTemplate ddmTemplate, long groupId, long classNameId, long classPK,
9232                    String type, OrderByComparator orderByComparator, boolean previous) {
9233                    StringBundler query = null;
9234    
9235                    if (orderByComparator != null) {
9236                            query = new StringBundler(6 +
9237                                            (orderByComparator.getOrderByFields().length * 6));
9238                    }
9239                    else {
9240                            query = new StringBundler(3);
9241                    }
9242    
9243                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
9244    
9245                    query.append(_FINDER_COLUMN_G_C_C_T_GROUPID_2);
9246    
9247                    query.append(_FINDER_COLUMN_G_C_C_T_CLASSNAMEID_2);
9248    
9249                    query.append(_FINDER_COLUMN_G_C_C_T_CLASSPK_2);
9250    
9251                    boolean bindType = false;
9252    
9253                    if (type == null) {
9254                            query.append(_FINDER_COLUMN_G_C_C_T_TYPE_1);
9255                    }
9256                    else if (type.equals(StringPool.BLANK)) {
9257                            query.append(_FINDER_COLUMN_G_C_C_T_TYPE_3);
9258                    }
9259                    else {
9260                            bindType = true;
9261    
9262                            query.append(_FINDER_COLUMN_G_C_C_T_TYPE_2);
9263                    }
9264    
9265                    if (orderByComparator != null) {
9266                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9267    
9268                            if (orderByConditionFields.length > 0) {
9269                                    query.append(WHERE_AND);
9270                            }
9271    
9272                            for (int i = 0; i < orderByConditionFields.length; i++) {
9273                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9274                                    query.append(orderByConditionFields[i]);
9275    
9276                                    if ((i + 1) < orderByConditionFields.length) {
9277                                            if (orderByComparator.isAscending() ^ previous) {
9278                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9279                                            }
9280                                            else {
9281                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9282                                            }
9283                                    }
9284                                    else {
9285                                            if (orderByComparator.isAscending() ^ previous) {
9286                                                    query.append(WHERE_GREATER_THAN);
9287                                            }
9288                                            else {
9289                                                    query.append(WHERE_LESSER_THAN);
9290                                            }
9291                                    }
9292                            }
9293    
9294                            query.append(ORDER_BY_CLAUSE);
9295    
9296                            String[] orderByFields = orderByComparator.getOrderByFields();
9297    
9298                            for (int i = 0; i < orderByFields.length; i++) {
9299                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9300                                    query.append(orderByFields[i]);
9301    
9302                                    if ((i + 1) < orderByFields.length) {
9303                                            if (orderByComparator.isAscending() ^ previous) {
9304                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9305                                            }
9306                                            else {
9307                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9308                                            }
9309                                    }
9310                                    else {
9311                                            if (orderByComparator.isAscending() ^ previous) {
9312                                                    query.append(ORDER_BY_ASC);
9313                                            }
9314                                            else {
9315                                                    query.append(ORDER_BY_DESC);
9316                                            }
9317                                    }
9318                            }
9319                    }
9320                    else {
9321                            query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
9322                    }
9323    
9324                    String sql = query.toString();
9325    
9326                    Query q = session.createQuery(sql);
9327    
9328                    q.setFirstResult(0);
9329                    q.setMaxResults(2);
9330    
9331                    QueryPos qPos = QueryPos.getInstance(q);
9332    
9333                    qPos.add(groupId);
9334    
9335                    qPos.add(classNameId);
9336    
9337                    qPos.add(classPK);
9338    
9339                    if (bindType) {
9340                            qPos.add(type);
9341                    }
9342    
9343                    if (orderByComparator != null) {
9344                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
9345    
9346                            for (Object value : values) {
9347                                    qPos.add(value);
9348                            }
9349                    }
9350    
9351                    List<DDMTemplate> list = q.list();
9352    
9353                    if (list.size() == 2) {
9354                            return list.get(1);
9355                    }
9356                    else {
9357                            return null;
9358                    }
9359            }
9360    
9361            /**
9362             * Returns all the d d m templates that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
9363             *
9364             * @param groupId the group ID
9365             * @param classNameId the class name ID
9366             * @param classPK the class p k
9367             * @param type the type
9368             * @return the matching d d m templates that the user has permission to view
9369             * @throws SystemException if a system exception occurred
9370             */
9371            @Override
9372            public List<DDMTemplate> filterFindByG_C_C_T(long groupId,
9373                    long classNameId, long classPK, String type) throws SystemException {
9374                    return filterFindByG_C_C_T(groupId, classNameId, classPK, type,
9375                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
9376            }
9377    
9378            /**
9379             * Returns a range of all the d d m templates that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
9380             *
9381             * <p>
9382             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9383             * </p>
9384             *
9385             * @param groupId the group ID
9386             * @param classNameId the class name ID
9387             * @param classPK the class p k
9388             * @param type the type
9389             * @param start the lower bound of the range of d d m templates
9390             * @param end the upper bound of the range of d d m templates (not inclusive)
9391             * @return the range of matching d d m templates that the user has permission to view
9392             * @throws SystemException if a system exception occurred
9393             */
9394            @Override
9395            public List<DDMTemplate> filterFindByG_C_C_T(long groupId,
9396                    long classNameId, long classPK, String type, int start, int end)
9397                    throws SystemException {
9398                    return filterFindByG_C_C_T(groupId, classNameId, classPK, type, start,
9399                            end, null);
9400            }
9401    
9402            /**
9403             * Returns an ordered range of all the d d m templates that the user has permissions to view where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
9404             *
9405             * <p>
9406             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9407             * </p>
9408             *
9409             * @param groupId the group ID
9410             * @param classNameId the class name ID
9411             * @param classPK the class p k
9412             * @param type the type
9413             * @param start the lower bound of the range of d d m templates
9414             * @param end the upper bound of the range of d d m templates (not inclusive)
9415             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9416             * @return the ordered range of matching d d m templates that the user has permission to view
9417             * @throws SystemException if a system exception occurred
9418             */
9419            @Override
9420            public List<DDMTemplate> filterFindByG_C_C_T(long groupId,
9421                    long classNameId, long classPK, String type, int start, int end,
9422                    OrderByComparator orderByComparator) throws SystemException {
9423                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9424                            return findByG_C_C_T(groupId, classNameId, classPK, type, start,
9425                                    end, orderByComparator);
9426                    }
9427    
9428                    StringBundler query = null;
9429    
9430                    if (orderByComparator != null) {
9431                            query = new StringBundler(6 +
9432                                            (orderByComparator.getOrderByFields().length * 3));
9433                    }
9434                    else {
9435                            query = new StringBundler(6);
9436                    }
9437    
9438                    if (getDB().isSupportsInlineDistinct()) {
9439                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_WHERE);
9440                    }
9441                    else {
9442                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
9443                    }
9444    
9445                    query.append(_FINDER_COLUMN_G_C_C_T_GROUPID_2);
9446    
9447                    query.append(_FINDER_COLUMN_G_C_C_T_CLASSNAMEID_2);
9448    
9449                    query.append(_FINDER_COLUMN_G_C_C_T_CLASSPK_2);
9450    
9451                    boolean bindType = false;
9452    
9453                    if (type == null) {
9454                            query.append(_FINDER_COLUMN_G_C_C_T_TYPE_1_SQL);
9455                    }
9456                    else if (type.equals(StringPool.BLANK)) {
9457                            query.append(_FINDER_COLUMN_G_C_C_T_TYPE_3_SQL);
9458                    }
9459                    else {
9460                            bindType = true;
9461    
9462                            query.append(_FINDER_COLUMN_G_C_C_T_TYPE_2_SQL);
9463                    }
9464    
9465                    if (!getDB().isSupportsInlineDistinct()) {
9466                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
9467                    }
9468    
9469                    if (orderByComparator != null) {
9470                            if (getDB().isSupportsInlineDistinct()) {
9471                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9472                                            orderByComparator, true);
9473                            }
9474                            else {
9475                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
9476                                            orderByComparator, true);
9477                            }
9478                    }
9479                    else {
9480                            if (getDB().isSupportsInlineDistinct()) {
9481                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
9482                            }
9483                            else {
9484                                    query.append(DDMTemplateModelImpl.ORDER_BY_SQL);
9485                            }
9486                    }
9487    
9488                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9489                                    DDMTemplate.class.getName(),
9490                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9491    
9492                    Session session = null;
9493    
9494                    try {
9495                            session = openSession();
9496    
9497                            SQLQuery q = session.createSQLQuery(sql);
9498    
9499                            if (getDB().isSupportsInlineDistinct()) {
9500                                    q.addEntity(_FILTER_ENTITY_ALIAS, DDMTemplateImpl.class);
9501                            }
9502                            else {
9503                                    q.addEntity(_FILTER_ENTITY_TABLE, DDMTemplateImpl.class);
9504                            }
9505    
9506                            QueryPos qPos = QueryPos.getInstance(q);
9507    
9508                            qPos.add(groupId);
9509    
9510                            qPos.add(classNameId);
9511    
9512                            qPos.add(classPK);
9513    
9514                            if (bindType) {
9515                                    qPos.add(type);
9516                            }
9517    
9518                            return (List<DDMTemplate>)QueryUtil.list(q, getDialect(), start, end);
9519                    }
9520                    catch (Exception e) {
9521                            throw processException(e);
9522                    }
9523                    finally {
9524                            closeSession(session);
9525                    }
9526            }
9527    
9528            /**
9529             * Returns the d d m templates before and after the current d d m template in the ordered set of d d m templates that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
9530             *
9531             * @param templateId the primary key of the current d d m template
9532             * @param groupId the group ID
9533             * @param classNameId the class name ID
9534             * @param classPK the class p k
9535             * @param type the type
9536             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9537             * @return the previous, current, and next d d m template
9538             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
9539             * @throws SystemException if a system exception occurred
9540             */
9541            @Override
9542            public DDMTemplate[] filterFindByG_C_C_T_PrevAndNext(long templateId,
9543                    long groupId, long classNameId, long classPK, String type,
9544                    OrderByComparator orderByComparator)
9545                    throws NoSuchTemplateException, SystemException {
9546                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9547                            return findByG_C_C_T_PrevAndNext(templateId, groupId, classNameId,
9548                                    classPK, type, orderByComparator);
9549                    }
9550    
9551                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
9552    
9553                    Session session = null;
9554    
9555                    try {
9556                            session = openSession();
9557    
9558                            DDMTemplate[] array = new DDMTemplateImpl[3];
9559    
9560                            array[0] = filterGetByG_C_C_T_PrevAndNext(session, ddmTemplate,
9561                                            groupId, classNameId, classPK, type, orderByComparator, true);
9562    
9563                            array[1] = ddmTemplate;
9564    
9565                            array[2] = filterGetByG_C_C_T_PrevAndNext(session, ddmTemplate,
9566                                            groupId, classNameId, classPK, type, orderByComparator,
9567                                            false);
9568    
9569                            return array;
9570                    }
9571                    catch (Exception e) {
9572                            throw processException(e);
9573                    }
9574                    finally {
9575                            closeSession(session);
9576                    }
9577            }
9578    
9579            protected DDMTemplate filterGetByG_C_C_T_PrevAndNext(Session session,
9580                    DDMTemplate ddmTemplate, long groupId, long classNameId, long classPK,
9581                    String type, OrderByComparator orderByComparator, boolean previous) {
9582                    StringBundler query = null;
9583    
9584                    if (orderByComparator != null) {
9585                            query = new StringBundler(6 +
9586                                            (orderByComparator.getOrderByFields().length * 6));
9587                    }
9588                    else {
9589                            query = new StringBundler(3);
9590                    }
9591    
9592                    if (getDB().isSupportsInlineDistinct()) {
9593                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_WHERE);
9594                    }
9595                    else {
9596                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
9597                    }
9598    
9599                    query.append(_FINDER_COLUMN_G_C_C_T_GROUPID_2);
9600    
9601                    query.append(_FINDER_COLUMN_G_C_C_T_CLASSNAMEID_2);
9602    
9603                    query.append(_FINDER_COLUMN_G_C_C_T_CLASSPK_2);
9604    
9605                    boolean bindType = false;
9606    
9607                    if (type == null) {
9608                            query.append(_FINDER_COLUMN_G_C_C_T_TYPE_1_SQL);
9609                    }
9610                    else if (type.equals(StringPool.BLANK)) {
9611                            query.append(_FINDER_COLUMN_G_C_C_T_TYPE_3_SQL);
9612                    }
9613                    else {
9614                            bindType = true;
9615    
9616                            query.append(_FINDER_COLUMN_G_C_C_T_TYPE_2_SQL);
9617                    }
9618    
9619                    if (!getDB().isSupportsInlineDistinct()) {
9620                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
9621                    }
9622    
9623                    if (orderByComparator != null) {
9624                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9625    
9626                            if (orderByConditionFields.length > 0) {
9627                                    query.append(WHERE_AND);
9628                            }
9629    
9630                            for (int i = 0; i < orderByConditionFields.length; i++) {
9631                                    if (getDB().isSupportsInlineDistinct()) {
9632                                            query.append(_ORDER_BY_ENTITY_ALIAS);
9633                                    }
9634                                    else {
9635                                            query.append(_ORDER_BY_ENTITY_TABLE);
9636                                    }
9637    
9638                                    query.append(orderByConditionFields[i]);
9639    
9640                                    if ((i + 1) < orderByConditionFields.length) {
9641                                            if (orderByComparator.isAscending() ^ previous) {
9642                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9643                                            }
9644                                            else {
9645                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9646                                            }
9647                                    }
9648                                    else {
9649                                            if (orderByComparator.isAscending() ^ previous) {
9650                                                    query.append(WHERE_GREATER_THAN);
9651                                            }
9652                                            else {
9653                                                    query.append(WHERE_LESSER_THAN);
9654                                            }
9655                                    }
9656                            }
9657    
9658                            query.append(ORDER_BY_CLAUSE);
9659    
9660                            String[] orderByFields = orderByComparator.getOrderByFields();
9661    
9662                            for (int i = 0; i < orderByFields.length; i++) {
9663                                    if (getDB().isSupportsInlineDistinct()) {
9664                                            query.append(_ORDER_BY_ENTITY_ALIAS);
9665                                    }
9666                                    else {
9667                                            query.append(_ORDER_BY_ENTITY_TABLE);
9668                                    }
9669    
9670                                    query.append(orderByFields[i]);
9671    
9672                                    if ((i + 1) < orderByFields.length) {
9673                                            if (orderByComparator.isAscending() ^ previous) {
9674                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9675                                            }
9676                                            else {
9677                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9678                                            }
9679                                    }
9680                                    else {
9681                                            if (orderByComparator.isAscending() ^ previous) {
9682                                                    query.append(ORDER_BY_ASC);
9683                                            }
9684                                            else {
9685                                                    query.append(ORDER_BY_DESC);
9686                                            }
9687                                    }
9688                            }
9689                    }
9690                    else {
9691                            if (getDB().isSupportsInlineDistinct()) {
9692                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
9693                            }
9694                            else {
9695                                    query.append(DDMTemplateModelImpl.ORDER_BY_SQL);
9696                            }
9697                    }
9698    
9699                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9700                                    DDMTemplate.class.getName(),
9701                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9702    
9703                    SQLQuery q = session.createSQLQuery(sql);
9704    
9705                    q.setFirstResult(0);
9706                    q.setMaxResults(2);
9707    
9708                    if (getDB().isSupportsInlineDistinct()) {
9709                            q.addEntity(_FILTER_ENTITY_ALIAS, DDMTemplateImpl.class);
9710                    }
9711                    else {
9712                            q.addEntity(_FILTER_ENTITY_TABLE, DDMTemplateImpl.class);
9713                    }
9714    
9715                    QueryPos qPos = QueryPos.getInstance(q);
9716    
9717                    qPos.add(groupId);
9718    
9719                    qPos.add(classNameId);
9720    
9721                    qPos.add(classPK);
9722    
9723                    if (bindType) {
9724                            qPos.add(type);
9725                    }
9726    
9727                    if (orderByComparator != null) {
9728                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
9729    
9730                            for (Object value : values) {
9731                                    qPos.add(value);
9732                            }
9733                    }
9734    
9735                    List<DDMTemplate> list = q.list();
9736    
9737                    if (list.size() == 2) {
9738                            return list.get(1);
9739                    }
9740                    else {
9741                            return null;
9742                    }
9743            }
9744    
9745            /**
9746             * Removes all the d d m templates where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; from the database.
9747             *
9748             * @param groupId the group ID
9749             * @param classNameId the class name ID
9750             * @param classPK the class p k
9751             * @param type the type
9752             * @throws SystemException if a system exception occurred
9753             */
9754            @Override
9755            public void removeByG_C_C_T(long groupId, long classNameId, long classPK,
9756                    String type) throws SystemException {
9757                    for (DDMTemplate ddmTemplate : findByG_C_C_T(groupId, classNameId,
9758                                    classPK, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9759                            remove(ddmTemplate);
9760                    }
9761            }
9762    
9763            /**
9764             * Returns the number of d d m templates where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
9765             *
9766             * @param groupId the group ID
9767             * @param classNameId the class name ID
9768             * @param classPK the class p k
9769             * @param type the type
9770             * @return the number of matching d d m templates
9771             * @throws SystemException if a system exception occurred
9772             */
9773            @Override
9774            public int countByG_C_C_T(long groupId, long classNameId, long classPK,
9775                    String type) throws SystemException {
9776                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_C_T;
9777    
9778                    Object[] finderArgs = new Object[] { groupId, classNameId, classPK, type };
9779    
9780                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9781                                    this);
9782    
9783                    if (count == null) {
9784                            StringBundler query = new StringBundler(5);
9785    
9786                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
9787    
9788                            query.append(_FINDER_COLUMN_G_C_C_T_GROUPID_2);
9789    
9790                            query.append(_FINDER_COLUMN_G_C_C_T_CLASSNAMEID_2);
9791    
9792                            query.append(_FINDER_COLUMN_G_C_C_T_CLASSPK_2);
9793    
9794                            boolean bindType = false;
9795    
9796                            if (type == null) {
9797                                    query.append(_FINDER_COLUMN_G_C_C_T_TYPE_1);
9798                            }
9799                            else if (type.equals(StringPool.BLANK)) {
9800                                    query.append(_FINDER_COLUMN_G_C_C_T_TYPE_3);
9801                            }
9802                            else {
9803                                    bindType = true;
9804    
9805                                    query.append(_FINDER_COLUMN_G_C_C_T_TYPE_2);
9806                            }
9807    
9808                            String sql = query.toString();
9809    
9810                            Session session = null;
9811    
9812                            try {
9813                                    session = openSession();
9814    
9815                                    Query q = session.createQuery(sql);
9816    
9817                                    QueryPos qPos = QueryPos.getInstance(q);
9818    
9819                                    qPos.add(groupId);
9820    
9821                                    qPos.add(classNameId);
9822    
9823                                    qPos.add(classPK);
9824    
9825                                    if (bindType) {
9826                                            qPos.add(type);
9827                                    }
9828    
9829                                    count = (Long)q.uniqueResult();
9830    
9831                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
9832                            }
9833                            catch (Exception e) {
9834                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9835    
9836                                    throw processException(e);
9837                            }
9838                            finally {
9839                                    closeSession(session);
9840                            }
9841                    }
9842    
9843                    return count.intValue();
9844            }
9845    
9846            /**
9847             * Returns the number of d d m templates that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
9848             *
9849             * @param groupId the group ID
9850             * @param classNameId the class name ID
9851             * @param classPK the class p k
9852             * @param type the type
9853             * @return the number of matching d d m templates that the user has permission to view
9854             * @throws SystemException if a system exception occurred
9855             */
9856            @Override
9857            public int filterCountByG_C_C_T(long groupId, long classNameId,
9858                    long classPK, String type) throws SystemException {
9859                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9860                            return countByG_C_C_T(groupId, classNameId, classPK, type);
9861                    }
9862    
9863                    StringBundler query = new StringBundler(5);
9864    
9865                    query.append(_FILTER_SQL_COUNT_DDMTEMPLATE_WHERE);
9866    
9867                    query.append(_FINDER_COLUMN_G_C_C_T_GROUPID_2);
9868    
9869                    query.append(_FINDER_COLUMN_G_C_C_T_CLASSNAMEID_2);
9870    
9871                    query.append(_FINDER_COLUMN_G_C_C_T_CLASSPK_2);
9872    
9873                    boolean bindType = false;
9874    
9875                    if (type == null) {
9876                            query.append(_FINDER_COLUMN_G_C_C_T_TYPE_1_SQL);
9877                    }
9878                    else if (type.equals(StringPool.BLANK)) {
9879                            query.append(_FINDER_COLUMN_G_C_C_T_TYPE_3_SQL);
9880                    }
9881                    else {
9882                            bindType = true;
9883    
9884                            query.append(_FINDER_COLUMN_G_C_C_T_TYPE_2_SQL);
9885                    }
9886    
9887                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9888                                    DDMTemplate.class.getName(),
9889                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9890    
9891                    Session session = null;
9892    
9893                    try {
9894                            session = openSession();
9895    
9896                            SQLQuery q = session.createSQLQuery(sql);
9897    
9898                            q.addScalar(COUNT_COLUMN_NAME,
9899                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
9900    
9901                            QueryPos qPos = QueryPos.getInstance(q);
9902    
9903                            qPos.add(groupId);
9904    
9905                            qPos.add(classNameId);
9906    
9907                            qPos.add(classPK);
9908    
9909                            if (bindType) {
9910                                    qPos.add(type);
9911                            }
9912    
9913                            Long count = (Long)q.uniqueResult();
9914    
9915                            return count.intValue();
9916                    }
9917                    catch (Exception e) {
9918                            throw processException(e);
9919                    }
9920                    finally {
9921                            closeSession(session);
9922                    }
9923            }
9924    
9925            private static final String _FINDER_COLUMN_G_C_C_T_GROUPID_2 = "ddmTemplate.groupId = ? AND ";
9926            private static final String _FINDER_COLUMN_G_C_C_T_CLASSNAMEID_2 = "ddmTemplate.classNameId = ? AND ";
9927            private static final String _FINDER_COLUMN_G_C_C_T_CLASSPK_2 = "ddmTemplate.classPK = ? AND ";
9928            private static final String _FINDER_COLUMN_G_C_C_T_TYPE_1 = "ddmTemplate.type IS NULL";
9929            private static final String _FINDER_COLUMN_G_C_C_T_TYPE_2 = "ddmTemplate.type = ?";
9930            private static final String _FINDER_COLUMN_G_C_C_T_TYPE_3 = "(ddmTemplate.type IS NULL OR ddmTemplate.type = '')";
9931            private static final String _FINDER_COLUMN_G_C_C_T_TYPE_1_SQL = "ddmTemplate.type_ IS NULL";
9932            private static final String _FINDER_COLUMN_G_C_C_T_TYPE_2_SQL = "ddmTemplate.type_ = ?";
9933            private static final String _FINDER_COLUMN_G_C_C_T_TYPE_3_SQL = "(ddmTemplate.type_ IS NULL OR ddmTemplate.type_ = '')";
9934            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C_T_M =
9935                    new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
9936                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
9937                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_C_T_M",
9938                            new String[] {
9939                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
9940                                    String.class.getName(), String.class.getName(),
9941                                    
9942                            Integer.class.getName(), Integer.class.getName(),
9943                                    OrderByComparator.class.getName()
9944                            });
9945            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_T_M =
9946                    new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
9947                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, DDMTemplateImpl.class,
9948                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_C_T_M",
9949                            new String[] {
9950                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
9951                                    String.class.getName(), String.class.getName()
9952                            },
9953                            DDMTemplateModelImpl.GROUPID_COLUMN_BITMASK |
9954                            DDMTemplateModelImpl.CLASSNAMEID_COLUMN_BITMASK |
9955                            DDMTemplateModelImpl.CLASSPK_COLUMN_BITMASK |
9956                            DDMTemplateModelImpl.TYPE_COLUMN_BITMASK |
9957                            DDMTemplateModelImpl.MODE_COLUMN_BITMASK);
9958            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_C_T_M = new FinderPath(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
9959                            DDMTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
9960                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_C_T_M",
9961                            new String[] {
9962                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
9963                                    String.class.getName(), String.class.getName()
9964                            });
9965    
9966            /**
9967             * Returns all the d d m templates where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and mode = &#63;.
9968             *
9969             * @param groupId the group ID
9970             * @param classNameId the class name ID
9971             * @param classPK the class p k
9972             * @param type the type
9973             * @param mode the mode
9974             * @return the matching d d m templates
9975             * @throws SystemException if a system exception occurred
9976             */
9977            @Override
9978            public List<DDMTemplate> findByG_C_C_T_M(long groupId, long classNameId,
9979                    long classPK, String type, String mode) throws SystemException {
9980                    return findByG_C_C_T_M(groupId, classNameId, classPK, type, mode,
9981                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
9982            }
9983    
9984            /**
9985             * Returns a range of all the d d m templates where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and mode = &#63;.
9986             *
9987             * <p>
9988             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9989             * </p>
9990             *
9991             * @param groupId the group ID
9992             * @param classNameId the class name ID
9993             * @param classPK the class p k
9994             * @param type the type
9995             * @param mode the mode
9996             * @param start the lower bound of the range of d d m templates
9997             * @param end the upper bound of the range of d d m templates (not inclusive)
9998             * @return the range of matching d d m templates
9999             * @throws SystemException if a system exception occurred
10000             */
10001            @Override
10002            public List<DDMTemplate> findByG_C_C_T_M(long groupId, long classNameId,
10003                    long classPK, String type, String mode, int start, int end)
10004                    throws SystemException {
10005                    return findByG_C_C_T_M(groupId, classNameId, classPK, type, mode,
10006                            start, end, null);
10007            }
10008    
10009            /**
10010             * Returns an ordered range of all the d d m templates where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and mode = &#63;.
10011             *
10012             * <p>
10013             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10014             * </p>
10015             *
10016             * @param groupId the group ID
10017             * @param classNameId the class name ID
10018             * @param classPK the class p k
10019             * @param type the type
10020             * @param mode the mode
10021             * @param start the lower bound of the range of d d m templates
10022             * @param end the upper bound of the range of d d m templates (not inclusive)
10023             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10024             * @return the ordered range of matching d d m templates
10025             * @throws SystemException if a system exception occurred
10026             */
10027            @Override
10028            public List<DDMTemplate> findByG_C_C_T_M(long groupId, long classNameId,
10029                    long classPK, String type, String mode, int start, int end,
10030                    OrderByComparator orderByComparator) throws SystemException {
10031                    boolean pagination = true;
10032                    FinderPath finderPath = null;
10033                    Object[] finderArgs = null;
10034    
10035                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10036                                    (orderByComparator == null)) {
10037                            pagination = false;
10038                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_T_M;
10039                            finderArgs = new Object[] { groupId, classNameId, classPK, type, mode };
10040                    }
10041                    else {
10042                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C_T_M;
10043                            finderArgs = new Object[] {
10044                                            groupId, classNameId, classPK, type, mode,
10045                                            
10046                                            start, end, orderByComparator
10047                                    };
10048                    }
10049    
10050                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
10051                                    finderArgs, this);
10052    
10053                    if ((list != null) && !list.isEmpty()) {
10054                            for (DDMTemplate ddmTemplate : list) {
10055                                    if ((groupId != ddmTemplate.getGroupId()) ||
10056                                                    (classNameId != ddmTemplate.getClassNameId()) ||
10057                                                    (classPK != ddmTemplate.getClassPK()) ||
10058                                                    !Validator.equals(type, ddmTemplate.getType()) ||
10059                                                    !Validator.equals(mode, ddmTemplate.getMode())) {
10060                                            list = null;
10061    
10062                                            break;
10063                                    }
10064                            }
10065                    }
10066    
10067                    if (list == null) {
10068                            StringBundler query = null;
10069    
10070                            if (orderByComparator != null) {
10071                                    query = new StringBundler(7 +
10072                                                    (orderByComparator.getOrderByFields().length * 3));
10073                            }
10074                            else {
10075                                    query = new StringBundler(7);
10076                            }
10077    
10078                            query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
10079    
10080                            query.append(_FINDER_COLUMN_G_C_C_T_M_GROUPID_2);
10081    
10082                            query.append(_FINDER_COLUMN_G_C_C_T_M_CLASSNAMEID_2);
10083    
10084                            query.append(_FINDER_COLUMN_G_C_C_T_M_CLASSPK_2);
10085    
10086                            boolean bindType = false;
10087    
10088                            if (type == null) {
10089                                    query.append(_FINDER_COLUMN_G_C_C_T_M_TYPE_1);
10090                            }
10091                            else if (type.equals(StringPool.BLANK)) {
10092                                    query.append(_FINDER_COLUMN_G_C_C_T_M_TYPE_3);
10093                            }
10094                            else {
10095                                    bindType = true;
10096    
10097                                    query.append(_FINDER_COLUMN_G_C_C_T_M_TYPE_2);
10098                            }
10099    
10100                            boolean bindMode = false;
10101    
10102                            if (mode == null) {
10103                                    query.append(_FINDER_COLUMN_G_C_C_T_M_MODE_1);
10104                            }
10105                            else if (mode.equals(StringPool.BLANK)) {
10106                                    query.append(_FINDER_COLUMN_G_C_C_T_M_MODE_3);
10107                            }
10108                            else {
10109                                    bindMode = true;
10110    
10111                                    query.append(_FINDER_COLUMN_G_C_C_T_M_MODE_2);
10112                            }
10113    
10114                            if (orderByComparator != null) {
10115                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10116                                            orderByComparator);
10117                            }
10118                            else
10119                             if (pagination) {
10120                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
10121                            }
10122    
10123                            String sql = query.toString();
10124    
10125                            Session session = null;
10126    
10127                            try {
10128                                    session = openSession();
10129    
10130                                    Query q = session.createQuery(sql);
10131    
10132                                    QueryPos qPos = QueryPos.getInstance(q);
10133    
10134                                    qPos.add(groupId);
10135    
10136                                    qPos.add(classNameId);
10137    
10138                                    qPos.add(classPK);
10139    
10140                                    if (bindType) {
10141                                            qPos.add(type);
10142                                    }
10143    
10144                                    if (bindMode) {
10145                                            qPos.add(mode);
10146                                    }
10147    
10148                                    if (!pagination) {
10149                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
10150                                                            start, end, false);
10151    
10152                                            Collections.sort(list);
10153    
10154                                            list = new UnmodifiableList<DDMTemplate>(list);
10155                                    }
10156                                    else {
10157                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
10158                                                            start, end);
10159                                    }
10160    
10161                                    cacheResult(list);
10162    
10163                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
10164                            }
10165                            catch (Exception e) {
10166                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10167    
10168                                    throw processException(e);
10169                            }
10170                            finally {
10171                                    closeSession(session);
10172                            }
10173                    }
10174    
10175                    return list;
10176            }
10177    
10178            /**
10179             * Returns the first d d m template in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and mode = &#63;.
10180             *
10181             * @param groupId the group ID
10182             * @param classNameId the class name ID
10183             * @param classPK the class p k
10184             * @param type the type
10185             * @param mode the mode
10186             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10187             * @return the first matching d d m template
10188             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
10189             * @throws SystemException if a system exception occurred
10190             */
10191            @Override
10192            public DDMTemplate findByG_C_C_T_M_First(long groupId, long classNameId,
10193                    long classPK, String type, String mode,
10194                    OrderByComparator orderByComparator)
10195                    throws NoSuchTemplateException, SystemException {
10196                    DDMTemplate ddmTemplate = fetchByG_C_C_T_M_First(groupId, classNameId,
10197                                    classPK, type, mode, orderByComparator);
10198    
10199                    if (ddmTemplate != null) {
10200                            return ddmTemplate;
10201                    }
10202    
10203                    StringBundler msg = new StringBundler(12);
10204    
10205                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10206    
10207                    msg.append("groupId=");
10208                    msg.append(groupId);
10209    
10210                    msg.append(", classNameId=");
10211                    msg.append(classNameId);
10212    
10213                    msg.append(", classPK=");
10214                    msg.append(classPK);
10215    
10216                    msg.append(", type=");
10217                    msg.append(type);
10218    
10219                    msg.append(", mode=");
10220                    msg.append(mode);
10221    
10222                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10223    
10224                    throw new NoSuchTemplateException(msg.toString());
10225            }
10226    
10227            /**
10228             * Returns the first d d m template in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and mode = &#63;.
10229             *
10230             * @param groupId the group ID
10231             * @param classNameId the class name ID
10232             * @param classPK the class p k
10233             * @param type the type
10234             * @param mode the mode
10235             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10236             * @return the first matching d d m template, or <code>null</code> if a matching d d m template could not be found
10237             * @throws SystemException if a system exception occurred
10238             */
10239            @Override
10240            public DDMTemplate fetchByG_C_C_T_M_First(long groupId, long classNameId,
10241                    long classPK, String type, String mode,
10242                    OrderByComparator orderByComparator) throws SystemException {
10243                    List<DDMTemplate> list = findByG_C_C_T_M(groupId, classNameId, classPK,
10244                                    type, mode, 0, 1, orderByComparator);
10245    
10246                    if (!list.isEmpty()) {
10247                            return list.get(0);
10248                    }
10249    
10250                    return null;
10251            }
10252    
10253            /**
10254             * Returns the last d d m template in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and mode = &#63;.
10255             *
10256             * @param groupId the group ID
10257             * @param classNameId the class name ID
10258             * @param classPK the class p k
10259             * @param type the type
10260             * @param mode the mode
10261             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10262             * @return the last matching d d m template
10263             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a matching d d m template could not be found
10264             * @throws SystemException if a system exception occurred
10265             */
10266            @Override
10267            public DDMTemplate findByG_C_C_T_M_Last(long groupId, long classNameId,
10268                    long classPK, String type, String mode,
10269                    OrderByComparator orderByComparator)
10270                    throws NoSuchTemplateException, SystemException {
10271                    DDMTemplate ddmTemplate = fetchByG_C_C_T_M_Last(groupId, classNameId,
10272                                    classPK, type, mode, orderByComparator);
10273    
10274                    if (ddmTemplate != null) {
10275                            return ddmTemplate;
10276                    }
10277    
10278                    StringBundler msg = new StringBundler(12);
10279    
10280                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10281    
10282                    msg.append("groupId=");
10283                    msg.append(groupId);
10284    
10285                    msg.append(", classNameId=");
10286                    msg.append(classNameId);
10287    
10288                    msg.append(", classPK=");
10289                    msg.append(classPK);
10290    
10291                    msg.append(", type=");
10292                    msg.append(type);
10293    
10294                    msg.append(", mode=");
10295                    msg.append(mode);
10296    
10297                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10298    
10299                    throw new NoSuchTemplateException(msg.toString());
10300            }
10301    
10302            /**
10303             * Returns the last d d m template in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and mode = &#63;.
10304             *
10305             * @param groupId the group ID
10306             * @param classNameId the class name ID
10307             * @param classPK the class p k
10308             * @param type the type
10309             * @param mode the mode
10310             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10311             * @return the last matching d d m template, or <code>null</code> if a matching d d m template could not be found
10312             * @throws SystemException if a system exception occurred
10313             */
10314            @Override
10315            public DDMTemplate fetchByG_C_C_T_M_Last(long groupId, long classNameId,
10316                    long classPK, String type, String mode,
10317                    OrderByComparator orderByComparator) throws SystemException {
10318                    int count = countByG_C_C_T_M(groupId, classNameId, classPK, type, mode);
10319    
10320                    if (count == 0) {
10321                            return null;
10322                    }
10323    
10324                    List<DDMTemplate> list = findByG_C_C_T_M(groupId, classNameId, classPK,
10325                                    type, mode, count - 1, count, orderByComparator);
10326    
10327                    if (!list.isEmpty()) {
10328                            return list.get(0);
10329                    }
10330    
10331                    return null;
10332            }
10333    
10334            /**
10335             * Returns the d d m templates before and after the current d d m template in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and mode = &#63;.
10336             *
10337             * @param templateId the primary key of the current d d m template
10338             * @param groupId the group ID
10339             * @param classNameId the class name ID
10340             * @param classPK the class p k
10341             * @param type the type
10342             * @param mode the mode
10343             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10344             * @return the previous, current, and next d d m template
10345             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
10346             * @throws SystemException if a system exception occurred
10347             */
10348            @Override
10349            public DDMTemplate[] findByG_C_C_T_M_PrevAndNext(long templateId,
10350                    long groupId, long classNameId, long classPK, String type, String mode,
10351                    OrderByComparator orderByComparator)
10352                    throws NoSuchTemplateException, SystemException {
10353                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
10354    
10355                    Session session = null;
10356    
10357                    try {
10358                            session = openSession();
10359    
10360                            DDMTemplate[] array = new DDMTemplateImpl[3];
10361    
10362                            array[0] = getByG_C_C_T_M_PrevAndNext(session, ddmTemplate,
10363                                            groupId, classNameId, classPK, type, mode,
10364                                            orderByComparator, true);
10365    
10366                            array[1] = ddmTemplate;
10367    
10368                            array[2] = getByG_C_C_T_M_PrevAndNext(session, ddmTemplate,
10369                                            groupId, classNameId, classPK, type, mode,
10370                                            orderByComparator, false);
10371    
10372                            return array;
10373                    }
10374                    catch (Exception e) {
10375                            throw processException(e);
10376                    }
10377                    finally {
10378                            closeSession(session);
10379                    }
10380            }
10381    
10382            protected DDMTemplate getByG_C_C_T_M_PrevAndNext(Session session,
10383                    DDMTemplate ddmTemplate, long groupId, long classNameId, long classPK,
10384                    String type, String mode, OrderByComparator orderByComparator,
10385                    boolean previous) {
10386                    StringBundler query = null;
10387    
10388                    if (orderByComparator != null) {
10389                            query = new StringBundler(6 +
10390                                            (orderByComparator.getOrderByFields().length * 6));
10391                    }
10392                    else {
10393                            query = new StringBundler(3);
10394                    }
10395    
10396                    query.append(_SQL_SELECT_DDMTEMPLATE_WHERE);
10397    
10398                    query.append(_FINDER_COLUMN_G_C_C_T_M_GROUPID_2);
10399    
10400                    query.append(_FINDER_COLUMN_G_C_C_T_M_CLASSNAMEID_2);
10401    
10402                    query.append(_FINDER_COLUMN_G_C_C_T_M_CLASSPK_2);
10403    
10404                    boolean bindType = false;
10405    
10406                    if (type == null) {
10407                            query.append(_FINDER_COLUMN_G_C_C_T_M_TYPE_1);
10408                    }
10409                    else if (type.equals(StringPool.BLANK)) {
10410                            query.append(_FINDER_COLUMN_G_C_C_T_M_TYPE_3);
10411                    }
10412                    else {
10413                            bindType = true;
10414    
10415                            query.append(_FINDER_COLUMN_G_C_C_T_M_TYPE_2);
10416                    }
10417    
10418                    boolean bindMode = false;
10419    
10420                    if (mode == null) {
10421                            query.append(_FINDER_COLUMN_G_C_C_T_M_MODE_1);
10422                    }
10423                    else if (mode.equals(StringPool.BLANK)) {
10424                            query.append(_FINDER_COLUMN_G_C_C_T_M_MODE_3);
10425                    }
10426                    else {
10427                            bindMode = true;
10428    
10429                            query.append(_FINDER_COLUMN_G_C_C_T_M_MODE_2);
10430                    }
10431    
10432                    if (orderByComparator != null) {
10433                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10434    
10435                            if (orderByConditionFields.length > 0) {
10436                                    query.append(WHERE_AND);
10437                            }
10438    
10439                            for (int i = 0; i < orderByConditionFields.length; i++) {
10440                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10441                                    query.append(orderByConditionFields[i]);
10442    
10443                                    if ((i + 1) < orderByConditionFields.length) {
10444                                            if (orderByComparator.isAscending() ^ previous) {
10445                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10446                                            }
10447                                            else {
10448                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10449                                            }
10450                                    }
10451                                    else {
10452                                            if (orderByComparator.isAscending() ^ previous) {
10453                                                    query.append(WHERE_GREATER_THAN);
10454                                            }
10455                                            else {
10456                                                    query.append(WHERE_LESSER_THAN);
10457                                            }
10458                                    }
10459                            }
10460    
10461                            query.append(ORDER_BY_CLAUSE);
10462    
10463                            String[] orderByFields = orderByComparator.getOrderByFields();
10464    
10465                            for (int i = 0; i < orderByFields.length; i++) {
10466                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10467                                    query.append(orderByFields[i]);
10468    
10469                                    if ((i + 1) < orderByFields.length) {
10470                                            if (orderByComparator.isAscending() ^ previous) {
10471                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10472                                            }
10473                                            else {
10474                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10475                                            }
10476                                    }
10477                                    else {
10478                                            if (orderByComparator.isAscending() ^ previous) {
10479                                                    query.append(ORDER_BY_ASC);
10480                                            }
10481                                            else {
10482                                                    query.append(ORDER_BY_DESC);
10483                                            }
10484                                    }
10485                            }
10486                    }
10487                    else {
10488                            query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
10489                    }
10490    
10491                    String sql = query.toString();
10492    
10493                    Query q = session.createQuery(sql);
10494    
10495                    q.setFirstResult(0);
10496                    q.setMaxResults(2);
10497    
10498                    QueryPos qPos = QueryPos.getInstance(q);
10499    
10500                    qPos.add(groupId);
10501    
10502                    qPos.add(classNameId);
10503    
10504                    qPos.add(classPK);
10505    
10506                    if (bindType) {
10507                            qPos.add(type);
10508                    }
10509    
10510                    if (bindMode) {
10511                            qPos.add(mode);
10512                    }
10513    
10514                    if (orderByComparator != null) {
10515                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
10516    
10517                            for (Object value : values) {
10518                                    qPos.add(value);
10519                            }
10520                    }
10521    
10522                    List<DDMTemplate> list = q.list();
10523    
10524                    if (list.size() == 2) {
10525                            return list.get(1);
10526                    }
10527                    else {
10528                            return null;
10529                    }
10530            }
10531    
10532            /**
10533             * Returns all the d d m templates that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and mode = &#63;.
10534             *
10535             * @param groupId the group ID
10536             * @param classNameId the class name ID
10537             * @param classPK the class p k
10538             * @param type the type
10539             * @param mode the mode
10540             * @return the matching d d m templates that the user has permission to view
10541             * @throws SystemException if a system exception occurred
10542             */
10543            @Override
10544            public List<DDMTemplate> filterFindByG_C_C_T_M(long groupId,
10545                    long classNameId, long classPK, String type, String mode)
10546                    throws SystemException {
10547                    return filterFindByG_C_C_T_M(groupId, classNameId, classPK, type, mode,
10548                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
10549            }
10550    
10551            /**
10552             * Returns a range of all the d d m templates that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and mode = &#63;.
10553             *
10554             * <p>
10555             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10556             * </p>
10557             *
10558             * @param groupId the group ID
10559             * @param classNameId the class name ID
10560             * @param classPK the class p k
10561             * @param type the type
10562             * @param mode the mode
10563             * @param start the lower bound of the range of d d m templates
10564             * @param end the upper bound of the range of d d m templates (not inclusive)
10565             * @return the range of matching d d m templates that the user has permission to view
10566             * @throws SystemException if a system exception occurred
10567             */
10568            @Override
10569            public List<DDMTemplate> filterFindByG_C_C_T_M(long groupId,
10570                    long classNameId, long classPK, String type, String mode, int start,
10571                    int end) throws SystemException {
10572                    return filterFindByG_C_C_T_M(groupId, classNameId, classPK, type, mode,
10573                            start, end, null);
10574            }
10575    
10576            /**
10577             * Returns an ordered range of all the d d m templates that the user has permissions to view where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and mode = &#63;.
10578             *
10579             * <p>
10580             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10581             * </p>
10582             *
10583             * @param groupId the group ID
10584             * @param classNameId the class name ID
10585             * @param classPK the class p k
10586             * @param type the type
10587             * @param mode the mode
10588             * @param start the lower bound of the range of d d m templates
10589             * @param end the upper bound of the range of d d m templates (not inclusive)
10590             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10591             * @return the ordered range of matching d d m templates that the user has permission to view
10592             * @throws SystemException if a system exception occurred
10593             */
10594            @Override
10595            public List<DDMTemplate> filterFindByG_C_C_T_M(long groupId,
10596                    long classNameId, long classPK, String type, String mode, int start,
10597                    int end, OrderByComparator orderByComparator) throws SystemException {
10598                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10599                            return findByG_C_C_T_M(groupId, classNameId, classPK, type, mode,
10600                                    start, end, orderByComparator);
10601                    }
10602    
10603                    StringBundler query = null;
10604    
10605                    if (orderByComparator != null) {
10606                            query = new StringBundler(7 +
10607                                            (orderByComparator.getOrderByFields().length * 3));
10608                    }
10609                    else {
10610                            query = new StringBundler(7);
10611                    }
10612    
10613                    if (getDB().isSupportsInlineDistinct()) {
10614                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_WHERE);
10615                    }
10616                    else {
10617                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
10618                    }
10619    
10620                    query.append(_FINDER_COLUMN_G_C_C_T_M_GROUPID_2);
10621    
10622                    query.append(_FINDER_COLUMN_G_C_C_T_M_CLASSNAMEID_2);
10623    
10624                    query.append(_FINDER_COLUMN_G_C_C_T_M_CLASSPK_2);
10625    
10626                    boolean bindType = false;
10627    
10628                    if (type == null) {
10629                            query.append(_FINDER_COLUMN_G_C_C_T_M_TYPE_1_SQL);
10630                    }
10631                    else if (type.equals(StringPool.BLANK)) {
10632                            query.append(_FINDER_COLUMN_G_C_C_T_M_TYPE_3_SQL);
10633                    }
10634                    else {
10635                            bindType = true;
10636    
10637                            query.append(_FINDER_COLUMN_G_C_C_T_M_TYPE_2_SQL);
10638                    }
10639    
10640                    boolean bindMode = false;
10641    
10642                    if (mode == null) {
10643                            query.append(_FINDER_COLUMN_G_C_C_T_M_MODE_1_SQL);
10644                    }
10645                    else if (mode.equals(StringPool.BLANK)) {
10646                            query.append(_FINDER_COLUMN_G_C_C_T_M_MODE_3_SQL);
10647                    }
10648                    else {
10649                            bindMode = true;
10650    
10651                            query.append(_FINDER_COLUMN_G_C_C_T_M_MODE_2_SQL);
10652                    }
10653    
10654                    if (!getDB().isSupportsInlineDistinct()) {
10655                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
10656                    }
10657    
10658                    if (orderByComparator != null) {
10659                            if (getDB().isSupportsInlineDistinct()) {
10660                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10661                                            orderByComparator, true);
10662                            }
10663                            else {
10664                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
10665                                            orderByComparator, true);
10666                            }
10667                    }
10668                    else {
10669                            if (getDB().isSupportsInlineDistinct()) {
10670                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
10671                            }
10672                            else {
10673                                    query.append(DDMTemplateModelImpl.ORDER_BY_SQL);
10674                            }
10675                    }
10676    
10677                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10678                                    DDMTemplate.class.getName(),
10679                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10680    
10681                    Session session = null;
10682    
10683                    try {
10684                            session = openSession();
10685    
10686                            SQLQuery q = session.createSQLQuery(sql);
10687    
10688                            if (getDB().isSupportsInlineDistinct()) {
10689                                    q.addEntity(_FILTER_ENTITY_ALIAS, DDMTemplateImpl.class);
10690                            }
10691                            else {
10692                                    q.addEntity(_FILTER_ENTITY_TABLE, DDMTemplateImpl.class);
10693                            }
10694    
10695                            QueryPos qPos = QueryPos.getInstance(q);
10696    
10697                            qPos.add(groupId);
10698    
10699                            qPos.add(classNameId);
10700    
10701                            qPos.add(classPK);
10702    
10703                            if (bindType) {
10704                                    qPos.add(type);
10705                            }
10706    
10707                            if (bindMode) {
10708                                    qPos.add(mode);
10709                            }
10710    
10711                            return (List<DDMTemplate>)QueryUtil.list(q, getDialect(), start, end);
10712                    }
10713                    catch (Exception e) {
10714                            throw processException(e);
10715                    }
10716                    finally {
10717                            closeSession(session);
10718                    }
10719            }
10720    
10721            /**
10722             * Returns the d d m templates before and after the current d d m template in the ordered set of d d m templates that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and mode = &#63;.
10723             *
10724             * @param templateId the primary key of the current d d m template
10725             * @param groupId the group ID
10726             * @param classNameId the class name ID
10727             * @param classPK the class p k
10728             * @param type the type
10729             * @param mode the mode
10730             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10731             * @return the previous, current, and next d d m template
10732             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
10733             * @throws SystemException if a system exception occurred
10734             */
10735            @Override
10736            public DDMTemplate[] filterFindByG_C_C_T_M_PrevAndNext(long templateId,
10737                    long groupId, long classNameId, long classPK, String type, String mode,
10738                    OrderByComparator orderByComparator)
10739                    throws NoSuchTemplateException, SystemException {
10740                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10741                            return findByG_C_C_T_M_PrevAndNext(templateId, groupId,
10742                                    classNameId, classPK, type, mode, orderByComparator);
10743                    }
10744    
10745                    DDMTemplate ddmTemplate = findByPrimaryKey(templateId);
10746    
10747                    Session session = null;
10748    
10749                    try {
10750                            session = openSession();
10751    
10752                            DDMTemplate[] array = new DDMTemplateImpl[3];
10753    
10754                            array[0] = filterGetByG_C_C_T_M_PrevAndNext(session, ddmTemplate,
10755                                            groupId, classNameId, classPK, type, mode,
10756                                            orderByComparator, true);
10757    
10758                            array[1] = ddmTemplate;
10759    
10760                            array[2] = filterGetByG_C_C_T_M_PrevAndNext(session, ddmTemplate,
10761                                            groupId, classNameId, classPK, type, mode,
10762                                            orderByComparator, false);
10763    
10764                            return array;
10765                    }
10766                    catch (Exception e) {
10767                            throw processException(e);
10768                    }
10769                    finally {
10770                            closeSession(session);
10771                    }
10772            }
10773    
10774            protected DDMTemplate filterGetByG_C_C_T_M_PrevAndNext(Session session,
10775                    DDMTemplate ddmTemplate, long groupId, long classNameId, long classPK,
10776                    String type, String mode, OrderByComparator orderByComparator,
10777                    boolean previous) {
10778                    StringBundler query = null;
10779    
10780                    if (orderByComparator != null) {
10781                            query = new StringBundler(6 +
10782                                            (orderByComparator.getOrderByFields().length * 6));
10783                    }
10784                    else {
10785                            query = new StringBundler(3);
10786                    }
10787    
10788                    if (getDB().isSupportsInlineDistinct()) {
10789                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_WHERE);
10790                    }
10791                    else {
10792                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
10793                    }
10794    
10795                    query.append(_FINDER_COLUMN_G_C_C_T_M_GROUPID_2);
10796    
10797                    query.append(_FINDER_COLUMN_G_C_C_T_M_CLASSNAMEID_2);
10798    
10799                    query.append(_FINDER_COLUMN_G_C_C_T_M_CLASSPK_2);
10800    
10801                    boolean bindType = false;
10802    
10803                    if (type == null) {
10804                            query.append(_FINDER_COLUMN_G_C_C_T_M_TYPE_1_SQL);
10805                    }
10806                    else if (type.equals(StringPool.BLANK)) {
10807                            query.append(_FINDER_COLUMN_G_C_C_T_M_TYPE_3_SQL);
10808                    }
10809                    else {
10810                            bindType = true;
10811    
10812                            query.append(_FINDER_COLUMN_G_C_C_T_M_TYPE_2_SQL);
10813                    }
10814    
10815                    boolean bindMode = false;
10816    
10817                    if (mode == null) {
10818                            query.append(_FINDER_COLUMN_G_C_C_T_M_MODE_1_SQL);
10819                    }
10820                    else if (mode.equals(StringPool.BLANK)) {
10821                            query.append(_FINDER_COLUMN_G_C_C_T_M_MODE_3_SQL);
10822                    }
10823                    else {
10824                            bindMode = true;
10825    
10826                            query.append(_FINDER_COLUMN_G_C_C_T_M_MODE_2_SQL);
10827                    }
10828    
10829                    if (!getDB().isSupportsInlineDistinct()) {
10830                            query.append(_FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
10831                    }
10832    
10833                    if (orderByComparator != null) {
10834                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10835    
10836                            if (orderByConditionFields.length > 0) {
10837                                    query.append(WHERE_AND);
10838                            }
10839    
10840                            for (int i = 0; i < orderByConditionFields.length; i++) {
10841                                    if (getDB().isSupportsInlineDistinct()) {
10842                                            query.append(_ORDER_BY_ENTITY_ALIAS);
10843                                    }
10844                                    else {
10845                                            query.append(_ORDER_BY_ENTITY_TABLE);
10846                                    }
10847    
10848                                    query.append(orderByConditionFields[i]);
10849    
10850                                    if ((i + 1) < orderByConditionFields.length) {
10851                                            if (orderByComparator.isAscending() ^ previous) {
10852                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10853                                            }
10854                                            else {
10855                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10856                                            }
10857                                    }
10858                                    else {
10859                                            if (orderByComparator.isAscending() ^ previous) {
10860                                                    query.append(WHERE_GREATER_THAN);
10861                                            }
10862                                            else {
10863                                                    query.append(WHERE_LESSER_THAN);
10864                                            }
10865                                    }
10866                            }
10867    
10868                            query.append(ORDER_BY_CLAUSE);
10869    
10870                            String[] orderByFields = orderByComparator.getOrderByFields();
10871    
10872                            for (int i = 0; i < orderByFields.length; i++) {
10873                                    if (getDB().isSupportsInlineDistinct()) {
10874                                            query.append(_ORDER_BY_ENTITY_ALIAS);
10875                                    }
10876                                    else {
10877                                            query.append(_ORDER_BY_ENTITY_TABLE);
10878                                    }
10879    
10880                                    query.append(orderByFields[i]);
10881    
10882                                    if ((i + 1) < orderByFields.length) {
10883                                            if (orderByComparator.isAscending() ^ previous) {
10884                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10885                                            }
10886                                            else {
10887                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10888                                            }
10889                                    }
10890                                    else {
10891                                            if (orderByComparator.isAscending() ^ previous) {
10892                                                    query.append(ORDER_BY_ASC);
10893                                            }
10894                                            else {
10895                                                    query.append(ORDER_BY_DESC);
10896                                            }
10897                                    }
10898                            }
10899                    }
10900                    else {
10901                            if (getDB().isSupportsInlineDistinct()) {
10902                                    query.append(DDMTemplateModelImpl.ORDER_BY_JPQL);
10903                            }
10904                            else {
10905                                    query.append(DDMTemplateModelImpl.ORDER_BY_SQL);
10906                            }
10907                    }
10908    
10909                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10910                                    DDMTemplate.class.getName(),
10911                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10912    
10913                    SQLQuery q = session.createSQLQuery(sql);
10914    
10915                    q.setFirstResult(0);
10916                    q.setMaxResults(2);
10917    
10918                    if (getDB().isSupportsInlineDistinct()) {
10919                            q.addEntity(_FILTER_ENTITY_ALIAS, DDMTemplateImpl.class);
10920                    }
10921                    else {
10922                            q.addEntity(_FILTER_ENTITY_TABLE, DDMTemplateImpl.class);
10923                    }
10924    
10925                    QueryPos qPos = QueryPos.getInstance(q);
10926    
10927                    qPos.add(groupId);
10928    
10929                    qPos.add(classNameId);
10930    
10931                    qPos.add(classPK);
10932    
10933                    if (bindType) {
10934                            qPos.add(type);
10935                    }
10936    
10937                    if (bindMode) {
10938                            qPos.add(mode);
10939                    }
10940    
10941                    if (orderByComparator != null) {
10942                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplate);
10943    
10944                            for (Object value : values) {
10945                                    qPos.add(value);
10946                            }
10947                    }
10948    
10949                    List<DDMTemplate> list = q.list();
10950    
10951                    if (list.size() == 2) {
10952                            return list.get(1);
10953                    }
10954                    else {
10955                            return null;
10956                    }
10957            }
10958    
10959            /**
10960             * Removes all the d d m templates where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and mode = &#63; from the database.
10961             *
10962             * @param groupId the group ID
10963             * @param classNameId the class name ID
10964             * @param classPK the class p k
10965             * @param type the type
10966             * @param mode the mode
10967             * @throws SystemException if a system exception occurred
10968             */
10969            @Override
10970            public void removeByG_C_C_T_M(long groupId, long classNameId, long classPK,
10971                    String type, String mode) throws SystemException {
10972                    for (DDMTemplate ddmTemplate : findByG_C_C_T_M(groupId, classNameId,
10973                                    classPK, type, mode, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10974                            remove(ddmTemplate);
10975                    }
10976            }
10977    
10978            /**
10979             * Returns the number of d d m templates where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and mode = &#63;.
10980             *
10981             * @param groupId the group ID
10982             * @param classNameId the class name ID
10983             * @param classPK the class p k
10984             * @param type the type
10985             * @param mode the mode
10986             * @return the number of matching d d m templates
10987             * @throws SystemException if a system exception occurred
10988             */
10989            @Override
10990            public int countByG_C_C_T_M(long groupId, long classNameId, long classPK,
10991                    String type, String mode) throws SystemException {
10992                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_C_T_M;
10993    
10994                    Object[] finderArgs = new Object[] {
10995                                    groupId, classNameId, classPK, type, mode
10996                            };
10997    
10998                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10999                                    this);
11000    
11001                    if (count == null) {
11002                            StringBundler query = new StringBundler(6);
11003    
11004                            query.append(_SQL_COUNT_DDMTEMPLATE_WHERE);
11005    
11006                            query.append(_FINDER_COLUMN_G_C_C_T_M_GROUPID_2);
11007    
11008                            query.append(_FINDER_COLUMN_G_C_C_T_M_CLASSNAMEID_2);
11009    
11010                            query.append(_FINDER_COLUMN_G_C_C_T_M_CLASSPK_2);
11011    
11012                            boolean bindType = false;
11013    
11014                            if (type == null) {
11015                                    query.append(_FINDER_COLUMN_G_C_C_T_M_TYPE_1);
11016                            }
11017                            else if (type.equals(StringPool.BLANK)) {
11018                                    query.append(_FINDER_COLUMN_G_C_C_T_M_TYPE_3);
11019                            }
11020                            else {
11021                                    bindType = true;
11022    
11023                                    query.append(_FINDER_COLUMN_G_C_C_T_M_TYPE_2);
11024                            }
11025    
11026                            boolean bindMode = false;
11027    
11028                            if (mode == null) {
11029                                    query.append(_FINDER_COLUMN_G_C_C_T_M_MODE_1);
11030                            }
11031                            else if (mode.equals(StringPool.BLANK)) {
11032                                    query.append(_FINDER_COLUMN_G_C_C_T_M_MODE_3);
11033                            }
11034                            else {
11035                                    bindMode = true;
11036    
11037                                    query.append(_FINDER_COLUMN_G_C_C_T_M_MODE_2);
11038                            }
11039    
11040                            String sql = query.toString();
11041    
11042                            Session session = null;
11043    
11044                            try {
11045                                    session = openSession();
11046    
11047                                    Query q = session.createQuery(sql);
11048    
11049                                    QueryPos qPos = QueryPos.getInstance(q);
11050    
11051                                    qPos.add(groupId);
11052    
11053                                    qPos.add(classNameId);
11054    
11055                                    qPos.add(classPK);
11056    
11057                                    if (bindType) {
11058                                            qPos.add(type);
11059                                    }
11060    
11061                                    if (bindMode) {
11062                                            qPos.add(mode);
11063                                    }
11064    
11065                                    count = (Long)q.uniqueResult();
11066    
11067                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
11068                            }
11069                            catch (Exception e) {
11070                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11071    
11072                                    throw processException(e);
11073                            }
11074                            finally {
11075                                    closeSession(session);
11076                            }
11077                    }
11078    
11079                    return count.intValue();
11080            }
11081    
11082            /**
11083             * Returns the number of d d m templates that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and mode = &#63;.
11084             *
11085             * @param groupId the group ID
11086             * @param classNameId the class name ID
11087             * @param classPK the class p k
11088             * @param type the type
11089             * @param mode the mode
11090             * @return the number of matching d d m templates that the user has permission to view
11091             * @throws SystemException if a system exception occurred
11092             */
11093            @Override
11094            public int filterCountByG_C_C_T_M(long groupId, long classNameId,
11095                    long classPK, String type, String mode) throws SystemException {
11096                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11097                            return countByG_C_C_T_M(groupId, classNameId, classPK, type, mode);
11098                    }
11099    
11100                    StringBundler query = new StringBundler(6);
11101    
11102                    query.append(_FILTER_SQL_COUNT_DDMTEMPLATE_WHERE);
11103    
11104                    query.append(_FINDER_COLUMN_G_C_C_T_M_GROUPID_2);
11105    
11106                    query.append(_FINDER_COLUMN_G_C_C_T_M_CLASSNAMEID_2);
11107    
11108                    query.append(_FINDER_COLUMN_G_C_C_T_M_CLASSPK_2);
11109    
11110                    boolean bindType = false;
11111    
11112                    if (type == null) {
11113                            query.append(_FINDER_COLUMN_G_C_C_T_M_TYPE_1_SQL);
11114                    }
11115                    else if (type.equals(StringPool.BLANK)) {
11116                            query.append(_FINDER_COLUMN_G_C_C_T_M_TYPE_3_SQL);
11117                    }
11118                    else {
11119                            bindType = true;
11120    
11121                            query.append(_FINDER_COLUMN_G_C_C_T_M_TYPE_2_SQL);
11122                    }
11123    
11124                    boolean bindMode = false;
11125    
11126                    if (mode == null) {
11127                            query.append(_FINDER_COLUMN_G_C_C_T_M_MODE_1_SQL);
11128                    }
11129                    else if (mode.equals(StringPool.BLANK)) {
11130                            query.append(_FINDER_COLUMN_G_C_C_T_M_MODE_3_SQL);
11131                    }
11132                    else {
11133                            bindMode = true;
11134    
11135                            query.append(_FINDER_COLUMN_G_C_C_T_M_MODE_2_SQL);
11136                    }
11137    
11138                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11139                                    DDMTemplate.class.getName(),
11140                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11141    
11142                    Session session = null;
11143    
11144                    try {
11145                            session = openSession();
11146    
11147                            SQLQuery q = session.createSQLQuery(sql);
11148    
11149                            q.addScalar(COUNT_COLUMN_NAME,
11150                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
11151    
11152                            QueryPos qPos = QueryPos.getInstance(q);
11153    
11154                            qPos.add(groupId);
11155    
11156                            qPos.add(classNameId);
11157    
11158                            qPos.add(classPK);
11159    
11160                            if (bindType) {
11161                                    qPos.add(type);
11162                            }
11163    
11164                            if (bindMode) {
11165                                    qPos.add(mode);
11166                            }
11167    
11168                            Long count = (Long)q.uniqueResult();
11169    
11170                            return count.intValue();
11171                    }
11172                    catch (Exception e) {
11173                            throw processException(e);
11174                    }
11175                    finally {
11176                            closeSession(session);
11177                    }
11178            }
11179    
11180            private static final String _FINDER_COLUMN_G_C_C_T_M_GROUPID_2 = "ddmTemplate.groupId = ? AND ";
11181            private static final String _FINDER_COLUMN_G_C_C_T_M_CLASSNAMEID_2 = "ddmTemplate.classNameId = ? AND ";
11182            private static final String _FINDER_COLUMN_G_C_C_T_M_CLASSPK_2 = "ddmTemplate.classPK = ? AND ";
11183            private static final String _FINDER_COLUMN_G_C_C_T_M_TYPE_1 = "ddmTemplate.type IS NULL AND ";
11184            private static final String _FINDER_COLUMN_G_C_C_T_M_TYPE_2 = "ddmTemplate.type = ? AND ";
11185            private static final String _FINDER_COLUMN_G_C_C_T_M_TYPE_3 = "(ddmTemplate.type IS NULL OR ddmTemplate.type = '') AND ";
11186            private static final String _FINDER_COLUMN_G_C_C_T_M_TYPE_1_SQL = "ddmTemplate.type_ IS NULL AND ";
11187            private static final String _FINDER_COLUMN_G_C_C_T_M_TYPE_2_SQL = "ddmTemplate.type_ = ? AND ";
11188            private static final String _FINDER_COLUMN_G_C_C_T_M_TYPE_3_SQL = "(ddmTemplate.type_ IS NULL OR ddmTemplate.type_ = '') AND ";
11189            private static final String _FINDER_COLUMN_G_C_C_T_M_MODE_1 = "ddmTemplate.mode IS NULL";
11190            private static final String _FINDER_COLUMN_G_C_C_T_M_MODE_2 = "ddmTemplate.mode = ?";
11191            private static final String _FINDER_COLUMN_G_C_C_T_M_MODE_3 = "(ddmTemplate.mode IS NULL OR ddmTemplate.mode = '')";
11192            private static final String _FINDER_COLUMN_G_C_C_T_M_MODE_1_SQL = "ddmTemplate.mode_ IS NULL";
11193            private static final String _FINDER_COLUMN_G_C_C_T_M_MODE_2_SQL = "ddmTemplate.mode_ = ?";
11194            private static final String _FINDER_COLUMN_G_C_C_T_M_MODE_3_SQL = "(ddmTemplate.mode_ IS NULL OR ddmTemplate.mode_ = '')";
11195    
11196            public DDMTemplatePersistenceImpl() {
11197                    setModelClass(DDMTemplate.class);
11198            }
11199    
11200            /**
11201             * Caches the d d m template in the entity cache if it is enabled.
11202             *
11203             * @param ddmTemplate the d d m template
11204             */
11205            @Override
11206            public void cacheResult(DDMTemplate ddmTemplate) {
11207                    EntityCacheUtil.putResult(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
11208                            DDMTemplateImpl.class, ddmTemplate.getPrimaryKey(), ddmTemplate);
11209    
11210                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
11211                            new Object[] { ddmTemplate.getUuid(), ddmTemplate.getGroupId() },
11212                            ddmTemplate);
11213    
11214                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
11215                            new Object[] { ddmTemplate.getSmallImageId() }, ddmTemplate);
11216    
11217                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_T,
11218                            new Object[] {
11219                                    ddmTemplate.getGroupId(), ddmTemplate.getClassNameId(),
11220                                    ddmTemplate.getTemplateKey()
11221                            }, ddmTemplate);
11222    
11223                    ddmTemplate.resetOriginalValues();
11224            }
11225    
11226            /**
11227             * Caches the d d m templates in the entity cache if it is enabled.
11228             *
11229             * @param ddmTemplates the d d m templates
11230             */
11231            @Override
11232            public void cacheResult(List<DDMTemplate> ddmTemplates) {
11233                    for (DDMTemplate ddmTemplate : ddmTemplates) {
11234                            if (EntityCacheUtil.getResult(
11235                                                    DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
11236                                                    DDMTemplateImpl.class, ddmTemplate.getPrimaryKey()) == null) {
11237                                    cacheResult(ddmTemplate);
11238                            }
11239                            else {
11240                                    ddmTemplate.resetOriginalValues();
11241                            }
11242                    }
11243            }
11244    
11245            /**
11246             * Clears the cache for all d d m templates.
11247             *
11248             * <p>
11249             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
11250             * </p>
11251             */
11252            @Override
11253            public void clearCache() {
11254                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
11255                            CacheRegistryUtil.clear(DDMTemplateImpl.class.getName());
11256                    }
11257    
11258                    EntityCacheUtil.clearCache(DDMTemplateImpl.class.getName());
11259    
11260                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
11261                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
11262                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
11263            }
11264    
11265            /**
11266             * Clears the cache for the d d m template.
11267             *
11268             * <p>
11269             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
11270             * </p>
11271             */
11272            @Override
11273            public void clearCache(DDMTemplate ddmTemplate) {
11274                    EntityCacheUtil.removeResult(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
11275                            DDMTemplateImpl.class, ddmTemplate.getPrimaryKey());
11276    
11277                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
11278                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
11279    
11280                    clearUniqueFindersCache(ddmTemplate);
11281            }
11282    
11283            @Override
11284            public void clearCache(List<DDMTemplate> ddmTemplates) {
11285                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
11286                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
11287    
11288                    for (DDMTemplate ddmTemplate : ddmTemplates) {
11289                            EntityCacheUtil.removeResult(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
11290                                    DDMTemplateImpl.class, ddmTemplate.getPrimaryKey());
11291    
11292                            clearUniqueFindersCache(ddmTemplate);
11293                    }
11294            }
11295    
11296            protected void cacheUniqueFindersCache(DDMTemplate ddmTemplate) {
11297                    if (ddmTemplate.isNew()) {
11298                            Object[] args = new Object[] {
11299                                            ddmTemplate.getUuid(), ddmTemplate.getGroupId()
11300                                    };
11301    
11302                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
11303                                    Long.valueOf(1));
11304                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
11305                                    ddmTemplate);
11306    
11307                            args = new Object[] { ddmTemplate.getSmallImageId() };
11308    
11309                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID, args,
11310                                    Long.valueOf(1));
11311                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID, args,
11312                                    ddmTemplate);
11313    
11314                            args = new Object[] {
11315                                            ddmTemplate.getGroupId(), ddmTemplate.getClassNameId(),
11316                                            ddmTemplate.getTemplateKey()
11317                                    };
11318    
11319                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_T, args,
11320                                    Long.valueOf(1));
11321                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_T, args,
11322                                    ddmTemplate);
11323                    }
11324                    else {
11325                            DDMTemplateModelImpl ddmTemplateModelImpl = (DDMTemplateModelImpl)ddmTemplate;
11326    
11327                            if ((ddmTemplateModelImpl.getColumnBitmask() &
11328                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
11329                                    Object[] args = new Object[] {
11330                                                    ddmTemplate.getUuid(), ddmTemplate.getGroupId()
11331                                            };
11332    
11333                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
11334                                            Long.valueOf(1));
11335                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
11336                                            ddmTemplate);
11337                            }
11338    
11339                            if ((ddmTemplateModelImpl.getColumnBitmask() &
11340                                            FINDER_PATH_FETCH_BY_SMALLIMAGEID.getColumnBitmask()) != 0) {
11341                                    Object[] args = new Object[] { ddmTemplate.getSmallImageId() };
11342    
11343                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID,
11344                                            args, Long.valueOf(1));
11345                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
11346                                            args, ddmTemplate);
11347                            }
11348    
11349                            if ((ddmTemplateModelImpl.getColumnBitmask() &
11350                                            FINDER_PATH_FETCH_BY_G_C_T.getColumnBitmask()) != 0) {
11351                                    Object[] args = new Object[] {
11352                                                    ddmTemplate.getGroupId(), ddmTemplate.getClassNameId(),
11353                                                    ddmTemplate.getTemplateKey()
11354                                            };
11355    
11356                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_T, args,
11357                                            Long.valueOf(1));
11358                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_T, args,
11359                                            ddmTemplate);
11360                            }
11361                    }
11362            }
11363    
11364            protected void clearUniqueFindersCache(DDMTemplate ddmTemplate) {
11365                    DDMTemplateModelImpl ddmTemplateModelImpl = (DDMTemplateModelImpl)ddmTemplate;
11366    
11367                    Object[] args = new Object[] {
11368                                    ddmTemplate.getUuid(), ddmTemplate.getGroupId()
11369                            };
11370    
11371                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
11372                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
11373    
11374                    if ((ddmTemplateModelImpl.getColumnBitmask() &
11375                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
11376                            args = new Object[] {
11377                                            ddmTemplateModelImpl.getOriginalUuid(),
11378                                            ddmTemplateModelImpl.getOriginalGroupId()
11379                                    };
11380    
11381                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
11382                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
11383                    }
11384    
11385                    args = new Object[] { ddmTemplate.getSmallImageId() };
11386    
11387                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID, args);
11388                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID, args);
11389    
11390                    if ((ddmTemplateModelImpl.getColumnBitmask() &
11391                                    FINDER_PATH_FETCH_BY_SMALLIMAGEID.getColumnBitmask()) != 0) {
11392                            args = new Object[] { ddmTemplateModelImpl.getOriginalSmallImageId() };
11393    
11394                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID, args);
11395                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID, args);
11396                    }
11397    
11398                    args = new Object[] {
11399                                    ddmTemplate.getGroupId(), ddmTemplate.getClassNameId(),
11400                                    ddmTemplate.getTemplateKey()
11401                            };
11402    
11403                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
11404                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_T, args);
11405    
11406                    if ((ddmTemplateModelImpl.getColumnBitmask() &
11407                                    FINDER_PATH_FETCH_BY_G_C_T.getColumnBitmask()) != 0) {
11408                            args = new Object[] {
11409                                            ddmTemplateModelImpl.getOriginalGroupId(),
11410                                            ddmTemplateModelImpl.getOriginalClassNameId(),
11411                                            ddmTemplateModelImpl.getOriginalTemplateKey()
11412                                    };
11413    
11414                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
11415                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_T, args);
11416                    }
11417            }
11418    
11419            /**
11420             * Creates a new d d m template with the primary key. Does not add the d d m template to the database.
11421             *
11422             * @param templateId the primary key for the new d d m template
11423             * @return the new d d m template
11424             */
11425            @Override
11426            public DDMTemplate create(long templateId) {
11427                    DDMTemplate ddmTemplate = new DDMTemplateImpl();
11428    
11429                    ddmTemplate.setNew(true);
11430                    ddmTemplate.setPrimaryKey(templateId);
11431    
11432                    String uuid = PortalUUIDUtil.generate();
11433    
11434                    ddmTemplate.setUuid(uuid);
11435    
11436                    return ddmTemplate;
11437            }
11438    
11439            /**
11440             * Removes the d d m template with the primary key from the database. Also notifies the appropriate model listeners.
11441             *
11442             * @param templateId the primary key of the d d m template
11443             * @return the d d m template that was removed
11444             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
11445             * @throws SystemException if a system exception occurred
11446             */
11447            @Override
11448            public DDMTemplate remove(long templateId)
11449                    throws NoSuchTemplateException, SystemException {
11450                    return remove((Serializable)templateId);
11451            }
11452    
11453            /**
11454             * Removes the d d m template with the primary key from the database. Also notifies the appropriate model listeners.
11455             *
11456             * @param primaryKey the primary key of the d d m template
11457             * @return the d d m template that was removed
11458             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
11459             * @throws SystemException if a system exception occurred
11460             */
11461            @Override
11462            public DDMTemplate remove(Serializable primaryKey)
11463                    throws NoSuchTemplateException, SystemException {
11464                    Session session = null;
11465    
11466                    try {
11467                            session = openSession();
11468    
11469                            DDMTemplate ddmTemplate = (DDMTemplate)session.get(DDMTemplateImpl.class,
11470                                            primaryKey);
11471    
11472                            if (ddmTemplate == null) {
11473                                    if (_log.isWarnEnabled()) {
11474                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
11475                                    }
11476    
11477                                    throw new NoSuchTemplateException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
11478                                            primaryKey);
11479                            }
11480    
11481                            return remove(ddmTemplate);
11482                    }
11483                    catch (NoSuchTemplateException nsee) {
11484                            throw nsee;
11485                    }
11486                    catch (Exception e) {
11487                            throw processException(e);
11488                    }
11489                    finally {
11490                            closeSession(session);
11491                    }
11492            }
11493    
11494            @Override
11495            protected DDMTemplate removeImpl(DDMTemplate ddmTemplate)
11496                    throws SystemException {
11497                    ddmTemplate = toUnwrappedModel(ddmTemplate);
11498    
11499                    Session session = null;
11500    
11501                    try {
11502                            session = openSession();
11503    
11504                            if (!session.contains(ddmTemplate)) {
11505                                    ddmTemplate = (DDMTemplate)session.get(DDMTemplateImpl.class,
11506                                                    ddmTemplate.getPrimaryKeyObj());
11507                            }
11508    
11509                            if (ddmTemplate != null) {
11510                                    session.delete(ddmTemplate);
11511                            }
11512                    }
11513                    catch (Exception e) {
11514                            throw processException(e);
11515                    }
11516                    finally {
11517                            closeSession(session);
11518                    }
11519    
11520                    if (ddmTemplate != null) {
11521                            clearCache(ddmTemplate);
11522                    }
11523    
11524                    return ddmTemplate;
11525            }
11526    
11527            @Override
11528            public DDMTemplate updateImpl(
11529                    com.liferay.portlet.dynamicdatamapping.model.DDMTemplate ddmTemplate)
11530                    throws SystemException {
11531                    ddmTemplate = toUnwrappedModel(ddmTemplate);
11532    
11533                    boolean isNew = ddmTemplate.isNew();
11534    
11535                    DDMTemplateModelImpl ddmTemplateModelImpl = (DDMTemplateModelImpl)ddmTemplate;
11536    
11537                    if (Validator.isNull(ddmTemplate.getUuid())) {
11538                            String uuid = PortalUUIDUtil.generate();
11539    
11540                            ddmTemplate.setUuid(uuid);
11541                    }
11542    
11543                    Session session = null;
11544    
11545                    try {
11546                            session = openSession();
11547    
11548                            if (ddmTemplate.isNew()) {
11549                                    session.save(ddmTemplate);
11550    
11551                                    ddmTemplate.setNew(false);
11552                            }
11553                            else {
11554                                    session.merge(ddmTemplate);
11555                            }
11556                    }
11557                    catch (Exception e) {
11558                            throw processException(e);
11559                    }
11560                    finally {
11561                            closeSession(session);
11562                    }
11563    
11564                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
11565    
11566                    if (isNew || !DDMTemplateModelImpl.COLUMN_BITMASK_ENABLED) {
11567                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
11568                    }
11569    
11570                    else {
11571                            if ((ddmTemplateModelImpl.getColumnBitmask() &
11572                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
11573                                    Object[] args = new Object[] {
11574                                                    ddmTemplateModelImpl.getOriginalUuid()
11575                                            };
11576    
11577                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
11578                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
11579                                            args);
11580    
11581                                    args = new Object[] { ddmTemplateModelImpl.getUuid() };
11582    
11583                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
11584                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
11585                                            args);
11586                            }
11587    
11588                            if ((ddmTemplateModelImpl.getColumnBitmask() &
11589                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
11590                                    Object[] args = new Object[] {
11591                                                    ddmTemplateModelImpl.getOriginalUuid(),
11592                                                    ddmTemplateModelImpl.getOriginalCompanyId()
11593                                            };
11594    
11595                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
11596                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
11597                                            args);
11598    
11599                                    args = new Object[] {
11600                                                    ddmTemplateModelImpl.getUuid(),
11601                                                    ddmTemplateModelImpl.getCompanyId()
11602                                            };
11603    
11604                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
11605                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
11606                                            args);
11607                            }
11608    
11609                            if ((ddmTemplateModelImpl.getColumnBitmask() &
11610                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
11611                                    Object[] args = new Object[] {
11612                                                    ddmTemplateModelImpl.getOriginalGroupId()
11613                                            };
11614    
11615                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
11616                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
11617                                            args);
11618    
11619                                    args = new Object[] { ddmTemplateModelImpl.getGroupId() };
11620    
11621                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
11622                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
11623                                            args);
11624                            }
11625    
11626                            if ((ddmTemplateModelImpl.getColumnBitmask() &
11627                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSPK.getColumnBitmask()) != 0) {
11628                                    Object[] args = new Object[] {
11629                                                    ddmTemplateModelImpl.getOriginalClassPK()
11630                                            };
11631    
11632                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSPK, args);
11633                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSPK,
11634                                            args);
11635    
11636                                    args = new Object[] { ddmTemplateModelImpl.getClassPK() };
11637    
11638                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSPK, args);
11639                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSPK,
11640                                            args);
11641                            }
11642    
11643                            if ((ddmTemplateModelImpl.getColumnBitmask() &
11644                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEKEY.getColumnBitmask()) != 0) {
11645                                    Object[] args = new Object[] {
11646                                                    ddmTemplateModelImpl.getOriginalTemplateKey()
11647                                            };
11648    
11649                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TEMPLATEKEY,
11650                                            args);
11651                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEKEY,
11652                                            args);
11653    
11654                                    args = new Object[] { ddmTemplateModelImpl.getTemplateKey() };
11655    
11656                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TEMPLATEKEY,
11657                                            args);
11658                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEKEY,
11659                                            args);
11660                            }
11661    
11662                            if ((ddmTemplateModelImpl.getColumnBitmask() &
11663                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE.getColumnBitmask()) != 0) {
11664                                    Object[] args = new Object[] {
11665                                                    ddmTemplateModelImpl.getOriginalType()
11666                                            };
11667    
11668                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
11669                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
11670                                            args);
11671    
11672                                    args = new Object[] { ddmTemplateModelImpl.getType() };
11673    
11674                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
11675                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
11676                                            args);
11677                            }
11678    
11679                            if ((ddmTemplateModelImpl.getColumnBitmask() &
11680                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LANGUAGE.getColumnBitmask()) != 0) {
11681                                    Object[] args = new Object[] {
11682                                                    ddmTemplateModelImpl.getOriginalLanguage()
11683                                            };
11684    
11685                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LANGUAGE, args);
11686                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LANGUAGE,
11687                                            args);
11688    
11689                                    args = new Object[] { ddmTemplateModelImpl.getLanguage() };
11690    
11691                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LANGUAGE, args);
11692                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LANGUAGE,
11693                                            args);
11694                            }
11695    
11696                            if ((ddmTemplateModelImpl.getColumnBitmask() &
11697                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
11698                                    Object[] args = new Object[] {
11699                                                    ddmTemplateModelImpl.getOriginalGroupId(),
11700                                                    ddmTemplateModelImpl.getOriginalClassNameId()
11701                                            };
11702    
11703                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
11704                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
11705                                            args);
11706    
11707                                    args = new Object[] {
11708                                                    ddmTemplateModelImpl.getGroupId(),
11709                                                    ddmTemplateModelImpl.getClassNameId()
11710                                            };
11711    
11712                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
11713                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
11714                                            args);
11715                            }
11716    
11717                            if ((ddmTemplateModelImpl.getColumnBitmask() &
11718                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_CPK.getColumnBitmask()) != 0) {
11719                                    Object[] args = new Object[] {
11720                                                    ddmTemplateModelImpl.getOriginalGroupId(),
11721                                                    ddmTemplateModelImpl.getOriginalClassPK()
11722                                            };
11723    
11724                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_CPK, args);
11725                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_CPK,
11726                                            args);
11727    
11728                                    args = new Object[] {
11729                                                    ddmTemplateModelImpl.getGroupId(),
11730                                                    ddmTemplateModelImpl.getClassPK()
11731                                            };
11732    
11733                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_CPK, args);
11734                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_CPK,
11735                                            args);
11736                            }
11737    
11738                            if ((ddmTemplateModelImpl.getColumnBitmask() &
11739                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C.getColumnBitmask()) != 0) {
11740                                    Object[] args = new Object[] {
11741                                                    ddmTemplateModelImpl.getOriginalGroupId(),
11742                                                    ddmTemplateModelImpl.getOriginalClassNameId(),
11743                                                    ddmTemplateModelImpl.getOriginalClassPK()
11744                                            };
11745    
11746                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C, args);
11747                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C,
11748                                            args);
11749    
11750                                    args = new Object[] {
11751                                                    ddmTemplateModelImpl.getGroupId(),
11752                                                    ddmTemplateModelImpl.getClassNameId(),
11753                                                    ddmTemplateModelImpl.getClassPK()
11754                                            };
11755    
11756                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C, args);
11757                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C,
11758                                            args);
11759                            }
11760    
11761                            if ((ddmTemplateModelImpl.getColumnBitmask() &
11762                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T.getColumnBitmask()) != 0) {
11763                                    Object[] args = new Object[] {
11764                                                    ddmTemplateModelImpl.getOriginalClassNameId(),
11765                                                    ddmTemplateModelImpl.getOriginalClassPK(),
11766                                                    ddmTemplateModelImpl.getOriginalType()
11767                                            };
11768    
11769                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_T, args);
11770                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T,
11771                                            args);
11772    
11773                                    args = new Object[] {
11774                                                    ddmTemplateModelImpl.getClassNameId(),
11775                                                    ddmTemplateModelImpl.getClassPK(),
11776                                                    ddmTemplateModelImpl.getType()
11777                                            };
11778    
11779                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_T, args);
11780                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T,
11781                                            args);
11782                            }
11783    
11784                            if ((ddmTemplateModelImpl.getColumnBitmask() &
11785                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_T.getColumnBitmask()) != 0) {
11786                                    Object[] args = new Object[] {
11787                                                    ddmTemplateModelImpl.getOriginalGroupId(),
11788                                                    ddmTemplateModelImpl.getOriginalClassNameId(),
11789                                                    ddmTemplateModelImpl.getOriginalClassPK(),
11790                                                    ddmTemplateModelImpl.getOriginalType()
11791                                            };
11792    
11793                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C_T, args);
11794                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_T,
11795                                            args);
11796    
11797                                    args = new Object[] {
11798                                                    ddmTemplateModelImpl.getGroupId(),
11799                                                    ddmTemplateModelImpl.getClassNameId(),
11800                                                    ddmTemplateModelImpl.getClassPK(),
11801                                                    ddmTemplateModelImpl.getType()
11802                                            };
11803    
11804                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C_T, args);
11805                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_T,
11806                                            args);
11807                            }
11808    
11809                            if ((ddmTemplateModelImpl.getColumnBitmask() &
11810                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_T_M.getColumnBitmask()) != 0) {
11811                                    Object[] args = new Object[] {
11812                                                    ddmTemplateModelImpl.getOriginalGroupId(),
11813                                                    ddmTemplateModelImpl.getOriginalClassNameId(),
11814                                                    ddmTemplateModelImpl.getOriginalClassPK(),
11815                                                    ddmTemplateModelImpl.getOriginalType(),
11816                                                    ddmTemplateModelImpl.getOriginalMode()
11817                                            };
11818    
11819                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C_T_M,
11820                                            args);
11821                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_T_M,
11822                                            args);
11823    
11824                                    args = new Object[] {
11825                                                    ddmTemplateModelImpl.getGroupId(),
11826                                                    ddmTemplateModelImpl.getClassNameId(),
11827                                                    ddmTemplateModelImpl.getClassPK(),
11828                                                    ddmTemplateModelImpl.getType(),
11829                                                    ddmTemplateModelImpl.getMode()
11830                                            };
11831    
11832                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C_T_M,
11833                                            args);
11834                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_T_M,
11835                                            args);
11836                            }
11837                    }
11838    
11839                    EntityCacheUtil.putResult(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
11840                            DDMTemplateImpl.class, ddmTemplate.getPrimaryKey(), ddmTemplate);
11841    
11842                    clearUniqueFindersCache(ddmTemplate);
11843                    cacheUniqueFindersCache(ddmTemplate);
11844    
11845                    return ddmTemplate;
11846            }
11847    
11848            protected DDMTemplate toUnwrappedModel(DDMTemplate ddmTemplate) {
11849                    if (ddmTemplate instanceof DDMTemplateImpl) {
11850                            return ddmTemplate;
11851                    }
11852    
11853                    DDMTemplateImpl ddmTemplateImpl = new DDMTemplateImpl();
11854    
11855                    ddmTemplateImpl.setNew(ddmTemplate.isNew());
11856                    ddmTemplateImpl.setPrimaryKey(ddmTemplate.getPrimaryKey());
11857    
11858                    ddmTemplateImpl.setUuid(ddmTemplate.getUuid());
11859                    ddmTemplateImpl.setTemplateId(ddmTemplate.getTemplateId());
11860                    ddmTemplateImpl.setGroupId(ddmTemplate.getGroupId());
11861                    ddmTemplateImpl.setCompanyId(ddmTemplate.getCompanyId());
11862                    ddmTemplateImpl.setUserId(ddmTemplate.getUserId());
11863                    ddmTemplateImpl.setUserName(ddmTemplate.getUserName());
11864                    ddmTemplateImpl.setCreateDate(ddmTemplate.getCreateDate());
11865                    ddmTemplateImpl.setModifiedDate(ddmTemplate.getModifiedDate());
11866                    ddmTemplateImpl.setClassNameId(ddmTemplate.getClassNameId());
11867                    ddmTemplateImpl.setClassPK(ddmTemplate.getClassPK());
11868                    ddmTemplateImpl.setTemplateKey(ddmTemplate.getTemplateKey());
11869                    ddmTemplateImpl.setName(ddmTemplate.getName());
11870                    ddmTemplateImpl.setDescription(ddmTemplate.getDescription());
11871                    ddmTemplateImpl.setType(ddmTemplate.getType());
11872                    ddmTemplateImpl.setMode(ddmTemplate.getMode());
11873                    ddmTemplateImpl.setLanguage(ddmTemplate.getLanguage());
11874                    ddmTemplateImpl.setScript(ddmTemplate.getScript());
11875                    ddmTemplateImpl.setCacheable(ddmTemplate.isCacheable());
11876                    ddmTemplateImpl.setSmallImage(ddmTemplate.isSmallImage());
11877                    ddmTemplateImpl.setSmallImageId(ddmTemplate.getSmallImageId());
11878                    ddmTemplateImpl.setSmallImageURL(ddmTemplate.getSmallImageURL());
11879    
11880                    return ddmTemplateImpl;
11881            }
11882    
11883            /**
11884             * Returns the d d m template with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
11885             *
11886             * @param primaryKey the primary key of the d d m template
11887             * @return the d d m template
11888             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
11889             * @throws SystemException if a system exception occurred
11890             */
11891            @Override
11892            public DDMTemplate findByPrimaryKey(Serializable primaryKey)
11893                    throws NoSuchTemplateException, SystemException {
11894                    DDMTemplate ddmTemplate = fetchByPrimaryKey(primaryKey);
11895    
11896                    if (ddmTemplate == null) {
11897                            if (_log.isWarnEnabled()) {
11898                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
11899                            }
11900    
11901                            throw new NoSuchTemplateException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
11902                                    primaryKey);
11903                    }
11904    
11905                    return ddmTemplate;
11906            }
11907    
11908            /**
11909             * 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.
11910             *
11911             * @param templateId the primary key of the d d m template
11912             * @return the d d m template
11913             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchTemplateException if a d d m template with the primary key could not be found
11914             * @throws SystemException if a system exception occurred
11915             */
11916            @Override
11917            public DDMTemplate findByPrimaryKey(long templateId)
11918                    throws NoSuchTemplateException, SystemException {
11919                    return findByPrimaryKey((Serializable)templateId);
11920            }
11921    
11922            /**
11923             * Returns the d d m template with the primary key or returns <code>null</code> if it could not be found.
11924             *
11925             * @param primaryKey the primary key of the d d m template
11926             * @return the d d m template, or <code>null</code> if a d d m template with the primary key could not be found
11927             * @throws SystemException if a system exception occurred
11928             */
11929            @Override
11930            public DDMTemplate fetchByPrimaryKey(Serializable primaryKey)
11931                    throws SystemException {
11932                    DDMTemplate ddmTemplate = (DDMTemplate)EntityCacheUtil.getResult(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
11933                                    DDMTemplateImpl.class, primaryKey);
11934    
11935                    if (ddmTemplate == _nullDDMTemplate) {
11936                            return null;
11937                    }
11938    
11939                    if (ddmTemplate == null) {
11940                            Session session = null;
11941    
11942                            try {
11943                                    session = openSession();
11944    
11945                                    ddmTemplate = (DDMTemplate)session.get(DDMTemplateImpl.class,
11946                                                    primaryKey);
11947    
11948                                    if (ddmTemplate != null) {
11949                                            cacheResult(ddmTemplate);
11950                                    }
11951                                    else {
11952                                            EntityCacheUtil.putResult(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
11953                                                    DDMTemplateImpl.class, primaryKey, _nullDDMTemplate);
11954                                    }
11955                            }
11956                            catch (Exception e) {
11957                                    EntityCacheUtil.removeResult(DDMTemplateModelImpl.ENTITY_CACHE_ENABLED,
11958                                            DDMTemplateImpl.class, primaryKey);
11959    
11960                                    throw processException(e);
11961                            }
11962                            finally {
11963                                    closeSession(session);
11964                            }
11965                    }
11966    
11967                    return ddmTemplate;
11968            }
11969    
11970            /**
11971             * Returns the d d m template with the primary key or returns <code>null</code> if it could not be found.
11972             *
11973             * @param templateId the primary key of the d d m template
11974             * @return the d d m template, or <code>null</code> if a d d m template with the primary key could not be found
11975             * @throws SystemException if a system exception occurred
11976             */
11977            @Override
11978            public DDMTemplate fetchByPrimaryKey(long templateId)
11979                    throws SystemException {
11980                    return fetchByPrimaryKey((Serializable)templateId);
11981            }
11982    
11983            /**
11984             * Returns all the d d m templates.
11985             *
11986             * @return the d d m templates
11987             * @throws SystemException if a system exception occurred
11988             */
11989            @Override
11990            public List<DDMTemplate> findAll() throws SystemException {
11991                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
11992            }
11993    
11994            /**
11995             * Returns a range of all the d d m templates.
11996             *
11997             * <p>
11998             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11999             * </p>
12000             *
12001             * @param start the lower bound of the range of d d m templates
12002             * @param end the upper bound of the range of d d m templates (not inclusive)
12003             * @return the range of d d m templates
12004             * @throws SystemException if a system exception occurred
12005             */
12006            @Override
12007            public List<DDMTemplate> findAll(int start, int end)
12008                    throws SystemException {
12009                    return findAll(start, end, null);
12010            }
12011    
12012            /**
12013             * Returns an ordered range of all the d d m templates.
12014             *
12015             * <p>
12016             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12017             * </p>
12018             *
12019             * @param start the lower bound of the range of d d m templates
12020             * @param end the upper bound of the range of d d m templates (not inclusive)
12021             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12022             * @return the ordered range of d d m templates
12023             * @throws SystemException if a system exception occurred
12024             */
12025            @Override
12026            public List<DDMTemplate> findAll(int start, int end,
12027                    OrderByComparator orderByComparator) throws SystemException {
12028                    boolean pagination = true;
12029                    FinderPath finderPath = null;
12030                    Object[] finderArgs = null;
12031    
12032                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12033                                    (orderByComparator == null)) {
12034                            pagination = false;
12035                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
12036                            finderArgs = FINDER_ARGS_EMPTY;
12037                    }
12038                    else {
12039                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
12040                            finderArgs = new Object[] { start, end, orderByComparator };
12041                    }
12042    
12043                    List<DDMTemplate> list = (List<DDMTemplate>)FinderCacheUtil.getResult(finderPath,
12044                                    finderArgs, this);
12045    
12046                    if (list == null) {
12047                            StringBundler query = null;
12048                            String sql = null;
12049    
12050                            if (orderByComparator != null) {
12051                                    query = new StringBundler(2 +
12052                                                    (orderByComparator.getOrderByFields().length * 3));
12053    
12054                                    query.append(_SQL_SELECT_DDMTEMPLATE);
12055    
12056                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12057                                            orderByComparator);
12058    
12059                                    sql = query.toString();
12060                            }
12061                            else {
12062                                    sql = _SQL_SELECT_DDMTEMPLATE;
12063    
12064                                    if (pagination) {
12065                                            sql = sql.concat(DDMTemplateModelImpl.ORDER_BY_JPQL);
12066                                    }
12067                            }
12068    
12069                            Session session = null;
12070    
12071                            try {
12072                                    session = openSession();
12073    
12074                                    Query q = session.createQuery(sql);
12075    
12076                                    if (!pagination) {
12077                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
12078                                                            start, end, false);
12079    
12080                                            Collections.sort(list);
12081    
12082                                            list = new UnmodifiableList<DDMTemplate>(list);
12083                                    }
12084                                    else {
12085                                            list = (List<DDMTemplate>)QueryUtil.list(q, getDialect(),
12086                                                            start, end);
12087                                    }
12088    
12089                                    cacheResult(list);
12090    
12091                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
12092                            }
12093                            catch (Exception e) {
12094                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12095    
12096                                    throw processException(e);
12097                            }
12098                            finally {
12099                                    closeSession(session);
12100                            }
12101                    }
12102    
12103                    return list;
12104            }
12105    
12106            /**
12107             * Removes all the d d m templates from the database.
12108             *
12109             * @throws SystemException if a system exception occurred
12110             */
12111            @Override
12112            public void removeAll() throws SystemException {
12113                    for (DDMTemplate ddmTemplate : findAll()) {
12114                            remove(ddmTemplate);
12115                    }
12116            }
12117    
12118            /**
12119             * Returns the number of d d m templates.
12120             *
12121             * @return the number of d d m templates
12122             * @throws SystemException if a system exception occurred
12123             */
12124            @Override
12125            public int countAll() throws SystemException {
12126                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
12127                                    FINDER_ARGS_EMPTY, this);
12128    
12129                    if (count == null) {
12130                            Session session = null;
12131    
12132                            try {
12133                                    session = openSession();
12134    
12135                                    Query q = session.createQuery(_SQL_COUNT_DDMTEMPLATE);
12136    
12137                                    count = (Long)q.uniqueResult();
12138    
12139                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
12140                                            FINDER_ARGS_EMPTY, count);
12141                            }
12142                            catch (Exception e) {
12143                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
12144                                            FINDER_ARGS_EMPTY);
12145    
12146                                    throw processException(e);
12147                            }
12148                            finally {
12149                                    closeSession(session);
12150                            }
12151                    }
12152    
12153                    return count.intValue();
12154            }
12155    
12156            @Override
12157            protected Set<String> getBadColumnNames() {
12158                    return _badColumnNames;
12159            }
12160    
12161            /**
12162             * Initializes the d d m template persistence.
12163             */
12164            public void afterPropertiesSet() {
12165                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
12166                                            com.liferay.portal.util.PropsUtil.get(
12167                                                    "value.object.listener.com.liferay.portlet.dynamicdatamapping.model.DDMTemplate")));
12168    
12169                    if (listenerClassNames.length > 0) {
12170                            try {
12171                                    List<ModelListener<DDMTemplate>> listenersList = new ArrayList<ModelListener<DDMTemplate>>();
12172    
12173                                    for (String listenerClassName : listenerClassNames) {
12174                                            listenersList.add((ModelListener<DDMTemplate>)InstanceFactory.newInstance(
12175                                                            getClassLoader(), listenerClassName));
12176                                    }
12177    
12178                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
12179                            }
12180                            catch (Exception e) {
12181                                    _log.error(e);
12182                            }
12183                    }
12184            }
12185    
12186            public void destroy() {
12187                    EntityCacheUtil.removeCache(DDMTemplateImpl.class.getName());
12188                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
12189                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12190                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12191            }
12192    
12193            private static final String _SQL_SELECT_DDMTEMPLATE = "SELECT ddmTemplate FROM DDMTemplate ddmTemplate";
12194            private static final String _SQL_SELECT_DDMTEMPLATE_WHERE = "SELECT ddmTemplate FROM DDMTemplate ddmTemplate WHERE ";
12195            private static final String _SQL_COUNT_DDMTEMPLATE = "SELECT COUNT(ddmTemplate) FROM DDMTemplate ddmTemplate";
12196            private static final String _SQL_COUNT_DDMTEMPLATE_WHERE = "SELECT COUNT(ddmTemplate) FROM DDMTemplate ddmTemplate WHERE ";
12197            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "ddmTemplate.templateId";
12198            private static final String _FILTER_SQL_SELECT_DDMTEMPLATE_WHERE = "SELECT DISTINCT {ddmTemplate.*} FROM DDMTemplate ddmTemplate WHERE ";
12199            private static final String _FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_1 =
12200                    "SELECT {DDMTemplate.*} FROM (SELECT DISTINCT ddmTemplate.templateId FROM DDMTemplate ddmTemplate WHERE ";
12201            private static final String _FILTER_SQL_SELECT_DDMTEMPLATE_NO_INLINE_DISTINCT_WHERE_2 =
12202                    ") TEMP_TABLE INNER JOIN DDMTemplate ON TEMP_TABLE.templateId = DDMTemplate.templateId";
12203            private static final String _FILTER_SQL_COUNT_DDMTEMPLATE_WHERE = "SELECT COUNT(DISTINCT ddmTemplate.templateId) AS COUNT_VALUE FROM DDMTemplate ddmTemplate WHERE ";
12204            private static final String _FILTER_ENTITY_ALIAS = "ddmTemplate";
12205            private static final String _FILTER_ENTITY_TABLE = "DDMTemplate";
12206            private static final String _ORDER_BY_ENTITY_ALIAS = "ddmTemplate.";
12207            private static final String _ORDER_BY_ENTITY_TABLE = "DDMTemplate.";
12208            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DDMTemplate exists with the primary key ";
12209            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DDMTemplate exists with the key {";
12210            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
12211            private static Log _log = LogFactoryUtil.getLog(DDMTemplatePersistenceImpl.class);
12212            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
12213                                    "uuid", "type", "mode"
12214                            });
12215            private static DDMTemplate _nullDDMTemplate = new DDMTemplateImpl() {
12216                            @Override
12217                            public Object clone() {
12218                                    return this;
12219                            }
12220    
12221                            @Override
12222                            public CacheModel<DDMTemplate> toCacheModel() {
12223                                    return _nullDDMTemplateCacheModel;
12224                            }
12225                    };
12226    
12227            private static CacheModel<DDMTemplate> _nullDDMTemplateCacheModel = new CacheModel<DDMTemplate>() {
12228                            @Override
12229                            public DDMTemplate toEntityModel() {
12230                                    return _nullDDMTemplate;
12231                            }
12232                    };
12233    }