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