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