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