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            public WorkflowInstanceLinkPersistenceImpl() {
701                    setModelClass(WorkflowInstanceLink.class);
702            }
703    
704            /**
705             * Caches the workflow instance link in the entity cache if it is enabled.
706             *
707             * @param workflowInstanceLink the workflow instance link
708             */
709            @Override
710            public void cacheResult(WorkflowInstanceLink workflowInstanceLink) {
711                    EntityCacheUtil.putResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
712                            WorkflowInstanceLinkImpl.class,
713                            workflowInstanceLink.getPrimaryKey(), workflowInstanceLink);
714    
715                    workflowInstanceLink.resetOriginalValues();
716            }
717    
718            /**
719             * Caches the workflow instance links in the entity cache if it is enabled.
720             *
721             * @param workflowInstanceLinks the workflow instance links
722             */
723            @Override
724            public void cacheResult(List<WorkflowInstanceLink> workflowInstanceLinks) {
725                    for (WorkflowInstanceLink workflowInstanceLink : workflowInstanceLinks) {
726                            if (EntityCacheUtil.getResult(
727                                                    WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
728                                                    WorkflowInstanceLinkImpl.class,
729                                                    workflowInstanceLink.getPrimaryKey()) == null) {
730                                    cacheResult(workflowInstanceLink);
731                            }
732                            else {
733                                    workflowInstanceLink.resetOriginalValues();
734                            }
735                    }
736            }
737    
738            /**
739             * Clears the cache for all workflow instance links.
740             *
741             * <p>
742             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
743             * </p>
744             */
745            @Override
746            public void clearCache() {
747                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
748                            CacheRegistryUtil.clear(WorkflowInstanceLinkImpl.class.getName());
749                    }
750    
751                    EntityCacheUtil.clearCache(WorkflowInstanceLinkImpl.class.getName());
752    
753                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
754                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
755                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
756            }
757    
758            /**
759             * Clears the cache for the workflow instance link.
760             *
761             * <p>
762             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
763             * </p>
764             */
765            @Override
766            public void clearCache(WorkflowInstanceLink workflowInstanceLink) {
767                    EntityCacheUtil.removeResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
768                            WorkflowInstanceLinkImpl.class, workflowInstanceLink.getPrimaryKey());
769    
770                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
771                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
772            }
773    
774            @Override
775            public void clearCache(List<WorkflowInstanceLink> workflowInstanceLinks) {
776                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
777                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
778    
779                    for (WorkflowInstanceLink workflowInstanceLink : workflowInstanceLinks) {
780                            EntityCacheUtil.removeResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
781                                    WorkflowInstanceLinkImpl.class,
782                                    workflowInstanceLink.getPrimaryKey());
783                    }
784            }
785    
786            /**
787             * Creates a new workflow instance link with the primary key. Does not add the workflow instance link to the database.
788             *
789             * @param workflowInstanceLinkId the primary key for the new workflow instance link
790             * @return the new workflow instance link
791             */
792            @Override
793            public WorkflowInstanceLink create(long workflowInstanceLinkId) {
794                    WorkflowInstanceLink workflowInstanceLink = new WorkflowInstanceLinkImpl();
795    
796                    workflowInstanceLink.setNew(true);
797                    workflowInstanceLink.setPrimaryKey(workflowInstanceLinkId);
798    
799                    return workflowInstanceLink;
800            }
801    
802            /**
803             * Removes the workflow instance link with the primary key from the database. Also notifies the appropriate model listeners.
804             *
805             * @param workflowInstanceLinkId the primary key of the workflow instance link
806             * @return the workflow instance link that was removed
807             * @throws com.liferay.portal.NoSuchWorkflowInstanceLinkException if a workflow instance link with the primary key could not be found
808             * @throws SystemException if a system exception occurred
809             */
810            @Override
811            public WorkflowInstanceLink remove(long workflowInstanceLinkId)
812                    throws NoSuchWorkflowInstanceLinkException, SystemException {
813                    return remove((Serializable)workflowInstanceLinkId);
814            }
815    
816            /**
817             * Removes the workflow instance link with the primary key from the database. Also notifies the appropriate model listeners.
818             *
819             * @param primaryKey the primary key of the workflow instance link
820             * @return the workflow instance link that was removed
821             * @throws com.liferay.portal.NoSuchWorkflowInstanceLinkException if a workflow instance link with the primary key could not be found
822             * @throws SystemException if a system exception occurred
823             */
824            @Override
825            public WorkflowInstanceLink remove(Serializable primaryKey)
826                    throws NoSuchWorkflowInstanceLinkException, SystemException {
827                    Session session = null;
828    
829                    try {
830                            session = openSession();
831    
832                            WorkflowInstanceLink workflowInstanceLink = (WorkflowInstanceLink)session.get(WorkflowInstanceLinkImpl.class,
833                                            primaryKey);
834    
835                            if (workflowInstanceLink == null) {
836                                    if (_log.isWarnEnabled()) {
837                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
838                                    }
839    
840                                    throw new NoSuchWorkflowInstanceLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
841                                            primaryKey);
842                            }
843    
844                            return remove(workflowInstanceLink);
845                    }
846                    catch (NoSuchWorkflowInstanceLinkException nsee) {
847                            throw nsee;
848                    }
849                    catch (Exception e) {
850                            throw processException(e);
851                    }
852                    finally {
853                            closeSession(session);
854                    }
855            }
856    
857            @Override
858            protected WorkflowInstanceLink removeImpl(
859                    WorkflowInstanceLink workflowInstanceLink) throws SystemException {
860                    workflowInstanceLink = toUnwrappedModel(workflowInstanceLink);
861    
862                    Session session = null;
863    
864                    try {
865                            session = openSession();
866    
867                            if (!session.contains(workflowInstanceLink)) {
868                                    workflowInstanceLink = (WorkflowInstanceLink)session.get(WorkflowInstanceLinkImpl.class,
869                                                    workflowInstanceLink.getPrimaryKeyObj());
870                            }
871    
872                            if (workflowInstanceLink != null) {
873                                    session.delete(workflowInstanceLink);
874                            }
875                    }
876                    catch (Exception e) {
877                            throw processException(e);
878                    }
879                    finally {
880                            closeSession(session);
881                    }
882    
883                    if (workflowInstanceLink != null) {
884                            clearCache(workflowInstanceLink);
885                    }
886    
887                    return workflowInstanceLink;
888            }
889    
890            @Override
891            public WorkflowInstanceLink updateImpl(
892                    com.liferay.portal.model.WorkflowInstanceLink workflowInstanceLink)
893                    throws SystemException {
894                    workflowInstanceLink = toUnwrappedModel(workflowInstanceLink);
895    
896                    boolean isNew = workflowInstanceLink.isNew();
897    
898                    WorkflowInstanceLinkModelImpl workflowInstanceLinkModelImpl = (WorkflowInstanceLinkModelImpl)workflowInstanceLink;
899    
900                    Session session = null;
901    
902                    try {
903                            session = openSession();
904    
905                            if (workflowInstanceLink.isNew()) {
906                                    session.save(workflowInstanceLink);
907    
908                                    workflowInstanceLink.setNew(false);
909                            }
910                            else {
911                                    session.merge(workflowInstanceLink);
912                            }
913                    }
914                    catch (Exception e) {
915                            throw processException(e);
916                    }
917                    finally {
918                            closeSession(session);
919                    }
920    
921                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
922    
923                    if (isNew || !WorkflowInstanceLinkModelImpl.COLUMN_BITMASK_ENABLED) {
924                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
925                    }
926    
927                    else {
928                            if ((workflowInstanceLinkModelImpl.getColumnBitmask() &
929                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_C.getColumnBitmask()) != 0) {
930                                    Object[] args = new Object[] {
931                                                    workflowInstanceLinkModelImpl.getOriginalGroupId(),
932                                                    workflowInstanceLinkModelImpl.getOriginalCompanyId(),
933                                                    workflowInstanceLinkModelImpl.getOriginalClassNameId(),
934                                                    workflowInstanceLinkModelImpl.getOriginalClassPK()
935                                            };
936    
937                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C_C, args);
938                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_C,
939                                            args);
940    
941                                    args = new Object[] {
942                                                    workflowInstanceLinkModelImpl.getGroupId(),
943                                                    workflowInstanceLinkModelImpl.getCompanyId(),
944                                                    workflowInstanceLinkModelImpl.getClassNameId(),
945                                                    workflowInstanceLinkModelImpl.getClassPK()
946                                            };
947    
948                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C_C, args);
949                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_C,
950                                            args);
951                            }
952                    }
953    
954                    EntityCacheUtil.putResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
955                            WorkflowInstanceLinkImpl.class,
956                            workflowInstanceLink.getPrimaryKey(), workflowInstanceLink);
957    
958                    return workflowInstanceLink;
959            }
960    
961            protected WorkflowInstanceLink toUnwrappedModel(
962                    WorkflowInstanceLink workflowInstanceLink) {
963                    if (workflowInstanceLink instanceof WorkflowInstanceLinkImpl) {
964                            return workflowInstanceLink;
965                    }
966    
967                    WorkflowInstanceLinkImpl workflowInstanceLinkImpl = new WorkflowInstanceLinkImpl();
968    
969                    workflowInstanceLinkImpl.setNew(workflowInstanceLink.isNew());
970                    workflowInstanceLinkImpl.setPrimaryKey(workflowInstanceLink.getPrimaryKey());
971    
972                    workflowInstanceLinkImpl.setWorkflowInstanceLinkId(workflowInstanceLink.getWorkflowInstanceLinkId());
973                    workflowInstanceLinkImpl.setGroupId(workflowInstanceLink.getGroupId());
974                    workflowInstanceLinkImpl.setCompanyId(workflowInstanceLink.getCompanyId());
975                    workflowInstanceLinkImpl.setUserId(workflowInstanceLink.getUserId());
976                    workflowInstanceLinkImpl.setUserName(workflowInstanceLink.getUserName());
977                    workflowInstanceLinkImpl.setCreateDate(workflowInstanceLink.getCreateDate());
978                    workflowInstanceLinkImpl.setModifiedDate(workflowInstanceLink.getModifiedDate());
979                    workflowInstanceLinkImpl.setClassNameId(workflowInstanceLink.getClassNameId());
980                    workflowInstanceLinkImpl.setClassPK(workflowInstanceLink.getClassPK());
981                    workflowInstanceLinkImpl.setWorkflowInstanceId(workflowInstanceLink.getWorkflowInstanceId());
982    
983                    return workflowInstanceLinkImpl;
984            }
985    
986            /**
987             * Returns the workflow instance link with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
988             *
989             * @param primaryKey the primary key of the workflow instance link
990             * @return the workflow instance link
991             * @throws com.liferay.portal.NoSuchWorkflowInstanceLinkException if a workflow instance link with the primary key could not be found
992             * @throws SystemException if a system exception occurred
993             */
994            @Override
995            public WorkflowInstanceLink findByPrimaryKey(Serializable primaryKey)
996                    throws NoSuchWorkflowInstanceLinkException, SystemException {
997                    WorkflowInstanceLink workflowInstanceLink = fetchByPrimaryKey(primaryKey);
998    
999                    if (workflowInstanceLink == null) {
1000                            if (_log.isWarnEnabled()) {
1001                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1002                            }
1003    
1004                            throw new NoSuchWorkflowInstanceLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1005                                    primaryKey);
1006                    }
1007    
1008                    return workflowInstanceLink;
1009            }
1010    
1011            /**
1012             * Returns the workflow instance link with the primary key or throws a {@link com.liferay.portal.NoSuchWorkflowInstanceLinkException} if it could not be found.
1013             *
1014             * @param workflowInstanceLinkId the primary key of the workflow instance link
1015             * @return the workflow instance link
1016             * @throws com.liferay.portal.NoSuchWorkflowInstanceLinkException if a workflow instance link with the primary key could not be found
1017             * @throws SystemException if a system exception occurred
1018             */
1019            @Override
1020            public WorkflowInstanceLink findByPrimaryKey(long workflowInstanceLinkId)
1021                    throws NoSuchWorkflowInstanceLinkException, SystemException {
1022                    return findByPrimaryKey((Serializable)workflowInstanceLinkId);
1023            }
1024    
1025            /**
1026             * Returns the workflow instance link with the primary key or returns <code>null</code> if it could not be found.
1027             *
1028             * @param primaryKey the primary key of the workflow instance link
1029             * @return the workflow instance link, or <code>null</code> if a workflow instance link with the primary key could not be found
1030             * @throws SystemException if a system exception occurred
1031             */
1032            @Override
1033            public WorkflowInstanceLink fetchByPrimaryKey(Serializable primaryKey)
1034                    throws SystemException {
1035                    WorkflowInstanceLink workflowInstanceLink = (WorkflowInstanceLink)EntityCacheUtil.getResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
1036                                    WorkflowInstanceLinkImpl.class, primaryKey);
1037    
1038                    if (workflowInstanceLink == _nullWorkflowInstanceLink) {
1039                            return null;
1040                    }
1041    
1042                    if (workflowInstanceLink == null) {
1043                            Session session = null;
1044    
1045                            try {
1046                                    session = openSession();
1047    
1048                                    workflowInstanceLink = (WorkflowInstanceLink)session.get(WorkflowInstanceLinkImpl.class,
1049                                                    primaryKey);
1050    
1051                                    if (workflowInstanceLink != null) {
1052                                            cacheResult(workflowInstanceLink);
1053                                    }
1054                                    else {
1055                                            EntityCacheUtil.putResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
1056                                                    WorkflowInstanceLinkImpl.class, primaryKey,
1057                                                    _nullWorkflowInstanceLink);
1058                                    }
1059                            }
1060                            catch (Exception e) {
1061                                    EntityCacheUtil.removeResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
1062                                            WorkflowInstanceLinkImpl.class, primaryKey);
1063    
1064                                    throw processException(e);
1065                            }
1066                            finally {
1067                                    closeSession(session);
1068                            }
1069                    }
1070    
1071                    return workflowInstanceLink;
1072            }
1073    
1074            /**
1075             * Returns the workflow instance link with the primary key or returns <code>null</code> if it could not be found.
1076             *
1077             * @param workflowInstanceLinkId the primary key of the workflow instance link
1078             * @return the workflow instance link, or <code>null</code> if a workflow instance link with the primary key could not be found
1079             * @throws SystemException if a system exception occurred
1080             */
1081            @Override
1082            public WorkflowInstanceLink fetchByPrimaryKey(long workflowInstanceLinkId)
1083                    throws SystemException {
1084                    return fetchByPrimaryKey((Serializable)workflowInstanceLinkId);
1085            }
1086    
1087            /**
1088             * Returns all the workflow instance links.
1089             *
1090             * @return the workflow instance links
1091             * @throws SystemException if a system exception occurred
1092             */
1093            @Override
1094            public List<WorkflowInstanceLink> findAll() throws SystemException {
1095                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1096            }
1097    
1098            /**
1099             * Returns a range of all the workflow instance links.
1100             *
1101             * <p>
1102             * 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.
1103             * </p>
1104             *
1105             * @param start the lower bound of the range of workflow instance links
1106             * @param end the upper bound of the range of workflow instance links (not inclusive)
1107             * @return the range of workflow instance links
1108             * @throws SystemException if a system exception occurred
1109             */
1110            @Override
1111            public List<WorkflowInstanceLink> findAll(int start, int end)
1112                    throws SystemException {
1113                    return findAll(start, end, null);
1114            }
1115    
1116            /**
1117             * Returns an ordered range of all the workflow instance links.
1118             *
1119             * <p>
1120             * 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.
1121             * </p>
1122             *
1123             * @param start the lower bound of the range of workflow instance links
1124             * @param end the upper bound of the range of workflow instance links (not inclusive)
1125             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1126             * @return the ordered range of workflow instance links
1127             * @throws SystemException if a system exception occurred
1128             */
1129            @Override
1130            public List<WorkflowInstanceLink> findAll(int start, int end,
1131                    OrderByComparator orderByComparator) throws SystemException {
1132                    boolean pagination = true;
1133                    FinderPath finderPath = null;
1134                    Object[] finderArgs = null;
1135    
1136                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1137                                    (orderByComparator == null)) {
1138                            pagination = false;
1139                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1140                            finderArgs = FINDER_ARGS_EMPTY;
1141                    }
1142                    else {
1143                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1144                            finderArgs = new Object[] { start, end, orderByComparator };
1145                    }
1146    
1147                    List<WorkflowInstanceLink> list = (List<WorkflowInstanceLink>)FinderCacheUtil.getResult(finderPath,
1148                                    finderArgs, this);
1149    
1150                    if (list == null) {
1151                            StringBundler query = null;
1152                            String sql = null;
1153    
1154                            if (orderByComparator != null) {
1155                                    query = new StringBundler(2 +
1156                                                    (orderByComparator.getOrderByFields().length * 3));
1157    
1158                                    query.append(_SQL_SELECT_WORKFLOWINSTANCELINK);
1159    
1160                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1161                                            orderByComparator);
1162    
1163                                    sql = query.toString();
1164                            }
1165                            else {
1166                                    sql = _SQL_SELECT_WORKFLOWINSTANCELINK;
1167    
1168                                    if (pagination) {
1169                                            sql = sql.concat(WorkflowInstanceLinkModelImpl.ORDER_BY_JPQL);
1170                                    }
1171                            }
1172    
1173                            Session session = null;
1174    
1175                            try {
1176                                    session = openSession();
1177    
1178                                    Query q = session.createQuery(sql);
1179    
1180                                    if (!pagination) {
1181                                            list = (List<WorkflowInstanceLink>)QueryUtil.list(q,
1182                                                            getDialect(), start, end, false);
1183    
1184                                            Collections.sort(list);
1185    
1186                                            list = new UnmodifiableList<WorkflowInstanceLink>(list);
1187                                    }
1188                                    else {
1189                                            list = (List<WorkflowInstanceLink>)QueryUtil.list(q,
1190                                                            getDialect(), start, end);
1191                                    }
1192    
1193                                    cacheResult(list);
1194    
1195                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1196                            }
1197                            catch (Exception e) {
1198                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1199    
1200                                    throw processException(e);
1201                            }
1202                            finally {
1203                                    closeSession(session);
1204                            }
1205                    }
1206    
1207                    return list;
1208            }
1209    
1210            /**
1211             * Removes all the workflow instance links from the database.
1212             *
1213             * @throws SystemException if a system exception occurred
1214             */
1215            @Override
1216            public void removeAll() throws SystemException {
1217                    for (WorkflowInstanceLink workflowInstanceLink : findAll()) {
1218                            remove(workflowInstanceLink);
1219                    }
1220            }
1221    
1222            /**
1223             * Returns the number of workflow instance links.
1224             *
1225             * @return the number of workflow instance links
1226             * @throws SystemException if a system exception occurred
1227             */
1228            @Override
1229            public int countAll() throws SystemException {
1230                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1231                                    FINDER_ARGS_EMPTY, this);
1232    
1233                    if (count == null) {
1234                            Session session = null;
1235    
1236                            try {
1237                                    session = openSession();
1238    
1239                                    Query q = session.createQuery(_SQL_COUNT_WORKFLOWINSTANCELINK);
1240    
1241                                    count = (Long)q.uniqueResult();
1242    
1243                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1244                                            FINDER_ARGS_EMPTY, count);
1245                            }
1246                            catch (Exception e) {
1247                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1248                                            FINDER_ARGS_EMPTY);
1249    
1250                                    throw processException(e);
1251                            }
1252                            finally {
1253                                    closeSession(session);
1254                            }
1255                    }
1256    
1257                    return count.intValue();
1258            }
1259    
1260            /**
1261             * Initializes the workflow instance link persistence.
1262             */
1263            public void afterPropertiesSet() {
1264                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1265                                            com.liferay.portal.util.PropsUtil.get(
1266                                                    "value.object.listener.com.liferay.portal.model.WorkflowInstanceLink")));
1267    
1268                    if (listenerClassNames.length > 0) {
1269                            try {
1270                                    List<ModelListener<WorkflowInstanceLink>> listenersList = new ArrayList<ModelListener<WorkflowInstanceLink>>();
1271    
1272                                    for (String listenerClassName : listenerClassNames) {
1273                                            listenersList.add((ModelListener<WorkflowInstanceLink>)InstanceFactory.newInstance(
1274                                                            getClassLoader(), listenerClassName));
1275                                    }
1276    
1277                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1278                            }
1279                            catch (Exception e) {
1280                                    _log.error(e);
1281                            }
1282                    }
1283            }
1284    
1285            public void destroy() {
1286                    EntityCacheUtil.removeCache(WorkflowInstanceLinkImpl.class.getName());
1287                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1288                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1289                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1290            }
1291    
1292            private static final String _SQL_SELECT_WORKFLOWINSTANCELINK = "SELECT workflowInstanceLink FROM WorkflowInstanceLink workflowInstanceLink";
1293            private static final String _SQL_SELECT_WORKFLOWINSTANCELINK_WHERE = "SELECT workflowInstanceLink FROM WorkflowInstanceLink workflowInstanceLink WHERE ";
1294            private static final String _SQL_COUNT_WORKFLOWINSTANCELINK = "SELECT COUNT(workflowInstanceLink) FROM WorkflowInstanceLink workflowInstanceLink";
1295            private static final String _SQL_COUNT_WORKFLOWINSTANCELINK_WHERE = "SELECT COUNT(workflowInstanceLink) FROM WorkflowInstanceLink workflowInstanceLink WHERE ";
1296            private static final String _ORDER_BY_ENTITY_ALIAS = "workflowInstanceLink.";
1297            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WorkflowInstanceLink exists with the primary key ";
1298            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WorkflowInstanceLink exists with the key {";
1299            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1300            private static Log _log = LogFactoryUtil.getLog(WorkflowInstanceLinkPersistenceImpl.class);
1301            private static WorkflowInstanceLink _nullWorkflowInstanceLink = new WorkflowInstanceLinkImpl() {
1302                            @Override
1303                            public Object clone() {
1304                                    return this;
1305                            }
1306    
1307                            @Override
1308                            public CacheModel<WorkflowInstanceLink> toCacheModel() {
1309                                    return _nullWorkflowInstanceLinkCacheModel;
1310                            }
1311                    };
1312    
1313            private static CacheModel<WorkflowInstanceLink> _nullWorkflowInstanceLinkCacheModel =
1314                    new CacheModel<WorkflowInstanceLink>() {
1315                            @Override
1316                            public WorkflowInstanceLink toEntityModel() {
1317                                    return _nullWorkflowInstanceLink;
1318                            }
1319                    };
1320    }