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