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