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