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.NoSuchWorkflowInstanceLinkException;
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.WorkflowInstanceLink;
38  import com.liferay.portal.model.impl.WorkflowInstanceLinkImpl;
39  import com.liferay.portal.model.impl.WorkflowInstanceLinkModelImpl;
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="WorkflowInstanceLinkPersistenceImpl.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       WorkflowInstanceLinkPersistence
58   * @see       WorkflowInstanceLinkUtil
59   * @generated
60   */
61  public class WorkflowInstanceLinkPersistenceImpl extends BasePersistenceImpl<WorkflowInstanceLink>
62      implements WorkflowInstanceLinkPersistence {
63      public static final String FINDER_CLASS_NAME_ENTITY = WorkflowInstanceLinkImpl.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_G_C_C_C = new FinderPath(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
67              WorkflowInstanceLinkModelImpl.FINDER_CACHE_ENABLED,
68              FINDER_CLASS_NAME_LIST, "findByG_C_C_C",
69              new String[] {
70                  Long.class.getName(), Long.class.getName(), Long.class.getName(),
71                  Long.class.getName()
72              });
73      public static final FinderPath FINDER_PATH_FIND_BY_OBC_G_C_C_C = new FinderPath(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
74              WorkflowInstanceLinkModelImpl.FINDER_CACHE_ENABLED,
75              FINDER_CLASS_NAME_LIST, "findByG_C_C_C",
76              new String[] {
77                  Long.class.getName(), Long.class.getName(), Long.class.getName(),
78                  Long.class.getName(),
79                  
80              "java.lang.Integer", "java.lang.Integer",
81                  "com.liferay.portal.kernel.util.OrderByComparator"
82              });
83      public static final FinderPath FINDER_PATH_COUNT_BY_G_C_C_C = new FinderPath(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
84              WorkflowInstanceLinkModelImpl.FINDER_CACHE_ENABLED,
85              FINDER_CLASS_NAME_LIST, "countByG_C_C_C",
86              new String[] {
87                  Long.class.getName(), Long.class.getName(), Long.class.getName(),
88                  Long.class.getName()
89              });
90      public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
91              WorkflowInstanceLinkModelImpl.FINDER_CACHE_ENABLED,
92              FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
93      public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
94              WorkflowInstanceLinkModelImpl.FINDER_CACHE_ENABLED,
95              FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
96  
97      public void cacheResult(WorkflowInstanceLink workflowInstanceLink) {
98          EntityCacheUtil.putResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
99              WorkflowInstanceLinkImpl.class,
100             workflowInstanceLink.getPrimaryKey(), workflowInstanceLink);
101     }
102 
103     public void cacheResult(List<WorkflowInstanceLink> workflowInstanceLinks) {
104         for (WorkflowInstanceLink workflowInstanceLink : workflowInstanceLinks) {
105             if (EntityCacheUtil.getResult(
106                         WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
107                         WorkflowInstanceLinkImpl.class,
108                         workflowInstanceLink.getPrimaryKey(), this) == null) {
109                 cacheResult(workflowInstanceLink);
110             }
111         }
112     }
113 
114     public void clearCache() {
115         CacheRegistry.clear(WorkflowInstanceLinkImpl.class.getName());
116         EntityCacheUtil.clearCache(WorkflowInstanceLinkImpl.class.getName());
117         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
118         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
119     }
120 
121     public WorkflowInstanceLink create(long workflowInstanceLinkId) {
122         WorkflowInstanceLink workflowInstanceLink = new WorkflowInstanceLinkImpl();
123 
124         workflowInstanceLink.setNew(true);
125         workflowInstanceLink.setPrimaryKey(workflowInstanceLinkId);
126 
127         return workflowInstanceLink;
128     }
129 
130     public WorkflowInstanceLink remove(Serializable primaryKey)
131         throws NoSuchModelException, SystemException {
132         return remove(((Long)primaryKey).longValue());
133     }
134 
135     public WorkflowInstanceLink remove(long workflowInstanceLinkId)
136         throws NoSuchWorkflowInstanceLinkException, SystemException {
137         Session session = null;
138 
139         try {
140             session = openSession();
141 
142             WorkflowInstanceLink workflowInstanceLink = (WorkflowInstanceLink)session.get(WorkflowInstanceLinkImpl.class,
143                     new Long(workflowInstanceLinkId));
144 
145             if (workflowInstanceLink == null) {
146                 if (_log.isWarnEnabled()) {
147                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
148                         workflowInstanceLinkId);
149                 }
150 
151                 throw new NoSuchWorkflowInstanceLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
152                     workflowInstanceLinkId);
153             }
154 
155             return remove(workflowInstanceLink);
156         }
157         catch (NoSuchWorkflowInstanceLinkException nsee) {
158             throw nsee;
159         }
160         catch (Exception e) {
161             throw processException(e);
162         }
163         finally {
164             closeSession(session);
165         }
166     }
167 
168     public WorkflowInstanceLink remove(
169         WorkflowInstanceLink workflowInstanceLink) throws SystemException {
170         for (ModelListener<WorkflowInstanceLink> listener : listeners) {
171             listener.onBeforeRemove(workflowInstanceLink);
172         }
173 
174         workflowInstanceLink = removeImpl(workflowInstanceLink);
175 
176         for (ModelListener<WorkflowInstanceLink> listener : listeners) {
177             listener.onAfterRemove(workflowInstanceLink);
178         }
179 
180         return workflowInstanceLink;
181     }
182 
183     protected WorkflowInstanceLink removeImpl(
184         WorkflowInstanceLink workflowInstanceLink) throws SystemException {
185         workflowInstanceLink = toUnwrappedModel(workflowInstanceLink);
186 
187         Session session = null;
188 
189         try {
190             session = openSession();
191 
192             if (workflowInstanceLink.isCachedModel() ||
193                     BatchSessionUtil.isEnabled()) {
194                 Object staleObject = session.get(WorkflowInstanceLinkImpl.class,
195                         workflowInstanceLink.getPrimaryKeyObj());
196 
197                 if (staleObject != null) {
198                     session.evict(staleObject);
199                 }
200             }
201 
202             session.delete(workflowInstanceLink);
203 
204             session.flush();
205         }
206         catch (Exception e) {
207             throw processException(e);
208         }
209         finally {
210             closeSession(session);
211         }
212 
213         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
214 
215         EntityCacheUtil.removeResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
216             WorkflowInstanceLinkImpl.class, workflowInstanceLink.getPrimaryKey());
217 
218         return workflowInstanceLink;
219     }
220 
221     public WorkflowInstanceLink updateImpl(
222         com.liferay.portal.model.WorkflowInstanceLink workflowInstanceLink,
223         boolean merge) throws SystemException {
224         workflowInstanceLink = toUnwrappedModel(workflowInstanceLink);
225 
226         Session session = null;
227 
228         try {
229             session = openSession();
230 
231             BatchSessionUtil.update(session, workflowInstanceLink, merge);
232 
233             workflowInstanceLink.setNew(false);
234         }
235         catch (Exception e) {
236             throw processException(e);
237         }
238         finally {
239             closeSession(session);
240         }
241 
242         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
243 
244         EntityCacheUtil.putResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
245             WorkflowInstanceLinkImpl.class,
246             workflowInstanceLink.getPrimaryKey(), workflowInstanceLink);
247 
248         return workflowInstanceLink;
249     }
250 
251     protected WorkflowInstanceLink toUnwrappedModel(
252         WorkflowInstanceLink workflowInstanceLink) {
253         if (workflowInstanceLink instanceof WorkflowInstanceLinkImpl) {
254             return workflowInstanceLink;
255         }
256 
257         WorkflowInstanceLinkImpl workflowInstanceLinkImpl = new WorkflowInstanceLinkImpl();
258 
259         workflowInstanceLinkImpl.setNew(workflowInstanceLink.isNew());
260         workflowInstanceLinkImpl.setPrimaryKey(workflowInstanceLink.getPrimaryKey());
261 
262         workflowInstanceLinkImpl.setWorkflowInstanceLinkId(workflowInstanceLink.getWorkflowInstanceLinkId());
263         workflowInstanceLinkImpl.setGroupId(workflowInstanceLink.getGroupId());
264         workflowInstanceLinkImpl.setCompanyId(workflowInstanceLink.getCompanyId());
265         workflowInstanceLinkImpl.setUserId(workflowInstanceLink.getUserId());
266         workflowInstanceLinkImpl.setUserName(workflowInstanceLink.getUserName());
267         workflowInstanceLinkImpl.setCreateDate(workflowInstanceLink.getCreateDate());
268         workflowInstanceLinkImpl.setModifiedDate(workflowInstanceLink.getModifiedDate());
269         workflowInstanceLinkImpl.setClassNameId(workflowInstanceLink.getClassNameId());
270         workflowInstanceLinkImpl.setClassPK(workflowInstanceLink.getClassPK());
271         workflowInstanceLinkImpl.setWorkflowInstanceId(workflowInstanceLink.getWorkflowInstanceId());
272 
273         return workflowInstanceLinkImpl;
274     }
275 
276     public WorkflowInstanceLink findByPrimaryKey(Serializable primaryKey)
277         throws NoSuchModelException, SystemException {
278         return findByPrimaryKey(((Long)primaryKey).longValue());
279     }
280 
281     public WorkflowInstanceLink findByPrimaryKey(long workflowInstanceLinkId)
282         throws NoSuchWorkflowInstanceLinkException, SystemException {
283         WorkflowInstanceLink workflowInstanceLink = fetchByPrimaryKey(workflowInstanceLinkId);
284 
285         if (workflowInstanceLink == null) {
286             if (_log.isWarnEnabled()) {
287                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
288                     workflowInstanceLinkId);
289             }
290 
291             throw new NoSuchWorkflowInstanceLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
292                 workflowInstanceLinkId);
293         }
294 
295         return workflowInstanceLink;
296     }
297 
298     public WorkflowInstanceLink fetchByPrimaryKey(Serializable primaryKey)
299         throws SystemException {
300         return fetchByPrimaryKey(((Long)primaryKey).longValue());
301     }
302 
303     public WorkflowInstanceLink fetchByPrimaryKey(long workflowInstanceLinkId)
304         throws SystemException {
305         WorkflowInstanceLink workflowInstanceLink = (WorkflowInstanceLink)EntityCacheUtil.getResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
306                 WorkflowInstanceLinkImpl.class, workflowInstanceLinkId, this);
307 
308         if (workflowInstanceLink == null) {
309             Session session = null;
310 
311             try {
312                 session = openSession();
313 
314                 workflowInstanceLink = (WorkflowInstanceLink)session.get(WorkflowInstanceLinkImpl.class,
315                         new Long(workflowInstanceLinkId));
316             }
317             catch (Exception e) {
318                 throw processException(e);
319             }
320             finally {
321                 if (workflowInstanceLink != null) {
322                     cacheResult(workflowInstanceLink);
323                 }
324 
325                 closeSession(session);
326             }
327         }
328 
329         return workflowInstanceLink;
330     }
331 
332     public List<WorkflowInstanceLink> findByG_C_C_C(long groupId,
333         long companyId, long classNameId, long classPK)
334         throws SystemException {
335         Object[] finderArgs = new Object[] {
336                 new Long(groupId), new Long(companyId), new Long(classNameId),
337                 new Long(classPK)
338             };
339 
340         List<WorkflowInstanceLink> list = (List<WorkflowInstanceLink>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_C_C_C,
341                 finderArgs, this);
342 
343         if (list == null) {
344             Session session = null;
345 
346             try {
347                 session = openSession();
348 
349                 StringBundler query = new StringBundler(6);
350 
351                 query.append(_SQL_SELECT_WORKFLOWINSTANCELINK_WHERE);
352 
353                 query.append(_FINDER_COLUMN_G_C_C_C_GROUPID_2);
354 
355                 query.append(_FINDER_COLUMN_G_C_C_C_COMPANYID_2);
356 
357                 query.append(_FINDER_COLUMN_G_C_C_C_CLASSNAMEID_2);
358 
359                 query.append(_FINDER_COLUMN_G_C_C_C_CLASSPK_2);
360 
361                 query.append(WorkflowInstanceLinkModelImpl.ORDER_BY_JPQL);
362 
363                 String sql = query.toString();
364 
365                 Query q = session.createQuery(sql);
366 
367                 QueryPos qPos = QueryPos.getInstance(q);
368 
369                 qPos.add(groupId);
370 
371                 qPos.add(companyId);
372 
373                 qPos.add(classNameId);
374 
375                 qPos.add(classPK);
376 
377                 list = q.list();
378             }
379             catch (Exception e) {
380                 throw processException(e);
381             }
382             finally {
383                 if (list == null) {
384                     list = new ArrayList<WorkflowInstanceLink>();
385                 }
386 
387                 cacheResult(list);
388 
389                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_C_C_C,
390                     finderArgs, list);
391 
392                 closeSession(session);
393             }
394         }
395 
396         return list;
397     }
398 
399     public List<WorkflowInstanceLink> findByG_C_C_C(long groupId,
400         long companyId, long classNameId, long classPK, int start, int end)
401         throws SystemException {
402         return findByG_C_C_C(groupId, companyId, classNameId, classPK, start,
403             end, null);
404     }
405 
406     public List<WorkflowInstanceLink> findByG_C_C_C(long groupId,
407         long companyId, long classNameId, long classPK, int start, int end,
408         OrderByComparator orderByComparator) throws SystemException {
409         Object[] finderArgs = new Object[] {
410                 new Long(groupId), new Long(companyId), new Long(classNameId),
411                 new Long(classPK),
412                 
413                 String.valueOf(start), String.valueOf(end),
414                 String.valueOf(orderByComparator)
415             };
416 
417         List<WorkflowInstanceLink> list = (List<WorkflowInstanceLink>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_G_C_C_C,
418                 finderArgs, this);
419 
420         if (list == null) {
421             Session session = null;
422 
423             try {
424                 session = openSession();
425 
426                 StringBundler query = null;
427 
428                 if (orderByComparator != null) {
429                     query = new StringBundler(6 +
430                             (orderByComparator.getOrderByFields().length * 3));
431                 }
432                 else {
433                     query = new StringBundler(6);
434                 }
435 
436                 query.append(_SQL_SELECT_WORKFLOWINSTANCELINK_WHERE);
437 
438                 query.append(_FINDER_COLUMN_G_C_C_C_GROUPID_2);
439 
440                 query.append(_FINDER_COLUMN_G_C_C_C_COMPANYID_2);
441 
442                 query.append(_FINDER_COLUMN_G_C_C_C_CLASSNAMEID_2);
443 
444                 query.append(_FINDER_COLUMN_G_C_C_C_CLASSPK_2);
445 
446                 if (orderByComparator != null) {
447                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
448                         orderByComparator);
449                 }
450 
451                 else {
452                     query.append(WorkflowInstanceLinkModelImpl.ORDER_BY_JPQL);
453                 }
454 
455                 String sql = query.toString();
456 
457                 Query q = session.createQuery(sql);
458 
459                 QueryPos qPos = QueryPos.getInstance(q);
460 
461                 qPos.add(groupId);
462 
463                 qPos.add(companyId);
464 
465                 qPos.add(classNameId);
466 
467                 qPos.add(classPK);
468 
469                 list = (List<WorkflowInstanceLink>)QueryUtil.list(q,
470                         getDialect(), start, end);
471             }
472             catch (Exception e) {
473                 throw processException(e);
474             }
475             finally {
476                 if (list == null) {
477                     list = new ArrayList<WorkflowInstanceLink>();
478                 }
479 
480                 cacheResult(list);
481 
482                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_G_C_C_C,
483                     finderArgs, list);
484 
485                 closeSession(session);
486             }
487         }
488 
489         return list;
490     }
491 
492     public WorkflowInstanceLink findByG_C_C_C_First(long groupId,
493         long companyId, long classNameId, long classPK,
494         OrderByComparator orderByComparator)
495         throws NoSuchWorkflowInstanceLinkException, SystemException {
496         List<WorkflowInstanceLink> list = findByG_C_C_C(groupId, companyId,
497                 classNameId, classPK, 0, 1, orderByComparator);
498 
499         if (list.isEmpty()) {
500             StringBundler msg = new StringBundler(10);
501 
502             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
503 
504             msg.append("groupId=");
505             msg.append(groupId);
506 
507             msg.append(", companyId=");
508             msg.append(companyId);
509 
510             msg.append(", classNameId=");
511             msg.append(classNameId);
512 
513             msg.append(", classPK=");
514             msg.append(classPK);
515 
516             msg.append(StringPool.CLOSE_CURLY_BRACE);
517 
518             throw new NoSuchWorkflowInstanceLinkException(msg.toString());
519         }
520         else {
521             return list.get(0);
522         }
523     }
524 
525     public WorkflowInstanceLink findByG_C_C_C_Last(long groupId,
526         long companyId, long classNameId, long classPK,
527         OrderByComparator orderByComparator)
528         throws NoSuchWorkflowInstanceLinkException, SystemException {
529         int count = countByG_C_C_C(groupId, companyId, classNameId, classPK);
530 
531         List<WorkflowInstanceLink> list = findByG_C_C_C(groupId, companyId,
532                 classNameId, classPK, count - 1, count, orderByComparator);
533 
534         if (list.isEmpty()) {
535             StringBundler msg = new StringBundler(10);
536 
537             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
538 
539             msg.append("groupId=");
540             msg.append(groupId);
541 
542             msg.append(", companyId=");
543             msg.append(companyId);
544 
545             msg.append(", classNameId=");
546             msg.append(classNameId);
547 
548             msg.append(", classPK=");
549             msg.append(classPK);
550 
551             msg.append(StringPool.CLOSE_CURLY_BRACE);
552 
553             throw new NoSuchWorkflowInstanceLinkException(msg.toString());
554         }
555         else {
556             return list.get(0);
557         }
558     }
559 
560     public WorkflowInstanceLink[] findByG_C_C_C_PrevAndNext(
561         long workflowInstanceLinkId, long groupId, long companyId,
562         long classNameId, long classPK, OrderByComparator orderByComparator)
563         throws NoSuchWorkflowInstanceLinkException, SystemException {
564         WorkflowInstanceLink workflowInstanceLink = findByPrimaryKey(workflowInstanceLinkId);
565 
566         int count = countByG_C_C_C(groupId, companyId, classNameId, classPK);
567 
568         Session session = null;
569 
570         try {
571             session = openSession();
572 
573             StringBundler query = null;
574 
575             if (orderByComparator != null) {
576                 query = new StringBundler(6 +
577                         (orderByComparator.getOrderByFields().length * 3));
578             }
579             else {
580                 query = new StringBundler(6);
581             }
582 
583             query.append(_SQL_SELECT_WORKFLOWINSTANCELINK_WHERE);
584 
585             query.append(_FINDER_COLUMN_G_C_C_C_GROUPID_2);
586 
587             query.append(_FINDER_COLUMN_G_C_C_C_COMPANYID_2);
588 
589             query.append(_FINDER_COLUMN_G_C_C_C_CLASSNAMEID_2);
590 
591             query.append(_FINDER_COLUMN_G_C_C_C_CLASSPK_2);
592 
593             if (orderByComparator != null) {
594                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
595                     orderByComparator);
596             }
597 
598             else {
599                 query.append(WorkflowInstanceLinkModelImpl.ORDER_BY_JPQL);
600             }
601 
602             String sql = query.toString();
603 
604             Query q = session.createQuery(sql);
605 
606             QueryPos qPos = QueryPos.getInstance(q);
607 
608             qPos.add(groupId);
609 
610             qPos.add(companyId);
611 
612             qPos.add(classNameId);
613 
614             qPos.add(classPK);
615 
616             Object[] objArray = QueryUtil.getPrevAndNext(q, count,
617                     orderByComparator, workflowInstanceLink);
618 
619             WorkflowInstanceLink[] array = new WorkflowInstanceLinkImpl[3];
620 
621             array[0] = (WorkflowInstanceLink)objArray[0];
622             array[1] = (WorkflowInstanceLink)objArray[1];
623             array[2] = (WorkflowInstanceLink)objArray[2];
624 
625             return array;
626         }
627         catch (Exception e) {
628             throw processException(e);
629         }
630         finally {
631             closeSession(session);
632         }
633     }
634 
635     public List<WorkflowInstanceLink> findAll() throws SystemException {
636         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
637     }
638 
639     public List<WorkflowInstanceLink> findAll(int start, int end)
640         throws SystemException {
641         return findAll(start, end, null);
642     }
643 
644     public List<WorkflowInstanceLink> findAll(int start, int end,
645         OrderByComparator orderByComparator) throws SystemException {
646         Object[] finderArgs = new Object[] {
647                 String.valueOf(start), String.valueOf(end),
648                 String.valueOf(orderByComparator)
649             };
650 
651         List<WorkflowInstanceLink> list = (List<WorkflowInstanceLink>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
652                 finderArgs, this);
653 
654         if (list == null) {
655             Session session = null;
656 
657             try {
658                 session = openSession();
659 
660                 StringBundler query = null;
661                 String sql = null;
662 
663                 if (orderByComparator != null) {
664                     query = new StringBundler(2 +
665                             (orderByComparator.getOrderByFields().length * 3));
666 
667                     query.append(_SQL_SELECT_WORKFLOWINSTANCELINK);
668 
669                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
670                         orderByComparator);
671 
672                     sql = query.toString();
673                 }
674 
675                 else {
676                     sql = _SQL_SELECT_WORKFLOWINSTANCELINK.concat(WorkflowInstanceLinkModelImpl.ORDER_BY_JPQL);
677                 }
678 
679                 Query q = session.createQuery(sql);
680 
681                 if (orderByComparator == null) {
682                     list = (List<WorkflowInstanceLink>)QueryUtil.list(q,
683                             getDialect(), start, end, false);
684 
685                     Collections.sort(list);
686                 }
687                 else {
688                     list = (List<WorkflowInstanceLink>)QueryUtil.list(q,
689                             getDialect(), start, end);
690                 }
691             }
692             catch (Exception e) {
693                 throw processException(e);
694             }
695             finally {
696                 if (list == null) {
697                     list = new ArrayList<WorkflowInstanceLink>();
698                 }
699 
700                 cacheResult(list);
701 
702                 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
703 
704                 closeSession(session);
705             }
706         }
707 
708         return list;
709     }
710 
711     public void removeByG_C_C_C(long groupId, long companyId, long classNameId,
712         long classPK) throws SystemException {
713         for (WorkflowInstanceLink workflowInstanceLink : findByG_C_C_C(
714                 groupId, companyId, classNameId, classPK)) {
715             remove(workflowInstanceLink);
716         }
717     }
718 
719     public void removeAll() throws SystemException {
720         for (WorkflowInstanceLink workflowInstanceLink : findAll()) {
721             remove(workflowInstanceLink);
722         }
723     }
724 
725     public int countByG_C_C_C(long groupId, long companyId, long classNameId,
726         long classPK) throws SystemException {
727         Object[] finderArgs = new Object[] {
728                 new Long(groupId), new Long(companyId), new Long(classNameId),
729                 new Long(classPK)
730             };
731 
732         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_C_C,
733                 finderArgs, this);
734 
735         if (count == null) {
736             Session session = null;
737 
738             try {
739                 session = openSession();
740 
741                 StringBundler query = new StringBundler(5);
742 
743                 query.append(_SQL_COUNT_WORKFLOWINSTANCELINK_WHERE);
744 
745                 query.append(_FINDER_COLUMN_G_C_C_C_GROUPID_2);
746 
747                 query.append(_FINDER_COLUMN_G_C_C_C_COMPANYID_2);
748 
749                 query.append(_FINDER_COLUMN_G_C_C_C_CLASSNAMEID_2);
750 
751                 query.append(_FINDER_COLUMN_G_C_C_C_CLASSPK_2);
752 
753                 String sql = query.toString();
754 
755                 Query q = session.createQuery(sql);
756 
757                 QueryPos qPos = QueryPos.getInstance(q);
758 
759                 qPos.add(groupId);
760 
761                 qPos.add(companyId);
762 
763                 qPos.add(classNameId);
764 
765                 qPos.add(classPK);
766 
767                 count = (Long)q.uniqueResult();
768             }
769             catch (Exception e) {
770                 throw processException(e);
771             }
772             finally {
773                 if (count == null) {
774                     count = Long.valueOf(0);
775                 }
776 
777                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_C_C,
778                     finderArgs, count);
779 
780                 closeSession(session);
781             }
782         }
783 
784         return count.intValue();
785     }
786 
787     public int countAll() throws SystemException {
788         Object[] finderArgs = new Object[0];
789 
790         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
791                 finderArgs, this);
792 
793         if (count == null) {
794             Session session = null;
795 
796             try {
797                 session = openSession();
798 
799                 Query q = session.createQuery(_SQL_COUNT_WORKFLOWINSTANCELINK);
800 
801                 count = (Long)q.uniqueResult();
802             }
803             catch (Exception e) {
804                 throw processException(e);
805             }
806             finally {
807                 if (count == null) {
808                     count = Long.valueOf(0);
809                 }
810 
811                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
812                     count);
813 
814                 closeSession(session);
815             }
816         }
817 
818         return count.intValue();
819     }
820 
821     public void afterPropertiesSet() {
822         String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
823                     com.liferay.portal.util.PropsUtil.get(
824                         "value.object.listener.com.liferay.portal.model.WorkflowInstanceLink")));
825 
826         if (listenerClassNames.length > 0) {
827             try {
828                 List<ModelListener<WorkflowInstanceLink>> listenersList = new ArrayList<ModelListener<WorkflowInstanceLink>>();
829 
830                 for (String listenerClassName : listenerClassNames) {
831                     listenersList.add((ModelListener<WorkflowInstanceLink>)Class.forName(
832                             listenerClassName).newInstance());
833                 }
834 
835                 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
836             }
837             catch (Exception e) {
838                 _log.error(e);
839             }
840         }
841     }
842 
843     @BeanReference(type = AccountPersistence.class)
844     protected AccountPersistence accountPersistence;
845     @BeanReference(type = AddressPersistence.class)
846     protected AddressPersistence addressPersistence;
847     @BeanReference(type = BrowserTrackerPersistence.class)
848     protected BrowserTrackerPersistence browserTrackerPersistence;
849     @BeanReference(type = ClassNamePersistence.class)
850     protected ClassNamePersistence classNamePersistence;
851     @BeanReference(type = CompanyPersistence.class)
852     protected CompanyPersistence companyPersistence;
853     @BeanReference(type = ContactPersistence.class)
854     protected ContactPersistence contactPersistence;
855     @BeanReference(type = CountryPersistence.class)
856     protected CountryPersistence countryPersistence;
857     @BeanReference(type = EmailAddressPersistence.class)
858     protected EmailAddressPersistence emailAddressPersistence;
859     @BeanReference(type = GroupPersistence.class)
860     protected GroupPersistence groupPersistence;
861     @BeanReference(type = ImagePersistence.class)
862     protected ImagePersistence imagePersistence;
863     @BeanReference(type = LayoutPersistence.class)
864     protected LayoutPersistence layoutPersistence;
865     @BeanReference(type = LayoutPrototypePersistence.class)
866     protected LayoutPrototypePersistence layoutPrototypePersistence;
867     @BeanReference(type = LayoutSetPersistence.class)
868     protected LayoutSetPersistence layoutSetPersistence;
869     @BeanReference(type = LayoutSetPrototypePersistence.class)
870     protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
871     @BeanReference(type = ListTypePersistence.class)
872     protected ListTypePersistence listTypePersistence;
873     @BeanReference(type = LockPersistence.class)
874     protected LockPersistence lockPersistence;
875     @BeanReference(type = MembershipRequestPersistence.class)
876     protected MembershipRequestPersistence membershipRequestPersistence;
877     @BeanReference(type = OrganizationPersistence.class)
878     protected OrganizationPersistence organizationPersistence;
879     @BeanReference(type = OrgGroupPermissionPersistence.class)
880     protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
881     @BeanReference(type = OrgGroupRolePersistence.class)
882     protected OrgGroupRolePersistence orgGroupRolePersistence;
883     @BeanReference(type = OrgLaborPersistence.class)
884     protected OrgLaborPersistence orgLaborPersistence;
885     @BeanReference(type = PasswordPolicyPersistence.class)
886     protected PasswordPolicyPersistence passwordPolicyPersistence;
887     @BeanReference(type = PasswordPolicyRelPersistence.class)
888     protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
889     @BeanReference(type = PasswordTrackerPersistence.class)
890     protected PasswordTrackerPersistence passwordTrackerPersistence;
891     @BeanReference(type = PermissionPersistence.class)
892     protected PermissionPersistence permissionPersistence;
893     @BeanReference(type = PhonePersistence.class)
894     protected PhonePersistence phonePersistence;
895     @BeanReference(type = PluginSettingPersistence.class)
896     protected PluginSettingPersistence pluginSettingPersistence;
897     @BeanReference(type = PortletPersistence.class)
898     protected PortletPersistence portletPersistence;
899     @BeanReference(type = PortletItemPersistence.class)
900     protected PortletItemPersistence portletItemPersistence;
901     @BeanReference(type = PortletPreferencesPersistence.class)
902     protected PortletPreferencesPersistence portletPreferencesPersistence;
903     @BeanReference(type = RegionPersistence.class)
904     protected RegionPersistence regionPersistence;
905     @BeanReference(type = ReleasePersistence.class)
906     protected ReleasePersistence releasePersistence;
907     @BeanReference(type = ResourcePersistence.class)
908     protected ResourcePersistence resourcePersistence;
909     @BeanReference(type = ResourceActionPersistence.class)
910     protected ResourceActionPersistence resourceActionPersistence;
911     @BeanReference(type = ResourceCodePersistence.class)
912     protected ResourceCodePersistence resourceCodePersistence;
913     @BeanReference(type = ResourcePermissionPersistence.class)
914     protected ResourcePermissionPersistence resourcePermissionPersistence;
915     @BeanReference(type = RolePersistence.class)
916     protected RolePersistence rolePersistence;
917     @BeanReference(type = ServiceComponentPersistence.class)
918     protected ServiceComponentPersistence serviceComponentPersistence;
919     @BeanReference(type = ShardPersistence.class)
920     protected ShardPersistence shardPersistence;
921     @BeanReference(type = SubscriptionPersistence.class)
922     protected SubscriptionPersistence subscriptionPersistence;
923     @BeanReference(type = TeamPersistence.class)
924     protected TeamPersistence teamPersistence;
925     @BeanReference(type = UserPersistence.class)
926     protected UserPersistence userPersistence;
927     @BeanReference(type = UserGroupPersistence.class)
928     protected UserGroupPersistence userGroupPersistence;
929     @BeanReference(type = UserGroupGroupRolePersistence.class)
930     protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
931     @BeanReference(type = UserGroupRolePersistence.class)
932     protected UserGroupRolePersistence userGroupRolePersistence;
933     @BeanReference(type = UserIdMapperPersistence.class)
934     protected UserIdMapperPersistence userIdMapperPersistence;
935     @BeanReference(type = UserTrackerPersistence.class)
936     protected UserTrackerPersistence userTrackerPersistence;
937     @BeanReference(type = UserTrackerPathPersistence.class)
938     protected UserTrackerPathPersistence userTrackerPathPersistence;
939     @BeanReference(type = WebDAVPropsPersistence.class)
940     protected WebDAVPropsPersistence webDAVPropsPersistence;
941     @BeanReference(type = WebsitePersistence.class)
942     protected WebsitePersistence websitePersistence;
943     @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
944     protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
945     @BeanReference(type = WorkflowInstanceLinkPersistence.class)
946     protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
947     private static final String _SQL_SELECT_WORKFLOWINSTANCELINK = "SELECT workflowInstanceLink FROM WorkflowInstanceLink workflowInstanceLink";
948     private static final String _SQL_SELECT_WORKFLOWINSTANCELINK_WHERE = "SELECT workflowInstanceLink FROM WorkflowInstanceLink workflowInstanceLink WHERE ";
949     private static final String _SQL_COUNT_WORKFLOWINSTANCELINK = "SELECT COUNT(workflowInstanceLink) FROM WorkflowInstanceLink workflowInstanceLink";
950     private static final String _SQL_COUNT_WORKFLOWINSTANCELINK_WHERE = "SELECT COUNT(workflowInstanceLink) FROM WorkflowInstanceLink workflowInstanceLink WHERE ";
951     private static final String _FINDER_COLUMN_G_C_C_C_GROUPID_2 = "workflowInstanceLink.groupId = ? AND ";
952     private static final String _FINDER_COLUMN_G_C_C_C_COMPANYID_2 = "workflowInstanceLink.companyId = ? AND ";
953     private static final String _FINDER_COLUMN_G_C_C_C_CLASSNAMEID_2 = "workflowInstanceLink.classNameId = ? AND ";
954     private static final String _FINDER_COLUMN_G_C_C_C_CLASSPK_2 = "workflowInstanceLink.classPK = ?";
955     private static final String _ORDER_BY_ENTITY_ALIAS = "workflowInstanceLink.";
956     private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WorkflowInstanceLink exists with the primary key ";
957     private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WorkflowInstanceLink exists with the key {";
958     private static Log _log = LogFactoryUtil.getLog(WorkflowInstanceLinkPersistenceImpl.class);
959 }