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