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