001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.NoSuchWorkflowDefinitionLinkException;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.UnmodifiableList;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.model.CacheModel;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.model.WorkflowDefinitionLink;
041    import com.liferay.portal.model.impl.WorkflowDefinitionLinkImpl;
042    import com.liferay.portal.model.impl.WorkflowDefinitionLinkModelImpl;
043    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044    
045    import java.io.Serializable;
046    
047    import java.util.ArrayList;
048    import java.util.Collections;
049    import java.util.List;
050    
051    /**
052     * The persistence implementation for the workflow definition link service.
053     *
054     * <p>
055     * Caching information and settings can be found in <code>portal.properties</code>
056     * </p>
057     *
058     * @author Brian Wing Shun Chan
059     * @see WorkflowDefinitionLinkPersistence
060     * @see WorkflowDefinitionLinkUtil
061     * @generated
062     */
063    public class WorkflowDefinitionLinkPersistenceImpl extends BasePersistenceImpl<WorkflowDefinitionLink>
064            implements WorkflowDefinitionLinkPersistence {
065            /*
066             * NOTE FOR DEVELOPERS:
067             *
068             * 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.
069             */
070            public static final String FINDER_CLASS_NAME_ENTITY = WorkflowDefinitionLinkImpl.class.getName();
071            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072                    ".List1";
073            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074                    ".List2";
075            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
076                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
077                            WorkflowDefinitionLinkImpl.class,
078                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
079            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
080                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
081                            WorkflowDefinitionLinkImpl.class,
082                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
083            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
084                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
085                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
086            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
087                    new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
088                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
089                            WorkflowDefinitionLinkImpl.class,
090                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
091                            new String[] {
092                                    Long.class.getName(),
093                                    
094                            Integer.class.getName(), Integer.class.getName(),
095                                    OrderByComparator.class.getName()
096                            });
097            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
098                    new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
099                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
100                            WorkflowDefinitionLinkImpl.class,
101                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
102                            new String[] { Long.class.getName() },
103                            WorkflowDefinitionLinkModelImpl.COMPANYID_COLUMN_BITMASK |
104                            WorkflowDefinitionLinkModelImpl.WORKFLOWDEFINITIONNAME_COLUMN_BITMASK);
105            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
106                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
107                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
108                            new String[] { Long.class.getName() });
109    
110            /**
111             * Returns all the workflow definition links where companyId = &#63;.
112             *
113             * @param companyId the company ID
114             * @return the matching workflow definition links
115             * @throws SystemException if a system exception occurred
116             */
117            public List<WorkflowDefinitionLink> findByCompanyId(long companyId)
118                    throws SystemException {
119                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
120                            null);
121            }
122    
123            /**
124             * Returns a range of all the workflow definition links where companyId = &#63;.
125             *
126             * <p>
127             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.WorkflowDefinitionLinkModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
128             * </p>
129             *
130             * @param companyId the company ID
131             * @param start the lower bound of the range of workflow definition links
132             * @param end the upper bound of the range of workflow definition links (not inclusive)
133             * @return the range of matching workflow definition links
134             * @throws SystemException if a system exception occurred
135             */
136            public List<WorkflowDefinitionLink> findByCompanyId(long companyId,
137                    int start, int end) throws SystemException {
138                    return findByCompanyId(companyId, start, end, null);
139            }
140    
141            /**
142             * Returns an ordered range of all the workflow definition links where companyId = &#63;.
143             *
144             * <p>
145             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.WorkflowDefinitionLinkModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
146             * </p>
147             *
148             * @param companyId the company ID
149             * @param start the lower bound of the range of workflow definition links
150             * @param end the upper bound of the range of workflow definition links (not inclusive)
151             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
152             * @return the ordered range of matching workflow definition links
153             * @throws SystemException if a system exception occurred
154             */
155            public List<WorkflowDefinitionLink> findByCompanyId(long companyId,
156                    int start, int end, OrderByComparator orderByComparator)
157                    throws SystemException {
158                    boolean pagination = true;
159                    FinderPath finderPath = null;
160                    Object[] finderArgs = null;
161    
162                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
163                                    (orderByComparator == null)) {
164                            pagination = false;
165                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
166                            finderArgs = new Object[] { companyId };
167                    }
168                    else {
169                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
170                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
171                    }
172    
173                    List<WorkflowDefinitionLink> list = (List<WorkflowDefinitionLink>)FinderCacheUtil.getResult(finderPath,
174                                    finderArgs, this);
175    
176                    if ((list != null) && !list.isEmpty()) {
177                            for (WorkflowDefinitionLink workflowDefinitionLink : list) {
178                                    if ((companyId != workflowDefinitionLink.getCompanyId())) {
179                                            list = null;
180    
181                                            break;
182                                    }
183                            }
184                    }
185    
186                    if (list == null) {
187                            StringBundler query = null;
188    
189                            if (orderByComparator != null) {
190                                    query = new StringBundler(3 +
191                                                    (orderByComparator.getOrderByFields().length * 3));
192                            }
193                            else {
194                                    query = new StringBundler(3);
195                            }
196    
197                            query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE);
198    
199                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
200    
201                            if (orderByComparator != null) {
202                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
203                                            orderByComparator);
204                            }
205                            else
206                             if (pagination) {
207                                    query.append(WorkflowDefinitionLinkModelImpl.ORDER_BY_JPQL);
208                            }
209    
210                            String sql = query.toString();
211    
212                            Session session = null;
213    
214                            try {
215                                    session = openSession();
216    
217                                    Query q = session.createQuery(sql);
218    
219                                    QueryPos qPos = QueryPos.getInstance(q);
220    
221                                    qPos.add(companyId);
222    
223                                    if (!pagination) {
224                                            list = (List<WorkflowDefinitionLink>)QueryUtil.list(q,
225                                                            getDialect(), start, end, false);
226    
227                                            Collections.sort(list);
228    
229                                            list = new UnmodifiableList<WorkflowDefinitionLink>(list);
230                                    }
231                                    else {
232                                            list = (List<WorkflowDefinitionLink>)QueryUtil.list(q,
233                                                            getDialect(), start, end);
234                                    }
235    
236                                    cacheResult(list);
237    
238                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
239                            }
240                            catch (Exception e) {
241                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
242    
243                                    throw processException(e);
244                            }
245                            finally {
246                                    closeSession(session);
247                            }
248                    }
249    
250                    return list;
251            }
252    
253            /**
254             * Returns the first workflow definition link in the ordered set where companyId = &#63;.
255             *
256             * @param companyId the company ID
257             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
258             * @return the first matching workflow definition link
259             * @throws com.liferay.portal.NoSuchWorkflowDefinitionLinkException if a matching workflow definition link could not be found
260             * @throws SystemException if a system exception occurred
261             */
262            public WorkflowDefinitionLink findByCompanyId_First(long companyId,
263                    OrderByComparator orderByComparator)
264                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
265                    WorkflowDefinitionLink workflowDefinitionLink = fetchByCompanyId_First(companyId,
266                                    orderByComparator);
267    
268                    if (workflowDefinitionLink != null) {
269                            return workflowDefinitionLink;
270                    }
271    
272                    StringBundler msg = new StringBundler(4);
273    
274                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
275    
276                    msg.append("companyId=");
277                    msg.append(companyId);
278    
279                    msg.append(StringPool.CLOSE_CURLY_BRACE);
280    
281                    throw new NoSuchWorkflowDefinitionLinkException(msg.toString());
282            }
283    
284            /**
285             * Returns the first workflow definition link in the ordered set where companyId = &#63;.
286             *
287             * @param companyId the company ID
288             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
289             * @return the first matching workflow definition link, or <code>null</code> if a matching workflow definition link could not be found
290             * @throws SystemException if a system exception occurred
291             */
292            public WorkflowDefinitionLink fetchByCompanyId_First(long companyId,
293                    OrderByComparator orderByComparator) throws SystemException {
294                    List<WorkflowDefinitionLink> list = findByCompanyId(companyId, 0, 1,
295                                    orderByComparator);
296    
297                    if (!list.isEmpty()) {
298                            return list.get(0);
299                    }
300    
301                    return null;
302            }
303    
304            /**
305             * Returns the last workflow definition link in the ordered set where companyId = &#63;.
306             *
307             * @param companyId the company ID
308             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
309             * @return the last matching workflow definition link
310             * @throws com.liferay.portal.NoSuchWorkflowDefinitionLinkException if a matching workflow definition link could not be found
311             * @throws SystemException if a system exception occurred
312             */
313            public WorkflowDefinitionLink findByCompanyId_Last(long companyId,
314                    OrderByComparator orderByComparator)
315                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
316                    WorkflowDefinitionLink workflowDefinitionLink = fetchByCompanyId_Last(companyId,
317                                    orderByComparator);
318    
319                    if (workflowDefinitionLink != null) {
320                            return workflowDefinitionLink;
321                    }
322    
323                    StringBundler msg = new StringBundler(4);
324    
325                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
326    
327                    msg.append("companyId=");
328                    msg.append(companyId);
329    
330                    msg.append(StringPool.CLOSE_CURLY_BRACE);
331    
332                    throw new NoSuchWorkflowDefinitionLinkException(msg.toString());
333            }
334    
335            /**
336             * Returns the last workflow definition link in the ordered set where companyId = &#63;.
337             *
338             * @param companyId the company ID
339             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
340             * @return the last matching workflow definition link, or <code>null</code> if a matching workflow definition link could not be found
341             * @throws SystemException if a system exception occurred
342             */
343            public WorkflowDefinitionLink fetchByCompanyId_Last(long companyId,
344                    OrderByComparator orderByComparator) throws SystemException {
345                    int count = countByCompanyId(companyId);
346    
347                    List<WorkflowDefinitionLink> list = findByCompanyId(companyId,
348                                    count - 1, count, orderByComparator);
349    
350                    if (!list.isEmpty()) {
351                            return list.get(0);
352                    }
353    
354                    return null;
355            }
356    
357            /**
358             * Returns the workflow definition links before and after the current workflow definition link in the ordered set where companyId = &#63;.
359             *
360             * @param workflowDefinitionLinkId the primary key of the current workflow definition link
361             * @param companyId the company ID
362             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
363             * @return the previous, current, and next workflow definition link
364             * @throws com.liferay.portal.NoSuchWorkflowDefinitionLinkException if a workflow definition link with the primary key could not be found
365             * @throws SystemException if a system exception occurred
366             */
367            public WorkflowDefinitionLink[] findByCompanyId_PrevAndNext(
368                    long workflowDefinitionLinkId, long companyId,
369                    OrderByComparator orderByComparator)
370                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
371                    WorkflowDefinitionLink workflowDefinitionLink = findByPrimaryKey(workflowDefinitionLinkId);
372    
373                    Session session = null;
374    
375                    try {
376                            session = openSession();
377    
378                            WorkflowDefinitionLink[] array = new WorkflowDefinitionLinkImpl[3];
379    
380                            array[0] = getByCompanyId_PrevAndNext(session,
381                                            workflowDefinitionLink, companyId, orderByComparator, true);
382    
383                            array[1] = workflowDefinitionLink;
384    
385                            array[2] = getByCompanyId_PrevAndNext(session,
386                                            workflowDefinitionLink, companyId, orderByComparator, false);
387    
388                            return array;
389                    }
390                    catch (Exception e) {
391                            throw processException(e);
392                    }
393                    finally {
394                            closeSession(session);
395                    }
396            }
397    
398            protected WorkflowDefinitionLink getByCompanyId_PrevAndNext(
399                    Session session, WorkflowDefinitionLink workflowDefinitionLink,
400                    long companyId, OrderByComparator orderByComparator, boolean previous) {
401                    StringBundler query = null;
402    
403                    if (orderByComparator != null) {
404                            query = new StringBundler(6 +
405                                            (orderByComparator.getOrderByFields().length * 6));
406                    }
407                    else {
408                            query = new StringBundler(3);
409                    }
410    
411                    query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE);
412    
413                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
414    
415                    if (orderByComparator != null) {
416                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
417    
418                            if (orderByConditionFields.length > 0) {
419                                    query.append(WHERE_AND);
420                            }
421    
422                            for (int i = 0; i < orderByConditionFields.length; i++) {
423                                    query.append(_ORDER_BY_ENTITY_ALIAS);
424                                    query.append(orderByConditionFields[i]);
425    
426                                    if ((i + 1) < orderByConditionFields.length) {
427                                            if (orderByComparator.isAscending() ^ previous) {
428                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
429                                            }
430                                            else {
431                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
432                                            }
433                                    }
434                                    else {
435                                            if (orderByComparator.isAscending() ^ previous) {
436                                                    query.append(WHERE_GREATER_THAN);
437                                            }
438                                            else {
439                                                    query.append(WHERE_LESSER_THAN);
440                                            }
441                                    }
442                            }
443    
444                            query.append(ORDER_BY_CLAUSE);
445    
446                            String[] orderByFields = orderByComparator.getOrderByFields();
447    
448                            for (int i = 0; i < orderByFields.length; i++) {
449                                    query.append(_ORDER_BY_ENTITY_ALIAS);
450                                    query.append(orderByFields[i]);
451    
452                                    if ((i + 1) < orderByFields.length) {
453                                            if (orderByComparator.isAscending() ^ previous) {
454                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
455                                            }
456                                            else {
457                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
458                                            }
459                                    }
460                                    else {
461                                            if (orderByComparator.isAscending() ^ previous) {
462                                                    query.append(ORDER_BY_ASC);
463                                            }
464                                            else {
465                                                    query.append(ORDER_BY_DESC);
466                                            }
467                                    }
468                            }
469                    }
470                    else {
471                            query.append(WorkflowDefinitionLinkModelImpl.ORDER_BY_JPQL);
472                    }
473    
474                    String sql = query.toString();
475    
476                    Query q = session.createQuery(sql);
477    
478                    q.setFirstResult(0);
479                    q.setMaxResults(2);
480    
481                    QueryPos qPos = QueryPos.getInstance(q);
482    
483                    qPos.add(companyId);
484    
485                    if (orderByComparator != null) {
486                            Object[] values = orderByComparator.getOrderByConditionValues(workflowDefinitionLink);
487    
488                            for (Object value : values) {
489                                    qPos.add(value);
490                            }
491                    }
492    
493                    List<WorkflowDefinitionLink> list = q.list();
494    
495                    if (list.size() == 2) {
496                            return list.get(1);
497                    }
498                    else {
499                            return null;
500                    }
501            }
502    
503            /**
504             * Removes all the workflow definition links where companyId = &#63; from the database.
505             *
506             * @param companyId the company ID
507             * @throws SystemException if a system exception occurred
508             */
509            public void removeByCompanyId(long companyId) throws SystemException {
510                    for (WorkflowDefinitionLink workflowDefinitionLink : findByCompanyId(
511                                    companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
512                            remove(workflowDefinitionLink);
513                    }
514            }
515    
516            /**
517             * Returns the number of workflow definition links where companyId = &#63;.
518             *
519             * @param companyId the company ID
520             * @return the number of matching workflow definition links
521             * @throws SystemException if a system exception occurred
522             */
523            public int countByCompanyId(long companyId) throws SystemException {
524                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
525    
526                    Object[] finderArgs = new Object[] { companyId };
527    
528                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
529                                    this);
530    
531                    if (count == null) {
532                            StringBundler query = new StringBundler(2);
533    
534                            query.append(_SQL_COUNT_WORKFLOWDEFINITIONLINK_WHERE);
535    
536                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
537    
538                            String sql = query.toString();
539    
540                            Session session = null;
541    
542                            try {
543                                    session = openSession();
544    
545                                    Query q = session.createQuery(sql);
546    
547                                    QueryPos qPos = QueryPos.getInstance(q);
548    
549                                    qPos.add(companyId);
550    
551                                    count = (Long)q.uniqueResult();
552    
553                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
554                            }
555                            catch (Exception e) {
556                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
557    
558                                    throw processException(e);
559                            }
560                            finally {
561                                    closeSession(session);
562                            }
563                    }
564    
565                    return count.intValue();
566            }
567    
568            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "workflowDefinitionLink.companyId = ?";
569            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_W_W = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
570                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
571                            WorkflowDefinitionLinkImpl.class,
572                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_W_W",
573                            new String[] {
574                                    Long.class.getName(), String.class.getName(),
575                                    Integer.class.getName(),
576                                    
577                            Integer.class.getName(), Integer.class.getName(),
578                                    OrderByComparator.class.getName()
579                            });
580            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_W_W = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
581                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
582                            WorkflowDefinitionLinkImpl.class,
583                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_W_W",
584                            new String[] {
585                                    Long.class.getName(), String.class.getName(),
586                                    Integer.class.getName()
587                            },
588                            WorkflowDefinitionLinkModelImpl.COMPANYID_COLUMN_BITMASK |
589                            WorkflowDefinitionLinkModelImpl.WORKFLOWDEFINITIONNAME_COLUMN_BITMASK |
590                            WorkflowDefinitionLinkModelImpl.WORKFLOWDEFINITIONVERSION_COLUMN_BITMASK);
591            public static final FinderPath FINDER_PATH_COUNT_BY_C_W_W = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
592                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
593                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_W_W",
594                            new String[] {
595                                    Long.class.getName(), String.class.getName(),
596                                    Integer.class.getName()
597                            });
598    
599            /**
600             * Returns all the workflow definition links where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63;.
601             *
602             * @param companyId the company ID
603             * @param workflowDefinitionName the workflow definition name
604             * @param workflowDefinitionVersion the workflow definition version
605             * @return the matching workflow definition links
606             * @throws SystemException if a system exception occurred
607             */
608            public List<WorkflowDefinitionLink> findByC_W_W(long companyId,
609                    String workflowDefinitionName, int workflowDefinitionVersion)
610                    throws SystemException {
611                    return findByC_W_W(companyId, workflowDefinitionName,
612                            workflowDefinitionVersion, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
613                            null);
614            }
615    
616            /**
617             * Returns a range of all the workflow definition links where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63;.
618             *
619             * <p>
620             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.WorkflowDefinitionLinkModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
621             * </p>
622             *
623             * @param companyId the company ID
624             * @param workflowDefinitionName the workflow definition name
625             * @param workflowDefinitionVersion the workflow definition version
626             * @param start the lower bound of the range of workflow definition links
627             * @param end the upper bound of the range of workflow definition links (not inclusive)
628             * @return the range of matching workflow definition links
629             * @throws SystemException if a system exception occurred
630             */
631            public List<WorkflowDefinitionLink> findByC_W_W(long companyId,
632                    String workflowDefinitionName, int workflowDefinitionVersion,
633                    int start, int end) throws SystemException {
634                    return findByC_W_W(companyId, workflowDefinitionName,
635                            workflowDefinitionVersion, start, end, null);
636            }
637    
638            /**
639             * Returns an ordered range of all the workflow definition links where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63;.
640             *
641             * <p>
642             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.WorkflowDefinitionLinkModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
643             * </p>
644             *
645             * @param companyId the company ID
646             * @param workflowDefinitionName the workflow definition name
647             * @param workflowDefinitionVersion the workflow definition version
648             * @param start the lower bound of the range of workflow definition links
649             * @param end the upper bound of the range of workflow definition links (not inclusive)
650             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
651             * @return the ordered range of matching workflow definition links
652             * @throws SystemException if a system exception occurred
653             */
654            public List<WorkflowDefinitionLink> findByC_W_W(long companyId,
655                    String workflowDefinitionName, int workflowDefinitionVersion,
656                    int start, int end, OrderByComparator orderByComparator)
657                    throws SystemException {
658                    boolean pagination = true;
659                    FinderPath finderPath = null;
660                    Object[] finderArgs = null;
661    
662                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
663                                    (orderByComparator == null)) {
664                            pagination = false;
665                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_W_W;
666                            finderArgs = new Object[] {
667                                            companyId, workflowDefinitionName, workflowDefinitionVersion
668                                    };
669                    }
670                    else {
671                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_W_W;
672                            finderArgs = new Object[] {
673                                            companyId, workflowDefinitionName, workflowDefinitionVersion,
674                                            
675                                            start, end, orderByComparator
676                                    };
677                    }
678    
679                    List<WorkflowDefinitionLink> list = (List<WorkflowDefinitionLink>)FinderCacheUtil.getResult(finderPath,
680                                    finderArgs, this);
681    
682                    if ((list != null) && !list.isEmpty()) {
683                            for (WorkflowDefinitionLink workflowDefinitionLink : list) {
684                                    if ((companyId != workflowDefinitionLink.getCompanyId()) ||
685                                                    !Validator.equals(workflowDefinitionName,
686                                                            workflowDefinitionLink.getWorkflowDefinitionName()) ||
687                                                    (workflowDefinitionVersion != workflowDefinitionLink.getWorkflowDefinitionVersion())) {
688                                            list = null;
689    
690                                            break;
691                                    }
692                            }
693                    }
694    
695                    if (list == null) {
696                            StringBundler query = null;
697    
698                            if (orderByComparator != null) {
699                                    query = new StringBundler(5 +
700                                                    (orderByComparator.getOrderByFields().length * 3));
701                            }
702                            else {
703                                    query = new StringBundler(5);
704                            }
705    
706                            query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE);
707    
708                            query.append(_FINDER_COLUMN_C_W_W_COMPANYID_2);
709    
710                            if (workflowDefinitionName == null) {
711                                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_1);
712                            }
713                            else {
714                                    if (workflowDefinitionName.equals(StringPool.BLANK)) {
715                                            query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_3);
716                                    }
717                                    else {
718                                            query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_2);
719                                    }
720                            }
721    
722                            query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONVERSION_2);
723    
724                            if (orderByComparator != null) {
725                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
726                                            orderByComparator);
727                            }
728                            else
729                             if (pagination) {
730                                    query.append(WorkflowDefinitionLinkModelImpl.ORDER_BY_JPQL);
731                            }
732    
733                            String sql = query.toString();
734    
735                            Session session = null;
736    
737                            try {
738                                    session = openSession();
739    
740                                    Query q = session.createQuery(sql);
741    
742                                    QueryPos qPos = QueryPos.getInstance(q);
743    
744                                    qPos.add(companyId);
745    
746                                    if (workflowDefinitionName != null) {
747                                            qPos.add(workflowDefinitionName);
748                                    }
749    
750                                    qPos.add(workflowDefinitionVersion);
751    
752                                    if (!pagination) {
753                                            list = (List<WorkflowDefinitionLink>)QueryUtil.list(q,
754                                                            getDialect(), start, end, false);
755    
756                                            Collections.sort(list);
757    
758                                            list = new UnmodifiableList<WorkflowDefinitionLink>(list);
759                                    }
760                                    else {
761                                            list = (List<WorkflowDefinitionLink>)QueryUtil.list(q,
762                                                            getDialect(), start, end);
763                                    }
764    
765                                    cacheResult(list);
766    
767                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
768                            }
769                            catch (Exception e) {
770                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
771    
772                                    throw processException(e);
773                            }
774                            finally {
775                                    closeSession(session);
776                            }
777                    }
778    
779                    return list;
780            }
781    
782            /**
783             * Returns the first workflow definition link in the ordered set where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63;.
784             *
785             * @param companyId the company ID
786             * @param workflowDefinitionName the workflow definition name
787             * @param workflowDefinitionVersion the workflow definition version
788             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
789             * @return the first matching workflow definition link
790             * @throws com.liferay.portal.NoSuchWorkflowDefinitionLinkException if a matching workflow definition link could not be found
791             * @throws SystemException if a system exception occurred
792             */
793            public WorkflowDefinitionLink findByC_W_W_First(long companyId,
794                    String workflowDefinitionName, int workflowDefinitionVersion,
795                    OrderByComparator orderByComparator)
796                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
797                    WorkflowDefinitionLink workflowDefinitionLink = fetchByC_W_W_First(companyId,
798                                    workflowDefinitionName, workflowDefinitionVersion,
799                                    orderByComparator);
800    
801                    if (workflowDefinitionLink != null) {
802                            return workflowDefinitionLink;
803                    }
804    
805                    StringBundler msg = new StringBundler(8);
806    
807                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
808    
809                    msg.append("companyId=");
810                    msg.append(companyId);
811    
812                    msg.append(", workflowDefinitionName=");
813                    msg.append(workflowDefinitionName);
814    
815                    msg.append(", workflowDefinitionVersion=");
816                    msg.append(workflowDefinitionVersion);
817    
818                    msg.append(StringPool.CLOSE_CURLY_BRACE);
819    
820                    throw new NoSuchWorkflowDefinitionLinkException(msg.toString());
821            }
822    
823            /**
824             * Returns the first workflow definition link in the ordered set where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63;.
825             *
826             * @param companyId the company ID
827             * @param workflowDefinitionName the workflow definition name
828             * @param workflowDefinitionVersion the workflow definition version
829             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
830             * @return the first matching workflow definition link, or <code>null</code> if a matching workflow definition link could not be found
831             * @throws SystemException if a system exception occurred
832             */
833            public WorkflowDefinitionLink fetchByC_W_W_First(long companyId,
834                    String workflowDefinitionName, int workflowDefinitionVersion,
835                    OrderByComparator orderByComparator) throws SystemException {
836                    List<WorkflowDefinitionLink> list = findByC_W_W(companyId,
837                                    workflowDefinitionName, workflowDefinitionVersion, 0, 1,
838                                    orderByComparator);
839    
840                    if (!list.isEmpty()) {
841                            return list.get(0);
842                    }
843    
844                    return null;
845            }
846    
847            /**
848             * Returns the last workflow definition link in the ordered set where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63;.
849             *
850             * @param companyId the company ID
851             * @param workflowDefinitionName the workflow definition name
852             * @param workflowDefinitionVersion the workflow definition version
853             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
854             * @return the last matching workflow definition link
855             * @throws com.liferay.portal.NoSuchWorkflowDefinitionLinkException if a matching workflow definition link could not be found
856             * @throws SystemException if a system exception occurred
857             */
858            public WorkflowDefinitionLink findByC_W_W_Last(long companyId,
859                    String workflowDefinitionName, int workflowDefinitionVersion,
860                    OrderByComparator orderByComparator)
861                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
862                    WorkflowDefinitionLink workflowDefinitionLink = fetchByC_W_W_Last(companyId,
863                                    workflowDefinitionName, workflowDefinitionVersion,
864                                    orderByComparator);
865    
866                    if (workflowDefinitionLink != null) {
867                            return workflowDefinitionLink;
868                    }
869    
870                    StringBundler msg = new StringBundler(8);
871    
872                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
873    
874                    msg.append("companyId=");
875                    msg.append(companyId);
876    
877                    msg.append(", workflowDefinitionName=");
878                    msg.append(workflowDefinitionName);
879    
880                    msg.append(", workflowDefinitionVersion=");
881                    msg.append(workflowDefinitionVersion);
882    
883                    msg.append(StringPool.CLOSE_CURLY_BRACE);
884    
885                    throw new NoSuchWorkflowDefinitionLinkException(msg.toString());
886            }
887    
888            /**
889             * Returns the last workflow definition link in the ordered set where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63;.
890             *
891             * @param companyId the company ID
892             * @param workflowDefinitionName the workflow definition name
893             * @param workflowDefinitionVersion the workflow definition version
894             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
895             * @return the last matching workflow definition link, or <code>null</code> if a matching workflow definition link could not be found
896             * @throws SystemException if a system exception occurred
897             */
898            public WorkflowDefinitionLink fetchByC_W_W_Last(long companyId,
899                    String workflowDefinitionName, int workflowDefinitionVersion,
900                    OrderByComparator orderByComparator) throws SystemException {
901                    int count = countByC_W_W(companyId, workflowDefinitionName,
902                                    workflowDefinitionVersion);
903    
904                    List<WorkflowDefinitionLink> list = findByC_W_W(companyId,
905                                    workflowDefinitionName, workflowDefinitionVersion, count - 1,
906                                    count, orderByComparator);
907    
908                    if (!list.isEmpty()) {
909                            return list.get(0);
910                    }
911    
912                    return null;
913            }
914    
915            /**
916             * Returns the workflow definition links before and after the current workflow definition link in the ordered set where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63;.
917             *
918             * @param workflowDefinitionLinkId the primary key of the current workflow definition link
919             * @param companyId the company ID
920             * @param workflowDefinitionName the workflow definition name
921             * @param workflowDefinitionVersion the workflow definition version
922             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
923             * @return the previous, current, and next workflow definition link
924             * @throws com.liferay.portal.NoSuchWorkflowDefinitionLinkException if a workflow definition link with the primary key could not be found
925             * @throws SystemException if a system exception occurred
926             */
927            public WorkflowDefinitionLink[] findByC_W_W_PrevAndNext(
928                    long workflowDefinitionLinkId, long companyId,
929                    String workflowDefinitionName, int workflowDefinitionVersion,
930                    OrderByComparator orderByComparator)
931                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
932                    WorkflowDefinitionLink workflowDefinitionLink = findByPrimaryKey(workflowDefinitionLinkId);
933    
934                    Session session = null;
935    
936                    try {
937                            session = openSession();
938    
939                            WorkflowDefinitionLink[] array = new WorkflowDefinitionLinkImpl[3];
940    
941                            array[0] = getByC_W_W_PrevAndNext(session, workflowDefinitionLink,
942                                            companyId, workflowDefinitionName,
943                                            workflowDefinitionVersion, orderByComparator, true);
944    
945                            array[1] = workflowDefinitionLink;
946    
947                            array[2] = getByC_W_W_PrevAndNext(session, workflowDefinitionLink,
948                                            companyId, workflowDefinitionName,
949                                            workflowDefinitionVersion, orderByComparator, false);
950    
951                            return array;
952                    }
953                    catch (Exception e) {
954                            throw processException(e);
955                    }
956                    finally {
957                            closeSession(session);
958                    }
959            }
960    
961            protected WorkflowDefinitionLink getByC_W_W_PrevAndNext(Session session,
962                    WorkflowDefinitionLink workflowDefinitionLink, long companyId,
963                    String workflowDefinitionName, int workflowDefinitionVersion,
964                    OrderByComparator orderByComparator, boolean previous) {
965                    StringBundler query = null;
966    
967                    if (orderByComparator != null) {
968                            query = new StringBundler(6 +
969                                            (orderByComparator.getOrderByFields().length * 6));
970                    }
971                    else {
972                            query = new StringBundler(3);
973                    }
974    
975                    query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE);
976    
977                    query.append(_FINDER_COLUMN_C_W_W_COMPANYID_2);
978    
979                    if (workflowDefinitionName == null) {
980                            query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_1);
981                    }
982                    else {
983                            if (workflowDefinitionName.equals(StringPool.BLANK)) {
984                                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_3);
985                            }
986                            else {
987                                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_2);
988                            }
989                    }
990    
991                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONVERSION_2);
992    
993                    if (orderByComparator != null) {
994                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
995    
996                            if (orderByConditionFields.length > 0) {
997                                    query.append(WHERE_AND);
998                            }
999    
1000                            for (int i = 0; i < orderByConditionFields.length; i++) {
1001                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1002                                    query.append(orderByConditionFields[i]);
1003    
1004                                    if ((i + 1) < orderByConditionFields.length) {
1005                                            if (orderByComparator.isAscending() ^ previous) {
1006                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1007                                            }
1008                                            else {
1009                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1010                                            }
1011                                    }
1012                                    else {
1013                                            if (orderByComparator.isAscending() ^ previous) {
1014                                                    query.append(WHERE_GREATER_THAN);
1015                                            }
1016                                            else {
1017                                                    query.append(WHERE_LESSER_THAN);
1018                                            }
1019                                    }
1020                            }
1021    
1022                            query.append(ORDER_BY_CLAUSE);
1023    
1024                            String[] orderByFields = orderByComparator.getOrderByFields();
1025    
1026                            for (int i = 0; i < orderByFields.length; i++) {
1027                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1028                                    query.append(orderByFields[i]);
1029    
1030                                    if ((i + 1) < orderByFields.length) {
1031                                            if (orderByComparator.isAscending() ^ previous) {
1032                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1033                                            }
1034                                            else {
1035                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1036                                            }
1037                                    }
1038                                    else {
1039                                            if (orderByComparator.isAscending() ^ previous) {
1040                                                    query.append(ORDER_BY_ASC);
1041                                            }
1042                                            else {
1043                                                    query.append(ORDER_BY_DESC);
1044                                            }
1045                                    }
1046                            }
1047                    }
1048                    else {
1049                            query.append(WorkflowDefinitionLinkModelImpl.ORDER_BY_JPQL);
1050                    }
1051    
1052                    String sql = query.toString();
1053    
1054                    Query q = session.createQuery(sql);
1055    
1056                    q.setFirstResult(0);
1057                    q.setMaxResults(2);
1058    
1059                    QueryPos qPos = QueryPos.getInstance(q);
1060    
1061                    qPos.add(companyId);
1062    
1063                    if (workflowDefinitionName != null) {
1064                            qPos.add(workflowDefinitionName);
1065                    }
1066    
1067                    qPos.add(workflowDefinitionVersion);
1068    
1069                    if (orderByComparator != null) {
1070                            Object[] values = orderByComparator.getOrderByConditionValues(workflowDefinitionLink);
1071    
1072                            for (Object value : values) {
1073                                    qPos.add(value);
1074                            }
1075                    }
1076    
1077                    List<WorkflowDefinitionLink> list = q.list();
1078    
1079                    if (list.size() == 2) {
1080                            return list.get(1);
1081                    }
1082                    else {
1083                            return null;
1084                    }
1085            }
1086    
1087            /**
1088             * Removes all the workflow definition links where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63; from the database.
1089             *
1090             * @param companyId the company ID
1091             * @param workflowDefinitionName the workflow definition name
1092             * @param workflowDefinitionVersion the workflow definition version
1093             * @throws SystemException if a system exception occurred
1094             */
1095            public void removeByC_W_W(long companyId, String workflowDefinitionName,
1096                    int workflowDefinitionVersion) throws SystemException {
1097                    for (WorkflowDefinitionLink workflowDefinitionLink : findByC_W_W(
1098                                    companyId, workflowDefinitionName, workflowDefinitionVersion,
1099                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1100                            remove(workflowDefinitionLink);
1101                    }
1102            }
1103    
1104            /**
1105             * Returns the number of workflow definition links where companyId = &#63; and workflowDefinitionName = &#63; and workflowDefinitionVersion = &#63;.
1106             *
1107             * @param companyId the company ID
1108             * @param workflowDefinitionName the workflow definition name
1109             * @param workflowDefinitionVersion the workflow definition version
1110             * @return the number of matching workflow definition links
1111             * @throws SystemException if a system exception occurred
1112             */
1113            public int countByC_W_W(long companyId, String workflowDefinitionName,
1114                    int workflowDefinitionVersion) throws SystemException {
1115                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_W_W;
1116    
1117                    Object[] finderArgs = new Object[] {
1118                                    companyId, workflowDefinitionName, workflowDefinitionVersion
1119                            };
1120    
1121                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1122                                    this);
1123    
1124                    if (count == null) {
1125                            StringBundler query = new StringBundler(4);
1126    
1127                            query.append(_SQL_COUNT_WORKFLOWDEFINITIONLINK_WHERE);
1128    
1129                            query.append(_FINDER_COLUMN_C_W_W_COMPANYID_2);
1130    
1131                            if (workflowDefinitionName == null) {
1132                                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_1);
1133                            }
1134                            else {
1135                                    if (workflowDefinitionName.equals(StringPool.BLANK)) {
1136                                            query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_3);
1137                                    }
1138                                    else {
1139                                            query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_2);
1140                                    }
1141                            }
1142    
1143                            query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONVERSION_2);
1144    
1145                            String sql = query.toString();
1146    
1147                            Session session = null;
1148    
1149                            try {
1150                                    session = openSession();
1151    
1152                                    Query q = session.createQuery(sql);
1153    
1154                                    QueryPos qPos = QueryPos.getInstance(q);
1155    
1156                                    qPos.add(companyId);
1157    
1158                                    if (workflowDefinitionName != null) {
1159                                            qPos.add(workflowDefinitionName);
1160                                    }
1161    
1162                                    qPos.add(workflowDefinitionVersion);
1163    
1164                                    count = (Long)q.uniqueResult();
1165    
1166                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1167                            }
1168                            catch (Exception e) {
1169                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1170    
1171                                    throw processException(e);
1172                            }
1173                            finally {
1174                                    closeSession(session);
1175                            }
1176                    }
1177    
1178                    return count.intValue();
1179            }
1180    
1181            private static final String _FINDER_COLUMN_C_W_W_COMPANYID_2 = "workflowDefinitionLink.companyId = ? AND ";
1182            private static final String _FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_1 = "workflowDefinitionLink.workflowDefinitionName IS NULL AND ";
1183            private static final String _FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_2 = "workflowDefinitionLink.workflowDefinitionName = ? AND ";
1184            private static final String _FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_3 = "(workflowDefinitionLink.workflowDefinitionName IS NULL OR workflowDefinitionLink.workflowDefinitionName = ?) AND ";
1185            private static final String _FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONVERSION_2 =
1186                    "workflowDefinitionLink.workflowDefinitionVersion = ?";
1187            public static final FinderPath FINDER_PATH_FETCH_BY_G_C_C_C_T = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
1188                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
1189                            WorkflowDefinitionLinkImpl.class, FINDER_CLASS_NAME_ENTITY,
1190                            "fetchByG_C_C_C_T",
1191                            new String[] {
1192                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
1193                                    Long.class.getName(), Long.class.getName()
1194                            },
1195                            WorkflowDefinitionLinkModelImpl.GROUPID_COLUMN_BITMASK |
1196                            WorkflowDefinitionLinkModelImpl.COMPANYID_COLUMN_BITMASK |
1197                            WorkflowDefinitionLinkModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1198                            WorkflowDefinitionLinkModelImpl.CLASSPK_COLUMN_BITMASK |
1199                            WorkflowDefinitionLinkModelImpl.TYPEPK_COLUMN_BITMASK);
1200            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_C_C_T = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
1201                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
1202                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_C_C_T",
1203                            new String[] {
1204                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
1205                                    Long.class.getName(), Long.class.getName()
1206                            });
1207    
1208            /**
1209             * Returns the workflow definition link where groupId = &#63; and companyId = &#63; and classNameId = &#63; and classPK = &#63; and typePK = &#63; or throws a {@link com.liferay.portal.NoSuchWorkflowDefinitionLinkException} if it could not be found.
1210             *
1211             * @param groupId the group ID
1212             * @param companyId the company ID
1213             * @param classNameId the class name ID
1214             * @param classPK the class p k
1215             * @param typePK the type p k
1216             * @return the matching workflow definition link
1217             * @throws com.liferay.portal.NoSuchWorkflowDefinitionLinkException if a matching workflow definition link could not be found
1218             * @throws SystemException if a system exception occurred
1219             */
1220            public WorkflowDefinitionLink findByG_C_C_C_T(long groupId, long companyId,
1221                    long classNameId, long classPK, long typePK)
1222                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
1223                    WorkflowDefinitionLink workflowDefinitionLink = fetchByG_C_C_C_T(groupId,
1224                                    companyId, classNameId, classPK, typePK);
1225    
1226                    if (workflowDefinitionLink == null) {
1227                            StringBundler msg = new StringBundler(12);
1228    
1229                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1230    
1231                            msg.append("groupId=");
1232                            msg.append(groupId);
1233    
1234                            msg.append(", companyId=");
1235                            msg.append(companyId);
1236    
1237                            msg.append(", classNameId=");
1238                            msg.append(classNameId);
1239    
1240                            msg.append(", classPK=");
1241                            msg.append(classPK);
1242    
1243                            msg.append(", typePK=");
1244                            msg.append(typePK);
1245    
1246                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1247    
1248                            if (_log.isWarnEnabled()) {
1249                                    _log.warn(msg.toString());
1250                            }
1251    
1252                            throw new NoSuchWorkflowDefinitionLinkException(msg.toString());
1253                    }
1254    
1255                    return workflowDefinitionLink;
1256            }
1257    
1258            /**
1259             * Returns the workflow definition link where groupId = &#63; and companyId = &#63; and classNameId = &#63; and classPK = &#63; and typePK = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1260             *
1261             * @param groupId the group ID
1262             * @param companyId the company ID
1263             * @param classNameId the class name ID
1264             * @param classPK the class p k
1265             * @param typePK the type p k
1266             * @return the matching workflow definition link, or <code>null</code> if a matching workflow definition link could not be found
1267             * @throws SystemException if a system exception occurred
1268             */
1269            public WorkflowDefinitionLink fetchByG_C_C_C_T(long groupId,
1270                    long companyId, long classNameId, long classPK, long typePK)
1271                    throws SystemException {
1272                    return fetchByG_C_C_C_T(groupId, companyId, classNameId, classPK,
1273                            typePK, true);
1274            }
1275    
1276            /**
1277             * Returns the workflow definition link where groupId = &#63; and companyId = &#63; and classNameId = &#63; and classPK = &#63; and typePK = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1278             *
1279             * @param groupId the group ID
1280             * @param companyId the company ID
1281             * @param classNameId the class name ID
1282             * @param classPK the class p k
1283             * @param typePK the type p k
1284             * @param retrieveFromCache whether to use the finder cache
1285             * @return the matching workflow definition link, or <code>null</code> if a matching workflow definition link could not be found
1286             * @throws SystemException if a system exception occurred
1287             */
1288            public WorkflowDefinitionLink fetchByG_C_C_C_T(long groupId,
1289                    long companyId, long classNameId, long classPK, long typePK,
1290                    boolean retrieveFromCache) throws SystemException {
1291                    Object[] finderArgs = new Object[] {
1292                                    groupId, companyId, classNameId, classPK, typePK
1293                            };
1294    
1295                    Object result = null;
1296    
1297                    if (retrieveFromCache) {
1298                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_C_C_C_T,
1299                                            finderArgs, this);
1300                    }
1301    
1302                    if (result instanceof WorkflowDefinitionLink) {
1303                            WorkflowDefinitionLink workflowDefinitionLink = (WorkflowDefinitionLink)result;
1304    
1305                            if ((groupId != workflowDefinitionLink.getGroupId()) ||
1306                                            (companyId != workflowDefinitionLink.getCompanyId()) ||
1307                                            (classNameId != workflowDefinitionLink.getClassNameId()) ||
1308                                            (classPK != workflowDefinitionLink.getClassPK()) ||
1309                                            (typePK != workflowDefinitionLink.getTypePK())) {
1310                                    result = null;
1311                            }
1312                    }
1313    
1314                    if (result == null) {
1315                            StringBundler query = new StringBundler(7);
1316    
1317                            query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE);
1318    
1319                            query.append(_FINDER_COLUMN_G_C_C_C_T_GROUPID_2);
1320    
1321                            query.append(_FINDER_COLUMN_G_C_C_C_T_COMPANYID_2);
1322    
1323                            query.append(_FINDER_COLUMN_G_C_C_C_T_CLASSNAMEID_2);
1324    
1325                            query.append(_FINDER_COLUMN_G_C_C_C_T_CLASSPK_2);
1326    
1327                            query.append(_FINDER_COLUMN_G_C_C_C_T_TYPEPK_2);
1328    
1329                            String sql = query.toString();
1330    
1331                            Session session = null;
1332    
1333                            try {
1334                                    session = openSession();
1335    
1336                                    Query q = session.createQuery(sql);
1337    
1338                                    QueryPos qPos = QueryPos.getInstance(q);
1339    
1340                                    qPos.add(groupId);
1341    
1342                                    qPos.add(companyId);
1343    
1344                                    qPos.add(classNameId);
1345    
1346                                    qPos.add(classPK);
1347    
1348                                    qPos.add(typePK);
1349    
1350                                    List<WorkflowDefinitionLink> list = q.list();
1351    
1352                                    if (list.isEmpty()) {
1353                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C_C_T,
1354                                                    finderArgs, list);
1355                                    }
1356                                    else {
1357                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
1358                                                    _log.warn(
1359                                                            "WorkflowDefinitionLinkPersistenceImpl.fetchByG_C_C_C_T(long, long, long, long, long, boolean) with parameters (" +
1360                                                            StringUtil.merge(finderArgs) +
1361                                                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
1362                                            }
1363    
1364                                            WorkflowDefinitionLink workflowDefinitionLink = list.get(0);
1365    
1366                                            result = workflowDefinitionLink;
1367    
1368                                            cacheResult(workflowDefinitionLink);
1369    
1370                                            if ((workflowDefinitionLink.getGroupId() != groupId) ||
1371                                                            (workflowDefinitionLink.getCompanyId() != companyId) ||
1372                                                            (workflowDefinitionLink.getClassNameId() != classNameId) ||
1373                                                            (workflowDefinitionLink.getClassPK() != classPK) ||
1374                                                            (workflowDefinitionLink.getTypePK() != typePK)) {
1375                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C_C_T,
1376                                                            finderArgs, workflowDefinitionLink);
1377                                            }
1378                                    }
1379                            }
1380                            catch (Exception e) {
1381                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_C_C_T,
1382                                            finderArgs);
1383    
1384                                    throw processException(e);
1385                            }
1386                            finally {
1387                                    closeSession(session);
1388                            }
1389                    }
1390    
1391                    if (result instanceof List<?>) {
1392                            return null;
1393                    }
1394                    else {
1395                            return (WorkflowDefinitionLink)result;
1396                    }
1397            }
1398    
1399            /**
1400             * Removes the workflow definition link where groupId = &#63; and companyId = &#63; and classNameId = &#63; and classPK = &#63; and typePK = &#63; from the database.
1401             *
1402             * @param groupId the group ID
1403             * @param companyId the company ID
1404             * @param classNameId the class name ID
1405             * @param classPK the class p k
1406             * @param typePK the type p k
1407             * @return the workflow definition link that was removed
1408             * @throws SystemException if a system exception occurred
1409             */
1410            public WorkflowDefinitionLink removeByG_C_C_C_T(long groupId,
1411                    long companyId, long classNameId, long classPK, long typePK)
1412                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
1413                    WorkflowDefinitionLink workflowDefinitionLink = findByG_C_C_C_T(groupId,
1414                                    companyId, classNameId, classPK, typePK);
1415    
1416                    return remove(workflowDefinitionLink);
1417            }
1418    
1419            /**
1420             * Returns the number of workflow definition links where groupId = &#63; and companyId = &#63; and classNameId = &#63; and classPK = &#63; and typePK = &#63;.
1421             *
1422             * @param groupId the group ID
1423             * @param companyId the company ID
1424             * @param classNameId the class name ID
1425             * @param classPK the class p k
1426             * @param typePK the type p k
1427             * @return the number of matching workflow definition links
1428             * @throws SystemException if a system exception occurred
1429             */
1430            public int countByG_C_C_C_T(long groupId, long companyId, long classNameId,
1431                    long classPK, long typePK) throws SystemException {
1432                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_C_C_T;
1433    
1434                    Object[] finderArgs = new Object[] {
1435                                    groupId, companyId, classNameId, classPK, typePK
1436                            };
1437    
1438                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1439                                    this);
1440    
1441                    if (count == null) {
1442                            StringBundler query = new StringBundler(6);
1443    
1444                            query.append(_SQL_COUNT_WORKFLOWDEFINITIONLINK_WHERE);
1445    
1446                            query.append(_FINDER_COLUMN_G_C_C_C_T_GROUPID_2);
1447    
1448                            query.append(_FINDER_COLUMN_G_C_C_C_T_COMPANYID_2);
1449    
1450                            query.append(_FINDER_COLUMN_G_C_C_C_T_CLASSNAMEID_2);
1451    
1452                            query.append(_FINDER_COLUMN_G_C_C_C_T_CLASSPK_2);
1453    
1454                            query.append(_FINDER_COLUMN_G_C_C_C_T_TYPEPK_2);
1455    
1456                            String sql = query.toString();
1457    
1458                            Session session = null;
1459    
1460                            try {
1461                                    session = openSession();
1462    
1463                                    Query q = session.createQuery(sql);
1464    
1465                                    QueryPos qPos = QueryPos.getInstance(q);
1466    
1467                                    qPos.add(groupId);
1468    
1469                                    qPos.add(companyId);
1470    
1471                                    qPos.add(classNameId);
1472    
1473                                    qPos.add(classPK);
1474    
1475                                    qPos.add(typePK);
1476    
1477                                    count = (Long)q.uniqueResult();
1478    
1479                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1480                            }
1481                            catch (Exception e) {
1482                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1483    
1484                                    throw processException(e);
1485                            }
1486                            finally {
1487                                    closeSession(session);
1488                            }
1489                    }
1490    
1491                    return count.intValue();
1492            }
1493    
1494            private static final String _FINDER_COLUMN_G_C_C_C_T_GROUPID_2 = "workflowDefinitionLink.groupId = ? AND ";
1495            private static final String _FINDER_COLUMN_G_C_C_C_T_COMPANYID_2 = "workflowDefinitionLink.companyId = ? AND ";
1496            private static final String _FINDER_COLUMN_G_C_C_C_T_CLASSNAMEID_2 = "workflowDefinitionLink.classNameId = ? AND ";
1497            private static final String _FINDER_COLUMN_G_C_C_C_T_CLASSPK_2 = "workflowDefinitionLink.classPK = ? AND ";
1498            private static final String _FINDER_COLUMN_G_C_C_C_T_TYPEPK_2 = "workflowDefinitionLink.typePK = ?";
1499    
1500            /**
1501             * Caches the workflow definition link in the entity cache if it is enabled.
1502             *
1503             * @param workflowDefinitionLink the workflow definition link
1504             */
1505            public void cacheResult(WorkflowDefinitionLink workflowDefinitionLink) {
1506                    EntityCacheUtil.putResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
1507                            WorkflowDefinitionLinkImpl.class,
1508                            workflowDefinitionLink.getPrimaryKey(), workflowDefinitionLink);
1509    
1510                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C_C_T,
1511                            new Object[] {
1512                                    Long.valueOf(workflowDefinitionLink.getGroupId()),
1513                                    Long.valueOf(workflowDefinitionLink.getCompanyId()),
1514                                    Long.valueOf(workflowDefinitionLink.getClassNameId()),
1515                                    Long.valueOf(workflowDefinitionLink.getClassPK()),
1516                                    Long.valueOf(workflowDefinitionLink.getTypePK())
1517                            }, workflowDefinitionLink);
1518    
1519                    workflowDefinitionLink.resetOriginalValues();
1520            }
1521    
1522            /**
1523             * Caches the workflow definition links in the entity cache if it is enabled.
1524             *
1525             * @param workflowDefinitionLinks the workflow definition links
1526             */
1527            public void cacheResult(
1528                    List<WorkflowDefinitionLink> workflowDefinitionLinks) {
1529                    for (WorkflowDefinitionLink workflowDefinitionLink : workflowDefinitionLinks) {
1530                            if (EntityCacheUtil.getResult(
1531                                                    WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
1532                                                    WorkflowDefinitionLinkImpl.class,
1533                                                    workflowDefinitionLink.getPrimaryKey()) == null) {
1534                                    cacheResult(workflowDefinitionLink);
1535                            }
1536                            else {
1537                                    workflowDefinitionLink.resetOriginalValues();
1538                            }
1539                    }
1540            }
1541    
1542            /**
1543             * Clears the cache for all workflow definition links.
1544             *
1545             * <p>
1546             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1547             * </p>
1548             */
1549            @Override
1550            public void clearCache() {
1551                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1552                            CacheRegistryUtil.clear(WorkflowDefinitionLinkImpl.class.getName());
1553                    }
1554    
1555                    EntityCacheUtil.clearCache(WorkflowDefinitionLinkImpl.class.getName());
1556    
1557                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1558                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1559                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1560            }
1561    
1562            /**
1563             * Clears the cache for the workflow definition link.
1564             *
1565             * <p>
1566             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1567             * </p>
1568             */
1569            @Override
1570            public void clearCache(WorkflowDefinitionLink workflowDefinitionLink) {
1571                    EntityCacheUtil.removeResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
1572                            WorkflowDefinitionLinkImpl.class,
1573                            workflowDefinitionLink.getPrimaryKey());
1574    
1575                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1576                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1577    
1578                    clearUniqueFindersCache(workflowDefinitionLink);
1579            }
1580    
1581            @Override
1582            public void clearCache(List<WorkflowDefinitionLink> workflowDefinitionLinks) {
1583                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1584                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1585    
1586                    for (WorkflowDefinitionLink workflowDefinitionLink : workflowDefinitionLinks) {
1587                            EntityCacheUtil.removeResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
1588                                    WorkflowDefinitionLinkImpl.class,
1589                                    workflowDefinitionLink.getPrimaryKey());
1590    
1591                            clearUniqueFindersCache(workflowDefinitionLink);
1592                    }
1593            }
1594    
1595            protected void cacheUniqueFindersCache(
1596                    WorkflowDefinitionLink workflowDefinitionLink) {
1597                    if (workflowDefinitionLink.isNew()) {
1598                            Object[] args = new Object[] {
1599                                            Long.valueOf(workflowDefinitionLink.getGroupId()),
1600                                            Long.valueOf(workflowDefinitionLink.getCompanyId()),
1601                                            Long.valueOf(workflowDefinitionLink.getClassNameId()),
1602                                            Long.valueOf(workflowDefinitionLink.getClassPK()),
1603                                            Long.valueOf(workflowDefinitionLink.getTypePK())
1604                                    };
1605    
1606                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_C_C_T, args,
1607                                    Long.valueOf(1));
1608                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C_C_T, args,
1609                                    workflowDefinitionLink);
1610                    }
1611                    else {
1612                            WorkflowDefinitionLinkModelImpl workflowDefinitionLinkModelImpl = (WorkflowDefinitionLinkModelImpl)workflowDefinitionLink;
1613    
1614                            if ((workflowDefinitionLinkModelImpl.getColumnBitmask() &
1615                                            FINDER_PATH_FETCH_BY_G_C_C_C_T.getColumnBitmask()) != 0) {
1616                                    Object[] args = new Object[] {
1617                                                    Long.valueOf(workflowDefinitionLink.getGroupId()),
1618                                                    Long.valueOf(workflowDefinitionLink.getCompanyId()),
1619                                                    Long.valueOf(workflowDefinitionLink.getClassNameId()),
1620                                                    Long.valueOf(workflowDefinitionLink.getClassPK()),
1621                                                    Long.valueOf(workflowDefinitionLink.getTypePK())
1622                                            };
1623    
1624                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_C_C_T, args,
1625                                            Long.valueOf(1));
1626                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C_C_T, args,
1627                                            workflowDefinitionLink);
1628                            }
1629                    }
1630            }
1631    
1632            protected void clearUniqueFindersCache(
1633                    WorkflowDefinitionLink workflowDefinitionLink) {
1634                    WorkflowDefinitionLinkModelImpl workflowDefinitionLinkModelImpl = (WorkflowDefinitionLinkModelImpl)workflowDefinitionLink;
1635    
1636                    Object[] args = new Object[] {
1637                                    Long.valueOf(workflowDefinitionLink.getGroupId()),
1638                                    Long.valueOf(workflowDefinitionLink.getCompanyId()),
1639                                    Long.valueOf(workflowDefinitionLink.getClassNameId()),
1640                                    Long.valueOf(workflowDefinitionLink.getClassPK()),
1641                                    Long.valueOf(workflowDefinitionLink.getTypePK())
1642                            };
1643    
1644                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C_C_T, args);
1645                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_C_C_T, args);
1646    
1647                    if ((workflowDefinitionLinkModelImpl.getColumnBitmask() &
1648                                    FINDER_PATH_FETCH_BY_G_C_C_C_T.getColumnBitmask()) != 0) {
1649                            args = new Object[] {
1650                                            Long.valueOf(workflowDefinitionLinkModelImpl.getOriginalGroupId()),
1651                                            Long.valueOf(workflowDefinitionLinkModelImpl.getOriginalCompanyId()),
1652                                            Long.valueOf(workflowDefinitionLinkModelImpl.getOriginalClassNameId()),
1653                                            Long.valueOf(workflowDefinitionLinkModelImpl.getOriginalClassPK()),
1654                                            Long.valueOf(workflowDefinitionLinkModelImpl.getOriginalTypePK())
1655                                    };
1656    
1657                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C_C_T, args);
1658                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_C_C_T, args);
1659                    }
1660            }
1661    
1662            /**
1663             * Creates a new workflow definition link with the primary key. Does not add the workflow definition link to the database.
1664             *
1665             * @param workflowDefinitionLinkId the primary key for the new workflow definition link
1666             * @return the new workflow definition link
1667             */
1668            public WorkflowDefinitionLink create(long workflowDefinitionLinkId) {
1669                    WorkflowDefinitionLink workflowDefinitionLink = new WorkflowDefinitionLinkImpl();
1670    
1671                    workflowDefinitionLink.setNew(true);
1672                    workflowDefinitionLink.setPrimaryKey(workflowDefinitionLinkId);
1673    
1674                    return workflowDefinitionLink;
1675            }
1676    
1677            /**
1678             * Removes the workflow definition link with the primary key from the database. Also notifies the appropriate model listeners.
1679             *
1680             * @param workflowDefinitionLinkId the primary key of the workflow definition link
1681             * @return the workflow definition link that was removed
1682             * @throws com.liferay.portal.NoSuchWorkflowDefinitionLinkException if a workflow definition link with the primary key could not be found
1683             * @throws SystemException if a system exception occurred
1684             */
1685            public WorkflowDefinitionLink remove(long workflowDefinitionLinkId)
1686                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
1687                    return remove(Long.valueOf(workflowDefinitionLinkId));
1688            }
1689    
1690            /**
1691             * Removes the workflow definition link with the primary key from the database. Also notifies the appropriate model listeners.
1692             *
1693             * @param primaryKey the primary key of the workflow definition link
1694             * @return the workflow definition link that was removed
1695             * @throws com.liferay.portal.NoSuchWorkflowDefinitionLinkException if a workflow definition link with the primary key could not be found
1696             * @throws SystemException if a system exception occurred
1697             */
1698            @Override
1699            public WorkflowDefinitionLink remove(Serializable primaryKey)
1700                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
1701                    Session session = null;
1702    
1703                    try {
1704                            session = openSession();
1705    
1706                            WorkflowDefinitionLink workflowDefinitionLink = (WorkflowDefinitionLink)session.get(WorkflowDefinitionLinkImpl.class,
1707                                            primaryKey);
1708    
1709                            if (workflowDefinitionLink == null) {
1710                                    if (_log.isWarnEnabled()) {
1711                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1712                                    }
1713    
1714                                    throw new NoSuchWorkflowDefinitionLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1715                                            primaryKey);
1716                            }
1717    
1718                            return remove(workflowDefinitionLink);
1719                    }
1720                    catch (NoSuchWorkflowDefinitionLinkException nsee) {
1721                            throw nsee;
1722                    }
1723                    catch (Exception e) {
1724                            throw processException(e);
1725                    }
1726                    finally {
1727                            closeSession(session);
1728                    }
1729            }
1730    
1731            @Override
1732            protected WorkflowDefinitionLink removeImpl(
1733                    WorkflowDefinitionLink workflowDefinitionLink)
1734                    throws SystemException {
1735                    workflowDefinitionLink = toUnwrappedModel(workflowDefinitionLink);
1736    
1737                    Session session = null;
1738    
1739                    try {
1740                            session = openSession();
1741    
1742                            if (!session.contains(workflowDefinitionLink)) {
1743                                    workflowDefinitionLink = (WorkflowDefinitionLink)session.get(WorkflowDefinitionLinkImpl.class,
1744                                                    workflowDefinitionLink.getPrimaryKeyObj());
1745                            }
1746    
1747                            if (workflowDefinitionLink != null) {
1748                                    session.delete(workflowDefinitionLink);
1749                            }
1750                    }
1751                    catch (Exception e) {
1752                            throw processException(e);
1753                    }
1754                    finally {
1755                            closeSession(session);
1756                    }
1757    
1758                    if (workflowDefinitionLink != null) {
1759                            clearCache(workflowDefinitionLink);
1760                    }
1761    
1762                    return workflowDefinitionLink;
1763            }
1764    
1765            @Override
1766            public WorkflowDefinitionLink updateImpl(
1767                    com.liferay.portal.model.WorkflowDefinitionLink workflowDefinitionLink)
1768                    throws SystemException {
1769                    workflowDefinitionLink = toUnwrappedModel(workflowDefinitionLink);
1770    
1771                    boolean isNew = workflowDefinitionLink.isNew();
1772    
1773                    WorkflowDefinitionLinkModelImpl workflowDefinitionLinkModelImpl = (WorkflowDefinitionLinkModelImpl)workflowDefinitionLink;
1774    
1775                    Session session = null;
1776    
1777                    try {
1778                            session = openSession();
1779    
1780                            if (workflowDefinitionLink.isNew()) {
1781                                    session.save(workflowDefinitionLink);
1782    
1783                                    workflowDefinitionLink.setNew(false);
1784                            }
1785                            else {
1786                                    session.merge(workflowDefinitionLink);
1787                            }
1788                    }
1789                    catch (Exception e) {
1790                            throw processException(e);
1791                    }
1792                    finally {
1793                            closeSession(session);
1794                    }
1795    
1796                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1797    
1798                    if (isNew || !WorkflowDefinitionLinkModelImpl.COLUMN_BITMASK_ENABLED) {
1799                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1800                    }
1801    
1802                    else {
1803                            if ((workflowDefinitionLinkModelImpl.getColumnBitmask() &
1804                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
1805                                    Object[] args = new Object[] {
1806                                                    Long.valueOf(workflowDefinitionLinkModelImpl.getOriginalCompanyId())
1807                                            };
1808    
1809                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
1810                                            args);
1811                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
1812                                            args);
1813    
1814                                    args = new Object[] {
1815                                                    Long.valueOf(workflowDefinitionLinkModelImpl.getCompanyId())
1816                                            };
1817    
1818                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
1819                                            args);
1820                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
1821                                            args);
1822                            }
1823    
1824                            if ((workflowDefinitionLinkModelImpl.getColumnBitmask() &
1825                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_W_W.getColumnBitmask()) != 0) {
1826                                    Object[] args = new Object[] {
1827                                                    Long.valueOf(workflowDefinitionLinkModelImpl.getOriginalCompanyId()),
1828                                                    
1829                                                    workflowDefinitionLinkModelImpl.getOriginalWorkflowDefinitionName(),
1830                                                    Integer.valueOf(workflowDefinitionLinkModelImpl.getOriginalWorkflowDefinitionVersion())
1831                                            };
1832    
1833                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_W_W, args);
1834                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_W_W,
1835                                            args);
1836    
1837                                    args = new Object[] {
1838                                                    Long.valueOf(workflowDefinitionLinkModelImpl.getCompanyId()),
1839                                                    
1840                                                    workflowDefinitionLinkModelImpl.getWorkflowDefinitionName(),
1841                                                    Integer.valueOf(workflowDefinitionLinkModelImpl.getWorkflowDefinitionVersion())
1842                                            };
1843    
1844                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_W_W, args);
1845                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_W_W,
1846                                            args);
1847                            }
1848                    }
1849    
1850                    EntityCacheUtil.putResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
1851                            WorkflowDefinitionLinkImpl.class,
1852                            workflowDefinitionLink.getPrimaryKey(), workflowDefinitionLink);
1853    
1854                    clearUniqueFindersCache(workflowDefinitionLink);
1855                    cacheUniqueFindersCache(workflowDefinitionLink);
1856    
1857                    return workflowDefinitionLink;
1858            }
1859    
1860            protected WorkflowDefinitionLink toUnwrappedModel(
1861                    WorkflowDefinitionLink workflowDefinitionLink) {
1862                    if (workflowDefinitionLink instanceof WorkflowDefinitionLinkImpl) {
1863                            return workflowDefinitionLink;
1864                    }
1865    
1866                    WorkflowDefinitionLinkImpl workflowDefinitionLinkImpl = new WorkflowDefinitionLinkImpl();
1867    
1868                    workflowDefinitionLinkImpl.setNew(workflowDefinitionLink.isNew());
1869                    workflowDefinitionLinkImpl.setPrimaryKey(workflowDefinitionLink.getPrimaryKey());
1870    
1871                    workflowDefinitionLinkImpl.setWorkflowDefinitionLinkId(workflowDefinitionLink.getWorkflowDefinitionLinkId());
1872                    workflowDefinitionLinkImpl.setGroupId(workflowDefinitionLink.getGroupId());
1873                    workflowDefinitionLinkImpl.setCompanyId(workflowDefinitionLink.getCompanyId());
1874                    workflowDefinitionLinkImpl.setUserId(workflowDefinitionLink.getUserId());
1875                    workflowDefinitionLinkImpl.setUserName(workflowDefinitionLink.getUserName());
1876                    workflowDefinitionLinkImpl.setCreateDate(workflowDefinitionLink.getCreateDate());
1877                    workflowDefinitionLinkImpl.setModifiedDate(workflowDefinitionLink.getModifiedDate());
1878                    workflowDefinitionLinkImpl.setClassNameId(workflowDefinitionLink.getClassNameId());
1879                    workflowDefinitionLinkImpl.setClassPK(workflowDefinitionLink.getClassPK());
1880                    workflowDefinitionLinkImpl.setTypePK(workflowDefinitionLink.getTypePK());
1881                    workflowDefinitionLinkImpl.setWorkflowDefinitionName(workflowDefinitionLink.getWorkflowDefinitionName());
1882                    workflowDefinitionLinkImpl.setWorkflowDefinitionVersion(workflowDefinitionLink.getWorkflowDefinitionVersion());
1883    
1884                    return workflowDefinitionLinkImpl;
1885            }
1886    
1887            /**
1888             * Returns the workflow definition link with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1889             *
1890             * @param primaryKey the primary key of the workflow definition link
1891             * @return the workflow definition link
1892             * @throws com.liferay.portal.NoSuchModelException if a workflow definition link with the primary key could not be found
1893             * @throws SystemException if a system exception occurred
1894             */
1895            @Override
1896            public WorkflowDefinitionLink findByPrimaryKey(Serializable primaryKey)
1897                    throws NoSuchModelException, SystemException {
1898                    return findByPrimaryKey(((Long)primaryKey).longValue());
1899            }
1900    
1901            /**
1902             * Returns the workflow definition link with the primary key or throws a {@link com.liferay.portal.NoSuchWorkflowDefinitionLinkException} if it could not be found.
1903             *
1904             * @param workflowDefinitionLinkId the primary key of the workflow definition link
1905             * @return the workflow definition link
1906             * @throws com.liferay.portal.NoSuchWorkflowDefinitionLinkException if a workflow definition link with the primary key could not be found
1907             * @throws SystemException if a system exception occurred
1908             */
1909            public WorkflowDefinitionLink findByPrimaryKey(
1910                    long workflowDefinitionLinkId)
1911                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
1912                    WorkflowDefinitionLink workflowDefinitionLink = fetchByPrimaryKey(workflowDefinitionLinkId);
1913    
1914                    if (workflowDefinitionLink == null) {
1915                            if (_log.isWarnEnabled()) {
1916                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1917                                            workflowDefinitionLinkId);
1918                            }
1919    
1920                            throw new NoSuchWorkflowDefinitionLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1921                                    workflowDefinitionLinkId);
1922                    }
1923    
1924                    return workflowDefinitionLink;
1925            }
1926    
1927            /**
1928             * Returns the workflow definition link with the primary key or returns <code>null</code> if it could not be found.
1929             *
1930             * @param primaryKey the primary key of the workflow definition link
1931             * @return the workflow definition link, or <code>null</code> if a workflow definition link with the primary key could not be found
1932             * @throws SystemException if a system exception occurred
1933             */
1934            @Override
1935            public WorkflowDefinitionLink fetchByPrimaryKey(Serializable primaryKey)
1936                    throws SystemException {
1937                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
1938            }
1939    
1940            /**
1941             * Returns the workflow definition link with the primary key or returns <code>null</code> if it could not be found.
1942             *
1943             * @param workflowDefinitionLinkId the primary key of the workflow definition link
1944             * @return the workflow definition link, or <code>null</code> if a workflow definition link with the primary key could not be found
1945             * @throws SystemException if a system exception occurred
1946             */
1947            public WorkflowDefinitionLink fetchByPrimaryKey(
1948                    long workflowDefinitionLinkId) throws SystemException {
1949                    WorkflowDefinitionLink workflowDefinitionLink = (WorkflowDefinitionLink)EntityCacheUtil.getResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
1950                                    WorkflowDefinitionLinkImpl.class, workflowDefinitionLinkId);
1951    
1952                    if (workflowDefinitionLink == _nullWorkflowDefinitionLink) {
1953                            return null;
1954                    }
1955    
1956                    if (workflowDefinitionLink == null) {
1957                            Session session = null;
1958    
1959                            try {
1960                                    session = openSession();
1961    
1962                                    workflowDefinitionLink = (WorkflowDefinitionLink)session.get(WorkflowDefinitionLinkImpl.class,
1963                                                    Long.valueOf(workflowDefinitionLinkId));
1964    
1965                                    if (workflowDefinitionLink != null) {
1966                                            cacheResult(workflowDefinitionLink);
1967                                    }
1968                                    else {
1969                                            EntityCacheUtil.putResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
1970                                                    WorkflowDefinitionLinkImpl.class,
1971                                                    workflowDefinitionLinkId, _nullWorkflowDefinitionLink);
1972                                    }
1973                            }
1974                            catch (Exception e) {
1975                                    EntityCacheUtil.removeResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
1976                                            WorkflowDefinitionLinkImpl.class, workflowDefinitionLinkId);
1977    
1978                                    throw processException(e);
1979                            }
1980                            finally {
1981                                    closeSession(session);
1982                            }
1983                    }
1984    
1985                    return workflowDefinitionLink;
1986            }
1987    
1988            /**
1989             * Returns all the workflow definition links.
1990             *
1991             * @return the workflow definition links
1992             * @throws SystemException if a system exception occurred
1993             */
1994            public List<WorkflowDefinitionLink> findAll() throws SystemException {
1995                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1996            }
1997    
1998            /**
1999             * Returns a range of all the workflow definition links.
2000             *
2001             * <p>
2002             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.WorkflowDefinitionLinkModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2003             * </p>
2004             *
2005             * @param start the lower bound of the range of workflow definition links
2006             * @param end the upper bound of the range of workflow definition links (not inclusive)
2007             * @return the range of workflow definition links
2008             * @throws SystemException if a system exception occurred
2009             */
2010            public List<WorkflowDefinitionLink> findAll(int start, int end)
2011                    throws SystemException {
2012                    return findAll(start, end, null);
2013            }
2014    
2015            /**
2016             * Returns an ordered range of all the workflow definition links.
2017             *
2018             * <p>
2019             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.WorkflowDefinitionLinkModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2020             * </p>
2021             *
2022             * @param start the lower bound of the range of workflow definition links
2023             * @param end the upper bound of the range of workflow definition links (not inclusive)
2024             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2025             * @return the ordered range of workflow definition links
2026             * @throws SystemException if a system exception occurred
2027             */
2028            public List<WorkflowDefinitionLink> findAll(int start, int end,
2029                    OrderByComparator orderByComparator) throws SystemException {
2030                    boolean pagination = true;
2031                    FinderPath finderPath = null;
2032                    Object[] finderArgs = null;
2033    
2034                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2035                                    (orderByComparator == null)) {
2036                            pagination = false;
2037                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2038                            finderArgs = FINDER_ARGS_EMPTY;
2039                    }
2040                    else {
2041                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2042                            finderArgs = new Object[] { start, end, orderByComparator };
2043                    }
2044    
2045                    List<WorkflowDefinitionLink> list = (List<WorkflowDefinitionLink>)FinderCacheUtil.getResult(finderPath,
2046                                    finderArgs, this);
2047    
2048                    if (list == null) {
2049                            StringBundler query = null;
2050                            String sql = null;
2051    
2052                            if (orderByComparator != null) {
2053                                    query = new StringBundler(2 +
2054                                                    (orderByComparator.getOrderByFields().length * 3));
2055    
2056                                    query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK);
2057    
2058                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2059                                            orderByComparator);
2060    
2061                                    sql = query.toString();
2062                            }
2063                            else {
2064                                    sql = _SQL_SELECT_WORKFLOWDEFINITIONLINK;
2065    
2066                                    if (pagination) {
2067                                            sql = sql.concat(WorkflowDefinitionLinkModelImpl.ORDER_BY_JPQL);
2068                                    }
2069                            }
2070    
2071                            Session session = null;
2072    
2073                            try {
2074                                    session = openSession();
2075    
2076                                    Query q = session.createQuery(sql);
2077    
2078                                    if (!pagination) {
2079                                            list = (List<WorkflowDefinitionLink>)QueryUtil.list(q,
2080                                                            getDialect(), start, end, false);
2081    
2082                                            Collections.sort(list);
2083    
2084                                            list = new UnmodifiableList<WorkflowDefinitionLink>(list);
2085                                    }
2086                                    else {
2087                                            list = (List<WorkflowDefinitionLink>)QueryUtil.list(q,
2088                                                            getDialect(), start, end);
2089                                    }
2090    
2091                                    cacheResult(list);
2092    
2093                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2094                            }
2095                            catch (Exception e) {
2096                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2097    
2098                                    throw processException(e);
2099                            }
2100                            finally {
2101                                    closeSession(session);
2102                            }
2103                    }
2104    
2105                    return list;
2106            }
2107    
2108            /**
2109             * Removes all the workflow definition links from the database.
2110             *
2111             * @throws SystemException if a system exception occurred
2112             */
2113            public void removeAll() throws SystemException {
2114                    for (WorkflowDefinitionLink workflowDefinitionLink : findAll()) {
2115                            remove(workflowDefinitionLink);
2116                    }
2117            }
2118    
2119            /**
2120             * Returns the number of workflow definition links.
2121             *
2122             * @return the number of workflow definition links
2123             * @throws SystemException if a system exception occurred
2124             */
2125            public int countAll() throws SystemException {
2126                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2127                                    FINDER_ARGS_EMPTY, this);
2128    
2129                    if (count == null) {
2130                            Session session = null;
2131    
2132                            try {
2133                                    session = openSession();
2134    
2135                                    Query q = session.createQuery(_SQL_COUNT_WORKFLOWDEFINITIONLINK);
2136    
2137                                    count = (Long)q.uniqueResult();
2138    
2139                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2140                                            FINDER_ARGS_EMPTY, count);
2141                            }
2142                            catch (Exception e) {
2143                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2144                                            FINDER_ARGS_EMPTY);
2145    
2146                                    throw processException(e);
2147                            }
2148                            finally {
2149                                    closeSession(session);
2150                            }
2151                    }
2152    
2153                    return count.intValue();
2154            }
2155    
2156            /**
2157             * Initializes the workflow definition link persistence.
2158             */
2159            public void afterPropertiesSet() {
2160                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2161                                            com.liferay.portal.util.PropsUtil.get(
2162                                                    "value.object.listener.com.liferay.portal.model.WorkflowDefinitionLink")));
2163    
2164                    if (listenerClassNames.length > 0) {
2165                            try {
2166                                    List<ModelListener<WorkflowDefinitionLink>> listenersList = new ArrayList<ModelListener<WorkflowDefinitionLink>>();
2167    
2168                                    for (String listenerClassName : listenerClassNames) {
2169                                            listenersList.add((ModelListener<WorkflowDefinitionLink>)InstanceFactory.newInstance(
2170                                                            listenerClassName));
2171                                    }
2172    
2173                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2174                            }
2175                            catch (Exception e) {
2176                                    _log.error(e);
2177                            }
2178                    }
2179            }
2180    
2181            public void destroy() {
2182                    EntityCacheUtil.removeCache(WorkflowDefinitionLinkImpl.class.getName());
2183                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2184                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2185                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2186            }
2187    
2188            private static final String _SQL_SELECT_WORKFLOWDEFINITIONLINK = "SELECT workflowDefinitionLink FROM WorkflowDefinitionLink workflowDefinitionLink";
2189            private static final String _SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE = "SELECT workflowDefinitionLink FROM WorkflowDefinitionLink workflowDefinitionLink WHERE ";
2190            private static final String _SQL_COUNT_WORKFLOWDEFINITIONLINK = "SELECT COUNT(workflowDefinitionLink) FROM WorkflowDefinitionLink workflowDefinitionLink";
2191            private static final String _SQL_COUNT_WORKFLOWDEFINITIONLINK_WHERE = "SELECT COUNT(workflowDefinitionLink) FROM WorkflowDefinitionLink workflowDefinitionLink WHERE ";
2192            private static final String _ORDER_BY_ENTITY_ALIAS = "workflowDefinitionLink.";
2193            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WorkflowDefinitionLink exists with the primary key ";
2194            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WorkflowDefinitionLink exists with the key {";
2195            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2196            private static Log _log = LogFactoryUtil.getLog(WorkflowDefinitionLinkPersistenceImpl.class);
2197            private static WorkflowDefinitionLink _nullWorkflowDefinitionLink = new WorkflowDefinitionLinkImpl() {
2198                            @Override
2199                            public Object clone() {
2200                                    return this;
2201                            }
2202    
2203                            @Override
2204                            public CacheModel<WorkflowDefinitionLink> toCacheModel() {
2205                                    return _nullWorkflowDefinitionLinkCacheModel;
2206                            }
2207                    };
2208    
2209            private static CacheModel<WorkflowDefinitionLink> _nullWorkflowDefinitionLinkCacheModel =
2210                    new CacheModel<WorkflowDefinitionLink>() {
2211                            public WorkflowDefinitionLink toEntityModel() {
2212                                    return _nullWorkflowDefinitionLink;
2213                            }
2214                    };
2215    }