001    /**
002     * Copyright (c) 2000-2011 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.portlet.tasks.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
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.kernel.util.Validator;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
040    import com.liferay.portal.service.persistence.BatchSessionUtil;
041    import com.liferay.portal.service.persistence.ResourcePersistence;
042    import com.liferay.portal.service.persistence.UserPersistence;
043    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044    
045    import com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence;
046    import com.liferay.portlet.social.service.persistence.SocialActivityPersistence;
047    import com.liferay.portlet.tasks.NoSuchProposalException;
048    import com.liferay.portlet.tasks.model.TasksProposal;
049    import com.liferay.portlet.tasks.model.impl.TasksProposalImpl;
050    import com.liferay.portlet.tasks.model.impl.TasksProposalModelImpl;
051    
052    import java.io.Serializable;
053    
054    import java.util.ArrayList;
055    import java.util.Collections;
056    import java.util.List;
057    
058    /**
059     * The persistence implementation for the tasks proposal service.
060     *
061     * <p>
062     * Never modify or reference this class directly. Always use {@link TasksProposalUtil} to access the tasks proposal persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
063     * </p>
064     *
065     * <p>
066     * Caching information and settings can be found in <code>portal.properties</code>
067     * </p>
068     *
069     * @author Brian Wing Shun Chan
070     * @see TasksProposalPersistence
071     * @see TasksProposalUtil
072     * @generated
073     */
074    public class TasksProposalPersistenceImpl extends BasePersistenceImpl<TasksProposal>
075            implements TasksProposalPersistence {
076            public static final String FINDER_CLASS_NAME_ENTITY = TasksProposalImpl.class.getName();
077            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
078                    ".List";
079            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
080                            TasksProposalModelImpl.FINDER_CACHE_ENABLED,
081                            FINDER_CLASS_NAME_LIST, "findByGroupId",
082                            new String[] {
083                                    Long.class.getName(),
084                                    
085                            "java.lang.Integer", "java.lang.Integer",
086                                    "com.liferay.portal.kernel.util.OrderByComparator"
087                            });
088            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
089                            TasksProposalModelImpl.FINDER_CACHE_ENABLED,
090                            FINDER_CLASS_NAME_LIST, "countByGroupId",
091                            new String[] { Long.class.getName() });
092            public static final FinderPath FINDER_PATH_FIND_BY_G_U = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
093                            TasksProposalModelImpl.FINDER_CACHE_ENABLED,
094                            FINDER_CLASS_NAME_LIST, "findByG_U",
095                            new String[] {
096                                    Long.class.getName(), Long.class.getName(),
097                                    
098                            "java.lang.Integer", "java.lang.Integer",
099                                    "com.liferay.portal.kernel.util.OrderByComparator"
100                            });
101            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
102                            TasksProposalModelImpl.FINDER_CACHE_ENABLED,
103                            FINDER_CLASS_NAME_LIST, "countByG_U",
104                            new String[] { Long.class.getName(), Long.class.getName() });
105            public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
106                            TasksProposalModelImpl.FINDER_CACHE_ENABLED,
107                            FINDER_CLASS_NAME_ENTITY, "fetchByC_C",
108                            new String[] { Long.class.getName(), String.class.getName() });
109            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
110                            TasksProposalModelImpl.FINDER_CACHE_ENABLED,
111                            FINDER_CLASS_NAME_LIST, "countByC_C",
112                            new String[] { Long.class.getName(), String.class.getName() });
113            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
114                            TasksProposalModelImpl.FINDER_CACHE_ENABLED,
115                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
116            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
117                            TasksProposalModelImpl.FINDER_CACHE_ENABLED,
118                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
119    
120            /**
121             * Caches the tasks proposal in the entity cache if it is enabled.
122             *
123             * @param tasksProposal the tasks proposal to cache
124             */
125            public void cacheResult(TasksProposal tasksProposal) {
126                    EntityCacheUtil.putResult(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
127                            TasksProposalImpl.class, tasksProposal.getPrimaryKey(),
128                            tasksProposal);
129    
130                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
131                            new Object[] {
132                                    new Long(tasksProposal.getClassNameId()),
133                                    
134                            tasksProposal.getClassPK()
135                            }, tasksProposal);
136            }
137    
138            /**
139             * Caches the tasks proposals in the entity cache if it is enabled.
140             *
141             * @param tasksProposals the tasks proposals to cache
142             */
143            public void cacheResult(List<TasksProposal> tasksProposals) {
144                    for (TasksProposal tasksProposal : tasksProposals) {
145                            if (EntityCacheUtil.getResult(
146                                                    TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
147                                                    TasksProposalImpl.class, tasksProposal.getPrimaryKey(),
148                                                    this) == null) {
149                                    cacheResult(tasksProposal);
150                            }
151                    }
152            }
153    
154            /**
155             * Clears the cache for all tasks proposals.
156             *
157             * <p>
158             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
159             * </p>
160             */
161            public void clearCache() {
162                    CacheRegistryUtil.clear(TasksProposalImpl.class.getName());
163                    EntityCacheUtil.clearCache(TasksProposalImpl.class.getName());
164                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
165                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
166            }
167    
168            /**
169             * Clears the cache for the tasks proposal.
170             *
171             * <p>
172             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
173             * </p>
174             */
175            public void clearCache(TasksProposal tasksProposal) {
176                    EntityCacheUtil.removeResult(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
177                            TasksProposalImpl.class, tasksProposal.getPrimaryKey());
178    
179                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
180                            new Object[] {
181                                    new Long(tasksProposal.getClassNameId()),
182                                    
183                            tasksProposal.getClassPK()
184                            });
185            }
186    
187            /**
188             * Creates a new tasks proposal with the primary key. Does not add the tasks proposal to the database.
189             *
190             * @param proposalId the primary key for the new tasks proposal
191             * @return the new tasks proposal
192             */
193            public TasksProposal create(long proposalId) {
194                    TasksProposal tasksProposal = new TasksProposalImpl();
195    
196                    tasksProposal.setNew(true);
197                    tasksProposal.setPrimaryKey(proposalId);
198    
199                    return tasksProposal;
200            }
201    
202            /**
203             * Removes the tasks proposal with the primary key from the database. Also notifies the appropriate model listeners.
204             *
205             * @param primaryKey the primary key of the tasks proposal to remove
206             * @return the tasks proposal that was removed
207             * @throws com.liferay.portal.NoSuchModelException if a tasks proposal with the primary key could not be found
208             * @throws SystemException if a system exception occurred
209             */
210            public TasksProposal remove(Serializable primaryKey)
211                    throws NoSuchModelException, SystemException {
212                    return remove(((Long)primaryKey).longValue());
213            }
214    
215            /**
216             * Removes the tasks proposal with the primary key from the database. Also notifies the appropriate model listeners.
217             *
218             * @param proposalId the primary key of the tasks proposal to remove
219             * @return the tasks proposal that was removed
220             * @throws com.liferay.portlet.tasks.NoSuchProposalException if a tasks proposal with the primary key could not be found
221             * @throws SystemException if a system exception occurred
222             */
223            public TasksProposal remove(long proposalId)
224                    throws NoSuchProposalException, SystemException {
225                    Session session = null;
226    
227                    try {
228                            session = openSession();
229    
230                            TasksProposal tasksProposal = (TasksProposal)session.get(TasksProposalImpl.class,
231                                            new Long(proposalId));
232    
233                            if (tasksProposal == null) {
234                                    if (_log.isWarnEnabled()) {
235                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + proposalId);
236                                    }
237    
238                                    throw new NoSuchProposalException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
239                                            proposalId);
240                            }
241    
242                            return remove(tasksProposal);
243                    }
244                    catch (NoSuchProposalException nsee) {
245                            throw nsee;
246                    }
247                    catch (Exception e) {
248                            throw processException(e);
249                    }
250                    finally {
251                            closeSession(session);
252                    }
253            }
254    
255            protected TasksProposal removeImpl(TasksProposal tasksProposal)
256                    throws SystemException {
257                    tasksProposal = toUnwrappedModel(tasksProposal);
258    
259                    Session session = null;
260    
261                    try {
262                            session = openSession();
263    
264                            BatchSessionUtil.delete(session, tasksProposal);
265                    }
266                    catch (Exception e) {
267                            throw processException(e);
268                    }
269                    finally {
270                            closeSession(session);
271                    }
272    
273                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
274    
275                    TasksProposalModelImpl tasksProposalModelImpl = (TasksProposalModelImpl)tasksProposal;
276    
277                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
278                            new Object[] {
279                                    new Long(tasksProposalModelImpl.getClassNameId()),
280                                    
281                            tasksProposalModelImpl.getClassPK()
282                            });
283    
284                    EntityCacheUtil.removeResult(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
285                            TasksProposalImpl.class, tasksProposal.getPrimaryKey());
286    
287                    return tasksProposal;
288            }
289    
290            public TasksProposal updateImpl(
291                    com.liferay.portlet.tasks.model.TasksProposal tasksProposal,
292                    boolean merge) throws SystemException {
293                    tasksProposal = toUnwrappedModel(tasksProposal);
294    
295                    boolean isNew = tasksProposal.isNew();
296    
297                    TasksProposalModelImpl tasksProposalModelImpl = (TasksProposalModelImpl)tasksProposal;
298    
299                    Session session = null;
300    
301                    try {
302                            session = openSession();
303    
304                            BatchSessionUtil.update(session, tasksProposal, merge);
305    
306                            tasksProposal.setNew(false);
307                    }
308                    catch (Exception e) {
309                            throw processException(e);
310                    }
311                    finally {
312                            closeSession(session);
313                    }
314    
315                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
316    
317                    EntityCacheUtil.putResult(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
318                            TasksProposalImpl.class, tasksProposal.getPrimaryKey(),
319                            tasksProposal);
320    
321                    if (!isNew &&
322                                    ((tasksProposal.getClassNameId() != tasksProposalModelImpl.getOriginalClassNameId()) ||
323                                    !Validator.equals(tasksProposal.getClassPK(),
324                                            tasksProposalModelImpl.getOriginalClassPK()))) {
325                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
326                                    new Object[] {
327                                            new Long(tasksProposalModelImpl.getOriginalClassNameId()),
328                                            
329                                    tasksProposalModelImpl.getOriginalClassPK()
330                                    });
331                    }
332    
333                    if (isNew ||
334                                    ((tasksProposal.getClassNameId() != tasksProposalModelImpl.getOriginalClassNameId()) ||
335                                    !Validator.equals(tasksProposal.getClassPK(),
336                                            tasksProposalModelImpl.getOriginalClassPK()))) {
337                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
338                                    new Object[] {
339                                            new Long(tasksProposal.getClassNameId()),
340                                            
341                                    tasksProposal.getClassPK()
342                                    }, tasksProposal);
343                    }
344    
345                    return tasksProposal;
346            }
347    
348            protected TasksProposal toUnwrappedModel(TasksProposal tasksProposal) {
349                    if (tasksProposal instanceof TasksProposalImpl) {
350                            return tasksProposal;
351                    }
352    
353                    TasksProposalImpl tasksProposalImpl = new TasksProposalImpl();
354    
355                    tasksProposalImpl.setNew(tasksProposal.isNew());
356                    tasksProposalImpl.setPrimaryKey(tasksProposal.getPrimaryKey());
357    
358                    tasksProposalImpl.setProposalId(tasksProposal.getProposalId());
359                    tasksProposalImpl.setGroupId(tasksProposal.getGroupId());
360                    tasksProposalImpl.setCompanyId(tasksProposal.getCompanyId());
361                    tasksProposalImpl.setUserId(tasksProposal.getUserId());
362                    tasksProposalImpl.setUserName(tasksProposal.getUserName());
363                    tasksProposalImpl.setCreateDate(tasksProposal.getCreateDate());
364                    tasksProposalImpl.setModifiedDate(tasksProposal.getModifiedDate());
365                    tasksProposalImpl.setClassNameId(tasksProposal.getClassNameId());
366                    tasksProposalImpl.setClassPK(tasksProposal.getClassPK());
367                    tasksProposalImpl.setName(tasksProposal.getName());
368                    tasksProposalImpl.setDescription(tasksProposal.getDescription());
369                    tasksProposalImpl.setPublishDate(tasksProposal.getPublishDate());
370                    tasksProposalImpl.setDueDate(tasksProposal.getDueDate());
371    
372                    return tasksProposalImpl;
373            }
374    
375            /**
376             * Finds the tasks proposal with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
377             *
378             * @param primaryKey the primary key of the tasks proposal to find
379             * @return the tasks proposal
380             * @throws com.liferay.portal.NoSuchModelException if a tasks proposal with the primary key could not be found
381             * @throws SystemException if a system exception occurred
382             */
383            public TasksProposal findByPrimaryKey(Serializable primaryKey)
384                    throws NoSuchModelException, SystemException {
385                    return findByPrimaryKey(((Long)primaryKey).longValue());
386            }
387    
388            /**
389             * Finds the tasks proposal with the primary key or throws a {@link com.liferay.portlet.tasks.NoSuchProposalException} if it could not be found.
390             *
391             * @param proposalId the primary key of the tasks proposal to find
392             * @return the tasks proposal
393             * @throws com.liferay.portlet.tasks.NoSuchProposalException if a tasks proposal with the primary key could not be found
394             * @throws SystemException if a system exception occurred
395             */
396            public TasksProposal findByPrimaryKey(long proposalId)
397                    throws NoSuchProposalException, SystemException {
398                    TasksProposal tasksProposal = fetchByPrimaryKey(proposalId);
399    
400                    if (tasksProposal == null) {
401                            if (_log.isWarnEnabled()) {
402                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + proposalId);
403                            }
404    
405                            throw new NoSuchProposalException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
406                                    proposalId);
407                    }
408    
409                    return tasksProposal;
410            }
411    
412            /**
413             * Finds the tasks proposal with the primary key or returns <code>null</code> if it could not be found.
414             *
415             * @param primaryKey the primary key of the tasks proposal to find
416             * @return the tasks proposal, or <code>null</code> if a tasks proposal with the primary key could not be found
417             * @throws SystemException if a system exception occurred
418             */
419            public TasksProposal fetchByPrimaryKey(Serializable primaryKey)
420                    throws SystemException {
421                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
422            }
423    
424            /**
425             * Finds the tasks proposal with the primary key or returns <code>null</code> if it could not be found.
426             *
427             * @param proposalId the primary key of the tasks proposal to find
428             * @return the tasks proposal, or <code>null</code> if a tasks proposal with the primary key could not be found
429             * @throws SystemException if a system exception occurred
430             */
431            public TasksProposal fetchByPrimaryKey(long proposalId)
432                    throws SystemException {
433                    TasksProposal tasksProposal = (TasksProposal)EntityCacheUtil.getResult(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
434                                    TasksProposalImpl.class, proposalId, this);
435    
436                    if (tasksProposal == null) {
437                            Session session = null;
438    
439                            try {
440                                    session = openSession();
441    
442                                    tasksProposal = (TasksProposal)session.get(TasksProposalImpl.class,
443                                                    new Long(proposalId));
444                            }
445                            catch (Exception e) {
446                                    throw processException(e);
447                            }
448                            finally {
449                                    if (tasksProposal != null) {
450                                            cacheResult(tasksProposal);
451                                    }
452    
453                                    closeSession(session);
454                            }
455                    }
456    
457                    return tasksProposal;
458            }
459    
460            /**
461             * Finds all the tasks proposals where groupId = &#63;.
462             *
463             * @param groupId the group id to search with
464             * @return the matching tasks proposals
465             * @throws SystemException if a system exception occurred
466             */
467            public List<TasksProposal> findByGroupId(long groupId)
468                    throws SystemException {
469                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
470            }
471    
472            /**
473             * Finds a range of all the tasks proposals where groupId = &#63;.
474             *
475             * <p>
476             * 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.
477             * </p>
478             *
479             * @param groupId the group id to search with
480             * @param start the lower bound of the range of tasks proposals to return
481             * @param end the upper bound of the range of tasks proposals to return (not inclusive)
482             * @return the range of matching tasks proposals
483             * @throws SystemException if a system exception occurred
484             */
485            public List<TasksProposal> findByGroupId(long groupId, int start, int end)
486                    throws SystemException {
487                    return findByGroupId(groupId, start, end, null);
488            }
489    
490            /**
491             * Finds an ordered range of all the tasks proposals where groupId = &#63;.
492             *
493             * <p>
494             * 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.
495             * </p>
496             *
497             * @param groupId the group id to search with
498             * @param start the lower bound of the range of tasks proposals to return
499             * @param end the upper bound of the range of tasks proposals to return (not inclusive)
500             * @param orderByComparator the comparator to order the results by
501             * @return the ordered range of matching tasks proposals
502             * @throws SystemException if a system exception occurred
503             */
504            public List<TasksProposal> findByGroupId(long groupId, int start, int end,
505                    OrderByComparator orderByComparator) throws SystemException {
506                    Object[] finderArgs = new Object[] {
507                                    groupId,
508                                    
509                                    String.valueOf(start), String.valueOf(end),
510                                    String.valueOf(orderByComparator)
511                            };
512    
513                    List<TasksProposal> list = (List<TasksProposal>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
514                                    finderArgs, this);
515    
516                    if (list == null) {
517                            StringBundler query = null;
518    
519                            if (orderByComparator != null) {
520                                    query = new StringBundler(3 +
521                                                    (orderByComparator.getOrderByFields().length * 3));
522                            }
523                            else {
524                                    query = new StringBundler(3);
525                            }
526    
527                            query.append(_SQL_SELECT_TASKSPROPOSAL_WHERE);
528    
529                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
530    
531                            if (orderByComparator != null) {
532                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
533                                            orderByComparator);
534                            }
535    
536                            else {
537                                    query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
538                            }
539    
540                            String sql = query.toString();
541    
542                            Session session = null;
543    
544                            try {
545                                    session = openSession();
546    
547                                    Query q = session.createQuery(sql);
548    
549                                    QueryPos qPos = QueryPos.getInstance(q);
550    
551                                    qPos.add(groupId);
552    
553                                    list = (List<TasksProposal>)QueryUtil.list(q, getDialect(),
554                                                    start, end);
555                            }
556                            catch (Exception e) {
557                                    throw processException(e);
558                            }
559                            finally {
560                                    if (list == null) {
561                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_GROUPID,
562                                                    finderArgs);
563                                    }
564                                    else {
565                                            cacheResult(list);
566    
567                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
568                                                    finderArgs, list);
569                                    }
570    
571                                    closeSession(session);
572                            }
573                    }
574    
575                    return list;
576            }
577    
578            /**
579             * Finds the first tasks proposal in the ordered set where groupId = &#63;.
580             *
581             * <p>
582             * 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.
583             * </p>
584             *
585             * @param groupId the group id to search with
586             * @param orderByComparator the comparator to order the set by
587             * @return the first matching tasks proposal
588             * @throws com.liferay.portlet.tasks.NoSuchProposalException if a matching tasks proposal could not be found
589             * @throws SystemException if a system exception occurred
590             */
591            public TasksProposal findByGroupId_First(long groupId,
592                    OrderByComparator orderByComparator)
593                    throws NoSuchProposalException, SystemException {
594                    List<TasksProposal> list = findByGroupId(groupId, 0, 1,
595                                    orderByComparator);
596    
597                    if (list.isEmpty()) {
598                            StringBundler msg = new StringBundler(4);
599    
600                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
601    
602                            msg.append("groupId=");
603                            msg.append(groupId);
604    
605                            msg.append(StringPool.CLOSE_CURLY_BRACE);
606    
607                            throw new NoSuchProposalException(msg.toString());
608                    }
609                    else {
610                            return list.get(0);
611                    }
612            }
613    
614            /**
615             * Finds the last tasks proposal in the ordered set where groupId = &#63;.
616             *
617             * <p>
618             * 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.
619             * </p>
620             *
621             * @param groupId the group id to search with
622             * @param orderByComparator the comparator to order the set by
623             * @return the last matching tasks proposal
624             * @throws com.liferay.portlet.tasks.NoSuchProposalException if a matching tasks proposal could not be found
625             * @throws SystemException if a system exception occurred
626             */
627            public TasksProposal findByGroupId_Last(long groupId,
628                    OrderByComparator orderByComparator)
629                    throws NoSuchProposalException, SystemException {
630                    int count = countByGroupId(groupId);
631    
632                    List<TasksProposal> list = findByGroupId(groupId, count - 1, count,
633                                    orderByComparator);
634    
635                    if (list.isEmpty()) {
636                            StringBundler msg = new StringBundler(4);
637    
638                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
639    
640                            msg.append("groupId=");
641                            msg.append(groupId);
642    
643                            msg.append(StringPool.CLOSE_CURLY_BRACE);
644    
645                            throw new NoSuchProposalException(msg.toString());
646                    }
647                    else {
648                            return list.get(0);
649                    }
650            }
651    
652            /**
653             * Finds the tasks proposals before and after the current tasks proposal in the ordered set where groupId = &#63;.
654             *
655             * <p>
656             * 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.
657             * </p>
658             *
659             * @param proposalId the primary key of the current tasks proposal
660             * @param groupId the group id to search with
661             * @param orderByComparator the comparator to order the set by
662             * @return the previous, current, and next tasks proposal
663             * @throws com.liferay.portlet.tasks.NoSuchProposalException if a tasks proposal with the primary key could not be found
664             * @throws SystemException if a system exception occurred
665             */
666            public TasksProposal[] findByGroupId_PrevAndNext(long proposalId,
667                    long groupId, OrderByComparator orderByComparator)
668                    throws NoSuchProposalException, SystemException {
669                    TasksProposal tasksProposal = findByPrimaryKey(proposalId);
670    
671                    Session session = null;
672    
673                    try {
674                            session = openSession();
675    
676                            TasksProposal[] array = new TasksProposalImpl[3];
677    
678                            array[0] = getByGroupId_PrevAndNext(session, tasksProposal,
679                                            groupId, orderByComparator, true);
680    
681                            array[1] = tasksProposal;
682    
683                            array[2] = getByGroupId_PrevAndNext(session, tasksProposal,
684                                            groupId, orderByComparator, false);
685    
686                            return array;
687                    }
688                    catch (Exception e) {
689                            throw processException(e);
690                    }
691                    finally {
692                            closeSession(session);
693                    }
694            }
695    
696            protected TasksProposal getByGroupId_PrevAndNext(Session session,
697                    TasksProposal tasksProposal, long groupId,
698                    OrderByComparator orderByComparator, boolean previous) {
699                    StringBundler query = null;
700    
701                    if (orderByComparator != null) {
702                            query = new StringBundler(6 +
703                                            (orderByComparator.getOrderByFields().length * 6));
704                    }
705                    else {
706                            query = new StringBundler(3);
707                    }
708    
709                    query.append(_SQL_SELECT_TASKSPROPOSAL_WHERE);
710    
711                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
712    
713                    if (orderByComparator != null) {
714                            String[] orderByFields = orderByComparator.getOrderByFields();
715    
716                            if (orderByFields.length > 0) {
717                                    query.append(WHERE_AND);
718                            }
719    
720                            for (int i = 0; i < orderByFields.length; i++) {
721                                    query.append(_ORDER_BY_ENTITY_ALIAS);
722                                    query.append(orderByFields[i]);
723    
724                                    if ((i + 1) < orderByFields.length) {
725                                            if (orderByComparator.isAscending() ^ previous) {
726                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
727                                            }
728                                            else {
729                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
730                                            }
731                                    }
732                                    else {
733                                            if (orderByComparator.isAscending() ^ previous) {
734                                                    query.append(WHERE_GREATER_THAN);
735                                            }
736                                            else {
737                                                    query.append(WHERE_LESSER_THAN);
738                                            }
739                                    }
740                            }
741    
742                            query.append(ORDER_BY_CLAUSE);
743    
744                            for (int i = 0; i < orderByFields.length; i++) {
745                                    query.append(_ORDER_BY_ENTITY_ALIAS);
746                                    query.append(orderByFields[i]);
747    
748                                    if ((i + 1) < orderByFields.length) {
749                                            if (orderByComparator.isAscending() ^ previous) {
750                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
751                                            }
752                                            else {
753                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
754                                            }
755                                    }
756                                    else {
757                                            if (orderByComparator.isAscending() ^ previous) {
758                                                    query.append(ORDER_BY_ASC);
759                                            }
760                                            else {
761                                                    query.append(ORDER_BY_DESC);
762                                            }
763                                    }
764                            }
765                    }
766    
767                    else {
768                            query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
769                    }
770    
771                    String sql = query.toString();
772    
773                    Query q = session.createQuery(sql);
774    
775                    q.setFirstResult(0);
776                    q.setMaxResults(2);
777    
778                    QueryPos qPos = QueryPos.getInstance(q);
779    
780                    qPos.add(groupId);
781    
782                    if (orderByComparator != null) {
783                            Object[] values = orderByComparator.getOrderByValues(tasksProposal);
784    
785                            for (Object value : values) {
786                                    qPos.add(value);
787                            }
788                    }
789    
790                    List<TasksProposal> list = q.list();
791    
792                    if (list.size() == 2) {
793                            return list.get(1);
794                    }
795                    else {
796                            return null;
797                    }
798            }
799    
800            /**
801             * Filters by the user's permissions and finds all the tasks proposals where groupId = &#63;.
802             *
803             * @param groupId the group id to search with
804             * @return the matching tasks proposals that the user has permission to view
805             * @throws SystemException if a system exception occurred
806             */
807            public List<TasksProposal> filterFindByGroupId(long groupId)
808                    throws SystemException {
809                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
810                            QueryUtil.ALL_POS, null);
811            }
812    
813            /**
814             * Filters by the user's permissions and finds a range of all the tasks proposals where groupId = &#63;.
815             *
816             * <p>
817             * 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.
818             * </p>
819             *
820             * @param groupId the group id to search with
821             * @param start the lower bound of the range of tasks proposals to return
822             * @param end the upper bound of the range of tasks proposals to return (not inclusive)
823             * @return the range of matching tasks proposals that the user has permission to view
824             * @throws SystemException if a system exception occurred
825             */
826            public List<TasksProposal> filterFindByGroupId(long groupId, int start,
827                    int end) throws SystemException {
828                    return filterFindByGroupId(groupId, start, end, null);
829            }
830    
831            /**
832             * Filters by the user's permissions and finds an ordered range of all the tasks proposals where groupId = &#63;.
833             *
834             * <p>
835             * 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.
836             * </p>
837             *
838             * @param groupId the group id to search with
839             * @param start the lower bound of the range of tasks proposals to return
840             * @param end the upper bound of the range of tasks proposals to return (not inclusive)
841             * @param orderByComparator the comparator to order the results by
842             * @return the ordered range of matching tasks proposals that the user has permission to view
843             * @throws SystemException if a system exception occurred
844             */
845            public List<TasksProposal> filterFindByGroupId(long groupId, int start,
846                    int end, OrderByComparator orderByComparator) throws SystemException {
847                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
848                            return findByGroupId(groupId, start, end, orderByComparator);
849                    }
850    
851                    StringBundler query = null;
852    
853                    if (orderByComparator != null) {
854                            query = new StringBundler(3 +
855                                            (orderByComparator.getOrderByFields().length * 3));
856                    }
857                    else {
858                            query = new StringBundler(3);
859                    }
860    
861                    if (getDB().isSupportsInlineDistinct()) {
862                            query.append(_FILTER_SQL_SELECT_TASKSPROPOSAL_WHERE);
863                    }
864                    else {
865                            query.append(_FILTER_SQL_SELECT_TASKSPROPOSAL_NO_INLINE_DISTINCT_WHERE_1);
866                    }
867    
868                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
869    
870                    if (!getDB().isSupportsInlineDistinct()) {
871                            query.append(_FILTER_SQL_SELECT_TASKSPROPOSAL_NO_INLINE_DISTINCT_WHERE_2);
872                    }
873    
874                    if (orderByComparator != null) {
875                            if (getDB().isSupportsInlineDistinct()) {
876                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
877                                            orderByComparator);
878                            }
879                            else {
880                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
881                                            orderByComparator);
882                            }
883                    }
884    
885                    else {
886                            if (getDB().isSupportsInlineDistinct()) {
887                                    query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
888                            }
889                            else {
890                                    query.append(TasksProposalModelImpl.ORDER_BY_SQL);
891                            }
892                    }
893    
894                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
895                                    TasksProposal.class.getName(), _FILTER_COLUMN_PK,
896                                    _FILTER_COLUMN_USERID, groupId);
897    
898                    Session session = null;
899    
900                    try {
901                            session = openSession();
902    
903                            SQLQuery q = session.createSQLQuery(sql);
904    
905                            if (getDB().isSupportsInlineDistinct()) {
906                                    q.addEntity(_FILTER_ENTITY_ALIAS, TasksProposalImpl.class);
907                            }
908                            else {
909                                    q.addEntity(_FILTER_ENTITY_TABLE, TasksProposalImpl.class);
910                            }
911    
912                            QueryPos qPos = QueryPos.getInstance(q);
913    
914                            qPos.add(groupId);
915    
916                            return (List<TasksProposal>)QueryUtil.list(q, getDialect(), start,
917                                    end);
918                    }
919                    catch (Exception e) {
920                            throw processException(e);
921                    }
922                    finally {
923                            closeSession(session);
924                    }
925            }
926    
927            /**
928             * Finds all the tasks proposals where groupId = &#63; and userId = &#63;.
929             *
930             * @param groupId the group id to search with
931             * @param userId the user id to search with
932             * @return the matching tasks proposals
933             * @throws SystemException if a system exception occurred
934             */
935            public List<TasksProposal> findByG_U(long groupId, long userId)
936                    throws SystemException {
937                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
938                            null);
939            }
940    
941            /**
942             * Finds a range of all the tasks proposals where groupId = &#63; and userId = &#63;.
943             *
944             * <p>
945             * 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.
946             * </p>
947             *
948             * @param groupId the group id to search with
949             * @param userId the user id to search with
950             * @param start the lower bound of the range of tasks proposals to return
951             * @param end the upper bound of the range of tasks proposals to return (not inclusive)
952             * @return the range of matching tasks proposals
953             * @throws SystemException if a system exception occurred
954             */
955            public List<TasksProposal> findByG_U(long groupId, long userId, int start,
956                    int end) throws SystemException {
957                    return findByG_U(groupId, userId, start, end, null);
958            }
959    
960            /**
961             * Finds an ordered range of all the tasks proposals where groupId = &#63; and userId = &#63;.
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 groupId the group id to search with
968             * @param userId the user id to search with
969             * @param start the lower bound of the range of tasks proposals to return
970             * @param end the upper bound of the range of tasks proposals to return (not inclusive)
971             * @param orderByComparator the comparator to order the results by
972             * @return the ordered range of matching tasks proposals
973             * @throws SystemException if a system exception occurred
974             */
975            public List<TasksProposal> findByG_U(long groupId, long userId, int start,
976                    int end, OrderByComparator orderByComparator) throws SystemException {
977                    Object[] finderArgs = new Object[] {
978                                    groupId, userId,
979                                    
980                                    String.valueOf(start), String.valueOf(end),
981                                    String.valueOf(orderByComparator)
982                            };
983    
984                    List<TasksProposal> list = (List<TasksProposal>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_U,
985                                    finderArgs, this);
986    
987                    if (list == null) {
988                            StringBundler query = null;
989    
990                            if (orderByComparator != null) {
991                                    query = new StringBundler(4 +
992                                                    (orderByComparator.getOrderByFields().length * 3));
993                            }
994                            else {
995                                    query = new StringBundler(4);
996                            }
997    
998                            query.append(_SQL_SELECT_TASKSPROPOSAL_WHERE);
999    
1000                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1001    
1002                            query.append(_FINDER_COLUMN_G_U_USERID_2);
1003    
1004                            if (orderByComparator != null) {
1005                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1006                                            orderByComparator);
1007                            }
1008    
1009                            else {
1010                                    query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
1011                            }
1012    
1013                            String sql = query.toString();
1014    
1015                            Session session = null;
1016    
1017                            try {
1018                                    session = openSession();
1019    
1020                                    Query q = session.createQuery(sql);
1021    
1022                                    QueryPos qPos = QueryPos.getInstance(q);
1023    
1024                                    qPos.add(groupId);
1025    
1026                                    qPos.add(userId);
1027    
1028                                    list = (List<TasksProposal>)QueryUtil.list(q, getDialect(),
1029                                                    start, end);
1030                            }
1031                            catch (Exception e) {
1032                                    throw processException(e);
1033                            }
1034                            finally {
1035                                    if (list == null) {
1036                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_G_U,
1037                                                    finderArgs);
1038                                    }
1039                                    else {
1040                                            cacheResult(list);
1041    
1042                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_U,
1043                                                    finderArgs, list);
1044                                    }
1045    
1046                                    closeSession(session);
1047                            }
1048                    }
1049    
1050                    return list;
1051            }
1052    
1053            /**
1054             * Finds the first tasks proposal in the ordered set where groupId = &#63; and userId = &#63;.
1055             *
1056             * <p>
1057             * 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.
1058             * </p>
1059             *
1060             * @param groupId the group id to search with
1061             * @param userId the user id to search with
1062             * @param orderByComparator the comparator to order the set by
1063             * @return the first matching tasks proposal
1064             * @throws com.liferay.portlet.tasks.NoSuchProposalException if a matching tasks proposal could not be found
1065             * @throws SystemException if a system exception occurred
1066             */
1067            public TasksProposal findByG_U_First(long groupId, long userId,
1068                    OrderByComparator orderByComparator)
1069                    throws NoSuchProposalException, SystemException {
1070                    List<TasksProposal> list = findByG_U(groupId, userId, 0, 1,
1071                                    orderByComparator);
1072    
1073                    if (list.isEmpty()) {
1074                            StringBundler msg = new StringBundler(6);
1075    
1076                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1077    
1078                            msg.append("groupId=");
1079                            msg.append(groupId);
1080    
1081                            msg.append(", userId=");
1082                            msg.append(userId);
1083    
1084                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1085    
1086                            throw new NoSuchProposalException(msg.toString());
1087                    }
1088                    else {
1089                            return list.get(0);
1090                    }
1091            }
1092    
1093            /**
1094             * Finds the last tasks proposal in the ordered set where groupId = &#63; and userId = &#63;.
1095             *
1096             * <p>
1097             * 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.
1098             * </p>
1099             *
1100             * @param groupId the group id to search with
1101             * @param userId the user id to search with
1102             * @param orderByComparator the comparator to order the set by
1103             * @return the last matching tasks proposal
1104             * @throws com.liferay.portlet.tasks.NoSuchProposalException if a matching tasks proposal could not be found
1105             * @throws SystemException if a system exception occurred
1106             */
1107            public TasksProposal findByG_U_Last(long groupId, long userId,
1108                    OrderByComparator orderByComparator)
1109                    throws NoSuchProposalException, SystemException {
1110                    int count = countByG_U(groupId, userId);
1111    
1112                    List<TasksProposal> list = findByG_U(groupId, userId, count - 1, count,
1113                                    orderByComparator);
1114    
1115                    if (list.isEmpty()) {
1116                            StringBundler msg = new StringBundler(6);
1117    
1118                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1119    
1120                            msg.append("groupId=");
1121                            msg.append(groupId);
1122    
1123                            msg.append(", userId=");
1124                            msg.append(userId);
1125    
1126                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1127    
1128                            throw new NoSuchProposalException(msg.toString());
1129                    }
1130                    else {
1131                            return list.get(0);
1132                    }
1133            }
1134    
1135            /**
1136             * Finds the tasks proposals before and after the current tasks proposal in the ordered set where groupId = &#63; and userId = &#63;.
1137             *
1138             * <p>
1139             * 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.
1140             * </p>
1141             *
1142             * @param proposalId the primary key of the current tasks proposal
1143             * @param groupId the group id to search with
1144             * @param userId the user id to search with
1145             * @param orderByComparator the comparator to order the set by
1146             * @return the previous, current, and next tasks proposal
1147             * @throws com.liferay.portlet.tasks.NoSuchProposalException if a tasks proposal with the primary key could not be found
1148             * @throws SystemException if a system exception occurred
1149             */
1150            public TasksProposal[] findByG_U_PrevAndNext(long proposalId, long groupId,
1151                    long userId, OrderByComparator orderByComparator)
1152                    throws NoSuchProposalException, SystemException {
1153                    TasksProposal tasksProposal = findByPrimaryKey(proposalId);
1154    
1155                    Session session = null;
1156    
1157                    try {
1158                            session = openSession();
1159    
1160                            TasksProposal[] array = new TasksProposalImpl[3];
1161    
1162                            array[0] = getByG_U_PrevAndNext(session, tasksProposal, groupId,
1163                                            userId, orderByComparator, true);
1164    
1165                            array[1] = tasksProposal;
1166    
1167                            array[2] = getByG_U_PrevAndNext(session, tasksProposal, groupId,
1168                                            userId, orderByComparator, false);
1169    
1170                            return array;
1171                    }
1172                    catch (Exception e) {
1173                            throw processException(e);
1174                    }
1175                    finally {
1176                            closeSession(session);
1177                    }
1178            }
1179    
1180            protected TasksProposal getByG_U_PrevAndNext(Session session,
1181                    TasksProposal tasksProposal, long groupId, long userId,
1182                    OrderByComparator orderByComparator, boolean previous) {
1183                    StringBundler query = null;
1184    
1185                    if (orderByComparator != null) {
1186                            query = new StringBundler(6 +
1187                                            (orderByComparator.getOrderByFields().length * 6));
1188                    }
1189                    else {
1190                            query = new StringBundler(3);
1191                    }
1192    
1193                    query.append(_SQL_SELECT_TASKSPROPOSAL_WHERE);
1194    
1195                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1196    
1197                    query.append(_FINDER_COLUMN_G_U_USERID_2);
1198    
1199                    if (orderByComparator != null) {
1200                            String[] orderByFields = orderByComparator.getOrderByFields();
1201    
1202                            if (orderByFields.length > 0) {
1203                                    query.append(WHERE_AND);
1204                            }
1205    
1206                            for (int i = 0; i < orderByFields.length; i++) {
1207                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1208                                    query.append(orderByFields[i]);
1209    
1210                                    if ((i + 1) < orderByFields.length) {
1211                                            if (orderByComparator.isAscending() ^ previous) {
1212                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1213                                            }
1214                                            else {
1215                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1216                                            }
1217                                    }
1218                                    else {
1219                                            if (orderByComparator.isAscending() ^ previous) {
1220                                                    query.append(WHERE_GREATER_THAN);
1221                                            }
1222                                            else {
1223                                                    query.append(WHERE_LESSER_THAN);
1224                                            }
1225                                    }
1226                            }
1227    
1228                            query.append(ORDER_BY_CLAUSE);
1229    
1230                            for (int i = 0; i < orderByFields.length; i++) {
1231                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1232                                    query.append(orderByFields[i]);
1233    
1234                                    if ((i + 1) < orderByFields.length) {
1235                                            if (orderByComparator.isAscending() ^ previous) {
1236                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1237                                            }
1238                                            else {
1239                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1240                                            }
1241                                    }
1242                                    else {
1243                                            if (orderByComparator.isAscending() ^ previous) {
1244                                                    query.append(ORDER_BY_ASC);
1245                                            }
1246                                            else {
1247                                                    query.append(ORDER_BY_DESC);
1248                                            }
1249                                    }
1250                            }
1251                    }
1252    
1253                    else {
1254                            query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
1255                    }
1256    
1257                    String sql = query.toString();
1258    
1259                    Query q = session.createQuery(sql);
1260    
1261                    q.setFirstResult(0);
1262                    q.setMaxResults(2);
1263    
1264                    QueryPos qPos = QueryPos.getInstance(q);
1265    
1266                    qPos.add(groupId);
1267    
1268                    qPos.add(userId);
1269    
1270                    if (orderByComparator != null) {
1271                            Object[] values = orderByComparator.getOrderByValues(tasksProposal);
1272    
1273                            for (Object value : values) {
1274                                    qPos.add(value);
1275                            }
1276                    }
1277    
1278                    List<TasksProposal> list = q.list();
1279    
1280                    if (list.size() == 2) {
1281                            return list.get(1);
1282                    }
1283                    else {
1284                            return null;
1285                    }
1286            }
1287    
1288            /**
1289             * Filters by the user's permissions and finds all the tasks proposals where groupId = &#63; and userId = &#63;.
1290             *
1291             * @param groupId the group id to search with
1292             * @param userId the user id to search with
1293             * @return the matching tasks proposals that the user has permission to view
1294             * @throws SystemException if a system exception occurred
1295             */
1296            public List<TasksProposal> filterFindByG_U(long groupId, long userId)
1297                    throws SystemException {
1298                    return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
1299                            QueryUtil.ALL_POS, null);
1300            }
1301    
1302            /**
1303             * Filters by the user's permissions and finds a range of all the tasks proposals where groupId = &#63; and userId = &#63;.
1304             *
1305             * <p>
1306             * 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.
1307             * </p>
1308             *
1309             * @param groupId the group id to search with
1310             * @param userId the user id to search with
1311             * @param start the lower bound of the range of tasks proposals to return
1312             * @param end the upper bound of the range of tasks proposals to return (not inclusive)
1313             * @return the range of matching tasks proposals that the user has permission to view
1314             * @throws SystemException if a system exception occurred
1315             */
1316            public List<TasksProposal> filterFindByG_U(long groupId, long userId,
1317                    int start, int end) throws SystemException {
1318                    return filterFindByG_U(groupId, userId, start, end, null);
1319            }
1320    
1321            /**
1322             * Filters by the user's permissions and finds an ordered range of all the tasks proposals where groupId = &#63; and userId = &#63;.
1323             *
1324             * <p>
1325             * 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.
1326             * </p>
1327             *
1328             * @param groupId the group id to search with
1329             * @param userId the user id to search with
1330             * @param start the lower bound of the range of tasks proposals to return
1331             * @param end the upper bound of the range of tasks proposals to return (not inclusive)
1332             * @param orderByComparator the comparator to order the results by
1333             * @return the ordered range of matching tasks proposals that the user has permission to view
1334             * @throws SystemException if a system exception occurred
1335             */
1336            public List<TasksProposal> filterFindByG_U(long groupId, long userId,
1337                    int start, int end, OrderByComparator orderByComparator)
1338                    throws SystemException {
1339                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1340                            return findByG_U(groupId, userId, start, end, orderByComparator);
1341                    }
1342    
1343                    StringBundler query = null;
1344    
1345                    if (orderByComparator != null) {
1346                            query = new StringBundler(4 +
1347                                            (orderByComparator.getOrderByFields().length * 3));
1348                    }
1349                    else {
1350                            query = new StringBundler(4);
1351                    }
1352    
1353                    if (getDB().isSupportsInlineDistinct()) {
1354                            query.append(_FILTER_SQL_SELECT_TASKSPROPOSAL_WHERE);
1355                    }
1356                    else {
1357                            query.append(_FILTER_SQL_SELECT_TASKSPROPOSAL_NO_INLINE_DISTINCT_WHERE_1);
1358                    }
1359    
1360                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1361    
1362                    query.append(_FINDER_COLUMN_G_U_USERID_2);
1363    
1364                    if (!getDB().isSupportsInlineDistinct()) {
1365                            query.append(_FILTER_SQL_SELECT_TASKSPROPOSAL_NO_INLINE_DISTINCT_WHERE_2);
1366                    }
1367    
1368                    if (orderByComparator != null) {
1369                            if (getDB().isSupportsInlineDistinct()) {
1370                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1371                                            orderByComparator);
1372                            }
1373                            else {
1374                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1375                                            orderByComparator);
1376                            }
1377                    }
1378    
1379                    else {
1380                            if (getDB().isSupportsInlineDistinct()) {
1381                                    query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
1382                            }
1383                            else {
1384                                    query.append(TasksProposalModelImpl.ORDER_BY_SQL);
1385                            }
1386                    }
1387    
1388                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1389                                    TasksProposal.class.getName(), _FILTER_COLUMN_PK,
1390                                    _FILTER_COLUMN_USERID, groupId);
1391    
1392                    Session session = null;
1393    
1394                    try {
1395                            session = openSession();
1396    
1397                            SQLQuery q = session.createSQLQuery(sql);
1398    
1399                            if (getDB().isSupportsInlineDistinct()) {
1400                                    q.addEntity(_FILTER_ENTITY_ALIAS, TasksProposalImpl.class);
1401                            }
1402                            else {
1403                                    q.addEntity(_FILTER_ENTITY_TABLE, TasksProposalImpl.class);
1404                            }
1405    
1406                            QueryPos qPos = QueryPos.getInstance(q);
1407    
1408                            qPos.add(groupId);
1409    
1410                            qPos.add(userId);
1411    
1412                            return (List<TasksProposal>)QueryUtil.list(q, getDialect(), start,
1413                                    end);
1414                    }
1415                    catch (Exception e) {
1416                            throw processException(e);
1417                    }
1418                    finally {
1419                            closeSession(session);
1420                    }
1421            }
1422    
1423            /**
1424             * Finds the tasks proposal where classNameId = &#63; and classPK = &#63; or throws a {@link com.liferay.portlet.tasks.NoSuchProposalException} if it could not be found.
1425             *
1426             * @param classNameId the class name id to search with
1427             * @param classPK the class p k to search with
1428             * @return the matching tasks proposal
1429             * @throws com.liferay.portlet.tasks.NoSuchProposalException if a matching tasks proposal could not be found
1430             * @throws SystemException if a system exception occurred
1431             */
1432            public TasksProposal findByC_C(long classNameId, String classPK)
1433                    throws NoSuchProposalException, SystemException {
1434                    TasksProposal tasksProposal = fetchByC_C(classNameId, classPK);
1435    
1436                    if (tasksProposal == null) {
1437                            StringBundler msg = new StringBundler(6);
1438    
1439                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1440    
1441                            msg.append("classNameId=");
1442                            msg.append(classNameId);
1443    
1444                            msg.append(", classPK=");
1445                            msg.append(classPK);
1446    
1447                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1448    
1449                            if (_log.isWarnEnabled()) {
1450                                    _log.warn(msg.toString());
1451                            }
1452    
1453                            throw new NoSuchProposalException(msg.toString());
1454                    }
1455    
1456                    return tasksProposal;
1457            }
1458    
1459            /**
1460             * Finds the tasks proposal where classNameId = &#63; and classPK = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1461             *
1462             * @param classNameId the class name id to search with
1463             * @param classPK the class p k to search with
1464             * @return the matching tasks proposal, or <code>null</code> if a matching tasks proposal could not be found
1465             * @throws SystemException if a system exception occurred
1466             */
1467            public TasksProposal fetchByC_C(long classNameId, String classPK)
1468                    throws SystemException {
1469                    return fetchByC_C(classNameId, classPK, true);
1470            }
1471    
1472            /**
1473             * Finds the tasks proposal where classNameId = &#63; and classPK = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1474             *
1475             * @param classNameId the class name id to search with
1476             * @param classPK the class p k to search with
1477             * @return the matching tasks proposal, or <code>null</code> if a matching tasks proposal could not be found
1478             * @throws SystemException if a system exception occurred
1479             */
1480            public TasksProposal fetchByC_C(long classNameId, String classPK,
1481                    boolean retrieveFromCache) throws SystemException {
1482                    Object[] finderArgs = new Object[] { classNameId, classPK };
1483    
1484                    Object result = null;
1485    
1486                    if (retrieveFromCache) {
1487                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
1488                                            finderArgs, this);
1489                    }
1490    
1491                    if (result == null) {
1492                            StringBundler query = new StringBundler(4);
1493    
1494                            query.append(_SQL_SELECT_TASKSPROPOSAL_WHERE);
1495    
1496                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1497    
1498                            if (classPK == null) {
1499                                    query.append(_FINDER_COLUMN_C_C_CLASSPK_1);
1500                            }
1501                            else {
1502                                    if (classPK.equals(StringPool.BLANK)) {
1503                                            query.append(_FINDER_COLUMN_C_C_CLASSPK_3);
1504                                    }
1505                                    else {
1506                                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1507                                    }
1508                            }
1509    
1510                            query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
1511    
1512                            String sql = query.toString();
1513    
1514                            Session session = null;
1515    
1516                            try {
1517                                    session = openSession();
1518    
1519                                    Query q = session.createQuery(sql);
1520    
1521                                    QueryPos qPos = QueryPos.getInstance(q);
1522    
1523                                    qPos.add(classNameId);
1524    
1525                                    if (classPK != null) {
1526                                            qPos.add(classPK);
1527                                    }
1528    
1529                                    List<TasksProposal> list = q.list();
1530    
1531                                    result = list;
1532    
1533                                    TasksProposal tasksProposal = null;
1534    
1535                                    if (list.isEmpty()) {
1536                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
1537                                                    finderArgs, list);
1538                                    }
1539                                    else {
1540                                            tasksProposal = list.get(0);
1541    
1542                                            cacheResult(tasksProposal);
1543    
1544                                            if ((tasksProposal.getClassNameId() != classNameId) ||
1545                                                            (tasksProposal.getClassPK() == null) ||
1546                                                            !tasksProposal.getClassPK().equals(classPK)) {
1547                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
1548                                                            finderArgs, tasksProposal);
1549                                            }
1550                                    }
1551    
1552                                    return tasksProposal;
1553                            }
1554                            catch (Exception e) {
1555                                    throw processException(e);
1556                            }
1557                            finally {
1558                                    if (result == null) {
1559                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
1560                                                    finderArgs);
1561                                    }
1562    
1563                                    closeSession(session);
1564                            }
1565                    }
1566                    else {
1567                            if (result instanceof List<?>) {
1568                                    return null;
1569                            }
1570                            else {
1571                                    return (TasksProposal)result;
1572                            }
1573                    }
1574            }
1575    
1576            /**
1577             * Finds all the tasks proposals.
1578             *
1579             * @return the tasks proposals
1580             * @throws SystemException if a system exception occurred
1581             */
1582            public List<TasksProposal> findAll() throws SystemException {
1583                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1584            }
1585    
1586            /**
1587             * Finds a range of all the tasks proposals.
1588             *
1589             * <p>
1590             * 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.
1591             * </p>
1592             *
1593             * @param start the lower bound of the range of tasks proposals to return
1594             * @param end the upper bound of the range of tasks proposals to return (not inclusive)
1595             * @return the range of tasks proposals
1596             * @throws SystemException if a system exception occurred
1597             */
1598            public List<TasksProposal> findAll(int start, int end)
1599                    throws SystemException {
1600                    return findAll(start, end, null);
1601            }
1602    
1603            /**
1604             * Finds an ordered range of all the tasks proposals.
1605             *
1606             * <p>
1607             * 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.
1608             * </p>
1609             *
1610             * @param start the lower bound of the range of tasks proposals to return
1611             * @param end the upper bound of the range of tasks proposals to return (not inclusive)
1612             * @param orderByComparator the comparator to order the results by
1613             * @return the ordered range of tasks proposals
1614             * @throws SystemException if a system exception occurred
1615             */
1616            public List<TasksProposal> findAll(int start, int end,
1617                    OrderByComparator orderByComparator) throws SystemException {
1618                    Object[] finderArgs = new Object[] {
1619                                    String.valueOf(start), String.valueOf(end),
1620                                    String.valueOf(orderByComparator)
1621                            };
1622    
1623                    List<TasksProposal> list = (List<TasksProposal>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1624                                    finderArgs, this);
1625    
1626                    if (list == null) {
1627                            StringBundler query = null;
1628                            String sql = null;
1629    
1630                            if (orderByComparator != null) {
1631                                    query = new StringBundler(2 +
1632                                                    (orderByComparator.getOrderByFields().length * 3));
1633    
1634                                    query.append(_SQL_SELECT_TASKSPROPOSAL);
1635    
1636                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1637                                            orderByComparator);
1638    
1639                                    sql = query.toString();
1640                            }
1641                            else {
1642                                    sql = _SQL_SELECT_TASKSPROPOSAL.concat(TasksProposalModelImpl.ORDER_BY_JPQL);
1643                            }
1644    
1645                            Session session = null;
1646    
1647                            try {
1648                                    session = openSession();
1649    
1650                                    Query q = session.createQuery(sql);
1651    
1652                                    if (orderByComparator == null) {
1653                                            list = (List<TasksProposal>)QueryUtil.list(q, getDialect(),
1654                                                            start, end, false);
1655    
1656                                            Collections.sort(list);
1657                                    }
1658                                    else {
1659                                            list = (List<TasksProposal>)QueryUtil.list(q, getDialect(),
1660                                                            start, end);
1661                                    }
1662                            }
1663                            catch (Exception e) {
1664                                    throw processException(e);
1665                            }
1666                            finally {
1667                                    if (list == null) {
1668                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
1669                                                    finderArgs);
1670                                    }
1671                                    else {
1672                                            cacheResult(list);
1673    
1674                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
1675                                                    list);
1676                                    }
1677    
1678                                    closeSession(session);
1679                            }
1680                    }
1681    
1682                    return list;
1683            }
1684    
1685            /**
1686             * Removes all the tasks proposals where groupId = &#63; from the database.
1687             *
1688             * @param groupId the group id to search with
1689             * @throws SystemException if a system exception occurred
1690             */
1691            public void removeByGroupId(long groupId) throws SystemException {
1692                    for (TasksProposal tasksProposal : findByGroupId(groupId)) {
1693                            remove(tasksProposal);
1694                    }
1695            }
1696    
1697            /**
1698             * Removes all the tasks proposals where groupId = &#63; and userId = &#63; from the database.
1699             *
1700             * @param groupId the group id to search with
1701             * @param userId the user id to search with
1702             * @throws SystemException if a system exception occurred
1703             */
1704            public void removeByG_U(long groupId, long userId)
1705                    throws SystemException {
1706                    for (TasksProposal tasksProposal : findByG_U(groupId, userId)) {
1707                            remove(tasksProposal);
1708                    }
1709            }
1710    
1711            /**
1712             * Removes the tasks proposal where classNameId = &#63; and classPK = &#63; from the database.
1713             *
1714             * @param classNameId the class name id to search with
1715             * @param classPK the class p k to search with
1716             * @throws SystemException if a system exception occurred
1717             */
1718            public void removeByC_C(long classNameId, String classPK)
1719                    throws NoSuchProposalException, SystemException {
1720                    TasksProposal tasksProposal = findByC_C(classNameId, classPK);
1721    
1722                    remove(tasksProposal);
1723            }
1724    
1725            /**
1726             * Removes all the tasks proposals from the database.
1727             *
1728             * @throws SystemException if a system exception occurred
1729             */
1730            public void removeAll() throws SystemException {
1731                    for (TasksProposal tasksProposal : findAll()) {
1732                            remove(tasksProposal);
1733                    }
1734            }
1735    
1736            /**
1737             * Counts all the tasks proposals where groupId = &#63;.
1738             *
1739             * @param groupId the group id to search with
1740             * @return the number of matching tasks proposals
1741             * @throws SystemException if a system exception occurred
1742             */
1743            public int countByGroupId(long groupId) throws SystemException {
1744                    Object[] finderArgs = new Object[] { groupId };
1745    
1746                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1747                                    finderArgs, this);
1748    
1749                    if (count == null) {
1750                            StringBundler query = new StringBundler(2);
1751    
1752                            query.append(_SQL_COUNT_TASKSPROPOSAL_WHERE);
1753    
1754                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1755    
1756                            String sql = query.toString();
1757    
1758                            Session session = null;
1759    
1760                            try {
1761                                    session = openSession();
1762    
1763                                    Query q = session.createQuery(sql);
1764    
1765                                    QueryPos qPos = QueryPos.getInstance(q);
1766    
1767                                    qPos.add(groupId);
1768    
1769                                    count = (Long)q.uniqueResult();
1770                            }
1771                            catch (Exception e) {
1772                                    throw processException(e);
1773                            }
1774                            finally {
1775                                    if (count == null) {
1776                                            count = Long.valueOf(0);
1777                                    }
1778    
1779                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1780                                            finderArgs, count);
1781    
1782                                    closeSession(session);
1783                            }
1784                    }
1785    
1786                    return count.intValue();
1787            }
1788    
1789            /**
1790             * Filters by the user's permissions and counts all the tasks proposals where groupId = &#63;.
1791             *
1792             * @param groupId the group id to search with
1793             * @return the number of matching tasks proposals that the user has permission to view
1794             * @throws SystemException if a system exception occurred
1795             */
1796            public int filterCountByGroupId(long groupId) throws SystemException {
1797                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1798                            return countByGroupId(groupId);
1799                    }
1800    
1801                    StringBundler query = new StringBundler(2);
1802    
1803                    query.append(_FILTER_SQL_COUNT_TASKSPROPOSAL_WHERE);
1804    
1805                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1806    
1807                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1808                                    TasksProposal.class.getName(), _FILTER_COLUMN_PK,
1809                                    _FILTER_COLUMN_USERID, groupId);
1810    
1811                    Session session = null;
1812    
1813                    try {
1814                            session = openSession();
1815    
1816                            SQLQuery q = session.createSQLQuery(sql);
1817    
1818                            q.addScalar(COUNT_COLUMN_NAME,
1819                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1820    
1821                            QueryPos qPos = QueryPos.getInstance(q);
1822    
1823                            qPos.add(groupId);
1824    
1825                            Long count = (Long)q.uniqueResult();
1826    
1827                            return count.intValue();
1828                    }
1829                    catch (Exception e) {
1830                            throw processException(e);
1831                    }
1832                    finally {
1833                            closeSession(session);
1834                    }
1835            }
1836    
1837            /**
1838             * Counts all the tasks proposals where groupId = &#63; and userId = &#63;.
1839             *
1840             * @param groupId the group id to search with
1841             * @param userId the user id to search with
1842             * @return the number of matching tasks proposals
1843             * @throws SystemException if a system exception occurred
1844             */
1845            public int countByG_U(long groupId, long userId) throws SystemException {
1846                    Object[] finderArgs = new Object[] { groupId, userId };
1847    
1848                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
1849                                    finderArgs, this);
1850    
1851                    if (count == null) {
1852                            StringBundler query = new StringBundler(3);
1853    
1854                            query.append(_SQL_COUNT_TASKSPROPOSAL_WHERE);
1855    
1856                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1857    
1858                            query.append(_FINDER_COLUMN_G_U_USERID_2);
1859    
1860                            String sql = query.toString();
1861    
1862                            Session session = null;
1863    
1864                            try {
1865                                    session = openSession();
1866    
1867                                    Query q = session.createQuery(sql);
1868    
1869                                    QueryPos qPos = QueryPos.getInstance(q);
1870    
1871                                    qPos.add(groupId);
1872    
1873                                    qPos.add(userId);
1874    
1875                                    count = (Long)q.uniqueResult();
1876                            }
1877                            catch (Exception e) {
1878                                    throw processException(e);
1879                            }
1880                            finally {
1881                                    if (count == null) {
1882                                            count = Long.valueOf(0);
1883                                    }
1884    
1885                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
1886                                            count);
1887    
1888                                    closeSession(session);
1889                            }
1890                    }
1891    
1892                    return count.intValue();
1893            }
1894    
1895            /**
1896             * Filters by the user's permissions and counts all the tasks proposals where groupId = &#63; and userId = &#63;.
1897             *
1898             * @param groupId the group id to search with
1899             * @param userId the user id to search with
1900             * @return the number of matching tasks proposals that the user has permission to view
1901             * @throws SystemException if a system exception occurred
1902             */
1903            public int filterCountByG_U(long groupId, long userId)
1904                    throws SystemException {
1905                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1906                            return countByG_U(groupId, userId);
1907                    }
1908    
1909                    StringBundler query = new StringBundler(3);
1910    
1911                    query.append(_FILTER_SQL_COUNT_TASKSPROPOSAL_WHERE);
1912    
1913                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1914    
1915                    query.append(_FINDER_COLUMN_G_U_USERID_2);
1916    
1917                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1918                                    TasksProposal.class.getName(), _FILTER_COLUMN_PK,
1919                                    _FILTER_COLUMN_USERID, groupId);
1920    
1921                    Session session = null;
1922    
1923                    try {
1924                            session = openSession();
1925    
1926                            SQLQuery q = session.createSQLQuery(sql);
1927    
1928                            q.addScalar(COUNT_COLUMN_NAME,
1929                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1930    
1931                            QueryPos qPos = QueryPos.getInstance(q);
1932    
1933                            qPos.add(groupId);
1934    
1935                            qPos.add(userId);
1936    
1937                            Long count = (Long)q.uniqueResult();
1938    
1939                            return count.intValue();
1940                    }
1941                    catch (Exception e) {
1942                            throw processException(e);
1943                    }
1944                    finally {
1945                            closeSession(session);
1946                    }
1947            }
1948    
1949            /**
1950             * Counts all the tasks proposals where classNameId = &#63; and classPK = &#63;.
1951             *
1952             * @param classNameId the class name id to search with
1953             * @param classPK the class p k to search with
1954             * @return the number of matching tasks proposals
1955             * @throws SystemException if a system exception occurred
1956             */
1957            public int countByC_C(long classNameId, String classPK)
1958                    throws SystemException {
1959                    Object[] finderArgs = new Object[] { classNameId, classPK };
1960    
1961                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1962                                    finderArgs, this);
1963    
1964                    if (count == null) {
1965                            StringBundler query = new StringBundler(3);
1966    
1967                            query.append(_SQL_COUNT_TASKSPROPOSAL_WHERE);
1968    
1969                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1970    
1971                            if (classPK == null) {
1972                                    query.append(_FINDER_COLUMN_C_C_CLASSPK_1);
1973                            }
1974                            else {
1975                                    if (classPK.equals(StringPool.BLANK)) {
1976                                            query.append(_FINDER_COLUMN_C_C_CLASSPK_3);
1977                                    }
1978                                    else {
1979                                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1980                                    }
1981                            }
1982    
1983                            String sql = query.toString();
1984    
1985                            Session session = null;
1986    
1987                            try {
1988                                    session = openSession();
1989    
1990                                    Query q = session.createQuery(sql);
1991    
1992                                    QueryPos qPos = QueryPos.getInstance(q);
1993    
1994                                    qPos.add(classNameId);
1995    
1996                                    if (classPK != null) {
1997                                            qPos.add(classPK);
1998                                    }
1999    
2000                                    count = (Long)q.uniqueResult();
2001                            }
2002                            catch (Exception e) {
2003                                    throw processException(e);
2004                            }
2005                            finally {
2006                                    if (count == null) {
2007                                            count = Long.valueOf(0);
2008                                    }
2009    
2010                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
2011                                            count);
2012    
2013                                    closeSession(session);
2014                            }
2015                    }
2016    
2017                    return count.intValue();
2018            }
2019    
2020            /**
2021             * Counts all the tasks proposals.
2022             *
2023             * @return the number of tasks proposals
2024             * @throws SystemException if a system exception occurred
2025             */
2026            public int countAll() throws SystemException {
2027                    Object[] finderArgs = new Object[0];
2028    
2029                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2030                                    finderArgs, this);
2031    
2032                    if (count == null) {
2033                            Session session = null;
2034    
2035                            try {
2036                                    session = openSession();
2037    
2038                                    Query q = session.createQuery(_SQL_COUNT_TASKSPROPOSAL);
2039    
2040                                    count = (Long)q.uniqueResult();
2041                            }
2042                            catch (Exception e) {
2043                                    throw processException(e);
2044                            }
2045                            finally {
2046                                    if (count == null) {
2047                                            count = Long.valueOf(0);
2048                                    }
2049    
2050                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2051                                            count);
2052    
2053                                    closeSession(session);
2054                            }
2055                    }
2056    
2057                    return count.intValue();
2058            }
2059    
2060            /**
2061             * Initializes the tasks proposal persistence.
2062             */
2063            public void afterPropertiesSet() {
2064                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2065                                            com.liferay.portal.util.PropsUtil.get(
2066                                                    "value.object.listener.com.liferay.portlet.tasks.model.TasksProposal")));
2067    
2068                    if (listenerClassNames.length > 0) {
2069                            try {
2070                                    List<ModelListener<TasksProposal>> listenersList = new ArrayList<ModelListener<TasksProposal>>();
2071    
2072                                    for (String listenerClassName : listenerClassNames) {
2073                                            listenersList.add((ModelListener<TasksProposal>)InstanceFactory.newInstance(
2074                                                            listenerClassName));
2075                                    }
2076    
2077                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2078                            }
2079                            catch (Exception e) {
2080                                    _log.error(e);
2081                            }
2082                    }
2083            }
2084    
2085            public void destroy() {
2086                    EntityCacheUtil.removeCache(TasksProposalImpl.class.getName());
2087                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2088                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
2089            }
2090    
2091            @BeanReference(type = TasksProposalPersistence.class)
2092            protected TasksProposalPersistence tasksProposalPersistence;
2093            @BeanReference(type = TasksReviewPersistence.class)
2094            protected TasksReviewPersistence tasksReviewPersistence;
2095            @BeanReference(type = ResourcePersistence.class)
2096            protected ResourcePersistence resourcePersistence;
2097            @BeanReference(type = UserPersistence.class)
2098            protected UserPersistence userPersistence;
2099            @BeanReference(type = MBMessagePersistence.class)
2100            protected MBMessagePersistence mbMessagePersistence;
2101            @BeanReference(type = SocialActivityPersistence.class)
2102            protected SocialActivityPersistence socialActivityPersistence;
2103            private static final String _SQL_SELECT_TASKSPROPOSAL = "SELECT tasksProposal FROM TasksProposal tasksProposal";
2104            private static final String _SQL_SELECT_TASKSPROPOSAL_WHERE = "SELECT tasksProposal FROM TasksProposal tasksProposal WHERE ";
2105            private static final String _SQL_COUNT_TASKSPROPOSAL = "SELECT COUNT(tasksProposal) FROM TasksProposal tasksProposal";
2106            private static final String _SQL_COUNT_TASKSPROPOSAL_WHERE = "SELECT COUNT(tasksProposal) FROM TasksProposal tasksProposal WHERE ";
2107            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "tasksProposal.groupId = ?";
2108            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "tasksProposal.groupId = ? AND ";
2109            private static final String _FINDER_COLUMN_G_U_USERID_2 = "tasksProposal.userId = ?";
2110            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "tasksProposal.classNameId = ? AND ";
2111            private static final String _FINDER_COLUMN_C_C_CLASSPK_1 = "tasksProposal.classPK IS NULL";
2112            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "tasksProposal.classPK = ?";
2113            private static final String _FINDER_COLUMN_C_C_CLASSPK_3 = "(tasksProposal.classPK IS NULL OR tasksProposal.classPK = ?)";
2114            private static final String _FILTER_SQL_SELECT_TASKSPROPOSAL_WHERE = "SELECT DISTINCT {tasksProposal.*} FROM TasksProposal tasksProposal WHERE ";
2115            private static final String _FILTER_SQL_SELECT_TASKSPROPOSAL_NO_INLINE_DISTINCT_WHERE_1 =
2116                    "SELECT {TasksProposal.*} FROM (SELECT DISTINCT tasksProposal.proposalId FROM TasksProposal tasksProposal WHERE ";
2117            private static final String _FILTER_SQL_SELECT_TASKSPROPOSAL_NO_INLINE_DISTINCT_WHERE_2 =
2118                    ") TEMP_TABLE INNER JOIN TasksProposal ON TEMP_TABLE.proposalId = TasksProposal.proposalId";
2119            private static final String _FILTER_SQL_COUNT_TASKSPROPOSAL_WHERE = "SELECT COUNT(DISTINCT tasksProposal.proposalId) AS COUNT_VALUE FROM TasksProposal tasksProposal WHERE ";
2120            private static final String _FILTER_COLUMN_PK = "tasksProposal.proposalId";
2121            private static final String _FILTER_COLUMN_USERID = "tasksProposal.userId";
2122            private static final String _FILTER_ENTITY_ALIAS = "tasksProposal";
2123            private static final String _FILTER_ENTITY_TABLE = "TasksProposal";
2124            private static final String _ORDER_BY_ENTITY_ALIAS = "tasksProposal.";
2125            private static final String _ORDER_BY_ENTITY_TABLE = "TasksProposal.";
2126            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No TasksProposal exists with the primary key ";
2127            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No TasksProposal exists with the key {";
2128            private static Log _log = LogFactoryUtil.getLog(TasksProposalPersistenceImpl.class);
2129    }