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