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