001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.NoSuchWorkflowDefinitionLinkException;
019    import com.liferay.portal.kernel.annotation.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.model.ModelListener;
038    import com.liferay.portal.model.WorkflowDefinitionLink;
039    import com.liferay.portal.model.impl.WorkflowDefinitionLinkImpl;
040    import com.liferay.portal.model.impl.WorkflowDefinitionLinkModelImpl;
041    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042    
043    import java.io.Serializable;
044    
045    import java.util.ArrayList;
046    import java.util.Collections;
047    import java.util.List;
048    
049    /**
050     * @author    Brian Wing Shun Chan
051     * @see       WorkflowDefinitionLinkPersistence
052     * @see       WorkflowDefinitionLinkUtil
053     * @generated
054     */
055    public class WorkflowDefinitionLinkPersistenceImpl extends BasePersistenceImpl<WorkflowDefinitionLink>
056            implements WorkflowDefinitionLinkPersistence {
057            public static final String FINDER_CLASS_NAME_ENTITY = WorkflowDefinitionLinkImpl.class.getName();
058            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
059                    ".List";
060            public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
061                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
062                            FINDER_CLASS_NAME_LIST, "findByCompanyId",
063                            new String[] {
064                                    Long.class.getName(),
065                                    
066                            "java.lang.Integer", "java.lang.Integer",
067                                    "com.liferay.portal.kernel.util.OrderByComparator"
068                            });
069            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
070                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
071                            FINDER_CLASS_NAME_LIST, "countByCompanyId",
072                            new String[] { Long.class.getName() });
073            public static final FinderPath FINDER_PATH_FETCH_BY_G_C_C = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
074                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
075                            FINDER_CLASS_NAME_ENTITY, "fetchByG_C_C",
076                            new String[] {
077                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
078                            });
079            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_C = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
080                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
081                            FINDER_CLASS_NAME_LIST, "countByG_C_C",
082                            new String[] {
083                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
084                            });
085            public static final FinderPath FINDER_PATH_FIND_BY_C_W_W = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
086                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
087                            FINDER_CLASS_NAME_LIST, "findByC_W_W",
088                            new String[] {
089                                    Long.class.getName(), String.class.getName(),
090                                    Integer.class.getName(),
091                                    
092                            "java.lang.Integer", "java.lang.Integer",
093                                    "com.liferay.portal.kernel.util.OrderByComparator"
094                            });
095            public static final FinderPath FINDER_PATH_COUNT_BY_C_W_W = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
096                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
097                            FINDER_CLASS_NAME_LIST, "countByC_W_W",
098                            new String[] {
099                                    Long.class.getName(), String.class.getName(),
100                                    Integer.class.getName()
101                            });
102            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
103                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
104                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
105            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
106                            WorkflowDefinitionLinkModelImpl.FINDER_CACHE_ENABLED,
107                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
108    
109            public void cacheResult(WorkflowDefinitionLink workflowDefinitionLink) {
110                    EntityCacheUtil.putResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
111                            WorkflowDefinitionLinkImpl.class,
112                            workflowDefinitionLink.getPrimaryKey(), workflowDefinitionLink);
113    
114                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C,
115                            new Object[] {
116                                    new Long(workflowDefinitionLink.getGroupId()),
117                                    new Long(workflowDefinitionLink.getCompanyId()),
118                                    new Long(workflowDefinitionLink.getClassNameId())
119                            }, workflowDefinitionLink);
120            }
121    
122            public void cacheResult(
123                    List<WorkflowDefinitionLink> workflowDefinitionLinks) {
124                    for (WorkflowDefinitionLink workflowDefinitionLink : workflowDefinitionLinks) {
125                            if (EntityCacheUtil.getResult(
126                                                    WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
127                                                    WorkflowDefinitionLinkImpl.class,
128                                                    workflowDefinitionLink.getPrimaryKey(), this) == null) {
129                                    cacheResult(workflowDefinitionLink);
130                            }
131                    }
132            }
133    
134            public void clearCache() {
135                    CacheRegistryUtil.clear(WorkflowDefinitionLinkImpl.class.getName());
136                    EntityCacheUtil.clearCache(WorkflowDefinitionLinkImpl.class.getName());
137                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
138                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
139            }
140    
141            public void clearCache(WorkflowDefinitionLink workflowDefinitionLink) {
142                    EntityCacheUtil.removeResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
143                            WorkflowDefinitionLinkImpl.class,
144                            workflowDefinitionLink.getPrimaryKey());
145    
146                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_C,
147                            new Object[] {
148                                    new Long(workflowDefinitionLink.getGroupId()),
149                                    new Long(workflowDefinitionLink.getCompanyId()),
150                                    new Long(workflowDefinitionLink.getClassNameId())
151                            });
152            }
153    
154            public WorkflowDefinitionLink create(long workflowDefinitionLinkId) {
155                    WorkflowDefinitionLink workflowDefinitionLink = new WorkflowDefinitionLinkImpl();
156    
157                    workflowDefinitionLink.setNew(true);
158                    workflowDefinitionLink.setPrimaryKey(workflowDefinitionLinkId);
159    
160                    return workflowDefinitionLink;
161            }
162    
163            public WorkflowDefinitionLink remove(Serializable primaryKey)
164                    throws NoSuchModelException, SystemException {
165                    return remove(((Long)primaryKey).longValue());
166            }
167    
168            public WorkflowDefinitionLink remove(long workflowDefinitionLinkId)
169                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
170                    Session session = null;
171    
172                    try {
173                            session = openSession();
174    
175                            WorkflowDefinitionLink workflowDefinitionLink = (WorkflowDefinitionLink)session.get(WorkflowDefinitionLinkImpl.class,
176                                            new Long(workflowDefinitionLinkId));
177    
178                            if (workflowDefinitionLink == null) {
179                                    if (_log.isWarnEnabled()) {
180                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
181                                                    workflowDefinitionLinkId);
182                                    }
183    
184                                    throw new NoSuchWorkflowDefinitionLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
185                                            workflowDefinitionLinkId);
186                            }
187    
188                            return remove(workflowDefinitionLink);
189                    }
190                    catch (NoSuchWorkflowDefinitionLinkException nsee) {
191                            throw nsee;
192                    }
193                    catch (Exception e) {
194                            throw processException(e);
195                    }
196                    finally {
197                            closeSession(session);
198                    }
199            }
200    
201            protected WorkflowDefinitionLink removeImpl(
202                    WorkflowDefinitionLink workflowDefinitionLink)
203                    throws SystemException {
204                    workflowDefinitionLink = toUnwrappedModel(workflowDefinitionLink);
205    
206                    Session session = null;
207    
208                    try {
209                            session = openSession();
210    
211                            if (workflowDefinitionLink.isCachedModel() ||
212                                            BatchSessionUtil.isEnabled()) {
213                                    Object staleObject = session.get(WorkflowDefinitionLinkImpl.class,
214                                                    workflowDefinitionLink.getPrimaryKeyObj());
215    
216                                    if (staleObject != null) {
217                                            session.evict(staleObject);
218                                    }
219                            }
220    
221                            session.delete(workflowDefinitionLink);
222    
223                            session.flush();
224                    }
225                    catch (Exception e) {
226                            throw processException(e);
227                    }
228                    finally {
229                            closeSession(session);
230                    }
231    
232                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
233    
234                    WorkflowDefinitionLinkModelImpl workflowDefinitionLinkModelImpl = (WorkflowDefinitionLinkModelImpl)workflowDefinitionLink;
235    
236                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_C,
237                            new Object[] {
238                                    new Long(workflowDefinitionLinkModelImpl.getOriginalGroupId()),
239                                    new Long(workflowDefinitionLinkModelImpl.getOriginalCompanyId()),
240                                    new Long(workflowDefinitionLinkModelImpl.getOriginalClassNameId())
241                            });
242    
243                    EntityCacheUtil.removeResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
244                            WorkflowDefinitionLinkImpl.class,
245                            workflowDefinitionLink.getPrimaryKey());
246    
247                    return workflowDefinitionLink;
248            }
249    
250            public WorkflowDefinitionLink updateImpl(
251                    com.liferay.portal.model.WorkflowDefinitionLink workflowDefinitionLink,
252                    boolean merge) throws SystemException {
253                    workflowDefinitionLink = toUnwrappedModel(workflowDefinitionLink);
254    
255                    boolean isNew = workflowDefinitionLink.isNew();
256    
257                    WorkflowDefinitionLinkModelImpl workflowDefinitionLinkModelImpl = (WorkflowDefinitionLinkModelImpl)workflowDefinitionLink;
258    
259                    Session session = null;
260    
261                    try {
262                            session = openSession();
263    
264                            BatchSessionUtil.update(session, workflowDefinitionLink, merge);
265    
266                            workflowDefinitionLink.setNew(false);
267                    }
268                    catch (Exception e) {
269                            throw processException(e);
270                    }
271                    finally {
272                            closeSession(session);
273                    }
274    
275                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
276    
277                    EntityCacheUtil.putResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
278                            WorkflowDefinitionLinkImpl.class,
279                            workflowDefinitionLink.getPrimaryKey(), workflowDefinitionLink);
280    
281                    if (!isNew &&
282                                    ((workflowDefinitionLink.getGroupId() != workflowDefinitionLinkModelImpl.getOriginalGroupId()) ||
283                                    (workflowDefinitionLink.getCompanyId() != workflowDefinitionLinkModelImpl.getOriginalCompanyId()) ||
284                                    (workflowDefinitionLink.getClassNameId() != workflowDefinitionLinkModelImpl.getOriginalClassNameId()))) {
285                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_C,
286                                    new Object[] {
287                                            new Long(workflowDefinitionLinkModelImpl.getOriginalGroupId()),
288                                            new Long(workflowDefinitionLinkModelImpl.getOriginalCompanyId()),
289                                            new Long(workflowDefinitionLinkModelImpl.getOriginalClassNameId())
290                                    });
291                    }
292    
293                    if (isNew ||
294                                    ((workflowDefinitionLink.getGroupId() != workflowDefinitionLinkModelImpl.getOriginalGroupId()) ||
295                                    (workflowDefinitionLink.getCompanyId() != workflowDefinitionLinkModelImpl.getOriginalCompanyId()) ||
296                                    (workflowDefinitionLink.getClassNameId() != workflowDefinitionLinkModelImpl.getOriginalClassNameId()))) {
297                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C,
298                                    new Object[] {
299                                            new Long(workflowDefinitionLink.getGroupId()),
300                                            new Long(workflowDefinitionLink.getCompanyId()),
301                                            new Long(workflowDefinitionLink.getClassNameId())
302                                    }, workflowDefinitionLink);
303                    }
304    
305                    return workflowDefinitionLink;
306            }
307    
308            protected WorkflowDefinitionLink toUnwrappedModel(
309                    WorkflowDefinitionLink workflowDefinitionLink) {
310                    if (workflowDefinitionLink instanceof WorkflowDefinitionLinkImpl) {
311                            return workflowDefinitionLink;
312                    }
313    
314                    WorkflowDefinitionLinkImpl workflowDefinitionLinkImpl = new WorkflowDefinitionLinkImpl();
315    
316                    workflowDefinitionLinkImpl.setNew(workflowDefinitionLink.isNew());
317                    workflowDefinitionLinkImpl.setPrimaryKey(workflowDefinitionLink.getPrimaryKey());
318    
319                    workflowDefinitionLinkImpl.setWorkflowDefinitionLinkId(workflowDefinitionLink.getWorkflowDefinitionLinkId());
320                    workflowDefinitionLinkImpl.setGroupId(workflowDefinitionLink.getGroupId());
321                    workflowDefinitionLinkImpl.setCompanyId(workflowDefinitionLink.getCompanyId());
322                    workflowDefinitionLinkImpl.setUserId(workflowDefinitionLink.getUserId());
323                    workflowDefinitionLinkImpl.setUserName(workflowDefinitionLink.getUserName());
324                    workflowDefinitionLinkImpl.setCreateDate(workflowDefinitionLink.getCreateDate());
325                    workflowDefinitionLinkImpl.setModifiedDate(workflowDefinitionLink.getModifiedDate());
326                    workflowDefinitionLinkImpl.setClassNameId(workflowDefinitionLink.getClassNameId());
327                    workflowDefinitionLinkImpl.setWorkflowDefinitionName(workflowDefinitionLink.getWorkflowDefinitionName());
328                    workflowDefinitionLinkImpl.setWorkflowDefinitionVersion(workflowDefinitionLink.getWorkflowDefinitionVersion());
329    
330                    return workflowDefinitionLinkImpl;
331            }
332    
333            public WorkflowDefinitionLink findByPrimaryKey(Serializable primaryKey)
334                    throws NoSuchModelException, SystemException {
335                    return findByPrimaryKey(((Long)primaryKey).longValue());
336            }
337    
338            public WorkflowDefinitionLink findByPrimaryKey(
339                    long workflowDefinitionLinkId)
340                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
341                    WorkflowDefinitionLink workflowDefinitionLink = fetchByPrimaryKey(workflowDefinitionLinkId);
342    
343                    if (workflowDefinitionLink == null) {
344                            if (_log.isWarnEnabled()) {
345                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
346                                            workflowDefinitionLinkId);
347                            }
348    
349                            throw new NoSuchWorkflowDefinitionLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
350                                    workflowDefinitionLinkId);
351                    }
352    
353                    return workflowDefinitionLink;
354            }
355    
356            public WorkflowDefinitionLink fetchByPrimaryKey(Serializable primaryKey)
357                    throws SystemException {
358                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
359            }
360    
361            public WorkflowDefinitionLink fetchByPrimaryKey(
362                    long workflowDefinitionLinkId) throws SystemException {
363                    WorkflowDefinitionLink workflowDefinitionLink = (WorkflowDefinitionLink)EntityCacheUtil.getResult(WorkflowDefinitionLinkModelImpl.ENTITY_CACHE_ENABLED,
364                                    WorkflowDefinitionLinkImpl.class, workflowDefinitionLinkId, this);
365    
366                    if (workflowDefinitionLink == null) {
367                            Session session = null;
368    
369                            try {
370                                    session = openSession();
371    
372                                    workflowDefinitionLink = (WorkflowDefinitionLink)session.get(WorkflowDefinitionLinkImpl.class,
373                                                    new Long(workflowDefinitionLinkId));
374                            }
375                            catch (Exception e) {
376                                    throw processException(e);
377                            }
378                            finally {
379                                    if (workflowDefinitionLink != null) {
380                                            cacheResult(workflowDefinitionLink);
381                                    }
382    
383                                    closeSession(session);
384                            }
385                    }
386    
387                    return workflowDefinitionLink;
388            }
389    
390            public List<WorkflowDefinitionLink> findByCompanyId(long companyId)
391                    throws SystemException {
392                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
393                            null);
394            }
395    
396            public List<WorkflowDefinitionLink> findByCompanyId(long companyId,
397                    int start, int end) throws SystemException {
398                    return findByCompanyId(companyId, start, end, null);
399            }
400    
401            public List<WorkflowDefinitionLink> findByCompanyId(long companyId,
402                    int start, int end, OrderByComparator orderByComparator)
403                    throws SystemException {
404                    Object[] finderArgs = new Object[] {
405                                    companyId,
406                                    
407                                    String.valueOf(start), String.valueOf(end),
408                                    String.valueOf(orderByComparator)
409                            };
410    
411                    List<WorkflowDefinitionLink> list = (List<WorkflowDefinitionLink>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
412                                    finderArgs, this);
413    
414                    if (list == null) {
415                            Session session = null;
416    
417                            try {
418                                    session = openSession();
419    
420                                    StringBundler query = null;
421    
422                                    if (orderByComparator != null) {
423                                            query = new StringBundler(3 +
424                                                            (orderByComparator.getOrderByFields().length * 3));
425                                    }
426                                    else {
427                                            query = new StringBundler(3);
428                                    }
429    
430                                    query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE);
431    
432                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
433    
434                                    if (orderByComparator != null) {
435                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
436                                                    orderByComparator);
437                                    }
438    
439                                    else {
440                                            query.append(WorkflowDefinitionLinkModelImpl.ORDER_BY_JPQL);
441                                    }
442    
443                                    String sql = query.toString();
444    
445                                    Query q = session.createQuery(sql);
446    
447                                    QueryPos qPos = QueryPos.getInstance(q);
448    
449                                    qPos.add(companyId);
450    
451                                    list = (List<WorkflowDefinitionLink>)QueryUtil.list(q,
452                                                    getDialect(), start, end);
453                            }
454                            catch (Exception e) {
455                                    throw processException(e);
456                            }
457                            finally {
458                                    if (list == null) {
459                                            list = new ArrayList<WorkflowDefinitionLink>();
460                                    }
461    
462                                    cacheResult(list);
463    
464                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
465                                            finderArgs, list);
466    
467                                    closeSession(session);
468                            }
469                    }
470    
471                    return list;
472            }
473    
474            public WorkflowDefinitionLink findByCompanyId_First(long companyId,
475                    OrderByComparator orderByComparator)
476                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
477                    List<WorkflowDefinitionLink> list = findByCompanyId(companyId, 0, 1,
478                                    orderByComparator);
479    
480                    if (list.isEmpty()) {
481                            StringBundler msg = new StringBundler(4);
482    
483                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
484    
485                            msg.append("companyId=");
486                            msg.append(companyId);
487    
488                            msg.append(StringPool.CLOSE_CURLY_BRACE);
489    
490                            throw new NoSuchWorkflowDefinitionLinkException(msg.toString());
491                    }
492                    else {
493                            return list.get(0);
494                    }
495            }
496    
497            public WorkflowDefinitionLink findByCompanyId_Last(long companyId,
498                    OrderByComparator orderByComparator)
499                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
500                    int count = countByCompanyId(companyId);
501    
502                    List<WorkflowDefinitionLink> list = findByCompanyId(companyId,
503                                    count - 1, count, orderByComparator);
504    
505                    if (list.isEmpty()) {
506                            StringBundler msg = new StringBundler(4);
507    
508                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
509    
510                            msg.append("companyId=");
511                            msg.append(companyId);
512    
513                            msg.append(StringPool.CLOSE_CURLY_BRACE);
514    
515                            throw new NoSuchWorkflowDefinitionLinkException(msg.toString());
516                    }
517                    else {
518                            return list.get(0);
519                    }
520            }
521    
522            public WorkflowDefinitionLink[] findByCompanyId_PrevAndNext(
523                    long workflowDefinitionLinkId, long companyId,
524                    OrderByComparator orderByComparator)
525                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
526                    WorkflowDefinitionLink workflowDefinitionLink = findByPrimaryKey(workflowDefinitionLinkId);
527    
528                    Session session = null;
529    
530                    try {
531                            session = openSession();
532    
533                            WorkflowDefinitionLink[] array = new WorkflowDefinitionLinkImpl[3];
534    
535                            array[0] = getByCompanyId_PrevAndNext(session,
536                                            workflowDefinitionLink, companyId, orderByComparator, true);
537    
538                            array[1] = workflowDefinitionLink;
539    
540                            array[2] = getByCompanyId_PrevAndNext(session,
541                                            workflowDefinitionLink, companyId, orderByComparator, false);
542    
543                            return array;
544                    }
545                    catch (Exception e) {
546                            throw processException(e);
547                    }
548                    finally {
549                            closeSession(session);
550                    }
551            }
552    
553            protected WorkflowDefinitionLink getByCompanyId_PrevAndNext(
554                    Session session, WorkflowDefinitionLink workflowDefinitionLink,
555                    long companyId, OrderByComparator orderByComparator, boolean previous) {
556                    StringBundler query = null;
557    
558                    if (orderByComparator != null) {
559                            query = new StringBundler(6 +
560                                            (orderByComparator.getOrderByFields().length * 6));
561                    }
562                    else {
563                            query = new StringBundler(3);
564                    }
565    
566                    query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE);
567    
568                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
569    
570                    if (orderByComparator != null) {
571                            String[] orderByFields = orderByComparator.getOrderByFields();
572    
573                            if (orderByFields.length > 0) {
574                                    query.append(WHERE_AND);
575                            }
576    
577                            for (int i = 0; i < orderByFields.length; i++) {
578                                    query.append(_ORDER_BY_ENTITY_ALIAS);
579                                    query.append(orderByFields[i]);
580    
581                                    if ((i + 1) < orderByFields.length) {
582                                            if (orderByComparator.isAscending() ^ previous) {
583                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
584                                            }
585                                            else {
586                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
587                                            }
588                                    }
589                                    else {
590                                            if (orderByComparator.isAscending() ^ previous) {
591                                                    query.append(WHERE_GREATER_THAN);
592                                            }
593                                            else {
594                                                    query.append(WHERE_LESSER_THAN);
595                                            }
596                                    }
597                            }
598    
599                            query.append(ORDER_BY_CLAUSE);
600    
601                            for (int i = 0; i < orderByFields.length; i++) {
602                                    query.append(_ORDER_BY_ENTITY_ALIAS);
603                                    query.append(orderByFields[i]);
604    
605                                    if ((i + 1) < orderByFields.length) {
606                                            if (orderByComparator.isAscending() ^ previous) {
607                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
608                                            }
609                                            else {
610                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
611                                            }
612                                    }
613                                    else {
614                                            if (orderByComparator.isAscending() ^ previous) {
615                                                    query.append(ORDER_BY_ASC);
616                                            }
617                                            else {
618                                                    query.append(ORDER_BY_DESC);
619                                            }
620                                    }
621                            }
622                    }
623    
624                    else {
625                            query.append(WorkflowDefinitionLinkModelImpl.ORDER_BY_JPQL);
626                    }
627    
628                    String sql = query.toString();
629    
630                    Query q = session.createQuery(sql);
631    
632                    q.setFirstResult(0);
633                    q.setMaxResults(2);
634    
635                    QueryPos qPos = QueryPos.getInstance(q);
636    
637                    qPos.add(companyId);
638    
639                    if (orderByComparator != null) {
640                            Object[] values = orderByComparator.getOrderByValues(workflowDefinitionLink);
641    
642                            for (Object value : values) {
643                                    qPos.add(value);
644                            }
645                    }
646    
647                    List<WorkflowDefinitionLink> list = q.list();
648    
649                    if (list.size() == 2) {
650                            return list.get(1);
651                    }
652                    else {
653                            return null;
654                    }
655            }
656    
657            public WorkflowDefinitionLink findByG_C_C(long groupId, long companyId,
658                    long classNameId)
659                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
660                    WorkflowDefinitionLink workflowDefinitionLink = fetchByG_C_C(groupId,
661                                    companyId, classNameId);
662    
663                    if (workflowDefinitionLink == null) {
664                            StringBundler msg = new StringBundler(8);
665    
666                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
667    
668                            msg.append("groupId=");
669                            msg.append(groupId);
670    
671                            msg.append(", companyId=");
672                            msg.append(companyId);
673    
674                            msg.append(", classNameId=");
675                            msg.append(classNameId);
676    
677                            msg.append(StringPool.CLOSE_CURLY_BRACE);
678    
679                            if (_log.isWarnEnabled()) {
680                                    _log.warn(msg.toString());
681                            }
682    
683                            throw new NoSuchWorkflowDefinitionLinkException(msg.toString());
684                    }
685    
686                    return workflowDefinitionLink;
687            }
688    
689            public WorkflowDefinitionLink fetchByG_C_C(long groupId, long companyId,
690                    long classNameId) throws SystemException {
691                    return fetchByG_C_C(groupId, companyId, classNameId, true);
692            }
693    
694            public WorkflowDefinitionLink fetchByG_C_C(long groupId, long companyId,
695                    long classNameId, boolean retrieveFromCache) throws SystemException {
696                    Object[] finderArgs = new Object[] { groupId, companyId, classNameId };
697    
698                    Object result = null;
699    
700                    if (retrieveFromCache) {
701                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_C_C,
702                                            finderArgs, this);
703                    }
704    
705                    if (result == null) {
706                            Session session = null;
707    
708                            try {
709                                    session = openSession();
710    
711                                    StringBundler query = new StringBundler(5);
712    
713                                    query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE);
714    
715                                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
716    
717                                    query.append(_FINDER_COLUMN_G_C_C_COMPANYID_2);
718    
719                                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
720    
721                                    query.append(WorkflowDefinitionLinkModelImpl.ORDER_BY_JPQL);
722    
723                                    String sql = query.toString();
724    
725                                    Query q = session.createQuery(sql);
726    
727                                    QueryPos qPos = QueryPos.getInstance(q);
728    
729                                    qPos.add(groupId);
730    
731                                    qPos.add(companyId);
732    
733                                    qPos.add(classNameId);
734    
735                                    List<WorkflowDefinitionLink> list = q.list();
736    
737                                    result = list;
738    
739                                    WorkflowDefinitionLink workflowDefinitionLink = null;
740    
741                                    if (list.isEmpty()) {
742                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C,
743                                                    finderArgs, list);
744                                    }
745                                    else {
746                                            workflowDefinitionLink = list.get(0);
747    
748                                            cacheResult(workflowDefinitionLink);
749    
750                                            if ((workflowDefinitionLink.getGroupId() != groupId) ||
751                                                            (workflowDefinitionLink.getCompanyId() != companyId) ||
752                                                            (workflowDefinitionLink.getClassNameId() != classNameId)) {
753                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C,
754                                                            finderArgs, workflowDefinitionLink);
755                                            }
756                                    }
757    
758                                    return workflowDefinitionLink;
759                            }
760                            catch (Exception e) {
761                                    throw processException(e);
762                            }
763                            finally {
764                                    if (result == null) {
765                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C,
766                                                    finderArgs, new ArrayList<WorkflowDefinitionLink>());
767                                    }
768    
769                                    closeSession(session);
770                            }
771                    }
772                    else {
773                            if (result instanceof List<?>) {
774                                    return null;
775                            }
776                            else {
777                                    return (WorkflowDefinitionLink)result;
778                            }
779                    }
780            }
781    
782            public List<WorkflowDefinitionLink> findByC_W_W(long companyId,
783                    String workflowDefinitionName, int workflowDefinitionVersion)
784                    throws SystemException {
785                    return findByC_W_W(companyId, workflowDefinitionName,
786                            workflowDefinitionVersion, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
787                            null);
788            }
789    
790            public List<WorkflowDefinitionLink> findByC_W_W(long companyId,
791                    String workflowDefinitionName, int workflowDefinitionVersion,
792                    int start, int end) throws SystemException {
793                    return findByC_W_W(companyId, workflowDefinitionName,
794                            workflowDefinitionVersion, start, end, null);
795            }
796    
797            public List<WorkflowDefinitionLink> findByC_W_W(long companyId,
798                    String workflowDefinitionName, int workflowDefinitionVersion,
799                    int start, int end, OrderByComparator orderByComparator)
800                    throws SystemException {
801                    Object[] finderArgs = new Object[] {
802                                    companyId, workflowDefinitionName, workflowDefinitionVersion,
803                                    
804                                    String.valueOf(start), String.valueOf(end),
805                                    String.valueOf(orderByComparator)
806                            };
807    
808                    List<WorkflowDefinitionLink> list = (List<WorkflowDefinitionLink>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_W_W,
809                                    finderArgs, this);
810    
811                    if (list == null) {
812                            Session session = null;
813    
814                            try {
815                                    session = openSession();
816    
817                                    StringBundler query = null;
818    
819                                    if (orderByComparator != null) {
820                                            query = new StringBundler(5 +
821                                                            (orderByComparator.getOrderByFields().length * 3));
822                                    }
823                                    else {
824                                            query = new StringBundler(5);
825                                    }
826    
827                                    query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE);
828    
829                                    query.append(_FINDER_COLUMN_C_W_W_COMPANYID_2);
830    
831                                    if (workflowDefinitionName == null) {
832                                            query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_1);
833                                    }
834                                    else {
835                                            if (workflowDefinitionName.equals(StringPool.BLANK)) {
836                                                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_3);
837                                            }
838                                            else {
839                                                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_2);
840                                            }
841                                    }
842    
843                                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONVERSION_2);
844    
845                                    if (orderByComparator != null) {
846                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
847                                                    orderByComparator);
848                                    }
849    
850                                    else {
851                                            query.append(WorkflowDefinitionLinkModelImpl.ORDER_BY_JPQL);
852                                    }
853    
854                                    String sql = query.toString();
855    
856                                    Query q = session.createQuery(sql);
857    
858                                    QueryPos qPos = QueryPos.getInstance(q);
859    
860                                    qPos.add(companyId);
861    
862                                    if (workflowDefinitionName != null) {
863                                            qPos.add(workflowDefinitionName);
864                                    }
865    
866                                    qPos.add(workflowDefinitionVersion);
867    
868                                    list = (List<WorkflowDefinitionLink>)QueryUtil.list(q,
869                                                    getDialect(), start, end);
870                            }
871                            catch (Exception e) {
872                                    throw processException(e);
873                            }
874                            finally {
875                                    if (list == null) {
876                                            list = new ArrayList<WorkflowDefinitionLink>();
877                                    }
878    
879                                    cacheResult(list);
880    
881                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_W_W,
882                                            finderArgs, list);
883    
884                                    closeSession(session);
885                            }
886                    }
887    
888                    return list;
889            }
890    
891            public WorkflowDefinitionLink findByC_W_W_First(long companyId,
892                    String workflowDefinitionName, int workflowDefinitionVersion,
893                    OrderByComparator orderByComparator)
894                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
895                    List<WorkflowDefinitionLink> list = findByC_W_W(companyId,
896                                    workflowDefinitionName, workflowDefinitionVersion, 0, 1,
897                                    orderByComparator);
898    
899                    if (list.isEmpty()) {
900                            StringBundler msg = new StringBundler(8);
901    
902                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
903    
904                            msg.append("companyId=");
905                            msg.append(companyId);
906    
907                            msg.append(", workflowDefinitionName=");
908                            msg.append(workflowDefinitionName);
909    
910                            msg.append(", workflowDefinitionVersion=");
911                            msg.append(workflowDefinitionVersion);
912    
913                            msg.append(StringPool.CLOSE_CURLY_BRACE);
914    
915                            throw new NoSuchWorkflowDefinitionLinkException(msg.toString());
916                    }
917                    else {
918                            return list.get(0);
919                    }
920            }
921    
922            public WorkflowDefinitionLink findByC_W_W_Last(long companyId,
923                    String workflowDefinitionName, int workflowDefinitionVersion,
924                    OrderByComparator orderByComparator)
925                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
926                    int count = countByC_W_W(companyId, workflowDefinitionName,
927                                    workflowDefinitionVersion);
928    
929                    List<WorkflowDefinitionLink> list = findByC_W_W(companyId,
930                                    workflowDefinitionName, workflowDefinitionVersion, count - 1,
931                                    count, orderByComparator);
932    
933                    if (list.isEmpty()) {
934                            StringBundler msg = new StringBundler(8);
935    
936                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
937    
938                            msg.append("companyId=");
939                            msg.append(companyId);
940    
941                            msg.append(", workflowDefinitionName=");
942                            msg.append(workflowDefinitionName);
943    
944                            msg.append(", workflowDefinitionVersion=");
945                            msg.append(workflowDefinitionVersion);
946    
947                            msg.append(StringPool.CLOSE_CURLY_BRACE);
948    
949                            throw new NoSuchWorkflowDefinitionLinkException(msg.toString());
950                    }
951                    else {
952                            return list.get(0);
953                    }
954            }
955    
956            public WorkflowDefinitionLink[] findByC_W_W_PrevAndNext(
957                    long workflowDefinitionLinkId, long companyId,
958                    String workflowDefinitionName, int workflowDefinitionVersion,
959                    OrderByComparator orderByComparator)
960                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
961                    WorkflowDefinitionLink workflowDefinitionLink = findByPrimaryKey(workflowDefinitionLinkId);
962    
963                    Session session = null;
964    
965                    try {
966                            session = openSession();
967    
968                            WorkflowDefinitionLink[] array = new WorkflowDefinitionLinkImpl[3];
969    
970                            array[0] = getByC_W_W_PrevAndNext(session, workflowDefinitionLink,
971                                            companyId, workflowDefinitionName,
972                                            workflowDefinitionVersion, orderByComparator, true);
973    
974                            array[1] = workflowDefinitionLink;
975    
976                            array[2] = getByC_W_W_PrevAndNext(session, workflowDefinitionLink,
977                                            companyId, workflowDefinitionName,
978                                            workflowDefinitionVersion, orderByComparator, false);
979    
980                            return array;
981                    }
982                    catch (Exception e) {
983                            throw processException(e);
984                    }
985                    finally {
986                            closeSession(session);
987                    }
988            }
989    
990            protected WorkflowDefinitionLink getByC_W_W_PrevAndNext(Session session,
991                    WorkflowDefinitionLink workflowDefinitionLink, long companyId,
992                    String workflowDefinitionName, int workflowDefinitionVersion,
993                    OrderByComparator orderByComparator, boolean previous) {
994                    StringBundler query = null;
995    
996                    if (orderByComparator != null) {
997                            query = new StringBundler(6 +
998                                            (orderByComparator.getOrderByFields().length * 6));
999                    }
1000                    else {
1001                            query = new StringBundler(3);
1002                    }
1003    
1004                    query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE);
1005    
1006                    query.append(_FINDER_COLUMN_C_W_W_COMPANYID_2);
1007    
1008                    if (workflowDefinitionName == null) {
1009                            query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_1);
1010                    }
1011                    else {
1012                            if (workflowDefinitionName.equals(StringPool.BLANK)) {
1013                                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_3);
1014                            }
1015                            else {
1016                                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_2);
1017                            }
1018                    }
1019    
1020                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONVERSION_2);
1021    
1022                    if (orderByComparator != null) {
1023                            String[] orderByFields = orderByComparator.getOrderByFields();
1024    
1025                            if (orderByFields.length > 0) {
1026                                    query.append(WHERE_AND);
1027                            }
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(WHERE_GREATER_THAN_HAS_NEXT);
1036                                            }
1037                                            else {
1038                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1039                                            }
1040                                    }
1041                                    else {
1042                                            if (orderByComparator.isAscending() ^ previous) {
1043                                                    query.append(WHERE_GREATER_THAN);
1044                                            }
1045                                            else {
1046                                                    query.append(WHERE_LESSER_THAN);
1047                                            }
1048                                    }
1049                            }
1050    
1051                            query.append(ORDER_BY_CLAUSE);
1052    
1053                            for (int i = 0; i < orderByFields.length; i++) {
1054                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1055                                    query.append(orderByFields[i]);
1056    
1057                                    if ((i + 1) < orderByFields.length) {
1058                                            if (orderByComparator.isAscending() ^ previous) {
1059                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1060                                            }
1061                                            else {
1062                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1063                                            }
1064                                    }
1065                                    else {
1066                                            if (orderByComparator.isAscending() ^ previous) {
1067                                                    query.append(ORDER_BY_ASC);
1068                                            }
1069                                            else {
1070                                                    query.append(ORDER_BY_DESC);
1071                                            }
1072                                    }
1073                            }
1074                    }
1075    
1076                    else {
1077                            query.append(WorkflowDefinitionLinkModelImpl.ORDER_BY_JPQL);
1078                    }
1079    
1080                    String sql = query.toString();
1081    
1082                    Query q = session.createQuery(sql);
1083    
1084                    q.setFirstResult(0);
1085                    q.setMaxResults(2);
1086    
1087                    QueryPos qPos = QueryPos.getInstance(q);
1088    
1089                    qPos.add(companyId);
1090    
1091                    if (workflowDefinitionName != null) {
1092                            qPos.add(workflowDefinitionName);
1093                    }
1094    
1095                    qPos.add(workflowDefinitionVersion);
1096    
1097                    if (orderByComparator != null) {
1098                            Object[] values = orderByComparator.getOrderByValues(workflowDefinitionLink);
1099    
1100                            for (Object value : values) {
1101                                    qPos.add(value);
1102                            }
1103                    }
1104    
1105                    List<WorkflowDefinitionLink> list = q.list();
1106    
1107                    if (list.size() == 2) {
1108                            return list.get(1);
1109                    }
1110                    else {
1111                            return null;
1112                    }
1113            }
1114    
1115            public List<WorkflowDefinitionLink> findAll() throws SystemException {
1116                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1117            }
1118    
1119            public List<WorkflowDefinitionLink> findAll(int start, int end)
1120                    throws SystemException {
1121                    return findAll(start, end, null);
1122            }
1123    
1124            public List<WorkflowDefinitionLink> findAll(int start, int end,
1125                    OrderByComparator orderByComparator) throws SystemException {
1126                    Object[] finderArgs = new Object[] {
1127                                    String.valueOf(start), String.valueOf(end),
1128                                    String.valueOf(orderByComparator)
1129                            };
1130    
1131                    List<WorkflowDefinitionLink> list = (List<WorkflowDefinitionLink>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1132                                    finderArgs, this);
1133    
1134                    if (list == null) {
1135                            Session session = null;
1136    
1137                            try {
1138                                    session = openSession();
1139    
1140                                    StringBundler query = null;
1141                                    String sql = null;
1142    
1143                                    if (orderByComparator != null) {
1144                                            query = new StringBundler(2 +
1145                                                            (orderByComparator.getOrderByFields().length * 3));
1146    
1147                                            query.append(_SQL_SELECT_WORKFLOWDEFINITIONLINK);
1148    
1149                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1150                                                    orderByComparator);
1151    
1152                                            sql = query.toString();
1153                                    }
1154                                    else {
1155                                            sql = _SQL_SELECT_WORKFLOWDEFINITIONLINK.concat(WorkflowDefinitionLinkModelImpl.ORDER_BY_JPQL);
1156                                    }
1157    
1158                                    Query q = session.createQuery(sql);
1159    
1160                                    if (orderByComparator == null) {
1161                                            list = (List<WorkflowDefinitionLink>)QueryUtil.list(q,
1162                                                            getDialect(), start, end, false);
1163    
1164                                            Collections.sort(list);
1165                                    }
1166                                    else {
1167                                            list = (List<WorkflowDefinitionLink>)QueryUtil.list(q,
1168                                                            getDialect(), start, end);
1169                                    }
1170                            }
1171                            catch (Exception e) {
1172                                    throw processException(e);
1173                            }
1174                            finally {
1175                                    if (list == null) {
1176                                            list = new ArrayList<WorkflowDefinitionLink>();
1177                                    }
1178    
1179                                    cacheResult(list);
1180    
1181                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1182    
1183                                    closeSession(session);
1184                            }
1185                    }
1186    
1187                    return list;
1188            }
1189    
1190            public void removeByCompanyId(long companyId) throws SystemException {
1191                    for (WorkflowDefinitionLink workflowDefinitionLink : findByCompanyId(
1192                                    companyId)) {
1193                            remove(workflowDefinitionLink);
1194                    }
1195            }
1196    
1197            public void removeByG_C_C(long groupId, long companyId, long classNameId)
1198                    throws NoSuchWorkflowDefinitionLinkException, SystemException {
1199                    WorkflowDefinitionLink workflowDefinitionLink = findByG_C_C(groupId,
1200                                    companyId, classNameId);
1201    
1202                    remove(workflowDefinitionLink);
1203            }
1204    
1205            public void removeByC_W_W(long companyId, String workflowDefinitionName,
1206                    int workflowDefinitionVersion) throws SystemException {
1207                    for (WorkflowDefinitionLink workflowDefinitionLink : findByC_W_W(
1208                                    companyId, workflowDefinitionName, workflowDefinitionVersion)) {
1209                            remove(workflowDefinitionLink);
1210                    }
1211            }
1212    
1213            public void removeAll() throws SystemException {
1214                    for (WorkflowDefinitionLink workflowDefinitionLink : findAll()) {
1215                            remove(workflowDefinitionLink);
1216                    }
1217            }
1218    
1219            public int countByCompanyId(long companyId) throws SystemException {
1220                    Object[] finderArgs = new Object[] { companyId };
1221    
1222                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1223                                    finderArgs, this);
1224    
1225                    if (count == null) {
1226                            Session session = null;
1227    
1228                            try {
1229                                    session = openSession();
1230    
1231                                    StringBundler query = new StringBundler(2);
1232    
1233                                    query.append(_SQL_COUNT_WORKFLOWDEFINITIONLINK_WHERE);
1234    
1235                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1236    
1237                                    String sql = query.toString();
1238    
1239                                    Query q = session.createQuery(sql);
1240    
1241                                    QueryPos qPos = QueryPos.getInstance(q);
1242    
1243                                    qPos.add(companyId);
1244    
1245                                    count = (Long)q.uniqueResult();
1246                            }
1247                            catch (Exception e) {
1248                                    throw processException(e);
1249                            }
1250                            finally {
1251                                    if (count == null) {
1252                                            count = Long.valueOf(0);
1253                                    }
1254    
1255                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1256                                            finderArgs, count);
1257    
1258                                    closeSession(session);
1259                            }
1260                    }
1261    
1262                    return count.intValue();
1263            }
1264    
1265            public int countByG_C_C(long groupId, long companyId, long classNameId)
1266                    throws SystemException {
1267                    Object[] finderArgs = new Object[] { groupId, companyId, classNameId };
1268    
1269                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_C,
1270                                    finderArgs, this);
1271    
1272                    if (count == null) {
1273                            Session session = null;
1274    
1275                            try {
1276                                    session = openSession();
1277    
1278                                    StringBundler query = new StringBundler(4);
1279    
1280                                    query.append(_SQL_COUNT_WORKFLOWDEFINITIONLINK_WHERE);
1281    
1282                                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
1283    
1284                                    query.append(_FINDER_COLUMN_G_C_C_COMPANYID_2);
1285    
1286                                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
1287    
1288                                    String sql = query.toString();
1289    
1290                                    Query q = session.createQuery(sql);
1291    
1292                                    QueryPos qPos = QueryPos.getInstance(q);
1293    
1294                                    qPos.add(groupId);
1295    
1296                                    qPos.add(companyId);
1297    
1298                                    qPos.add(classNameId);
1299    
1300                                    count = (Long)q.uniqueResult();
1301                            }
1302                            catch (Exception e) {
1303                                    throw processException(e);
1304                            }
1305                            finally {
1306                                    if (count == null) {
1307                                            count = Long.valueOf(0);
1308                                    }
1309    
1310                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_C,
1311                                            finderArgs, count);
1312    
1313                                    closeSession(session);
1314                            }
1315                    }
1316    
1317                    return count.intValue();
1318            }
1319    
1320            public int countByC_W_W(long companyId, String workflowDefinitionName,
1321                    int workflowDefinitionVersion) throws SystemException {
1322                    Object[] finderArgs = new Object[] {
1323                                    companyId, workflowDefinitionName, workflowDefinitionVersion
1324                            };
1325    
1326                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_W_W,
1327                                    finderArgs, this);
1328    
1329                    if (count == null) {
1330                            Session session = null;
1331    
1332                            try {
1333                                    session = openSession();
1334    
1335                                    StringBundler query = new StringBundler(4);
1336    
1337                                    query.append(_SQL_COUNT_WORKFLOWDEFINITIONLINK_WHERE);
1338    
1339                                    query.append(_FINDER_COLUMN_C_W_W_COMPANYID_2);
1340    
1341                                    if (workflowDefinitionName == null) {
1342                                            query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_1);
1343                                    }
1344                                    else {
1345                                            if (workflowDefinitionName.equals(StringPool.BLANK)) {
1346                                                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_3);
1347                                            }
1348                                            else {
1349                                                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_2);
1350                                            }
1351                                    }
1352    
1353                                    query.append(_FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONVERSION_2);
1354    
1355                                    String sql = query.toString();
1356    
1357                                    Query q = session.createQuery(sql);
1358    
1359                                    QueryPos qPos = QueryPos.getInstance(q);
1360    
1361                                    qPos.add(companyId);
1362    
1363                                    if (workflowDefinitionName != null) {
1364                                            qPos.add(workflowDefinitionName);
1365                                    }
1366    
1367                                    qPos.add(workflowDefinitionVersion);
1368    
1369                                    count = (Long)q.uniqueResult();
1370                            }
1371                            catch (Exception e) {
1372                                    throw processException(e);
1373                            }
1374                            finally {
1375                                    if (count == null) {
1376                                            count = Long.valueOf(0);
1377                                    }
1378    
1379                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_W_W,
1380                                            finderArgs, count);
1381    
1382                                    closeSession(session);
1383                            }
1384                    }
1385    
1386                    return count.intValue();
1387            }
1388    
1389            public int countAll() throws SystemException {
1390                    Object[] finderArgs = new Object[0];
1391    
1392                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1393                                    finderArgs, this);
1394    
1395                    if (count == null) {
1396                            Session session = null;
1397    
1398                            try {
1399                                    session = openSession();
1400    
1401                                    Query q = session.createQuery(_SQL_COUNT_WORKFLOWDEFINITIONLINK);
1402    
1403                                    count = (Long)q.uniqueResult();
1404                            }
1405                            catch (Exception e) {
1406                                    throw processException(e);
1407                            }
1408                            finally {
1409                                    if (count == null) {
1410                                            count = Long.valueOf(0);
1411                                    }
1412    
1413                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1414                                            count);
1415    
1416                                    closeSession(session);
1417                            }
1418                    }
1419    
1420                    return count.intValue();
1421            }
1422    
1423            public void afterPropertiesSet() {
1424                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1425                                            com.liferay.portal.util.PropsUtil.get(
1426                                                    "value.object.listener.com.liferay.portal.model.WorkflowDefinitionLink")));
1427    
1428                    if (listenerClassNames.length > 0) {
1429                            try {
1430                                    List<ModelListener<WorkflowDefinitionLink>> listenersList = new ArrayList<ModelListener<WorkflowDefinitionLink>>();
1431    
1432                                    for (String listenerClassName : listenerClassNames) {
1433                                            listenersList.add((ModelListener<WorkflowDefinitionLink>)InstanceFactory.newInstance(
1434                                                            listenerClassName));
1435                                    }
1436    
1437                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1438                            }
1439                            catch (Exception e) {
1440                                    _log.error(e);
1441                            }
1442                    }
1443            }
1444    
1445            @BeanReference(type = AccountPersistence.class)
1446            protected AccountPersistence accountPersistence;
1447            @BeanReference(type = AddressPersistence.class)
1448            protected AddressPersistence addressPersistence;
1449            @BeanReference(type = BrowserTrackerPersistence.class)
1450            protected BrowserTrackerPersistence browserTrackerPersistence;
1451            @BeanReference(type = ClassNamePersistence.class)
1452            protected ClassNamePersistence classNamePersistence;
1453            @BeanReference(type = CompanyPersistence.class)
1454            protected CompanyPersistence companyPersistence;
1455            @BeanReference(type = ContactPersistence.class)
1456            protected ContactPersistence contactPersistence;
1457            @BeanReference(type = CountryPersistence.class)
1458            protected CountryPersistence countryPersistence;
1459            @BeanReference(type = EmailAddressPersistence.class)
1460            protected EmailAddressPersistence emailAddressPersistence;
1461            @BeanReference(type = GroupPersistence.class)
1462            protected GroupPersistence groupPersistence;
1463            @BeanReference(type = ImagePersistence.class)
1464            protected ImagePersistence imagePersistence;
1465            @BeanReference(type = LayoutPersistence.class)
1466            protected LayoutPersistence layoutPersistence;
1467            @BeanReference(type = LayoutPrototypePersistence.class)
1468            protected LayoutPrototypePersistence layoutPrototypePersistence;
1469            @BeanReference(type = LayoutSetPersistence.class)
1470            protected LayoutSetPersistence layoutSetPersistence;
1471            @BeanReference(type = LayoutSetPrototypePersistence.class)
1472            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1473            @BeanReference(type = ListTypePersistence.class)
1474            protected ListTypePersistence listTypePersistence;
1475            @BeanReference(type = LockPersistence.class)
1476            protected LockPersistence lockPersistence;
1477            @BeanReference(type = MembershipRequestPersistence.class)
1478            protected MembershipRequestPersistence membershipRequestPersistence;
1479            @BeanReference(type = OrganizationPersistence.class)
1480            protected OrganizationPersistence organizationPersistence;
1481            @BeanReference(type = OrgGroupPermissionPersistence.class)
1482            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1483            @BeanReference(type = OrgGroupRolePersistence.class)
1484            protected OrgGroupRolePersistence orgGroupRolePersistence;
1485            @BeanReference(type = OrgLaborPersistence.class)
1486            protected OrgLaborPersistence orgLaborPersistence;
1487            @BeanReference(type = PasswordPolicyPersistence.class)
1488            protected PasswordPolicyPersistence passwordPolicyPersistence;
1489            @BeanReference(type = PasswordPolicyRelPersistence.class)
1490            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1491            @BeanReference(type = PasswordTrackerPersistence.class)
1492            protected PasswordTrackerPersistence passwordTrackerPersistence;
1493            @BeanReference(type = PermissionPersistence.class)
1494            protected PermissionPersistence permissionPersistence;
1495            @BeanReference(type = PhonePersistence.class)
1496            protected PhonePersistence phonePersistence;
1497            @BeanReference(type = PluginSettingPersistence.class)
1498            protected PluginSettingPersistence pluginSettingPersistence;
1499            @BeanReference(type = PortletPersistence.class)
1500            protected PortletPersistence portletPersistence;
1501            @BeanReference(type = PortletItemPersistence.class)
1502            protected PortletItemPersistence portletItemPersistence;
1503            @BeanReference(type = PortletPreferencesPersistence.class)
1504            protected PortletPreferencesPersistence portletPreferencesPersistence;
1505            @BeanReference(type = RegionPersistence.class)
1506            protected RegionPersistence regionPersistence;
1507            @BeanReference(type = ReleasePersistence.class)
1508            protected ReleasePersistence releasePersistence;
1509            @BeanReference(type = ResourcePersistence.class)
1510            protected ResourcePersistence resourcePersistence;
1511            @BeanReference(type = ResourceActionPersistence.class)
1512            protected ResourceActionPersistence resourceActionPersistence;
1513            @BeanReference(type = ResourceCodePersistence.class)
1514            protected ResourceCodePersistence resourceCodePersistence;
1515            @BeanReference(type = ResourcePermissionPersistence.class)
1516            protected ResourcePermissionPersistence resourcePermissionPersistence;
1517            @BeanReference(type = RolePersistence.class)
1518            protected RolePersistence rolePersistence;
1519            @BeanReference(type = ServiceComponentPersistence.class)
1520            protected ServiceComponentPersistence serviceComponentPersistence;
1521            @BeanReference(type = ShardPersistence.class)
1522            protected ShardPersistence shardPersistence;
1523            @BeanReference(type = SubscriptionPersistence.class)
1524            protected SubscriptionPersistence subscriptionPersistence;
1525            @BeanReference(type = TicketPersistence.class)
1526            protected TicketPersistence ticketPersistence;
1527            @BeanReference(type = TeamPersistence.class)
1528            protected TeamPersistence teamPersistence;
1529            @BeanReference(type = UserPersistence.class)
1530            protected UserPersistence userPersistence;
1531            @BeanReference(type = UserGroupPersistence.class)
1532            protected UserGroupPersistence userGroupPersistence;
1533            @BeanReference(type = UserGroupGroupRolePersistence.class)
1534            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1535            @BeanReference(type = UserGroupRolePersistence.class)
1536            protected UserGroupRolePersistence userGroupRolePersistence;
1537            @BeanReference(type = UserIdMapperPersistence.class)
1538            protected UserIdMapperPersistence userIdMapperPersistence;
1539            @BeanReference(type = UserTrackerPersistence.class)
1540            protected UserTrackerPersistence userTrackerPersistence;
1541            @BeanReference(type = UserTrackerPathPersistence.class)
1542            protected UserTrackerPathPersistence userTrackerPathPersistence;
1543            @BeanReference(type = WebDAVPropsPersistence.class)
1544            protected WebDAVPropsPersistence webDAVPropsPersistence;
1545            @BeanReference(type = WebsitePersistence.class)
1546            protected WebsitePersistence websitePersistence;
1547            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1548            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1549            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1550            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1551            private static final String _SQL_SELECT_WORKFLOWDEFINITIONLINK = "SELECT workflowDefinitionLink FROM WorkflowDefinitionLink workflowDefinitionLink";
1552            private static final String _SQL_SELECT_WORKFLOWDEFINITIONLINK_WHERE = "SELECT workflowDefinitionLink FROM WorkflowDefinitionLink workflowDefinitionLink WHERE ";
1553            private static final String _SQL_COUNT_WORKFLOWDEFINITIONLINK = "SELECT COUNT(workflowDefinitionLink) FROM WorkflowDefinitionLink workflowDefinitionLink";
1554            private static final String _SQL_COUNT_WORKFLOWDEFINITIONLINK_WHERE = "SELECT COUNT(workflowDefinitionLink) FROM WorkflowDefinitionLink workflowDefinitionLink WHERE ";
1555            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "workflowDefinitionLink.companyId = ?";
1556            private static final String _FINDER_COLUMN_G_C_C_GROUPID_2 = "workflowDefinitionLink.groupId = ? AND ";
1557            private static final String _FINDER_COLUMN_G_C_C_COMPANYID_2 = "workflowDefinitionLink.companyId = ? AND ";
1558            private static final String _FINDER_COLUMN_G_C_C_CLASSNAMEID_2 = "workflowDefinitionLink.classNameId = ?";
1559            private static final String _FINDER_COLUMN_C_W_W_COMPANYID_2 = "workflowDefinitionLink.companyId = ? AND ";
1560            private static final String _FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_1 = "workflowDefinitionLink.workflowDefinitionName IS NULL AND ";
1561            private static final String _FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_2 = "workflowDefinitionLink.workflowDefinitionName = ? AND ";
1562            private static final String _FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONNAME_3 = "(workflowDefinitionLink.workflowDefinitionName IS NULL OR workflowDefinitionLink.workflowDefinitionName = ?) AND ";
1563            private static final String _FINDER_COLUMN_C_W_W_WORKFLOWDEFINITIONVERSION_2 =
1564                    "workflowDefinitionLink.workflowDefinitionVersion = ?";
1565            private static final String _ORDER_BY_ENTITY_ALIAS = "workflowDefinitionLink.";
1566            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WorkflowDefinitionLink exists with the primary key ";
1567            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WorkflowDefinitionLink exists with the key {";
1568            private static Log _log = LogFactoryUtil.getLog(WorkflowDefinitionLinkPersistenceImpl.class);
1569    }