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