001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.NoSuchWorkflowInstanceLinkException;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.UnmodifiableList;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.model.WorkflowInstanceLink;
040    import com.liferay.portal.model.impl.WorkflowInstanceLinkImpl;
041    import com.liferay.portal.model.impl.WorkflowInstanceLinkModelImpl;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import java.io.Serializable;
045    
046    import java.util.ArrayList;
047    import java.util.Collections;
048    import java.util.List;
049    
050    /**
051     * The persistence implementation for the workflow instance link service.
052     *
053     * <p>
054     * Caching information and settings can be found in <code>portal.properties</code>
055     * </p>
056     *
057     * @author Brian Wing Shun Chan
058     * @see WorkflowInstanceLinkPersistence
059     * @see WorkflowInstanceLinkUtil
060     * @generated
061     */
062    public class WorkflowInstanceLinkPersistenceImpl extends BasePersistenceImpl<WorkflowInstanceLink>
063            implements WorkflowInstanceLinkPersistence {
064            /*
065             * NOTE FOR DEVELOPERS:
066             *
067             * Never modify or reference this class directly. Always use {@link WorkflowInstanceLinkUtil} to access the workflow instance link persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
068             */
069            public static final String FINDER_CLASS_NAME_ENTITY = WorkflowInstanceLinkImpl.class.getName();
070            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071                    ".List1";
072            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List2";
074            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
075                            WorkflowInstanceLinkModelImpl.FINDER_CACHE_ENABLED,
076                            WorkflowInstanceLinkImpl.class,
077                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
078            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
079                            WorkflowInstanceLinkModelImpl.FINDER_CACHE_ENABLED,
080                            WorkflowInstanceLinkImpl.class,
081                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
082            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
083                            WorkflowInstanceLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
084                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
085            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C_C = new FinderPath(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
086                            WorkflowInstanceLinkModelImpl.FINDER_CACHE_ENABLED,
087                            WorkflowInstanceLinkImpl.class,
088                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_C_C",
089                            new String[] {
090                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
091                                    Long.class.getName(),
092                                    
093                            Integer.class.getName(), Integer.class.getName(),
094                                    OrderByComparator.class.getName()
095                            });
096            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_C =
097                    new FinderPath(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
098                            WorkflowInstanceLinkModelImpl.FINDER_CACHE_ENABLED,
099                            WorkflowInstanceLinkImpl.class,
100                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_C_C",
101                            new String[] {
102                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
103                                    Long.class.getName()
104                            },
105                            WorkflowInstanceLinkModelImpl.GROUPID_COLUMN_BITMASK |
106                            WorkflowInstanceLinkModelImpl.COMPANYID_COLUMN_BITMASK |
107                            WorkflowInstanceLinkModelImpl.CLASSNAMEID_COLUMN_BITMASK |
108                            WorkflowInstanceLinkModelImpl.CLASSPK_COLUMN_BITMASK |
109                            WorkflowInstanceLinkModelImpl.CREATEDATE_COLUMN_BITMASK);
110            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_C_C = new FinderPath(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
111                            WorkflowInstanceLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
112                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_C_C",
113                            new String[] {
114                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
115                                    Long.class.getName()
116                            });
117    
118            /**
119             * Returns all the workflow instance links where groupId = &#63; and companyId = &#63; and classNameId = &#63; and classPK = &#63;.
120             *
121             * @param groupId the group ID
122             * @param companyId the company ID
123             * @param classNameId the class name ID
124             * @param classPK the class p k
125             * @return the matching workflow instance links
126             * @throws SystemException if a system exception occurred
127             */
128            public List<WorkflowInstanceLink> findByG_C_C_C(long groupId,
129                    long companyId, long classNameId, long classPK)
130                    throws SystemException {
131                    return findByG_C_C_C(groupId, companyId, classNameId, classPK,
132                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
133            }
134    
135            /**
136             * Returns a range of all the workflow instance links where groupId = &#63; and companyId = &#63; and classNameId = &#63; and classPK = &#63;.
137             *
138             * <p>
139             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.WorkflowInstanceLinkModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
140             * </p>
141             *
142             * @param groupId the group ID
143             * @param companyId the company ID
144             * @param classNameId the class name ID
145             * @param classPK the class p k
146             * @param start the lower bound of the range of workflow instance links
147             * @param end the upper bound of the range of workflow instance links (not inclusive)
148             * @return the range of matching workflow instance links
149             * @throws SystemException if a system exception occurred
150             */
151            public List<WorkflowInstanceLink> findByG_C_C_C(long groupId,
152                    long companyId, long classNameId, long classPK, int start, int end)
153                    throws SystemException {
154                    return findByG_C_C_C(groupId, companyId, classNameId, classPK, start,
155                            end, null);
156            }
157    
158            /**
159             * Returns an ordered range of all the workflow instance links where groupId = &#63; and companyId = &#63; and classNameId = &#63; and classPK = &#63;.
160             *
161             * <p>
162             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.WorkflowInstanceLinkModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
163             * </p>
164             *
165             * @param groupId the group ID
166             * @param companyId the company ID
167             * @param classNameId the class name ID
168             * @param classPK the class p k
169             * @param start the lower bound of the range of workflow instance links
170             * @param end the upper bound of the range of workflow instance links (not inclusive)
171             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
172             * @return the ordered range of matching workflow instance links
173             * @throws SystemException if a system exception occurred
174             */
175            public List<WorkflowInstanceLink> findByG_C_C_C(long groupId,
176                    long companyId, long classNameId, long classPK, int start, int end,
177                    OrderByComparator orderByComparator) throws SystemException {
178                    boolean pagination = true;
179                    FinderPath finderPath = null;
180                    Object[] finderArgs = null;
181    
182                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
183                                    (orderByComparator == null)) {
184                            pagination = false;
185                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_C;
186                            finderArgs = new Object[] { groupId, companyId, classNameId, classPK };
187                    }
188                    else {
189                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C_C;
190                            finderArgs = new Object[] {
191                                            groupId, companyId, classNameId, classPK,
192                                            
193                                            start, end, orderByComparator
194                                    };
195                    }
196    
197                    List<WorkflowInstanceLink> list = (List<WorkflowInstanceLink>)FinderCacheUtil.getResult(finderPath,
198                                    finderArgs, this);
199    
200                    if ((list != null) && !list.isEmpty()) {
201                            for (WorkflowInstanceLink workflowInstanceLink : list) {
202                                    if ((groupId != workflowInstanceLink.getGroupId()) ||
203                                                    (companyId != workflowInstanceLink.getCompanyId()) ||
204                                                    (classNameId != workflowInstanceLink.getClassNameId()) ||
205                                                    (classPK != workflowInstanceLink.getClassPK())) {
206                                            list = null;
207    
208                                            break;
209                                    }
210                            }
211                    }
212    
213                    if (list == null) {
214                            StringBundler query = null;
215    
216                            if (orderByComparator != null) {
217                                    query = new StringBundler(6 +
218                                                    (orderByComparator.getOrderByFields().length * 3));
219                            }
220                            else {
221                                    query = new StringBundler(6);
222                            }
223    
224                            query.append(_SQL_SELECT_WORKFLOWINSTANCELINK_WHERE);
225    
226                            query.append(_FINDER_COLUMN_G_C_C_C_GROUPID_2);
227    
228                            query.append(_FINDER_COLUMN_G_C_C_C_COMPANYID_2);
229    
230                            query.append(_FINDER_COLUMN_G_C_C_C_CLASSNAMEID_2);
231    
232                            query.append(_FINDER_COLUMN_G_C_C_C_CLASSPK_2);
233    
234                            if (orderByComparator != null) {
235                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
236                                            orderByComparator);
237                            }
238                            else
239                             if (pagination) {
240                                    query.append(WorkflowInstanceLinkModelImpl.ORDER_BY_JPQL);
241                            }
242    
243                            String sql = query.toString();
244    
245                            Session session = null;
246    
247                            try {
248                                    session = openSession();
249    
250                                    Query q = session.createQuery(sql);
251    
252                                    QueryPos qPos = QueryPos.getInstance(q);
253    
254                                    qPos.add(groupId);
255    
256                                    qPos.add(companyId);
257    
258                                    qPos.add(classNameId);
259    
260                                    qPos.add(classPK);
261    
262                                    if (!pagination) {
263                                            list = (List<WorkflowInstanceLink>)QueryUtil.list(q,
264                                                            getDialect(), start, end, false);
265    
266                                            Collections.sort(list);
267    
268                                            list = new UnmodifiableList<WorkflowInstanceLink>(list);
269                                    }
270                                    else {
271                                            list = (List<WorkflowInstanceLink>)QueryUtil.list(q,
272                                                            getDialect(), start, end);
273                                    }
274    
275                                    cacheResult(list);
276    
277                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
278                            }
279                            catch (Exception e) {
280                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
281    
282                                    throw processException(e);
283                            }
284                            finally {
285                                    closeSession(session);
286                            }
287                    }
288    
289                    return list;
290            }
291    
292            /**
293             * Returns the first workflow instance link in the ordered set where groupId = &#63; and companyId = &#63; and classNameId = &#63; and classPK = &#63;.
294             *
295             * @param groupId the group ID
296             * @param companyId the company ID
297             * @param classNameId the class name ID
298             * @param classPK the class p k
299             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
300             * @return the first matching workflow instance link
301             * @throws com.liferay.portal.NoSuchWorkflowInstanceLinkException if a matching workflow instance link could not be found
302             * @throws SystemException if a system exception occurred
303             */
304            public WorkflowInstanceLink findByG_C_C_C_First(long groupId,
305                    long companyId, long classNameId, long classPK,
306                    OrderByComparator orderByComparator)
307                    throws NoSuchWorkflowInstanceLinkException, SystemException {
308                    WorkflowInstanceLink workflowInstanceLink = fetchByG_C_C_C_First(groupId,
309                                    companyId, classNameId, classPK, orderByComparator);
310    
311                    if (workflowInstanceLink != null) {
312                            return workflowInstanceLink;
313                    }
314    
315                    StringBundler msg = new StringBundler(10);
316    
317                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
318    
319                    msg.append("groupId=");
320                    msg.append(groupId);
321    
322                    msg.append(", companyId=");
323                    msg.append(companyId);
324    
325                    msg.append(", classNameId=");
326                    msg.append(classNameId);
327    
328                    msg.append(", classPK=");
329                    msg.append(classPK);
330    
331                    msg.append(StringPool.CLOSE_CURLY_BRACE);
332    
333                    throw new NoSuchWorkflowInstanceLinkException(msg.toString());
334            }
335    
336            /**
337             * Returns the first workflow instance link in the ordered set where groupId = &#63; and companyId = &#63; and classNameId = &#63; and classPK = &#63;.
338             *
339             * @param groupId the group ID
340             * @param companyId the company ID
341             * @param classNameId the class name ID
342             * @param classPK the class p k
343             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
344             * @return the first matching workflow instance link, or <code>null</code> if a matching workflow instance link could not be found
345             * @throws SystemException if a system exception occurred
346             */
347            public WorkflowInstanceLink fetchByG_C_C_C_First(long groupId,
348                    long companyId, long classNameId, long classPK,
349                    OrderByComparator orderByComparator) throws SystemException {
350                    List<WorkflowInstanceLink> list = findByG_C_C_C(groupId, companyId,
351                                    classNameId, classPK, 0, 1, orderByComparator);
352    
353                    if (!list.isEmpty()) {
354                            return list.get(0);
355                    }
356    
357                    return null;
358            }
359    
360            /**
361             * Returns the last workflow instance link in the ordered set where groupId = &#63; and companyId = &#63; and classNameId = &#63; and classPK = &#63;.
362             *
363             * @param groupId the group ID
364             * @param companyId the company ID
365             * @param classNameId the class name ID
366             * @param classPK the class p k
367             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
368             * @return the last matching workflow instance link
369             * @throws com.liferay.portal.NoSuchWorkflowInstanceLinkException if a matching workflow instance link could not be found
370             * @throws SystemException if a system exception occurred
371             */
372            public WorkflowInstanceLink findByG_C_C_C_Last(long groupId,
373                    long companyId, long classNameId, long classPK,
374                    OrderByComparator orderByComparator)
375                    throws NoSuchWorkflowInstanceLinkException, SystemException {
376                    WorkflowInstanceLink workflowInstanceLink = fetchByG_C_C_C_Last(groupId,
377                                    companyId, classNameId, classPK, orderByComparator);
378    
379                    if (workflowInstanceLink != null) {
380                            return workflowInstanceLink;
381                    }
382    
383                    StringBundler msg = new StringBundler(10);
384    
385                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
386    
387                    msg.append("groupId=");
388                    msg.append(groupId);
389    
390                    msg.append(", companyId=");
391                    msg.append(companyId);
392    
393                    msg.append(", classNameId=");
394                    msg.append(classNameId);
395    
396                    msg.append(", classPK=");
397                    msg.append(classPK);
398    
399                    msg.append(StringPool.CLOSE_CURLY_BRACE);
400    
401                    throw new NoSuchWorkflowInstanceLinkException(msg.toString());
402            }
403    
404            /**
405             * Returns the last workflow instance link in the ordered set where groupId = &#63; and companyId = &#63; and classNameId = &#63; and classPK = &#63;.
406             *
407             * @param groupId the group ID
408             * @param companyId the company ID
409             * @param classNameId the class name ID
410             * @param classPK the class p k
411             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
412             * @return the last matching workflow instance link, or <code>null</code> if a matching workflow instance link could not be found
413             * @throws SystemException if a system exception occurred
414             */
415            public WorkflowInstanceLink fetchByG_C_C_C_Last(long groupId,
416                    long companyId, long classNameId, long classPK,
417                    OrderByComparator orderByComparator) throws SystemException {
418                    int count = countByG_C_C_C(groupId, companyId, classNameId, classPK);
419    
420                    List<WorkflowInstanceLink> list = findByG_C_C_C(groupId, companyId,
421                                    classNameId, classPK, count - 1, count, orderByComparator);
422    
423                    if (!list.isEmpty()) {
424                            return list.get(0);
425                    }
426    
427                    return null;
428            }
429    
430            /**
431             * Returns the workflow instance links before and after the current workflow instance link in the ordered set where groupId = &#63; and companyId = &#63; and classNameId = &#63; and classPK = &#63;.
432             *
433             * @param workflowInstanceLinkId the primary key of the current workflow instance link
434             * @param groupId the group ID
435             * @param companyId the company ID
436             * @param classNameId the class name ID
437             * @param classPK the class p k
438             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
439             * @return the previous, current, and next workflow instance link
440             * @throws com.liferay.portal.NoSuchWorkflowInstanceLinkException if a workflow instance link with the primary key could not be found
441             * @throws SystemException if a system exception occurred
442             */
443            public WorkflowInstanceLink[] findByG_C_C_C_PrevAndNext(
444                    long workflowInstanceLinkId, long groupId, long companyId,
445                    long classNameId, long classPK, OrderByComparator orderByComparator)
446                    throws NoSuchWorkflowInstanceLinkException, SystemException {
447                    WorkflowInstanceLink workflowInstanceLink = findByPrimaryKey(workflowInstanceLinkId);
448    
449                    Session session = null;
450    
451                    try {
452                            session = openSession();
453    
454                            WorkflowInstanceLink[] array = new WorkflowInstanceLinkImpl[3];
455    
456                            array[0] = getByG_C_C_C_PrevAndNext(session, workflowInstanceLink,
457                                            groupId, companyId, classNameId, classPK,
458                                            orderByComparator, true);
459    
460                            array[1] = workflowInstanceLink;
461    
462                            array[2] = getByG_C_C_C_PrevAndNext(session, workflowInstanceLink,
463                                            groupId, companyId, classNameId, classPK,
464                                            orderByComparator, false);
465    
466                            return array;
467                    }
468                    catch (Exception e) {
469                            throw processException(e);
470                    }
471                    finally {
472                            closeSession(session);
473                    }
474            }
475    
476            protected WorkflowInstanceLink getByG_C_C_C_PrevAndNext(Session session,
477                    WorkflowInstanceLink workflowInstanceLink, long groupId,
478                    long companyId, long classNameId, long classPK,
479                    OrderByComparator orderByComparator, boolean previous) {
480                    StringBundler query = null;
481    
482                    if (orderByComparator != null) {
483                            query = new StringBundler(6 +
484                                            (orderByComparator.getOrderByFields().length * 6));
485                    }
486                    else {
487                            query = new StringBundler(3);
488                    }
489    
490                    query.append(_SQL_SELECT_WORKFLOWINSTANCELINK_WHERE);
491    
492                    query.append(_FINDER_COLUMN_G_C_C_C_GROUPID_2);
493    
494                    query.append(_FINDER_COLUMN_G_C_C_C_COMPANYID_2);
495    
496                    query.append(_FINDER_COLUMN_G_C_C_C_CLASSNAMEID_2);
497    
498                    query.append(_FINDER_COLUMN_G_C_C_C_CLASSPK_2);
499    
500                    if (orderByComparator != null) {
501                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
502    
503                            if (orderByConditionFields.length > 0) {
504                                    query.append(WHERE_AND);
505                            }
506    
507                            for (int i = 0; i < orderByConditionFields.length; i++) {
508                                    query.append(_ORDER_BY_ENTITY_ALIAS);
509                                    query.append(orderByConditionFields[i]);
510    
511                                    if ((i + 1) < orderByConditionFields.length) {
512                                            if (orderByComparator.isAscending() ^ previous) {
513                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
514                                            }
515                                            else {
516                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
517                                            }
518                                    }
519                                    else {
520                                            if (orderByComparator.isAscending() ^ previous) {
521                                                    query.append(WHERE_GREATER_THAN);
522                                            }
523                                            else {
524                                                    query.append(WHERE_LESSER_THAN);
525                                            }
526                                    }
527                            }
528    
529                            query.append(ORDER_BY_CLAUSE);
530    
531                            String[] orderByFields = orderByComparator.getOrderByFields();
532    
533                            for (int i = 0; i < orderByFields.length; i++) {
534                                    query.append(_ORDER_BY_ENTITY_ALIAS);
535                                    query.append(orderByFields[i]);
536    
537                                    if ((i + 1) < orderByFields.length) {
538                                            if (orderByComparator.isAscending() ^ previous) {
539                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
540                                            }
541                                            else {
542                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
543                                            }
544                                    }
545                                    else {
546                                            if (orderByComparator.isAscending() ^ previous) {
547                                                    query.append(ORDER_BY_ASC);
548                                            }
549                                            else {
550                                                    query.append(ORDER_BY_DESC);
551                                            }
552                                    }
553                            }
554                    }
555                    else {
556                            query.append(WorkflowInstanceLinkModelImpl.ORDER_BY_JPQL);
557                    }
558    
559                    String sql = query.toString();
560    
561                    Query q = session.createQuery(sql);
562    
563                    q.setFirstResult(0);
564                    q.setMaxResults(2);
565    
566                    QueryPos qPos = QueryPos.getInstance(q);
567    
568                    qPos.add(groupId);
569    
570                    qPos.add(companyId);
571    
572                    qPos.add(classNameId);
573    
574                    qPos.add(classPK);
575    
576                    if (orderByComparator != null) {
577                            Object[] values = orderByComparator.getOrderByConditionValues(workflowInstanceLink);
578    
579                            for (Object value : values) {
580                                    qPos.add(value);
581                            }
582                    }
583    
584                    List<WorkflowInstanceLink> list = q.list();
585    
586                    if (list.size() == 2) {
587                            return list.get(1);
588                    }
589                    else {
590                            return null;
591                    }
592            }
593    
594            /**
595             * Removes all the workflow instance links where groupId = &#63; and companyId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
596             *
597             * @param groupId the group ID
598             * @param companyId the company ID
599             * @param classNameId the class name ID
600             * @param classPK the class p k
601             * @throws SystemException if a system exception occurred
602             */
603            public void removeByG_C_C_C(long groupId, long companyId, long classNameId,
604                    long classPK) throws SystemException {
605                    for (WorkflowInstanceLink workflowInstanceLink : findByG_C_C_C(
606                                    groupId, companyId, classNameId, classPK, QueryUtil.ALL_POS,
607                                    QueryUtil.ALL_POS, null)) {
608                            remove(workflowInstanceLink);
609                    }
610            }
611    
612            /**
613             * Returns the number of workflow instance links where groupId = &#63; and companyId = &#63; and classNameId = &#63; and classPK = &#63;.
614             *
615             * @param groupId the group ID
616             * @param companyId the company ID
617             * @param classNameId the class name ID
618             * @param classPK the class p k
619             * @return the number of matching workflow instance links
620             * @throws SystemException if a system exception occurred
621             */
622            public int countByG_C_C_C(long groupId, long companyId, long classNameId,
623                    long classPK) throws SystemException {
624                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_C_C;
625    
626                    Object[] finderArgs = new Object[] {
627                                    groupId, companyId, classNameId, classPK
628                            };
629    
630                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
631                                    this);
632    
633                    if (count == null) {
634                            StringBundler query = new StringBundler(5);
635    
636                            query.append(_SQL_COUNT_WORKFLOWINSTANCELINK_WHERE);
637    
638                            query.append(_FINDER_COLUMN_G_C_C_C_GROUPID_2);
639    
640                            query.append(_FINDER_COLUMN_G_C_C_C_COMPANYID_2);
641    
642                            query.append(_FINDER_COLUMN_G_C_C_C_CLASSNAMEID_2);
643    
644                            query.append(_FINDER_COLUMN_G_C_C_C_CLASSPK_2);
645    
646                            String sql = query.toString();
647    
648                            Session session = null;
649    
650                            try {
651                                    session = openSession();
652    
653                                    Query q = session.createQuery(sql);
654    
655                                    QueryPos qPos = QueryPos.getInstance(q);
656    
657                                    qPos.add(groupId);
658    
659                                    qPos.add(companyId);
660    
661                                    qPos.add(classNameId);
662    
663                                    qPos.add(classPK);
664    
665                                    count = (Long)q.uniqueResult();
666    
667                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
668                            }
669                            catch (Exception e) {
670                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
671    
672                                    throw processException(e);
673                            }
674                            finally {
675                                    closeSession(session);
676                            }
677                    }
678    
679                    return count.intValue();
680            }
681    
682            private static final String _FINDER_COLUMN_G_C_C_C_GROUPID_2 = "workflowInstanceLink.groupId = ? AND ";
683            private static final String _FINDER_COLUMN_G_C_C_C_COMPANYID_2 = "workflowInstanceLink.companyId = ? AND ";
684            private static final String _FINDER_COLUMN_G_C_C_C_CLASSNAMEID_2 = "workflowInstanceLink.classNameId = ? AND ";
685            private static final String _FINDER_COLUMN_G_C_C_C_CLASSPK_2 = "workflowInstanceLink.classPK = ?";
686    
687            /**
688             * Caches the workflow instance link in the entity cache if it is enabled.
689             *
690             * @param workflowInstanceLink the workflow instance link
691             */
692            public void cacheResult(WorkflowInstanceLink workflowInstanceLink) {
693                    EntityCacheUtil.putResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
694                            WorkflowInstanceLinkImpl.class,
695                            workflowInstanceLink.getPrimaryKey(), workflowInstanceLink);
696    
697                    workflowInstanceLink.resetOriginalValues();
698            }
699    
700            /**
701             * Caches the workflow instance links in the entity cache if it is enabled.
702             *
703             * @param workflowInstanceLinks the workflow instance links
704             */
705            public void cacheResult(List<WorkflowInstanceLink> workflowInstanceLinks) {
706                    for (WorkflowInstanceLink workflowInstanceLink : workflowInstanceLinks) {
707                            if (EntityCacheUtil.getResult(
708                                                    WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
709                                                    WorkflowInstanceLinkImpl.class,
710                                                    workflowInstanceLink.getPrimaryKey()) == null) {
711                                    cacheResult(workflowInstanceLink);
712                            }
713                            else {
714                                    workflowInstanceLink.resetOriginalValues();
715                            }
716                    }
717            }
718    
719            /**
720             * Clears the cache for all workflow instance links.
721             *
722             * <p>
723             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
724             * </p>
725             */
726            @Override
727            public void clearCache() {
728                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
729                            CacheRegistryUtil.clear(WorkflowInstanceLinkImpl.class.getName());
730                    }
731    
732                    EntityCacheUtil.clearCache(WorkflowInstanceLinkImpl.class.getName());
733    
734                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
735                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
736                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
737            }
738    
739            /**
740             * Clears the cache for the workflow instance link.
741             *
742             * <p>
743             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
744             * </p>
745             */
746            @Override
747            public void clearCache(WorkflowInstanceLink workflowInstanceLink) {
748                    EntityCacheUtil.removeResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
749                            WorkflowInstanceLinkImpl.class, workflowInstanceLink.getPrimaryKey());
750    
751                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
752                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
753            }
754    
755            @Override
756            public void clearCache(List<WorkflowInstanceLink> workflowInstanceLinks) {
757                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
758                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
759    
760                    for (WorkflowInstanceLink workflowInstanceLink : workflowInstanceLinks) {
761                            EntityCacheUtil.removeResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
762                                    WorkflowInstanceLinkImpl.class,
763                                    workflowInstanceLink.getPrimaryKey());
764                    }
765            }
766    
767            /**
768             * Creates a new workflow instance link with the primary key. Does not add the workflow instance link to the database.
769             *
770             * @param workflowInstanceLinkId the primary key for the new workflow instance link
771             * @return the new workflow instance link
772             */
773            public WorkflowInstanceLink create(long workflowInstanceLinkId) {
774                    WorkflowInstanceLink workflowInstanceLink = new WorkflowInstanceLinkImpl();
775    
776                    workflowInstanceLink.setNew(true);
777                    workflowInstanceLink.setPrimaryKey(workflowInstanceLinkId);
778    
779                    return workflowInstanceLink;
780            }
781    
782            /**
783             * Removes the workflow instance link with the primary key from the database. Also notifies the appropriate model listeners.
784             *
785             * @param workflowInstanceLinkId the primary key of the workflow instance link
786             * @return the workflow instance link that was removed
787             * @throws com.liferay.portal.NoSuchWorkflowInstanceLinkException if a workflow instance link with the primary key could not be found
788             * @throws SystemException if a system exception occurred
789             */
790            public WorkflowInstanceLink remove(long workflowInstanceLinkId)
791                    throws NoSuchWorkflowInstanceLinkException, SystemException {
792                    return remove(Long.valueOf(workflowInstanceLinkId));
793            }
794    
795            /**
796             * Removes the workflow instance link with the primary key from the database. Also notifies the appropriate model listeners.
797             *
798             * @param primaryKey the primary key of the workflow instance link
799             * @return the workflow instance link that was removed
800             * @throws com.liferay.portal.NoSuchWorkflowInstanceLinkException if a workflow instance link with the primary key could not be found
801             * @throws SystemException if a system exception occurred
802             */
803            @Override
804            public WorkflowInstanceLink remove(Serializable primaryKey)
805                    throws NoSuchWorkflowInstanceLinkException, SystemException {
806                    Session session = null;
807    
808                    try {
809                            session = openSession();
810    
811                            WorkflowInstanceLink workflowInstanceLink = (WorkflowInstanceLink)session.get(WorkflowInstanceLinkImpl.class,
812                                            primaryKey);
813    
814                            if (workflowInstanceLink == null) {
815                                    if (_log.isWarnEnabled()) {
816                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
817                                    }
818    
819                                    throw new NoSuchWorkflowInstanceLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
820                                            primaryKey);
821                            }
822    
823                            return remove(workflowInstanceLink);
824                    }
825                    catch (NoSuchWorkflowInstanceLinkException nsee) {
826                            throw nsee;
827                    }
828                    catch (Exception e) {
829                            throw processException(e);
830                    }
831                    finally {
832                            closeSession(session);
833                    }
834            }
835    
836            @Override
837            protected WorkflowInstanceLink removeImpl(
838                    WorkflowInstanceLink workflowInstanceLink) throws SystemException {
839                    workflowInstanceLink = toUnwrappedModel(workflowInstanceLink);
840    
841                    Session session = null;
842    
843                    try {
844                            session = openSession();
845    
846                            if (!session.contains(workflowInstanceLink)) {
847                                    workflowInstanceLink = (WorkflowInstanceLink)session.get(WorkflowInstanceLinkImpl.class,
848                                                    workflowInstanceLink.getPrimaryKeyObj());
849                            }
850    
851                            if (workflowInstanceLink != null) {
852                                    session.delete(workflowInstanceLink);
853                            }
854                    }
855                    catch (Exception e) {
856                            throw processException(e);
857                    }
858                    finally {
859                            closeSession(session);
860                    }
861    
862                    if (workflowInstanceLink != null) {
863                            clearCache(workflowInstanceLink);
864                    }
865    
866                    return workflowInstanceLink;
867            }
868    
869            @Override
870            public WorkflowInstanceLink updateImpl(
871                    com.liferay.portal.model.WorkflowInstanceLink workflowInstanceLink)
872                    throws SystemException {
873                    workflowInstanceLink = toUnwrappedModel(workflowInstanceLink);
874    
875                    boolean isNew = workflowInstanceLink.isNew();
876    
877                    WorkflowInstanceLinkModelImpl workflowInstanceLinkModelImpl = (WorkflowInstanceLinkModelImpl)workflowInstanceLink;
878    
879                    Session session = null;
880    
881                    try {
882                            session = openSession();
883    
884                            if (workflowInstanceLink.isNew()) {
885                                    session.save(workflowInstanceLink);
886    
887                                    workflowInstanceLink.setNew(false);
888                            }
889                            else {
890                                    session.merge(workflowInstanceLink);
891                            }
892                    }
893                    catch (Exception e) {
894                            throw processException(e);
895                    }
896                    finally {
897                            closeSession(session);
898                    }
899    
900                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
901    
902                    if (isNew || !WorkflowInstanceLinkModelImpl.COLUMN_BITMASK_ENABLED) {
903                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
904                    }
905    
906                    else {
907                            if ((workflowInstanceLinkModelImpl.getColumnBitmask() &
908                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_C.getColumnBitmask()) != 0) {
909                                    Object[] args = new Object[] {
910                                                    Long.valueOf(workflowInstanceLinkModelImpl.getOriginalGroupId()),
911                                                    Long.valueOf(workflowInstanceLinkModelImpl.getOriginalCompanyId()),
912                                                    Long.valueOf(workflowInstanceLinkModelImpl.getOriginalClassNameId()),
913                                                    Long.valueOf(workflowInstanceLinkModelImpl.getOriginalClassPK())
914                                            };
915    
916                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C_C, args);
917                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_C,
918                                            args);
919    
920                                    args = new Object[] {
921                                                    Long.valueOf(workflowInstanceLinkModelImpl.getGroupId()),
922                                                    Long.valueOf(workflowInstanceLinkModelImpl.getCompanyId()),
923                                                    Long.valueOf(workflowInstanceLinkModelImpl.getClassNameId()),
924                                                    Long.valueOf(workflowInstanceLinkModelImpl.getClassPK())
925                                            };
926    
927                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C_C, args);
928                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_C,
929                                            args);
930                            }
931                    }
932    
933                    EntityCacheUtil.putResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
934                            WorkflowInstanceLinkImpl.class,
935                            workflowInstanceLink.getPrimaryKey(), workflowInstanceLink);
936    
937                    return workflowInstanceLink;
938            }
939    
940            protected WorkflowInstanceLink toUnwrappedModel(
941                    WorkflowInstanceLink workflowInstanceLink) {
942                    if (workflowInstanceLink instanceof WorkflowInstanceLinkImpl) {
943                            return workflowInstanceLink;
944                    }
945    
946                    WorkflowInstanceLinkImpl workflowInstanceLinkImpl = new WorkflowInstanceLinkImpl();
947    
948                    workflowInstanceLinkImpl.setNew(workflowInstanceLink.isNew());
949                    workflowInstanceLinkImpl.setPrimaryKey(workflowInstanceLink.getPrimaryKey());
950    
951                    workflowInstanceLinkImpl.setWorkflowInstanceLinkId(workflowInstanceLink.getWorkflowInstanceLinkId());
952                    workflowInstanceLinkImpl.setGroupId(workflowInstanceLink.getGroupId());
953                    workflowInstanceLinkImpl.setCompanyId(workflowInstanceLink.getCompanyId());
954                    workflowInstanceLinkImpl.setUserId(workflowInstanceLink.getUserId());
955                    workflowInstanceLinkImpl.setUserName(workflowInstanceLink.getUserName());
956                    workflowInstanceLinkImpl.setCreateDate(workflowInstanceLink.getCreateDate());
957                    workflowInstanceLinkImpl.setModifiedDate(workflowInstanceLink.getModifiedDate());
958                    workflowInstanceLinkImpl.setClassNameId(workflowInstanceLink.getClassNameId());
959                    workflowInstanceLinkImpl.setClassPK(workflowInstanceLink.getClassPK());
960                    workflowInstanceLinkImpl.setWorkflowInstanceId(workflowInstanceLink.getWorkflowInstanceId());
961    
962                    return workflowInstanceLinkImpl;
963            }
964    
965            /**
966             * Returns the workflow instance link with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
967             *
968             * @param primaryKey the primary key of the workflow instance link
969             * @return the workflow instance link
970             * @throws com.liferay.portal.NoSuchModelException if a workflow instance link with the primary key could not be found
971             * @throws SystemException if a system exception occurred
972             */
973            @Override
974            public WorkflowInstanceLink findByPrimaryKey(Serializable primaryKey)
975                    throws NoSuchModelException, SystemException {
976                    return findByPrimaryKey(((Long)primaryKey).longValue());
977            }
978    
979            /**
980             * Returns the workflow instance link with the primary key or throws a {@link com.liferay.portal.NoSuchWorkflowInstanceLinkException} if it could not be found.
981             *
982             * @param workflowInstanceLinkId the primary key of the workflow instance link
983             * @return the workflow instance link
984             * @throws com.liferay.portal.NoSuchWorkflowInstanceLinkException if a workflow instance link with the primary key could not be found
985             * @throws SystemException if a system exception occurred
986             */
987            public WorkflowInstanceLink findByPrimaryKey(long workflowInstanceLinkId)
988                    throws NoSuchWorkflowInstanceLinkException, SystemException {
989                    WorkflowInstanceLink workflowInstanceLink = fetchByPrimaryKey(workflowInstanceLinkId);
990    
991                    if (workflowInstanceLink == null) {
992                            if (_log.isWarnEnabled()) {
993                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
994                                            workflowInstanceLinkId);
995                            }
996    
997                            throw new NoSuchWorkflowInstanceLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
998                                    workflowInstanceLinkId);
999                    }
1000    
1001                    return workflowInstanceLink;
1002            }
1003    
1004            /**
1005             * Returns the workflow instance link with the primary key or returns <code>null</code> if it could not be found.
1006             *
1007             * @param primaryKey the primary key of the workflow instance link
1008             * @return the workflow instance link, or <code>null</code> if a workflow instance link with the primary key could not be found
1009             * @throws SystemException if a system exception occurred
1010             */
1011            @Override
1012            public WorkflowInstanceLink fetchByPrimaryKey(Serializable primaryKey)
1013                    throws SystemException {
1014                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
1015            }
1016    
1017            /**
1018             * Returns the workflow instance link with the primary key or returns <code>null</code> if it could not be found.
1019             *
1020             * @param workflowInstanceLinkId the primary key of the workflow instance link
1021             * @return the workflow instance link, or <code>null</code> if a workflow instance link with the primary key could not be found
1022             * @throws SystemException if a system exception occurred
1023             */
1024            public WorkflowInstanceLink fetchByPrimaryKey(long workflowInstanceLinkId)
1025                    throws SystemException {
1026                    WorkflowInstanceLink workflowInstanceLink = (WorkflowInstanceLink)EntityCacheUtil.getResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
1027                                    WorkflowInstanceLinkImpl.class, workflowInstanceLinkId);
1028    
1029                    if (workflowInstanceLink == _nullWorkflowInstanceLink) {
1030                            return null;
1031                    }
1032    
1033                    if (workflowInstanceLink == null) {
1034                            Session session = null;
1035    
1036                            try {
1037                                    session = openSession();
1038    
1039                                    workflowInstanceLink = (WorkflowInstanceLink)session.get(WorkflowInstanceLinkImpl.class,
1040                                                    Long.valueOf(workflowInstanceLinkId));
1041    
1042                                    if (workflowInstanceLink != null) {
1043                                            cacheResult(workflowInstanceLink);
1044                                    }
1045                                    else {
1046                                            EntityCacheUtil.putResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
1047                                                    WorkflowInstanceLinkImpl.class, workflowInstanceLinkId,
1048                                                    _nullWorkflowInstanceLink);
1049                                    }
1050                            }
1051                            catch (Exception e) {
1052                                    EntityCacheUtil.removeResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
1053                                            WorkflowInstanceLinkImpl.class, workflowInstanceLinkId);
1054    
1055                                    throw processException(e);
1056                            }
1057                            finally {
1058                                    closeSession(session);
1059                            }
1060                    }
1061    
1062                    return workflowInstanceLink;
1063            }
1064    
1065            /**
1066             * Returns all the workflow instance links.
1067             *
1068             * @return the workflow instance links
1069             * @throws SystemException if a system exception occurred
1070             */
1071            public List<WorkflowInstanceLink> findAll() throws SystemException {
1072                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1073            }
1074    
1075            /**
1076             * Returns a range of all the workflow instance links.
1077             *
1078             * <p>
1079             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.WorkflowInstanceLinkModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1080             * </p>
1081             *
1082             * @param start the lower bound of the range of workflow instance links
1083             * @param end the upper bound of the range of workflow instance links (not inclusive)
1084             * @return the range of workflow instance links
1085             * @throws SystemException if a system exception occurred
1086             */
1087            public List<WorkflowInstanceLink> findAll(int start, int end)
1088                    throws SystemException {
1089                    return findAll(start, end, null);
1090            }
1091    
1092            /**
1093             * Returns an ordered range of all the workflow instance links.
1094             *
1095             * <p>
1096             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.WorkflowInstanceLinkModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1097             * </p>
1098             *
1099             * @param start the lower bound of the range of workflow instance links
1100             * @param end the upper bound of the range of workflow instance links (not inclusive)
1101             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1102             * @return the ordered range of workflow instance links
1103             * @throws SystemException if a system exception occurred
1104             */
1105            public List<WorkflowInstanceLink> findAll(int start, int end,
1106                    OrderByComparator orderByComparator) throws SystemException {
1107                    boolean pagination = true;
1108                    FinderPath finderPath = null;
1109                    Object[] finderArgs = null;
1110    
1111                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1112                                    (orderByComparator == null)) {
1113                            pagination = false;
1114                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1115                            finderArgs = FINDER_ARGS_EMPTY;
1116                    }
1117                    else {
1118                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1119                            finderArgs = new Object[] { start, end, orderByComparator };
1120                    }
1121    
1122                    List<WorkflowInstanceLink> list = (List<WorkflowInstanceLink>)FinderCacheUtil.getResult(finderPath,
1123                                    finderArgs, this);
1124    
1125                    if (list == null) {
1126                            StringBundler query = null;
1127                            String sql = null;
1128    
1129                            if (orderByComparator != null) {
1130                                    query = new StringBundler(2 +
1131                                                    (orderByComparator.getOrderByFields().length * 3));
1132    
1133                                    query.append(_SQL_SELECT_WORKFLOWINSTANCELINK);
1134    
1135                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1136                                            orderByComparator);
1137    
1138                                    sql = query.toString();
1139                            }
1140                            else {
1141                                    sql = _SQL_SELECT_WORKFLOWINSTANCELINK;
1142    
1143                                    if (pagination) {
1144                                            sql = sql.concat(WorkflowInstanceLinkModelImpl.ORDER_BY_JPQL);
1145                                    }
1146                            }
1147    
1148                            Session session = null;
1149    
1150                            try {
1151                                    session = openSession();
1152    
1153                                    Query q = session.createQuery(sql);
1154    
1155                                    if (!pagination) {
1156                                            list = (List<WorkflowInstanceLink>)QueryUtil.list(q,
1157                                                            getDialect(), start, end, false);
1158    
1159                                            Collections.sort(list);
1160    
1161                                            list = new UnmodifiableList<WorkflowInstanceLink>(list);
1162                                    }
1163                                    else {
1164                                            list = (List<WorkflowInstanceLink>)QueryUtil.list(q,
1165                                                            getDialect(), start, end);
1166                                    }
1167    
1168                                    cacheResult(list);
1169    
1170                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1171                            }
1172                            catch (Exception e) {
1173                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1174    
1175                                    throw processException(e);
1176                            }
1177                            finally {
1178                                    closeSession(session);
1179                            }
1180                    }
1181    
1182                    return list;
1183            }
1184    
1185            /**
1186             * Removes all the workflow instance links from the database.
1187             *
1188             * @throws SystemException if a system exception occurred
1189             */
1190            public void removeAll() throws SystemException {
1191                    for (WorkflowInstanceLink workflowInstanceLink : findAll()) {
1192                            remove(workflowInstanceLink);
1193                    }
1194            }
1195    
1196            /**
1197             * Returns the number of workflow instance links.
1198             *
1199             * @return the number of workflow instance links
1200             * @throws SystemException if a system exception occurred
1201             */
1202            public int countAll() throws SystemException {
1203                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1204                                    FINDER_ARGS_EMPTY, this);
1205    
1206                    if (count == null) {
1207                            Session session = null;
1208    
1209                            try {
1210                                    session = openSession();
1211    
1212                                    Query q = session.createQuery(_SQL_COUNT_WORKFLOWINSTANCELINK);
1213    
1214                                    count = (Long)q.uniqueResult();
1215    
1216                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1217                                            FINDER_ARGS_EMPTY, count);
1218                            }
1219                            catch (Exception e) {
1220                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1221                                            FINDER_ARGS_EMPTY);
1222    
1223                                    throw processException(e);
1224                            }
1225                            finally {
1226                                    closeSession(session);
1227                            }
1228                    }
1229    
1230                    return count.intValue();
1231            }
1232    
1233            /**
1234             * Initializes the workflow instance link persistence.
1235             */
1236            public void afterPropertiesSet() {
1237                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1238                                            com.liferay.portal.util.PropsUtil.get(
1239                                                    "value.object.listener.com.liferay.portal.model.WorkflowInstanceLink")));
1240    
1241                    if (listenerClassNames.length > 0) {
1242                            try {
1243                                    List<ModelListener<WorkflowInstanceLink>> listenersList = new ArrayList<ModelListener<WorkflowInstanceLink>>();
1244    
1245                                    for (String listenerClassName : listenerClassNames) {
1246                                            listenersList.add((ModelListener<WorkflowInstanceLink>)InstanceFactory.newInstance(
1247                                                            listenerClassName));
1248                                    }
1249    
1250                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1251                            }
1252                            catch (Exception e) {
1253                                    _log.error(e);
1254                            }
1255                    }
1256            }
1257    
1258            public void destroy() {
1259                    EntityCacheUtil.removeCache(WorkflowInstanceLinkImpl.class.getName());
1260                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1261                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1262                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1263            }
1264    
1265            private static final String _SQL_SELECT_WORKFLOWINSTANCELINK = "SELECT workflowInstanceLink FROM WorkflowInstanceLink workflowInstanceLink";
1266            private static final String _SQL_SELECT_WORKFLOWINSTANCELINK_WHERE = "SELECT workflowInstanceLink FROM WorkflowInstanceLink workflowInstanceLink WHERE ";
1267            private static final String _SQL_COUNT_WORKFLOWINSTANCELINK = "SELECT COUNT(workflowInstanceLink) FROM WorkflowInstanceLink workflowInstanceLink";
1268            private static final String _SQL_COUNT_WORKFLOWINSTANCELINK_WHERE = "SELECT COUNT(workflowInstanceLink) FROM WorkflowInstanceLink workflowInstanceLink WHERE ";
1269            private static final String _ORDER_BY_ENTITY_ALIAS = "workflowInstanceLink.";
1270            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WorkflowInstanceLink exists with the primary key ";
1271            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WorkflowInstanceLink exists with the key {";
1272            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1273            private static Log _log = LogFactoryUtil.getLog(WorkflowInstanceLinkPersistenceImpl.class);
1274            private static WorkflowInstanceLink _nullWorkflowInstanceLink = new WorkflowInstanceLinkImpl() {
1275                            @Override
1276                            public Object clone() {
1277                                    return this;
1278                            }
1279    
1280                            @Override
1281                            public CacheModel<WorkflowInstanceLink> toCacheModel() {
1282                                    return _nullWorkflowInstanceLinkCacheModel;
1283                            }
1284                    };
1285    
1286            private static CacheModel<WorkflowInstanceLink> _nullWorkflowInstanceLinkCacheModel =
1287                    new CacheModel<WorkflowInstanceLink>() {
1288                            public WorkflowInstanceLink toEntityModel() {
1289                                    return _nullWorkflowInstanceLink;
1290                            }
1291                    };
1292    }