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