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