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