001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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.getOriginalClassNameId()),
280                                    
281                            tasksProposalModelImpl.getOriginalClassPK()
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                            Session session = null;
518    
519                            try {
520                                    session = openSession();
521    
522                                    StringBundler query = null;
523    
524                                    if (orderByComparator != null) {
525                                            query = new StringBundler(3 +
526                                                            (orderByComparator.getOrderByFields().length * 3));
527                                    }
528                                    else {
529                                            query = new StringBundler(3);
530                                    }
531    
532                                    query.append(_SQL_SELECT_TASKSPROPOSAL_WHERE);
533    
534                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
535    
536                                    if (orderByComparator != null) {
537                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
538                                                    orderByComparator);
539                                    }
540    
541                                    else {
542                                            query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
543                                    }
544    
545                                    String sql = query.toString();
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                                            list = new ArrayList<TasksProposal>();
562                                    }
563    
564                                    cacheResult(list);
565    
566                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
567                                            finderArgs, list);
568    
569                                    closeSession(session);
570                            }
571                    }
572    
573                    return list;
574            }
575    
576            /**
577             * Finds the first tasks proposal in the ordered set where groupId = &#63;.
578             *
579             * <p>
580             * 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.
581             * </p>
582             *
583             * @param groupId the group id to search with
584             * @param orderByComparator the comparator to order the set by
585             * @return the first matching tasks proposal
586             * @throws com.liferay.portlet.tasks.NoSuchProposalException if a matching tasks proposal could not be found
587             * @throws SystemException if a system exception occurred
588             */
589            public TasksProposal findByGroupId_First(long groupId,
590                    OrderByComparator orderByComparator)
591                    throws NoSuchProposalException, SystemException {
592                    List<TasksProposal> list = findByGroupId(groupId, 0, 1,
593                                    orderByComparator);
594    
595                    if (list.isEmpty()) {
596                            StringBundler msg = new StringBundler(4);
597    
598                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
599    
600                            msg.append("groupId=");
601                            msg.append(groupId);
602    
603                            msg.append(StringPool.CLOSE_CURLY_BRACE);
604    
605                            throw new NoSuchProposalException(msg.toString());
606                    }
607                    else {
608                            return list.get(0);
609                    }
610            }
611    
612            /**
613             * Finds the last tasks proposal in the ordered set where groupId = &#63;.
614             *
615             * <p>
616             * 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.
617             * </p>
618             *
619             * @param groupId the group id to search with
620             * @param orderByComparator the comparator to order the set by
621             * @return the last matching tasks proposal
622             * @throws com.liferay.portlet.tasks.NoSuchProposalException if a matching tasks proposal could not be found
623             * @throws SystemException if a system exception occurred
624             */
625            public TasksProposal findByGroupId_Last(long groupId,
626                    OrderByComparator orderByComparator)
627                    throws NoSuchProposalException, SystemException {
628                    int count = countByGroupId(groupId);
629    
630                    List<TasksProposal> list = findByGroupId(groupId, count - 1, count,
631                                    orderByComparator);
632    
633                    if (list.isEmpty()) {
634                            StringBundler msg = new StringBundler(4);
635    
636                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
637    
638                            msg.append("groupId=");
639                            msg.append(groupId);
640    
641                            msg.append(StringPool.CLOSE_CURLY_BRACE);
642    
643                            throw new NoSuchProposalException(msg.toString());
644                    }
645                    else {
646                            return list.get(0);
647                    }
648            }
649    
650            /**
651             * Finds the tasks proposals before and after the current tasks proposal in the ordered set where groupId = &#63;.
652             *
653             * <p>
654             * 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.
655             * </p>
656             *
657             * @param proposalId the primary key of the current tasks proposal
658             * @param groupId the group id to search with
659             * @param orderByComparator the comparator to order the set by
660             * @return the previous, current, and next tasks proposal
661             * @throws com.liferay.portlet.tasks.NoSuchProposalException if a tasks proposal with the primary key could not be found
662             * @throws SystemException if a system exception occurred
663             */
664            public TasksProposal[] findByGroupId_PrevAndNext(long proposalId,
665                    long groupId, OrderByComparator orderByComparator)
666                    throws NoSuchProposalException, SystemException {
667                    TasksProposal tasksProposal = findByPrimaryKey(proposalId);
668    
669                    Session session = null;
670    
671                    try {
672                            session = openSession();
673    
674                            TasksProposal[] array = new TasksProposalImpl[3];
675    
676                            array[0] = getByGroupId_PrevAndNext(session, tasksProposal,
677                                            groupId, orderByComparator, true);
678    
679                            array[1] = tasksProposal;
680    
681                            array[2] = getByGroupId_PrevAndNext(session, tasksProposal,
682                                            groupId, orderByComparator, false);
683    
684                            return array;
685                    }
686                    catch (Exception e) {
687                            throw processException(e);
688                    }
689                    finally {
690                            closeSession(session);
691                    }
692            }
693    
694            protected TasksProposal getByGroupId_PrevAndNext(Session session,
695                    TasksProposal tasksProposal, long groupId,
696                    OrderByComparator orderByComparator, boolean previous) {
697                    StringBundler query = null;
698    
699                    if (orderByComparator != null) {
700                            query = new StringBundler(6 +
701                                            (orderByComparator.getOrderByFields().length * 6));
702                    }
703                    else {
704                            query = new StringBundler(3);
705                    }
706    
707                    query.append(_SQL_SELECT_TASKSPROPOSAL_WHERE);
708    
709                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
710    
711                    if (orderByComparator != null) {
712                            String[] orderByFields = orderByComparator.getOrderByFields();
713    
714                            if (orderByFields.length > 0) {
715                                    query.append(WHERE_AND);
716                            }
717    
718                            for (int i = 0; i < orderByFields.length; i++) {
719                                    query.append(_ORDER_BY_ENTITY_ALIAS);
720                                    query.append(orderByFields[i]);
721    
722                                    if ((i + 1) < orderByFields.length) {
723                                            if (orderByComparator.isAscending() ^ previous) {
724                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
725                                            }
726                                            else {
727                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
728                                            }
729                                    }
730                                    else {
731                                            if (orderByComparator.isAscending() ^ previous) {
732                                                    query.append(WHERE_GREATER_THAN);
733                                            }
734                                            else {
735                                                    query.append(WHERE_LESSER_THAN);
736                                            }
737                                    }
738                            }
739    
740                            query.append(ORDER_BY_CLAUSE);
741    
742                            for (int i = 0; i < orderByFields.length; i++) {
743                                    query.append(_ORDER_BY_ENTITY_ALIAS);
744                                    query.append(orderByFields[i]);
745    
746                                    if ((i + 1) < orderByFields.length) {
747                                            if (orderByComparator.isAscending() ^ previous) {
748                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
749                                            }
750                                            else {
751                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
752                                            }
753                                    }
754                                    else {
755                                            if (orderByComparator.isAscending() ^ previous) {
756                                                    query.append(ORDER_BY_ASC);
757                                            }
758                                            else {
759                                                    query.append(ORDER_BY_DESC);
760                                            }
761                                    }
762                            }
763                    }
764    
765                    else {
766                            query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
767                    }
768    
769                    String sql = query.toString();
770    
771                    Query q = session.createQuery(sql);
772    
773                    q.setFirstResult(0);
774                    q.setMaxResults(2);
775    
776                    QueryPos qPos = QueryPos.getInstance(q);
777    
778                    qPos.add(groupId);
779    
780                    if (orderByComparator != null) {
781                            Object[] values = orderByComparator.getOrderByValues(tasksProposal);
782    
783                            for (Object value : values) {
784                                    qPos.add(value);
785                            }
786                    }
787    
788                    List<TasksProposal> list = q.list();
789    
790                    if (list.size() == 2) {
791                            return list.get(1);
792                    }
793                    else {
794                            return null;
795                    }
796            }
797    
798            /**
799             * Filters by the user's permissions and finds all the tasks proposals where groupId = &#63;.
800             *
801             * @param groupId the group id to search with
802             * @return the matching tasks proposals that the user has permission to view
803             * @throws SystemException if a system exception occurred
804             */
805            public List<TasksProposal> filterFindByGroupId(long groupId)
806                    throws SystemException {
807                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
808                            QueryUtil.ALL_POS, null);
809            }
810    
811            /**
812             * Filters by the user's permissions and finds a range of all the tasks proposals where groupId = &#63;.
813             *
814             * <p>
815             * 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.
816             * </p>
817             *
818             * @param groupId the group id to search with
819             * @param start the lower bound of the range of tasks proposals to return
820             * @param end the upper bound of the range of tasks proposals to return (not inclusive)
821             * @return the range of matching tasks proposals that the user has permission to view
822             * @throws SystemException if a system exception occurred
823             */
824            public List<TasksProposal> filterFindByGroupId(long groupId, int start,
825                    int end) throws SystemException {
826                    return filterFindByGroupId(groupId, start, end, null);
827            }
828    
829            /**
830             * Filters by the user's permissions and finds an ordered range of all the tasks proposals where groupId = &#63;.
831             *
832             * <p>
833             * 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.
834             * </p>
835             *
836             * @param groupId the group id to search with
837             * @param start the lower bound of the range of tasks proposals to return
838             * @param end the upper bound of the range of tasks proposals to return (not inclusive)
839             * @param orderByComparator the comparator to order the results by
840             * @return the ordered range of matching tasks proposals that the user has permission to view
841             * @throws SystemException if a system exception occurred
842             */
843            public List<TasksProposal> filterFindByGroupId(long groupId, int start,
844                    int end, OrderByComparator orderByComparator) throws SystemException {
845                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
846                            return findByGroupId(groupId, start, end, orderByComparator);
847                    }
848    
849                    Session session = null;
850    
851                    try {
852                            session = openSession();
853    
854                            StringBundler query = null;
855    
856                            if (orderByComparator != null) {
857                                    query = new StringBundler(3 +
858                                                    (orderByComparator.getOrderByFields().length * 3));
859                            }
860                            else {
861                                    query = new StringBundler(3);
862                            }
863    
864                            if (getDB().isSupportsInlineDistinct()) {
865                                    query.append(_FILTER_SQL_SELECT_TASKSPROPOSAL_WHERE);
866                            }
867                            else {
868                                    query.append(_FILTER_SQL_SELECT_TASKSPROPOSAL_NO_INLINE_DISTINCT_WHERE);
869                            }
870    
871                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
872    
873                            if (orderByComparator != null) {
874                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
875                                            orderByComparator);
876                            }
877    
878                            else {
879                                    query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
880                            }
881    
882                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
883                                            TasksProposal.class.getName(), _FILTER_COLUMN_PK,
884                                            _FILTER_COLUMN_USERID, groupId);
885    
886                            SQLQuery q = session.createSQLQuery(sql);
887    
888                            q.addEntity(_FILTER_ENTITY_ALIAS, TasksProposalImpl.class);
889    
890                            QueryPos qPos = QueryPos.getInstance(q);
891    
892                            qPos.add(groupId);
893    
894                            return (List<TasksProposal>)QueryUtil.list(q, getDialect(), start,
895                                    end);
896                    }
897                    catch (Exception e) {
898                            throw processException(e);
899                    }
900                    finally {
901                            closeSession(session);
902                    }
903            }
904    
905            /**
906             * Finds all the tasks proposals where groupId = &#63; and userId = &#63;.
907             *
908             * @param groupId the group id to search with
909             * @param userId the user id to search with
910             * @return the matching tasks proposals
911             * @throws SystemException if a system exception occurred
912             */
913            public List<TasksProposal> findByG_U(long groupId, long userId)
914                    throws SystemException {
915                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
916                            null);
917            }
918    
919            /**
920             * Finds a range of all the tasks proposals where groupId = &#63; and userId = &#63;.
921             *
922             * <p>
923             * 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.
924             * </p>
925             *
926             * @param groupId the group id to search with
927             * @param userId the user id to search with
928             * @param start the lower bound of the range of tasks proposals to return
929             * @param end the upper bound of the range of tasks proposals to return (not inclusive)
930             * @return the range of matching tasks proposals
931             * @throws SystemException if a system exception occurred
932             */
933            public List<TasksProposal> findByG_U(long groupId, long userId, int start,
934                    int end) throws SystemException {
935                    return findByG_U(groupId, userId, start, end, null);
936            }
937    
938            /**
939             * Finds an ordered range of all the tasks proposals where groupId = &#63; and userId = &#63;.
940             *
941             * <p>
942             * 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.
943             * </p>
944             *
945             * @param groupId the group id to search with
946             * @param userId the user id to search with
947             * @param start the lower bound of the range of tasks proposals to return
948             * @param end the upper bound of the range of tasks proposals to return (not inclusive)
949             * @param orderByComparator the comparator to order the results by
950             * @return the ordered range of matching tasks proposals
951             * @throws SystemException if a system exception occurred
952             */
953            public List<TasksProposal> findByG_U(long groupId, long userId, int start,
954                    int end, OrderByComparator orderByComparator) throws SystemException {
955                    Object[] finderArgs = new Object[] {
956                                    groupId, userId,
957                                    
958                                    String.valueOf(start), String.valueOf(end),
959                                    String.valueOf(orderByComparator)
960                            };
961    
962                    List<TasksProposal> list = (List<TasksProposal>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_U,
963                                    finderArgs, this);
964    
965                    if (list == null) {
966                            Session session = null;
967    
968                            try {
969                                    session = openSession();
970    
971                                    StringBundler query = null;
972    
973                                    if (orderByComparator != null) {
974                                            query = new StringBundler(4 +
975                                                            (orderByComparator.getOrderByFields().length * 3));
976                                    }
977                                    else {
978                                            query = new StringBundler(4);
979                                    }
980    
981                                    query.append(_SQL_SELECT_TASKSPROPOSAL_WHERE);
982    
983                                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
984    
985                                    query.append(_FINDER_COLUMN_G_U_USERID_2);
986    
987                                    if (orderByComparator != null) {
988                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
989                                                    orderByComparator);
990                                    }
991    
992                                    else {
993                                            query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
994                                    }
995    
996                                    String sql = query.toString();
997    
998                                    Query q = session.createQuery(sql);
999    
1000                                    QueryPos qPos = QueryPos.getInstance(q);
1001    
1002                                    qPos.add(groupId);
1003    
1004                                    qPos.add(userId);
1005    
1006                                    list = (List<TasksProposal>)QueryUtil.list(q, getDialect(),
1007                                                    start, end);
1008                            }
1009                            catch (Exception e) {
1010                                    throw processException(e);
1011                            }
1012                            finally {
1013                                    if (list == null) {
1014                                            list = new ArrayList<TasksProposal>();
1015                                    }
1016    
1017                                    cacheResult(list);
1018    
1019                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_U, finderArgs,
1020                                            list);
1021    
1022                                    closeSession(session);
1023                            }
1024                    }
1025    
1026                    return list;
1027            }
1028    
1029            /**
1030             * Finds the first tasks proposal in the ordered set where groupId = &#63; and userId = &#63;.
1031             *
1032             * <p>
1033             * 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.
1034             * </p>
1035             *
1036             * @param groupId the group id to search with
1037             * @param userId the user id to search with
1038             * @param orderByComparator the comparator to order the set by
1039             * @return the first matching tasks proposal
1040             * @throws com.liferay.portlet.tasks.NoSuchProposalException if a matching tasks proposal could not be found
1041             * @throws SystemException if a system exception occurred
1042             */
1043            public TasksProposal findByG_U_First(long groupId, long userId,
1044                    OrderByComparator orderByComparator)
1045                    throws NoSuchProposalException, SystemException {
1046                    List<TasksProposal> list = findByG_U(groupId, userId, 0, 1,
1047                                    orderByComparator);
1048    
1049                    if (list.isEmpty()) {
1050                            StringBundler msg = new StringBundler(6);
1051    
1052                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1053    
1054                            msg.append("groupId=");
1055                            msg.append(groupId);
1056    
1057                            msg.append(", userId=");
1058                            msg.append(userId);
1059    
1060                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1061    
1062                            throw new NoSuchProposalException(msg.toString());
1063                    }
1064                    else {
1065                            return list.get(0);
1066                    }
1067            }
1068    
1069            /**
1070             * Finds the last tasks proposal in the ordered set where groupId = &#63; and userId = &#63;.
1071             *
1072             * <p>
1073             * 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.
1074             * </p>
1075             *
1076             * @param groupId the group id to search with
1077             * @param userId the user id to search with
1078             * @param orderByComparator the comparator to order the set by
1079             * @return the last matching tasks proposal
1080             * @throws com.liferay.portlet.tasks.NoSuchProposalException if a matching tasks proposal could not be found
1081             * @throws SystemException if a system exception occurred
1082             */
1083            public TasksProposal findByG_U_Last(long groupId, long userId,
1084                    OrderByComparator orderByComparator)
1085                    throws NoSuchProposalException, SystemException {
1086                    int count = countByG_U(groupId, userId);
1087    
1088                    List<TasksProposal> list = findByG_U(groupId, userId, count - 1, count,
1089                                    orderByComparator);
1090    
1091                    if (list.isEmpty()) {
1092                            StringBundler msg = new StringBundler(6);
1093    
1094                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1095    
1096                            msg.append("groupId=");
1097                            msg.append(groupId);
1098    
1099                            msg.append(", userId=");
1100                            msg.append(userId);
1101    
1102                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1103    
1104                            throw new NoSuchProposalException(msg.toString());
1105                    }
1106                    else {
1107                            return list.get(0);
1108                    }
1109            }
1110    
1111            /**
1112             * Finds the tasks proposals before and after the current tasks proposal in the ordered set where groupId = &#63; and userId = &#63;.
1113             *
1114             * <p>
1115             * 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.
1116             * </p>
1117             *
1118             * @param proposalId the primary key of the current tasks proposal
1119             * @param groupId the group id to search with
1120             * @param userId the user id to search with
1121             * @param orderByComparator the comparator to order the set by
1122             * @return the previous, current, and next tasks proposal
1123             * @throws com.liferay.portlet.tasks.NoSuchProposalException if a tasks proposal with the primary key could not be found
1124             * @throws SystemException if a system exception occurred
1125             */
1126            public TasksProposal[] findByG_U_PrevAndNext(long proposalId, long groupId,
1127                    long userId, OrderByComparator orderByComparator)
1128                    throws NoSuchProposalException, SystemException {
1129                    TasksProposal tasksProposal = findByPrimaryKey(proposalId);
1130    
1131                    Session session = null;
1132    
1133                    try {
1134                            session = openSession();
1135    
1136                            TasksProposal[] array = new TasksProposalImpl[3];
1137    
1138                            array[0] = getByG_U_PrevAndNext(session, tasksProposal, groupId,
1139                                            userId, orderByComparator, true);
1140    
1141                            array[1] = tasksProposal;
1142    
1143                            array[2] = getByG_U_PrevAndNext(session, tasksProposal, groupId,
1144                                            userId, orderByComparator, false);
1145    
1146                            return array;
1147                    }
1148                    catch (Exception e) {
1149                            throw processException(e);
1150                    }
1151                    finally {
1152                            closeSession(session);
1153                    }
1154            }
1155    
1156            protected TasksProposal getByG_U_PrevAndNext(Session session,
1157                    TasksProposal tasksProposal, long groupId, long userId,
1158                    OrderByComparator orderByComparator, boolean previous) {
1159                    StringBundler query = null;
1160    
1161                    if (orderByComparator != null) {
1162                            query = new StringBundler(6 +
1163                                            (orderByComparator.getOrderByFields().length * 6));
1164                    }
1165                    else {
1166                            query = new StringBundler(3);
1167                    }
1168    
1169                    query.append(_SQL_SELECT_TASKSPROPOSAL_WHERE);
1170    
1171                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1172    
1173                    query.append(_FINDER_COLUMN_G_U_USERID_2);
1174    
1175                    if (orderByComparator != null) {
1176                            String[] orderByFields = orderByComparator.getOrderByFields();
1177    
1178                            if (orderByFields.length > 0) {
1179                                    query.append(WHERE_AND);
1180                            }
1181    
1182                            for (int i = 0; i < orderByFields.length; i++) {
1183                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1184                                    query.append(orderByFields[i]);
1185    
1186                                    if ((i + 1) < orderByFields.length) {
1187                                            if (orderByComparator.isAscending() ^ previous) {
1188                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1189                                            }
1190                                            else {
1191                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1192                                            }
1193                                    }
1194                                    else {
1195                                            if (orderByComparator.isAscending() ^ previous) {
1196                                                    query.append(WHERE_GREATER_THAN);
1197                                            }
1198                                            else {
1199                                                    query.append(WHERE_LESSER_THAN);
1200                                            }
1201                                    }
1202                            }
1203    
1204                            query.append(ORDER_BY_CLAUSE);
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(ORDER_BY_ASC_HAS_NEXT);
1213                                            }
1214                                            else {
1215                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1216                                            }
1217                                    }
1218                                    else {
1219                                            if (orderByComparator.isAscending() ^ previous) {
1220                                                    query.append(ORDER_BY_ASC);
1221                                            }
1222                                            else {
1223                                                    query.append(ORDER_BY_DESC);
1224                                            }
1225                                    }
1226                            }
1227                    }
1228    
1229                    else {
1230                            query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
1231                    }
1232    
1233                    String sql = query.toString();
1234    
1235                    Query q = session.createQuery(sql);
1236    
1237                    q.setFirstResult(0);
1238                    q.setMaxResults(2);
1239    
1240                    QueryPos qPos = QueryPos.getInstance(q);
1241    
1242                    qPos.add(groupId);
1243    
1244                    qPos.add(userId);
1245    
1246                    if (orderByComparator != null) {
1247                            Object[] values = orderByComparator.getOrderByValues(tasksProposal);
1248    
1249                            for (Object value : values) {
1250                                    qPos.add(value);
1251                            }
1252                    }
1253    
1254                    List<TasksProposal> list = q.list();
1255    
1256                    if (list.size() == 2) {
1257                            return list.get(1);
1258                    }
1259                    else {
1260                            return null;
1261                    }
1262            }
1263    
1264            /**
1265             * Filters by the user's permissions and finds all the tasks proposals where groupId = &#63; and userId = &#63;.
1266             *
1267             * @param groupId the group id to search with
1268             * @param userId the user id to search with
1269             * @return the matching tasks proposals that the user has permission to view
1270             * @throws SystemException if a system exception occurred
1271             */
1272            public List<TasksProposal> filterFindByG_U(long groupId, long userId)
1273                    throws SystemException {
1274                    return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
1275                            QueryUtil.ALL_POS, null);
1276            }
1277    
1278            /**
1279             * Filters by the user's permissions and finds a range of all the tasks proposals where groupId = &#63; and userId = &#63;.
1280             *
1281             * <p>
1282             * 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.
1283             * </p>
1284             *
1285             * @param groupId the group id to search with
1286             * @param userId the user id to search with
1287             * @param start the lower bound of the range of tasks proposals to return
1288             * @param end the upper bound of the range of tasks proposals to return (not inclusive)
1289             * @return the range of matching tasks proposals that the user has permission to view
1290             * @throws SystemException if a system exception occurred
1291             */
1292            public List<TasksProposal> filterFindByG_U(long groupId, long userId,
1293                    int start, int end) throws SystemException {
1294                    return filterFindByG_U(groupId, userId, start, end, null);
1295            }
1296    
1297            /**
1298             * Filters by the user's permissions and finds an ordered range of all the tasks proposals where groupId = &#63; and userId = &#63;.
1299             *
1300             * <p>
1301             * 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.
1302             * </p>
1303             *
1304             * @param groupId the group id to search with
1305             * @param userId the user id to search with
1306             * @param start the lower bound of the range of tasks proposals to return
1307             * @param end the upper bound of the range of tasks proposals to return (not inclusive)
1308             * @param orderByComparator the comparator to order the results by
1309             * @return the ordered range of matching tasks proposals that the user has permission to view
1310             * @throws SystemException if a system exception occurred
1311             */
1312            public List<TasksProposal> filterFindByG_U(long groupId, long userId,
1313                    int start, int end, OrderByComparator orderByComparator)
1314                    throws SystemException {
1315                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1316                            return findByG_U(groupId, userId, start, end, orderByComparator);
1317                    }
1318    
1319                    Session session = null;
1320    
1321                    try {
1322                            session = openSession();
1323    
1324                            StringBundler query = null;
1325    
1326                            if (orderByComparator != null) {
1327                                    query = new StringBundler(4 +
1328                                                    (orderByComparator.getOrderByFields().length * 3));
1329                            }
1330                            else {
1331                                    query = new StringBundler(4);
1332                            }
1333    
1334                            if (getDB().isSupportsInlineDistinct()) {
1335                                    query.append(_FILTER_SQL_SELECT_TASKSPROPOSAL_WHERE);
1336                            }
1337                            else {
1338                                    query.append(_FILTER_SQL_SELECT_TASKSPROPOSAL_NO_INLINE_DISTINCT_WHERE);
1339                            }
1340    
1341                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1342    
1343                            query.append(_FINDER_COLUMN_G_U_USERID_2);
1344    
1345                            if (orderByComparator != null) {
1346                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1347                                            orderByComparator);
1348                            }
1349    
1350                            else {
1351                                    query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
1352                            }
1353    
1354                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1355                                            TasksProposal.class.getName(), _FILTER_COLUMN_PK,
1356                                            _FILTER_COLUMN_USERID, groupId);
1357    
1358                            SQLQuery q = session.createSQLQuery(sql);
1359    
1360                            q.addEntity(_FILTER_ENTITY_ALIAS, TasksProposalImpl.class);
1361    
1362                            QueryPos qPos = QueryPos.getInstance(q);
1363    
1364                            qPos.add(groupId);
1365    
1366                            qPos.add(userId);
1367    
1368                            return (List<TasksProposal>)QueryUtil.list(q, getDialect(), start,
1369                                    end);
1370                    }
1371                    catch (Exception e) {
1372                            throw processException(e);
1373                    }
1374                    finally {
1375                            closeSession(session);
1376                    }
1377            }
1378    
1379            /**
1380             * 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.
1381             *
1382             * @param classNameId the class name id to search with
1383             * @param classPK the class p k to search with
1384             * @return the matching tasks proposal
1385             * @throws com.liferay.portlet.tasks.NoSuchProposalException if a matching tasks proposal could not be found
1386             * @throws SystemException if a system exception occurred
1387             */
1388            public TasksProposal findByC_C(long classNameId, String classPK)
1389                    throws NoSuchProposalException, SystemException {
1390                    TasksProposal tasksProposal = fetchByC_C(classNameId, classPK);
1391    
1392                    if (tasksProposal == null) {
1393                            StringBundler msg = new StringBundler(6);
1394    
1395                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1396    
1397                            msg.append("classNameId=");
1398                            msg.append(classNameId);
1399    
1400                            msg.append(", classPK=");
1401                            msg.append(classPK);
1402    
1403                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1404    
1405                            if (_log.isWarnEnabled()) {
1406                                    _log.warn(msg.toString());
1407                            }
1408    
1409                            throw new NoSuchProposalException(msg.toString());
1410                    }
1411    
1412                    return tasksProposal;
1413            }
1414    
1415            /**
1416             * 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.
1417             *
1418             * @param classNameId the class name id to search with
1419             * @param classPK the class p k to search with
1420             * @return the matching tasks proposal, or <code>null</code> if a matching tasks proposal could not be found
1421             * @throws SystemException if a system exception occurred
1422             */
1423            public TasksProposal fetchByC_C(long classNameId, String classPK)
1424                    throws SystemException {
1425                    return fetchByC_C(classNameId, classPK, true);
1426            }
1427    
1428            /**
1429             * 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.
1430             *
1431             * @param classNameId the class name id to search with
1432             * @param classPK the class p k to search with
1433             * @return the matching tasks proposal, or <code>null</code> if a matching tasks proposal could not be found
1434             * @throws SystemException if a system exception occurred
1435             */
1436            public TasksProposal fetchByC_C(long classNameId, String classPK,
1437                    boolean retrieveFromCache) throws SystemException {
1438                    Object[] finderArgs = new Object[] { classNameId, classPK };
1439    
1440                    Object result = null;
1441    
1442                    if (retrieveFromCache) {
1443                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
1444                                            finderArgs, this);
1445                    }
1446    
1447                    if (result == null) {
1448                            Session session = null;
1449    
1450                            try {
1451                                    session = openSession();
1452    
1453                                    StringBundler query = new StringBundler(4);
1454    
1455                                    query.append(_SQL_SELECT_TASKSPROPOSAL_WHERE);
1456    
1457                                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1458    
1459                                    if (classPK == null) {
1460                                            query.append(_FINDER_COLUMN_C_C_CLASSPK_1);
1461                                    }
1462                                    else {
1463                                            if (classPK.equals(StringPool.BLANK)) {
1464                                                    query.append(_FINDER_COLUMN_C_C_CLASSPK_3);
1465                                            }
1466                                            else {
1467                                                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1468                                            }
1469                                    }
1470    
1471                                    query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
1472    
1473                                    String sql = query.toString();
1474    
1475                                    Query q = session.createQuery(sql);
1476    
1477                                    QueryPos qPos = QueryPos.getInstance(q);
1478    
1479                                    qPos.add(classNameId);
1480    
1481                                    if (classPK != null) {
1482                                            qPos.add(classPK);
1483                                    }
1484    
1485                                    List<TasksProposal> list = q.list();
1486    
1487                                    result = list;
1488    
1489                                    TasksProposal tasksProposal = null;
1490    
1491                                    if (list.isEmpty()) {
1492                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
1493                                                    finderArgs, list);
1494                                    }
1495                                    else {
1496                                            tasksProposal = list.get(0);
1497    
1498                                            cacheResult(tasksProposal);
1499    
1500                                            if ((tasksProposal.getClassNameId() != classNameId) ||
1501                                                            (tasksProposal.getClassPK() == null) ||
1502                                                            !tasksProposal.getClassPK().equals(classPK)) {
1503                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
1504                                                            finderArgs, tasksProposal);
1505                                            }
1506                                    }
1507    
1508                                    return tasksProposal;
1509                            }
1510                            catch (Exception e) {
1511                                    throw processException(e);
1512                            }
1513                            finally {
1514                                    if (result == null) {
1515                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
1516                                                    finderArgs, new ArrayList<TasksProposal>());
1517                                    }
1518    
1519                                    closeSession(session);
1520                            }
1521                    }
1522                    else {
1523                            if (result instanceof List<?>) {
1524                                    return null;
1525                            }
1526                            else {
1527                                    return (TasksProposal)result;
1528                            }
1529                    }
1530            }
1531    
1532            /**
1533             * Finds all the tasks proposals.
1534             *
1535             * @return the tasks proposals
1536             * @throws SystemException if a system exception occurred
1537             */
1538            public List<TasksProposal> findAll() throws SystemException {
1539                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1540            }
1541    
1542            /**
1543             * Finds a range of all the tasks proposals.
1544             *
1545             * <p>
1546             * 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.
1547             * </p>
1548             *
1549             * @param start the lower bound of the range of tasks proposals to return
1550             * @param end the upper bound of the range of tasks proposals to return (not inclusive)
1551             * @return the range of tasks proposals
1552             * @throws SystemException if a system exception occurred
1553             */
1554            public List<TasksProposal> findAll(int start, int end)
1555                    throws SystemException {
1556                    return findAll(start, end, null);
1557            }
1558    
1559            /**
1560             * Finds an ordered range of all the tasks proposals.
1561             *
1562             * <p>
1563             * 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.
1564             * </p>
1565             *
1566             * @param start the lower bound of the range of tasks proposals to return
1567             * @param end the upper bound of the range of tasks proposals to return (not inclusive)
1568             * @param orderByComparator the comparator to order the results by
1569             * @return the ordered range of tasks proposals
1570             * @throws SystemException if a system exception occurred
1571             */
1572            public List<TasksProposal> findAll(int start, int end,
1573                    OrderByComparator orderByComparator) throws SystemException {
1574                    Object[] finderArgs = new Object[] {
1575                                    String.valueOf(start), String.valueOf(end),
1576                                    String.valueOf(orderByComparator)
1577                            };
1578    
1579                    List<TasksProposal> list = (List<TasksProposal>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1580                                    finderArgs, this);
1581    
1582                    if (list == null) {
1583                            Session session = null;
1584    
1585                            try {
1586                                    session = openSession();
1587    
1588                                    StringBundler query = null;
1589                                    String sql = null;
1590    
1591                                    if (orderByComparator != null) {
1592                                            query = new StringBundler(2 +
1593                                                            (orderByComparator.getOrderByFields().length * 3));
1594    
1595                                            query.append(_SQL_SELECT_TASKSPROPOSAL);
1596    
1597                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1598                                                    orderByComparator);
1599    
1600                                            sql = query.toString();
1601                                    }
1602                                    else {
1603                                            sql = _SQL_SELECT_TASKSPROPOSAL.concat(TasksProposalModelImpl.ORDER_BY_JPQL);
1604                                    }
1605    
1606                                    Query q = session.createQuery(sql);
1607    
1608                                    if (orderByComparator == null) {
1609                                            list = (List<TasksProposal>)QueryUtil.list(q, getDialect(),
1610                                                            start, end, false);
1611    
1612                                            Collections.sort(list);
1613                                    }
1614                                    else {
1615                                            list = (List<TasksProposal>)QueryUtil.list(q, getDialect(),
1616                                                            start, end);
1617                                    }
1618                            }
1619                            catch (Exception e) {
1620                                    throw processException(e);
1621                            }
1622                            finally {
1623                                    if (list == null) {
1624                                            list = new ArrayList<TasksProposal>();
1625                                    }
1626    
1627                                    cacheResult(list);
1628    
1629                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1630    
1631                                    closeSession(session);
1632                            }
1633                    }
1634    
1635                    return list;
1636            }
1637    
1638            /**
1639             * Removes all the tasks proposals where groupId = &#63; from the database.
1640             *
1641             * @param groupId the group id to search with
1642             * @throws SystemException if a system exception occurred
1643             */
1644            public void removeByGroupId(long groupId) throws SystemException {
1645                    for (TasksProposal tasksProposal : findByGroupId(groupId)) {
1646                            remove(tasksProposal);
1647                    }
1648            }
1649    
1650            /**
1651             * Removes all the tasks proposals where groupId = &#63; and userId = &#63; from the database.
1652             *
1653             * @param groupId the group id to search with
1654             * @param userId the user id to search with
1655             * @throws SystemException if a system exception occurred
1656             */
1657            public void removeByG_U(long groupId, long userId)
1658                    throws SystemException {
1659                    for (TasksProposal tasksProposal : findByG_U(groupId, userId)) {
1660                            remove(tasksProposal);
1661                    }
1662            }
1663    
1664            /**
1665             * Removes the tasks proposal where classNameId = &#63; and classPK = &#63; from the database.
1666             *
1667             * @param classNameId the class name id to search with
1668             * @param classPK the class p k to search with
1669             * @throws SystemException if a system exception occurred
1670             */
1671            public void removeByC_C(long classNameId, String classPK)
1672                    throws NoSuchProposalException, SystemException {
1673                    TasksProposal tasksProposal = findByC_C(classNameId, classPK);
1674    
1675                    remove(tasksProposal);
1676            }
1677    
1678            /**
1679             * Removes all the tasks proposals from the database.
1680             *
1681             * @throws SystemException if a system exception occurred
1682             */
1683            public void removeAll() throws SystemException {
1684                    for (TasksProposal tasksProposal : findAll()) {
1685                            remove(tasksProposal);
1686                    }
1687            }
1688    
1689            /**
1690             * Counts all the tasks proposals where groupId = &#63;.
1691             *
1692             * @param groupId the group id to search with
1693             * @return the number of matching tasks proposals
1694             * @throws SystemException if a system exception occurred
1695             */
1696            public int countByGroupId(long groupId) throws SystemException {
1697                    Object[] finderArgs = new Object[] { groupId };
1698    
1699                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1700                                    finderArgs, this);
1701    
1702                    if (count == null) {
1703                            Session session = null;
1704    
1705                            try {
1706                                    session = openSession();
1707    
1708                                    StringBundler query = new StringBundler(2);
1709    
1710                                    query.append(_SQL_COUNT_TASKSPROPOSAL_WHERE);
1711    
1712                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1713    
1714                                    String sql = query.toString();
1715    
1716                                    Query q = session.createQuery(sql);
1717    
1718                                    QueryPos qPos = QueryPos.getInstance(q);
1719    
1720                                    qPos.add(groupId);
1721    
1722                                    count = (Long)q.uniqueResult();
1723                            }
1724                            catch (Exception e) {
1725                                    throw processException(e);
1726                            }
1727                            finally {
1728                                    if (count == null) {
1729                                            count = Long.valueOf(0);
1730                                    }
1731    
1732                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1733                                            finderArgs, count);
1734    
1735                                    closeSession(session);
1736                            }
1737                    }
1738    
1739                    return count.intValue();
1740            }
1741    
1742            /**
1743             * Filters by the user's permissions and counts all the tasks proposals where groupId = &#63;.
1744             *
1745             * @param groupId the group id to search with
1746             * @return the number of matching tasks proposals that the user has permission to view
1747             * @throws SystemException if a system exception occurred
1748             */
1749            public int filterCountByGroupId(long groupId) throws SystemException {
1750                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1751                            return countByGroupId(groupId);
1752                    }
1753    
1754                    Session session = null;
1755    
1756                    try {
1757                            session = openSession();
1758    
1759                            StringBundler query = new StringBundler(2);
1760    
1761                            query.append(_FILTER_SQL_COUNT_TASKSPROPOSAL_WHERE);
1762    
1763                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1764    
1765                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1766                                            TasksProposal.class.getName(), _FILTER_COLUMN_PK,
1767                                            _FILTER_COLUMN_USERID, groupId);
1768    
1769                            SQLQuery q = session.createSQLQuery(sql);
1770    
1771                            q.addScalar(COUNT_COLUMN_NAME,
1772                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1773    
1774                            QueryPos qPos = QueryPos.getInstance(q);
1775    
1776                            qPos.add(groupId);
1777    
1778                            Long count = (Long)q.uniqueResult();
1779    
1780                            return count.intValue();
1781                    }
1782                    catch (Exception e) {
1783                            throw processException(e);
1784                    }
1785                    finally {
1786                            closeSession(session);
1787                    }
1788            }
1789    
1790            /**
1791             * Counts all the tasks proposals where groupId = &#63; and userId = &#63;.
1792             *
1793             * @param groupId the group id to search with
1794             * @param userId the user id to search with
1795             * @return the number of matching tasks proposals
1796             * @throws SystemException if a system exception occurred
1797             */
1798            public int countByG_U(long groupId, long userId) throws SystemException {
1799                    Object[] finderArgs = new Object[] { groupId, userId };
1800    
1801                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
1802                                    finderArgs, this);
1803    
1804                    if (count == null) {
1805                            Session session = null;
1806    
1807                            try {
1808                                    session = openSession();
1809    
1810                                    StringBundler query = new StringBundler(3);
1811    
1812                                    query.append(_SQL_COUNT_TASKSPROPOSAL_WHERE);
1813    
1814                                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1815    
1816                                    query.append(_FINDER_COLUMN_G_U_USERID_2);
1817    
1818                                    String sql = query.toString();
1819    
1820                                    Query q = session.createQuery(sql);
1821    
1822                                    QueryPos qPos = QueryPos.getInstance(q);
1823    
1824                                    qPos.add(groupId);
1825    
1826                                    qPos.add(userId);
1827    
1828                                    count = (Long)q.uniqueResult();
1829                            }
1830                            catch (Exception e) {
1831                                    throw processException(e);
1832                            }
1833                            finally {
1834                                    if (count == null) {
1835                                            count = Long.valueOf(0);
1836                                    }
1837    
1838                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
1839                                            count);
1840    
1841                                    closeSession(session);
1842                            }
1843                    }
1844    
1845                    return count.intValue();
1846            }
1847    
1848            /**
1849             * Filters by the user's permissions and counts all the tasks proposals where groupId = &#63; and userId = &#63;.
1850             *
1851             * @param groupId the group id to search with
1852             * @param userId the user id to search with
1853             * @return the number of matching tasks proposals that the user has permission to view
1854             * @throws SystemException if a system exception occurred
1855             */
1856            public int filterCountByG_U(long groupId, long userId)
1857                    throws SystemException {
1858                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1859                            return countByG_U(groupId, userId);
1860                    }
1861    
1862                    Session session = null;
1863    
1864                    try {
1865                            session = openSession();
1866    
1867                            StringBundler query = new StringBundler(3);
1868    
1869                            query.append(_FILTER_SQL_COUNT_TASKSPROPOSAL_WHERE);
1870    
1871                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1872    
1873                            query.append(_FINDER_COLUMN_G_U_USERID_2);
1874    
1875                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1876                                            TasksProposal.class.getName(), _FILTER_COLUMN_PK,
1877                                            _FILTER_COLUMN_USERID, groupId);
1878    
1879                            SQLQuery q = session.createSQLQuery(sql);
1880    
1881                            q.addScalar(COUNT_COLUMN_NAME,
1882                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1883    
1884                            QueryPos qPos = QueryPos.getInstance(q);
1885    
1886                            qPos.add(groupId);
1887    
1888                            qPos.add(userId);
1889    
1890                            Long count = (Long)q.uniqueResult();
1891    
1892                            return count.intValue();
1893                    }
1894                    catch (Exception e) {
1895                            throw processException(e);
1896                    }
1897                    finally {
1898                            closeSession(session);
1899                    }
1900            }
1901    
1902            /**
1903             * Counts all the tasks proposals where classNameId = &#63; and classPK = &#63;.
1904             *
1905             * @param classNameId the class name id to search with
1906             * @param classPK the class p k to search with
1907             * @return the number of matching tasks proposals
1908             * @throws SystemException if a system exception occurred
1909             */
1910            public int countByC_C(long classNameId, String classPK)
1911                    throws SystemException {
1912                    Object[] finderArgs = new Object[] { classNameId, classPK };
1913    
1914                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1915                                    finderArgs, this);
1916    
1917                    if (count == null) {
1918                            Session session = null;
1919    
1920                            try {
1921                                    session = openSession();
1922    
1923                                    StringBundler query = new StringBundler(3);
1924    
1925                                    query.append(_SQL_COUNT_TASKSPROPOSAL_WHERE);
1926    
1927                                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1928    
1929                                    if (classPK == null) {
1930                                            query.append(_FINDER_COLUMN_C_C_CLASSPK_1);
1931                                    }
1932                                    else {
1933                                            if (classPK.equals(StringPool.BLANK)) {
1934                                                    query.append(_FINDER_COLUMN_C_C_CLASSPK_3);
1935                                            }
1936                                            else {
1937                                                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1938                                            }
1939                                    }
1940    
1941                                    String sql = query.toString();
1942    
1943                                    Query q = session.createQuery(sql);
1944    
1945                                    QueryPos qPos = QueryPos.getInstance(q);
1946    
1947                                    qPos.add(classNameId);
1948    
1949                                    if (classPK != null) {
1950                                            qPos.add(classPK);
1951                                    }
1952    
1953                                    count = (Long)q.uniqueResult();
1954                            }
1955                            catch (Exception e) {
1956                                    throw processException(e);
1957                            }
1958                            finally {
1959                                    if (count == null) {
1960                                            count = Long.valueOf(0);
1961                                    }
1962    
1963                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1964                                            count);
1965    
1966                                    closeSession(session);
1967                            }
1968                    }
1969    
1970                    return count.intValue();
1971            }
1972    
1973            /**
1974             * Counts all the tasks proposals.
1975             *
1976             * @return the number of tasks proposals
1977             * @throws SystemException if a system exception occurred
1978             */
1979            public int countAll() throws SystemException {
1980                    Object[] finderArgs = new Object[0];
1981    
1982                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1983                                    finderArgs, this);
1984    
1985                    if (count == null) {
1986                            Session session = null;
1987    
1988                            try {
1989                                    session = openSession();
1990    
1991                                    Query q = session.createQuery(_SQL_COUNT_TASKSPROPOSAL);
1992    
1993                                    count = (Long)q.uniqueResult();
1994                            }
1995                            catch (Exception e) {
1996                                    throw processException(e);
1997                            }
1998                            finally {
1999                                    if (count == null) {
2000                                            count = Long.valueOf(0);
2001                                    }
2002    
2003                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2004                                            count);
2005    
2006                                    closeSession(session);
2007                            }
2008                    }
2009    
2010                    return count.intValue();
2011            }
2012    
2013            /**
2014             * Initializes the tasks proposal persistence.
2015             */
2016            public void afterPropertiesSet() {
2017                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2018                                            com.liferay.portal.util.PropsUtil.get(
2019                                                    "value.object.listener.com.liferay.portlet.tasks.model.TasksProposal")));
2020    
2021                    if (listenerClassNames.length > 0) {
2022                            try {
2023                                    List<ModelListener<TasksProposal>> listenersList = new ArrayList<ModelListener<TasksProposal>>();
2024    
2025                                    for (String listenerClassName : listenerClassNames) {
2026                                            listenersList.add((ModelListener<TasksProposal>)InstanceFactory.newInstance(
2027                                                            listenerClassName));
2028                                    }
2029    
2030                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2031                            }
2032                            catch (Exception e) {
2033                                    _log.error(e);
2034                            }
2035                    }
2036            }
2037    
2038            public void destroy() {
2039                    EntityCacheUtil.removeCache(TasksProposalImpl.class.getName());
2040                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2041                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
2042            }
2043    
2044            @BeanReference(type = TasksProposalPersistence.class)
2045            protected TasksProposalPersistence tasksProposalPersistence;
2046            @BeanReference(type = TasksReviewPersistence.class)
2047            protected TasksReviewPersistence tasksReviewPersistence;
2048            @BeanReference(type = ResourcePersistence.class)
2049            protected ResourcePersistence resourcePersistence;
2050            @BeanReference(type = UserPersistence.class)
2051            protected UserPersistence userPersistence;
2052            @BeanReference(type = MBMessagePersistence.class)
2053            protected MBMessagePersistence mbMessagePersistence;
2054            @BeanReference(type = SocialActivityPersistence.class)
2055            protected SocialActivityPersistence socialActivityPersistence;
2056            private static final String _SQL_SELECT_TASKSPROPOSAL = "SELECT tasksProposal FROM TasksProposal tasksProposal";
2057            private static final String _SQL_SELECT_TASKSPROPOSAL_WHERE = "SELECT tasksProposal FROM TasksProposal tasksProposal WHERE ";
2058            private static final String _SQL_COUNT_TASKSPROPOSAL = "SELECT COUNT(tasksProposal) FROM TasksProposal tasksProposal";
2059            private static final String _SQL_COUNT_TASKSPROPOSAL_WHERE = "SELECT COUNT(tasksProposal) FROM TasksProposal tasksProposal WHERE ";
2060            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "tasksProposal.groupId = ?";
2061            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "tasksProposal.groupId = ? AND ";
2062            private static final String _FINDER_COLUMN_G_U_USERID_2 = "tasksProposal.userId = ?";
2063            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "tasksProposal.classNameId = ? AND ";
2064            private static final String _FINDER_COLUMN_C_C_CLASSPK_1 = "tasksProposal.classPK IS NULL";
2065            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "tasksProposal.classPK = ?";
2066            private static final String _FINDER_COLUMN_C_C_CLASSPK_3 = "(tasksProposal.classPK IS NULL OR tasksProposal.classPK = ?)";
2067            private static final String _FILTER_SQL_SELECT_TASKSPROPOSAL_WHERE = "SELECT DISTINCT {tasksProposal.*} FROM TasksProposal tasksProposal WHERE ";
2068            private static final String _FILTER_SQL_SELECT_TASKSPROPOSAL_NO_INLINE_DISTINCT_WHERE =
2069                    "SELECT {tasksProposal.*} FROM (SELECT DISTINCT proposalId FROM TasksProposal) tasksProposal2 INNER JOIN TasksProposal tasksProposal ON (tasksProposal2.proposalId = tasksProposal.proposalId) WHERE ";
2070            private static final String _FILTER_SQL_COUNT_TASKSPROPOSAL_WHERE = "SELECT COUNT(DISTINCT tasksProposal.proposalId) AS COUNT_VALUE FROM TasksProposal tasksProposal WHERE ";
2071            private static final String _FILTER_COLUMN_PK = "tasksProposal.proposalId";
2072            private static final String _FILTER_COLUMN_USERID = "tasksProposal.userId";
2073            private static final String _FILTER_ENTITY_ALIAS = "tasksProposal";
2074            private static final String _ORDER_BY_ENTITY_ALIAS = "tasksProposal.";
2075            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No TasksProposal exists with the primary key ";
2076            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No TasksProposal exists with the key {";
2077            private static Log _log = LogFactoryUtil.getLog(TasksProposalPersistenceImpl.class);
2078    }