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