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