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.portal.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.NoSuchWorkflowDefinitionLinkException;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.OrderByComparator;
030    import com.liferay.portal.kernel.util.StringBundler;
031    import com.liferay.portal.kernel.util.StringPool;
032    import com.liferay.portal.kernel.util.StringUtil;
033    import com.liferay.portal.kernel.util.Validator;
034    import com.liferay.portal.model.CacheModel;
035    import com.liferay.portal.model.MVCCModel;
036    import com.liferay.portal.model.WorkflowDefinitionLink;
037    import com.liferay.portal.model.impl.WorkflowDefinitionLinkImpl;
038    import com.liferay.portal.model.impl.WorkflowDefinitionLinkModelImpl;
039    import com.liferay.portal.service.ServiceContext;
040    import com.liferay.portal.service.ServiceContextThreadLocal;
041    import com.liferay.portal.service.persistence.WorkflowDefinitionLinkPersistence;
042    
043    import java.io.Serializable;
044    
045    import java.util.Collections;
046    import java.util.Date;
047    import java.util.HashMap;
048    import java.util.HashSet;
049    import java.util.Iterator;
050    import java.util.List;
051    import java.util.Map;
052    import java.util.Set;
053    
054    /**
055     * The persistence implementation for the workflow definition link service.
056     *
057     * <p>
058     * Caching information and settings can be found in <code>portal.properties</code>
059     * </p>
060     *
061     * @author Brian Wing Shun Chan
062     * @see WorkflowDefinitionLinkPersistence
063     * @see com.liferay.portal.service.persistence.WorkflowDefinitionLinkUtil
064     * @generated
065     */
066    @ProviderType
067    public class WorkflowDefinitionLinkPersistenceImpl extends BasePersistenceImpl<WorkflowDefinitionLink>
068            implements WorkflowDefinitionLinkPersistence {
069            /*
070             * NOTE FOR DEVELOPERS:
071             *
072             * Never modify or reference this class directly. Always use {@link WorkflowDefinitionLinkUtil} to access the workflow definition link persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
073             */
074            public static final String FINDER_CLASS_NAME_ENTITY = WorkflowDefinitionLinkImpl.class.getName();
075            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076                    ".List1";
077            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List2";
079            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
080                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
081                            WorkflowDefinitionLinkImpl.class,
082                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
083            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
084                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
085                            WorkflowDefinitionLinkImpl.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
087            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
088                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
089                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
090            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
091                    new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
092                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
093                            WorkflowDefinitionLinkImpl.class,
094                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
095                            new String[] {
096                                    Long.class.getName(),
097                                    
098                            Integer.class.getName(), Integer.class.getName(),
099                                    OrderByComparator.class.getName()
100                            });
101            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
102                    new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
103                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
104                            WorkflowDefinitionLinkImpl.class,
105                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
106                            new String[] { Long.class.getName() },
107                            WorkflowDefinitionLinkModelImpl.COMPANYID_COLUMN_BITMASK |
108                            WorkflowDefinitionLinkModelImpl.WORKFLOWDEFINITIONNAME_COLUMN_BITMASK);
109            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
110                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
111                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
112                            new String[] { Long.class.getName() });
113    
114            /**
115             * Returns all the workflow definition links where companyId = &#63;.
116             *
117             * @param companyId the company ID
118             * @return the matching workflow definition links
119             */
120            @Override
121            public List<WorkflowDefinitionLink> findByCompanyId(long companyId) {
122                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
123                            null);
124            }
125    
126            /**
127             * Returns a range of all the workflow definition links where companyId = &#63;.
128             *
129             * <p>
130             * 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 WorkflowDefinitionLinkModelImpl}. 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.
131             * </p>
132             *
133             * @param companyId the company ID
134             * @param start the lower bound of the range of workflow definition links
135             * @param end the upper bound of the range of workflow definition links (not inclusive)
136             * @return the range of matching workflow definition links
137             */
138            @Override
139            public List<WorkflowDefinitionLink> findByCompanyId(long companyId,
140                    int start, int end) {
141                    return findByCompanyId(companyId, start, end, null);
142            }
143    
144            /**
145             * Returns an ordered range of all the workflow definition links where companyId = &#63;.
146             *
147             * <p>
148             * 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 WorkflowDefinitionLinkModelImpl}. 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.
149             * </p>
150             *
151             * @param companyId the company ID
152             * @param start the lower bound of the range of workflow definition links
153             * @param end the upper bound of the range of workflow definition links (not inclusive)
154             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
155             * @return the ordered range of matching workflow definition links
156             */
157            @Override
158            public List<WorkflowDefinitionLink> findByCompanyId(long companyId,
159                    int start, int end,
160                    OrderByComparator<WorkflowDefinitionLink> orderByComparator) {
161                    boolean pagination = true;
162                    FinderPath finderPath = null;
163                    Object[] finderArgs = null;
164    
165                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
166                                    (orderByComparator == null)) {
167                            pagination = false;
168                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
169                            finderArgs = new Object[] { companyId };
170                    }
171                    else {
172                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
173                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
174                    }
175    
176                    List<WorkflowDefinitionLink> list = (List<WorkflowDefinitionLink>)FinderCacheUtil.getResult(finderPath,
177                                    finderArgs, this);
178    
179                    if ((list != null) && !list.isEmpty()) {
180                            for (WorkflowDefinitionLink workflowDefinitionLink : list) {
181                                    if ((companyId != workflowDefinitionLink.getCompanyId())) {
182                                            list = null;
183    
184                                            break;
185                                    }
186                            }
187                    }
188    
189                    if (list == null) {
190                            StringBundler query = null;
191    
192                            if (orderByComparator != null) {
193                                    query = new StringBundler(3 +
194                                                    (orderByComparator.getOrderByFields().length * 3));
195                            }
196                            else {
197                                    query = new StringBundler(3);
198                            }
199    
200                            query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE);
201    
202                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
203    
204                            if (orderByComparator != null) {
205                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
206                                            orderByComparator);
207                            }
208                            else
209                             if (pagination) {
210                                    query.append(WorkflowDefinitionLinkModelImpl.ORDER_BY_JPQL);
211                            }
212    
213                            String sql = query.toString();
214    
215                            Session session = null;
216    
217                            try {
218                                    session = openSession();
219    
220                                    Query q = session.createQuery(sql);
221    
222                                    QueryPos qPos = QueryPos.getInstance(q);
223    
224                                    qPos.add(companyId);
225    
226                                    if (!pagination) {
227                                            list = (List<WorkflowDefinitionLink>)QueryUtil.list(q,
228                                                            getDialect(), start, end, false);
229    
230                                            Collections.sort(list);
231    
232                                            list = Collections.unmodifiableList(list);
233                                    }
234                                    else {
235                                            list = (List<WorkflowDefinitionLink>)QueryUtil.list(q,
236                                                            getDialect(), start, end);
237                                    }
238    
239                                    cacheResult(list);
240    
241                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
242                            }
243                            catch (Exception e) {
244                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
245    
246                                    throw processException(e);
247                            }
248                            finally {
249                                    closeSession(session);
250                            }
251                    }
252    
253                    return list;
254            }
255    
256            /**
257             * Returns the first workflow definition link in the ordered set where companyId = &#63;.
258             *
259             * @param companyId the company ID
260             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
261             * @return the first matching workflow definition link
262             * @throws NoSuchWorkflowDefinitionLinkException if a matching workflow definition link could not be found
263             */
264            @Override
265            public WorkflowDefinitionLink findByCompanyId_First(long companyId,
266                    OrderByComparator<WorkflowDefinitionLink> orderByComparator)
267                    throws NoSuchWorkflowDefinitionLinkException {
268                    WorkflowDefinitionLink workflowDefinitionLink = fetchByCompanyId_First(companyId,
269                                    orderByComparator);
270    
271                    if (workflowDefinitionLink != null) {
272                            return workflowDefinitionLink;
273                    }
274    
275                    StringBundler msg = new StringBundler(4);
276    
277                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
278    
279                    msg.append("companyId=");
280                    msg.append(companyId);
281    
282                    msg.append(StringPool.CLOSE_CURLY_BRACE);
283    
284                    throw new NoSuchWorkflowDefinitionLinkException(msg.toString());
285            }
286    
287            /**
288             * Returns the first workflow definition link in the ordered set where companyId = &#63;.
289             *
290             * @param companyId the company ID
291             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
292             * @return the first matching workflow definition link, or <code>null</code> if a matching workflow definition link could not be found
293             */
294            @Override
295            public WorkflowDefinitionLink fetchByCompanyId_First(long companyId,
296                    OrderByComparator<WorkflowDefinitionLink> orderByComparator) {
297                    List<WorkflowDefinitionLink> list = findByCompanyId(companyId, 0, 1,
298                                    orderByComparator);
299    
300                    if (!list.isEmpty()) {
301                            return list.get(0);
302                    }
303    
304                    return null;
305            }
306    
307            /**
308             * Returns the last workflow definition link in the ordered set where companyId = &#63;.
309             *
310             * @param companyId the company ID
311             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
312             * @return the last matching workflow definition link
313             * @throws NoSuchWorkflowDefinitionLinkException if a matching workflow definition link could not be found
314             */
315            @Override
316            public WorkflowDefinitionLink findByCompanyId_Last(long companyId,
317                    OrderByComparator<WorkflowDefinitionLink> orderByComparator)
318                    throws NoSuchWorkflowDefinitionLinkException {
319                    WorkflowDefinitionLink workflowDefinitionLink = fetchByCompanyId_Last(companyId,
320                                    orderByComparator);
321    
322                    if (workflowDefinitionLink != null) {
323                            return workflowDefinitionLink;
324                    }
325    
326                    StringBundler msg = new StringBundler(4);
327    
328                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
329    
330                    msg.append("companyId=");
331                    msg.append(companyId);
332    
333                    msg.append(StringPool.CLOSE_CURLY_BRACE);
334    
335                    throw new NoSuchWorkflowDefinitionLinkException(msg.toString());
336            }
337    
338            /**
339             * Returns the last workflow definition link in the ordered set where companyId = &#63;.
340             *
341             * @param companyId the company ID
342             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
343             * @return the last matching workflow definition link, or <code>null</code> if a matching workflow definition link could not be found
344             */
345            @Override
346            public WorkflowDefinitionLink fetchByCompanyId_Last(long companyId,
347                    OrderByComparator<WorkflowDefinitionLink> orderByComparator) {
348                    int count = countByCompanyId(companyId);
349    
350                    if (count == 0) {
351                            return null;
352                    }
353    
354                    List<WorkflowDefinitionLink> list = findByCompanyId(companyId,
355                                    count - 1, count, orderByComparator);
356    
357                    if (!list.isEmpty()) {
358                            return list.get(0);
359                    }
360    
361                    return null;
362            }
363    
364            /**
365             * Returns the workflow definition links before and after the current workflow definition link in the ordered set where companyId = &#63;.
366             *
367             * @param workflowDefinitionLinkId the primary key of the current workflow definition link
368             * @param companyId the company ID
369             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
370             * @return the previous, current, and next workflow definition link
371             * @throws NoSuchWorkflowDefinitionLinkException if a workflow definition link with the primary key could not be found
372             */
373            @Override
374            public WorkflowDefinitionLink[] findByCompanyId_PrevAndNext(
375                    long workflowDefinitionLinkId, long companyId,
376                    OrderByComparator<WorkflowDefinitionLink> orderByComparator)
377                    throws NoSuchWorkflowDefinitionLinkException {
378                    WorkflowDefinitionLink workflowDefinitionLink = findByPrimaryKey(workflowDefinitionLinkId);
379    
380                    Session session = null;
381    
382                    try {
383                            session = openSession();
384    
385                            WorkflowDefinitionLink[] array = new WorkflowDefinitionLinkImpl[3];
386    
387                            array[0] = getByCompanyId_PrevAndNext(session,
388                                            workflowDefinitionLink, companyId, orderByComparator, true);
389    
390                            array[1] = workflowDefinitionLink;
391    
392                            array[2] = getByCompanyId_PrevAndNext(session,
393                                            workflowDefinitionLink, companyId, orderByComparator, false);
394    
395                            return array;
396                    }
397                    catch (Exception e) {
398                            throw processException(e);
399                    }
400                    finally {
401                            closeSession(session);
402                    }
403            }
404    
405            protected WorkflowDefinitionLink getByCompanyId_PrevAndNext(
406                    Session session, WorkflowDefinitionLink workflowDefinitionLink,
407                    long companyId,
408                    OrderByComparator<WorkflowDefinitionLink> orderByComparator,
409                    boolean previous) {
410                    StringBundler query = null;
411    
412                    if (orderByComparator != null) {
413                            query = new StringBundler(6 +
414                                            (orderByComparator.getOrderByFields().length * 6));
415                    }
416                    else {
417                            query = new StringBundler(3);
418                    }
419    
420                    query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE);
421    
422                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
423    
424                    if (orderByComparator != null) {
425                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
426    
427                            if (orderByConditionFields.length > 0) {
428                                    query.append(WHERE_AND);
429                            }
430    
431                            for (int i = 0; i < orderByConditionFields.length; i++) {
432                                    query.append(_ORDER_BY_ENTITY_ALIAS);
433                                    query.append(orderByConditionFields[i]);
434    
435                                    if ((i + 1) < orderByConditionFields.length) {
436                                            if (orderByComparator.isAscending() ^ previous) {
437                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
438                                            }
439                                            else {
440                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
441                                            }
442                                    }
443                                    else {
444                                            if (orderByComparator.isAscending() ^ previous) {
445                                                    query.append(WHERE_GREATER_THAN);
446                                            }
447                                            else {
448                                                    query.append(WHERE_LESSER_THAN);
449                                            }
450                                    }
451                            }
452    
453                            query.append(ORDER_BY_CLAUSE);
454    
455                            String[] orderByFields = orderByComparator.getOrderByFields();
456    
457                            for (int i = 0; i < orderByFields.length; i++) {
458                                    query.append(_ORDER_BY_ENTITY_ALIAS);
459                                    query.append(orderByFields[i]);
460    
461                                    if ((i + 1) < orderByFields.length) {
462                                            if (orderByComparator.isAscending() ^ previous) {
463                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
464                                            }
465                                            else {
466                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
467                                            }
468                                    }
469                                    else {
470                                            if (orderByComparator.isAscending() ^ previous) {
471                                                    query.append(ORDER_BY_ASC);
472                                            }
473                                            else {
474                                                    query.append(ORDER_BY_DESC);
475                                            }
476                                    }
477                            }
478                    }
479                    else {
480                            query.append(WorkflowDefinitionLinkModelImpl.ORDER_BY_JPQL);
481                    }
482    
483                    String sql = query.toString();
484    
485                    Query q = session.createQuery(sql);
486    
487                    q.setFirstResult(0);
488                    q.setMaxResults(2);
489    
490                    QueryPos qPos = QueryPos.getInstance(q);
491    
492                    qPos.add(companyId);
493    
494                    if (orderByComparator != null) {
495                            Object[] values = orderByComparator.getOrderByConditionValues(workflowDefinitionLink);
496    
497                            for (Object value : values) {
498                                    qPos.add(value);
499                            }
500                    }
501    
502                    List<WorkflowDefinitionLink> list = q.list();
503    
504                    if (list.size() == 2) {
505                            return list.get(1);
506                    }
507                    else {
508                            return null;
509                    }
510            }
511    
512            /**
513             * Removes all the workflow definition links where companyId = &#63; from the database.
514             *
515             * @param companyId the company ID
516             */
517            @Override
518            public void removeByCompanyId(long companyId) {
519                    for (WorkflowDefinitionLink workflowDefinitionLink : findByCompanyId(
520                                    companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
521                            remove(workflowDefinitionLink);
522                    }
523            }
524    
525            /**
526             * Returns the number of workflow definition links where companyId = &#63;.
527             *
528             * @param companyId the company ID
529             * @return the number of matching workflow definition links
530             */
531            @Override
532            public int countByCompanyId(long companyId) {
533                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
534    
535                    Object[] finderArgs = new Object[] { companyId };
536    
537                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
538                                    this);
539    
540                    if (count == null) {
541                            StringBundler query = new StringBundler(2);
542    
543                            query.append(_SQL_COUNT_WORKFLOWDEFINITIONLINK_WHERE);
544    
545                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
546    
547                            String sql = query.toString();
548    
549                            Session session = null;
550    
551                            try {
552                                    session = openSession();
553    
554                                    Query q = session.createQuery(sql);
555    
556                                    QueryPos qPos = QueryPos.getInstance(q);
557    
558                                    qPos.add(companyId);
559    
560                                    count = (Long)q.uniqueResult();
561    
562                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
563                            }
564                            catch (Exception e) {
565                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
566    
567                                    throw processException(e);
568                            }
569                            finally {
570                                    closeSession(session);
571                            }
572                    }
573    
574                    return count.intValue();
575            }
576    
577            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "workflowDefinitionLink.companyId = ?";
578            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
579                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
580                            WorkflowDefinitionLinkImpl.class,
581                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_C",
582                            new String[] {
583                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
584                                    
585                            Integer.class.getName(), Integer.class.getName(),
586                                    OrderByComparator.class.getName()
587                            });
588            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
589                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
590                            WorkflowDefinitionLinkImpl.class,
591                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_C",
592                            new String[] {
593                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
594                            },
595                            WorkflowDefinitionLinkModelImpl.GROUPID_COLUMN_BITMASK |
596                            WorkflowDefinitionLinkModelImpl.COMPANYID_COLUMN_BITMASK |
597                            WorkflowDefinitionLinkModelImpl.CLASSNAMEID_COLUMN_BITMASK |
598                            WorkflowDefinitionLinkModelImpl.WORKFLOWDEFINITIONNAME_COLUMN_BITMASK);
599            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_C = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
600                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
601                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_C",
602                            new String[] {
603                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
604                            });
605    
606            /**
607             * Returns all the workflow definition links where groupId = &#63; and companyId = &#63; and classNameId = &#63;.
608             *
609             * @param groupId the group ID
610             * @param companyId the company ID
611             * @param classNameId the class name ID
612             * @return the matching workflow definition links
613             */
614            @Override
615            public List<WorkflowDefinitionLink> findByG_C_C(long groupId,
616                    long companyId, long classNameId) {
617                    return findByG_C_C(groupId, companyId, classNameId, QueryUtil.ALL_POS,
618                            QueryUtil.ALL_POS, null);
619            }
620    
621            /**
622             * Returns a range of all the workflow definition links where groupId = &#63; and companyId = &#63; and classNameId = &#63;.
623             *
624             * <p>
625             * 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 WorkflowDefinitionLinkModelImpl}. 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.
626             * </p>
627             *
628             * @param groupId the group ID
629             * @param companyId the company ID
630             * @param classNameId the class name ID
631             * @param start the lower bound of the range of workflow definition links
632             * @param end the upper bound of the range of workflow definition links (not inclusive)
633             * @return the range of matching workflow definition links
634             */
635            @Override
636            public List<WorkflowDefinitionLink> findByG_C_C(long groupId,
637                    long companyId, long classNameId, int start, int end) {
638                    return findByG_C_C(groupId, companyId, classNameId, start, end, null);
639            }
640    
641            /**
642             * Returns an ordered range of all the workflow definition links where groupId = &#63; and companyId = &#63; and classNameId = &#63;.
643             *
644             * <p>
645             * 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 WorkflowDefinitionLinkModelImpl}. 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.
646             * </p>
647             *
648             * @param groupId the group ID
649             * @param companyId the company ID
650             * @param classNameId the class name ID
651             * @param start the lower bound of the range of workflow definition links
652             * @param end the upper bound of the range of workflow definition links (not inclusive)
653             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
654             * @return the ordered range of matching workflow definition links
655             */
656            @Override
657            public List<WorkflowDefinitionLink> findByG_C_C(long groupId,
658                    long companyId, long classNameId, int start, int end,
659                    OrderByComparator<WorkflowDefinitionLink> orderByComparator) {
660                    boolean pagination = true;
661                    FinderPath finderPath = null;
662                    Object[] finderArgs = null;
663    
664                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
665                                    (orderByComparator == null)) {
666                            pagination = false;
667                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C;
668                            finderArgs = new Object[] { groupId, companyId, classNameId };
669                    }
670                    else {
671                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C;
672                            finderArgs = new Object[] {
673                                            groupId, companyId, classNameId,
674                                            
675                                            start, end, orderByComparator
676                                    };
677                    }
678    
679                    List<WorkflowDefinitionLink> list = (List<WorkflowDefinitionLink>)FinderCacheUtil.getResult(finderPath,
680                                    finderArgs, this);
681    
682                    if ((list != null) && !list.isEmpty()) {
683                            for (WorkflowDefinitionLink workflowDefinitionLink : list) {
684                                    if ((groupId != workflowDefinitionLink.getGroupId()) ||
685                                                    (companyId != workflowDefinitionLink.getCompanyId()) ||
686                                                    (classNameId != workflowDefinitionLink.getClassNameId())) {
687                                            list = null;
688    
689                                            break;
690                                    }
691                            }
692                    }
693    
694                    if (list == null) {
695                            StringBundler query = null;
696    
697                            if (orderByComparator != null) {
698                                    query = new StringBundler(5 +
699                                                    (orderByComparator.getOrderByFields().length * 3));
700                            }
701                            else {
702                                    query = new StringBundler(5);
703                            }
704    
705                            query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE);
706    
707                            query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
708    
709                            query.append(_FINDER_COLUMN_G_C_C_COMPANYID_2);
710    
711                            query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
712    
713                            if (orderByComparator != null) {
714                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
715                                            orderByComparator);
716                            }
717                            else
718                             if (pagination) {
719                                    query.append(WorkflowDefinitionLinkModelImpl.ORDER_BY_JPQL);
720                            }
721    
722                            String sql = query.toString();
723    
724                            Session session = null;
725    
726                            try {
727                                    session = openSession();
728    
729                                    Query q = session.createQuery(sql);
730    
731                                    QueryPos qPos = QueryPos.getInstance(q);
732    
733                                    qPos.add(groupId);
734    
735                                    qPos.add(companyId);
736    
737                                    qPos.add(classNameId);
738    
739                                    if (!pagination) {
740                                            list = (List<WorkflowDefinitionLink>)QueryUtil.list(q,
741                                                            getDialect(), start, end, false);
742    
743                                            Collections.sort(list);
744    
745                                            list = Collections.unmodifiableList(list);
746                                    }
747                                    else {
748                                            list = (List<WorkflowDefinitionLink>)QueryUtil.list(q,
749                                                            getDialect(), start, end);
750                                    }
751    
752                                    cacheResult(list);
753    
754                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
755                            }
756                            catch (Exception e) {
757                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
758    
759                                    throw processException(e);
760                            }
761                            finally {
762                                    closeSession(session);
763                            }
764                    }
765    
766                    return list;
767            }
768    
769            /**
770             * Returns the first workflow definition link in the ordered set where groupId = &#63; and companyId = &#63; and classNameId = &#63;.
771             *
772             * @param groupId the group ID
773             * @param companyId the company ID
774             * @param classNameId the class name ID
775             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
776             * @return the first matching workflow definition link
777             * @throws NoSuchWorkflowDefinitionLinkException if a matching workflow definition link could not be found
778             */
779            @Override
780            public WorkflowDefinitionLink findByG_C_C_First(long groupId,
781                    long companyId, long classNameId,
782                    OrderByComparator<WorkflowDefinitionLink> orderByComparator)
783                    throws NoSuchWorkflowDefinitionLinkException {
784                    WorkflowDefinitionLink workflowDefinitionLink = fetchByG_C_C_First(groupId,
785                                    companyId, classNameId, orderByComparator);
786    
787                    if (workflowDefinitionLink != null) {
788                            return workflowDefinitionLink;
789                    }
790    
791                    StringBundler msg = new StringBundler(8);
792    
793                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
794    
795                    msg.append("groupId=");
796                    msg.append(groupId);
797    
798                    msg.append(", companyId=");
799                    msg.append(companyId);
800    
801                    msg.append(", classNameId=");
802                    msg.append(classNameId);
803    
804                    msg.append(StringPool.CLOSE_CURLY_BRACE);
805    
806                    throw new NoSuchWorkflowDefinitionLinkException(msg.toString());
807            }
808    
809            /**
810             * Returns the first workflow definition link in the ordered set where groupId = &#63; and companyId = &#63; and classNameId = &#63;.
811             *
812             * @param groupId the group ID
813             * @param companyId the company ID
814             * @param classNameId the class name ID
815             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
816             * @return the first matching workflow definition link, or <code>null</code> if a matching workflow definition link could not be found
817             */
818            @Override
819            public WorkflowDefinitionLink fetchByG_C_C_First(long groupId,
820                    long companyId, long classNameId,
821                    OrderByComparator<WorkflowDefinitionLink> orderByComparator) {
822                    List<WorkflowDefinitionLink> list = findByG_C_C(groupId, companyId,
823                                    classNameId, 0, 1, orderByComparator);
824    
825                    if (!list.isEmpty()) {
826                            return list.get(0);
827                    }
828    
829                    return null;
830            }
831    
832            /**
833             * Returns the last workflow definition link in the ordered set where groupId = &#63; and companyId = &#63; and classNameId = &#63;.
834             *
835             * @param groupId the group ID
836             * @param companyId the company ID
837             * @param classNameId the class name ID
838             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
839             * @return the last matching workflow definition link
840             * @throws NoSuchWorkflowDefinitionLinkException if a matching workflow definition link could not be found
841             */
842            @Override
843            public WorkflowDefinitionLink findByG_C_C_Last(long groupId,
844                    long companyId, long classNameId,
845                    OrderByComparator<WorkflowDefinitionLink> orderByComparator)
846                    throws NoSuchWorkflowDefinitionLinkException {
847                    WorkflowDefinitionLink workflowDefinitionLink = fetchByG_C_C_Last(groupId,
848                                    companyId, classNameId, orderByComparator);
849    
850                    if (workflowDefinitionLink != null) {
851                            return workflowDefinitionLink;
852                    }
853    
854                    StringBundler msg = new StringBundler(8);
855    
856                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
857    
858                    msg.append("groupId=");
859                    msg.append(groupId);
860    
861                    msg.append(", companyId=");
862                    msg.append(companyId);
863    
864                    msg.append(", classNameId=");
865                    msg.append(classNameId);
866    
867                    msg.append(StringPool.CLOSE_CURLY_BRACE);
868    
869                    throw new NoSuchWorkflowDefinitionLinkException(msg.toString());
870            }
871    
872            /**
873             * Returns the last workflow definition link in the ordered set where groupId = &#63; and companyId = &#63; and classNameId = &#63;.
874             *
875             * @param groupId the group ID
876             * @param companyId the company ID
877             * @param classNameId the class name ID
878             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
879             * @return the last matching workflow definition link, or <code>null</code> if a matching workflow definition link could not be found
880             */
881            @Override
882            public WorkflowDefinitionLink fetchByG_C_C_Last(long groupId,
883                    long companyId, long classNameId,
884                    OrderByComparator<WorkflowDefinitionLink> orderByComparator) {
885                    int count = countByG_C_C(groupId, companyId, classNameId);
886    
887                    if (count == 0) {
888                            return null;
889                    }
890    
891                    List<WorkflowDefinitionLink> list = findByG_C_C(groupId, companyId,
892                                    classNameId, count - 1, count, orderByComparator);
893    
894                    if (!list.isEmpty()) {
895                            return list.get(0);
896                    }
897    
898                    return null;
899            }
900    
901            /**
902             * Returns the workflow definition links before and after the current workflow definition link in the ordered set where groupId = &#63; and companyId = &#63; and classNameId = &#63;.
903             *
904             * @param workflowDefinitionLinkId the primary key of the current workflow definition link
905             * @param groupId the group ID
906             * @param companyId the company ID
907             * @param classNameId the class name ID
908             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
909             * @return the previous, current, and next workflow definition link
910             * @throws NoSuchWorkflowDefinitionLinkException if a workflow definition link with the primary key could not be found
911             */
912            @Override
913            public WorkflowDefinitionLink[] findByG_C_C_PrevAndNext(
914                    long workflowDefinitionLinkId, long groupId, long companyId,
915                    long classNameId,
916                    OrderByComparator<WorkflowDefinitionLink> orderByComparator)
917                    throws NoSuchWorkflowDefinitionLinkException {
918                    WorkflowDefinitionLink workflowDefinitionLink = findByPrimaryKey(workflowDefinitionLinkId);
919    
920                    Session session = null;
921    
922                    try {
923                            session = openSession();
924    
925                            WorkflowDefinitionLink[] array = new WorkflowDefinitionLinkImpl[3];
926    
927                            array[0] = getByG_C_C_PrevAndNext(session, workflowDefinitionLink,
928                                            groupId, companyId, classNameId, orderByComparator, true);
929    
930                            array[1] = workflowDefinitionLink;
931    
932                            array[2] = getByG_C_C_PrevAndNext(session, workflowDefinitionLink,
933                                            groupId, companyId, classNameId, orderByComparator, false);
934    
935                            return array;
936                    }
937                    catch (Exception e) {
938                            throw processException(e);
939                    }
940                    finally {
941                            closeSession(session);
942                    }
943            }
944    
945            protected WorkflowDefinitionLink getByG_C_C_PrevAndNext(Session session,
946                    WorkflowDefinitionLink workflowDefinitionLink, long groupId,
947                    long companyId, long classNameId,
948                    OrderByComparator<WorkflowDefinitionLink> orderByComparator,
949                    boolean previous) {
950                    StringBundler query = null;
951    
952                    if (orderByComparator != null) {
953                            query = new StringBundler(6 +
954                                            (orderByComparator.getOrderByFields().length * 6));
955                    }
956                    else {
957                            query = new StringBundler(3);
958                    }
959    
960                    query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE);
961    
962                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
963    
964                    query.append(_FINDER_COLUMN_G_C_C_COMPANYID_2);
965    
966                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
967    
968                    if (orderByComparator != null) {
969                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
970    
971                            if (orderByConditionFields.length > 0) {
972                                    query.append(WHERE_AND);
973                            }
974    
975                            for (int i = 0; i < orderByConditionFields.length; i++) {
976                                    query.append(_ORDER_BY_ENTITY_ALIAS);
977                                    query.append(orderByConditionFields[i]);
978    
979                                    if ((i + 1) < orderByConditionFields.length) {
980                                            if (orderByComparator.isAscending() ^ previous) {
981                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
982                                            }
983                                            else {
984                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
985                                            }
986                                    }
987                                    else {
988                                            if (orderByComparator.isAscending() ^ previous) {
989                                                    query.append(WHERE_GREATER_THAN);
990                                            }
991                                            else {
992                                                    query.append(WHERE_LESSER_THAN);
993                                            }
994                                    }
995                            }
996    
997                            query.append(ORDER_BY_CLAUSE);
998    
999                            String[] orderByFields = orderByComparator.getOrderByFields();
1000    
1001                            for (int i = 0; i < orderByFields.length; i++) {
1002                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1003                                    query.append(orderByFields[i]);
1004    
1005                                    if ((i + 1) < orderByFields.length) {
1006                                            if (orderByComparator.isAscending() ^ previous) {
1007                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1008                                            }
1009                                            else {
1010                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1011                                            }
1012                                    }
1013                                    else {
1014                                            if (orderByComparator.isAscending() ^ previous) {
1015                                                    query.append(ORDER_BY_ASC);
1016                                            }
1017                                            else {
1018                                                    query.append(ORDER_BY_DESC);
1019                                            }
1020                                    }
1021                            }
1022                    }
1023                    else {
1024                            query.append(WorkflowDefinitionLinkModelImpl.ORDER_BY_JPQL);
1025                    }
1026    
1027                    String sql = query.toString();
1028    
1029                    Query q = session.createQuery(sql);
1030    
1031                    q.setFirstResult(0);
1032                    q.setMaxResults(2);
1033    
1034                    QueryPos qPos = QueryPos.getInstance(q);
1035    
1036                    qPos.add(groupId);
1037    
1038                    qPos.add(companyId);
1039    
1040                    qPos.add(classNameId);
1041    
1042                    if (orderByComparator != null) {
1043                            Object[] values = orderByComparator.getOrderByConditionValues(workflowDefinitionLink);
1044    
1045                            for (Object value : values) {
1046                                    qPos.add(value);
1047                            }
1048                    }
1049    
1050                    List<WorkflowDefinitionLink> list = q.list();
1051    
1052                    if (list.size() == 2) {
1053                            return list.get(1);
1054                    }
1055                    else {
1056                            return null;
1057                    }
1058            }
1059    
1060            /**
1061             * Removes all the workflow definition links where groupId = &#63; and companyId = &#63; and classNameId = &#63; from the database.
1062             *
1063             * @param groupId the group ID
1064             * @param companyId the company ID
1065             * @param classNameId the class name ID
1066             */
1067            @Override
1068            public void removeByG_C_C(long groupId, long companyId, long classNameId) {
1069                    for (WorkflowDefinitionLink workflowDefinitionLink : findByG_C_C(
1070                                    groupId, companyId, classNameId, QueryUtil.ALL_POS,
1071                                    QueryUtil.ALL_POS, null)) {
1072                            remove(workflowDefinitionLink);
1073                    }
1074            }
1075    
1076            /**
1077             * Returns the number of workflow definition links where groupId = &#63; and companyId = &#63; and classNameId = &#63;.
1078             *
1079             * @param groupId the group ID
1080             * @param companyId the company ID
1081             * @param classNameId the class name ID
1082             * @return the number of matching workflow definition links
1083             */
1084            @Override
1085            public int countByG_C_C(long groupId, long companyId, long classNameId) {
1086                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_C;
1087    
1088                    Object[] finderArgs = new Object[] { groupId, companyId, classNameId };
1089    
1090                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1091                                    this);
1092    
1093                    if (count == null) {
1094                            StringBundler query = new StringBundler(4);
1095    
1096                            query.append(_SQL_COUNT_WORKFLOWDEFINITIONLINK_WHERE);
1097    
1098                            query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
1099    
1100                            query.append(_FINDER_COLUMN_G_C_C_COMPANYID_2);
1101    
1102                            query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
1103    
1104                            String sql = query.toString();
1105    
1106                            Session session = null;
1107    
1108                            try {
1109                                    session = openSession();
1110    
1111                                    Query q = session.createQuery(sql);
1112    
1113                                    QueryPos qPos = QueryPos.getInstance(q);
1114    
1115                                    qPos.add(groupId);
1116    
1117                                    qPos.add(companyId);
1118    
1119                                    qPos.add(classNameId);
1120    
1121                                    count = (Long)q.uniqueResult();
1122    
1123                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1124                            }
1125                            catch (Exception e) {
1126                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1127    
1128                                    throw processException(e);
1129                            }
1130                            finally {
1131                                    closeSession(session);
1132                            }
1133                    }
1134    
1135                    return count.intValue();
1136            }
1137    
1138            private static final String _FINDER_COLUMN_G_C_C_GROUPID_2 = "workflowDefinitionLink.groupId = ? AND ";
1139            private static final String _FINDER_COLUMN_G_C_C_COMPANYID_2 = "workflowDefinitionLink.companyId = ? AND ";
1140            private static final String _FINDER_COLUMN_G_C_C_CLASSNAMEID_2 = "workflowDefinitionLink.classNameId = ?";
1141            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_W_W = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
1142                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
1143                            WorkflowDefinitionLinkImpl.class,
1144                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_W_W",
1145                            new String[] {
1146                                    Long.class.getName(), String.class.getName(),
1147                                    Integer.class.getName(),
1148                                    
1149                            Integer.class.getName(), Integer.class.getName(),
1150                                    OrderByComparator.class.getName()
1151                            });
1152            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_W_W = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
1153                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
1154                            WorkflowDefinitionLinkImpl.class,
1155                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_W_W",
1156                            new String[] {
1157                                    Long.class.getName(), String.class.getName(),
1158                                    Integer.class.getName()
1159                            },
1160                            WorkflowDefinitionLinkModelImpl.COMPANYID_COLUMN_BITMASK |
1161                            WorkflowDefinitionLinkModelImpl.WORKFLOWDEFINITIONNAME_COLUMN_BITMASK |
1162                            WorkflowDefinitionLinkModelImpl.WORKFLOWDEFINITIONVERSION_COLUMN_BITMASK);
1163            public static final FinderPath FINDER_PATH_COUNT_BY_C_W_W = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
1164                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
1165                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_W_W",
1166                            new String[] {
1167                                    Long.class.getName(), String.class.getName(),
1168                                    Integer.class.getName()
1169                            });
1170    
1171            /**
1172             * Returns all the workflow definition links where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63;.
1173             *
1174             * @param companyId the company ID
1175             * @param workflowDefinitionName the workflow definition name
1176             * @param workflowDefinitionVersion the workflow definition version
1177             * @return the matching workflow definition links
1178             */
1179            @Override
1180            public List<WorkflowDefinitionLink> findByC_W_W(long companyId,
1181                    String workflowDefinitionName, int workflowDefinitionVersion) {
1182                    return findByC_W_W(companyId, workflowDefinitionName,
1183                            workflowDefinitionVersion, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1184                            null);
1185            }
1186    
1187            /**
1188             * Returns a range of all the workflow definition links where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63;.
1189             *
1190             * <p>
1191             * 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 WorkflowDefinitionLinkModelImpl}. 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.
1192             * </p>
1193             *
1194             * @param companyId the company ID
1195             * @param workflowDefinitionName the workflow definition name
1196             * @param workflowDefinitionVersion the workflow definition version
1197             * @param start the lower bound of the range of workflow definition links
1198             * @param end the upper bound of the range of workflow definition links (not inclusive)
1199             * @return the range of matching workflow definition links
1200             */
1201            @Override
1202            public List<WorkflowDefinitionLink> findByC_W_W(long companyId,
1203                    String workflowDefinitionName, int workflowDefinitionVersion,
1204                    int start, int end) {
1205                    return findByC_W_W(companyId, workflowDefinitionName,
1206                            workflowDefinitionVersion, start, end, null);
1207            }
1208    
1209            /**
1210             * Returns an ordered range of all the workflow definition links where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63;.
1211             *
1212             * <p>
1213             * 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 WorkflowDefinitionLinkModelImpl}. 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.
1214             * </p>
1215             *
1216             * @param companyId the company ID
1217             * @param workflowDefinitionName the workflow definition name
1218             * @param workflowDefinitionVersion the workflow definition version
1219             * @param start the lower bound of the range of workflow definition links
1220             * @param end the upper bound of the range of workflow definition links (not inclusive)
1221             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1222             * @return the ordered range of matching workflow definition links
1223             */
1224            @Override
1225            public List<WorkflowDefinitionLink> findByC_W_W(long companyId,
1226                    String workflowDefinitionName, int workflowDefinitionVersion,
1227                    int start, int end,
1228                    OrderByComparator<WorkflowDefinitionLink> orderByComparator) {
1229                    boolean pagination = true;
1230                    FinderPath finderPath = null;
1231                    Object[] finderArgs = null;
1232    
1233                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1234                                    (orderByComparator == null)) {
1235                            pagination = false;
1236                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_W_W;
1237                            finderArgs = new Object[] {
1238                                            companyId, workflowDefinitionName, workflowDefinitionVersion
1239                                    };
1240                    }
1241                    else {
1242                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_W_W;
1243                            finderArgs = new Object[] {
1244                                            companyId, workflowDefinitionName, workflowDefinitionVersion,
1245                                            
1246                                            start, end, orderByComparator
1247                                    };
1248                    }
1249    
1250                    List<WorkflowDefinitionLink> list = (List<WorkflowDefinitionLink>)FinderCacheUtil.getResult(finderPath,
1251                                    finderArgs, this);
1252    
1253                    if ((list != null) && !list.isEmpty()) {
1254                            for (WorkflowDefinitionLink workflowDefinitionLink : list) {
1255                                    if ((companyId != workflowDefinitionLink.getCompanyId()) ||
1256                                                    !Validator.equals(workflowDefinitionName,
1257                                                            workflowDefinitionLink.getWorkflowDefinitionName()) ||
1258                                                    (workflowDefinitionVersion != workflowDefinitionLink.getWorkflowDefinitionVersion())) {
1259                                            list = null;
1260    
1261                                            break;
1262                                    }
1263                            }
1264                    }
1265    
1266                    if (list == null) {
1267                            StringBundler query = null;
1268    
1269                            if (orderByComparator != null) {
1270                                    query = new StringBundler(5 +
1271                                                    (orderByComparator.getOrderByFields().length * 3));
1272                            }
1273                            else {
1274                                    query = new StringBundler(5);
1275                            }
1276    
1277                            query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE);
1278    
1279                            query.append(_FINDER_COLUMN_C_W_W_COMPANYID_2);
1280    
1281                            boolean bindWorkflowDefinitionName = false;
1282    
1283                            if (workflowDefinitionName == null) {
1284                                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_1);
1285                            }
1286                            else if (workflowDefinitionName.equals(StringPool.BLANK)) {
1287                                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_3);
1288                            }
1289                            else {
1290                                    bindWorkflowDefinitionName = true;
1291    
1292                                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_2);
1293                            }
1294    
1295                            query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONVERSION_2);
1296    
1297                            if (orderByComparator != null) {
1298                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1299                                            orderByComparator);
1300                            }
1301                            else
1302                             if (pagination) {
1303                                    query.append(WorkflowDefinitionLinkModelImpl.ORDER_BY_JPQL);
1304                            }
1305    
1306                            String sql = query.toString();
1307    
1308                            Session session = null;
1309    
1310                            try {
1311                                    session = openSession();
1312    
1313                                    Query q = session.createQuery(sql);
1314    
1315                                    QueryPos qPos = QueryPos.getInstance(q);
1316    
1317                                    qPos.add(companyId);
1318    
1319                                    if (bindWorkflowDefinitionName) {
1320                                            qPos.add(workflowDefinitionName);
1321                                    }
1322    
1323                                    qPos.add(workflowDefinitionVersion);
1324    
1325                                    if (!pagination) {
1326                                            list = (List<WorkflowDefinitionLink>)QueryUtil.list(q,
1327                                                            getDialect(), start, end, false);
1328    
1329                                            Collections.sort(list);
1330    
1331                                            list = Collections.unmodifiableList(list);
1332                                    }
1333                                    else {
1334                                            list = (List<WorkflowDefinitionLink>)QueryUtil.list(q,
1335                                                            getDialect(), start, end);
1336                                    }
1337    
1338                                    cacheResult(list);
1339    
1340                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1341                            }
1342                            catch (Exception e) {
1343                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1344    
1345                                    throw processException(e);
1346                            }
1347                            finally {
1348                                    closeSession(session);
1349                            }
1350                    }
1351    
1352                    return list;
1353            }
1354    
1355            /**
1356             * Returns the first workflow definition link in the ordered set where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63;.
1357             *
1358             * @param companyId the company ID
1359             * @param workflowDefinitionName the workflow definition name
1360             * @param workflowDefinitionVersion the workflow definition version
1361             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1362             * @return the first matching workflow definition link
1363             * @throws NoSuchWorkflowDefinitionLinkException if a matching workflow definition link could not be found
1364             */
1365            @Override
1366            public WorkflowDefinitionLink findByC_W_W_First(long companyId,
1367                    String workflowDefinitionName, int workflowDefinitionVersion,
1368                    OrderByComparator<WorkflowDefinitionLink> orderByComparator)
1369                    throws NoSuchWorkflowDefinitionLinkException {
1370                    WorkflowDefinitionLink workflowDefinitionLink = fetchByC_W_W_First(companyId,
1371                                    workflowDefinitionName, workflowDefinitionVersion,
1372                                    orderByComparator);
1373    
1374                    if (workflowDefinitionLink != null) {
1375                            return workflowDefinitionLink;
1376                    }
1377    
1378                    StringBundler msg = new StringBundler(8);
1379    
1380                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1381    
1382                    msg.append("companyId=");
1383                    msg.append(companyId);
1384    
1385                    msg.append(", workflowDefinitionName=");
1386                    msg.append(workflowDefinitionName);
1387    
1388                    msg.append(", workflowDefinitionVersion=");
1389                    msg.append(workflowDefinitionVersion);
1390    
1391                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1392    
1393                    throw new NoSuchWorkflowDefinitionLinkException(msg.toString());
1394            }
1395    
1396            /**
1397             * Returns the first workflow definition link in the ordered set where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63;.
1398             *
1399             * @param companyId the company ID
1400             * @param workflowDefinitionName the workflow definition name
1401             * @param workflowDefinitionVersion the workflow definition version
1402             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1403             * @return the first matching workflow definition link, or <code>null</code> if a matching workflow definition link could not be found
1404             */
1405            @Override
1406            public WorkflowDefinitionLink fetchByC_W_W_First(long companyId,
1407                    String workflowDefinitionName, int workflowDefinitionVersion,
1408                    OrderByComparator<WorkflowDefinitionLink> orderByComparator) {
1409                    List<WorkflowDefinitionLink> list = findByC_W_W(companyId,
1410                                    workflowDefinitionName, workflowDefinitionVersion, 0, 1,
1411                                    orderByComparator);
1412    
1413                    if (!list.isEmpty()) {
1414                            return list.get(0);
1415                    }
1416    
1417                    return null;
1418            }
1419    
1420            /**
1421             * Returns the last workflow definition link in the ordered set where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63;.
1422             *
1423             * @param companyId the company ID
1424             * @param workflowDefinitionName the workflow definition name
1425             * @param workflowDefinitionVersion the workflow definition version
1426             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1427             * @return the last matching workflow definition link
1428             * @throws NoSuchWorkflowDefinitionLinkException if a matching workflow definition link could not be found
1429             */
1430            @Override
1431            public WorkflowDefinitionLink findByC_W_W_Last(long companyId,
1432                    String workflowDefinitionName, int workflowDefinitionVersion,
1433                    OrderByComparator<WorkflowDefinitionLink> orderByComparator)
1434                    throws NoSuchWorkflowDefinitionLinkException {
1435                    WorkflowDefinitionLink workflowDefinitionLink = fetchByC_W_W_Last(companyId,
1436                                    workflowDefinitionName, workflowDefinitionVersion,
1437                                    orderByComparator);
1438    
1439                    if (workflowDefinitionLink != null) {
1440                            return workflowDefinitionLink;
1441                    }
1442    
1443                    StringBundler msg = new StringBundler(8);
1444    
1445                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1446    
1447                    msg.append("companyId=");
1448                    msg.append(companyId);
1449    
1450                    msg.append(", workflowDefinitionName=");
1451                    msg.append(workflowDefinitionName);
1452    
1453                    msg.append(", workflowDefinitionVersion=");
1454                    msg.append(workflowDefinitionVersion);
1455    
1456                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1457    
1458                    throw new NoSuchWorkflowDefinitionLinkException(msg.toString());
1459            }
1460    
1461            /**
1462             * Returns the last workflow definition link in the ordered set where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63;.
1463             *
1464             * @param companyId the company ID
1465             * @param workflowDefinitionName the workflow definition name
1466             * @param workflowDefinitionVersion the workflow definition version
1467             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1468             * @return the last matching workflow definition link, or <code>null</code> if a matching workflow definition link could not be found
1469             */
1470            @Override
1471            public WorkflowDefinitionLink fetchByC_W_W_Last(long companyId,
1472                    String workflowDefinitionName, int workflowDefinitionVersion,
1473                    OrderByComparator<WorkflowDefinitionLink> orderByComparator) {
1474                    int count = countByC_W_W(companyId, workflowDefinitionName,
1475                                    workflowDefinitionVersion);
1476    
1477                    if (count == 0) {
1478                            return null;
1479                    }
1480    
1481                    List<WorkflowDefinitionLink> list = findByC_W_W(companyId,
1482                                    workflowDefinitionName, workflowDefinitionVersion, count - 1,
1483                                    count, orderByComparator);
1484    
1485                    if (!list.isEmpty()) {
1486                            return list.get(0);
1487                    }
1488    
1489                    return null;
1490            }
1491    
1492            /**
1493             * Returns the workflow definition links before and after the current workflow definition link in the ordered set where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63;.
1494             *
1495             * @param workflowDefinitionLinkId the primary key of the current workflow definition link
1496             * @param companyId the company ID
1497             * @param workflowDefinitionName the workflow definition name
1498             * @param workflowDefinitionVersion the workflow definition version
1499             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1500             * @return the previous, current, and next workflow definition link
1501             * @throws NoSuchWorkflowDefinitionLinkException if a workflow definition link with the primary key could not be found
1502             */
1503            @Override
1504            public WorkflowDefinitionLink[] findByC_W_W_PrevAndNext(
1505                    long workflowDefinitionLinkId, long companyId,
1506                    String workflowDefinitionName, int workflowDefinitionVersion,
1507                    OrderByComparator<WorkflowDefinitionLink> orderByComparator)
1508                    throws NoSuchWorkflowDefinitionLinkException {
1509                    WorkflowDefinitionLink workflowDefinitionLink = findByPrimaryKey(workflowDefinitionLinkId);
1510    
1511                    Session session = null;
1512    
1513                    try {
1514                            session = openSession();
1515    
1516                            WorkflowDefinitionLink[] array = new WorkflowDefinitionLinkImpl[3];
1517    
1518                            array[0] = getByC_W_W_PrevAndNext(session, workflowDefinitionLink,
1519                                            companyId, workflowDefinitionName,
1520                                            workflowDefinitionVersion, orderByComparator, true);
1521    
1522                            array[1] = workflowDefinitionLink;
1523    
1524                            array[2] = getByC_W_W_PrevAndNext(session, workflowDefinitionLink,
1525                                            companyId, workflowDefinitionName,
1526                                            workflowDefinitionVersion, orderByComparator, false);
1527    
1528                            return array;
1529                    }
1530                    catch (Exception e) {
1531                            throw processException(e);
1532                    }
1533                    finally {
1534                            closeSession(session);
1535                    }
1536            }
1537    
1538            protected WorkflowDefinitionLink getByC_W_W_PrevAndNext(Session session,
1539                    WorkflowDefinitionLink workflowDefinitionLink, long companyId,
1540                    String workflowDefinitionName, int workflowDefinitionVersion,
1541                    OrderByComparator<WorkflowDefinitionLink> orderByComparator,
1542                    boolean previous) {
1543                    StringBundler query = null;
1544    
1545                    if (orderByComparator != null) {
1546                            query = new StringBundler(6 +
1547                                            (orderByComparator.getOrderByFields().length * 6));
1548                    }
1549                    else {
1550                            query = new StringBundler(3);
1551                    }
1552    
1553                    query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE);
1554    
1555                    query.append(_FINDER_COLUMN_C_W_W_COMPANYID_2);
1556    
1557                    boolean bindWorkflowDefinitionName = false;
1558    
1559                    if (workflowDefinitionName == null) {
1560                            query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_1);
1561                    }
1562                    else if (workflowDefinitionName.equals(StringPool.BLANK)) {
1563                            query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_3);
1564                    }
1565                    else {
1566                            bindWorkflowDefinitionName = true;
1567    
1568                            query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_2);
1569                    }
1570    
1571                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONVERSION_2);
1572    
1573                    if (orderByComparator != null) {
1574                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1575    
1576                            if (orderByConditionFields.length > 0) {
1577                                    query.append(WHERE_AND);
1578                            }
1579    
1580                            for (int i = 0; i < orderByConditionFields.length; i++) {
1581                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1582                                    query.append(orderByConditionFields[i]);
1583    
1584                                    if ((i + 1) < orderByConditionFields.length) {
1585                                            if (orderByComparator.isAscending() ^ previous) {
1586                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1587                                            }
1588                                            else {
1589                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1590                                            }
1591                                    }
1592                                    else {
1593                                            if (orderByComparator.isAscending() ^ previous) {
1594                                                    query.append(WHERE_GREATER_THAN);
1595                                            }
1596                                            else {
1597                                                    query.append(WHERE_LESSER_THAN);
1598                                            }
1599                                    }
1600                            }
1601    
1602                            query.append(ORDER_BY_CLAUSE);
1603    
1604                            String[] orderByFields = orderByComparator.getOrderByFields();
1605    
1606                            for (int i = 0; i < orderByFields.length; i++) {
1607                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1608                                    query.append(orderByFields[i]);
1609    
1610                                    if ((i + 1) < orderByFields.length) {
1611                                            if (orderByComparator.isAscending() ^ previous) {
1612                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1613                                            }
1614                                            else {
1615                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1616                                            }
1617                                    }
1618                                    else {
1619                                            if (orderByComparator.isAscending() ^ previous) {
1620                                                    query.append(ORDER_BY_ASC);
1621                                            }
1622                                            else {
1623                                                    query.append(ORDER_BY_DESC);
1624                                            }
1625                                    }
1626                            }
1627                    }
1628                    else {
1629                            query.append(WorkflowDefinitionLinkModelImpl.ORDER_BY_JPQL);
1630                    }
1631    
1632                    String sql = query.toString();
1633    
1634                    Query q = session.createQuery(sql);
1635    
1636                    q.setFirstResult(0);
1637                    q.setMaxResults(2);
1638    
1639                    QueryPos qPos = QueryPos.getInstance(q);
1640    
1641                    qPos.add(companyId);
1642    
1643                    if (bindWorkflowDefinitionName) {
1644                            qPos.add(workflowDefinitionName);
1645                    }
1646    
1647                    qPos.add(workflowDefinitionVersion);
1648    
1649                    if (orderByComparator != null) {
1650                            Object[] values = orderByComparator.getOrderByConditionValues(workflowDefinitionLink);
1651    
1652                            for (Object value : values) {
1653                                    qPos.add(value);
1654                            }
1655                    }
1656    
1657                    List<WorkflowDefinitionLink> list = q.list();
1658    
1659                    if (list.size() == 2) {
1660                            return list.get(1);
1661                    }
1662                    else {
1663                            return null;
1664                    }
1665            }
1666    
1667            /**
1668             * Removes all the workflow definition links where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63; from the database.
1669             *
1670             * @param companyId the company ID
1671             * @param workflowDefinitionName the workflow definition name
1672             * @param workflowDefinitionVersion the workflow definition version
1673             */
1674            @Override
1675            public void removeByC_W_W(long companyId, String workflowDefinitionName,
1676                    int workflowDefinitionVersion) {
1677                    for (WorkflowDefinitionLink workflowDefinitionLink : findByC_W_W(
1678                                    companyId, workflowDefinitionName, workflowDefinitionVersion,
1679                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1680                            remove(workflowDefinitionLink);
1681                    }
1682            }
1683    
1684            /**
1685             * Returns the number of workflow definition links where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63;.
1686             *
1687             * @param companyId the company ID
1688             * @param workflowDefinitionName the workflow definition name
1689             * @param workflowDefinitionVersion the workflow definition version
1690             * @return the number of matching workflow definition links
1691             */
1692            @Override
1693            public int countByC_W_W(long companyId, String workflowDefinitionName,
1694                    int workflowDefinitionVersion) {
1695                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_W_W;
1696    
1697                    Object[] finderArgs = new Object[] {
1698                                    companyId, workflowDefinitionName, workflowDefinitionVersion
1699                            };
1700    
1701                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1702                                    this);
1703    
1704                    if (count == null) {
1705                            StringBundler query = new StringBundler(4);
1706    
1707                            query.append(_SQL_COUNT_WORKFLOWDEFINITIONLINK_WHERE);
1708    
1709                            query.append(_FINDER_COLUMN_C_W_W_COMPANYID_2);
1710    
1711                            boolean bindWorkflowDefinitionName = false;
1712    
1713                            if (workflowDefinitionName == null) {
1714                                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_1);
1715                            }
1716                            else if (workflowDefinitionName.equals(StringPool.BLANK)) {
1717                                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_3);
1718                            }
1719                            else {
1720                                    bindWorkflowDefinitionName = true;
1721    
1722                                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_2);
1723                            }
1724    
1725                            query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONVERSION_2);
1726    
1727                            String sql = query.toString();
1728    
1729                            Session session = null;
1730    
1731                            try {
1732                                    session = openSession();
1733    
1734                                    Query q = session.createQuery(sql);
1735    
1736                                    QueryPos qPos = QueryPos.getInstance(q);
1737    
1738                                    qPos.add(companyId);
1739    
1740                                    if (bindWorkflowDefinitionName) {
1741                                            qPos.add(workflowDefinitionName);
1742                                    }
1743    
1744                                    qPos.add(workflowDefinitionVersion);
1745    
1746                                    count = (Long)q.uniqueResult();
1747    
1748                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1749                            }
1750                            catch (Exception e) {
1751                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1752    
1753                                    throw processException(e);
1754                            }
1755                            finally {
1756                                    closeSession(session);
1757                            }
1758                    }
1759    
1760                    return count.intValue();
1761            }
1762    
1763            private static final String _FINDER_COLUMN_C_W_W_COMPANYID_2 = "workflowDefinitionLink.companyId = ? AND ";
1764            private static final String _FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_1 = "workflowDefinitionLink.workflowDefinitionName IS NULL AND ";
1765            private static final String _FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_2 = "workflowDefinitionLink.workflowDefinitionName = ? AND ";
1766            private static final String _FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_3 = "(workflowDefinitionLink.workflowDefinitionName IS NULL OR workflowDefinitionLink.workflowDefinitionName = '') AND ";
1767            private static final String _FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONVERSION_2 =
1768                    "workflowDefinitionLink.workflowDefinitionVersion = ?";
1769            public static final FinderPath FINDER_PATH_FETCH_BY_G_C_C_C_T = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
1770                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
1771                            WorkflowDefinitionLinkImpl.class, FINDER_CLASS_NAME_ENTITY,
1772                            "fetchByG_C_C_C_T",
1773                            new String[] {
1774                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
1775                                    Long.class.getName(), Long.class.getName()
1776                            },
1777                            WorkflowDefinitionLinkModelImpl.GROUPID_COLUMN_BITMASK |
1778                            WorkflowDefinitionLinkModelImpl.COMPANYID_COLUMN_BITMASK |
1779                            WorkflowDefinitionLinkModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1780                            WorkflowDefinitionLinkModelImpl.CLASSPK_COLUMN_BITMASK |
1781                            WorkflowDefinitionLinkModelImpl.TYPEPK_COLUMN_BITMASK);
1782            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_C_C_T = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
1783                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
1784                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_C_C_T",
1785                            new String[] {
1786                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
1787                                    Long.class.getName(), Long.class.getName()
1788                            });
1789    
1790            /**
1791             * Returns the workflow definition link where groupId = &#63; and companyId = &#63; and classNameId = &#63; and classPK = &#63; and typePK = &#63; or throws a {@link NoSuchWorkflowDefinitionLinkException} if it could not be found.
1792             *
1793             * @param groupId the group ID
1794             * @param companyId the company ID
1795             * @param classNameId the class name ID
1796             * @param classPK the class p k
1797             * @param typePK the type p k
1798             * @return the matching workflow definition link
1799             * @throws NoSuchWorkflowDefinitionLinkException if a matching workflow definition link could not be found
1800             */
1801            @Override
1802            public WorkflowDefinitionLink findByG_C_C_C_T(long groupId, long companyId,
1803                    long classNameId, long classPK, long typePK)
1804                    throws NoSuchWorkflowDefinitionLinkException {
1805                    WorkflowDefinitionLink workflowDefinitionLink = fetchByG_C_C_C_T(groupId,
1806                                    companyId, classNameId, classPK, typePK);
1807    
1808                    if (workflowDefinitionLink == null) {
1809                            StringBundler msg = new StringBundler(12);
1810    
1811                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1812    
1813                            msg.append("groupId=");
1814                            msg.append(groupId);
1815    
1816                            msg.append(", companyId=");
1817                            msg.append(companyId);
1818    
1819                            msg.append(", classNameId=");
1820                            msg.append(classNameId);
1821    
1822                            msg.append(", classPK=");
1823                            msg.append(classPK);
1824    
1825                            msg.append(", typePK=");
1826                            msg.append(typePK);
1827    
1828                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1829    
1830                            if (_log.isWarnEnabled()) {
1831                                    _log.warn(msg.toString());
1832                            }
1833    
1834                            throw new NoSuchWorkflowDefinitionLinkException(msg.toString());
1835                    }
1836    
1837                    return workflowDefinitionLink;
1838            }
1839    
1840            /**
1841             * Returns the workflow definition link where groupId = &#63; and companyId = &#63; and classNameId = &#63; and classPK = &#63; and typePK = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1842             *
1843             * @param groupId the group ID
1844             * @param companyId the company ID
1845             * @param classNameId the class name ID
1846             * @param classPK the class p k
1847             * @param typePK the type p k
1848             * @return the matching workflow definition link, or <code>null</code> if a matching workflow definition link could not be found
1849             */
1850            @Override
1851            public WorkflowDefinitionLink fetchByG_C_C_C_T(long groupId,
1852                    long companyId, long classNameId, long classPK, long typePK) {
1853                    return fetchByG_C_C_C_T(groupId, companyId, classNameId, classPK,
1854                            typePK, true);
1855            }
1856    
1857            /**
1858             * Returns the workflow definition link where groupId = &#63; and companyId = &#63; and classNameId = &#63; and classPK = &#63; and typePK = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1859             *
1860             * @param groupId the group ID
1861             * @param companyId the company ID
1862             * @param classNameId the class name ID
1863             * @param classPK the class p k
1864             * @param typePK the type p k
1865             * @param retrieveFromCache whether to use the finder cache
1866             * @return the matching workflow definition link, or <code>null</code> if a matching workflow definition link could not be found
1867             */
1868            @Override
1869            public WorkflowDefinitionLink fetchByG_C_C_C_T(long groupId,
1870                    long companyId, long classNameId, long classPK, long typePK,
1871                    boolean retrieveFromCache) {
1872                    Object[] finderArgs = new Object[] {
1873                                    groupId, companyId, classNameId, classPK, typePK
1874                            };
1875    
1876                    Object result = null;
1877    
1878                    if (retrieveFromCache) {
1879                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_C_C_C_T,
1880                                            finderArgs, this);
1881                    }
1882    
1883                    if (result instanceof WorkflowDefinitionLink) {
1884                            WorkflowDefinitionLink workflowDefinitionLink = (WorkflowDefinitionLink)result;
1885    
1886                            if ((groupId != workflowDefinitionLink.getGroupId()) ||
1887                                            (companyId != workflowDefinitionLink.getCompanyId()) ||
1888                                            (classNameId != workflowDefinitionLink.getClassNameId()) ||
1889                                            (classPK != workflowDefinitionLink.getClassPK()) ||
1890                                            (typePK != workflowDefinitionLink.getTypePK())) {
1891                                    result = null;
1892                            }
1893                    }
1894    
1895                    if (result == null) {
1896                            StringBundler query = new StringBundler(7);
1897    
1898                            query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE);
1899    
1900                            query.append(_FINDER_COLUMN_G_C_C_C_T_GROUPID_2);
1901    
1902                            query.append(_FINDER_COLUMN_G_C_C_C_T_COMPANYID_2);
1903    
1904                            query.append(_FINDER_COLUMN_G_C_C_C_T_CLASSNAMEID_2);
1905    
1906                            query.append(_FINDER_COLUMN_G_C_C_C_T_CLASSPK_2);
1907    
1908                            query.append(_FINDER_COLUMN_G_C_C_C_T_TYPEPK_2);
1909    
1910                            String sql = query.toString();
1911    
1912                            Session session = null;
1913    
1914                            try {
1915                                    session = openSession();
1916    
1917                                    Query q = session.createQuery(sql);
1918    
1919                                    QueryPos qPos = QueryPos.getInstance(q);
1920    
1921                                    qPos.add(groupId);
1922    
1923                                    qPos.add(companyId);
1924    
1925                                    qPos.add(classNameId);
1926    
1927                                    qPos.add(classPK);
1928    
1929                                    qPos.add(typePK);
1930    
1931                                    List<WorkflowDefinitionLink> list = q.list();
1932    
1933                                    if (list.isEmpty()) {
1934                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C_C_T,
1935                                                    finderArgs, list);
1936                                    }
1937                                    else {
1938                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
1939                                                    _log.warn(
1940                                                            "WorkflowDefinitionLinkPersistenceImpl.fetchByG_C_C_C_T(long, long, long, long, long, boolean) with parameters (" +
1941                                                            StringUtil.merge(finderArgs) +
1942                                                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
1943                                            }
1944    
1945                                            WorkflowDefinitionLink workflowDefinitionLink = list.get(0);
1946    
1947                                            result = workflowDefinitionLink;
1948    
1949                                            cacheResult(workflowDefinitionLink);
1950    
1951                                            if ((workflowDefinitionLink.getGroupId() != groupId) ||
1952                                                            (workflowDefinitionLink.getCompanyId() != companyId) ||
1953                                                            (workflowDefinitionLink.getClassNameId() != classNameId) ||
1954                                                            (workflowDefinitionLink.getClassPK() != classPK) ||
1955                                                            (workflowDefinitionLink.getTypePK() != typePK)) {
1956                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C_C_T,
1957                                                            finderArgs, workflowDefinitionLink);
1958                                            }
1959                                    }
1960                            }
1961                            catch (Exception e) {
1962                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_C_C_T,
1963                                            finderArgs);
1964    
1965                                    throw processException(e);
1966                            }
1967                            finally {
1968                                    closeSession(session);
1969                            }
1970                    }
1971    
1972                    if (result instanceof List<?>) {
1973                            return null;
1974                    }
1975                    else {
1976                            return (WorkflowDefinitionLink)result;
1977                    }
1978            }
1979    
1980            /**
1981             * Removes the workflow definition link where groupId = &#63; and companyId = &#63; and classNameId = &#63; and classPK = &#63; and typePK = &#63; from the database.
1982             *
1983             * @param groupId the group ID
1984             * @param companyId the company ID
1985             * @param classNameId the class name ID
1986             * @param classPK the class p k
1987             * @param typePK the type p k
1988             * @return the workflow definition link that was removed
1989             */
1990            @Override
1991            public WorkflowDefinitionLink removeByG_C_C_C_T(long groupId,
1992                    long companyId, long classNameId, long classPK, long typePK)
1993                    throws NoSuchWorkflowDefinitionLinkException {
1994                    WorkflowDefinitionLink workflowDefinitionLink = findByG_C_C_C_T(groupId,
1995                                    companyId, classNameId, classPK, typePK);
1996    
1997                    return remove(workflowDefinitionLink);
1998            }
1999    
2000            /**
2001             * Returns the number of workflow definition links where groupId = &#63; and companyId = &#63; and classNameId = &#63; and classPK = &#63; and typePK = &#63;.
2002             *
2003             * @param groupId the group ID
2004             * @param companyId the company ID
2005             * @param classNameId the class name ID
2006             * @param classPK the class p k
2007             * @param typePK the type p k
2008             * @return the number of matching workflow definition links
2009             */
2010            @Override
2011            public int countByG_C_C_C_T(long groupId, long companyId, long classNameId,
2012                    long classPK, long typePK) {
2013                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_C_C_T;
2014    
2015                    Object[] finderArgs = new Object[] {
2016                                    groupId, companyId, classNameId, classPK, typePK
2017                            };
2018    
2019                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2020                                    this);
2021    
2022                    if (count == null) {
2023                            StringBundler query = new StringBundler(6);
2024    
2025                            query.append(_SQL_COUNT_WORKFLOWDEFINITIONLINK_WHERE);
2026    
2027                            query.append(_FINDER_COLUMN_G_C_C_C_T_GROUPID_2);
2028    
2029                            query.append(_FINDER_COLUMN_G_C_C_C_T_COMPANYID_2);
2030    
2031                            query.append(_FINDER_COLUMN_G_C_C_C_T_CLASSNAMEID_2);
2032    
2033                            query.append(_FINDER_COLUMN_G_C_C_C_T_CLASSPK_2);
2034    
2035                            query.append(_FINDER_COLUMN_G_C_C_C_T_TYPEPK_2);
2036    
2037                            String sql = query.toString();
2038    
2039                            Session session = null;
2040    
2041                            try {
2042                                    session = openSession();
2043    
2044                                    Query q = session.createQuery(sql);
2045    
2046                                    QueryPos qPos = QueryPos.getInstance(q);
2047    
2048                                    qPos.add(groupId);
2049    
2050                                    qPos.add(companyId);
2051    
2052                                    qPos.add(classNameId);
2053    
2054                                    qPos.add(classPK);
2055    
2056                                    qPos.add(typePK);
2057    
2058                                    count = (Long)q.uniqueResult();
2059    
2060                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2061                            }
2062                            catch (Exception e) {
2063                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2064    
2065                                    throw processException(e);
2066                            }
2067                            finally {
2068                                    closeSession(session);
2069                            }
2070                    }
2071    
2072                    return count.intValue();
2073            }
2074    
2075            private static final String _FINDER_COLUMN_G_C_C_C_T_GROUPID_2 = "workflowDefinitionLink.groupId = ? AND ";
2076            private static final String _FINDER_COLUMN_G_C_C_C_T_COMPANYID_2 = "workflowDefinitionLink.companyId = ? AND ";
2077            private static final String _FINDER_COLUMN_G_C_C_C_T_CLASSNAMEID_2 = "workflowDefinitionLink.classNameId = ? AND ";
2078            private static final String _FINDER_COLUMN_G_C_C_C_T_CLASSPK_2 = "workflowDefinitionLink.classPK = ? AND ";
2079            private static final String _FINDER_COLUMN_G_C_C_C_T_TYPEPK_2 = "workflowDefinitionLink.typePK = ?";
2080    
2081            public WorkflowDefinitionLinkPersistenceImpl() {
2082                    setModelClass(WorkflowDefinitionLink.class);
2083            }
2084    
2085            /**
2086             * Caches the workflow definition link in the entity cache if it is enabled.
2087             *
2088             * @param workflowDefinitionLink the workflow definition link
2089             */
2090            @Override
2091            public void cacheResult(WorkflowDefinitionLink workflowDefinitionLink) {
2092                    EntityCacheUtil.putResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
2093                            WorkflowDefinitionLinkImpl.class,
2094                            workflowDefinitionLink.getPrimaryKey(), workflowDefinitionLink);
2095    
2096                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C_C_T,
2097                            new Object[] {
2098                                    workflowDefinitionLink.getGroupId(),
2099                                    workflowDefinitionLink.getCompanyId(),
2100                                    workflowDefinitionLink.getClassNameId(),
2101                                    workflowDefinitionLink.getClassPK(),
2102                                    workflowDefinitionLink.getTypePK()
2103                            }, workflowDefinitionLink);
2104    
2105                    workflowDefinitionLink.resetOriginalValues();
2106            }
2107    
2108            /**
2109             * Caches the workflow definition links in the entity cache if it is enabled.
2110             *
2111             * @param workflowDefinitionLinks the workflow definition links
2112             */
2113            @Override
2114            public void cacheResult(
2115                    List<WorkflowDefinitionLink> workflowDefinitionLinks) {
2116                    for (WorkflowDefinitionLink workflowDefinitionLink : workflowDefinitionLinks) {
2117                            if (EntityCacheUtil.getResult(
2118                                                    WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
2119                                                    WorkflowDefinitionLinkImpl.class,
2120                                                    workflowDefinitionLink.getPrimaryKey()) == null) {
2121                                    cacheResult(workflowDefinitionLink);
2122                            }
2123                            else {
2124                                    workflowDefinitionLink.resetOriginalValues();
2125                            }
2126                    }
2127            }
2128    
2129            /**
2130             * Clears the cache for all workflow definition links.
2131             *
2132             * <p>
2133             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2134             * </p>
2135             */
2136            @Override
2137            public void clearCache() {
2138                    EntityCacheUtil.clearCache(WorkflowDefinitionLinkImpl.class);
2139    
2140                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2141                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2142                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2143            }
2144    
2145            /**
2146             * Clears the cache for the workflow definition link.
2147             *
2148             * <p>
2149             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2150             * </p>
2151             */
2152            @Override
2153            public void clearCache(WorkflowDefinitionLink workflowDefinitionLink) {
2154                    EntityCacheUtil.removeResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
2155                            WorkflowDefinitionLinkImpl.class,
2156                            workflowDefinitionLink.getPrimaryKey());
2157    
2158                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2159                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2160    
2161                    clearUniqueFindersCache(workflowDefinitionLink);
2162            }
2163    
2164            @Override
2165            public void clearCache(List<WorkflowDefinitionLink> workflowDefinitionLinks) {
2166                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2167                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2168    
2169                    for (WorkflowDefinitionLink workflowDefinitionLink : workflowDefinitionLinks) {
2170                            EntityCacheUtil.removeResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
2171                                    WorkflowDefinitionLinkImpl.class,
2172                                    workflowDefinitionLink.getPrimaryKey());
2173    
2174                            clearUniqueFindersCache(workflowDefinitionLink);
2175                    }
2176            }
2177    
2178            protected void cacheUniqueFindersCache(
2179                    WorkflowDefinitionLink workflowDefinitionLink) {
2180                    if (workflowDefinitionLink.isNew()) {
2181                            Object[] args = new Object[] {
2182                                            workflowDefinitionLink.getGroupId(),
2183                                            workflowDefinitionLink.getCompanyId(),
2184                                            workflowDefinitionLink.getClassNameId(),
2185                                            workflowDefinitionLink.getClassPK(),
2186                                            workflowDefinitionLink.getTypePK()
2187                                    };
2188    
2189                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_C_C_T, args,
2190                                    Long.valueOf(1));
2191                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C_C_T, args,
2192                                    workflowDefinitionLink);
2193                    }
2194                    else {
2195                            WorkflowDefinitionLinkModelImpl workflowDefinitionLinkModelImpl = (WorkflowDefinitionLinkModelImpl)workflowDefinitionLink;
2196    
2197                            if ((workflowDefinitionLinkModelImpl.getColumnBitmask() &
2198                                            FINDER_PATH_FETCH_BY_G_C_C_C_T.getColumnBitmask()) != 0) {
2199                                    Object[] args = new Object[] {
2200                                                    workflowDefinitionLink.getGroupId(),
2201                                                    workflowDefinitionLink.getCompanyId(),
2202                                                    workflowDefinitionLink.getClassNameId(),
2203                                                    workflowDefinitionLink.getClassPK(),
2204                                                    workflowDefinitionLink.getTypePK()
2205                                            };
2206    
2207                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_C_C_T, args,
2208                                            Long.valueOf(1));
2209                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C_C_T, args,
2210                                            workflowDefinitionLink);
2211                            }
2212                    }
2213            }
2214    
2215            protected void clearUniqueFindersCache(
2216                    WorkflowDefinitionLink workflowDefinitionLink) {
2217                    WorkflowDefinitionLinkModelImpl workflowDefinitionLinkModelImpl = (WorkflowDefinitionLinkModelImpl)workflowDefinitionLink;
2218    
2219                    Object[] args = new Object[] {
2220                                    workflowDefinitionLink.getGroupId(),
2221                                    workflowDefinitionLink.getCompanyId(),
2222                                    workflowDefinitionLink.getClassNameId(),
2223                                    workflowDefinitionLink.getClassPK(),
2224                                    workflowDefinitionLink.getTypePK()
2225                            };
2226    
2227                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C_C_T, args);
2228                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_C_C_T, args);
2229    
2230                    if ((workflowDefinitionLinkModelImpl.getColumnBitmask() &
2231                                    FINDER_PATH_FETCH_BY_G_C_C_C_T.getColumnBitmask()) != 0) {
2232                            args = new Object[] {
2233                                            workflowDefinitionLinkModelImpl.getOriginalGroupId(),
2234                                            workflowDefinitionLinkModelImpl.getOriginalCompanyId(),
2235                                            workflowDefinitionLinkModelImpl.getOriginalClassNameId(),
2236                                            workflowDefinitionLinkModelImpl.getOriginalClassPK(),
2237                                            workflowDefinitionLinkModelImpl.getOriginalTypePK()
2238                                    };
2239    
2240                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C_C_T, args);
2241                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_C_C_T, args);
2242                    }
2243            }
2244    
2245            /**
2246             * Creates a new workflow definition link with the primary key. Does not add the workflow definition link to the database.
2247             *
2248             * @param workflowDefinitionLinkId the primary key for the new workflow definition link
2249             * @return the new workflow definition link
2250             */
2251            @Override
2252            public WorkflowDefinitionLink create(long workflowDefinitionLinkId) {
2253                    WorkflowDefinitionLink workflowDefinitionLink = new WorkflowDefinitionLinkImpl();
2254    
2255                    workflowDefinitionLink.setNew(true);
2256                    workflowDefinitionLink.setPrimaryKey(workflowDefinitionLinkId);
2257    
2258                    return workflowDefinitionLink;
2259            }
2260    
2261            /**
2262             * Removes the workflow definition link with the primary key from the database. Also notifies the appropriate model listeners.
2263             *
2264             * @param workflowDefinitionLinkId the primary key of the workflow definition link
2265             * @return the workflow definition link that was removed
2266             * @throws NoSuchWorkflowDefinitionLinkException if a workflow definition link with the primary key could not be found
2267             */
2268            @Override
2269            public WorkflowDefinitionLink remove(long workflowDefinitionLinkId)
2270                    throws NoSuchWorkflowDefinitionLinkException {
2271                    return remove((Serializable)workflowDefinitionLinkId);
2272            }
2273    
2274            /**
2275             * Removes the workflow definition link with the primary key from the database. Also notifies the appropriate model listeners.
2276             *
2277             * @param primaryKey the primary key of the workflow definition link
2278             * @return the workflow definition link that was removed
2279             * @throws NoSuchWorkflowDefinitionLinkException if a workflow definition link with the primary key could not be found
2280             */
2281            @Override
2282            public WorkflowDefinitionLink remove(Serializable primaryKey)
2283                    throws NoSuchWorkflowDefinitionLinkException {
2284                    Session session = null;
2285    
2286                    try {
2287                            session = openSession();
2288    
2289                            WorkflowDefinitionLink workflowDefinitionLink = (WorkflowDefinitionLink)session.get(WorkflowDefinitionLinkImpl.class,
2290                                            primaryKey);
2291    
2292                            if (workflowDefinitionLink == null) {
2293                                    if (_log.isWarnEnabled()) {
2294                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2295                                    }
2296    
2297                                    throw new NoSuchWorkflowDefinitionLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2298                                            primaryKey);
2299                            }
2300    
2301                            return remove(workflowDefinitionLink);
2302                    }
2303                    catch (NoSuchWorkflowDefinitionLinkException nsee) {
2304                            throw nsee;
2305                    }
2306                    catch (Exception e) {
2307                            throw processException(e);
2308                    }
2309                    finally {
2310                            closeSession(session);
2311                    }
2312            }
2313    
2314            @Override
2315            protected WorkflowDefinitionLink removeImpl(
2316                    WorkflowDefinitionLink workflowDefinitionLink) {
2317                    workflowDefinitionLink = toUnwrappedModel(workflowDefinitionLink);
2318    
2319                    Session session = null;
2320    
2321                    try {
2322                            session = openSession();
2323    
2324                            if (!session.contains(workflowDefinitionLink)) {
2325                                    workflowDefinitionLink = (WorkflowDefinitionLink)session.get(WorkflowDefinitionLinkImpl.class,
2326                                                    workflowDefinitionLink.getPrimaryKeyObj());
2327                            }
2328    
2329                            if (workflowDefinitionLink != null) {
2330                                    session.delete(workflowDefinitionLink);
2331                            }
2332                    }
2333                    catch (Exception e) {
2334                            throw processException(e);
2335                    }
2336                    finally {
2337                            closeSession(session);
2338                    }
2339    
2340                    if (workflowDefinitionLink != null) {
2341                            clearCache(workflowDefinitionLink);
2342                    }
2343    
2344                    return workflowDefinitionLink;
2345            }
2346    
2347            @Override
2348            public WorkflowDefinitionLink updateImpl(
2349                    WorkflowDefinitionLink workflowDefinitionLink) {
2350                    workflowDefinitionLink = toUnwrappedModel(workflowDefinitionLink);
2351    
2352                    boolean isNew = workflowDefinitionLink.isNew();
2353    
2354                    WorkflowDefinitionLinkModelImpl workflowDefinitionLinkModelImpl = (WorkflowDefinitionLinkModelImpl)workflowDefinitionLink;
2355    
2356                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
2357    
2358                    Date now = new Date();
2359    
2360                    if (isNew && (workflowDefinitionLink.getCreateDate() == null)) {
2361                            if (serviceContext == null) {
2362                                    workflowDefinitionLink.setCreateDate(now);
2363                            }
2364                            else {
2365                                    workflowDefinitionLink.setCreateDate(serviceContext.getCreateDate(
2366                                                    now));
2367                            }
2368                    }
2369    
2370                    if (!workflowDefinitionLinkModelImpl.hasSetModifiedDate()) {
2371                            if (serviceContext == null) {
2372                                    workflowDefinitionLink.setModifiedDate(now);
2373                            }
2374                            else {
2375                                    workflowDefinitionLink.setModifiedDate(serviceContext.getModifiedDate(
2376                                                    now));
2377                            }
2378                    }
2379    
2380                    Session session = null;
2381    
2382                    try {
2383                            session = openSession();
2384    
2385                            if (workflowDefinitionLink.isNew()) {
2386                                    session.save(workflowDefinitionLink);
2387    
2388                                    workflowDefinitionLink.setNew(false);
2389                            }
2390                            else {
2391                                    session.merge(workflowDefinitionLink);
2392                            }
2393                    }
2394                    catch (Exception e) {
2395                            throw processException(e);
2396                    }
2397                    finally {
2398                            closeSession(session);
2399                    }
2400    
2401                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2402    
2403                    if (isNew || !WorkflowDefinitionLinkModelImpl.COLUMN_BITMASK_ENABLED) {
2404                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2405                    }
2406    
2407                    else {
2408                            if ((workflowDefinitionLinkModelImpl.getColumnBitmask() &
2409                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
2410                                    Object[] args = new Object[] {
2411                                                    workflowDefinitionLinkModelImpl.getOriginalCompanyId()
2412                                            };
2413    
2414                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
2415                                            args);
2416                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
2417                                            args);
2418    
2419                                    args = new Object[] {
2420                                                    workflowDefinitionLinkModelImpl.getCompanyId()
2421                                            };
2422    
2423                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
2424                                            args);
2425                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
2426                                            args);
2427                            }
2428    
2429                            if ((workflowDefinitionLinkModelImpl.getColumnBitmask() &
2430                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C.getColumnBitmask()) != 0) {
2431                                    Object[] args = new Object[] {
2432                                                    workflowDefinitionLinkModelImpl.getOriginalGroupId(),
2433                                                    workflowDefinitionLinkModelImpl.getOriginalCompanyId(),
2434                                                    workflowDefinitionLinkModelImpl.getOriginalClassNameId()
2435                                            };
2436    
2437                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C, args);
2438                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C,
2439                                            args);
2440    
2441                                    args = new Object[] {
2442                                                    workflowDefinitionLinkModelImpl.getGroupId(),
2443                                                    workflowDefinitionLinkModelImpl.getCompanyId(),
2444                                                    workflowDefinitionLinkModelImpl.getClassNameId()
2445                                            };
2446    
2447                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C, args);
2448                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C,
2449                                            args);
2450                            }
2451    
2452                            if ((workflowDefinitionLinkModelImpl.getColumnBitmask() &
2453                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_W_W.getColumnBitmask()) != 0) {
2454                                    Object[] args = new Object[] {
2455                                                    workflowDefinitionLinkModelImpl.getOriginalCompanyId(),
2456                                                    workflowDefinitionLinkModelImpl.getOriginalWorkflowDefinitionName(),
2457                                                    workflowDefinitionLinkModelImpl.getOriginalWorkflowDefinitionVersion()
2458                                            };
2459    
2460                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_W_W, args);
2461                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_W_W,
2462                                            args);
2463    
2464                                    args = new Object[] {
2465                                                    workflowDefinitionLinkModelImpl.getCompanyId(),
2466                                                    workflowDefinitionLinkModelImpl.getWorkflowDefinitionName(),
2467                                                    workflowDefinitionLinkModelImpl.getWorkflowDefinitionVersion()
2468                                            };
2469    
2470                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_W_W, args);
2471                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_W_W,
2472                                            args);
2473                            }
2474                    }
2475    
2476                    EntityCacheUtil.putResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
2477                            WorkflowDefinitionLinkImpl.class,
2478                            workflowDefinitionLink.getPrimaryKey(), workflowDefinitionLink,
2479                            false);
2480    
2481                    clearUniqueFindersCache(workflowDefinitionLink);
2482                    cacheUniqueFindersCache(workflowDefinitionLink);
2483    
2484                    workflowDefinitionLink.resetOriginalValues();
2485    
2486                    return workflowDefinitionLink;
2487            }
2488    
2489            protected WorkflowDefinitionLink toUnwrappedModel(
2490                    WorkflowDefinitionLink workflowDefinitionLink) {
2491                    if (workflowDefinitionLink instanceof WorkflowDefinitionLinkImpl) {
2492                            return workflowDefinitionLink;
2493                    }
2494    
2495                    WorkflowDefinitionLinkImpl workflowDefinitionLinkImpl = new WorkflowDefinitionLinkImpl();
2496    
2497                    workflowDefinitionLinkImpl.setNew(workflowDefinitionLink.isNew());
2498                    workflowDefinitionLinkImpl.setPrimaryKey(workflowDefinitionLink.getPrimaryKey());
2499    
2500                    workflowDefinitionLinkImpl.setMvccVersion(workflowDefinitionLink.getMvccVersion());
2501                    workflowDefinitionLinkImpl.setWorkflowDefinitionLinkId(workflowDefinitionLink.getWorkflowDefinitionLinkId());
2502                    workflowDefinitionLinkImpl.setGroupId(workflowDefinitionLink.getGroupId());
2503                    workflowDefinitionLinkImpl.setCompanyId(workflowDefinitionLink.getCompanyId());
2504                    workflowDefinitionLinkImpl.setUserId(workflowDefinitionLink.getUserId());
2505                    workflowDefinitionLinkImpl.setUserName(workflowDefinitionLink.getUserName());
2506                    workflowDefinitionLinkImpl.setCreateDate(workflowDefinitionLink.getCreateDate());
2507                    workflowDefinitionLinkImpl.setModifiedDate(workflowDefinitionLink.getModifiedDate());
2508                    workflowDefinitionLinkImpl.setClassNameId(workflowDefinitionLink.getClassNameId());
2509                    workflowDefinitionLinkImpl.setClassPK(workflowDefinitionLink.getClassPK());
2510                    workflowDefinitionLinkImpl.setTypePK(workflowDefinitionLink.getTypePK());
2511                    workflowDefinitionLinkImpl.setWorkflowDefinitionName(workflowDefinitionLink.getWorkflowDefinitionName());
2512                    workflowDefinitionLinkImpl.setWorkflowDefinitionVersion(workflowDefinitionLink.getWorkflowDefinitionVersion());
2513    
2514                    return workflowDefinitionLinkImpl;
2515            }
2516    
2517            /**
2518             * Returns the workflow definition link with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2519             *
2520             * @param primaryKey the primary key of the workflow definition link
2521             * @return the workflow definition link
2522             * @throws NoSuchWorkflowDefinitionLinkException if a workflow definition link with the primary key could not be found
2523             */
2524            @Override
2525            public WorkflowDefinitionLink findByPrimaryKey(Serializable primaryKey)
2526                    throws NoSuchWorkflowDefinitionLinkException {
2527                    WorkflowDefinitionLink workflowDefinitionLink = fetchByPrimaryKey(primaryKey);
2528    
2529                    if (workflowDefinitionLink == null) {
2530                            if (_log.isWarnEnabled()) {
2531                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2532                            }
2533    
2534                            throw new NoSuchWorkflowDefinitionLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2535                                    primaryKey);
2536                    }
2537    
2538                    return workflowDefinitionLink;
2539            }
2540    
2541            /**
2542             * Returns the workflow definition link with the primary key or throws a {@link NoSuchWorkflowDefinitionLinkException} if it could not be found.
2543             *
2544             * @param workflowDefinitionLinkId the primary key of the workflow definition link
2545             * @return the workflow definition link
2546             * @throws NoSuchWorkflowDefinitionLinkException if a workflow definition link with the primary key could not be found
2547             */
2548            @Override
2549            public WorkflowDefinitionLink findByPrimaryKey(
2550                    long workflowDefinitionLinkId)
2551                    throws NoSuchWorkflowDefinitionLinkException {
2552                    return findByPrimaryKey((Serializable)workflowDefinitionLinkId);
2553            }
2554    
2555            /**
2556             * Returns the workflow definition link with the primary key or returns <code>null</code> if it could not be found.
2557             *
2558             * @param primaryKey the primary key of the workflow definition link
2559             * @return the workflow definition link, or <code>null</code> if a workflow definition link with the primary key could not be found
2560             */
2561            @Override
2562            public WorkflowDefinitionLink fetchByPrimaryKey(Serializable primaryKey) {
2563                    WorkflowDefinitionLink workflowDefinitionLink = (WorkflowDefinitionLink)EntityCacheUtil.getResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
2564                                    WorkflowDefinitionLinkImpl.class, primaryKey);
2565    
2566                    if (workflowDefinitionLink == _nullWorkflowDefinitionLink) {
2567                            return null;
2568                    }
2569    
2570                    if (workflowDefinitionLink == null) {
2571                            Session session = null;
2572    
2573                            try {
2574                                    session = openSession();
2575    
2576                                    workflowDefinitionLink = (WorkflowDefinitionLink)session.get(WorkflowDefinitionLinkImpl.class,
2577                                                    primaryKey);
2578    
2579                                    if (workflowDefinitionLink != null) {
2580                                            cacheResult(workflowDefinitionLink);
2581                                    }
2582                                    else {
2583                                            EntityCacheUtil.putResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
2584                                                    WorkflowDefinitionLinkImpl.class, primaryKey,
2585                                                    _nullWorkflowDefinitionLink);
2586                                    }
2587                            }
2588                            catch (Exception e) {
2589                                    EntityCacheUtil.removeResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
2590                                            WorkflowDefinitionLinkImpl.class, primaryKey);
2591    
2592                                    throw processException(e);
2593                            }
2594                            finally {
2595                                    closeSession(session);
2596                            }
2597                    }
2598    
2599                    return workflowDefinitionLink;
2600            }
2601    
2602            /**
2603             * Returns the workflow definition link with the primary key or returns <code>null</code> if it could not be found.
2604             *
2605             * @param workflowDefinitionLinkId the primary key of the workflow definition link
2606             * @return the workflow definition link, or <code>null</code> if a workflow definition link with the primary key could not be found
2607             */
2608            @Override
2609            public WorkflowDefinitionLink fetchByPrimaryKey(
2610                    long workflowDefinitionLinkId) {
2611                    return fetchByPrimaryKey((Serializable)workflowDefinitionLinkId);
2612            }
2613    
2614            @Override
2615            public Map<Serializable, WorkflowDefinitionLink> fetchByPrimaryKeys(
2616                    Set<Serializable> primaryKeys) {
2617                    if (primaryKeys.isEmpty()) {
2618                            return Collections.emptyMap();
2619                    }
2620    
2621                    Map<Serializable, WorkflowDefinitionLink> map = new HashMap<Serializable, WorkflowDefinitionLink>();
2622    
2623                    if (primaryKeys.size() == 1) {
2624                            Iterator<Serializable> iterator = primaryKeys.iterator();
2625    
2626                            Serializable primaryKey = iterator.next();
2627    
2628                            WorkflowDefinitionLink workflowDefinitionLink = fetchByPrimaryKey(primaryKey);
2629    
2630                            if (workflowDefinitionLink != null) {
2631                                    map.put(primaryKey, workflowDefinitionLink);
2632                            }
2633    
2634                            return map;
2635                    }
2636    
2637                    Set<Serializable> uncachedPrimaryKeys = null;
2638    
2639                    for (Serializable primaryKey : primaryKeys) {
2640                            WorkflowDefinitionLink workflowDefinitionLink = (WorkflowDefinitionLink)EntityCacheUtil.getResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
2641                                            WorkflowDefinitionLinkImpl.class, primaryKey);
2642    
2643                            if (workflowDefinitionLink == null) {
2644                                    if (uncachedPrimaryKeys == null) {
2645                                            uncachedPrimaryKeys = new HashSet<Serializable>();
2646                                    }
2647    
2648                                    uncachedPrimaryKeys.add(primaryKey);
2649                            }
2650                            else {
2651                                    map.put(primaryKey, workflowDefinitionLink);
2652                            }
2653                    }
2654    
2655                    if (uncachedPrimaryKeys == null) {
2656                            return map;
2657                    }
2658    
2659                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2660                                    1);
2661    
2662                    query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE_PKS_IN);
2663    
2664                    for (Serializable primaryKey : uncachedPrimaryKeys) {
2665                            query.append(String.valueOf(primaryKey));
2666    
2667                            query.append(StringPool.COMMA);
2668                    }
2669    
2670                    query.setIndex(query.index() - 1);
2671    
2672                    query.append(StringPool.CLOSE_PARENTHESIS);
2673    
2674                    String sql = query.toString();
2675    
2676                    Session session = null;
2677    
2678                    try {
2679                            session = openSession();
2680    
2681                            Query q = session.createQuery(sql);
2682    
2683                            for (WorkflowDefinitionLink workflowDefinitionLink : (List<WorkflowDefinitionLink>)q.list()) {
2684                                    map.put(workflowDefinitionLink.getPrimaryKeyObj(),
2685                                            workflowDefinitionLink);
2686    
2687                                    cacheResult(workflowDefinitionLink);
2688    
2689                                    uncachedPrimaryKeys.remove(workflowDefinitionLink.getPrimaryKeyObj());
2690                            }
2691    
2692                            for (Serializable primaryKey : uncachedPrimaryKeys) {
2693                                    EntityCacheUtil.putResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
2694                                            WorkflowDefinitionLinkImpl.class, primaryKey,
2695                                            _nullWorkflowDefinitionLink);
2696                            }
2697                    }
2698                    catch (Exception e) {
2699                            throw processException(e);
2700                    }
2701                    finally {
2702                            closeSession(session);
2703                    }
2704    
2705                    return map;
2706            }
2707    
2708            /**
2709             * Returns all the workflow definition links.
2710             *
2711             * @return the workflow definition links
2712             */
2713            @Override
2714            public List<WorkflowDefinitionLink> findAll() {
2715                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2716            }
2717    
2718            /**
2719             * Returns a range of all the workflow definition links.
2720             *
2721             * <p>
2722             * 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 WorkflowDefinitionLinkModelImpl}. 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.
2723             * </p>
2724             *
2725             * @param start the lower bound of the range of workflow definition links
2726             * @param end the upper bound of the range of workflow definition links (not inclusive)
2727             * @return the range of workflow definition links
2728             */
2729            @Override
2730            public List<WorkflowDefinitionLink> findAll(int start, int end) {
2731                    return findAll(start, end, null);
2732            }
2733    
2734            /**
2735             * Returns an ordered range of all the workflow definition links.
2736             *
2737             * <p>
2738             * 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 WorkflowDefinitionLinkModelImpl}. 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.
2739             * </p>
2740             *
2741             * @param start the lower bound of the range of workflow definition links
2742             * @param end the upper bound of the range of workflow definition links (not inclusive)
2743             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2744             * @return the ordered range of workflow definition links
2745             */
2746            @Override
2747            public List<WorkflowDefinitionLink> findAll(int start, int end,
2748                    OrderByComparator<WorkflowDefinitionLink> orderByComparator) {
2749                    boolean pagination = true;
2750                    FinderPath finderPath = null;
2751                    Object[] finderArgs = null;
2752    
2753                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2754                                    (orderByComparator == null)) {
2755                            pagination = false;
2756                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2757                            finderArgs = FINDER_ARGS_EMPTY;
2758                    }
2759                    else {
2760                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2761                            finderArgs = new Object[] { start, end, orderByComparator };
2762                    }
2763    
2764                    List<WorkflowDefinitionLink> list = (List<WorkflowDefinitionLink>)FinderCacheUtil.getResult(finderPath,
2765                                    finderArgs, this);
2766    
2767                    if (list == null) {
2768                            StringBundler query = null;
2769                            String sql = null;
2770    
2771                            if (orderByComparator != null) {
2772                                    query = new StringBundler(2 +
2773                                                    (orderByComparator.getOrderByFields().length * 3));
2774    
2775                                    query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK);
2776    
2777                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2778                                            orderByComparator);
2779    
2780                                    sql = query.toString();
2781                            }
2782                            else {
2783                                    sql = _SQL_SELECT_WORKFLOWDEFINITIONLINK;
2784    
2785                                    if (pagination) {
2786                                            sql = sql.concat(WorkflowDefinitionLinkModelImpl.ORDER_BY_JPQL);
2787                                    }
2788                            }
2789    
2790                            Session session = null;
2791    
2792                            try {
2793                                    session = openSession();
2794    
2795                                    Query q = session.createQuery(sql);
2796    
2797                                    if (!pagination) {
2798                                            list = (List<WorkflowDefinitionLink>)QueryUtil.list(q,
2799                                                            getDialect(), start, end, false);
2800    
2801                                            Collections.sort(list);
2802    
2803                                            list = Collections.unmodifiableList(list);
2804                                    }
2805                                    else {
2806                                            list = (List<WorkflowDefinitionLink>)QueryUtil.list(q,
2807                                                            getDialect(), start, end);
2808                                    }
2809    
2810                                    cacheResult(list);
2811    
2812                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2813                            }
2814                            catch (Exception e) {
2815                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2816    
2817                                    throw processException(e);
2818                            }
2819                            finally {
2820                                    closeSession(session);
2821                            }
2822                    }
2823    
2824                    return list;
2825            }
2826    
2827            /**
2828             * Removes all the workflow definition links from the database.
2829             *
2830             */
2831            @Override
2832            public void removeAll() {
2833                    for (WorkflowDefinitionLink workflowDefinitionLink : findAll()) {
2834                            remove(workflowDefinitionLink);
2835                    }
2836            }
2837    
2838            /**
2839             * Returns the number of workflow definition links.
2840             *
2841             * @return the number of workflow definition links
2842             */
2843            @Override
2844            public int countAll() {
2845                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2846                                    FINDER_ARGS_EMPTY, this);
2847    
2848                    if (count == null) {
2849                            Session session = null;
2850    
2851                            try {
2852                                    session = openSession();
2853    
2854                                    Query q = session.createQuery(_SQL_COUNT_WORKFLOWDEFINITIONLINK);
2855    
2856                                    count = (Long)q.uniqueResult();
2857    
2858                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2859                                            FINDER_ARGS_EMPTY, count);
2860                            }
2861                            catch (Exception e) {
2862                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2863                                            FINDER_ARGS_EMPTY);
2864    
2865                                    throw processException(e);
2866                            }
2867                            finally {
2868                                    closeSession(session);
2869                            }
2870                    }
2871    
2872                    return count.intValue();
2873            }
2874    
2875            /**
2876             * Initializes the workflow definition link persistence.
2877             */
2878            public void afterPropertiesSet() {
2879            }
2880    
2881            public void destroy() {
2882                    EntityCacheUtil.removeCache(WorkflowDefinitionLinkImpl.class.getName());
2883                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2884                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2885                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2886            }
2887    
2888            private static final String _SQL_SELECT_WORKFLOWDEFINITIONLINK = "SELECT workflowDefinitionLink FROM WorkflowDefinitionLink workflowDefinitionLink";
2889            private static final String _SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE_PKS_IN = "SELECT workflowDefinitionLink FROM WorkflowDefinitionLink workflowDefinitionLink WHERE workflowDefinitionLinkId IN (";
2890            private static final String _SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE = "SELECT workflowDefinitionLink FROM WorkflowDefinitionLink workflowDefinitionLink WHERE ";
2891            private static final String _SQL_COUNT_WORKFLOWDEFINITIONLINK = "SELECT COUNT(workflowDefinitionLink) FROM WorkflowDefinitionLink workflowDefinitionLink";
2892            private static final String _SQL_COUNT_WORKFLOWDEFINITIONLINK_WHERE = "SELECT COUNT(workflowDefinitionLink) FROM WorkflowDefinitionLink workflowDefinitionLink WHERE ";
2893            private static final String _ORDER_BY_ENTITY_ALIAS = "workflowDefinitionLink.";
2894            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WorkflowDefinitionLink exists with the primary key ";
2895            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WorkflowDefinitionLink exists with the key {";
2896            private static final Log _log = LogFactoryUtil.getLog(WorkflowDefinitionLinkPersistenceImpl.class);
2897            private static final WorkflowDefinitionLink _nullWorkflowDefinitionLink = new WorkflowDefinitionLinkImpl() {
2898                            @Override
2899                            public Object clone() {
2900                                    return this;
2901                            }
2902    
2903                            @Override
2904                            public CacheModel<WorkflowDefinitionLink> toCacheModel() {
2905                                    return _nullWorkflowDefinitionLinkCacheModel;
2906                            }
2907                    };
2908    
2909            private static final CacheModel<WorkflowDefinitionLink> _nullWorkflowDefinitionLinkCacheModel =
2910                    new NullCacheModel();
2911    
2912            private static class NullCacheModel implements CacheModel<WorkflowDefinitionLink>,
2913                    MVCCModel {
2914                    @Override
2915                    public long getMvccVersion() {
2916                            return -1;
2917                    }
2918    
2919                    @Override
2920                    public void setMvccVersion(long mvccVersion) {
2921                    }
2922    
2923                    @Override
2924                    public WorkflowDefinitionLink toEntityModel() {
2925                            return _nullWorkflowDefinitionLink;
2926                    }
2927            }
2928    }