001    /**
002     * Copyright (c) 2000-2010 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;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.NoSuchWorkflowDefinitionLinkException;
019    import com.liferay.portal.kernel.annotation.BeanReference;
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.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.model.ModelListener;
038    import com.liferay.portal.model.WorkflowDefinitionLink;
039    import com.liferay.portal.model.impl.WorkflowDefinitionLinkImpl;
040    import com.liferay.portal.model.impl.WorkflowDefinitionLinkModelImpl;
041    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042    
043    import java.io.Serializable;
044    
045    import java.util.ArrayList;
046    import java.util.Collections;
047    import java.util.List;
048    
049    /**
050     * The persistence for the workflow definition link service.
051     *
052     * <p>
053     * Never modify this class directly. Modify <code>service.xml</code> and rerun ServiceBuilder to regnerate this class.
054     * </p>
055     *
056     * <p>
057     * Caching information and settings can be found in <code>portal.properties</code>
058     * </p>
059     *
060     * @author Brian Wing Shun Chan
061     * @see WorkflowDefinitionLinkPersistence
062     * @see WorkflowDefinitionLinkUtil
063     * @generated
064     */
065    public class WorkflowDefinitionLinkPersistenceImpl extends BasePersistenceImpl<WorkflowDefinitionLink>
066            implements WorkflowDefinitionLinkPersistence {
067            public static final String FINDER_CLASS_NAME_ENTITY = WorkflowDefinitionLinkImpl.class.getName();
068            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
069                    ".List";
070            public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
071                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
072                            FINDER_CLASS_NAME_LIST, "findByCompanyId",
073                            new String[] {
074                                    Long.class.getName(),
075                                    
076                            "java.lang.Integer", "java.lang.Integer",
077                                    "com.liferay.portal.kernel.util.OrderByComparator"
078                            });
079            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
080                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
081                            FINDER_CLASS_NAME_LIST, "countByCompanyId",
082                            new String[] { Long.class.getName() });
083            public static final FinderPath FINDER_PATH_FETCH_BY_G_C_C = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
084                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
085                            FINDER_CLASS_NAME_ENTITY, "fetchByG_C_C",
086                            new String[] {
087                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
088                            });
089            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_C = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
090                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
091                            FINDER_CLASS_NAME_LIST, "countByG_C_C",
092                            new String[] {
093                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
094                            });
095            public static final FinderPath FINDER_PATH_FIND_BY_C_W_W = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
096                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
097                            FINDER_CLASS_NAME_LIST, "findByC_W_W",
098                            new String[] {
099                                    Long.class.getName(), String.class.getName(),
100                                    Integer.class.getName(),
101                                    
102                            "java.lang.Integer", "java.lang.Integer",
103                                    "com.liferay.portal.kernel.util.OrderByComparator"
104                            });
105            public static final FinderPath FINDER_PATH_COUNT_BY_C_W_W = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
106                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
107                            FINDER_CLASS_NAME_LIST, "countByC_W_W",
108                            new String[] {
109                                    Long.class.getName(), String.class.getName(),
110                                    Integer.class.getName()
111                            });
112            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
113                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
114                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
115            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
116                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
117                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
118    
119            /**
120             * Caches the workflow definition link in the entity cache if it is enabled.
121             *
122             * @param workflowDefinitionLink the workflow definition link to cache
123             */
124            public void cacheResult(WorkflowDefinitionLink workflowDefinitionLink) {
125                    EntityCacheUtil.putResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
126                            WorkflowDefinitionLinkImpl.class,
127                            workflowDefinitionLink.getPrimaryKey(), workflowDefinitionLink);
128    
129                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C,
130                            new Object[] {
131                                    new Long(workflowDefinitionLink.getGroupId()),
132                                    new Long(workflowDefinitionLink.getCompanyId()),
133                                    new Long(workflowDefinitionLink.getClassNameId())
134                            }, workflowDefinitionLink);
135            }
136    
137            /**
138             * Caches the workflow definition links in the entity cache if it is enabled.
139             *
140             * @param workflowDefinitionLinks the workflow definition links to cache
141             */
142            public void cacheResult(
143                    List<WorkflowDefinitionLink> workflowDefinitionLinks) {
144                    for (WorkflowDefinitionLink workflowDefinitionLink : workflowDefinitionLinks) {
145                            if (EntityCacheUtil.getResult(
146                                                    WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
147                                                    WorkflowDefinitionLinkImpl.class,
148                                                    workflowDefinitionLink.getPrimaryKey(), this) == null) {
149                                    cacheResult(workflowDefinitionLink);
150                            }
151                    }
152            }
153    
154            /**
155             * Clears the cache for all workflow definition links.
156             *
157             * <p>
158             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
159             * </p>
160             */
161            public void clearCache() {
162                    CacheRegistryUtil.clear(WorkflowDefinitionLinkImpl.class.getName());
163                    EntityCacheUtil.clearCache(WorkflowDefinitionLinkImpl.class.getName());
164                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
165                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
166            }
167    
168            /**
169             * Clears the cache for the workflow definition link.
170             *
171             * <p>
172             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
173             * </p>
174             */
175            public void clearCache(WorkflowDefinitionLink workflowDefinitionLink) {
176                    EntityCacheUtil.removeResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
177                            WorkflowDefinitionLinkImpl.class,
178                            workflowDefinitionLink.getPrimaryKey());
179    
180                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_C,
181                            new Object[] {
182                                    new Long(workflowDefinitionLink.getGroupId()),
183                                    new Long(workflowDefinitionLink.getCompanyId()),
184                                    new Long(workflowDefinitionLink.getClassNameId())
185                            });
186            }
187    
188            /**
189             * Creates a new workflow definition link with the primary key.
190             *
191             * @param workflowDefinitionLinkId the primary key for the new workflow definition link
192             * @return the new workflow definition link
193             */
194            public WorkflowDefinitionLink create(long workflowDefinitionLinkId) {
195                    WorkflowDefinitionLink workflowDefinitionLink = new WorkflowDefinitionLinkImpl();
196    
197                    workflowDefinitionLink.setNew(true);
198                    workflowDefinitionLink.setPrimaryKey(workflowDefinitionLinkId);
199    
200                    return workflowDefinitionLink;
201            }
202    
203            /**
204             * Removes the workflow definition link with the primary key from the database. Also notifies the appropriate model listeners.
205             *
206             * @param primaryKey the primary key of the workflow definition link to remove
207             * @return the workflow definition link that was removed
208             * @throws com.liferay.portal.NoSuchModelException if a workflow definition link with the primary key could not be found
209             * @throws SystemException if a system exception occurred
210             */
211            public WorkflowDefinitionLink remove(Serializable primaryKey)
212                    throws NoSuchModelException, SystemException {
213                    return remove(((Long)primaryKey).longValue());
214            }
215    
216            /**
217             * Removes the workflow definition link with the primary key from the database. Also notifies the appropriate model listeners.
218             *
219             * @param workflowDefinitionLinkId the primary key of the workflow definition link to remove
220             * @return the workflow definition link that was removed
221             * @throws com.liferay.portal.NoSuchWorkflowDefinitionLinkException if a workflow definition link with the primary key could not be found
222             * @throws SystemException if a system exception occurred
223             */
224            public WorkflowDefinitionLink remove(long workflowDefinitionLinkId)
225                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
226                    Session session = null;
227    
228                    try {
229                            session = openSession();
230    
231                            WorkflowDefinitionLink workflowDefinitionLink = (WorkflowDefinitionLink)session.get(WorkflowDefinitionLinkImpl.class,
232                                            new Long(workflowDefinitionLinkId));
233    
234                            if (workflowDefinitionLink == null) {
235                                    if (_log.isWarnEnabled()) {
236                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
237                                                    workflowDefinitionLinkId);
238                                    }
239    
240                                    throw new NoSuchWorkflowDefinitionLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
241                                            workflowDefinitionLinkId);
242                            }
243    
244                            return remove(workflowDefinitionLink);
245                    }
246                    catch (NoSuchWorkflowDefinitionLinkException nsee) {
247                            throw nsee;
248                    }
249                    catch (Exception e) {
250                            throw processException(e);
251                    }
252                    finally {
253                            closeSession(session);
254                    }
255            }
256    
257            protected WorkflowDefinitionLink removeImpl(
258                    WorkflowDefinitionLink workflowDefinitionLink)
259                    throws SystemException {
260                    workflowDefinitionLink = toUnwrappedModel(workflowDefinitionLink);
261    
262                    Session session = null;
263    
264                    try {
265                            session = openSession();
266    
267                            if (workflowDefinitionLink.isCachedModel() ||
268                                            BatchSessionUtil.isEnabled()) {
269                                    Object staleObject = session.get(WorkflowDefinitionLinkImpl.class,
270                                                    workflowDefinitionLink.getPrimaryKeyObj());
271    
272                                    if (staleObject != null) {
273                                            session.evict(staleObject);
274                                    }
275                            }
276    
277                            session.delete(workflowDefinitionLink);
278    
279                            session.flush();
280                    }
281                    catch (Exception e) {
282                            throw processException(e);
283                    }
284                    finally {
285                            closeSession(session);
286                    }
287    
288                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
289    
290                    WorkflowDefinitionLinkModelImpl workflowDefinitionLinkModelImpl = (WorkflowDefinitionLinkModelImpl)workflowDefinitionLink;
291    
292                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_C,
293                            new Object[] {
294                                    new Long(workflowDefinitionLinkModelImpl.getOriginalGroupId()),
295                                    new Long(workflowDefinitionLinkModelImpl.getOriginalCompanyId()),
296                                    new Long(workflowDefinitionLinkModelImpl.getOriginalClassNameId())
297                            });
298    
299                    EntityCacheUtil.removeResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
300                            WorkflowDefinitionLinkImpl.class,
301                            workflowDefinitionLink.getPrimaryKey());
302    
303                    return workflowDefinitionLink;
304            }
305    
306            public WorkflowDefinitionLink updateImpl(
307                    com.liferay.portal.model.WorkflowDefinitionLink workflowDefinitionLink,
308                    boolean merge) throws SystemException {
309                    workflowDefinitionLink = toUnwrappedModel(workflowDefinitionLink);
310    
311                    boolean isNew = workflowDefinitionLink.isNew();
312    
313                    WorkflowDefinitionLinkModelImpl workflowDefinitionLinkModelImpl = (WorkflowDefinitionLinkModelImpl)workflowDefinitionLink;
314    
315                    Session session = null;
316    
317                    try {
318                            session = openSession();
319    
320                            BatchSessionUtil.update(session, workflowDefinitionLink, merge);
321    
322                            workflowDefinitionLink.setNew(false);
323                    }
324                    catch (Exception e) {
325                            throw processException(e);
326                    }
327                    finally {
328                            closeSession(session);
329                    }
330    
331                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
332    
333                    EntityCacheUtil.putResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
334                            WorkflowDefinitionLinkImpl.class,
335                            workflowDefinitionLink.getPrimaryKey(), workflowDefinitionLink);
336    
337                    if (!isNew &&
338                                    ((workflowDefinitionLink.getGroupId() != workflowDefinitionLinkModelImpl.getOriginalGroupId()) ||
339                                    (workflowDefinitionLink.getCompanyId() != workflowDefinitionLinkModelImpl.getOriginalCompanyId()) ||
340                                    (workflowDefinitionLink.getClassNameId() != workflowDefinitionLinkModelImpl.getOriginalClassNameId()))) {
341                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_C,
342                                    new Object[] {
343                                            new Long(workflowDefinitionLinkModelImpl.getOriginalGroupId()),
344                                            new Long(workflowDefinitionLinkModelImpl.getOriginalCompanyId()),
345                                            new Long(workflowDefinitionLinkModelImpl.getOriginalClassNameId())
346                                    });
347                    }
348    
349                    if (isNew ||
350                                    ((workflowDefinitionLink.getGroupId() != workflowDefinitionLinkModelImpl.getOriginalGroupId()) ||
351                                    (workflowDefinitionLink.getCompanyId() != workflowDefinitionLinkModelImpl.getOriginalCompanyId()) ||
352                                    (workflowDefinitionLink.getClassNameId() != workflowDefinitionLinkModelImpl.getOriginalClassNameId()))) {
353                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C,
354                                    new Object[] {
355                                            new Long(workflowDefinitionLink.getGroupId()),
356                                            new Long(workflowDefinitionLink.getCompanyId()),
357                                            new Long(workflowDefinitionLink.getClassNameId())
358                                    }, workflowDefinitionLink);
359                    }
360    
361                    return workflowDefinitionLink;
362            }
363    
364            protected WorkflowDefinitionLink toUnwrappedModel(
365                    WorkflowDefinitionLink workflowDefinitionLink) {
366                    if (workflowDefinitionLink instanceof WorkflowDefinitionLinkImpl) {
367                            return workflowDefinitionLink;
368                    }
369    
370                    WorkflowDefinitionLinkImpl workflowDefinitionLinkImpl = new WorkflowDefinitionLinkImpl();
371    
372                    workflowDefinitionLinkImpl.setNew(workflowDefinitionLink.isNew());
373                    workflowDefinitionLinkImpl.setPrimaryKey(workflowDefinitionLink.getPrimaryKey());
374    
375                    workflowDefinitionLinkImpl.setWorkflowDefinitionLinkId(workflowDefinitionLink.getWorkflowDefinitionLinkId());
376                    workflowDefinitionLinkImpl.setGroupId(workflowDefinitionLink.getGroupId());
377                    workflowDefinitionLinkImpl.setCompanyId(workflowDefinitionLink.getCompanyId());
378                    workflowDefinitionLinkImpl.setUserId(workflowDefinitionLink.getUserId());
379                    workflowDefinitionLinkImpl.setUserName(workflowDefinitionLink.getUserName());
380                    workflowDefinitionLinkImpl.setCreateDate(workflowDefinitionLink.getCreateDate());
381                    workflowDefinitionLinkImpl.setModifiedDate(workflowDefinitionLink.getModifiedDate());
382                    workflowDefinitionLinkImpl.setClassNameId(workflowDefinitionLink.getClassNameId());
383                    workflowDefinitionLinkImpl.setWorkflowDefinitionName(workflowDefinitionLink.getWorkflowDefinitionName());
384                    workflowDefinitionLinkImpl.setWorkflowDefinitionVersion(workflowDefinitionLink.getWorkflowDefinitionVersion());
385    
386                    return workflowDefinitionLinkImpl;
387            }
388    
389            /**
390             * Finds the workflow definition link with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
391             *
392             * @param primaryKey the primary key of the workflow definition link to find
393             * @return the workflow definition link
394             * @throws com.liferay.portal.NoSuchModelException if a workflow definition link with the primary key could not be found
395             * @throws SystemException if a system exception occurred
396             */
397            public WorkflowDefinitionLink findByPrimaryKey(Serializable primaryKey)
398                    throws NoSuchModelException, SystemException {
399                    return findByPrimaryKey(((Long)primaryKey).longValue());
400            }
401    
402            /**
403             * Finds the workflow definition link with the primary key or throws a {@link com.liferay.portal.NoSuchWorkflowDefinitionLinkException} if it could not be found.
404             *
405             * @param workflowDefinitionLinkId the primary key of the workflow definition link to find
406             * @return the workflow definition link
407             * @throws com.liferay.portal.NoSuchWorkflowDefinitionLinkException if a workflow definition link with the primary key could not be found
408             * @throws SystemException if a system exception occurred
409             */
410            public WorkflowDefinitionLink findByPrimaryKey(
411                    long workflowDefinitionLinkId)
412                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
413                    WorkflowDefinitionLink workflowDefinitionLink = fetchByPrimaryKey(workflowDefinitionLinkId);
414    
415                    if (workflowDefinitionLink == null) {
416                            if (_log.isWarnEnabled()) {
417                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
418                                            workflowDefinitionLinkId);
419                            }
420    
421                            throw new NoSuchWorkflowDefinitionLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
422                                    workflowDefinitionLinkId);
423                    }
424    
425                    return workflowDefinitionLink;
426            }
427    
428            /**
429             * Finds the workflow definition link with the primary key or returns <code>null</code> if it could not be found.
430             *
431             * @param primaryKey the primary key of the workflow definition link to find
432             * @return the workflow definition link, or <code>null</code> if a workflow definition link with the primary key could not be found
433             * @throws SystemException if a system exception occurred
434             */
435            public WorkflowDefinitionLink fetchByPrimaryKey(Serializable primaryKey)
436                    throws SystemException {
437                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
438            }
439    
440            /**
441             * Finds the workflow definition link with the primary key or returns <code>null</code> if it could not be found.
442             *
443             * @param workflowDefinitionLinkId the primary key of the workflow definition link to find
444             * @return the workflow definition link, or <code>null</code> if a workflow definition link with the primary key could not be found
445             * @throws SystemException if a system exception occurred
446             */
447            public WorkflowDefinitionLink fetchByPrimaryKey(
448                    long workflowDefinitionLinkId) throws SystemException {
449                    WorkflowDefinitionLink workflowDefinitionLink = (WorkflowDefinitionLink)EntityCacheUtil.getResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
450                                    WorkflowDefinitionLinkImpl.class, workflowDefinitionLinkId, this);
451    
452                    if (workflowDefinitionLink == null) {
453                            Session session = null;
454    
455                            try {
456                                    session = openSession();
457    
458                                    workflowDefinitionLink = (WorkflowDefinitionLink)session.get(WorkflowDefinitionLinkImpl.class,
459                                                    new Long(workflowDefinitionLinkId));
460                            }
461                            catch (Exception e) {
462                                    throw processException(e);
463                            }
464                            finally {
465                                    if (workflowDefinitionLink != null) {
466                                            cacheResult(workflowDefinitionLink);
467                                    }
468    
469                                    closeSession(session);
470                            }
471                    }
472    
473                    return workflowDefinitionLink;
474            }
475    
476            /**
477             * Finds all the workflow definition links where companyId = &#63;.
478             *
479             * @param companyId the company id to search with
480             * @return the matching workflow definition links
481             * @throws SystemException if a system exception occurred
482             */
483            public List<WorkflowDefinitionLink> findByCompanyId(long companyId)
484                    throws SystemException {
485                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
486                            null);
487            }
488    
489            /**
490             * Finds a range of all the workflow definition links where companyId = &#63;.
491             *
492             * <p>
493             * 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.
494             * </p>
495             *
496             * @param companyId the company id to search with
497             * @param start the lower bound of the range of workflow definition links to return
498             * @param end the upper bound of the range of workflow definition links to return (not inclusive)
499             * @return the range of matching workflow definition links
500             * @throws SystemException if a system exception occurred
501             */
502            public List<WorkflowDefinitionLink> findByCompanyId(long companyId,
503                    int start, int end) throws SystemException {
504                    return findByCompanyId(companyId, start, end, null);
505            }
506    
507            /**
508             * Finds an ordered range of all the workflow definition links where companyId = &#63;.
509             *
510             * <p>
511             * 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.
512             * </p>
513             *
514             * @param companyId the company id to search with
515             * @param start the lower bound of the range of workflow definition links to return
516             * @param end the upper bound of the range of workflow definition links to return (not inclusive)
517             * @param orderByComparator the comparator to order the results by
518             * @return the ordered range of matching workflow definition links
519             * @throws SystemException if a system exception occurred
520             */
521            public List<WorkflowDefinitionLink> findByCompanyId(long companyId,
522                    int start, int end, OrderByComparator orderByComparator)
523                    throws SystemException {
524                    Object[] finderArgs = new Object[] {
525                                    companyId,
526                                    
527                                    String.valueOf(start), String.valueOf(end),
528                                    String.valueOf(orderByComparator)
529                            };
530    
531                    List<WorkflowDefinitionLink> list = (List<WorkflowDefinitionLink>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
532                                    finderArgs, this);
533    
534                    if (list == null) {
535                            Session session = null;
536    
537                            try {
538                                    session = openSession();
539    
540                                    StringBundler query = null;
541    
542                                    if (orderByComparator != null) {
543                                            query = new StringBundler(3 +
544                                                            (orderByComparator.getOrderByFields().length * 3));
545                                    }
546                                    else {
547                                            query = new StringBundler(3);
548                                    }
549    
550                                    query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE);
551    
552                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
553    
554                                    if (orderByComparator != null) {
555                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
556                                                    orderByComparator);
557                                    }
558    
559                                    else {
560                                            query.append(WorkflowDefinitionLinkModelImpl.ORDER_BY_JPQL);
561                                    }
562    
563                                    String sql = query.toString();
564    
565                                    Query q = session.createQuery(sql);
566    
567                                    QueryPos qPos = QueryPos.getInstance(q);
568    
569                                    qPos.add(companyId);
570    
571                                    list = (List<WorkflowDefinitionLink>)QueryUtil.list(q,
572                                                    getDialect(), start, end);
573                            }
574                            catch (Exception e) {
575                                    throw processException(e);
576                            }
577                            finally {
578                                    if (list == null) {
579                                            list = new ArrayList<WorkflowDefinitionLink>();
580                                    }
581    
582                                    cacheResult(list);
583    
584                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
585                                            finderArgs, list);
586    
587                                    closeSession(session);
588                            }
589                    }
590    
591                    return list;
592            }
593    
594            /**
595             * Finds the first workflow definition link in the ordered set where companyId = &#63;.
596             *
597             * <p>
598             * 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.
599             * </p>
600             *
601             * @param companyId the company id to search with
602             * @param orderByComparator the comparator to order the set by
603             * @return the first matching workflow definition link
604             * @throws com.liferay.portal.NoSuchWorkflowDefinitionLinkException if a matching workflow definition link could not be found
605             * @throws SystemException if a system exception occurred
606             */
607            public WorkflowDefinitionLink findByCompanyId_First(long companyId,
608                    OrderByComparator orderByComparator)
609                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
610                    List<WorkflowDefinitionLink> list = findByCompanyId(companyId, 0, 1,
611                                    orderByComparator);
612    
613                    if (list.isEmpty()) {
614                            StringBundler msg = new StringBundler(4);
615    
616                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
617    
618                            msg.append("companyId=");
619                            msg.append(companyId);
620    
621                            msg.append(StringPool.CLOSE_CURLY_BRACE);
622    
623                            throw new NoSuchWorkflowDefinitionLinkException(msg.toString());
624                    }
625                    else {
626                            return list.get(0);
627                    }
628            }
629    
630            /**
631             * Finds the last workflow definition link in the ordered set where companyId = &#63;.
632             *
633             * <p>
634             * 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.
635             * </p>
636             *
637             * @param companyId the company id to search with
638             * @param orderByComparator the comparator to order the set by
639             * @return the last matching workflow definition link
640             * @throws com.liferay.portal.NoSuchWorkflowDefinitionLinkException if a matching workflow definition link could not be found
641             * @throws SystemException if a system exception occurred
642             */
643            public WorkflowDefinitionLink findByCompanyId_Last(long companyId,
644                    OrderByComparator orderByComparator)
645                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
646                    int count = countByCompanyId(companyId);
647    
648                    List<WorkflowDefinitionLink> list = findByCompanyId(companyId,
649                                    count - 1, count, orderByComparator);
650    
651                    if (list.isEmpty()) {
652                            StringBundler msg = new StringBundler(4);
653    
654                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
655    
656                            msg.append("companyId=");
657                            msg.append(companyId);
658    
659                            msg.append(StringPool.CLOSE_CURLY_BRACE);
660    
661                            throw new NoSuchWorkflowDefinitionLinkException(msg.toString());
662                    }
663                    else {
664                            return list.get(0);
665                    }
666            }
667    
668            /**
669             * Finds the workflow definition links before and after the current workflow definition link in the ordered set where companyId = &#63;.
670             *
671             * <p>
672             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
673             * </p>
674             *
675             * @param workflowDefinitionLinkId the primary key of the current workflow definition link
676             * @param companyId the company id to search with
677             * @param orderByComparator the comparator to order the set by
678             * @return the previous, current, and next workflow definition link
679             * @throws com.liferay.portal.NoSuchWorkflowDefinitionLinkException if a workflow definition link with the primary key could not be found
680             * @throws SystemException if a system exception occurred
681             */
682            public WorkflowDefinitionLink[] findByCompanyId_PrevAndNext(
683                    long workflowDefinitionLinkId, long companyId,
684                    OrderByComparator orderByComparator)
685                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
686                    WorkflowDefinitionLink workflowDefinitionLink = findByPrimaryKey(workflowDefinitionLinkId);
687    
688                    Session session = null;
689    
690                    try {
691                            session = openSession();
692    
693                            WorkflowDefinitionLink[] array = new WorkflowDefinitionLinkImpl[3];
694    
695                            array[0] = getByCompanyId_PrevAndNext(session,
696                                            workflowDefinitionLink, companyId, orderByComparator, true);
697    
698                            array[1] = workflowDefinitionLink;
699    
700                            array[2] = getByCompanyId_PrevAndNext(session,
701                                            workflowDefinitionLink, companyId, orderByComparator, false);
702    
703                            return array;
704                    }
705                    catch (Exception e) {
706                            throw processException(e);
707                    }
708                    finally {
709                            closeSession(session);
710                    }
711            }
712    
713            protected WorkflowDefinitionLink getByCompanyId_PrevAndNext(
714                    Session session, WorkflowDefinitionLink workflowDefinitionLink,
715                    long companyId, OrderByComparator orderByComparator, boolean previous) {
716                    StringBundler query = null;
717    
718                    if (orderByComparator != null) {
719                            query = new StringBundler(6 +
720                                            (orderByComparator.getOrderByFields().length * 6));
721                    }
722                    else {
723                            query = new StringBundler(3);
724                    }
725    
726                    query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE);
727    
728                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
729    
730                    if (orderByComparator != null) {
731                            String[] orderByFields = orderByComparator.getOrderByFields();
732    
733                            if (orderByFields.length > 0) {
734                                    query.append(WHERE_AND);
735                            }
736    
737                            for (int i = 0; i < orderByFields.length; i++) {
738                                    query.append(_ORDER_BY_ENTITY_ALIAS);
739                                    query.append(orderByFields[i]);
740    
741                                    if ((i + 1) < orderByFields.length) {
742                                            if (orderByComparator.isAscending() ^ previous) {
743                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
744                                            }
745                                            else {
746                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
747                                            }
748                                    }
749                                    else {
750                                            if (orderByComparator.isAscending() ^ previous) {
751                                                    query.append(WHERE_GREATER_THAN);
752                                            }
753                                            else {
754                                                    query.append(WHERE_LESSER_THAN);
755                                            }
756                                    }
757                            }
758    
759                            query.append(ORDER_BY_CLAUSE);
760    
761                            for (int i = 0; i < orderByFields.length; i++) {
762                                    query.append(_ORDER_BY_ENTITY_ALIAS);
763                                    query.append(orderByFields[i]);
764    
765                                    if ((i + 1) < orderByFields.length) {
766                                            if (orderByComparator.isAscending() ^ previous) {
767                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
768                                            }
769                                            else {
770                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
771                                            }
772                                    }
773                                    else {
774                                            if (orderByComparator.isAscending() ^ previous) {
775                                                    query.append(ORDER_BY_ASC);
776                                            }
777                                            else {
778                                                    query.append(ORDER_BY_DESC);
779                                            }
780                                    }
781                            }
782                    }
783    
784                    else {
785                            query.append(WorkflowDefinitionLinkModelImpl.ORDER_BY_JPQL);
786                    }
787    
788                    String sql = query.toString();
789    
790                    Query q = session.createQuery(sql);
791    
792                    q.setFirstResult(0);
793                    q.setMaxResults(2);
794    
795                    QueryPos qPos = QueryPos.getInstance(q);
796    
797                    qPos.add(companyId);
798    
799                    if (orderByComparator != null) {
800                            Object[] values = orderByComparator.getOrderByValues(workflowDefinitionLink);
801    
802                            for (Object value : values) {
803                                    qPos.add(value);
804                            }
805                    }
806    
807                    List<WorkflowDefinitionLink> list = q.list();
808    
809                    if (list.size() == 2) {
810                            return list.get(1);
811                    }
812                    else {
813                            return null;
814                    }
815            }
816    
817            /**
818             * Finds the workflow definition link where groupId = &#63; and companyId = &#63; and classNameId = &#63; or throws a {@link com.liferay.portal.NoSuchWorkflowDefinitionLinkException} if it could not be found.
819             *
820             * @param groupId the group id to search with
821             * @param companyId the company id to search with
822             * @param classNameId the class name id to search with
823             * @return the matching workflow definition link
824             * @throws com.liferay.portal.NoSuchWorkflowDefinitionLinkException if a matching workflow definition link could not be found
825             * @throws SystemException if a system exception occurred
826             */
827            public WorkflowDefinitionLink findByG_C_C(long groupId, long companyId,
828                    long classNameId)
829                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
830                    WorkflowDefinitionLink workflowDefinitionLink = fetchByG_C_C(groupId,
831                                    companyId, classNameId);
832    
833                    if (workflowDefinitionLink == null) {
834                            StringBundler msg = new StringBundler(8);
835    
836                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
837    
838                            msg.append("groupId=");
839                            msg.append(groupId);
840    
841                            msg.append(", companyId=");
842                            msg.append(companyId);
843    
844                            msg.append(", classNameId=");
845                            msg.append(classNameId);
846    
847                            msg.append(StringPool.CLOSE_CURLY_BRACE);
848    
849                            if (_log.isWarnEnabled()) {
850                                    _log.warn(msg.toString());
851                            }
852    
853                            throw new NoSuchWorkflowDefinitionLinkException(msg.toString());
854                    }
855    
856                    return workflowDefinitionLink;
857            }
858    
859            /**
860             * Finds the workflow definition link where groupId = &#63; and companyId = &#63; and classNameId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
861             *
862             * @param groupId the group id to search with
863             * @param companyId the company id to search with
864             * @param classNameId the class name id to search with
865             * @return the matching workflow definition link, or <code>null</code> if a matching workflow definition link could not be found
866             * @throws SystemException if a system exception occurred
867             */
868            public WorkflowDefinitionLink fetchByG_C_C(long groupId, long companyId,
869                    long classNameId) throws SystemException {
870                    return fetchByG_C_C(groupId, companyId, classNameId, true);
871            }
872    
873            /**
874             * Finds the workflow definition link where groupId = &#63; and companyId = &#63; and classNameId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
875             *
876             * @param groupId the group id to search with
877             * @param companyId the company id to search with
878             * @param classNameId the class name id to search with
879             * @return the matching workflow definition link, or <code>null</code> if a matching workflow definition link could not be found
880             * @throws SystemException if a system exception occurred
881             */
882            public WorkflowDefinitionLink fetchByG_C_C(long groupId, long companyId,
883                    long classNameId, boolean retrieveFromCache) throws SystemException {
884                    Object[] finderArgs = new Object[] { groupId, companyId, classNameId };
885    
886                    Object result = null;
887    
888                    if (retrieveFromCache) {
889                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_C_C,
890                                            finderArgs, this);
891                    }
892    
893                    if (result == null) {
894                            Session session = null;
895    
896                            try {
897                                    session = openSession();
898    
899                                    StringBundler query = new StringBundler(5);
900    
901                                    query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE);
902    
903                                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
904    
905                                    query.append(_FINDER_COLUMN_G_C_C_COMPANYID_2);
906    
907                                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
908    
909                                    query.append(WorkflowDefinitionLinkModelImpl.ORDER_BY_JPQL);
910    
911                                    String sql = query.toString();
912    
913                                    Query q = session.createQuery(sql);
914    
915                                    QueryPos qPos = QueryPos.getInstance(q);
916    
917                                    qPos.add(groupId);
918    
919                                    qPos.add(companyId);
920    
921                                    qPos.add(classNameId);
922    
923                                    List<WorkflowDefinitionLink> list = q.list();
924    
925                                    result = list;
926    
927                                    WorkflowDefinitionLink workflowDefinitionLink = null;
928    
929                                    if (list.isEmpty()) {
930                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C,
931                                                    finderArgs, list);
932                                    }
933                                    else {
934                                            workflowDefinitionLink = list.get(0);
935    
936                                            cacheResult(workflowDefinitionLink);
937    
938                                            if ((workflowDefinitionLink.getGroupId() != groupId) ||
939                                                            (workflowDefinitionLink.getCompanyId() != companyId) ||
940                                                            (workflowDefinitionLink.getClassNameId() != classNameId)) {
941                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C,
942                                                            finderArgs, workflowDefinitionLink);
943                                            }
944                                    }
945    
946                                    return workflowDefinitionLink;
947                            }
948                            catch (Exception e) {
949                                    throw processException(e);
950                            }
951                            finally {
952                                    if (result == null) {
953                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C,
954                                                    finderArgs, new ArrayList<WorkflowDefinitionLink>());
955                                    }
956    
957                                    closeSession(session);
958                            }
959                    }
960                    else {
961                            if (result instanceof List<?>) {
962                                    return null;
963                            }
964                            else {
965                                    return (WorkflowDefinitionLink)result;
966                            }
967                    }
968            }
969    
970            /**
971             * Finds all the workflow definition links where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63;.
972             *
973             * @param companyId the company id to search with
974             * @param workflowDefinitionName the workflow definition name to search with
975             * @param workflowDefinitionVersion the workflow definition version to search with
976             * @return the matching workflow definition links
977             * @throws SystemException if a system exception occurred
978             */
979            public List<WorkflowDefinitionLink> findByC_W_W(long companyId,
980                    String workflowDefinitionName, int workflowDefinitionVersion)
981                    throws SystemException {
982                    return findByC_W_W(companyId, workflowDefinitionName,
983                            workflowDefinitionVersion, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
984                            null);
985            }
986    
987            /**
988             * Finds a range of all the workflow definition links where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63;.
989             *
990             * <p>
991             * 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.
992             * </p>
993             *
994             * @param companyId the company id to search with
995             * @param workflowDefinitionName the workflow definition name to search with
996             * @param workflowDefinitionVersion the workflow definition version to search with
997             * @param start the lower bound of the range of workflow definition links to return
998             * @param end the upper bound of the range of workflow definition links to return (not inclusive)
999             * @return the range of matching workflow definition links
1000             * @throws SystemException if a system exception occurred
1001             */
1002            public List<WorkflowDefinitionLink> findByC_W_W(long companyId,
1003                    String workflowDefinitionName, int workflowDefinitionVersion,
1004                    int start, int end) throws SystemException {
1005                    return findByC_W_W(companyId, workflowDefinitionName,
1006                            workflowDefinitionVersion, start, end, null);
1007            }
1008    
1009            /**
1010             * Finds an ordered range of all the workflow definition links where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63;.
1011             *
1012             * <p>
1013             * 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.
1014             * </p>
1015             *
1016             * @param companyId the company id to search with
1017             * @param workflowDefinitionName the workflow definition name to search with
1018             * @param workflowDefinitionVersion the workflow definition version to search with
1019             * @param start the lower bound of the range of workflow definition links to return
1020             * @param end the upper bound of the range of workflow definition links to return (not inclusive)
1021             * @param orderByComparator the comparator to order the results by
1022             * @return the ordered range of matching workflow definition links
1023             * @throws SystemException if a system exception occurred
1024             */
1025            public List<WorkflowDefinitionLink> findByC_W_W(long companyId,
1026                    String workflowDefinitionName, int workflowDefinitionVersion,
1027                    int start, int end, OrderByComparator orderByComparator)
1028                    throws SystemException {
1029                    Object[] finderArgs = new Object[] {
1030                                    companyId, workflowDefinitionName, workflowDefinitionVersion,
1031                                    
1032                                    String.valueOf(start), String.valueOf(end),
1033                                    String.valueOf(orderByComparator)
1034                            };
1035    
1036                    List<WorkflowDefinitionLink> list = (List<WorkflowDefinitionLink>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_W_W,
1037                                    finderArgs, this);
1038    
1039                    if (list == null) {
1040                            Session session = null;
1041    
1042                            try {
1043                                    session = openSession();
1044    
1045                                    StringBundler query = null;
1046    
1047                                    if (orderByComparator != null) {
1048                                            query = new StringBundler(5 +
1049                                                            (orderByComparator.getOrderByFields().length * 3));
1050                                    }
1051                                    else {
1052                                            query = new StringBundler(5);
1053                                    }
1054    
1055                                    query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE);
1056    
1057                                    query.append(_FINDER_COLUMN_C_W_W_COMPANYID_2);
1058    
1059                                    if (workflowDefinitionName == null) {
1060                                            query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_1);
1061                                    }
1062                                    else {
1063                                            if (workflowDefinitionName.equals(StringPool.BLANK)) {
1064                                                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_3);
1065                                            }
1066                                            else {
1067                                                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_2);
1068                                            }
1069                                    }
1070    
1071                                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONVERSION_2);
1072    
1073                                    if (orderByComparator != null) {
1074                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1075                                                    orderByComparator);
1076                                    }
1077    
1078                                    else {
1079                                            query.append(WorkflowDefinitionLinkModelImpl.ORDER_BY_JPQL);
1080                                    }
1081    
1082                                    String sql = query.toString();
1083    
1084                                    Query q = session.createQuery(sql);
1085    
1086                                    QueryPos qPos = QueryPos.getInstance(q);
1087    
1088                                    qPos.add(companyId);
1089    
1090                                    if (workflowDefinitionName != null) {
1091                                            qPos.add(workflowDefinitionName);
1092                                    }
1093    
1094                                    qPos.add(workflowDefinitionVersion);
1095    
1096                                    list = (List<WorkflowDefinitionLink>)QueryUtil.list(q,
1097                                                    getDialect(), start, end);
1098                            }
1099                            catch (Exception e) {
1100                                    throw processException(e);
1101                            }
1102                            finally {
1103                                    if (list == null) {
1104                                            list = new ArrayList<WorkflowDefinitionLink>();
1105                                    }
1106    
1107                                    cacheResult(list);
1108    
1109                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_W_W,
1110                                            finderArgs, list);
1111    
1112                                    closeSession(session);
1113                            }
1114                    }
1115    
1116                    return list;
1117            }
1118    
1119            /**
1120             * Finds the first workflow definition link in the ordered set where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63;.
1121             *
1122             * <p>
1123             * 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.
1124             * </p>
1125             *
1126             * @param companyId the company id to search with
1127             * @param workflowDefinitionName the workflow definition name to search with
1128             * @param workflowDefinitionVersion the workflow definition version to search with
1129             * @param orderByComparator the comparator to order the set by
1130             * @return the first matching workflow definition link
1131             * @throws com.liferay.portal.NoSuchWorkflowDefinitionLinkException if a matching workflow definition link could not be found
1132             * @throws SystemException if a system exception occurred
1133             */
1134            public WorkflowDefinitionLink findByC_W_W_First(long companyId,
1135                    String workflowDefinitionName, int workflowDefinitionVersion,
1136                    OrderByComparator orderByComparator)
1137                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
1138                    List<WorkflowDefinitionLink> list = findByC_W_W(companyId,
1139                                    workflowDefinitionName, workflowDefinitionVersion, 0, 1,
1140                                    orderByComparator);
1141    
1142                    if (list.isEmpty()) {
1143                            StringBundler msg = new StringBundler(8);
1144    
1145                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1146    
1147                            msg.append("companyId=");
1148                            msg.append(companyId);
1149    
1150                            msg.append(", workflowDefinitionName=");
1151                            msg.append(workflowDefinitionName);
1152    
1153                            msg.append(", workflowDefinitionVersion=");
1154                            msg.append(workflowDefinitionVersion);
1155    
1156                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1157    
1158                            throw new NoSuchWorkflowDefinitionLinkException(msg.toString());
1159                    }
1160                    else {
1161                            return list.get(0);
1162                    }
1163            }
1164    
1165            /**
1166             * Finds the last workflow definition link in the ordered set where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63;.
1167             *
1168             * <p>
1169             * 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.
1170             * </p>
1171             *
1172             * @param companyId the company id to search with
1173             * @param workflowDefinitionName the workflow definition name to search with
1174             * @param workflowDefinitionVersion the workflow definition version to search with
1175             * @param orderByComparator the comparator to order the set by
1176             * @return the last matching workflow definition link
1177             * @throws com.liferay.portal.NoSuchWorkflowDefinitionLinkException if a matching workflow definition link could not be found
1178             * @throws SystemException if a system exception occurred
1179             */
1180            public WorkflowDefinitionLink findByC_W_W_Last(long companyId,
1181                    String workflowDefinitionName, int workflowDefinitionVersion,
1182                    OrderByComparator orderByComparator)
1183                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
1184                    int count = countByC_W_W(companyId, workflowDefinitionName,
1185                                    workflowDefinitionVersion);
1186    
1187                    List<WorkflowDefinitionLink> list = findByC_W_W(companyId,
1188                                    workflowDefinitionName, workflowDefinitionVersion, count - 1,
1189                                    count, orderByComparator);
1190    
1191                    if (list.isEmpty()) {
1192                            StringBundler msg = new StringBundler(8);
1193    
1194                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1195    
1196                            msg.append("companyId=");
1197                            msg.append(companyId);
1198    
1199                            msg.append(", workflowDefinitionName=");
1200                            msg.append(workflowDefinitionName);
1201    
1202                            msg.append(", workflowDefinitionVersion=");
1203                            msg.append(workflowDefinitionVersion);
1204    
1205                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1206    
1207                            throw new NoSuchWorkflowDefinitionLinkException(msg.toString());
1208                    }
1209                    else {
1210                            return list.get(0);
1211                    }
1212            }
1213    
1214            /**
1215             * Finds 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;.
1216             *
1217             * <p>
1218             * 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.
1219             * </p>
1220             *
1221             * @param workflowDefinitionLinkId the primary key of the current workflow definition link
1222             * @param companyId the company id to search with
1223             * @param workflowDefinitionName the workflow definition name to search with
1224             * @param workflowDefinitionVersion the workflow definition version to search with
1225             * @param orderByComparator the comparator to order the set by
1226             * @return the previous, current, and next workflow definition link
1227             * @throws com.liferay.portal.NoSuchWorkflowDefinitionLinkException if a workflow definition link with the primary key could not be found
1228             * @throws SystemException if a system exception occurred
1229             */
1230            public WorkflowDefinitionLink[] findByC_W_W_PrevAndNext(
1231                    long workflowDefinitionLinkId, long companyId,
1232                    String workflowDefinitionName, int workflowDefinitionVersion,
1233                    OrderByComparator orderByComparator)
1234                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
1235                    WorkflowDefinitionLink workflowDefinitionLink = findByPrimaryKey(workflowDefinitionLinkId);
1236    
1237                    Session session = null;
1238    
1239                    try {
1240                            session = openSession();
1241    
1242                            WorkflowDefinitionLink[] array = new WorkflowDefinitionLinkImpl[3];
1243    
1244                            array[0] = getByC_W_W_PrevAndNext(session, workflowDefinitionLink,
1245                                            companyId, workflowDefinitionName,
1246                                            workflowDefinitionVersion, orderByComparator, true);
1247    
1248                            array[1] = workflowDefinitionLink;
1249    
1250                            array[2] = getByC_W_W_PrevAndNext(session, workflowDefinitionLink,
1251                                            companyId, workflowDefinitionName,
1252                                            workflowDefinitionVersion, orderByComparator, false);
1253    
1254                            return array;
1255                    }
1256                    catch (Exception e) {
1257                            throw processException(e);
1258                    }
1259                    finally {
1260                            closeSession(session);
1261                    }
1262            }
1263    
1264            protected WorkflowDefinitionLink getByC_W_W_PrevAndNext(Session session,
1265                    WorkflowDefinitionLink workflowDefinitionLink, long companyId,
1266                    String workflowDefinitionName, int workflowDefinitionVersion,
1267                    OrderByComparator orderByComparator, boolean previous) {
1268                    StringBundler query = null;
1269    
1270                    if (orderByComparator != null) {
1271                            query = new StringBundler(6 +
1272                                            (orderByComparator.getOrderByFields().length * 6));
1273                    }
1274                    else {
1275                            query = new StringBundler(3);
1276                    }
1277    
1278                    query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE);
1279    
1280                    query.append(_FINDER_COLUMN_C_W_W_COMPANYID_2);
1281    
1282                    if (workflowDefinitionName == null) {
1283                            query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_1);
1284                    }
1285                    else {
1286                            if (workflowDefinitionName.equals(StringPool.BLANK)) {
1287                                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_3);
1288                            }
1289                            else {
1290                                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_2);
1291                            }
1292                    }
1293    
1294                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONVERSION_2);
1295    
1296                    if (orderByComparator != null) {
1297                            String[] orderByFields = orderByComparator.getOrderByFields();
1298    
1299                            if (orderByFields.length > 0) {
1300                                    query.append(WHERE_AND);
1301                            }
1302    
1303                            for (int i = 0; i < orderByFields.length; i++) {
1304                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1305                                    query.append(orderByFields[i]);
1306    
1307                                    if ((i + 1) < orderByFields.length) {
1308                                            if (orderByComparator.isAscending() ^ previous) {
1309                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1310                                            }
1311                                            else {
1312                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1313                                            }
1314                                    }
1315                                    else {
1316                                            if (orderByComparator.isAscending() ^ previous) {
1317                                                    query.append(WHERE_GREATER_THAN);
1318                                            }
1319                                            else {
1320                                                    query.append(WHERE_LESSER_THAN);
1321                                            }
1322                                    }
1323                            }
1324    
1325                            query.append(ORDER_BY_CLAUSE);
1326    
1327                            for (int i = 0; i < orderByFields.length; i++) {
1328                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1329                                    query.append(orderByFields[i]);
1330    
1331                                    if ((i + 1) < orderByFields.length) {
1332                                            if (orderByComparator.isAscending() ^ previous) {
1333                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1334                                            }
1335                                            else {
1336                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1337                                            }
1338                                    }
1339                                    else {
1340                                            if (orderByComparator.isAscending() ^ previous) {
1341                                                    query.append(ORDER_BY_ASC);
1342                                            }
1343                                            else {
1344                                                    query.append(ORDER_BY_DESC);
1345                                            }
1346                                    }
1347                            }
1348                    }
1349    
1350                    else {
1351                            query.append(WorkflowDefinitionLinkModelImpl.ORDER_BY_JPQL);
1352                    }
1353    
1354                    String sql = query.toString();
1355    
1356                    Query q = session.createQuery(sql);
1357    
1358                    q.setFirstResult(0);
1359                    q.setMaxResults(2);
1360    
1361                    QueryPos qPos = QueryPos.getInstance(q);
1362    
1363                    qPos.add(companyId);
1364    
1365                    if (workflowDefinitionName != null) {
1366                            qPos.add(workflowDefinitionName);
1367                    }
1368    
1369                    qPos.add(workflowDefinitionVersion);
1370    
1371                    if (orderByComparator != null) {
1372                            Object[] values = orderByComparator.getOrderByValues(workflowDefinitionLink);
1373    
1374                            for (Object value : values) {
1375                                    qPos.add(value);
1376                            }
1377                    }
1378    
1379                    List<WorkflowDefinitionLink> list = q.list();
1380    
1381                    if (list.size() == 2) {
1382                            return list.get(1);
1383                    }
1384                    else {
1385                            return null;
1386                    }
1387            }
1388    
1389            /**
1390             * Finds all the workflow definition links.
1391             *
1392             * @return the workflow definition links
1393             * @throws SystemException if a system exception occurred
1394             */
1395            public List<WorkflowDefinitionLink> findAll() throws SystemException {
1396                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1397            }
1398    
1399            /**
1400             * Finds a range of all the workflow definition links.
1401             *
1402             * <p>
1403             * 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.
1404             * </p>
1405             *
1406             * @param start the lower bound of the range of workflow definition links to return
1407             * @param end the upper bound of the range of workflow definition links to return (not inclusive)
1408             * @return the range of workflow definition links
1409             * @throws SystemException if a system exception occurred
1410             */
1411            public List<WorkflowDefinitionLink> findAll(int start, int end)
1412                    throws SystemException {
1413                    return findAll(start, end, null);
1414            }
1415    
1416            /**
1417             * Finds an ordered range of all the workflow definition links.
1418             *
1419             * <p>
1420             * 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.
1421             * </p>
1422             *
1423             * @param start the lower bound of the range of workflow definition links to return
1424             * @param end the upper bound of the range of workflow definition links to return (not inclusive)
1425             * @param orderByComparator the comparator to order the results by
1426             * @return the ordered range of workflow definition links
1427             * @throws SystemException if a system exception occurred
1428             */
1429            public List<WorkflowDefinitionLink> findAll(int start, int end,
1430                    OrderByComparator orderByComparator) throws SystemException {
1431                    Object[] finderArgs = new Object[] {
1432                                    String.valueOf(start), String.valueOf(end),
1433                                    String.valueOf(orderByComparator)
1434                            };
1435    
1436                    List<WorkflowDefinitionLink> list = (List<WorkflowDefinitionLink>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1437                                    finderArgs, this);
1438    
1439                    if (list == null) {
1440                            Session session = null;
1441    
1442                            try {
1443                                    session = openSession();
1444    
1445                                    StringBundler query = null;
1446                                    String sql = null;
1447    
1448                                    if (orderByComparator != null) {
1449                                            query = new StringBundler(2 +
1450                                                            (orderByComparator.getOrderByFields().length * 3));
1451    
1452                                            query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK);
1453    
1454                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1455                                                    orderByComparator);
1456    
1457                                            sql = query.toString();
1458                                    }
1459                                    else {
1460                                            sql = _SQL_SELECT_WORKFLOWDEFINITIONLINK.concat(WorkflowDefinitionLinkModelImpl.ORDER_BY_JPQL);
1461                                    }
1462    
1463                                    Query q = session.createQuery(sql);
1464    
1465                                    if (orderByComparator == null) {
1466                                            list = (List<WorkflowDefinitionLink>)QueryUtil.list(q,
1467                                                            getDialect(), start, end, false);
1468    
1469                                            Collections.sort(list);
1470                                    }
1471                                    else {
1472                                            list = (List<WorkflowDefinitionLink>)QueryUtil.list(q,
1473                                                            getDialect(), start, end);
1474                                    }
1475                            }
1476                            catch (Exception e) {
1477                                    throw processException(e);
1478                            }
1479                            finally {
1480                                    if (list == null) {
1481                                            list = new ArrayList<WorkflowDefinitionLink>();
1482                                    }
1483    
1484                                    cacheResult(list);
1485    
1486                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1487    
1488                                    closeSession(session);
1489                            }
1490                    }
1491    
1492                    return list;
1493            }
1494    
1495            /**
1496             * Removes all the workflow definition links where companyId = &#63; from the database.
1497             *
1498             * @param companyId the company id to search with
1499             * @throws SystemException if a system exception occurred
1500             */
1501            public void removeByCompanyId(long companyId) throws SystemException {
1502                    for (WorkflowDefinitionLink workflowDefinitionLink : findByCompanyId(
1503                                    companyId)) {
1504                            remove(workflowDefinitionLink);
1505                    }
1506            }
1507    
1508            /**
1509             * Removes the workflow definition link where groupId = &#63; and companyId = &#63; and classNameId = &#63; from the database.
1510             *
1511             * @param groupId the group id to search with
1512             * @param companyId the company id to search with
1513             * @param classNameId the class name id to search with
1514             * @throws SystemException if a system exception occurred
1515             */
1516            public void removeByG_C_C(long groupId, long companyId, long classNameId)
1517                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
1518                    WorkflowDefinitionLink workflowDefinitionLink = findByG_C_C(groupId,
1519                                    companyId, classNameId);
1520    
1521                    remove(workflowDefinitionLink);
1522            }
1523    
1524            /**
1525             * Removes all the workflow definition links where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63; from the database.
1526             *
1527             * @param companyId the company id to search with
1528             * @param workflowDefinitionName the workflow definition name to search with
1529             * @param workflowDefinitionVersion the workflow definition version to search with
1530             * @throws SystemException if a system exception occurred
1531             */
1532            public void removeByC_W_W(long companyId, String workflowDefinitionName,
1533                    int workflowDefinitionVersion) throws SystemException {
1534                    for (WorkflowDefinitionLink workflowDefinitionLink : findByC_W_W(
1535                                    companyId, workflowDefinitionName, workflowDefinitionVersion)) {
1536                            remove(workflowDefinitionLink);
1537                    }
1538            }
1539    
1540            /**
1541             * Removes all the workflow definition links from the database.
1542             *
1543             * @throws SystemException if a system exception occurred
1544             */
1545            public void removeAll() throws SystemException {
1546                    for (WorkflowDefinitionLink workflowDefinitionLink : findAll()) {
1547                            remove(workflowDefinitionLink);
1548                    }
1549            }
1550    
1551            /**
1552             * Counts all the workflow definition links where companyId = &#63;.
1553             *
1554             * @param companyId the company id to search with
1555             * @return the number of matching workflow definition links
1556             * @throws SystemException if a system exception occurred
1557             */
1558            public int countByCompanyId(long companyId) throws SystemException {
1559                    Object[] finderArgs = new Object[] { companyId };
1560    
1561                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1562                                    finderArgs, this);
1563    
1564                    if (count == null) {
1565                            Session session = null;
1566    
1567                            try {
1568                                    session = openSession();
1569    
1570                                    StringBundler query = new StringBundler(2);
1571    
1572                                    query.append(_SQL_COUNT_WORKFLOWDEFINITIONLINK_WHERE);
1573    
1574                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1575    
1576                                    String sql = query.toString();
1577    
1578                                    Query q = session.createQuery(sql);
1579    
1580                                    QueryPos qPos = QueryPos.getInstance(q);
1581    
1582                                    qPos.add(companyId);
1583    
1584                                    count = (Long)q.uniqueResult();
1585                            }
1586                            catch (Exception e) {
1587                                    throw processException(e);
1588                            }
1589                            finally {
1590                                    if (count == null) {
1591                                            count = Long.valueOf(0);
1592                                    }
1593    
1594                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1595                                            finderArgs, count);
1596    
1597                                    closeSession(session);
1598                            }
1599                    }
1600    
1601                    return count.intValue();
1602            }
1603    
1604            /**
1605             * Counts all the workflow definition links where groupId = &#63; and companyId = &#63; and classNameId = &#63;.
1606             *
1607             * @param groupId the group id to search with
1608             * @param companyId the company id to search with
1609             * @param classNameId the class name id to search with
1610             * @return the number of matching workflow definition links
1611             * @throws SystemException if a system exception occurred
1612             */
1613            public int countByG_C_C(long groupId, long companyId, long classNameId)
1614                    throws SystemException {
1615                    Object[] finderArgs = new Object[] { groupId, companyId, classNameId };
1616    
1617                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_C,
1618                                    finderArgs, this);
1619    
1620                    if (count == null) {
1621                            Session session = null;
1622    
1623                            try {
1624                                    session = openSession();
1625    
1626                                    StringBundler query = new StringBundler(4);
1627    
1628                                    query.append(_SQL_COUNT_WORKFLOWDEFINITIONLINK_WHERE);
1629    
1630                                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
1631    
1632                                    query.append(_FINDER_COLUMN_G_C_C_COMPANYID_2);
1633    
1634                                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
1635    
1636                                    String sql = query.toString();
1637    
1638                                    Query q = session.createQuery(sql);
1639    
1640                                    QueryPos qPos = QueryPos.getInstance(q);
1641    
1642                                    qPos.add(groupId);
1643    
1644                                    qPos.add(companyId);
1645    
1646                                    qPos.add(classNameId);
1647    
1648                                    count = (Long)q.uniqueResult();
1649                            }
1650                            catch (Exception e) {
1651                                    throw processException(e);
1652                            }
1653                            finally {
1654                                    if (count == null) {
1655                                            count = Long.valueOf(0);
1656                                    }
1657    
1658                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_C,
1659                                            finderArgs, count);
1660    
1661                                    closeSession(session);
1662                            }
1663                    }
1664    
1665                    return count.intValue();
1666            }
1667    
1668            /**
1669             * Counts all the workflow definition links where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63;.
1670             *
1671             * @param companyId the company id to search with
1672             * @param workflowDefinitionName the workflow definition name to search with
1673             * @param workflowDefinitionVersion the workflow definition version to search with
1674             * @return the number of matching workflow definition links
1675             * @throws SystemException if a system exception occurred
1676             */
1677            public int countByC_W_W(long companyId, String workflowDefinitionName,
1678                    int workflowDefinitionVersion) throws SystemException {
1679                    Object[] finderArgs = new Object[] {
1680                                    companyId, workflowDefinitionName, workflowDefinitionVersion
1681                            };
1682    
1683                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_W_W,
1684                                    finderArgs, this);
1685    
1686                    if (count == null) {
1687                            Session session = null;
1688    
1689                            try {
1690                                    session = openSession();
1691    
1692                                    StringBundler query = new StringBundler(4);
1693    
1694                                    query.append(_SQL_COUNT_WORKFLOWDEFINITIONLINK_WHERE);
1695    
1696                                    query.append(_FINDER_COLUMN_C_W_W_COMPANYID_2);
1697    
1698                                    if (workflowDefinitionName == null) {
1699                                            query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_1);
1700                                    }
1701                                    else {
1702                                            if (workflowDefinitionName.equals(StringPool.BLANK)) {
1703                                                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_3);
1704                                            }
1705                                            else {
1706                                                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_2);
1707                                            }
1708                                    }
1709    
1710                                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONVERSION_2);
1711    
1712                                    String sql = query.toString();
1713    
1714                                    Query q = session.createQuery(sql);
1715    
1716                                    QueryPos qPos = QueryPos.getInstance(q);
1717    
1718                                    qPos.add(companyId);
1719    
1720                                    if (workflowDefinitionName != null) {
1721                                            qPos.add(workflowDefinitionName);
1722                                    }
1723    
1724                                    qPos.add(workflowDefinitionVersion);
1725    
1726                                    count = (Long)q.uniqueResult();
1727                            }
1728                            catch (Exception e) {
1729                                    throw processException(e);
1730                            }
1731                            finally {
1732                                    if (count == null) {
1733                                            count = Long.valueOf(0);
1734                                    }
1735    
1736                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_W_W,
1737                                            finderArgs, count);
1738    
1739                                    closeSession(session);
1740                            }
1741                    }
1742    
1743                    return count.intValue();
1744            }
1745    
1746            /**
1747             * Counts all the workflow definition links.
1748             *
1749             * @return the number of workflow definition links
1750             * @throws SystemException if a system exception occurred
1751             */
1752            public int countAll() throws SystemException {
1753                    Object[] finderArgs = new Object[0];
1754    
1755                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1756                                    finderArgs, this);
1757    
1758                    if (count == null) {
1759                            Session session = null;
1760    
1761                            try {
1762                                    session = openSession();
1763    
1764                                    Query q = session.createQuery(_SQL_COUNT_WORKFLOWDEFINITIONLINK);
1765    
1766                                    count = (Long)q.uniqueResult();
1767                            }
1768                            catch (Exception e) {
1769                                    throw processException(e);
1770                            }
1771                            finally {
1772                                    if (count == null) {
1773                                            count = Long.valueOf(0);
1774                                    }
1775    
1776                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1777                                            count);
1778    
1779                                    closeSession(session);
1780                            }
1781                    }
1782    
1783                    return count.intValue();
1784            }
1785    
1786            /**
1787             * Initializes the workflow definition link persistence.
1788             */
1789            public void afterPropertiesSet() {
1790                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1791                                            com.liferay.portal.util.PropsUtil.get(
1792                                                    "value.object.listener.com.liferay.portal.model.WorkflowDefinitionLink")));
1793    
1794                    if (listenerClassNames.length > 0) {
1795                            try {
1796                                    List<ModelListener<WorkflowDefinitionLink>> listenersList = new ArrayList<ModelListener<WorkflowDefinitionLink>>();
1797    
1798                                    for (String listenerClassName : listenerClassNames) {
1799                                            listenersList.add((ModelListener<WorkflowDefinitionLink>)InstanceFactory.newInstance(
1800                                                            listenerClassName));
1801                                    }
1802    
1803                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1804                            }
1805                            catch (Exception e) {
1806                                    _log.error(e);
1807                            }
1808                    }
1809            }
1810    
1811            @BeanReference(type = AccountPersistence.class)
1812            protected AccountPersistence accountPersistence;
1813            @BeanReference(type = AddressPersistence.class)
1814            protected AddressPersistence addressPersistence;
1815            @BeanReference(type = BrowserTrackerPersistence.class)
1816            protected BrowserTrackerPersistence browserTrackerPersistence;
1817            @BeanReference(type = ClassNamePersistence.class)
1818            protected ClassNamePersistence classNamePersistence;
1819            @BeanReference(type = CompanyPersistence.class)
1820            protected CompanyPersistence companyPersistence;
1821            @BeanReference(type = ContactPersistence.class)
1822            protected ContactPersistence contactPersistence;
1823            @BeanReference(type = CountryPersistence.class)
1824            protected CountryPersistence countryPersistence;
1825            @BeanReference(type = EmailAddressPersistence.class)
1826            protected EmailAddressPersistence emailAddressPersistence;
1827            @BeanReference(type = GroupPersistence.class)
1828            protected GroupPersistence groupPersistence;
1829            @BeanReference(type = ImagePersistence.class)
1830            protected ImagePersistence imagePersistence;
1831            @BeanReference(type = LayoutPersistence.class)
1832            protected LayoutPersistence layoutPersistence;
1833            @BeanReference(type = LayoutPrototypePersistence.class)
1834            protected LayoutPrototypePersistence layoutPrototypePersistence;
1835            @BeanReference(type = LayoutSetPersistence.class)
1836            protected LayoutSetPersistence layoutSetPersistence;
1837            @BeanReference(type = LayoutSetPrototypePersistence.class)
1838            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1839            @BeanReference(type = ListTypePersistence.class)
1840            protected ListTypePersistence listTypePersistence;
1841            @BeanReference(type = LockPersistence.class)
1842            protected LockPersistence lockPersistence;
1843            @BeanReference(type = MembershipRequestPersistence.class)
1844            protected MembershipRequestPersistence membershipRequestPersistence;
1845            @BeanReference(type = OrganizationPersistence.class)
1846            protected OrganizationPersistence organizationPersistence;
1847            @BeanReference(type = OrgGroupPermissionPersistence.class)
1848            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1849            @BeanReference(type = OrgGroupRolePersistence.class)
1850            protected OrgGroupRolePersistence orgGroupRolePersistence;
1851            @BeanReference(type = OrgLaborPersistence.class)
1852            protected OrgLaborPersistence orgLaborPersistence;
1853            @BeanReference(type = PasswordPolicyPersistence.class)
1854            protected PasswordPolicyPersistence passwordPolicyPersistence;
1855            @BeanReference(type = PasswordPolicyRelPersistence.class)
1856            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1857            @BeanReference(type = PasswordTrackerPersistence.class)
1858            protected PasswordTrackerPersistence passwordTrackerPersistence;
1859            @BeanReference(type = PermissionPersistence.class)
1860            protected PermissionPersistence permissionPersistence;
1861            @BeanReference(type = PhonePersistence.class)
1862            protected PhonePersistence phonePersistence;
1863            @BeanReference(type = PluginSettingPersistence.class)
1864            protected PluginSettingPersistence pluginSettingPersistence;
1865            @BeanReference(type = PortletPersistence.class)
1866            protected PortletPersistence portletPersistence;
1867            @BeanReference(type = PortletItemPersistence.class)
1868            protected PortletItemPersistence portletItemPersistence;
1869            @BeanReference(type = PortletPreferencesPersistence.class)
1870            protected PortletPreferencesPersistence portletPreferencesPersistence;
1871            @BeanReference(type = RegionPersistence.class)
1872            protected RegionPersistence regionPersistence;
1873            @BeanReference(type = ReleasePersistence.class)
1874            protected ReleasePersistence releasePersistence;
1875            @BeanReference(type = ResourcePersistence.class)
1876            protected ResourcePersistence resourcePersistence;
1877            @BeanReference(type = ResourceActionPersistence.class)
1878            protected ResourceActionPersistence resourceActionPersistence;
1879            @BeanReference(type = ResourceCodePersistence.class)
1880            protected ResourceCodePersistence resourceCodePersistence;
1881            @BeanReference(type = ResourcePermissionPersistence.class)
1882            protected ResourcePermissionPersistence resourcePermissionPersistence;
1883            @BeanReference(type = RolePersistence.class)
1884            protected RolePersistence rolePersistence;
1885            @BeanReference(type = ServiceComponentPersistence.class)
1886            protected ServiceComponentPersistence serviceComponentPersistence;
1887            @BeanReference(type = ShardPersistence.class)
1888            protected ShardPersistence shardPersistence;
1889            @BeanReference(type = SubscriptionPersistence.class)
1890            protected SubscriptionPersistence subscriptionPersistence;
1891            @BeanReference(type = TicketPersistence.class)
1892            protected TicketPersistence ticketPersistence;
1893            @BeanReference(type = TeamPersistence.class)
1894            protected TeamPersistence teamPersistence;
1895            @BeanReference(type = UserPersistence.class)
1896            protected UserPersistence userPersistence;
1897            @BeanReference(type = UserGroupPersistence.class)
1898            protected UserGroupPersistence userGroupPersistence;
1899            @BeanReference(type = UserGroupGroupRolePersistence.class)
1900            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1901            @BeanReference(type = UserGroupRolePersistence.class)
1902            protected UserGroupRolePersistence userGroupRolePersistence;
1903            @BeanReference(type = UserIdMapperPersistence.class)
1904            protected UserIdMapperPersistence userIdMapperPersistence;
1905            @BeanReference(type = UserTrackerPersistence.class)
1906            protected UserTrackerPersistence userTrackerPersistence;
1907            @BeanReference(type = UserTrackerPathPersistence.class)
1908            protected UserTrackerPathPersistence userTrackerPathPersistence;
1909            @BeanReference(type = WebDAVPropsPersistence.class)
1910            protected WebDAVPropsPersistence webDAVPropsPersistence;
1911            @BeanReference(type = WebsitePersistence.class)
1912            protected WebsitePersistence websitePersistence;
1913            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1914            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1915            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1916            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1917            private static final String _SQL_SELECT_WORKFLOWDEFINITIONLINK = "SELECT workflowDefinitionLink FROM WorkflowDefinitionLink workflowDefinitionLink";
1918            private static final String _SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE = "SELECT workflowDefinitionLink FROM WorkflowDefinitionLink workflowDefinitionLink WHERE ";
1919            private static final String _SQL_COUNT_WORKFLOWDEFINITIONLINK = "SELECT COUNT(workflowDefinitionLink) FROM WorkflowDefinitionLink workflowDefinitionLink";
1920            private static final String _SQL_COUNT_WORKFLOWDEFINITIONLINK_WHERE = "SELECT COUNT(workflowDefinitionLink) FROM WorkflowDefinitionLink workflowDefinitionLink WHERE ";
1921            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "workflowDefinitionLink.companyId = ?";
1922            private static final String _FINDER_COLUMN_G_C_C_GROUPID_2 = "workflowDefinitionLink.groupId = ? AND ";
1923            private static final String _FINDER_COLUMN_G_C_C_COMPANYID_2 = "workflowDefinitionLink.companyId = ? AND ";
1924            private static final String _FINDER_COLUMN_G_C_C_CLASSNAMEID_2 = "workflowDefinitionLink.classNameId = ?";
1925            private static final String _FINDER_COLUMN_C_W_W_COMPANYID_2 = "workflowDefinitionLink.companyId = ? AND ";
1926            private static final String _FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_1 = "workflowDefinitionLink.workflowDefinitionName IS NULL AND ";
1927            private static final String _FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_2 = "workflowDefinitionLink.workflowDefinitionName = ? AND ";
1928            private static final String _FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_3 = "(workflowDefinitionLink.workflowDefinitionName IS NULL OR workflowDefinitionLink.workflowDefinitionName = ?) AND ";
1929            private static final String _FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONVERSION_2 =
1930                    "workflowDefinitionLink.workflowDefinitionVersion = ?";
1931            private static final String _ORDER_BY_ENTITY_ALIAS = "workflowDefinitionLink.";
1932            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WorkflowDefinitionLink exists with the primary key ";
1933            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WorkflowDefinitionLink exists with the key {";
1934            private static Log _log = LogFactoryUtil.getLog(WorkflowDefinitionLinkPersistenceImpl.class);
1935    }