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