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