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