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