1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.tasks.service.persistence;
16  
17  import com.liferay.portal.NoSuchModelException;
18  import com.liferay.portal.SystemException;
19  import com.liferay.portal.kernel.annotation.BeanReference;
20  import com.liferay.portal.kernel.cache.CacheRegistry;
21  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
22  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
23  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
24  import com.liferay.portal.kernel.dao.orm.FinderPath;
25  import com.liferay.portal.kernel.dao.orm.Query;
26  import com.liferay.portal.kernel.dao.orm.QueryPos;
27  import com.liferay.portal.kernel.dao.orm.QueryUtil;
28  import com.liferay.portal.kernel.dao.orm.Session;
29  import com.liferay.portal.kernel.log.Log;
30  import com.liferay.portal.kernel.log.LogFactoryUtil;
31  import com.liferay.portal.kernel.util.GetterUtil;
32  import com.liferay.portal.kernel.util.OrderByComparator;
33  import com.liferay.portal.kernel.util.StringBundler;
34  import com.liferay.portal.kernel.util.StringPool;
35  import com.liferay.portal.kernel.util.StringUtil;
36  import com.liferay.portal.kernel.util.Validator;
37  import com.liferay.portal.model.ModelListener;
38  import com.liferay.portal.service.persistence.BatchSessionUtil;
39  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
40  
41  import com.liferay.portlet.tasks.NoSuchProposalException;
42  import com.liferay.portlet.tasks.model.TasksProposal;
43  import com.liferay.portlet.tasks.model.impl.TasksProposalImpl;
44  import com.liferay.portlet.tasks.model.impl.TasksProposalModelImpl;
45  
46  import java.io.Serializable;
47  
48  import java.util.ArrayList;
49  import java.util.Collections;
50  import java.util.List;
51  
52  /**
53   * <a href="TasksProposalPersistenceImpl.java.html"><b><i>View Source</i></b></a>
54   *
55   * <p>
56   * ServiceBuilder generated this class. Modifications in this class will be
57   * overwritten the next time is generated.
58   * </p>
59   *
60   * @author    Brian Wing Shun Chan
61   * @see       TasksProposalPersistence
62   * @see       TasksProposalUtil
63   * @generated
64   */
65  public class TasksProposalPersistenceImpl extends BasePersistenceImpl<TasksProposal>
66      implements TasksProposalPersistence {
67      public static final String FINDER_CLASS_NAME_ENTITY = TasksProposalImpl.class.getName();
68      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
69          ".List";
70      public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
71              TasksProposalModelImpl.FINDER_CACHE_ENABLED,
72              FINDER_CLASS_NAME_LIST, "findByGroupId",
73              new String[] { Long.class.getName() });
74      public static final FinderPath FINDER_PATH_FIND_BY_OBC_GROUPID = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
75              TasksProposalModelImpl.FINDER_CACHE_ENABLED,
76              FINDER_CLASS_NAME_LIST, "findByGroupId",
77              new String[] {
78                  Long.class.getName(),
79                  
80              "java.lang.Integer", "java.lang.Integer",
81                  "com.liferay.portal.kernel.util.OrderByComparator"
82              });
83      public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
84              TasksProposalModelImpl.FINDER_CACHE_ENABLED,
85              FINDER_CLASS_NAME_LIST, "countByGroupId",
86              new String[] { Long.class.getName() });
87      public static final FinderPath FINDER_PATH_FIND_BY_G_U = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
88              TasksProposalModelImpl.FINDER_CACHE_ENABLED,
89              FINDER_CLASS_NAME_LIST, "findByG_U",
90              new String[] { Long.class.getName(), Long.class.getName() });
91      public static final FinderPath FINDER_PATH_FIND_BY_OBC_G_U = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
92              TasksProposalModelImpl.FINDER_CACHE_ENABLED,
93              FINDER_CLASS_NAME_LIST, "findByG_U",
94              new String[] {
95                  Long.class.getName(), Long.class.getName(),
96                  
97              "java.lang.Integer", "java.lang.Integer",
98                  "com.liferay.portal.kernel.util.OrderByComparator"
99              });
100     public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
101             TasksProposalModelImpl.FINDER_CACHE_ENABLED,
102             FINDER_CLASS_NAME_LIST, "countByG_U",
103             new String[] { Long.class.getName(), Long.class.getName() });
104     public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
105             TasksProposalModelImpl.FINDER_CACHE_ENABLED,
106             FINDER_CLASS_NAME_ENTITY, "fetchByC_C",
107             new String[] { Long.class.getName(), String.class.getName() });
108     public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
109             TasksProposalModelImpl.FINDER_CACHE_ENABLED,
110             FINDER_CLASS_NAME_LIST, "countByC_C",
111             new String[] { Long.class.getName(), String.class.getName() });
112     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
113             TasksProposalModelImpl.FINDER_CACHE_ENABLED,
114             FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
115     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
116             TasksProposalModelImpl.FINDER_CACHE_ENABLED,
117             FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
118 
119     public void cacheResult(TasksProposal tasksProposal) {
120         EntityCacheUtil.putResult(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
121             TasksProposalImpl.class, tasksProposal.getPrimaryKey(),
122             tasksProposal);
123 
124         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
125             new Object[] {
126                 new Long(tasksProposal.getClassNameId()),
127                 
128             tasksProposal.getClassPK()
129             }, tasksProposal);
130     }
131 
132     public void cacheResult(List<TasksProposal> tasksProposals) {
133         for (TasksProposal tasksProposal : tasksProposals) {
134             if (EntityCacheUtil.getResult(
135                         TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
136                         TasksProposalImpl.class, tasksProposal.getPrimaryKey(),
137                         this) == null) {
138                 cacheResult(tasksProposal);
139             }
140         }
141     }
142 
143     public void clearCache() {
144         CacheRegistry.clear(TasksProposalImpl.class.getName());
145         EntityCacheUtil.clearCache(TasksProposalImpl.class.getName());
146         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
147         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
148     }
149 
150     public TasksProposal create(long proposalId) {
151         TasksProposal tasksProposal = new TasksProposalImpl();
152 
153         tasksProposal.setNew(true);
154         tasksProposal.setPrimaryKey(proposalId);
155 
156         return tasksProposal;
157     }
158 
159     public TasksProposal remove(Serializable primaryKey)
160         throws NoSuchModelException, SystemException {
161         return remove(((Long)primaryKey).longValue());
162     }
163 
164     public TasksProposal remove(long proposalId)
165         throws NoSuchProposalException, SystemException {
166         Session session = null;
167 
168         try {
169             session = openSession();
170 
171             TasksProposal tasksProposal = (TasksProposal)session.get(TasksProposalImpl.class,
172                     new Long(proposalId));
173 
174             if (tasksProposal == null) {
175                 if (_log.isWarnEnabled()) {
176                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + proposalId);
177                 }
178 
179                 throw new NoSuchProposalException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
180                     proposalId);
181             }
182 
183             return remove(tasksProposal);
184         }
185         catch (NoSuchProposalException nsee) {
186             throw nsee;
187         }
188         catch (Exception e) {
189             throw processException(e);
190         }
191         finally {
192             closeSession(session);
193         }
194     }
195 
196     public TasksProposal remove(TasksProposal tasksProposal)
197         throws SystemException {
198         for (ModelListener<TasksProposal> listener : listeners) {
199             listener.onBeforeRemove(tasksProposal);
200         }
201 
202         tasksProposal = removeImpl(tasksProposal);
203 
204         for (ModelListener<TasksProposal> listener : listeners) {
205             listener.onAfterRemove(tasksProposal);
206         }
207 
208         return tasksProposal;
209     }
210 
211     protected TasksProposal removeImpl(TasksProposal tasksProposal)
212         throws SystemException {
213         tasksProposal = toUnwrappedModel(tasksProposal);
214 
215         Session session = null;
216 
217         try {
218             session = openSession();
219 
220             if (tasksProposal.isCachedModel() || BatchSessionUtil.isEnabled()) {
221                 Object staleObject = session.get(TasksProposalImpl.class,
222                         tasksProposal.getPrimaryKeyObj());
223 
224                 if (staleObject != null) {
225                     session.evict(staleObject);
226                 }
227             }
228 
229             session.delete(tasksProposal);
230 
231             session.flush();
232         }
233         catch (Exception e) {
234             throw processException(e);
235         }
236         finally {
237             closeSession(session);
238         }
239 
240         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
241 
242         TasksProposalModelImpl tasksProposalModelImpl = (TasksProposalModelImpl)tasksProposal;
243 
244         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
245             new Object[] {
246                 new Long(tasksProposalModelImpl.getOriginalClassNameId()),
247                 
248             tasksProposalModelImpl.getOriginalClassPK()
249             });
250 
251         EntityCacheUtil.removeResult(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
252             TasksProposalImpl.class, tasksProposal.getPrimaryKey());
253 
254         return tasksProposal;
255     }
256 
257     /**
258      * @deprecated Use {@link BasePersistence#update(com.liferay.portal.model.BaseModel, boolean)}.
259      */
260     public TasksProposal update(TasksProposal tasksProposal)
261         throws SystemException {
262         if (_log.isWarnEnabled()) {
263             _log.warn(
264                 "Using the deprecated update(TasksProposal tasksProposal) method. Use update(TasksProposal tasksProposal, boolean merge) instead.");
265         }
266 
267         return update(tasksProposal, false);
268     }
269 
270     public TasksProposal updateImpl(
271         com.liferay.portlet.tasks.model.TasksProposal tasksProposal,
272         boolean merge) throws SystemException {
273         tasksProposal = toUnwrappedModel(tasksProposal);
274 
275         boolean isNew = tasksProposal.isNew();
276 
277         TasksProposalModelImpl tasksProposalModelImpl = (TasksProposalModelImpl)tasksProposal;
278 
279         Session session = null;
280 
281         try {
282             session = openSession();
283 
284             BatchSessionUtil.update(session, tasksProposal, merge);
285 
286             tasksProposal.setNew(false);
287         }
288         catch (Exception e) {
289             throw processException(e);
290         }
291         finally {
292             closeSession(session);
293         }
294 
295         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
296 
297         EntityCacheUtil.putResult(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
298             TasksProposalImpl.class, tasksProposal.getPrimaryKey(),
299             tasksProposal);
300 
301         if (!isNew &&
302                 ((tasksProposal.getClassNameId() != tasksProposalModelImpl.getOriginalClassNameId()) ||
303                 !Validator.equals(tasksProposal.getClassPK(),
304                     tasksProposalModelImpl.getOriginalClassPK()))) {
305             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
306                 new Object[] {
307                     new Long(tasksProposalModelImpl.getOriginalClassNameId()),
308                     
309                 tasksProposalModelImpl.getOriginalClassPK()
310                 });
311         }
312 
313         if (isNew ||
314                 ((tasksProposal.getClassNameId() != tasksProposalModelImpl.getOriginalClassNameId()) ||
315                 !Validator.equals(tasksProposal.getClassPK(),
316                     tasksProposalModelImpl.getOriginalClassPK()))) {
317             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
318                 new Object[] {
319                     new Long(tasksProposal.getClassNameId()),
320                     
321                 tasksProposal.getClassPK()
322                 }, tasksProposal);
323         }
324 
325         return tasksProposal;
326     }
327 
328     protected TasksProposal toUnwrappedModel(TasksProposal tasksProposal) {
329         if (tasksProposal instanceof TasksProposalImpl) {
330             return tasksProposal;
331         }
332 
333         TasksProposalImpl tasksProposalImpl = new TasksProposalImpl();
334 
335         tasksProposalImpl.setNew(tasksProposal.isNew());
336         tasksProposalImpl.setPrimaryKey(tasksProposal.getPrimaryKey());
337 
338         tasksProposalImpl.setProposalId(tasksProposal.getProposalId());
339         tasksProposalImpl.setGroupId(tasksProposal.getGroupId());
340         tasksProposalImpl.setCompanyId(tasksProposal.getCompanyId());
341         tasksProposalImpl.setUserId(tasksProposal.getUserId());
342         tasksProposalImpl.setUserName(tasksProposal.getUserName());
343         tasksProposalImpl.setCreateDate(tasksProposal.getCreateDate());
344         tasksProposalImpl.setModifiedDate(tasksProposal.getModifiedDate());
345         tasksProposalImpl.setClassNameId(tasksProposal.getClassNameId());
346         tasksProposalImpl.setClassPK(tasksProposal.getClassPK());
347         tasksProposalImpl.setName(tasksProposal.getName());
348         tasksProposalImpl.setDescription(tasksProposal.getDescription());
349         tasksProposalImpl.setPublishDate(tasksProposal.getPublishDate());
350         tasksProposalImpl.setDueDate(tasksProposal.getDueDate());
351 
352         return tasksProposalImpl;
353     }
354 
355     public TasksProposal findByPrimaryKey(Serializable primaryKey)
356         throws NoSuchModelException, SystemException {
357         return findByPrimaryKey(((Long)primaryKey).longValue());
358     }
359 
360     public TasksProposal findByPrimaryKey(long proposalId)
361         throws NoSuchProposalException, SystemException {
362         TasksProposal tasksProposal = fetchByPrimaryKey(proposalId);
363 
364         if (tasksProposal == null) {
365             if (_log.isWarnEnabled()) {
366                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + proposalId);
367             }
368 
369             throw new NoSuchProposalException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
370                 proposalId);
371         }
372 
373         return tasksProposal;
374     }
375 
376     public TasksProposal fetchByPrimaryKey(Serializable primaryKey)
377         throws SystemException {
378         return fetchByPrimaryKey(((Long)primaryKey).longValue());
379     }
380 
381     public TasksProposal fetchByPrimaryKey(long proposalId)
382         throws SystemException {
383         TasksProposal tasksProposal = (TasksProposal)EntityCacheUtil.getResult(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
384                 TasksProposalImpl.class, proposalId, this);
385 
386         if (tasksProposal == null) {
387             Session session = null;
388 
389             try {
390                 session = openSession();
391 
392                 tasksProposal = (TasksProposal)session.get(TasksProposalImpl.class,
393                         new Long(proposalId));
394             }
395             catch (Exception e) {
396                 throw processException(e);
397             }
398             finally {
399                 if (tasksProposal != null) {
400                     cacheResult(tasksProposal);
401                 }
402 
403                 closeSession(session);
404             }
405         }
406 
407         return tasksProposal;
408     }
409 
410     public List<TasksProposal> findByGroupId(long groupId)
411         throws SystemException {
412         Object[] finderArgs = new Object[] { new Long(groupId) };
413 
414         List<TasksProposal> list = (List<TasksProposal>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
415                 finderArgs, this);
416 
417         if (list == null) {
418             Session session = null;
419 
420             try {
421                 session = openSession();
422 
423                 StringBundler query = new StringBundler(3);
424 
425                 query.append(_SQL_SELECT_TASKSPROPOSAL_WHERE);
426 
427                 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
428 
429                 query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
430 
431                 String sql = query.toString();
432 
433                 Query q = session.createQuery(sql);
434 
435                 QueryPos qPos = QueryPos.getInstance(q);
436 
437                 qPos.add(groupId);
438 
439                 list = q.list();
440             }
441             catch (Exception e) {
442                 throw processException(e);
443             }
444             finally {
445                 if (list == null) {
446                     list = new ArrayList<TasksProposal>();
447                 }
448 
449                 cacheResult(list);
450 
451                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
452                     finderArgs, list);
453 
454                 closeSession(session);
455             }
456         }
457 
458         return list;
459     }
460 
461     public List<TasksProposal> findByGroupId(long groupId, int start, int end)
462         throws SystemException {
463         return findByGroupId(groupId, start, end, null);
464     }
465 
466     public List<TasksProposal> findByGroupId(long groupId, int start, int end,
467         OrderByComparator obc) throws SystemException {
468         Object[] finderArgs = new Object[] {
469                 new Long(groupId),
470                 
471                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
472             };
473 
474         List<TasksProposal> list = (List<TasksProposal>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
475                 finderArgs, this);
476 
477         if (list == null) {
478             Session session = null;
479 
480             try {
481                 session = openSession();
482 
483                 StringBundler query = null;
484 
485                 if (obc != null) {
486                     query = new StringBundler(3 +
487                             (obc.getOrderByFields().length * 3));
488                 }
489                 else {
490                     query = new StringBundler(3);
491                 }
492 
493                 query.append(_SQL_SELECT_TASKSPROPOSAL_WHERE);
494 
495                 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
496 
497                 if (obc != null) {
498                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
499                 }
500 
501                 else {
502                     query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
503                 }
504 
505                 String sql = query.toString();
506 
507                 Query q = session.createQuery(sql);
508 
509                 QueryPos qPos = QueryPos.getInstance(q);
510 
511                 qPos.add(groupId);
512 
513                 list = (List<TasksProposal>)QueryUtil.list(q, getDialect(),
514                         start, end);
515             }
516             catch (Exception e) {
517                 throw processException(e);
518             }
519             finally {
520                 if (list == null) {
521                     list = new ArrayList<TasksProposal>();
522                 }
523 
524                 cacheResult(list);
525 
526                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
527                     finderArgs, list);
528 
529                 closeSession(session);
530             }
531         }
532 
533         return list;
534     }
535 
536     public TasksProposal findByGroupId_First(long groupId, OrderByComparator obc)
537         throws NoSuchProposalException, SystemException {
538         List<TasksProposal> list = findByGroupId(groupId, 0, 1, obc);
539 
540         if (list.isEmpty()) {
541             StringBundler msg = new StringBundler(4);
542 
543             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
544 
545             msg.append("groupId=");
546             msg.append(groupId);
547 
548             msg.append(StringPool.CLOSE_CURLY_BRACE);
549 
550             throw new NoSuchProposalException(msg.toString());
551         }
552         else {
553             return list.get(0);
554         }
555     }
556 
557     public TasksProposal findByGroupId_Last(long groupId, OrderByComparator obc)
558         throws NoSuchProposalException, SystemException {
559         int count = countByGroupId(groupId);
560 
561         List<TasksProposal> list = findByGroupId(groupId, count - 1, count, obc);
562 
563         if (list.isEmpty()) {
564             StringBundler msg = new StringBundler(4);
565 
566             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
567 
568             msg.append("groupId=");
569             msg.append(groupId);
570 
571             msg.append(StringPool.CLOSE_CURLY_BRACE);
572 
573             throw new NoSuchProposalException(msg.toString());
574         }
575         else {
576             return list.get(0);
577         }
578     }
579 
580     public TasksProposal[] findByGroupId_PrevAndNext(long proposalId,
581         long groupId, OrderByComparator obc)
582         throws NoSuchProposalException, SystemException {
583         TasksProposal tasksProposal = findByPrimaryKey(proposalId);
584 
585         int count = countByGroupId(groupId);
586 
587         Session session = null;
588 
589         try {
590             session = openSession();
591 
592             StringBundler query = null;
593 
594             if (obc != null) {
595                 query = new StringBundler(3 +
596                         (obc.getOrderByFields().length * 3));
597             }
598             else {
599                 query = new StringBundler(3);
600             }
601 
602             query.append(_SQL_SELECT_TASKSPROPOSAL_WHERE);
603 
604             query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
605 
606             if (obc != null) {
607                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
608             }
609 
610             else {
611                 query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
612             }
613 
614             String sql = query.toString();
615 
616             Query q = session.createQuery(sql);
617 
618             QueryPos qPos = QueryPos.getInstance(q);
619 
620             qPos.add(groupId);
621 
622             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
623                     tasksProposal);
624 
625             TasksProposal[] array = new TasksProposalImpl[3];
626 
627             array[0] = (TasksProposal)objArray[0];
628             array[1] = (TasksProposal)objArray[1];
629             array[2] = (TasksProposal)objArray[2];
630 
631             return array;
632         }
633         catch (Exception e) {
634             throw processException(e);
635         }
636         finally {
637             closeSession(session);
638         }
639     }
640 
641     public List<TasksProposal> findByG_U(long groupId, long userId)
642         throws SystemException {
643         Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
644 
645         List<TasksProposal> list = (List<TasksProposal>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_U,
646                 finderArgs, this);
647 
648         if (list == null) {
649             Session session = null;
650 
651             try {
652                 session = openSession();
653 
654                 StringBundler query = new StringBundler(4);
655 
656                 query.append(_SQL_SELECT_TASKSPROPOSAL_WHERE);
657 
658                 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
659 
660                 query.append(_FINDER_COLUMN_G_U_USERID_2);
661 
662                 query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
663 
664                 String sql = query.toString();
665 
666                 Query q = session.createQuery(sql);
667 
668                 QueryPos qPos = QueryPos.getInstance(q);
669 
670                 qPos.add(groupId);
671 
672                 qPos.add(userId);
673 
674                 list = q.list();
675             }
676             catch (Exception e) {
677                 throw processException(e);
678             }
679             finally {
680                 if (list == null) {
681                     list = new ArrayList<TasksProposal>();
682                 }
683 
684                 cacheResult(list);
685 
686                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_U, finderArgs,
687                     list);
688 
689                 closeSession(session);
690             }
691         }
692 
693         return list;
694     }
695 
696     public List<TasksProposal> findByG_U(long groupId, long userId, int start,
697         int end) throws SystemException {
698         return findByG_U(groupId, userId, start, end, null);
699     }
700 
701     public List<TasksProposal> findByG_U(long groupId, long userId, int start,
702         int end, OrderByComparator obc) throws SystemException {
703         Object[] finderArgs = new Object[] {
704                 new Long(groupId), new Long(userId),
705                 
706                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
707             };
708 
709         List<TasksProposal> list = (List<TasksProposal>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_G_U,
710                 finderArgs, this);
711 
712         if (list == null) {
713             Session session = null;
714 
715             try {
716                 session = openSession();
717 
718                 StringBundler query = null;
719 
720                 if (obc != null) {
721                     query = new StringBundler(4 +
722                             (obc.getOrderByFields().length * 3));
723                 }
724                 else {
725                     query = new StringBundler(4);
726                 }
727 
728                 query.append(_SQL_SELECT_TASKSPROPOSAL_WHERE);
729 
730                 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
731 
732                 query.append(_FINDER_COLUMN_G_U_USERID_2);
733 
734                 if (obc != null) {
735                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
736                 }
737 
738                 else {
739                     query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
740                 }
741 
742                 String sql = query.toString();
743 
744                 Query q = session.createQuery(sql);
745 
746                 QueryPos qPos = QueryPos.getInstance(q);
747 
748                 qPos.add(groupId);
749 
750                 qPos.add(userId);
751 
752                 list = (List<TasksProposal>)QueryUtil.list(q, getDialect(),
753                         start, end);
754             }
755             catch (Exception e) {
756                 throw processException(e);
757             }
758             finally {
759                 if (list == null) {
760                     list = new ArrayList<TasksProposal>();
761                 }
762 
763                 cacheResult(list);
764 
765                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_G_U,
766                     finderArgs, list);
767 
768                 closeSession(session);
769             }
770         }
771 
772         return list;
773     }
774 
775     public TasksProposal findByG_U_First(long groupId, long userId,
776         OrderByComparator obc) throws NoSuchProposalException, SystemException {
777         List<TasksProposal> list = findByG_U(groupId, userId, 0, 1, obc);
778 
779         if (list.isEmpty()) {
780             StringBundler msg = new StringBundler(6);
781 
782             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
783 
784             msg.append("groupId=");
785             msg.append(groupId);
786 
787             msg.append(", userId=");
788             msg.append(userId);
789 
790             msg.append(StringPool.CLOSE_CURLY_BRACE);
791 
792             throw new NoSuchProposalException(msg.toString());
793         }
794         else {
795             return list.get(0);
796         }
797     }
798 
799     public TasksProposal findByG_U_Last(long groupId, long userId,
800         OrderByComparator obc) throws NoSuchProposalException, SystemException {
801         int count = countByG_U(groupId, userId);
802 
803         List<TasksProposal> list = findByG_U(groupId, userId, count - 1, count,
804                 obc);
805 
806         if (list.isEmpty()) {
807             StringBundler msg = new StringBundler(6);
808 
809             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
810 
811             msg.append("groupId=");
812             msg.append(groupId);
813 
814             msg.append(", userId=");
815             msg.append(userId);
816 
817             msg.append(StringPool.CLOSE_CURLY_BRACE);
818 
819             throw new NoSuchProposalException(msg.toString());
820         }
821         else {
822             return list.get(0);
823         }
824     }
825 
826     public TasksProposal[] findByG_U_PrevAndNext(long proposalId, long groupId,
827         long userId, OrderByComparator obc)
828         throws NoSuchProposalException, SystemException {
829         TasksProposal tasksProposal = findByPrimaryKey(proposalId);
830 
831         int count = countByG_U(groupId, userId);
832 
833         Session session = null;
834 
835         try {
836             session = openSession();
837 
838             StringBundler query = null;
839 
840             if (obc != null) {
841                 query = new StringBundler(4 +
842                         (obc.getOrderByFields().length * 3));
843             }
844             else {
845                 query = new StringBundler(4);
846             }
847 
848             query.append(_SQL_SELECT_TASKSPROPOSAL_WHERE);
849 
850             query.append(_FINDER_COLUMN_G_U_GROUPID_2);
851 
852             query.append(_FINDER_COLUMN_G_U_USERID_2);
853 
854             if (obc != null) {
855                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
856             }
857 
858             else {
859                 query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
860             }
861 
862             String sql = query.toString();
863 
864             Query q = session.createQuery(sql);
865 
866             QueryPos qPos = QueryPos.getInstance(q);
867 
868             qPos.add(groupId);
869 
870             qPos.add(userId);
871 
872             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
873                     tasksProposal);
874 
875             TasksProposal[] array = new TasksProposalImpl[3];
876 
877             array[0] = (TasksProposal)objArray[0];
878             array[1] = (TasksProposal)objArray[1];
879             array[2] = (TasksProposal)objArray[2];
880 
881             return array;
882         }
883         catch (Exception e) {
884             throw processException(e);
885         }
886         finally {
887             closeSession(session);
888         }
889     }
890 
891     public TasksProposal findByC_C(long classNameId, String classPK)
892         throws NoSuchProposalException, SystemException {
893         TasksProposal tasksProposal = fetchByC_C(classNameId, classPK);
894 
895         if (tasksProposal == null) {
896             StringBundler msg = new StringBundler(6);
897 
898             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
899 
900             msg.append("classNameId=");
901             msg.append(classNameId);
902 
903             msg.append(", classPK=");
904             msg.append(classPK);
905 
906             msg.append(StringPool.CLOSE_CURLY_BRACE);
907 
908             if (_log.isWarnEnabled()) {
909                 _log.warn(msg.toString());
910             }
911 
912             throw new NoSuchProposalException(msg.toString());
913         }
914 
915         return tasksProposal;
916     }
917 
918     public TasksProposal fetchByC_C(long classNameId, String classPK)
919         throws SystemException {
920         return fetchByC_C(classNameId, classPK, true);
921     }
922 
923     public TasksProposal fetchByC_C(long classNameId, String classPK,
924         boolean retrieveFromCache) throws SystemException {
925         Object[] finderArgs = new Object[] { new Long(classNameId), classPK };
926 
927         Object result = null;
928 
929         if (retrieveFromCache) {
930             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
931                     finderArgs, this);
932         }
933 
934         if (result == null) {
935             Session session = null;
936 
937             try {
938                 session = openSession();
939 
940                 StringBundler query = new StringBundler(4);
941 
942                 query.append(_SQL_SELECT_TASKSPROPOSAL_WHERE);
943 
944                 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
945 
946                 if (classPK == null) {
947                     query.append(_FINDER_COLUMN_C_C_CLASSPK_1);
948                 }
949                 else {
950                     if (classPK.equals(StringPool.BLANK)) {
951                         query.append(_FINDER_COLUMN_C_C_CLASSPK_3);
952                     }
953                     else {
954                         query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
955                     }
956                 }
957 
958                 query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
959 
960                 String sql = query.toString();
961 
962                 Query q = session.createQuery(sql);
963 
964                 QueryPos qPos = QueryPos.getInstance(q);
965 
966                 qPos.add(classNameId);
967 
968                 if (classPK != null) {
969                     qPos.add(classPK);
970                 }
971 
972                 List<TasksProposal> list = q.list();
973 
974                 result = list;
975 
976                 TasksProposal tasksProposal = null;
977 
978                 if (list.isEmpty()) {
979                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
980                         finderArgs, list);
981                 }
982                 else {
983                     tasksProposal = list.get(0);
984 
985                     cacheResult(tasksProposal);
986 
987                     if ((tasksProposal.getClassNameId() != classNameId) ||
988                             (tasksProposal.getClassPK() == null) ||
989                             !tasksProposal.getClassPK().equals(classPK)) {
990                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
991                             finderArgs, tasksProposal);
992                     }
993                 }
994 
995                 return tasksProposal;
996             }
997             catch (Exception e) {
998                 throw processException(e);
999             }
1000            finally {
1001                if (result == null) {
1002                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
1003                        finderArgs, new ArrayList<TasksProposal>());
1004                }
1005
1006                closeSession(session);
1007            }
1008        }
1009        else {
1010            if (result instanceof List<?>) {
1011                return null;
1012            }
1013            else {
1014                return (TasksProposal)result;
1015            }
1016        }
1017    }
1018
1019    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1020        throws SystemException {
1021        Session session = null;
1022
1023        try {
1024            session = openSession();
1025
1026            dynamicQuery.compile(session);
1027
1028            return dynamicQuery.list();
1029        }
1030        catch (Exception e) {
1031            throw processException(e);
1032        }
1033        finally {
1034            closeSession(session);
1035        }
1036    }
1037
1038    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1039        int start, int end) throws SystemException {
1040        Session session = null;
1041
1042        try {
1043            session = openSession();
1044
1045            dynamicQuery.setLimit(start, end);
1046
1047            dynamicQuery.compile(session);
1048
1049            return dynamicQuery.list();
1050        }
1051        catch (Exception e) {
1052            throw processException(e);
1053        }
1054        finally {
1055            closeSession(session);
1056        }
1057    }
1058
1059    public List<TasksProposal> findAll() throws SystemException {
1060        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1061    }
1062
1063    public List<TasksProposal> findAll(int start, int end)
1064        throws SystemException {
1065        return findAll(start, end, null);
1066    }
1067
1068    public List<TasksProposal> findAll(int start, int end, OrderByComparator obc)
1069        throws SystemException {
1070        Object[] finderArgs = new Object[] {
1071                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1072            };
1073
1074        List<TasksProposal> list = (List<TasksProposal>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1075                finderArgs, this);
1076
1077        if (list == null) {
1078            Session session = null;
1079
1080            try {
1081                session = openSession();
1082
1083                StringBundler query = null;
1084                String sql = null;
1085
1086                if (obc != null) {
1087                    query = new StringBundler(2 +
1088                            (obc.getOrderByFields().length * 3));
1089
1090                    query.append(_SQL_SELECT_TASKSPROPOSAL);
1091
1092                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1093
1094                    sql = query.toString();
1095                }
1096
1097                else {
1098                    sql = _SQL_SELECT_TASKSPROPOSAL.concat(TasksProposalModelImpl.ORDER_BY_JPQL);
1099                }
1100
1101                Query q = session.createQuery(sql);
1102
1103                if (obc == null) {
1104                    list = (List<TasksProposal>)QueryUtil.list(q, getDialect(),
1105                            start, end, false);
1106
1107                    Collections.sort(list);
1108                }
1109                else {
1110                    list = (List<TasksProposal>)QueryUtil.list(q, getDialect(),
1111                            start, end);
1112                }
1113            }
1114            catch (Exception e) {
1115                throw processException(e);
1116            }
1117            finally {
1118                if (list == null) {
1119                    list = new ArrayList<TasksProposal>();
1120                }
1121
1122                cacheResult(list);
1123
1124                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1125
1126                closeSession(session);
1127            }
1128        }
1129
1130        return list;
1131    }
1132
1133    public void removeByGroupId(long groupId) throws SystemException {
1134        for (TasksProposal tasksProposal : findByGroupId(groupId)) {
1135            remove(tasksProposal);
1136        }
1137    }
1138
1139    public void removeByG_U(long groupId, long userId)
1140        throws SystemException {
1141        for (TasksProposal tasksProposal : findByG_U(groupId, userId)) {
1142            remove(tasksProposal);
1143        }
1144    }
1145
1146    public void removeByC_C(long classNameId, String classPK)
1147        throws NoSuchProposalException, SystemException {
1148        TasksProposal tasksProposal = findByC_C(classNameId, classPK);
1149
1150        remove(tasksProposal);
1151    }
1152
1153    public void removeAll() throws SystemException {
1154        for (TasksProposal tasksProposal : findAll()) {
1155            remove(tasksProposal);
1156        }
1157    }
1158
1159    public int countByGroupId(long groupId) throws SystemException {
1160        Object[] finderArgs = new Object[] { new Long(groupId) };
1161
1162        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1163                finderArgs, this);
1164
1165        if (count == null) {
1166            Session session = null;
1167
1168            try {
1169                session = openSession();
1170
1171                StringBundler query = new StringBundler(2);
1172
1173                query.append(_SQL_COUNT_TASKSPROPOSAL_WHERE);
1174
1175                query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1176
1177                String sql = query.toString();
1178
1179                Query q = session.createQuery(sql);
1180
1181                QueryPos qPos = QueryPos.getInstance(q);
1182
1183                qPos.add(groupId);
1184
1185                count = (Long)q.uniqueResult();
1186            }
1187            catch (Exception e) {
1188                throw processException(e);
1189            }
1190            finally {
1191                if (count == null) {
1192                    count = Long.valueOf(0);
1193                }
1194
1195                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1196                    finderArgs, count);
1197
1198                closeSession(session);
1199            }
1200        }
1201
1202        return count.intValue();
1203    }
1204
1205    public int countByG_U(long groupId, long userId) throws SystemException {
1206        Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
1207
1208        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
1209                finderArgs, this);
1210
1211        if (count == null) {
1212            Session session = null;
1213
1214            try {
1215                session = openSession();
1216
1217                StringBundler query = new StringBundler(3);
1218
1219                query.append(_SQL_COUNT_TASKSPROPOSAL_WHERE);
1220
1221                query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1222
1223                query.append(_FINDER_COLUMN_G_U_USERID_2);
1224
1225                String sql = query.toString();
1226
1227                Query q = session.createQuery(sql);
1228
1229                QueryPos qPos = QueryPos.getInstance(q);
1230
1231                qPos.add(groupId);
1232
1233                qPos.add(userId);
1234
1235                count = (Long)q.uniqueResult();
1236            }
1237            catch (Exception e) {
1238                throw processException(e);
1239            }
1240            finally {
1241                if (count == null) {
1242                    count = Long.valueOf(0);
1243                }
1244
1245                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
1246                    count);
1247
1248                closeSession(session);
1249            }
1250        }
1251
1252        return count.intValue();
1253    }
1254
1255    public int countByC_C(long classNameId, String classPK)
1256        throws SystemException {
1257        Object[] finderArgs = new Object[] { new Long(classNameId), classPK };
1258
1259        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1260                finderArgs, this);
1261
1262        if (count == null) {
1263            Session session = null;
1264
1265            try {
1266                session = openSession();
1267
1268                StringBundler query = new StringBundler(3);
1269
1270                query.append(_SQL_COUNT_TASKSPROPOSAL_WHERE);
1271
1272                query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1273
1274                if (classPK == null) {
1275                    query.append(_FINDER_COLUMN_C_C_CLASSPK_1);
1276                }
1277                else {
1278                    if (classPK.equals(StringPool.BLANK)) {
1279                        query.append(_FINDER_COLUMN_C_C_CLASSPK_3);
1280                    }
1281                    else {
1282                        query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1283                    }
1284                }
1285
1286                String sql = query.toString();
1287
1288                Query q = session.createQuery(sql);
1289
1290                QueryPos qPos = QueryPos.getInstance(q);
1291
1292                qPos.add(classNameId);
1293
1294                if (classPK != null) {
1295                    qPos.add(classPK);
1296                }
1297
1298                count = (Long)q.uniqueResult();
1299            }
1300            catch (Exception e) {
1301                throw processException(e);
1302            }
1303            finally {
1304                if (count == null) {
1305                    count = Long.valueOf(0);
1306                }
1307
1308                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1309                    count);
1310
1311                closeSession(session);
1312            }
1313        }
1314
1315        return count.intValue();
1316    }
1317
1318    public int countAll() throws SystemException {
1319        Object[] finderArgs = new Object[0];
1320
1321        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1322                finderArgs, this);
1323
1324        if (count == null) {
1325            Session session = null;
1326
1327            try {
1328                session = openSession();
1329
1330                Query q = session.createQuery(_SQL_COUNT_TASKSPROPOSAL);
1331
1332                count = (Long)q.uniqueResult();
1333            }
1334            catch (Exception e) {
1335                throw processException(e);
1336            }
1337            finally {
1338                if (count == null) {
1339                    count = Long.valueOf(0);
1340                }
1341
1342                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1343                    count);
1344
1345                closeSession(session);
1346            }
1347        }
1348
1349        return count.intValue();
1350    }
1351
1352    public void afterPropertiesSet() {
1353        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1354                    com.liferay.portal.util.PropsUtil.get(
1355                        "value.object.listener.com.liferay.portlet.tasks.model.TasksProposal")));
1356
1357        if (listenerClassNames.length > 0) {
1358            try {
1359                List<ModelListener<TasksProposal>> listenersList = new ArrayList<ModelListener<TasksProposal>>();
1360
1361                for (String listenerClassName : listenerClassNames) {
1362                    listenersList.add((ModelListener<TasksProposal>)Class.forName(
1363                            listenerClassName).newInstance());
1364                }
1365
1366                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1367            }
1368            catch (Exception e) {
1369                _log.error(e);
1370            }
1371        }
1372    }
1373
1374    @BeanReference(name = "com.liferay.portlet.tasks.service.persistence.TasksProposalPersistence")
1375    protected com.liferay.portlet.tasks.service.persistence.TasksProposalPersistence tasksProposalPersistence;
1376    @BeanReference(name = "com.liferay.portlet.tasks.service.persistence.TasksReviewPersistence")
1377    protected com.liferay.portlet.tasks.service.persistence.TasksReviewPersistence tasksReviewPersistence;
1378    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence")
1379    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1380    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence")
1381    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1382    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence")
1383    protected com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence mbMessagePersistence;
1384    @BeanReference(name = "com.liferay.portlet.social.service.persistence.SocialActivityPersistence")
1385    protected com.liferay.portlet.social.service.persistence.SocialActivityPersistence socialActivityPersistence;
1386    private static final String _SQL_SELECT_TASKSPROPOSAL = "SELECT tasksProposal FROM TasksProposal tasksProposal";
1387    private static final String _SQL_SELECT_TASKSPROPOSAL_WHERE = "SELECT tasksProposal FROM TasksProposal tasksProposal WHERE ";
1388    private static final String _SQL_COUNT_TASKSPROPOSAL = "SELECT COUNT(tasksProposal) FROM TasksProposal tasksProposal";
1389    private static final String _SQL_COUNT_TASKSPROPOSAL_WHERE = "SELECT COUNT(tasksProposal) FROM TasksProposal tasksProposal WHERE ";
1390    private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "tasksProposal.groupId = ?";
1391    private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "tasksProposal.groupId = ? AND ";
1392    private static final String _FINDER_COLUMN_G_U_USERID_2 = "tasksProposal.userId = ?";
1393    private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "tasksProposal.classNameId = ? AND ";
1394    private static final String _FINDER_COLUMN_C_C_CLASSPK_1 = "tasksProposal.classPK IS NULL";
1395    private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "tasksProposal.classPK = ?";
1396    private static final String _FINDER_COLUMN_C_C_CLASSPK_3 = "(tasksProposal.classPK IS NULL OR tasksProposal.classPK = ?)";
1397    private static final String _ORDER_BY_ENTITY_ALIAS = "tasksProposal.";
1398    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No TasksProposal exists with the primary key ";
1399    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No TasksProposal exists with the key {";
1400    private static Log _log = LogFactoryUtil.getLog(TasksProposalPersistenceImpl.class);
1401}