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