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 * 2));
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(7 +
526                                            (orderByComparator.getOrderByConditionFields().length * 3) +
527                                            (orderByComparator.getOrderByFields().length * 3));
528                    }
529                    else {
530                            query = new StringBundler(6);
531                    }
532    
533                    query.append(_SQL_SELECT_WORKFLOWINSTANCELINK_WHERE);
534    
535                    query.append(_FINDER_COLUMN_G_C_C_C_GROUPID_2);
536    
537                    query.append(_FINDER_COLUMN_G_C_C_C_COMPANYID_2);
538    
539                    query.append(_FINDER_COLUMN_G_C_C_C_CLASSNAMEID_2);
540    
541                    query.append(_FINDER_COLUMN_G_C_C_C_CLASSPK_2);
542    
543                    if (orderByComparator != null) {
544                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
545    
546                            if (orderByConditionFields.length > 0) {
547                                    query.append(WHERE_AND);
548                            }
549    
550                            for (int i = 0; i < orderByConditionFields.length; i++) {
551                                    query.append(_ORDER_BY_ENTITY_ALIAS);
552                                    query.append(orderByConditionFields[i]);
553    
554                                    if ((i + 1) < orderByConditionFields.length) {
555                                            if (orderByComparator.isAscending() ^ previous) {
556                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
557                                            }
558                                            else {
559                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
560                                            }
561                                    }
562                                    else {
563                                            if (orderByComparator.isAscending() ^ previous) {
564                                                    query.append(WHERE_GREATER_THAN);
565                                            }
566                                            else {
567                                                    query.append(WHERE_LESSER_THAN);
568                                            }
569                                    }
570                            }
571    
572                            query.append(ORDER_BY_CLAUSE);
573    
574                            String[] orderByFields = orderByComparator.getOrderByFields();
575    
576                            for (int i = 0; i < orderByFields.length; i++) {
577                                    query.append(_ORDER_BY_ENTITY_ALIAS);
578                                    query.append(orderByFields[i]);
579    
580                                    if ((i + 1) < orderByFields.length) {
581                                            if (orderByComparator.isAscending() ^ previous) {
582                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
583                                            }
584                                            else {
585                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
586                                            }
587                                    }
588                                    else {
589                                            if (orderByComparator.isAscending() ^ previous) {
590                                                    query.append(ORDER_BY_ASC);
591                                            }
592                                            else {
593                                                    query.append(ORDER_BY_DESC);
594                                            }
595                                    }
596                            }
597                    }
598                    else {
599                            query.append(WorkflowInstanceLinkModelImpl.ORDER_BY_JPQL);
600                    }
601    
602                    String sql = query.toString();
603    
604                    Query q = session.createQuery(sql);
605    
606                    q.setFirstResult(0);
607                    q.setMaxResults(2);
608    
609                    QueryPos qPos = QueryPos.getInstance(q);
610    
611                    qPos.add(groupId);
612    
613                    qPos.add(companyId);
614    
615                    qPos.add(classNameId);
616    
617                    qPos.add(classPK);
618    
619                    if (orderByComparator != null) {
620                            Object[] values = orderByComparator.getOrderByConditionValues(workflowInstanceLink);
621    
622                            for (Object value : values) {
623                                    qPos.add(value);
624                            }
625                    }
626    
627                    List<WorkflowInstanceLink> list = q.list();
628    
629                    if (list.size() == 2) {
630                            return list.get(1);
631                    }
632                    else {
633                            return null;
634                    }
635            }
636    
637            /**
638             * Removes all the workflow instance links where groupId = &#63; and companyId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
639             *
640             * @param groupId the group ID
641             * @param companyId the company ID
642             * @param classNameId the class name ID
643             * @param classPK the class p k
644             */
645            @Override
646            public void removeByG_C_C_C(long groupId, long companyId, long classNameId,
647                    long classPK) {
648                    for (WorkflowInstanceLink workflowInstanceLink : findByG_C_C_C(
649                                    groupId, companyId, classNameId, classPK, QueryUtil.ALL_POS,
650                                    QueryUtil.ALL_POS, null)) {
651                            remove(workflowInstanceLink);
652                    }
653            }
654    
655            /**
656             * Returns the number of workflow instance links where groupId = &#63; and companyId = &#63; and classNameId = &#63; and classPK = &#63;.
657             *
658             * @param groupId the group ID
659             * @param companyId the company ID
660             * @param classNameId the class name ID
661             * @param classPK the class p k
662             * @return the number of matching workflow instance links
663             */
664            @Override
665            public int countByG_C_C_C(long groupId, long companyId, long classNameId,
666                    long classPK) {
667                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_C_C;
668    
669                    Object[] finderArgs = new Object[] {
670                                    groupId, companyId, classNameId, classPK
671                            };
672    
673                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
674    
675                    if (count == null) {
676                            StringBundler query = new StringBundler(5);
677    
678                            query.append(_SQL_COUNT_WORKFLOWINSTANCELINK_WHERE);
679    
680                            query.append(_FINDER_COLUMN_G_C_C_C_GROUPID_2);
681    
682                            query.append(_FINDER_COLUMN_G_C_C_C_COMPANYID_2);
683    
684                            query.append(_FINDER_COLUMN_G_C_C_C_CLASSNAMEID_2);
685    
686                            query.append(_FINDER_COLUMN_G_C_C_C_CLASSPK_2);
687    
688                            String sql = query.toString();
689    
690                            Session session = null;
691    
692                            try {
693                                    session = openSession();
694    
695                                    Query q = session.createQuery(sql);
696    
697                                    QueryPos qPos = QueryPos.getInstance(q);
698    
699                                    qPos.add(groupId);
700    
701                                    qPos.add(companyId);
702    
703                                    qPos.add(classNameId);
704    
705                                    qPos.add(classPK);
706    
707                                    count = (Long)q.uniqueResult();
708    
709                                    finderCache.putResult(finderPath, finderArgs, count);
710                            }
711                            catch (Exception e) {
712                                    finderCache.removeResult(finderPath, finderArgs);
713    
714                                    throw processException(e);
715                            }
716                            finally {
717                                    closeSession(session);
718                            }
719                    }
720    
721                    return count.intValue();
722            }
723    
724            private static final String _FINDER_COLUMN_G_C_C_C_GROUPID_2 = "workflowInstanceLink.groupId = ? AND ";
725            private static final String _FINDER_COLUMN_G_C_C_C_COMPANYID_2 = "workflowInstanceLink.companyId = ? AND ";
726            private static final String _FINDER_COLUMN_G_C_C_C_CLASSNAMEID_2 = "workflowInstanceLink.classNameId = ? AND ";
727            private static final String _FINDER_COLUMN_G_C_C_C_CLASSPK_2 = "workflowInstanceLink.classPK = ?";
728    
729            public WorkflowInstanceLinkPersistenceImpl() {
730                    setModelClass(WorkflowInstanceLink.class);
731            }
732    
733            /**
734             * Caches the workflow instance link in the entity cache if it is enabled.
735             *
736             * @param workflowInstanceLink the workflow instance link
737             */
738            @Override
739            public void cacheResult(WorkflowInstanceLink workflowInstanceLink) {
740                    entityCache.putResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
741                            WorkflowInstanceLinkImpl.class,
742                            workflowInstanceLink.getPrimaryKey(), workflowInstanceLink);
743    
744                    workflowInstanceLink.resetOriginalValues();
745            }
746    
747            /**
748             * Caches the workflow instance links in the entity cache if it is enabled.
749             *
750             * @param workflowInstanceLinks the workflow instance links
751             */
752            @Override
753            public void cacheResult(List<WorkflowInstanceLink> workflowInstanceLinks) {
754                    for (WorkflowInstanceLink workflowInstanceLink : workflowInstanceLinks) {
755                            if (entityCache.getResult(
756                                                    WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
757                                                    WorkflowInstanceLinkImpl.class,
758                                                    workflowInstanceLink.getPrimaryKey()) == null) {
759                                    cacheResult(workflowInstanceLink);
760                            }
761                            else {
762                                    workflowInstanceLink.resetOriginalValues();
763                            }
764                    }
765            }
766    
767            /**
768             * Clears the cache for all workflow instance links.
769             *
770             * <p>
771             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
772             * </p>
773             */
774            @Override
775            public void clearCache() {
776                    entityCache.clearCache(WorkflowInstanceLinkImpl.class);
777    
778                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
779                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
780                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
781            }
782    
783            /**
784             * Clears the cache for the workflow instance link.
785             *
786             * <p>
787             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
788             * </p>
789             */
790            @Override
791            public void clearCache(WorkflowInstanceLink workflowInstanceLink) {
792                    entityCache.removeResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
793                            WorkflowInstanceLinkImpl.class, workflowInstanceLink.getPrimaryKey());
794    
795                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
796                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
797            }
798    
799            @Override
800            public void clearCache(List<WorkflowInstanceLink> workflowInstanceLinks) {
801                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
802                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
803    
804                    for (WorkflowInstanceLink workflowInstanceLink : workflowInstanceLinks) {
805                            entityCache.removeResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
806                                    WorkflowInstanceLinkImpl.class,
807                                    workflowInstanceLink.getPrimaryKey());
808                    }
809            }
810    
811            /**
812             * Creates a new workflow instance link with the primary key. Does not add the workflow instance link to the database.
813             *
814             * @param workflowInstanceLinkId the primary key for the new workflow instance link
815             * @return the new workflow instance link
816             */
817            @Override
818            public WorkflowInstanceLink create(long workflowInstanceLinkId) {
819                    WorkflowInstanceLink workflowInstanceLink = new WorkflowInstanceLinkImpl();
820    
821                    workflowInstanceLink.setNew(true);
822                    workflowInstanceLink.setPrimaryKey(workflowInstanceLinkId);
823    
824                    workflowInstanceLink.setCompanyId(companyProvider.getCompanyId());
825    
826                    return workflowInstanceLink;
827            }
828    
829            /**
830             * Removes the workflow instance link with the primary key from the database. Also notifies the appropriate model listeners.
831             *
832             * @param workflowInstanceLinkId the primary key of the workflow instance link
833             * @return the workflow instance link that was removed
834             * @throws NoSuchWorkflowInstanceLinkException if a workflow instance link with the primary key could not be found
835             */
836            @Override
837            public WorkflowInstanceLink remove(long workflowInstanceLinkId)
838                    throws NoSuchWorkflowInstanceLinkException {
839                    return remove((Serializable)workflowInstanceLinkId);
840            }
841    
842            /**
843             * Removes the workflow instance link with the primary key from the database. Also notifies the appropriate model listeners.
844             *
845             * @param primaryKey the primary key of the workflow instance link
846             * @return the workflow instance link that was removed
847             * @throws NoSuchWorkflowInstanceLinkException if a workflow instance link with the primary key could not be found
848             */
849            @Override
850            public WorkflowInstanceLink remove(Serializable primaryKey)
851                    throws NoSuchWorkflowInstanceLinkException {
852                    Session session = null;
853    
854                    try {
855                            session = openSession();
856    
857                            WorkflowInstanceLink workflowInstanceLink = (WorkflowInstanceLink)session.get(WorkflowInstanceLinkImpl.class,
858                                            primaryKey);
859    
860                            if (workflowInstanceLink == null) {
861                                    if (_log.isWarnEnabled()) {
862                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
863                                    }
864    
865                                    throw new NoSuchWorkflowInstanceLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
866                                            primaryKey);
867                            }
868    
869                            return remove(workflowInstanceLink);
870                    }
871                    catch (NoSuchWorkflowInstanceLinkException nsee) {
872                            throw nsee;
873                    }
874                    catch (Exception e) {
875                            throw processException(e);
876                    }
877                    finally {
878                            closeSession(session);
879                    }
880            }
881    
882            @Override
883            protected WorkflowInstanceLink removeImpl(
884                    WorkflowInstanceLink workflowInstanceLink) {
885                    workflowInstanceLink = toUnwrappedModel(workflowInstanceLink);
886    
887                    Session session = null;
888    
889                    try {
890                            session = openSession();
891    
892                            if (!session.contains(workflowInstanceLink)) {
893                                    workflowInstanceLink = (WorkflowInstanceLink)session.get(WorkflowInstanceLinkImpl.class,
894                                                    workflowInstanceLink.getPrimaryKeyObj());
895                            }
896    
897                            if (workflowInstanceLink != null) {
898                                    session.delete(workflowInstanceLink);
899                            }
900                    }
901                    catch (Exception e) {
902                            throw processException(e);
903                    }
904                    finally {
905                            closeSession(session);
906                    }
907    
908                    if (workflowInstanceLink != null) {
909                            clearCache(workflowInstanceLink);
910                    }
911    
912                    return workflowInstanceLink;
913            }
914    
915            @Override
916            public WorkflowInstanceLink updateImpl(
917                    WorkflowInstanceLink workflowInstanceLink) {
918                    workflowInstanceLink = toUnwrappedModel(workflowInstanceLink);
919    
920                    boolean isNew = workflowInstanceLink.isNew();
921    
922                    WorkflowInstanceLinkModelImpl workflowInstanceLinkModelImpl = (WorkflowInstanceLinkModelImpl)workflowInstanceLink;
923    
924                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
925    
926                    Date now = new Date();
927    
928                    if (isNew && (workflowInstanceLink.getCreateDate() == null)) {
929                            if (serviceContext == null) {
930                                    workflowInstanceLink.setCreateDate(now);
931                            }
932                            else {
933                                    workflowInstanceLink.setCreateDate(serviceContext.getCreateDate(
934                                                    now));
935                            }
936                    }
937    
938                    if (!workflowInstanceLinkModelImpl.hasSetModifiedDate()) {
939                            if (serviceContext == null) {
940                                    workflowInstanceLink.setModifiedDate(now);
941                            }
942                            else {
943                                    workflowInstanceLink.setModifiedDate(serviceContext.getModifiedDate(
944                                                    now));
945                            }
946                    }
947    
948                    Session session = null;
949    
950                    try {
951                            session = openSession();
952    
953                            if (workflowInstanceLink.isNew()) {
954                                    session.save(workflowInstanceLink);
955    
956                                    workflowInstanceLink.setNew(false);
957                            }
958                            else {
959                                    workflowInstanceLink = (WorkflowInstanceLink)session.merge(workflowInstanceLink);
960                            }
961                    }
962                    catch (Exception e) {
963                            throw processException(e);
964                    }
965                    finally {
966                            closeSession(session);
967                    }
968    
969                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
970    
971                    if (isNew || !WorkflowInstanceLinkModelImpl.COLUMN_BITMASK_ENABLED) {
972                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
973                    }
974    
975                    else {
976                            if ((workflowInstanceLinkModelImpl.getColumnBitmask() &
977                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_C.getColumnBitmask()) != 0) {
978                                    Object[] args = new Object[] {
979                                                    workflowInstanceLinkModelImpl.getOriginalGroupId(),
980                                                    workflowInstanceLinkModelImpl.getOriginalCompanyId(),
981                                                    workflowInstanceLinkModelImpl.getOriginalClassNameId(),
982                                                    workflowInstanceLinkModelImpl.getOriginalClassPK()
983                                            };
984    
985                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_C_C, args);
986                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_C,
987                                            args);
988    
989                                    args = new Object[] {
990                                                    workflowInstanceLinkModelImpl.getGroupId(),
991                                                    workflowInstanceLinkModelImpl.getCompanyId(),
992                                                    workflowInstanceLinkModelImpl.getClassNameId(),
993                                                    workflowInstanceLinkModelImpl.getClassPK()
994                                            };
995    
996                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C_C_C, args);
997                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_C,
998                                            args);
999                            }
1000                    }
1001    
1002                    entityCache.putResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
1003                            WorkflowInstanceLinkImpl.class,
1004                            workflowInstanceLink.getPrimaryKey(), workflowInstanceLink, false);
1005    
1006                    workflowInstanceLink.resetOriginalValues();
1007    
1008                    return workflowInstanceLink;
1009            }
1010    
1011            protected WorkflowInstanceLink toUnwrappedModel(
1012                    WorkflowInstanceLink workflowInstanceLink) {
1013                    if (workflowInstanceLink instanceof WorkflowInstanceLinkImpl) {
1014                            return workflowInstanceLink;
1015                    }
1016    
1017                    WorkflowInstanceLinkImpl workflowInstanceLinkImpl = new WorkflowInstanceLinkImpl();
1018    
1019                    workflowInstanceLinkImpl.setNew(workflowInstanceLink.isNew());
1020                    workflowInstanceLinkImpl.setPrimaryKey(workflowInstanceLink.getPrimaryKey());
1021    
1022                    workflowInstanceLinkImpl.setMvccVersion(workflowInstanceLink.getMvccVersion());
1023                    workflowInstanceLinkImpl.setWorkflowInstanceLinkId(workflowInstanceLink.getWorkflowInstanceLinkId());
1024                    workflowInstanceLinkImpl.setGroupId(workflowInstanceLink.getGroupId());
1025                    workflowInstanceLinkImpl.setCompanyId(workflowInstanceLink.getCompanyId());
1026                    workflowInstanceLinkImpl.setUserId(workflowInstanceLink.getUserId());
1027                    workflowInstanceLinkImpl.setUserName(workflowInstanceLink.getUserName());
1028                    workflowInstanceLinkImpl.setCreateDate(workflowInstanceLink.getCreateDate());
1029                    workflowInstanceLinkImpl.setModifiedDate(workflowInstanceLink.getModifiedDate());
1030                    workflowInstanceLinkImpl.setClassNameId(workflowInstanceLink.getClassNameId());
1031                    workflowInstanceLinkImpl.setClassPK(workflowInstanceLink.getClassPK());
1032                    workflowInstanceLinkImpl.setWorkflowInstanceId(workflowInstanceLink.getWorkflowInstanceId());
1033    
1034                    return workflowInstanceLinkImpl;
1035            }
1036    
1037            /**
1038             * Returns the workflow instance link with the primary key or throws a {@link com.liferay.portal.exception.NoSuchModelException} if it could not be found.
1039             *
1040             * @param primaryKey the primary key of the workflow instance link
1041             * @return the workflow instance link
1042             * @throws NoSuchWorkflowInstanceLinkException if a workflow instance link with the primary key could not be found
1043             */
1044            @Override
1045            public WorkflowInstanceLink findByPrimaryKey(Serializable primaryKey)
1046                    throws NoSuchWorkflowInstanceLinkException {
1047                    WorkflowInstanceLink workflowInstanceLink = fetchByPrimaryKey(primaryKey);
1048    
1049                    if (workflowInstanceLink == null) {
1050                            if (_log.isWarnEnabled()) {
1051                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1052                            }
1053    
1054                            throw new NoSuchWorkflowInstanceLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1055                                    primaryKey);
1056                    }
1057    
1058                    return workflowInstanceLink;
1059            }
1060    
1061            /**
1062             * Returns the workflow instance link with the primary key or throws a {@link NoSuchWorkflowInstanceLinkException} if it could not be found.
1063             *
1064             * @param workflowInstanceLinkId the primary key of the workflow instance link
1065             * @return the workflow instance link
1066             * @throws NoSuchWorkflowInstanceLinkException if a workflow instance link with the primary key could not be found
1067             */
1068            @Override
1069            public WorkflowInstanceLink findByPrimaryKey(long workflowInstanceLinkId)
1070                    throws NoSuchWorkflowInstanceLinkException {
1071                    return findByPrimaryKey((Serializable)workflowInstanceLinkId);
1072            }
1073    
1074            /**
1075             * Returns the workflow instance link with the primary key or returns <code>null</code> if it could not be found.
1076             *
1077             * @param primaryKey the primary key of the workflow instance link
1078             * @return the workflow instance link, or <code>null</code> if a workflow instance link with the primary key could not be found
1079             */
1080            @Override
1081            public WorkflowInstanceLink fetchByPrimaryKey(Serializable primaryKey) {
1082                    WorkflowInstanceLink workflowInstanceLink = (WorkflowInstanceLink)entityCache.getResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
1083                                    WorkflowInstanceLinkImpl.class, primaryKey);
1084    
1085                    if (workflowInstanceLink == _nullWorkflowInstanceLink) {
1086                            return null;
1087                    }
1088    
1089                    if (workflowInstanceLink == null) {
1090                            Session session = null;
1091    
1092                            try {
1093                                    session = openSession();
1094    
1095                                    workflowInstanceLink = (WorkflowInstanceLink)session.get(WorkflowInstanceLinkImpl.class,
1096                                                    primaryKey);
1097    
1098                                    if (workflowInstanceLink != null) {
1099                                            cacheResult(workflowInstanceLink);
1100                                    }
1101                                    else {
1102                                            entityCache.putResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
1103                                                    WorkflowInstanceLinkImpl.class, primaryKey,
1104                                                    _nullWorkflowInstanceLink);
1105                                    }
1106                            }
1107                            catch (Exception e) {
1108                                    entityCache.removeResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
1109                                            WorkflowInstanceLinkImpl.class, primaryKey);
1110    
1111                                    throw processException(e);
1112                            }
1113                            finally {
1114                                    closeSession(session);
1115                            }
1116                    }
1117    
1118                    return workflowInstanceLink;
1119            }
1120    
1121            /**
1122             * Returns the workflow instance link with the primary key or returns <code>null</code> if it could not be found.
1123             *
1124             * @param workflowInstanceLinkId the primary key of the workflow instance link
1125             * @return the workflow instance link, or <code>null</code> if a workflow instance link with the primary key could not be found
1126             */
1127            @Override
1128            public WorkflowInstanceLink fetchByPrimaryKey(long workflowInstanceLinkId) {
1129                    return fetchByPrimaryKey((Serializable)workflowInstanceLinkId);
1130            }
1131    
1132            @Override
1133            public Map<Serializable, WorkflowInstanceLink> fetchByPrimaryKeys(
1134                    Set<Serializable> primaryKeys) {
1135                    if (primaryKeys.isEmpty()) {
1136                            return Collections.emptyMap();
1137                    }
1138    
1139                    Map<Serializable, WorkflowInstanceLink> map = new HashMap<Serializable, WorkflowInstanceLink>();
1140    
1141                    if (primaryKeys.size() == 1) {
1142                            Iterator<Serializable> iterator = primaryKeys.iterator();
1143    
1144                            Serializable primaryKey = iterator.next();
1145    
1146                            WorkflowInstanceLink workflowInstanceLink = fetchByPrimaryKey(primaryKey);
1147    
1148                            if (workflowInstanceLink != null) {
1149                                    map.put(primaryKey, workflowInstanceLink);
1150                            }
1151    
1152                            return map;
1153                    }
1154    
1155                    Set<Serializable> uncachedPrimaryKeys = null;
1156    
1157                    for (Serializable primaryKey : primaryKeys) {
1158                            WorkflowInstanceLink workflowInstanceLink = (WorkflowInstanceLink)entityCache.getResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
1159                                            WorkflowInstanceLinkImpl.class, primaryKey);
1160    
1161                            if (workflowInstanceLink == null) {
1162                                    if (uncachedPrimaryKeys == null) {
1163                                            uncachedPrimaryKeys = new HashSet<Serializable>();
1164                                    }
1165    
1166                                    uncachedPrimaryKeys.add(primaryKey);
1167                            }
1168                            else {
1169                                    map.put(primaryKey, workflowInstanceLink);
1170                            }
1171                    }
1172    
1173                    if (uncachedPrimaryKeys == null) {
1174                            return map;
1175                    }
1176    
1177                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1178                                    1);
1179    
1180                    query.append(_SQL_SELECT_WORKFLOWINSTANCELINK_WHERE_PKS_IN);
1181    
1182                    for (Serializable primaryKey : uncachedPrimaryKeys) {
1183                            query.append(String.valueOf(primaryKey));
1184    
1185                            query.append(StringPool.COMMA);
1186                    }
1187    
1188                    query.setIndex(query.index() - 1);
1189    
1190                    query.append(StringPool.CLOSE_PARENTHESIS);
1191    
1192                    String sql = query.toString();
1193    
1194                    Session session = null;
1195    
1196                    try {
1197                            session = openSession();
1198    
1199                            Query q = session.createQuery(sql);
1200    
1201                            for (WorkflowInstanceLink workflowInstanceLink : (List<WorkflowInstanceLink>)q.list()) {
1202                                    map.put(workflowInstanceLink.getPrimaryKeyObj(),
1203                                            workflowInstanceLink);
1204    
1205                                    cacheResult(workflowInstanceLink);
1206    
1207                                    uncachedPrimaryKeys.remove(workflowInstanceLink.getPrimaryKeyObj());
1208                            }
1209    
1210                            for (Serializable primaryKey : uncachedPrimaryKeys) {
1211                                    entityCache.putResult(WorkflowInstanceLinkModelImpl.ENTITY_CACHE_ENABLED,
1212                                            WorkflowInstanceLinkImpl.class, primaryKey,
1213                                            _nullWorkflowInstanceLink);
1214                            }
1215                    }
1216                    catch (Exception e) {
1217                            throw processException(e);
1218                    }
1219                    finally {
1220                            closeSession(session);
1221                    }
1222    
1223                    return map;
1224            }
1225    
1226            /**
1227             * Returns all the workflow instance links.
1228             *
1229             * @return the workflow instance links
1230             */
1231            @Override
1232            public List<WorkflowInstanceLink> findAll() {
1233                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1234            }
1235    
1236            /**
1237             * Returns a range of all the workflow instance links.
1238             *
1239             * <p>
1240             * 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.
1241             * </p>
1242             *
1243             * @param start the lower bound of the range of workflow instance links
1244             * @param end the upper bound of the range of workflow instance links (not inclusive)
1245             * @return the range of workflow instance links
1246             */
1247            @Override
1248            public List<WorkflowInstanceLink> findAll(int start, int end) {
1249                    return findAll(start, end, null);
1250            }
1251    
1252            /**
1253             * Returns an ordered range of all the workflow instance links.
1254             *
1255             * <p>
1256             * 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.
1257             * </p>
1258             *
1259             * @param start the lower bound of the range of workflow instance links
1260             * @param end the upper bound of the range of workflow instance links (not inclusive)
1261             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1262             * @return the ordered range of workflow instance links
1263             */
1264            @Override
1265            public List<WorkflowInstanceLink> findAll(int start, int end,
1266                    OrderByComparator<WorkflowInstanceLink> orderByComparator) {
1267                    return findAll(start, end, orderByComparator, true);
1268            }
1269    
1270            /**
1271             * Returns an ordered range of all the workflow instance links.
1272             *
1273             * <p>
1274             * 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.
1275             * </p>
1276             *
1277             * @param start the lower bound of the range of workflow instance links
1278             * @param end the upper bound of the range of workflow instance links (not inclusive)
1279             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1280             * @param retrieveFromCache whether to retrieve from the finder cache
1281             * @return the ordered range of workflow instance links
1282             */
1283            @Override
1284            public List<WorkflowInstanceLink> findAll(int start, int end,
1285                    OrderByComparator<WorkflowInstanceLink> orderByComparator,
1286                    boolean retrieveFromCache) {
1287                    boolean pagination = true;
1288                    FinderPath finderPath = null;
1289                    Object[] finderArgs = null;
1290    
1291                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1292                                    (orderByComparator == null)) {
1293                            pagination = false;
1294                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1295                            finderArgs = FINDER_ARGS_EMPTY;
1296                    }
1297                    else {
1298                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1299                            finderArgs = new Object[] { start, end, orderByComparator };
1300                    }
1301    
1302                    List<WorkflowInstanceLink> list = null;
1303    
1304                    if (retrieveFromCache) {
1305                            list = (List<WorkflowInstanceLink>)finderCache.getResult(finderPath,
1306                                            finderArgs, this);
1307                    }
1308    
1309                    if (list == null) {
1310                            StringBundler query = null;
1311                            String sql = null;
1312    
1313                            if (orderByComparator != null) {
1314                                    query = new StringBundler(2 +
1315                                                    (orderByComparator.getOrderByFields().length * 2));
1316    
1317                                    query.append(_SQL_SELECT_WORKFLOWINSTANCELINK);
1318    
1319                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1320                                            orderByComparator);
1321    
1322                                    sql = query.toString();
1323                            }
1324                            else {
1325                                    sql = _SQL_SELECT_WORKFLOWINSTANCELINK;
1326    
1327                                    if (pagination) {
1328                                            sql = sql.concat(WorkflowInstanceLinkModelImpl.ORDER_BY_JPQL);
1329                                    }
1330                            }
1331    
1332                            Session session = null;
1333    
1334                            try {
1335                                    session = openSession();
1336    
1337                                    Query q = session.createQuery(sql);
1338    
1339                                    if (!pagination) {
1340                                            list = (List<WorkflowInstanceLink>)QueryUtil.list(q,
1341                                                            getDialect(), start, end, false);
1342    
1343                                            Collections.sort(list);
1344    
1345                                            list = Collections.unmodifiableList(list);
1346                                    }
1347                                    else {
1348                                            list = (List<WorkflowInstanceLink>)QueryUtil.list(q,
1349                                                            getDialect(), start, end);
1350                                    }
1351    
1352                                    cacheResult(list);
1353    
1354                                    finderCache.putResult(finderPath, finderArgs, list);
1355                            }
1356                            catch (Exception e) {
1357                                    finderCache.removeResult(finderPath, finderArgs);
1358    
1359                                    throw processException(e);
1360                            }
1361                            finally {
1362                                    closeSession(session);
1363                            }
1364                    }
1365    
1366                    return list;
1367            }
1368    
1369            /**
1370             * Removes all the workflow instance links from the database.
1371             *
1372             */
1373            @Override
1374            public void removeAll() {
1375                    for (WorkflowInstanceLink workflowInstanceLink : findAll()) {
1376                            remove(workflowInstanceLink);
1377                    }
1378            }
1379    
1380            /**
1381             * Returns the number of workflow instance links.
1382             *
1383             * @return the number of workflow instance links
1384             */
1385            @Override
1386            public int countAll() {
1387                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
1388                                    FINDER_ARGS_EMPTY, this);
1389    
1390                    if (count == null) {
1391                            Session session = null;
1392    
1393                            try {
1394                                    session = openSession();
1395    
1396                                    Query q = session.createQuery(_SQL_COUNT_WORKFLOWINSTANCELINK);
1397    
1398                                    count = (Long)q.uniqueResult();
1399    
1400                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
1401                                            count);
1402                            }
1403                            catch (Exception e) {
1404                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
1405                                            FINDER_ARGS_EMPTY);
1406    
1407                                    throw processException(e);
1408                            }
1409                            finally {
1410                                    closeSession(session);
1411                            }
1412                    }
1413    
1414                    return count.intValue();
1415            }
1416    
1417            @Override
1418            protected Map<String, Integer> getTableColumnsMap() {
1419                    return WorkflowInstanceLinkModelImpl.TABLE_COLUMNS_MAP;
1420            }
1421    
1422            /**
1423             * Initializes the workflow instance link persistence.
1424             */
1425            public void afterPropertiesSet() {
1426            }
1427    
1428            public void destroy() {
1429                    entityCache.removeCache(WorkflowInstanceLinkImpl.class.getName());
1430                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
1431                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1432                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1433            }
1434    
1435            @BeanReference(type = CompanyProviderWrapper.class)
1436            protected CompanyProvider companyProvider;
1437            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
1438            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
1439            private static final String _SQL_SELECT_WORKFLOWINSTANCELINK = "SELECT workflowInstanceLink FROM WorkflowInstanceLink workflowInstanceLink";
1440            private static final String _SQL_SELECT_WORKFLOWINSTANCELINK_WHERE_PKS_IN = "SELECT workflowInstanceLink FROM WorkflowInstanceLink workflowInstanceLink WHERE workflowInstanceLinkId IN (";
1441            private static final String _SQL_SELECT_WORKFLOWINSTANCELINK_WHERE = "SELECT workflowInstanceLink FROM WorkflowInstanceLink workflowInstanceLink WHERE ";
1442            private static final String _SQL_COUNT_WORKFLOWINSTANCELINK = "SELECT COUNT(workflowInstanceLink) FROM WorkflowInstanceLink workflowInstanceLink";
1443            private static final String _SQL_COUNT_WORKFLOWINSTANCELINK_WHERE = "SELECT COUNT(workflowInstanceLink) FROM WorkflowInstanceLink workflowInstanceLink WHERE ";
1444            private static final String _ORDER_BY_ENTITY_ALIAS = "workflowInstanceLink.";
1445            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WorkflowInstanceLink exists with the primary key ";
1446            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WorkflowInstanceLink exists with the key {";
1447            private static final Log _log = LogFactoryUtil.getLog(WorkflowInstanceLinkPersistenceImpl.class);
1448            private static final WorkflowInstanceLink _nullWorkflowInstanceLink = new WorkflowInstanceLinkImpl() {
1449                            @Override
1450                            public Object clone() {
1451                                    return this;
1452                            }
1453    
1454                            @Override
1455                            public CacheModel<WorkflowInstanceLink> toCacheModel() {
1456                                    return _nullWorkflowInstanceLinkCacheModel;
1457                            }
1458                    };
1459    
1460            private static final CacheModel<WorkflowInstanceLink> _nullWorkflowInstanceLinkCacheModel =
1461                    new NullCacheModel();
1462    
1463            private static class NullCacheModel implements CacheModel<WorkflowInstanceLink>,
1464                    MVCCModel {
1465                    @Override
1466                    public long getMvccVersion() {
1467                            return -1;
1468                    }
1469    
1470                    @Override
1471                    public void setMvccVersion(long mvccVersion) {
1472                    }
1473    
1474                    @Override
1475                    public WorkflowInstanceLink toEntityModel() {
1476                            return _nullWorkflowInstanceLink;
1477                    }
1478            }
1479    }