001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.dynamicdatamapping.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.log.Log;
027    import com.liferay.portal.kernel.log.LogFactoryUtil;
028    import com.liferay.portal.kernel.util.OrderByComparator;
029    import com.liferay.portal.kernel.util.StringBundler;
030    import com.liferay.portal.kernel.util.StringPool;
031    import com.liferay.portal.model.CacheModel;
032    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
033    
034    import com.liferay.portlet.dynamicdatamapping.NoSuchTemplateLinkException;
035    import com.liferay.portlet.dynamicdatamapping.model.DDMTemplateLink;
036    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateLinkImpl;
037    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMTemplateLinkModelImpl;
038    import com.liferay.portlet.dynamicdatamapping.service.persistence.DDMTemplateLinkPersistence;
039    
040    import java.io.Serializable;
041    
042    import java.util.Collections;
043    import java.util.HashMap;
044    import java.util.HashSet;
045    import java.util.Iterator;
046    import java.util.List;
047    import java.util.Map;
048    import java.util.Set;
049    
050    /**
051     * The persistence implementation for the d d m template link service.
052     *
053     * <p>
054     * Caching information and settings can be found in <code>portal.properties</code>
055     * </p>
056     *
057     * @author Brian Wing Shun Chan
058     * @see DDMTemplateLinkPersistence
059     * @see com.liferay.portlet.dynamicdatamapping.service.persistence.DDMTemplateLinkUtil
060     * @generated
061     */
062    @ProviderType
063    public class DDMTemplateLinkPersistenceImpl extends BasePersistenceImpl<DDMTemplateLink>
064            implements DDMTemplateLinkPersistence {
065            /*
066             * NOTE FOR DEVELOPERS:
067             *
068             * Never modify or reference this class directly. Always use {@link DDMTemplateLinkUtil} to access the d d m template link persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
069             */
070            public static final String FINDER_CLASS_NAME_ENTITY = DDMTemplateLinkImpl.class.getName();
071            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072                    ".List1";
073            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074                    ".List2";
075            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DDMTemplateLinkModelImpl.ENTITY_CACHE_ENABLED,
076                            DDMTemplateLinkModelImpl.FINDER_CACHE_ENABLED,
077                            DDMTemplateLinkImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
078                            "findAll", new String[0]);
079            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DDMTemplateLinkModelImpl.ENTITY_CACHE_ENABLED,
080                            DDMTemplateLinkModelImpl.FINDER_CACHE_ENABLED,
081                            DDMTemplateLinkImpl.class,
082                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
083            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DDMTemplateLinkModelImpl.ENTITY_CACHE_ENABLED,
084                            DDMTemplateLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
085                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
086            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSNAMEID =
087                    new FinderPath(DDMTemplateLinkModelImpl.ENTITY_CACHE_ENABLED,
088                            DDMTemplateLinkModelImpl.FINDER_CACHE_ENABLED,
089                            DDMTemplateLinkImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
090                            "findByClassNameId",
091                            new String[] {
092                                    Long.class.getName(),
093                                    
094                            Integer.class.getName(), Integer.class.getName(),
095                                    OrderByComparator.class.getName()
096                            });
097            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID =
098                    new FinderPath(DDMTemplateLinkModelImpl.ENTITY_CACHE_ENABLED,
099                            DDMTemplateLinkModelImpl.FINDER_CACHE_ENABLED,
100                            DDMTemplateLinkImpl.class,
101                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByClassNameId",
102                            new String[] { Long.class.getName() },
103                            DDMTemplateLinkModelImpl.CLASSNAMEID_COLUMN_BITMASK);
104            public static final FinderPath FINDER_PATH_COUNT_BY_CLASSNAMEID = new FinderPath(DDMTemplateLinkModelImpl.ENTITY_CACHE_ENABLED,
105                            DDMTemplateLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
106                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByClassNameId",
107                            new String[] { Long.class.getName() });
108    
109            /**
110             * Returns all the d d m template links where classNameId = &#63;.
111             *
112             * @param classNameId the class name ID
113             * @return the matching d d m template links
114             */
115            @Override
116            public List<DDMTemplateLink> findByClassNameId(long classNameId) {
117                    return findByClassNameId(classNameId, QueryUtil.ALL_POS,
118                            QueryUtil.ALL_POS, null);
119            }
120    
121            /**
122             * Returns a range of all the d d m template links where classNameId = &#63;.
123             *
124             * <p>
125             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DDMTemplateLinkModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
126             * </p>
127             *
128             * @param classNameId the class name ID
129             * @param start the lower bound of the range of d d m template links
130             * @param end the upper bound of the range of d d m template links (not inclusive)
131             * @return the range of matching d d m template links
132             */
133            @Override
134            public List<DDMTemplateLink> findByClassNameId(long classNameId, int start,
135                    int end) {
136                    return findByClassNameId(classNameId, start, end, null);
137            }
138    
139            /**
140             * Returns an ordered range of all the d d m template links where classNameId = &#63;.
141             *
142             * <p>
143             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DDMTemplateLinkModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
144             * </p>
145             *
146             * @param classNameId the class name ID
147             * @param start the lower bound of the range of d d m template links
148             * @param end the upper bound of the range of d d m template links (not inclusive)
149             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
150             * @return the ordered range of matching d d m template links
151             */
152            @Override
153            public List<DDMTemplateLink> findByClassNameId(long classNameId, int start,
154                    int end, OrderByComparator<DDMTemplateLink> orderByComparator) {
155                    boolean pagination = true;
156                    FinderPath finderPath = null;
157                    Object[] finderArgs = null;
158    
159                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
160                                    (orderByComparator == null)) {
161                            pagination = false;
162                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID;
163                            finderArgs = new Object[] { classNameId };
164                    }
165                    else {
166                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSNAMEID;
167                            finderArgs = new Object[] { classNameId, start, end, orderByComparator };
168                    }
169    
170                    List<DDMTemplateLink> list = (List<DDMTemplateLink>)FinderCacheUtil.getResult(finderPath,
171                                    finderArgs, this);
172    
173                    if ((list != null) && !list.isEmpty()) {
174                            for (DDMTemplateLink ddmTemplateLink : list) {
175                                    if ((classNameId != ddmTemplateLink.getClassNameId())) {
176                                            list = null;
177    
178                                            break;
179                                    }
180                            }
181                    }
182    
183                    if (list == null) {
184                            StringBundler query = null;
185    
186                            if (orderByComparator != null) {
187                                    query = new StringBundler(3 +
188                                                    (orderByComparator.getOrderByFields().length * 3));
189                            }
190                            else {
191                                    query = new StringBundler(3);
192                            }
193    
194                            query.append(_SQL_SELECT_DDMTEMPLATELINK_WHERE);
195    
196                            query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
197    
198                            if (orderByComparator != null) {
199                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
200                                            orderByComparator);
201                            }
202                            else
203                             if (pagination) {
204                                    query.append(DDMTemplateLinkModelImpl.ORDER_BY_JPQL);
205                            }
206    
207                            String sql = query.toString();
208    
209                            Session session = null;
210    
211                            try {
212                                    session = openSession();
213    
214                                    Query q = session.createQuery(sql);
215    
216                                    QueryPos qPos = QueryPos.getInstance(q);
217    
218                                    qPos.add(classNameId);
219    
220                                    if (!pagination) {
221                                            list = (List<DDMTemplateLink>)QueryUtil.list(q,
222                                                            getDialect(), start, end, false);
223    
224                                            Collections.sort(list);
225    
226                                            list = Collections.unmodifiableList(list);
227                                    }
228                                    else {
229                                            list = (List<DDMTemplateLink>)QueryUtil.list(q,
230                                                            getDialect(), start, end);
231                                    }
232    
233                                    cacheResult(list);
234    
235                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
236                            }
237                            catch (Exception e) {
238                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
239    
240                                    throw processException(e);
241                            }
242                            finally {
243                                    closeSession(session);
244                            }
245                    }
246    
247                    return list;
248            }
249    
250            /**
251             * Returns the first d d m template link in the ordered set where classNameId = &#63;.
252             *
253             * @param classNameId the class name ID
254             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
255             * @return the first matching d d m template link
256             * @throws NoSuchTemplateLinkException if a matching d d m template link could not be found
257             */
258            @Override
259            public DDMTemplateLink findByClassNameId_First(long classNameId,
260                    OrderByComparator<DDMTemplateLink> orderByComparator)
261                    throws NoSuchTemplateLinkException {
262                    DDMTemplateLink ddmTemplateLink = fetchByClassNameId_First(classNameId,
263                                    orderByComparator);
264    
265                    if (ddmTemplateLink != null) {
266                            return ddmTemplateLink;
267                    }
268    
269                    StringBundler msg = new StringBundler(4);
270    
271                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
272    
273                    msg.append("classNameId=");
274                    msg.append(classNameId);
275    
276                    msg.append(StringPool.CLOSE_CURLY_BRACE);
277    
278                    throw new NoSuchTemplateLinkException(msg.toString());
279            }
280    
281            /**
282             * Returns the first d d m template link in the ordered set where classNameId = &#63;.
283             *
284             * @param classNameId the class name ID
285             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
286             * @return the first matching d d m template link, or <code>null</code> if a matching d d m template link could not be found
287             */
288            @Override
289            public DDMTemplateLink fetchByClassNameId_First(long classNameId,
290                    OrderByComparator<DDMTemplateLink> orderByComparator) {
291                    List<DDMTemplateLink> list = findByClassNameId(classNameId, 0, 1,
292                                    orderByComparator);
293    
294                    if (!list.isEmpty()) {
295                            return list.get(0);
296                    }
297    
298                    return null;
299            }
300    
301            /**
302             * Returns the last d d m template link in the ordered set where classNameId = &#63;.
303             *
304             * @param classNameId the class name ID
305             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
306             * @return the last matching d d m template link
307             * @throws NoSuchTemplateLinkException if a matching d d m template link could not be found
308             */
309            @Override
310            public DDMTemplateLink findByClassNameId_Last(long classNameId,
311                    OrderByComparator<DDMTemplateLink> orderByComparator)
312                    throws NoSuchTemplateLinkException {
313                    DDMTemplateLink ddmTemplateLink = fetchByClassNameId_Last(classNameId,
314                                    orderByComparator);
315    
316                    if (ddmTemplateLink != null) {
317                            return ddmTemplateLink;
318                    }
319    
320                    StringBundler msg = new StringBundler(4);
321    
322                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
323    
324                    msg.append("classNameId=");
325                    msg.append(classNameId);
326    
327                    msg.append(StringPool.CLOSE_CURLY_BRACE);
328    
329                    throw new NoSuchTemplateLinkException(msg.toString());
330            }
331    
332            /**
333             * Returns the last d d m template link in the ordered set where classNameId = &#63;.
334             *
335             * @param classNameId the class name ID
336             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
337             * @return the last matching d d m template link, or <code>null</code> if a matching d d m template link could not be found
338             */
339            @Override
340            public DDMTemplateLink fetchByClassNameId_Last(long classNameId,
341                    OrderByComparator<DDMTemplateLink> orderByComparator) {
342                    int count = countByClassNameId(classNameId);
343    
344                    if (count == 0) {
345                            return null;
346                    }
347    
348                    List<DDMTemplateLink> list = findByClassNameId(classNameId, count - 1,
349                                    count, orderByComparator);
350    
351                    if (!list.isEmpty()) {
352                            return list.get(0);
353                    }
354    
355                    return null;
356            }
357    
358            /**
359             * Returns the d d m template links before and after the current d d m template link in the ordered set where classNameId = &#63;.
360             *
361             * @param templateLinkId the primary key of the current d d m template link
362             * @param classNameId the class name ID
363             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
364             * @return the previous, current, and next d d m template link
365             * @throws NoSuchTemplateLinkException if a d d m template link with the primary key could not be found
366             */
367            @Override
368            public DDMTemplateLink[] findByClassNameId_PrevAndNext(
369                    long templateLinkId, long classNameId,
370                    OrderByComparator<DDMTemplateLink> orderByComparator)
371                    throws NoSuchTemplateLinkException {
372                    DDMTemplateLink ddmTemplateLink = findByPrimaryKey(templateLinkId);
373    
374                    Session session = null;
375    
376                    try {
377                            session = openSession();
378    
379                            DDMTemplateLink[] array = new DDMTemplateLinkImpl[3];
380    
381                            array[0] = getByClassNameId_PrevAndNext(session, ddmTemplateLink,
382                                            classNameId, orderByComparator, true);
383    
384                            array[1] = ddmTemplateLink;
385    
386                            array[2] = getByClassNameId_PrevAndNext(session, ddmTemplateLink,
387                                            classNameId, orderByComparator, false);
388    
389                            return array;
390                    }
391                    catch (Exception e) {
392                            throw processException(e);
393                    }
394                    finally {
395                            closeSession(session);
396                    }
397            }
398    
399            protected DDMTemplateLink getByClassNameId_PrevAndNext(Session session,
400                    DDMTemplateLink ddmTemplateLink, long classNameId,
401                    OrderByComparator<DDMTemplateLink> orderByComparator, boolean previous) {
402                    StringBundler query = null;
403    
404                    if (orderByComparator != null) {
405                            query = new StringBundler(6 +
406                                            (orderByComparator.getOrderByFields().length * 6));
407                    }
408                    else {
409                            query = new StringBundler(3);
410                    }
411    
412                    query.append(_SQL_SELECT_DDMTEMPLATELINK_WHERE);
413    
414                    query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
415    
416                    if (orderByComparator != null) {
417                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
418    
419                            if (orderByConditionFields.length > 0) {
420                                    query.append(WHERE_AND);
421                            }
422    
423                            for (int i = 0; i < orderByConditionFields.length; i++) {
424                                    query.append(_ORDER_BY_ENTITY_ALIAS);
425                                    query.append(orderByConditionFields[i]);
426    
427                                    if ((i + 1) < orderByConditionFields.length) {
428                                            if (orderByComparator.isAscending() ^ previous) {
429                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
430                                            }
431                                            else {
432                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
433                                            }
434                                    }
435                                    else {
436                                            if (orderByComparator.isAscending() ^ previous) {
437                                                    query.append(WHERE_GREATER_THAN);
438                                            }
439                                            else {
440                                                    query.append(WHERE_LESSER_THAN);
441                                            }
442                                    }
443                            }
444    
445                            query.append(ORDER_BY_CLAUSE);
446    
447                            String[] orderByFields = orderByComparator.getOrderByFields();
448    
449                            for (int i = 0; i < orderByFields.length; i++) {
450                                    query.append(_ORDER_BY_ENTITY_ALIAS);
451                                    query.append(orderByFields[i]);
452    
453                                    if ((i + 1) < orderByFields.length) {
454                                            if (orderByComparator.isAscending() ^ previous) {
455                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
456                                            }
457                                            else {
458                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
459                                            }
460                                    }
461                                    else {
462                                            if (orderByComparator.isAscending() ^ previous) {
463                                                    query.append(ORDER_BY_ASC);
464                                            }
465                                            else {
466                                                    query.append(ORDER_BY_DESC);
467                                            }
468                                    }
469                            }
470                    }
471                    else {
472                            query.append(DDMTemplateLinkModelImpl.ORDER_BY_JPQL);
473                    }
474    
475                    String sql = query.toString();
476    
477                    Query q = session.createQuery(sql);
478    
479                    q.setFirstResult(0);
480                    q.setMaxResults(2);
481    
482                    QueryPos qPos = QueryPos.getInstance(q);
483    
484                    qPos.add(classNameId);
485    
486                    if (orderByComparator != null) {
487                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplateLink);
488    
489                            for (Object value : values) {
490                                    qPos.add(value);
491                            }
492                    }
493    
494                    List<DDMTemplateLink> list = q.list();
495    
496                    if (list.size() == 2) {
497                            return list.get(1);
498                    }
499                    else {
500                            return null;
501                    }
502            }
503    
504            /**
505             * Removes all the d d m template links where classNameId = &#63; from the database.
506             *
507             * @param classNameId the class name ID
508             */
509            @Override
510            public void removeByClassNameId(long classNameId) {
511                    for (DDMTemplateLink ddmTemplateLink : findByClassNameId(classNameId,
512                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
513                            remove(ddmTemplateLink);
514                    }
515            }
516    
517            /**
518             * Returns the number of d d m template links where classNameId = &#63;.
519             *
520             * @param classNameId the class name ID
521             * @return the number of matching d d m template links
522             */
523            @Override
524            public int countByClassNameId(long classNameId) {
525                    FinderPath finderPath = FINDER_PATH_COUNT_BY_CLASSNAMEID;
526    
527                    Object[] finderArgs = new Object[] { classNameId };
528    
529                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
530                                    this);
531    
532                    if (count == null) {
533                            StringBundler query = new StringBundler(2);
534    
535                            query.append(_SQL_COUNT_DDMTEMPLATELINK_WHERE);
536    
537                            query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
538    
539                            String sql = query.toString();
540    
541                            Session session = null;
542    
543                            try {
544                                    session = openSession();
545    
546                                    Query q = session.createQuery(sql);
547    
548                                    QueryPos qPos = QueryPos.getInstance(q);
549    
550                                    qPos.add(classNameId);
551    
552                                    count = (Long)q.uniqueResult();
553    
554                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
555                            }
556                            catch (Exception e) {
557                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
558    
559                                    throw processException(e);
560                            }
561                            finally {
562                                    closeSession(session);
563                            }
564                    }
565    
566                    return count.intValue();
567            }
568    
569            private static final String _FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2 = "ddmTemplateLink.classNameId = ?";
570            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TEMPLATEID =
571                    new FinderPath(DDMTemplateLinkModelImpl.ENTITY_CACHE_ENABLED,
572                            DDMTemplateLinkModelImpl.FINDER_CACHE_ENABLED,
573                            DDMTemplateLinkImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
574                            "findByTemplateId",
575                            new String[] {
576                                    Long.class.getName(),
577                                    
578                            Integer.class.getName(), Integer.class.getName(),
579                                    OrderByComparator.class.getName()
580                            });
581            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID =
582                    new FinderPath(DDMTemplateLinkModelImpl.ENTITY_CACHE_ENABLED,
583                            DDMTemplateLinkModelImpl.FINDER_CACHE_ENABLED,
584                            DDMTemplateLinkImpl.class,
585                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTemplateId",
586                            new String[] { Long.class.getName() },
587                            DDMTemplateLinkModelImpl.TEMPLATEID_COLUMN_BITMASK);
588            public static final FinderPath FINDER_PATH_COUNT_BY_TEMPLATEID = new FinderPath(DDMTemplateLinkModelImpl.ENTITY_CACHE_ENABLED,
589                            DDMTemplateLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
590                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTemplateId",
591                            new String[] { Long.class.getName() });
592    
593            /**
594             * Returns all the d d m template links where templateId = &#63;.
595             *
596             * @param templateId the template ID
597             * @return the matching d d m template links
598             */
599            @Override
600            public List<DDMTemplateLink> findByTemplateId(long templateId) {
601                    return findByTemplateId(templateId, QueryUtil.ALL_POS,
602                            QueryUtil.ALL_POS, null);
603            }
604    
605            /**
606             * Returns a range of all the d d m template links where templateId = &#63;.
607             *
608             * <p>
609             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DDMTemplateLinkModelImpl}. 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.
610             * </p>
611             *
612             * @param templateId the template ID
613             * @param start the lower bound of the range of d d m template links
614             * @param end the upper bound of the range of d d m template links (not inclusive)
615             * @return the range of matching d d m template links
616             */
617            @Override
618            public List<DDMTemplateLink> findByTemplateId(long templateId, int start,
619                    int end) {
620                    return findByTemplateId(templateId, start, end, null);
621            }
622    
623            /**
624             * Returns an ordered range of all the d d m template links where templateId = &#63;.
625             *
626             * <p>
627             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DDMTemplateLinkModelImpl}. 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.
628             * </p>
629             *
630             * @param templateId the template ID
631             * @param start the lower bound of the range of d d m template links
632             * @param end the upper bound of the range of d d m template links (not inclusive)
633             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
634             * @return the ordered range of matching d d m template links
635             */
636            @Override
637            public List<DDMTemplateLink> findByTemplateId(long templateId, int start,
638                    int end, OrderByComparator<DDMTemplateLink> orderByComparator) {
639                    boolean pagination = true;
640                    FinderPath finderPath = null;
641                    Object[] finderArgs = null;
642    
643                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
644                                    (orderByComparator == null)) {
645                            pagination = false;
646                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID;
647                            finderArgs = new Object[] { templateId };
648                    }
649                    else {
650                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TEMPLATEID;
651                            finderArgs = new Object[] { templateId, start, end, orderByComparator };
652                    }
653    
654                    List<DDMTemplateLink> list = (List<DDMTemplateLink>)FinderCacheUtil.getResult(finderPath,
655                                    finderArgs, this);
656    
657                    if ((list != null) && !list.isEmpty()) {
658                            for (DDMTemplateLink ddmTemplateLink : list) {
659                                    if ((templateId != ddmTemplateLink.getTemplateId())) {
660                                            list = null;
661    
662                                            break;
663                                    }
664                            }
665                    }
666    
667                    if (list == null) {
668                            StringBundler query = null;
669    
670                            if (orderByComparator != null) {
671                                    query = new StringBundler(3 +
672                                                    (orderByComparator.getOrderByFields().length * 3));
673                            }
674                            else {
675                                    query = new StringBundler(3);
676                            }
677    
678                            query.append(_SQL_SELECT_DDMTEMPLATELINK_WHERE);
679    
680                            query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2);
681    
682                            if (orderByComparator != null) {
683                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
684                                            orderByComparator);
685                            }
686                            else
687                             if (pagination) {
688                                    query.append(DDMTemplateLinkModelImpl.ORDER_BY_JPQL);
689                            }
690    
691                            String sql = query.toString();
692    
693                            Session session = null;
694    
695                            try {
696                                    session = openSession();
697    
698                                    Query q = session.createQuery(sql);
699    
700                                    QueryPos qPos = QueryPos.getInstance(q);
701    
702                                    qPos.add(templateId);
703    
704                                    if (!pagination) {
705                                            list = (List<DDMTemplateLink>)QueryUtil.list(q,
706                                                            getDialect(), start, end, false);
707    
708                                            Collections.sort(list);
709    
710                                            list = Collections.unmodifiableList(list);
711                                    }
712                                    else {
713                                            list = (List<DDMTemplateLink>)QueryUtil.list(q,
714                                                            getDialect(), start, end);
715                                    }
716    
717                                    cacheResult(list);
718    
719                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
720                            }
721                            catch (Exception e) {
722                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
723    
724                                    throw processException(e);
725                            }
726                            finally {
727                                    closeSession(session);
728                            }
729                    }
730    
731                    return list;
732            }
733    
734            /**
735             * Returns the first d d m template link in the ordered set where templateId = &#63;.
736             *
737             * @param templateId the template ID
738             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
739             * @return the first matching d d m template link
740             * @throws NoSuchTemplateLinkException if a matching d d m template link could not be found
741             */
742            @Override
743            public DDMTemplateLink findByTemplateId_First(long templateId,
744                    OrderByComparator<DDMTemplateLink> orderByComparator)
745                    throws NoSuchTemplateLinkException {
746                    DDMTemplateLink ddmTemplateLink = fetchByTemplateId_First(templateId,
747                                    orderByComparator);
748    
749                    if (ddmTemplateLink != null) {
750                            return ddmTemplateLink;
751                    }
752    
753                    StringBundler msg = new StringBundler(4);
754    
755                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
756    
757                    msg.append("templateId=");
758                    msg.append(templateId);
759    
760                    msg.append(StringPool.CLOSE_CURLY_BRACE);
761    
762                    throw new NoSuchTemplateLinkException(msg.toString());
763            }
764    
765            /**
766             * Returns the first d d m template link in the ordered set where templateId = &#63;.
767             *
768             * @param templateId the template ID
769             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
770             * @return the first matching d d m template link, or <code>null</code> if a matching d d m template link could not be found
771             */
772            @Override
773            public DDMTemplateLink fetchByTemplateId_First(long templateId,
774                    OrderByComparator<DDMTemplateLink> orderByComparator) {
775                    List<DDMTemplateLink> list = findByTemplateId(templateId, 0, 1,
776                                    orderByComparator);
777    
778                    if (!list.isEmpty()) {
779                            return list.get(0);
780                    }
781    
782                    return null;
783            }
784    
785            /**
786             * Returns the last d d m template link in the ordered set where templateId = &#63;.
787             *
788             * @param templateId the template ID
789             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
790             * @return the last matching d d m template link
791             * @throws NoSuchTemplateLinkException if a matching d d m template link could not be found
792             */
793            @Override
794            public DDMTemplateLink findByTemplateId_Last(long templateId,
795                    OrderByComparator<DDMTemplateLink> orderByComparator)
796                    throws NoSuchTemplateLinkException {
797                    DDMTemplateLink ddmTemplateLink = fetchByTemplateId_Last(templateId,
798                                    orderByComparator);
799    
800                    if (ddmTemplateLink != null) {
801                            return ddmTemplateLink;
802                    }
803    
804                    StringBundler msg = new StringBundler(4);
805    
806                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
807    
808                    msg.append("templateId=");
809                    msg.append(templateId);
810    
811                    msg.append(StringPool.CLOSE_CURLY_BRACE);
812    
813                    throw new NoSuchTemplateLinkException(msg.toString());
814            }
815    
816            /**
817             * Returns the last d d m template link in the ordered set where templateId = &#63;.
818             *
819             * @param templateId the template ID
820             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
821             * @return the last matching d d m template link, or <code>null</code> if a matching d d m template link could not be found
822             */
823            @Override
824            public DDMTemplateLink fetchByTemplateId_Last(long templateId,
825                    OrderByComparator<DDMTemplateLink> orderByComparator) {
826                    int count = countByTemplateId(templateId);
827    
828                    if (count == 0) {
829                            return null;
830                    }
831    
832                    List<DDMTemplateLink> list = findByTemplateId(templateId, count - 1,
833                                    count, orderByComparator);
834    
835                    if (!list.isEmpty()) {
836                            return list.get(0);
837                    }
838    
839                    return null;
840            }
841    
842            /**
843             * Returns the d d m template links before and after the current d d m template link in the ordered set where templateId = &#63;.
844             *
845             * @param templateLinkId the primary key of the current d d m template link
846             * @param templateId the template ID
847             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
848             * @return the previous, current, and next d d m template link
849             * @throws NoSuchTemplateLinkException if a d d m template link with the primary key could not be found
850             */
851            @Override
852            public DDMTemplateLink[] findByTemplateId_PrevAndNext(long templateLinkId,
853                    long templateId, OrderByComparator<DDMTemplateLink> orderByComparator)
854                    throws NoSuchTemplateLinkException {
855                    DDMTemplateLink ddmTemplateLink = findByPrimaryKey(templateLinkId);
856    
857                    Session session = null;
858    
859                    try {
860                            session = openSession();
861    
862                            DDMTemplateLink[] array = new DDMTemplateLinkImpl[3];
863    
864                            array[0] = getByTemplateId_PrevAndNext(session, ddmTemplateLink,
865                                            templateId, orderByComparator, true);
866    
867                            array[1] = ddmTemplateLink;
868    
869                            array[2] = getByTemplateId_PrevAndNext(session, ddmTemplateLink,
870                                            templateId, orderByComparator, false);
871    
872                            return array;
873                    }
874                    catch (Exception e) {
875                            throw processException(e);
876                    }
877                    finally {
878                            closeSession(session);
879                    }
880            }
881    
882            protected DDMTemplateLink getByTemplateId_PrevAndNext(Session session,
883                    DDMTemplateLink ddmTemplateLink, long templateId,
884                    OrderByComparator<DDMTemplateLink> orderByComparator, boolean previous) {
885                    StringBundler query = null;
886    
887                    if (orderByComparator != null) {
888                            query = new StringBundler(6 +
889                                            (orderByComparator.getOrderByFields().length * 6));
890                    }
891                    else {
892                            query = new StringBundler(3);
893                    }
894    
895                    query.append(_SQL_SELECT_DDMTEMPLATELINK_WHERE);
896    
897                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2);
898    
899                    if (orderByComparator != null) {
900                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
901    
902                            if (orderByConditionFields.length > 0) {
903                                    query.append(WHERE_AND);
904                            }
905    
906                            for (int i = 0; i < orderByConditionFields.length; i++) {
907                                    query.append(_ORDER_BY_ENTITY_ALIAS);
908                                    query.append(orderByConditionFields[i]);
909    
910                                    if ((i + 1) < orderByConditionFields.length) {
911                                            if (orderByComparator.isAscending() ^ previous) {
912                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
913                                            }
914                                            else {
915                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
916                                            }
917                                    }
918                                    else {
919                                            if (orderByComparator.isAscending() ^ previous) {
920                                                    query.append(WHERE_GREATER_THAN);
921                                            }
922                                            else {
923                                                    query.append(WHERE_LESSER_THAN);
924                                            }
925                                    }
926                            }
927    
928                            query.append(ORDER_BY_CLAUSE);
929    
930                            String[] orderByFields = orderByComparator.getOrderByFields();
931    
932                            for (int i = 0; i < orderByFields.length; i++) {
933                                    query.append(_ORDER_BY_ENTITY_ALIAS);
934                                    query.append(orderByFields[i]);
935    
936                                    if ((i + 1) < orderByFields.length) {
937                                            if (orderByComparator.isAscending() ^ previous) {
938                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
939                                            }
940                                            else {
941                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
942                                            }
943                                    }
944                                    else {
945                                            if (orderByComparator.isAscending() ^ previous) {
946                                                    query.append(ORDER_BY_ASC);
947                                            }
948                                            else {
949                                                    query.append(ORDER_BY_DESC);
950                                            }
951                                    }
952                            }
953                    }
954                    else {
955                            query.append(DDMTemplateLinkModelImpl.ORDER_BY_JPQL);
956                    }
957    
958                    String sql = query.toString();
959    
960                    Query q = session.createQuery(sql);
961    
962                    q.setFirstResult(0);
963                    q.setMaxResults(2);
964    
965                    QueryPos qPos = QueryPos.getInstance(q);
966    
967                    qPos.add(templateId);
968    
969                    if (orderByComparator != null) {
970                            Object[] values = orderByComparator.getOrderByConditionValues(ddmTemplateLink);
971    
972                            for (Object value : values) {
973                                    qPos.add(value);
974                            }
975                    }
976    
977                    List<DDMTemplateLink> list = q.list();
978    
979                    if (list.size() == 2) {
980                            return list.get(1);
981                    }
982                    else {
983                            return null;
984                    }
985            }
986    
987            /**
988             * Removes all the d d m template links where templateId = &#63; from the database.
989             *
990             * @param templateId the template ID
991             */
992            @Override
993            public void removeByTemplateId(long templateId) {
994                    for (DDMTemplateLink ddmTemplateLink : findByTemplateId(templateId,
995                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
996                            remove(ddmTemplateLink);
997                    }
998            }
999    
1000            /**
1001             * Returns the number of d d m template links where templateId = &#63;.
1002             *
1003             * @param templateId the template ID
1004             * @return the number of matching d d m template links
1005             */
1006            @Override
1007            public int countByTemplateId(long templateId) {
1008                    FinderPath finderPath = FINDER_PATH_COUNT_BY_TEMPLATEID;
1009    
1010                    Object[] finderArgs = new Object[] { templateId };
1011    
1012                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1013                                    this);
1014    
1015                    if (count == null) {
1016                            StringBundler query = new StringBundler(2);
1017    
1018                            query.append(_SQL_COUNT_DDMTEMPLATELINK_WHERE);
1019    
1020                            query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2);
1021    
1022                            String sql = query.toString();
1023    
1024                            Session session = null;
1025    
1026                            try {
1027                                    session = openSession();
1028    
1029                                    Query q = session.createQuery(sql);
1030    
1031                                    QueryPos qPos = QueryPos.getInstance(q);
1032    
1033                                    qPos.add(templateId);
1034    
1035                                    count = (Long)q.uniqueResult();
1036    
1037                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1038                            }
1039                            catch (Exception e) {
1040                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1041    
1042                                    throw processException(e);
1043                            }
1044                            finally {
1045                                    closeSession(session);
1046                            }
1047                    }
1048    
1049                    return count.intValue();
1050            }
1051    
1052            private static final String _FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2 = "ddmTemplateLink.templateId = ?";
1053            public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(DDMTemplateLinkModelImpl.ENTITY_CACHE_ENABLED,
1054                            DDMTemplateLinkModelImpl.FINDER_CACHE_ENABLED,
1055                            DDMTemplateLinkImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByC_C",
1056                            new String[] { Long.class.getName(), Long.class.getName() },
1057                            DDMTemplateLinkModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1058                            DDMTemplateLinkModelImpl.CLASSPK_COLUMN_BITMASK);
1059            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(DDMTemplateLinkModelImpl.ENTITY_CACHE_ENABLED,
1060                            DDMTemplateLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
1061                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
1062                            new String[] { Long.class.getName(), Long.class.getName() });
1063    
1064            /**
1065             * Returns the d d m template link where classNameId = &#63; and classPK = &#63; or throws a {@link NoSuchTemplateLinkException} if it could not be found.
1066             *
1067             * @param classNameId the class name ID
1068             * @param classPK the class p k
1069             * @return the matching d d m template link
1070             * @throws NoSuchTemplateLinkException if a matching d d m template link could not be found
1071             */
1072            @Override
1073            public DDMTemplateLink findByC_C(long classNameId, long classPK)
1074                    throws NoSuchTemplateLinkException {
1075                    DDMTemplateLink ddmTemplateLink = fetchByC_C(classNameId, classPK);
1076    
1077                    if (ddmTemplateLink == null) {
1078                            StringBundler msg = new StringBundler(6);
1079    
1080                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1081    
1082                            msg.append("classNameId=");
1083                            msg.append(classNameId);
1084    
1085                            msg.append(", classPK=");
1086                            msg.append(classPK);
1087    
1088                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1089    
1090                            if (_log.isWarnEnabled()) {
1091                                    _log.warn(msg.toString());
1092                            }
1093    
1094                            throw new NoSuchTemplateLinkException(msg.toString());
1095                    }
1096    
1097                    return ddmTemplateLink;
1098            }
1099    
1100            /**
1101             * Returns the d d m template link where classNameId = &#63; and classPK = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1102             *
1103             * @param classNameId the class name ID
1104             * @param classPK the class p k
1105             * @return the matching d d m template link, or <code>null</code> if a matching d d m template link could not be found
1106             */
1107            @Override
1108            public DDMTemplateLink fetchByC_C(long classNameId, long classPK) {
1109                    return fetchByC_C(classNameId, classPK, true);
1110            }
1111    
1112            /**
1113             * Returns the d d m template link where classNameId = &#63; and classPK = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1114             *
1115             * @param classNameId the class name ID
1116             * @param classPK the class p k
1117             * @param retrieveFromCache whether to use the finder cache
1118             * @return the matching d d m template link, or <code>null</code> if a matching d d m template link could not be found
1119             */
1120            @Override
1121            public DDMTemplateLink fetchByC_C(long classNameId, long classPK,
1122                    boolean retrieveFromCache) {
1123                    Object[] finderArgs = new Object[] { classNameId, classPK };
1124    
1125                    Object result = null;
1126    
1127                    if (retrieveFromCache) {
1128                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
1129                                            finderArgs, this);
1130                    }
1131    
1132                    if (result instanceof DDMTemplateLink) {
1133                            DDMTemplateLink ddmTemplateLink = (DDMTemplateLink)result;
1134    
1135                            if ((classNameId != ddmTemplateLink.getClassNameId()) ||
1136                                            (classPK != ddmTemplateLink.getClassPK())) {
1137                                    result = null;
1138                            }
1139                    }
1140    
1141                    if (result == null) {
1142                            StringBundler query = new StringBundler(4);
1143    
1144                            query.append(_SQL_SELECT_DDMTEMPLATELINK_WHERE);
1145    
1146                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1147    
1148                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1149    
1150                            String sql = query.toString();
1151    
1152                            Session session = null;
1153    
1154                            try {
1155                                    session = openSession();
1156    
1157                                    Query q = session.createQuery(sql);
1158    
1159                                    QueryPos qPos = QueryPos.getInstance(q);
1160    
1161                                    qPos.add(classNameId);
1162    
1163                                    qPos.add(classPK);
1164    
1165                                    List<DDMTemplateLink> list = q.list();
1166    
1167                                    if (list.isEmpty()) {
1168                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
1169                                                    finderArgs, list);
1170                                    }
1171                                    else {
1172                                            DDMTemplateLink ddmTemplateLink = list.get(0);
1173    
1174                                            result = ddmTemplateLink;
1175    
1176                                            cacheResult(ddmTemplateLink);
1177    
1178                                            if ((ddmTemplateLink.getClassNameId() != classNameId) ||
1179                                                            (ddmTemplateLink.getClassPK() != classPK)) {
1180                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
1181                                                            finderArgs, ddmTemplateLink);
1182                                            }
1183                                    }
1184                            }
1185                            catch (Exception e) {
1186                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
1187                                            finderArgs);
1188    
1189                                    throw processException(e);
1190                            }
1191                            finally {
1192                                    closeSession(session);
1193                            }
1194                    }
1195    
1196                    if (result instanceof List<?>) {
1197                            return null;
1198                    }
1199                    else {
1200                            return (DDMTemplateLink)result;
1201                    }
1202            }
1203    
1204            /**
1205             * Removes the d d m template link where classNameId = &#63; and classPK = &#63; from the database.
1206             *
1207             * @param classNameId the class name ID
1208             * @param classPK the class p k
1209             * @return the d d m template link that was removed
1210             */
1211            @Override
1212            public DDMTemplateLink removeByC_C(long classNameId, long classPK)
1213                    throws NoSuchTemplateLinkException {
1214                    DDMTemplateLink ddmTemplateLink = findByC_C(classNameId, classPK);
1215    
1216                    return remove(ddmTemplateLink);
1217            }
1218    
1219            /**
1220             * Returns the number of d d m template links where classNameId = &#63; and classPK = &#63;.
1221             *
1222             * @param classNameId the class name ID
1223             * @param classPK the class p k
1224             * @return the number of matching d d m template links
1225             */
1226            @Override
1227            public int countByC_C(long classNameId, long classPK) {
1228                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
1229    
1230                    Object[] finderArgs = new Object[] { classNameId, classPK };
1231    
1232                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1233                                    this);
1234    
1235                    if (count == null) {
1236                            StringBundler query = new StringBundler(3);
1237    
1238                            query.append(_SQL_COUNT_DDMTEMPLATELINK_WHERE);
1239    
1240                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1241    
1242                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1243    
1244                            String sql = query.toString();
1245    
1246                            Session session = null;
1247    
1248                            try {
1249                                    session = openSession();
1250    
1251                                    Query q = session.createQuery(sql);
1252    
1253                                    QueryPos qPos = QueryPos.getInstance(q);
1254    
1255                                    qPos.add(classNameId);
1256    
1257                                    qPos.add(classPK);
1258    
1259                                    count = (Long)q.uniqueResult();
1260    
1261                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1262                            }
1263                            catch (Exception e) {
1264                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1265    
1266                                    throw processException(e);
1267                            }
1268                            finally {
1269                                    closeSession(session);
1270                            }
1271                    }
1272    
1273                    return count.intValue();
1274            }
1275    
1276            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "ddmTemplateLink.classNameId = ? AND ";
1277            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "ddmTemplateLink.classPK = ?";
1278    
1279            public DDMTemplateLinkPersistenceImpl() {
1280                    setModelClass(DDMTemplateLink.class);
1281            }
1282    
1283            /**
1284             * Caches the d d m template link in the entity cache if it is enabled.
1285             *
1286             * @param ddmTemplateLink the d d m template link
1287             */
1288            @Override
1289            public void cacheResult(DDMTemplateLink ddmTemplateLink) {
1290                    EntityCacheUtil.putResult(DDMTemplateLinkModelImpl.ENTITY_CACHE_ENABLED,
1291                            DDMTemplateLinkImpl.class, ddmTemplateLink.getPrimaryKey(),
1292                            ddmTemplateLink);
1293    
1294                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
1295                            new Object[] {
1296                                    ddmTemplateLink.getClassNameId(), ddmTemplateLink.getClassPK()
1297                            }, ddmTemplateLink);
1298    
1299                    ddmTemplateLink.resetOriginalValues();
1300            }
1301    
1302            /**
1303             * Caches the d d m template links in the entity cache if it is enabled.
1304             *
1305             * @param ddmTemplateLinks the d d m template links
1306             */
1307            @Override
1308            public void cacheResult(List<DDMTemplateLink> ddmTemplateLinks) {
1309                    for (DDMTemplateLink ddmTemplateLink : ddmTemplateLinks) {
1310                            if (EntityCacheUtil.getResult(
1311                                                    DDMTemplateLinkModelImpl.ENTITY_CACHE_ENABLED,
1312                                                    DDMTemplateLinkImpl.class,
1313                                                    ddmTemplateLink.getPrimaryKey()) == null) {
1314                                    cacheResult(ddmTemplateLink);
1315                            }
1316                            else {
1317                                    ddmTemplateLink.resetOriginalValues();
1318                            }
1319                    }
1320            }
1321    
1322            /**
1323             * Clears the cache for all d d m template links.
1324             *
1325             * <p>
1326             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1327             * </p>
1328             */
1329            @Override
1330            public void clearCache() {
1331                    EntityCacheUtil.clearCache(DDMTemplateLinkImpl.class);
1332    
1333                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1334                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1335                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1336            }
1337    
1338            /**
1339             * Clears the cache for the d d m template link.
1340             *
1341             * <p>
1342             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1343             * </p>
1344             */
1345            @Override
1346            public void clearCache(DDMTemplateLink ddmTemplateLink) {
1347                    EntityCacheUtil.removeResult(DDMTemplateLinkModelImpl.ENTITY_CACHE_ENABLED,
1348                            DDMTemplateLinkImpl.class, ddmTemplateLink.getPrimaryKey());
1349    
1350                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1351                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1352    
1353                    clearUniqueFindersCache(ddmTemplateLink);
1354            }
1355    
1356            @Override
1357            public void clearCache(List<DDMTemplateLink> ddmTemplateLinks) {
1358                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1359                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1360    
1361                    for (DDMTemplateLink ddmTemplateLink : ddmTemplateLinks) {
1362                            EntityCacheUtil.removeResult(DDMTemplateLinkModelImpl.ENTITY_CACHE_ENABLED,
1363                                    DDMTemplateLinkImpl.class, ddmTemplateLink.getPrimaryKey());
1364    
1365                            clearUniqueFindersCache(ddmTemplateLink);
1366                    }
1367            }
1368    
1369            protected void cacheUniqueFindersCache(DDMTemplateLink ddmTemplateLink) {
1370                    if (ddmTemplateLink.isNew()) {
1371                            Object[] args = new Object[] {
1372                                            ddmTemplateLink.getClassNameId(),
1373                                            ddmTemplateLink.getClassPK()
1374                                    };
1375    
1376                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
1377                                    Long.valueOf(1));
1378                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args,
1379                                    ddmTemplateLink);
1380                    }
1381                    else {
1382                            DDMTemplateLinkModelImpl ddmTemplateLinkModelImpl = (DDMTemplateLinkModelImpl)ddmTemplateLink;
1383    
1384                            if ((ddmTemplateLinkModelImpl.getColumnBitmask() &
1385                                            FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
1386                                    Object[] args = new Object[] {
1387                                                    ddmTemplateLink.getClassNameId(),
1388                                                    ddmTemplateLink.getClassPK()
1389                                            };
1390    
1391                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
1392                                            Long.valueOf(1));
1393                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args,
1394                                            ddmTemplateLink);
1395                            }
1396                    }
1397            }
1398    
1399            protected void clearUniqueFindersCache(DDMTemplateLink ddmTemplateLink) {
1400                    DDMTemplateLinkModelImpl ddmTemplateLinkModelImpl = (DDMTemplateLinkModelImpl)ddmTemplateLink;
1401    
1402                    Object[] args = new Object[] {
1403                                    ddmTemplateLink.getClassNameId(), ddmTemplateLink.getClassPK()
1404                            };
1405    
1406                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1407                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
1408    
1409                    if ((ddmTemplateLinkModelImpl.getColumnBitmask() &
1410                                    FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
1411                            args = new Object[] {
1412                                            ddmTemplateLinkModelImpl.getOriginalClassNameId(),
1413                                            ddmTemplateLinkModelImpl.getOriginalClassPK()
1414                                    };
1415    
1416                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1417                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
1418                    }
1419            }
1420    
1421            /**
1422             * Creates a new d d m template link with the primary key. Does not add the d d m template link to the database.
1423             *
1424             * @param templateLinkId the primary key for the new d d m template link
1425             * @return the new d d m template link
1426             */
1427            @Override
1428            public DDMTemplateLink create(long templateLinkId) {
1429                    DDMTemplateLink ddmTemplateLink = new DDMTemplateLinkImpl();
1430    
1431                    ddmTemplateLink.setNew(true);
1432                    ddmTemplateLink.setPrimaryKey(templateLinkId);
1433    
1434                    return ddmTemplateLink;
1435            }
1436    
1437            /**
1438             * Removes the d d m template link with the primary key from the database. Also notifies the appropriate model listeners.
1439             *
1440             * @param templateLinkId the primary key of the d d m template link
1441             * @return the d d m template link that was removed
1442             * @throws NoSuchTemplateLinkException if a d d m template link with the primary key could not be found
1443             */
1444            @Override
1445            public DDMTemplateLink remove(long templateLinkId)
1446                    throws NoSuchTemplateLinkException {
1447                    return remove((Serializable)templateLinkId);
1448            }
1449    
1450            /**
1451             * Removes the d d m template link with the primary key from the database. Also notifies the appropriate model listeners.
1452             *
1453             * @param primaryKey the primary key of the d d m template link
1454             * @return the d d m template link that was removed
1455             * @throws NoSuchTemplateLinkException if a d d m template link with the primary key could not be found
1456             */
1457            @Override
1458            public DDMTemplateLink remove(Serializable primaryKey)
1459                    throws NoSuchTemplateLinkException {
1460                    Session session = null;
1461    
1462                    try {
1463                            session = openSession();
1464    
1465                            DDMTemplateLink ddmTemplateLink = (DDMTemplateLink)session.get(DDMTemplateLinkImpl.class,
1466                                            primaryKey);
1467    
1468                            if (ddmTemplateLink == null) {
1469                                    if (_log.isWarnEnabled()) {
1470                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1471                                    }
1472    
1473                                    throw new NoSuchTemplateLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1474                                            primaryKey);
1475                            }
1476    
1477                            return remove(ddmTemplateLink);
1478                    }
1479                    catch (NoSuchTemplateLinkException nsee) {
1480                            throw nsee;
1481                    }
1482                    catch (Exception e) {
1483                            throw processException(e);
1484                    }
1485                    finally {
1486                            closeSession(session);
1487                    }
1488            }
1489    
1490            @Override
1491            protected DDMTemplateLink removeImpl(DDMTemplateLink ddmTemplateLink) {
1492                    ddmTemplateLink = toUnwrappedModel(ddmTemplateLink);
1493    
1494                    Session session = null;
1495    
1496                    try {
1497                            session = openSession();
1498    
1499                            if (!session.contains(ddmTemplateLink)) {
1500                                    ddmTemplateLink = (DDMTemplateLink)session.get(DDMTemplateLinkImpl.class,
1501                                                    ddmTemplateLink.getPrimaryKeyObj());
1502                            }
1503    
1504                            if (ddmTemplateLink != null) {
1505                                    session.delete(ddmTemplateLink);
1506                            }
1507                    }
1508                    catch (Exception e) {
1509                            throw processException(e);
1510                    }
1511                    finally {
1512                            closeSession(session);
1513                    }
1514    
1515                    if (ddmTemplateLink != null) {
1516                            clearCache(ddmTemplateLink);
1517                    }
1518    
1519                    return ddmTemplateLink;
1520            }
1521    
1522            @Override
1523            public DDMTemplateLink updateImpl(DDMTemplateLink ddmTemplateLink) {
1524                    ddmTemplateLink = toUnwrappedModel(ddmTemplateLink);
1525    
1526                    boolean isNew = ddmTemplateLink.isNew();
1527    
1528                    DDMTemplateLinkModelImpl ddmTemplateLinkModelImpl = (DDMTemplateLinkModelImpl)ddmTemplateLink;
1529    
1530                    Session session = null;
1531    
1532                    try {
1533                            session = openSession();
1534    
1535                            if (ddmTemplateLink.isNew()) {
1536                                    session.save(ddmTemplateLink);
1537    
1538                                    ddmTemplateLink.setNew(false);
1539                            }
1540                            else {
1541                                    session.merge(ddmTemplateLink);
1542                            }
1543                    }
1544                    catch (Exception e) {
1545                            throw processException(e);
1546                    }
1547                    finally {
1548                            closeSession(session);
1549                    }
1550    
1551                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1552    
1553                    if (isNew || !DDMTemplateLinkModelImpl.COLUMN_BITMASK_ENABLED) {
1554                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1555                    }
1556    
1557                    else {
1558                            if ((ddmTemplateLinkModelImpl.getColumnBitmask() &
1559                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID.getColumnBitmask()) != 0) {
1560                                    Object[] args = new Object[] {
1561                                                    ddmTemplateLinkModelImpl.getOriginalClassNameId()
1562                                            };
1563    
1564                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
1565                                            args);
1566                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID,
1567                                            args);
1568    
1569                                    args = new Object[] { ddmTemplateLinkModelImpl.getClassNameId() };
1570    
1571                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
1572                                            args);
1573                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID,
1574                                            args);
1575                            }
1576    
1577                            if ((ddmTemplateLinkModelImpl.getColumnBitmask() &
1578                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID.getColumnBitmask()) != 0) {
1579                                    Object[] args = new Object[] {
1580                                                    ddmTemplateLinkModelImpl.getOriginalTemplateId()
1581                                            };
1582    
1583                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TEMPLATEID,
1584                                            args);
1585                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID,
1586                                            args);
1587    
1588                                    args = new Object[] { ddmTemplateLinkModelImpl.getTemplateId() };
1589    
1590                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TEMPLATEID,
1591                                            args);
1592                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID,
1593                                            args);
1594                            }
1595                    }
1596    
1597                    EntityCacheUtil.putResult(DDMTemplateLinkModelImpl.ENTITY_CACHE_ENABLED,
1598                            DDMTemplateLinkImpl.class, ddmTemplateLink.getPrimaryKey(),
1599                            ddmTemplateLink, false);
1600    
1601                    clearUniqueFindersCache(ddmTemplateLink);
1602                    cacheUniqueFindersCache(ddmTemplateLink);
1603    
1604                    ddmTemplateLink.resetOriginalValues();
1605    
1606                    return ddmTemplateLink;
1607            }
1608    
1609            protected DDMTemplateLink toUnwrappedModel(DDMTemplateLink ddmTemplateLink) {
1610                    if (ddmTemplateLink instanceof DDMTemplateLinkImpl) {
1611                            return ddmTemplateLink;
1612                    }
1613    
1614                    DDMTemplateLinkImpl ddmTemplateLinkImpl = new DDMTemplateLinkImpl();
1615    
1616                    ddmTemplateLinkImpl.setNew(ddmTemplateLink.isNew());
1617                    ddmTemplateLinkImpl.setPrimaryKey(ddmTemplateLink.getPrimaryKey());
1618    
1619                    ddmTemplateLinkImpl.setTemplateLinkId(ddmTemplateLink.getTemplateLinkId());
1620                    ddmTemplateLinkImpl.setClassNameId(ddmTemplateLink.getClassNameId());
1621                    ddmTemplateLinkImpl.setClassPK(ddmTemplateLink.getClassPK());
1622                    ddmTemplateLinkImpl.setTemplateId(ddmTemplateLink.getTemplateId());
1623    
1624                    return ddmTemplateLinkImpl;
1625            }
1626    
1627            /**
1628             * Returns the d d m template link with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1629             *
1630             * @param primaryKey the primary key of the d d m template link
1631             * @return the d d m template link
1632             * @throws NoSuchTemplateLinkException if a d d m template link with the primary key could not be found
1633             */
1634            @Override
1635            public DDMTemplateLink findByPrimaryKey(Serializable primaryKey)
1636                    throws NoSuchTemplateLinkException {
1637                    DDMTemplateLink ddmTemplateLink = fetchByPrimaryKey(primaryKey);
1638    
1639                    if (ddmTemplateLink == null) {
1640                            if (_log.isWarnEnabled()) {
1641                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1642                            }
1643    
1644                            throw new NoSuchTemplateLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1645                                    primaryKey);
1646                    }
1647    
1648                    return ddmTemplateLink;
1649            }
1650    
1651            /**
1652             * Returns the d d m template link with the primary key or throws a {@link NoSuchTemplateLinkException} if it could not be found.
1653             *
1654             * @param templateLinkId the primary key of the d d m template link
1655             * @return the d d m template link
1656             * @throws NoSuchTemplateLinkException if a d d m template link with the primary key could not be found
1657             */
1658            @Override
1659            public DDMTemplateLink findByPrimaryKey(long templateLinkId)
1660                    throws NoSuchTemplateLinkException {
1661                    return findByPrimaryKey((Serializable)templateLinkId);
1662            }
1663    
1664            /**
1665             * Returns the d d m template link with the primary key or returns <code>null</code> if it could not be found.
1666             *
1667             * @param primaryKey the primary key of the d d m template link
1668             * @return the d d m template link, or <code>null</code> if a d d m template link with the primary key could not be found
1669             */
1670            @Override
1671            public DDMTemplateLink fetchByPrimaryKey(Serializable primaryKey) {
1672                    DDMTemplateLink ddmTemplateLink = (DDMTemplateLink)EntityCacheUtil.getResult(DDMTemplateLinkModelImpl.ENTITY_CACHE_ENABLED,
1673                                    DDMTemplateLinkImpl.class, primaryKey);
1674    
1675                    if (ddmTemplateLink == _nullDDMTemplateLink) {
1676                            return null;
1677                    }
1678    
1679                    if (ddmTemplateLink == null) {
1680                            Session session = null;
1681    
1682                            try {
1683                                    session = openSession();
1684    
1685                                    ddmTemplateLink = (DDMTemplateLink)session.get(DDMTemplateLinkImpl.class,
1686                                                    primaryKey);
1687    
1688                                    if (ddmTemplateLink != null) {
1689                                            cacheResult(ddmTemplateLink);
1690                                    }
1691                                    else {
1692                                            EntityCacheUtil.putResult(DDMTemplateLinkModelImpl.ENTITY_CACHE_ENABLED,
1693                                                    DDMTemplateLinkImpl.class, primaryKey,
1694                                                    _nullDDMTemplateLink);
1695                                    }
1696                            }
1697                            catch (Exception e) {
1698                                    EntityCacheUtil.removeResult(DDMTemplateLinkModelImpl.ENTITY_CACHE_ENABLED,
1699                                            DDMTemplateLinkImpl.class, primaryKey);
1700    
1701                                    throw processException(e);
1702                            }
1703                            finally {
1704                                    closeSession(session);
1705                            }
1706                    }
1707    
1708                    return ddmTemplateLink;
1709            }
1710    
1711            /**
1712             * Returns the d d m template link with the primary key or returns <code>null</code> if it could not be found.
1713             *
1714             * @param templateLinkId the primary key of the d d m template link
1715             * @return the d d m template link, or <code>null</code> if a d d m template link with the primary key could not be found
1716             */
1717            @Override
1718            public DDMTemplateLink fetchByPrimaryKey(long templateLinkId) {
1719                    return fetchByPrimaryKey((Serializable)templateLinkId);
1720            }
1721    
1722            @Override
1723            public Map<Serializable, DDMTemplateLink> fetchByPrimaryKeys(
1724                    Set<Serializable> primaryKeys) {
1725                    if (primaryKeys.isEmpty()) {
1726                            return Collections.emptyMap();
1727                    }
1728    
1729                    Map<Serializable, DDMTemplateLink> map = new HashMap<Serializable, DDMTemplateLink>();
1730    
1731                    if (primaryKeys.size() == 1) {
1732                            Iterator<Serializable> iterator = primaryKeys.iterator();
1733    
1734                            Serializable primaryKey = iterator.next();
1735    
1736                            DDMTemplateLink ddmTemplateLink = fetchByPrimaryKey(primaryKey);
1737    
1738                            if (ddmTemplateLink != null) {
1739                                    map.put(primaryKey, ddmTemplateLink);
1740                            }
1741    
1742                            return map;
1743                    }
1744    
1745                    Set<Serializable> uncachedPrimaryKeys = null;
1746    
1747                    for (Serializable primaryKey : primaryKeys) {
1748                            DDMTemplateLink ddmTemplateLink = (DDMTemplateLink)EntityCacheUtil.getResult(DDMTemplateLinkModelImpl.ENTITY_CACHE_ENABLED,
1749                                            DDMTemplateLinkImpl.class, primaryKey);
1750    
1751                            if (ddmTemplateLink == null) {
1752                                    if (uncachedPrimaryKeys == null) {
1753                                            uncachedPrimaryKeys = new HashSet<Serializable>();
1754                                    }
1755    
1756                                    uncachedPrimaryKeys.add(primaryKey);
1757                            }
1758                            else {
1759                                    map.put(primaryKey, ddmTemplateLink);
1760                            }
1761                    }
1762    
1763                    if (uncachedPrimaryKeys == null) {
1764                            return map;
1765                    }
1766    
1767                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1768                                    1);
1769    
1770                    query.append(_SQL_SELECT_DDMTEMPLATELINK_WHERE_PKS_IN);
1771    
1772                    for (Serializable primaryKey : uncachedPrimaryKeys) {
1773                            query.append(String.valueOf(primaryKey));
1774    
1775                            query.append(StringPool.COMMA);
1776                    }
1777    
1778                    query.setIndex(query.index() - 1);
1779    
1780                    query.append(StringPool.CLOSE_PARENTHESIS);
1781    
1782                    String sql = query.toString();
1783    
1784                    Session session = null;
1785    
1786                    try {
1787                            session = openSession();
1788    
1789                            Query q = session.createQuery(sql);
1790    
1791                            for (DDMTemplateLink ddmTemplateLink : (List<DDMTemplateLink>)q.list()) {
1792                                    map.put(ddmTemplateLink.getPrimaryKeyObj(), ddmTemplateLink);
1793    
1794                                    cacheResult(ddmTemplateLink);
1795    
1796                                    uncachedPrimaryKeys.remove(ddmTemplateLink.getPrimaryKeyObj());
1797                            }
1798    
1799                            for (Serializable primaryKey : uncachedPrimaryKeys) {
1800                                    EntityCacheUtil.putResult(DDMTemplateLinkModelImpl.ENTITY_CACHE_ENABLED,
1801                                            DDMTemplateLinkImpl.class, primaryKey, _nullDDMTemplateLink);
1802                            }
1803                    }
1804                    catch (Exception e) {
1805                            throw processException(e);
1806                    }
1807                    finally {
1808                            closeSession(session);
1809                    }
1810    
1811                    return map;
1812            }
1813    
1814            /**
1815             * Returns all the d d m template links.
1816             *
1817             * @return the d d m template links
1818             */
1819            @Override
1820            public List<DDMTemplateLink> findAll() {
1821                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1822            }
1823    
1824            /**
1825             * Returns a range of all the d d m template links.
1826             *
1827             * <p>
1828             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DDMTemplateLinkModelImpl}. 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.
1829             * </p>
1830             *
1831             * @param start the lower bound of the range of d d m template links
1832             * @param end the upper bound of the range of d d m template links (not inclusive)
1833             * @return the range of d d m template links
1834             */
1835            @Override
1836            public List<DDMTemplateLink> findAll(int start, int end) {
1837                    return findAll(start, end, null);
1838            }
1839    
1840            /**
1841             * Returns an ordered range of all the d d m template links.
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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DDMTemplateLinkModelImpl}. 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 start the lower bound of the range of d d m template links
1848             * @param end the upper bound of the range of d d m template links (not inclusive)
1849             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1850             * @return the ordered range of d d m template links
1851             */
1852            @Override
1853            public List<DDMTemplateLink> findAll(int start, int end,
1854                    OrderByComparator<DDMTemplateLink> orderByComparator) {
1855                    boolean pagination = true;
1856                    FinderPath finderPath = null;
1857                    Object[] finderArgs = null;
1858    
1859                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1860                                    (orderByComparator == null)) {
1861                            pagination = false;
1862                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1863                            finderArgs = FINDER_ARGS_EMPTY;
1864                    }
1865                    else {
1866                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1867                            finderArgs = new Object[] { start, end, orderByComparator };
1868                    }
1869    
1870                    List<DDMTemplateLink> list = (List<DDMTemplateLink>)FinderCacheUtil.getResult(finderPath,
1871                                    finderArgs, this);
1872    
1873                    if (list == null) {
1874                            StringBundler query = null;
1875                            String sql = null;
1876    
1877                            if (orderByComparator != null) {
1878                                    query = new StringBundler(2 +
1879                                                    (orderByComparator.getOrderByFields().length * 3));
1880    
1881                                    query.append(_SQL_SELECT_DDMTEMPLATELINK);
1882    
1883                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1884                                            orderByComparator);
1885    
1886                                    sql = query.toString();
1887                            }
1888                            else {
1889                                    sql = _SQL_SELECT_DDMTEMPLATELINK;
1890    
1891                                    if (pagination) {
1892                                            sql = sql.concat(DDMTemplateLinkModelImpl.ORDER_BY_JPQL);
1893                                    }
1894                            }
1895    
1896                            Session session = null;
1897    
1898                            try {
1899                                    session = openSession();
1900    
1901                                    Query q = session.createQuery(sql);
1902    
1903                                    if (!pagination) {
1904                                            list = (List<DDMTemplateLink>)QueryUtil.list(q,
1905                                                            getDialect(), start, end, false);
1906    
1907                                            Collections.sort(list);
1908    
1909                                            list = Collections.unmodifiableList(list);
1910                                    }
1911                                    else {
1912                                            list = (List<DDMTemplateLink>)QueryUtil.list(q,
1913                                                            getDialect(), start, end);
1914                                    }
1915    
1916                                    cacheResult(list);
1917    
1918                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1919                            }
1920                            catch (Exception e) {
1921                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1922    
1923                                    throw processException(e);
1924                            }
1925                            finally {
1926                                    closeSession(session);
1927                            }
1928                    }
1929    
1930                    return list;
1931            }
1932    
1933            /**
1934             * Removes all the d d m template links from the database.
1935             *
1936             */
1937            @Override
1938            public void removeAll() {
1939                    for (DDMTemplateLink ddmTemplateLink : findAll()) {
1940                            remove(ddmTemplateLink);
1941                    }
1942            }
1943    
1944            /**
1945             * Returns the number of d d m template links.
1946             *
1947             * @return the number of d d m template links
1948             */
1949            @Override
1950            public int countAll() {
1951                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1952                                    FINDER_ARGS_EMPTY, this);
1953    
1954                    if (count == null) {
1955                            Session session = null;
1956    
1957                            try {
1958                                    session = openSession();
1959    
1960                                    Query q = session.createQuery(_SQL_COUNT_DDMTEMPLATELINK);
1961    
1962                                    count = (Long)q.uniqueResult();
1963    
1964                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1965                                            FINDER_ARGS_EMPTY, count);
1966                            }
1967                            catch (Exception e) {
1968                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1969                                            FINDER_ARGS_EMPTY);
1970    
1971                                    throw processException(e);
1972                            }
1973                            finally {
1974                                    closeSession(session);
1975                            }
1976                    }
1977    
1978                    return count.intValue();
1979            }
1980    
1981            /**
1982             * Initializes the d d m template link persistence.
1983             */
1984            public void afterPropertiesSet() {
1985            }
1986    
1987            public void destroy() {
1988                    EntityCacheUtil.removeCache(DDMTemplateLinkImpl.class.getName());
1989                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1990                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1991                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1992            }
1993    
1994            private static final String _SQL_SELECT_DDMTEMPLATELINK = "SELECT ddmTemplateLink FROM DDMTemplateLink ddmTemplateLink";
1995            private static final String _SQL_SELECT_DDMTEMPLATELINK_WHERE_PKS_IN = "SELECT ddmTemplateLink FROM DDMTemplateLink ddmTemplateLink WHERE templateLinkId IN (";
1996            private static final String _SQL_SELECT_DDMTEMPLATELINK_WHERE = "SELECT ddmTemplateLink FROM DDMTemplateLink ddmTemplateLink WHERE ";
1997            private static final String _SQL_COUNT_DDMTEMPLATELINK = "SELECT COUNT(ddmTemplateLink) FROM DDMTemplateLink ddmTemplateLink";
1998            private static final String _SQL_COUNT_DDMTEMPLATELINK_WHERE = "SELECT COUNT(ddmTemplateLink) FROM DDMTemplateLink ddmTemplateLink WHERE ";
1999            private static final String _ORDER_BY_ENTITY_ALIAS = "ddmTemplateLink.";
2000            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DDMTemplateLink exists with the primary key ";
2001            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DDMTemplateLink exists with the key {";
2002            private static final Log _log = LogFactoryUtil.getLog(DDMTemplateLinkPersistenceImpl.class);
2003            private static final DDMTemplateLink _nullDDMTemplateLink = new DDMTemplateLinkImpl() {
2004                            @Override
2005                            public Object clone() {
2006                                    return this;
2007                            }
2008    
2009                            @Override
2010                            public CacheModel<DDMTemplateLink> toCacheModel() {
2011                                    return _nullDDMTemplateLinkCacheModel;
2012                            }
2013                    };
2014    
2015            private static final CacheModel<DDMTemplateLink> _nullDDMTemplateLinkCacheModel =
2016                    new CacheModel<DDMTemplateLink>() {
2017                            @Override
2018                            public DDMTemplateLink toEntityModel() {
2019                                    return _nullDDMTemplateLink;
2020                            }
2021                    };
2022    }