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            public WorkflowDefinitionLinkPersistenceImpl() {
1539                    setModelClass(WorkflowDefinitionLink.class);
1540            }
1541    
1542            /**
1543             * Caches the workflow definition link in the entity cache if it is enabled.
1544             *
1545             * @param workflowDefinitionLink the workflow definition link
1546             */
1547            @Override
1548            public void cacheResult(WorkflowDefinitionLink workflowDefinitionLink) {
1549                    EntityCacheUtil.putResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
1550                            WorkflowDefinitionLinkImpl.class,
1551                            workflowDefinitionLink.getPrimaryKey(), workflowDefinitionLink);
1552    
1553                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C_C_T,
1554                            new Object[] {
1555                                    workflowDefinitionLink.getGroupId(),
1556                                    workflowDefinitionLink.getCompanyId(),
1557                                    workflowDefinitionLink.getClassNameId(),
1558                                    workflowDefinitionLink.getClassPK(),
1559                                    workflowDefinitionLink.getTypePK()
1560                            }, workflowDefinitionLink);
1561    
1562                    workflowDefinitionLink.resetOriginalValues();
1563            }
1564    
1565            /**
1566             * Caches the workflow definition links in the entity cache if it is enabled.
1567             *
1568             * @param workflowDefinitionLinks the workflow definition links
1569             */
1570            @Override
1571            public void cacheResult(
1572                    List<WorkflowDefinitionLink> workflowDefinitionLinks) {
1573                    for (WorkflowDefinitionLink workflowDefinitionLink : workflowDefinitionLinks) {
1574                            if (EntityCacheUtil.getResult(
1575                                                    WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
1576                                                    WorkflowDefinitionLinkImpl.class,
1577                                                    workflowDefinitionLink.getPrimaryKey()) == null) {
1578                                    cacheResult(workflowDefinitionLink);
1579                            }
1580                            else {
1581                                    workflowDefinitionLink.resetOriginalValues();
1582                            }
1583                    }
1584            }
1585    
1586            /**
1587             * Clears the cache for all workflow definition links.
1588             *
1589             * <p>
1590             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1591             * </p>
1592             */
1593            @Override
1594            public void clearCache() {
1595                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1596                            CacheRegistryUtil.clear(WorkflowDefinitionLinkImpl.class.getName());
1597                    }
1598    
1599                    EntityCacheUtil.clearCache(WorkflowDefinitionLinkImpl.class.getName());
1600    
1601                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1602                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1603                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1604            }
1605    
1606            /**
1607             * Clears the cache for the workflow definition link.
1608             *
1609             * <p>
1610             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1611             * </p>
1612             */
1613            @Override
1614            public void clearCache(WorkflowDefinitionLink workflowDefinitionLink) {
1615                    EntityCacheUtil.removeResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
1616                            WorkflowDefinitionLinkImpl.class,
1617                            workflowDefinitionLink.getPrimaryKey());
1618    
1619                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1620                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1621    
1622                    clearUniqueFindersCache(workflowDefinitionLink);
1623            }
1624    
1625            @Override
1626            public void clearCache(List<WorkflowDefinitionLink> workflowDefinitionLinks) {
1627                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1628                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1629    
1630                    for (WorkflowDefinitionLink workflowDefinitionLink : workflowDefinitionLinks) {
1631                            EntityCacheUtil.removeResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
1632                                    WorkflowDefinitionLinkImpl.class,
1633                                    workflowDefinitionLink.getPrimaryKey());
1634    
1635                            clearUniqueFindersCache(workflowDefinitionLink);
1636                    }
1637            }
1638    
1639            protected void cacheUniqueFindersCache(
1640                    WorkflowDefinitionLink workflowDefinitionLink) {
1641                    if (workflowDefinitionLink.isNew()) {
1642                            Object[] args = new Object[] {
1643                                            workflowDefinitionLink.getGroupId(),
1644                                            workflowDefinitionLink.getCompanyId(),
1645                                            workflowDefinitionLink.getClassNameId(),
1646                                            workflowDefinitionLink.getClassPK(),
1647                                            workflowDefinitionLink.getTypePK()
1648                                    };
1649    
1650                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_C_C_T, args,
1651                                    Long.valueOf(1));
1652                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C_C_T, args,
1653                                    workflowDefinitionLink);
1654                    }
1655                    else {
1656                            WorkflowDefinitionLinkModelImpl workflowDefinitionLinkModelImpl = (WorkflowDefinitionLinkModelImpl)workflowDefinitionLink;
1657    
1658                            if ((workflowDefinitionLinkModelImpl.getColumnBitmask() &
1659                                            FINDER_PATH_FETCH_BY_G_C_C_C_T.getColumnBitmask()) != 0) {
1660                                    Object[] args = new Object[] {
1661                                                    workflowDefinitionLink.getGroupId(),
1662                                                    workflowDefinitionLink.getCompanyId(),
1663                                                    workflowDefinitionLink.getClassNameId(),
1664                                                    workflowDefinitionLink.getClassPK(),
1665                                                    workflowDefinitionLink.getTypePK()
1666                                            };
1667    
1668                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_C_C_T, args,
1669                                            Long.valueOf(1));
1670                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C_C_T, args,
1671                                            workflowDefinitionLink);
1672                            }
1673                    }
1674            }
1675    
1676            protected void clearUniqueFindersCache(
1677                    WorkflowDefinitionLink workflowDefinitionLink) {
1678                    WorkflowDefinitionLinkModelImpl workflowDefinitionLinkModelImpl = (WorkflowDefinitionLinkModelImpl)workflowDefinitionLink;
1679    
1680                    Object[] args = new Object[] {
1681                                    workflowDefinitionLink.getGroupId(),
1682                                    workflowDefinitionLink.getCompanyId(),
1683                                    workflowDefinitionLink.getClassNameId(),
1684                                    workflowDefinitionLink.getClassPK(),
1685                                    workflowDefinitionLink.getTypePK()
1686                            };
1687    
1688                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C_C_T, args);
1689                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_C_C_T, args);
1690    
1691                    if ((workflowDefinitionLinkModelImpl.getColumnBitmask() &
1692                                    FINDER_PATH_FETCH_BY_G_C_C_C_T.getColumnBitmask()) != 0) {
1693                            args = new Object[] {
1694                                            workflowDefinitionLinkModelImpl.getOriginalGroupId(),
1695                                            workflowDefinitionLinkModelImpl.getOriginalCompanyId(),
1696                                            workflowDefinitionLinkModelImpl.getOriginalClassNameId(),
1697                                            workflowDefinitionLinkModelImpl.getOriginalClassPK(),
1698                                            workflowDefinitionLinkModelImpl.getOriginalTypePK()
1699                                    };
1700    
1701                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C_C_T, args);
1702                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_C_C_T, args);
1703                    }
1704            }
1705    
1706            /**
1707             * Creates a new workflow definition link with the primary key. Does not add the workflow definition link to the database.
1708             *
1709             * @param workflowDefinitionLinkId the primary key for the new workflow definition link
1710             * @return the new workflow definition link
1711             */
1712            @Override
1713            public WorkflowDefinitionLink create(long workflowDefinitionLinkId) {
1714                    WorkflowDefinitionLink workflowDefinitionLink = new WorkflowDefinitionLinkImpl();
1715    
1716                    workflowDefinitionLink.setNew(true);
1717                    workflowDefinitionLink.setPrimaryKey(workflowDefinitionLinkId);
1718    
1719                    return workflowDefinitionLink;
1720            }
1721    
1722            /**
1723             * Removes the workflow definition link with the primary key from the database. Also notifies the appropriate model listeners.
1724             *
1725             * @param workflowDefinitionLinkId the primary key of the workflow definition link
1726             * @return the workflow definition link that was removed
1727             * @throws com.liferay.portal.NoSuchWorkflowDefinitionLinkException if a workflow definition link with the primary key could not be found
1728             * @throws SystemException if a system exception occurred
1729             */
1730            @Override
1731            public WorkflowDefinitionLink remove(long workflowDefinitionLinkId)
1732                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
1733                    return remove((Serializable)workflowDefinitionLinkId);
1734            }
1735    
1736            /**
1737             * Removes the workflow definition link with the primary key from the database. Also notifies the appropriate model listeners.
1738             *
1739             * @param primaryKey the primary key of the workflow definition link
1740             * @return the workflow definition link that was removed
1741             * @throws com.liferay.portal.NoSuchWorkflowDefinitionLinkException if a workflow definition link with the primary key could not be found
1742             * @throws SystemException if a system exception occurred
1743             */
1744            @Override
1745            public WorkflowDefinitionLink remove(Serializable primaryKey)
1746                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
1747                    Session session = null;
1748    
1749                    try {
1750                            session = openSession();
1751    
1752                            WorkflowDefinitionLink workflowDefinitionLink = (WorkflowDefinitionLink)session.get(WorkflowDefinitionLinkImpl.class,
1753                                            primaryKey);
1754    
1755                            if (workflowDefinitionLink == null) {
1756                                    if (_log.isWarnEnabled()) {
1757                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1758                                    }
1759    
1760                                    throw new NoSuchWorkflowDefinitionLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1761                                            primaryKey);
1762                            }
1763    
1764                            return remove(workflowDefinitionLink);
1765                    }
1766                    catch (NoSuchWorkflowDefinitionLinkException nsee) {
1767                            throw nsee;
1768                    }
1769                    catch (Exception e) {
1770                            throw processException(e);
1771                    }
1772                    finally {
1773                            closeSession(session);
1774                    }
1775            }
1776    
1777            @Override
1778            protected WorkflowDefinitionLink removeImpl(
1779                    WorkflowDefinitionLink workflowDefinitionLink)
1780                    throws SystemException {
1781                    workflowDefinitionLink = toUnwrappedModel(workflowDefinitionLink);
1782    
1783                    Session session = null;
1784    
1785                    try {
1786                            session = openSession();
1787    
1788                            if (!session.contains(workflowDefinitionLink)) {
1789                                    workflowDefinitionLink = (WorkflowDefinitionLink)session.get(WorkflowDefinitionLinkImpl.class,
1790                                                    workflowDefinitionLink.getPrimaryKeyObj());
1791                            }
1792    
1793                            if (workflowDefinitionLink != null) {
1794                                    session.delete(workflowDefinitionLink);
1795                            }
1796                    }
1797                    catch (Exception e) {
1798                            throw processException(e);
1799                    }
1800                    finally {
1801                            closeSession(session);
1802                    }
1803    
1804                    if (workflowDefinitionLink != null) {
1805                            clearCache(workflowDefinitionLink);
1806                    }
1807    
1808                    return workflowDefinitionLink;
1809            }
1810    
1811            @Override
1812            public WorkflowDefinitionLink updateImpl(
1813                    com.liferay.portal.model.WorkflowDefinitionLink workflowDefinitionLink)
1814                    throws SystemException {
1815                    workflowDefinitionLink = toUnwrappedModel(workflowDefinitionLink);
1816    
1817                    boolean isNew = workflowDefinitionLink.isNew();
1818    
1819                    WorkflowDefinitionLinkModelImpl workflowDefinitionLinkModelImpl = (WorkflowDefinitionLinkModelImpl)workflowDefinitionLink;
1820    
1821                    Session session = null;
1822    
1823                    try {
1824                            session = openSession();
1825    
1826                            if (workflowDefinitionLink.isNew()) {
1827                                    session.save(workflowDefinitionLink);
1828    
1829                                    workflowDefinitionLink.setNew(false);
1830                            }
1831                            else {
1832                                    session.merge(workflowDefinitionLink);
1833                            }
1834                    }
1835                    catch (Exception e) {
1836                            throw processException(e);
1837                    }
1838                    finally {
1839                            closeSession(session);
1840                    }
1841    
1842                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1843    
1844                    if (isNew || !WorkflowDefinitionLinkModelImpl.COLUMN_BITMASK_ENABLED) {
1845                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1846                    }
1847    
1848                    else {
1849                            if ((workflowDefinitionLinkModelImpl.getColumnBitmask() &
1850                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
1851                                    Object[] args = new Object[] {
1852                                                    workflowDefinitionLinkModelImpl.getOriginalCompanyId()
1853                                            };
1854    
1855                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
1856                                            args);
1857                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
1858                                            args);
1859    
1860                                    args = new Object[] {
1861                                                    workflowDefinitionLinkModelImpl.getCompanyId()
1862                                            };
1863    
1864                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
1865                                            args);
1866                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
1867                                            args);
1868                            }
1869    
1870                            if ((workflowDefinitionLinkModelImpl.getColumnBitmask() &
1871                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_W_W.getColumnBitmask()) != 0) {
1872                                    Object[] args = new Object[] {
1873                                                    workflowDefinitionLinkModelImpl.getOriginalCompanyId(),
1874                                                    workflowDefinitionLinkModelImpl.getOriginalWorkflowDefinitionName(),
1875                                                    workflowDefinitionLinkModelImpl.getOriginalWorkflowDefinitionVersion()
1876                                            };
1877    
1878                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_W_W, args);
1879                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_W_W,
1880                                            args);
1881    
1882                                    args = new Object[] {
1883                                                    workflowDefinitionLinkModelImpl.getCompanyId(),
1884                                                    workflowDefinitionLinkModelImpl.getWorkflowDefinitionName(),
1885                                                    workflowDefinitionLinkModelImpl.getWorkflowDefinitionVersion()
1886                                            };
1887    
1888                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_W_W, args);
1889                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_W_W,
1890                                            args);
1891                            }
1892                    }
1893    
1894                    EntityCacheUtil.putResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
1895                            WorkflowDefinitionLinkImpl.class,
1896                            workflowDefinitionLink.getPrimaryKey(), workflowDefinitionLink);
1897    
1898                    clearUniqueFindersCache(workflowDefinitionLink);
1899                    cacheUniqueFindersCache(workflowDefinitionLink);
1900    
1901                    return workflowDefinitionLink;
1902            }
1903    
1904            protected WorkflowDefinitionLink toUnwrappedModel(
1905                    WorkflowDefinitionLink workflowDefinitionLink) {
1906                    if (workflowDefinitionLink instanceof WorkflowDefinitionLinkImpl) {
1907                            return workflowDefinitionLink;
1908                    }
1909    
1910                    WorkflowDefinitionLinkImpl workflowDefinitionLinkImpl = new WorkflowDefinitionLinkImpl();
1911    
1912                    workflowDefinitionLinkImpl.setNew(workflowDefinitionLink.isNew());
1913                    workflowDefinitionLinkImpl.setPrimaryKey(workflowDefinitionLink.getPrimaryKey());
1914    
1915                    workflowDefinitionLinkImpl.setWorkflowDefinitionLinkId(workflowDefinitionLink.getWorkflowDefinitionLinkId());
1916                    workflowDefinitionLinkImpl.setGroupId(workflowDefinitionLink.getGroupId());
1917                    workflowDefinitionLinkImpl.setCompanyId(workflowDefinitionLink.getCompanyId());
1918                    workflowDefinitionLinkImpl.setUserId(workflowDefinitionLink.getUserId());
1919                    workflowDefinitionLinkImpl.setUserName(workflowDefinitionLink.getUserName());
1920                    workflowDefinitionLinkImpl.setCreateDate(workflowDefinitionLink.getCreateDate());
1921                    workflowDefinitionLinkImpl.setModifiedDate(workflowDefinitionLink.getModifiedDate());
1922                    workflowDefinitionLinkImpl.setClassNameId(workflowDefinitionLink.getClassNameId());
1923                    workflowDefinitionLinkImpl.setClassPK(workflowDefinitionLink.getClassPK());
1924                    workflowDefinitionLinkImpl.setTypePK(workflowDefinitionLink.getTypePK());
1925                    workflowDefinitionLinkImpl.setWorkflowDefinitionName(workflowDefinitionLink.getWorkflowDefinitionName());
1926                    workflowDefinitionLinkImpl.setWorkflowDefinitionVersion(workflowDefinitionLink.getWorkflowDefinitionVersion());
1927    
1928                    return workflowDefinitionLinkImpl;
1929            }
1930    
1931            /**
1932             * Returns the workflow definition link with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1933             *
1934             * @param primaryKey the primary key of the workflow definition link
1935             * @return the workflow definition link
1936             * @throws com.liferay.portal.NoSuchWorkflowDefinitionLinkException if a workflow definition link with the primary key could not be found
1937             * @throws SystemException if a system exception occurred
1938             */
1939            @Override
1940            public WorkflowDefinitionLink findByPrimaryKey(Serializable primaryKey)
1941                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
1942                    WorkflowDefinitionLink workflowDefinitionLink = fetchByPrimaryKey(primaryKey);
1943    
1944                    if (workflowDefinitionLink == null) {
1945                            if (_log.isWarnEnabled()) {
1946                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1947                            }
1948    
1949                            throw new NoSuchWorkflowDefinitionLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1950                                    primaryKey);
1951                    }
1952    
1953                    return workflowDefinitionLink;
1954            }
1955    
1956            /**
1957             * Returns the workflow definition link with the primary key or throws a {@link com.liferay.portal.NoSuchWorkflowDefinitionLinkException} if it could not be found.
1958             *
1959             * @param workflowDefinitionLinkId the primary key of the workflow definition link
1960             * @return the workflow definition link
1961             * @throws com.liferay.portal.NoSuchWorkflowDefinitionLinkException if a workflow definition link with the primary key could not be found
1962             * @throws SystemException if a system exception occurred
1963             */
1964            @Override
1965            public WorkflowDefinitionLink findByPrimaryKey(
1966                    long workflowDefinitionLinkId)
1967                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
1968                    return findByPrimaryKey((Serializable)workflowDefinitionLinkId);
1969            }
1970    
1971            /**
1972             * Returns the workflow definition link with the primary key or returns <code>null</code> if it could not be found.
1973             *
1974             * @param primaryKey the primary key of the workflow definition link
1975             * @return the workflow definition link, or <code>null</code> if a workflow definition link with the primary key could not be found
1976             * @throws SystemException if a system exception occurred
1977             */
1978            @Override
1979            public WorkflowDefinitionLink fetchByPrimaryKey(Serializable primaryKey)
1980                    throws SystemException {
1981                    WorkflowDefinitionLink workflowDefinitionLink = (WorkflowDefinitionLink)EntityCacheUtil.getResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
1982                                    WorkflowDefinitionLinkImpl.class, primaryKey);
1983    
1984                    if (workflowDefinitionLink == _nullWorkflowDefinitionLink) {
1985                            return null;
1986                    }
1987    
1988                    if (workflowDefinitionLink == null) {
1989                            Session session = null;
1990    
1991                            try {
1992                                    session = openSession();
1993    
1994                                    workflowDefinitionLink = (WorkflowDefinitionLink)session.get(WorkflowDefinitionLinkImpl.class,
1995                                                    primaryKey);
1996    
1997                                    if (workflowDefinitionLink != null) {
1998                                            cacheResult(workflowDefinitionLink);
1999                                    }
2000                                    else {
2001                                            EntityCacheUtil.putResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
2002                                                    WorkflowDefinitionLinkImpl.class, primaryKey,
2003                                                    _nullWorkflowDefinitionLink);
2004                                    }
2005                            }
2006                            catch (Exception e) {
2007                                    EntityCacheUtil.removeResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
2008                                            WorkflowDefinitionLinkImpl.class, primaryKey);
2009    
2010                                    throw processException(e);
2011                            }
2012                            finally {
2013                                    closeSession(session);
2014                            }
2015                    }
2016    
2017                    return workflowDefinitionLink;
2018            }
2019    
2020            /**
2021             * Returns the workflow definition link with the primary key or returns <code>null</code> if it could not be found.
2022             *
2023             * @param workflowDefinitionLinkId the primary key of the workflow definition link
2024             * @return the workflow definition link, or <code>null</code> if a workflow definition link with the primary key could not be found
2025             * @throws SystemException if a system exception occurred
2026             */
2027            @Override
2028            public WorkflowDefinitionLink fetchByPrimaryKey(
2029                    long workflowDefinitionLinkId) throws SystemException {
2030                    return fetchByPrimaryKey((Serializable)workflowDefinitionLinkId);
2031            }
2032    
2033            /**
2034             * Returns all the workflow definition links.
2035             *
2036             * @return the workflow definition links
2037             * @throws SystemException if a system exception occurred
2038             */
2039            @Override
2040            public List<WorkflowDefinitionLink> findAll() throws SystemException {
2041                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2042            }
2043    
2044            /**
2045             * Returns a range of all the workflow definition links.
2046             *
2047             * <p>
2048             * 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.
2049             * </p>
2050             *
2051             * @param start the lower bound of the range of workflow definition links
2052             * @param end the upper bound of the range of workflow definition links (not inclusive)
2053             * @return the range of workflow definition links
2054             * @throws SystemException if a system exception occurred
2055             */
2056            @Override
2057            public List<WorkflowDefinitionLink> findAll(int start, int end)
2058                    throws SystemException {
2059                    return findAll(start, end, null);
2060            }
2061    
2062            /**
2063             * Returns an ordered range of all the workflow definition links.
2064             *
2065             * <p>
2066             * 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.
2067             * </p>
2068             *
2069             * @param start the lower bound of the range of workflow definition links
2070             * @param end the upper bound of the range of workflow definition links (not inclusive)
2071             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2072             * @return the ordered range of workflow definition links
2073             * @throws SystemException if a system exception occurred
2074             */
2075            @Override
2076            public List<WorkflowDefinitionLink> findAll(int start, int end,
2077                    OrderByComparator orderByComparator) throws SystemException {
2078                    boolean pagination = true;
2079                    FinderPath finderPath = null;
2080                    Object[] finderArgs = null;
2081    
2082                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2083                                    (orderByComparator == null)) {
2084                            pagination = false;
2085                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2086                            finderArgs = FINDER_ARGS_EMPTY;
2087                    }
2088                    else {
2089                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2090                            finderArgs = new Object[] { start, end, orderByComparator };
2091                    }
2092    
2093                    List<WorkflowDefinitionLink> list = (List<WorkflowDefinitionLink>)FinderCacheUtil.getResult(finderPath,
2094                                    finderArgs, this);
2095    
2096                    if (list == null) {
2097                            StringBundler query = null;
2098                            String sql = null;
2099    
2100                            if (orderByComparator != null) {
2101                                    query = new StringBundler(2 +
2102                                                    (orderByComparator.getOrderByFields().length * 3));
2103    
2104                                    query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK);
2105    
2106                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2107                                            orderByComparator);
2108    
2109                                    sql = query.toString();
2110                            }
2111                            else {
2112                                    sql = _SQL_SELECT_WORKFLOWDEFINITIONLINK;
2113    
2114                                    if (pagination) {
2115                                            sql = sql.concat(WorkflowDefinitionLinkModelImpl.ORDER_BY_JPQL);
2116                                    }
2117                            }
2118    
2119                            Session session = null;
2120    
2121                            try {
2122                                    session = openSession();
2123    
2124                                    Query q = session.createQuery(sql);
2125    
2126                                    if (!pagination) {
2127                                            list = (List<WorkflowDefinitionLink>)QueryUtil.list(q,
2128                                                            getDialect(), start, end, false);
2129    
2130                                            Collections.sort(list);
2131    
2132                                            list = new UnmodifiableList<WorkflowDefinitionLink>(list);
2133                                    }
2134                                    else {
2135                                            list = (List<WorkflowDefinitionLink>)QueryUtil.list(q,
2136                                                            getDialect(), start, end);
2137                                    }
2138    
2139                                    cacheResult(list);
2140    
2141                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2142                            }
2143                            catch (Exception e) {
2144                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2145    
2146                                    throw processException(e);
2147                            }
2148                            finally {
2149                                    closeSession(session);
2150                            }
2151                    }
2152    
2153                    return list;
2154            }
2155    
2156            /**
2157             * Removes all the workflow definition links from the database.
2158             *
2159             * @throws SystemException if a system exception occurred
2160             */
2161            @Override
2162            public void removeAll() throws SystemException {
2163                    for (WorkflowDefinitionLink workflowDefinitionLink : findAll()) {
2164                            remove(workflowDefinitionLink);
2165                    }
2166            }
2167    
2168            /**
2169             * Returns the number of workflow definition links.
2170             *
2171             * @return the number of workflow definition links
2172             * @throws SystemException if a system exception occurred
2173             */
2174            @Override
2175            public int countAll() throws SystemException {
2176                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2177                                    FINDER_ARGS_EMPTY, this);
2178    
2179                    if (count == null) {
2180                            Session session = null;
2181    
2182                            try {
2183                                    session = openSession();
2184    
2185                                    Query q = session.createQuery(_SQL_COUNT_WORKFLOWDEFINITIONLINK);
2186    
2187                                    count = (Long)q.uniqueResult();
2188    
2189                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2190                                            FINDER_ARGS_EMPTY, count);
2191                            }
2192                            catch (Exception e) {
2193                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2194                                            FINDER_ARGS_EMPTY);
2195    
2196                                    throw processException(e);
2197                            }
2198                            finally {
2199                                    closeSession(session);
2200                            }
2201                    }
2202    
2203                    return count.intValue();
2204            }
2205    
2206            /**
2207             * Initializes the workflow definition link persistence.
2208             */
2209            public void afterPropertiesSet() {
2210                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2211                                            com.liferay.portal.util.PropsUtil.get(
2212                                                    "value.object.listener.com.liferay.portal.model.WorkflowDefinitionLink")));
2213    
2214                    if (listenerClassNames.length > 0) {
2215                            try {
2216                                    List<ModelListener<WorkflowDefinitionLink>> listenersList = new ArrayList<ModelListener<WorkflowDefinitionLink>>();
2217    
2218                                    for (String listenerClassName : listenerClassNames) {
2219                                            listenersList.add((ModelListener<WorkflowDefinitionLink>)InstanceFactory.newInstance(
2220                                                            getClassLoader(), listenerClassName));
2221                                    }
2222    
2223                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2224                            }
2225                            catch (Exception e) {
2226                                    _log.error(e);
2227                            }
2228                    }
2229            }
2230    
2231            public void destroy() {
2232                    EntityCacheUtil.removeCache(WorkflowDefinitionLinkImpl.class.getName());
2233                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2234                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2235                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2236            }
2237    
2238            private static final String _SQL_SELECT_WORKFLOWDEFINITIONLINK = "SELECT workflowDefinitionLink FROM WorkflowDefinitionLink workflowDefinitionLink";
2239            private static final String _SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE = "SELECT workflowDefinitionLink FROM WorkflowDefinitionLink workflowDefinitionLink WHERE ";
2240            private static final String _SQL_COUNT_WORKFLOWDEFINITIONLINK = "SELECT COUNT(workflowDefinitionLink) FROM WorkflowDefinitionLink workflowDefinitionLink";
2241            private static final String _SQL_COUNT_WORKFLOWDEFINITIONLINK_WHERE = "SELECT COUNT(workflowDefinitionLink) FROM WorkflowDefinitionLink workflowDefinitionLink WHERE ";
2242            private static final String _ORDER_BY_ENTITY_ALIAS = "workflowDefinitionLink.";
2243            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WorkflowDefinitionLink exists with the primary key ";
2244            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WorkflowDefinitionLink exists with the key {";
2245            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2246            private static Log _log = LogFactoryUtil.getLog(WorkflowDefinitionLinkPersistenceImpl.class);
2247            private static WorkflowDefinitionLink _nullWorkflowDefinitionLink = new WorkflowDefinitionLinkImpl() {
2248                            @Override
2249                            public Object clone() {
2250                                    return this;
2251                            }
2252    
2253                            @Override
2254                            public CacheModel<WorkflowDefinitionLink> toCacheModel() {
2255                                    return _nullWorkflowDefinitionLinkCacheModel;
2256                            }
2257                    };
2258    
2259            private static CacheModel<WorkflowDefinitionLink> _nullWorkflowDefinitionLinkCacheModel =
2260                    new CacheModel<WorkflowDefinitionLink>() {
2261                            @Override
2262                            public WorkflowDefinitionLink toEntityModel() {
2263                                    return _nullWorkflowDefinitionLink;
2264                            }
2265                    };
2266    }