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