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.kernel.annotation.BeanReference;
19  import com.liferay.portal.kernel.cache.CacheRegistry;
20  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
21  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
22  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
23  import com.liferay.portal.kernel.dao.orm.FinderPath;
24  import com.liferay.portal.kernel.dao.orm.Query;
25  import com.liferay.portal.kernel.dao.orm.QueryPos;
26  import com.liferay.portal.kernel.dao.orm.QueryUtil;
27  import com.liferay.portal.kernel.dao.orm.Session;
28  import com.liferay.portal.kernel.exception.SystemException;
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     public TasksProposal updateImpl(
258         com.liferay.portlet.tasks.model.TasksProposal tasksProposal,
259         boolean merge) throws SystemException {
260         tasksProposal = toUnwrappedModel(tasksProposal);
261 
262         boolean isNew = tasksProposal.isNew();
263 
264         TasksProposalModelImpl tasksProposalModelImpl = (TasksProposalModelImpl)tasksProposal;
265 
266         Session session = null;
267 
268         try {
269             session = openSession();
270 
271             BatchSessionUtil.update(session, tasksProposal, merge);
272 
273             tasksProposal.setNew(false);
274         }
275         catch (Exception e) {
276             throw processException(e);
277         }
278         finally {
279             closeSession(session);
280         }
281 
282         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
283 
284         EntityCacheUtil.putResult(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
285             TasksProposalImpl.class, tasksProposal.getPrimaryKey(),
286             tasksProposal);
287 
288         if (!isNew &&
289                 ((tasksProposal.getClassNameId() != tasksProposalModelImpl.getOriginalClassNameId()) ||
290                 !Validator.equals(tasksProposal.getClassPK(),
291                     tasksProposalModelImpl.getOriginalClassPK()))) {
292             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
293                 new Object[] {
294                     new Long(tasksProposalModelImpl.getOriginalClassNameId()),
295                     
296                 tasksProposalModelImpl.getOriginalClassPK()
297                 });
298         }
299 
300         if (isNew ||
301                 ((tasksProposal.getClassNameId() != tasksProposalModelImpl.getOriginalClassNameId()) ||
302                 !Validator.equals(tasksProposal.getClassPK(),
303                     tasksProposalModelImpl.getOriginalClassPK()))) {
304             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
305                 new Object[] {
306                     new Long(tasksProposal.getClassNameId()),
307                     
308                 tasksProposal.getClassPK()
309                 }, tasksProposal);
310         }
311 
312         return tasksProposal;
313     }
314 
315     protected TasksProposal toUnwrappedModel(TasksProposal tasksProposal) {
316         if (tasksProposal instanceof TasksProposalImpl) {
317             return tasksProposal;
318         }
319 
320         TasksProposalImpl tasksProposalImpl = new TasksProposalImpl();
321 
322         tasksProposalImpl.setNew(tasksProposal.isNew());
323         tasksProposalImpl.setPrimaryKey(tasksProposal.getPrimaryKey());
324 
325         tasksProposalImpl.setProposalId(tasksProposal.getProposalId());
326         tasksProposalImpl.setGroupId(tasksProposal.getGroupId());
327         tasksProposalImpl.setCompanyId(tasksProposal.getCompanyId());
328         tasksProposalImpl.setUserId(tasksProposal.getUserId());
329         tasksProposalImpl.setUserName(tasksProposal.getUserName());
330         tasksProposalImpl.setCreateDate(tasksProposal.getCreateDate());
331         tasksProposalImpl.setModifiedDate(tasksProposal.getModifiedDate());
332         tasksProposalImpl.setClassNameId(tasksProposal.getClassNameId());
333         tasksProposalImpl.setClassPK(tasksProposal.getClassPK());
334         tasksProposalImpl.setName(tasksProposal.getName());
335         tasksProposalImpl.setDescription(tasksProposal.getDescription());
336         tasksProposalImpl.setPublishDate(tasksProposal.getPublishDate());
337         tasksProposalImpl.setDueDate(tasksProposal.getDueDate());
338 
339         return tasksProposalImpl;
340     }
341 
342     public TasksProposal findByPrimaryKey(Serializable primaryKey)
343         throws NoSuchModelException, SystemException {
344         return findByPrimaryKey(((Long)primaryKey).longValue());
345     }
346 
347     public TasksProposal findByPrimaryKey(long proposalId)
348         throws NoSuchProposalException, SystemException {
349         TasksProposal tasksProposal = fetchByPrimaryKey(proposalId);
350 
351         if (tasksProposal == null) {
352             if (_log.isWarnEnabled()) {
353                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + proposalId);
354             }
355 
356             throw new NoSuchProposalException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
357                 proposalId);
358         }
359 
360         return tasksProposal;
361     }
362 
363     public TasksProposal fetchByPrimaryKey(Serializable primaryKey)
364         throws SystemException {
365         return fetchByPrimaryKey(((Long)primaryKey).longValue());
366     }
367 
368     public TasksProposal fetchByPrimaryKey(long proposalId)
369         throws SystemException {
370         TasksProposal tasksProposal = (TasksProposal)EntityCacheUtil.getResult(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
371                 TasksProposalImpl.class, proposalId, this);
372 
373         if (tasksProposal == null) {
374             Session session = null;
375 
376             try {
377                 session = openSession();
378 
379                 tasksProposal = (TasksProposal)session.get(TasksProposalImpl.class,
380                         new Long(proposalId));
381             }
382             catch (Exception e) {
383                 throw processException(e);
384             }
385             finally {
386                 if (tasksProposal != null) {
387                     cacheResult(tasksProposal);
388                 }
389 
390                 closeSession(session);
391             }
392         }
393 
394         return tasksProposal;
395     }
396 
397     public List<TasksProposal> findByGroupId(long groupId)
398         throws SystemException {
399         Object[] finderArgs = new Object[] { new Long(groupId) };
400 
401         List<TasksProposal> list = (List<TasksProposal>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
402                 finderArgs, this);
403 
404         if (list == null) {
405             Session session = null;
406 
407             try {
408                 session = openSession();
409 
410                 StringBundler query = new StringBundler(3);
411 
412                 query.append(_SQL_SELECT_TASKSPROPOSAL_WHERE);
413 
414                 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
415 
416                 query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
417 
418                 String sql = query.toString();
419 
420                 Query q = session.createQuery(sql);
421 
422                 QueryPos qPos = QueryPos.getInstance(q);
423 
424                 qPos.add(groupId);
425 
426                 list = q.list();
427             }
428             catch (Exception e) {
429                 throw processException(e);
430             }
431             finally {
432                 if (list == null) {
433                     list = new ArrayList<TasksProposal>();
434                 }
435 
436                 cacheResult(list);
437 
438                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
439                     finderArgs, list);
440 
441                 closeSession(session);
442             }
443         }
444 
445         return list;
446     }
447 
448     public List<TasksProposal> findByGroupId(long groupId, int start, int end)
449         throws SystemException {
450         return findByGroupId(groupId, start, end, null);
451     }
452 
453     public List<TasksProposal> findByGroupId(long groupId, int start, int end,
454         OrderByComparator obc) throws SystemException {
455         Object[] finderArgs = new Object[] {
456                 new Long(groupId),
457                 
458                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
459             };
460 
461         List<TasksProposal> list = (List<TasksProposal>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
462                 finderArgs, this);
463 
464         if (list == null) {
465             Session session = null;
466 
467             try {
468                 session = openSession();
469 
470                 StringBundler query = null;
471 
472                 if (obc != null) {
473                     query = new StringBundler(3 +
474                             (obc.getOrderByFields().length * 3));
475                 }
476                 else {
477                     query = new StringBundler(3);
478                 }
479 
480                 query.append(_SQL_SELECT_TASKSPROPOSAL_WHERE);
481 
482                 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
483 
484                 if (obc != null) {
485                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
486                 }
487 
488                 else {
489                     query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
490                 }
491 
492                 String sql = query.toString();
493 
494                 Query q = session.createQuery(sql);
495 
496                 QueryPos qPos = QueryPos.getInstance(q);
497 
498                 qPos.add(groupId);
499 
500                 list = (List<TasksProposal>)QueryUtil.list(q, getDialect(),
501                         start, end);
502             }
503             catch (Exception e) {
504                 throw processException(e);
505             }
506             finally {
507                 if (list == null) {
508                     list = new ArrayList<TasksProposal>();
509                 }
510 
511                 cacheResult(list);
512 
513                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
514                     finderArgs, list);
515 
516                 closeSession(session);
517             }
518         }
519 
520         return list;
521     }
522 
523     public TasksProposal findByGroupId_First(long groupId, OrderByComparator obc)
524         throws NoSuchProposalException, SystemException {
525         List<TasksProposal> list = findByGroupId(groupId, 0, 1, obc);
526 
527         if (list.isEmpty()) {
528             StringBundler msg = new StringBundler(4);
529 
530             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
531 
532             msg.append("groupId=");
533             msg.append(groupId);
534 
535             msg.append(StringPool.CLOSE_CURLY_BRACE);
536 
537             throw new NoSuchProposalException(msg.toString());
538         }
539         else {
540             return list.get(0);
541         }
542     }
543 
544     public TasksProposal findByGroupId_Last(long groupId, OrderByComparator obc)
545         throws NoSuchProposalException, SystemException {
546         int count = countByGroupId(groupId);
547 
548         List<TasksProposal> list = findByGroupId(groupId, count - 1, count, obc);
549 
550         if (list.isEmpty()) {
551             StringBundler msg = new StringBundler(4);
552 
553             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
554 
555             msg.append("groupId=");
556             msg.append(groupId);
557 
558             msg.append(StringPool.CLOSE_CURLY_BRACE);
559 
560             throw new NoSuchProposalException(msg.toString());
561         }
562         else {
563             return list.get(0);
564         }
565     }
566 
567     public TasksProposal[] findByGroupId_PrevAndNext(long proposalId,
568         long groupId, OrderByComparator obc)
569         throws NoSuchProposalException, SystemException {
570         TasksProposal tasksProposal = findByPrimaryKey(proposalId);
571 
572         int count = countByGroupId(groupId);
573 
574         Session session = null;
575 
576         try {
577             session = openSession();
578 
579             StringBundler query = null;
580 
581             if (obc != null) {
582                 query = new StringBundler(3 +
583                         (obc.getOrderByFields().length * 3));
584             }
585             else {
586                 query = new StringBundler(3);
587             }
588 
589             query.append(_SQL_SELECT_TASKSPROPOSAL_WHERE);
590 
591             query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
592 
593             if (obc != null) {
594                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
595             }
596 
597             else {
598                 query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
599             }
600 
601             String sql = query.toString();
602 
603             Query q = session.createQuery(sql);
604 
605             QueryPos qPos = QueryPos.getInstance(q);
606 
607             qPos.add(groupId);
608 
609             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
610                     tasksProposal);
611 
612             TasksProposal[] array = new TasksProposalImpl[3];
613 
614             array[0] = (TasksProposal)objArray[0];
615             array[1] = (TasksProposal)objArray[1];
616             array[2] = (TasksProposal)objArray[2];
617 
618             return array;
619         }
620         catch (Exception e) {
621             throw processException(e);
622         }
623         finally {
624             closeSession(session);
625         }
626     }
627 
628     public List<TasksProposal> findByG_U(long groupId, long userId)
629         throws SystemException {
630         Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
631 
632         List<TasksProposal> list = (List<TasksProposal>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_U,
633                 finderArgs, this);
634 
635         if (list == null) {
636             Session session = null;
637 
638             try {
639                 session = openSession();
640 
641                 StringBundler query = new StringBundler(4);
642 
643                 query.append(_SQL_SELECT_TASKSPROPOSAL_WHERE);
644 
645                 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
646 
647                 query.append(_FINDER_COLUMN_G_U_USERID_2);
648 
649                 query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
650 
651                 String sql = query.toString();
652 
653                 Query q = session.createQuery(sql);
654 
655                 QueryPos qPos = QueryPos.getInstance(q);
656 
657                 qPos.add(groupId);
658 
659                 qPos.add(userId);
660 
661                 list = q.list();
662             }
663             catch (Exception e) {
664                 throw processException(e);
665             }
666             finally {
667                 if (list == null) {
668                     list = new ArrayList<TasksProposal>();
669                 }
670 
671                 cacheResult(list);
672 
673                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_U, finderArgs,
674                     list);
675 
676                 closeSession(session);
677             }
678         }
679 
680         return list;
681     }
682 
683     public List<TasksProposal> findByG_U(long groupId, long userId, int start,
684         int end) throws SystemException {
685         return findByG_U(groupId, userId, start, end, null);
686     }
687 
688     public List<TasksProposal> findByG_U(long groupId, long userId, int start,
689         int end, OrderByComparator obc) throws SystemException {
690         Object[] finderArgs = new Object[] {
691                 new Long(groupId), new Long(userId),
692                 
693                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
694             };
695 
696         List<TasksProposal> list = (List<TasksProposal>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_G_U,
697                 finderArgs, this);
698 
699         if (list == null) {
700             Session session = null;
701 
702             try {
703                 session = openSession();
704 
705                 StringBundler query = null;
706 
707                 if (obc != null) {
708                     query = new StringBundler(4 +
709                             (obc.getOrderByFields().length * 3));
710                 }
711                 else {
712                     query = new StringBundler(4);
713                 }
714 
715                 query.append(_SQL_SELECT_TASKSPROPOSAL_WHERE);
716 
717                 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
718 
719                 query.append(_FINDER_COLUMN_G_U_USERID_2);
720 
721                 if (obc != null) {
722                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
723                 }
724 
725                 else {
726                     query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
727                 }
728 
729                 String sql = query.toString();
730 
731                 Query q = session.createQuery(sql);
732 
733                 QueryPos qPos = QueryPos.getInstance(q);
734 
735                 qPos.add(groupId);
736 
737                 qPos.add(userId);
738 
739                 list = (List<TasksProposal>)QueryUtil.list(q, getDialect(),
740                         start, end);
741             }
742             catch (Exception e) {
743                 throw processException(e);
744             }
745             finally {
746                 if (list == null) {
747                     list = new ArrayList<TasksProposal>();
748                 }
749 
750                 cacheResult(list);
751 
752                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_G_U,
753                     finderArgs, list);
754 
755                 closeSession(session);
756             }
757         }
758 
759         return list;
760     }
761 
762     public TasksProposal findByG_U_First(long groupId, long userId,
763         OrderByComparator obc) throws NoSuchProposalException, SystemException {
764         List<TasksProposal> list = findByG_U(groupId, userId, 0, 1, obc);
765 
766         if (list.isEmpty()) {
767             StringBundler msg = new StringBundler(6);
768 
769             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
770 
771             msg.append("groupId=");
772             msg.append(groupId);
773 
774             msg.append(", userId=");
775             msg.append(userId);
776 
777             msg.append(StringPool.CLOSE_CURLY_BRACE);
778 
779             throw new NoSuchProposalException(msg.toString());
780         }
781         else {
782             return list.get(0);
783         }
784     }
785 
786     public TasksProposal findByG_U_Last(long groupId, long userId,
787         OrderByComparator obc) throws NoSuchProposalException, SystemException {
788         int count = countByG_U(groupId, userId);
789 
790         List<TasksProposal> list = findByG_U(groupId, userId, count - 1, count,
791                 obc);
792 
793         if (list.isEmpty()) {
794             StringBundler msg = new StringBundler(6);
795 
796             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
797 
798             msg.append("groupId=");
799             msg.append(groupId);
800 
801             msg.append(", userId=");
802             msg.append(userId);
803 
804             msg.append(StringPool.CLOSE_CURLY_BRACE);
805 
806             throw new NoSuchProposalException(msg.toString());
807         }
808         else {
809             return list.get(0);
810         }
811     }
812 
813     public TasksProposal[] findByG_U_PrevAndNext(long proposalId, long groupId,
814         long userId, OrderByComparator obc)
815         throws NoSuchProposalException, SystemException {
816         TasksProposal tasksProposal = findByPrimaryKey(proposalId);
817 
818         int count = countByG_U(groupId, userId);
819 
820         Session session = null;
821 
822         try {
823             session = openSession();
824 
825             StringBundler query = null;
826 
827             if (obc != null) {
828                 query = new StringBundler(4 +
829                         (obc.getOrderByFields().length * 3));
830             }
831             else {
832                 query = new StringBundler(4);
833             }
834 
835             query.append(_SQL_SELECT_TASKSPROPOSAL_WHERE);
836 
837             query.append(_FINDER_COLUMN_G_U_GROUPID_2);
838 
839             query.append(_FINDER_COLUMN_G_U_USERID_2);
840 
841             if (obc != null) {
842                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
843             }
844 
845             else {
846                 query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
847             }
848 
849             String sql = query.toString();
850 
851             Query q = session.createQuery(sql);
852 
853             QueryPos qPos = QueryPos.getInstance(q);
854 
855             qPos.add(groupId);
856 
857             qPos.add(userId);
858 
859             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
860                     tasksProposal);
861 
862             TasksProposal[] array = new TasksProposalImpl[3];
863 
864             array[0] = (TasksProposal)objArray[0];
865             array[1] = (TasksProposal)objArray[1];
866             array[2] = (TasksProposal)objArray[2];
867 
868             return array;
869         }
870         catch (Exception e) {
871             throw processException(e);
872         }
873         finally {
874             closeSession(session);
875         }
876     }
877 
878     public TasksProposal findByC_C(long classNameId, String classPK)
879         throws NoSuchProposalException, SystemException {
880         TasksProposal tasksProposal = fetchByC_C(classNameId, classPK);
881 
882         if (tasksProposal == null) {
883             StringBundler msg = new StringBundler(6);
884 
885             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
886 
887             msg.append("classNameId=");
888             msg.append(classNameId);
889 
890             msg.append(", classPK=");
891             msg.append(classPK);
892 
893             msg.append(StringPool.CLOSE_CURLY_BRACE);
894 
895             if (_log.isWarnEnabled()) {
896                 _log.warn(msg.toString());
897             }
898 
899             throw new NoSuchProposalException(msg.toString());
900         }
901 
902         return tasksProposal;
903     }
904 
905     public TasksProposal fetchByC_C(long classNameId, String classPK)
906         throws SystemException {
907         return fetchByC_C(classNameId, classPK, true);
908     }
909 
910     public TasksProposal fetchByC_C(long classNameId, String classPK,
911         boolean retrieveFromCache) throws SystemException {
912         Object[] finderArgs = new Object[] { new Long(classNameId), classPK };
913 
914         Object result = null;
915 
916         if (retrieveFromCache) {
917             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
918                     finderArgs, this);
919         }
920 
921         if (result == null) {
922             Session session = null;
923 
924             try {
925                 session = openSession();
926 
927                 StringBundler query = new StringBundler(4);
928 
929                 query.append(_SQL_SELECT_TASKSPROPOSAL_WHERE);
930 
931                 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
932 
933                 if (classPK == null) {
934                     query.append(_FINDER_COLUMN_C_C_CLASSPK_1);
935                 }
936                 else {
937                     if (classPK.equals(StringPool.BLANK)) {
938                         query.append(_FINDER_COLUMN_C_C_CLASSPK_3);
939                     }
940                     else {
941                         query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
942                     }
943                 }
944 
945                 query.append(TasksProposalModelImpl.ORDER_BY_JPQL);
946 
947                 String sql = query.toString();
948 
949                 Query q = session.createQuery(sql);
950 
951                 QueryPos qPos = QueryPos.getInstance(q);
952 
953                 qPos.add(classNameId);
954 
955                 if (classPK != null) {
956                     qPos.add(classPK);
957                 }
958 
959                 List<TasksProposal> list = q.list();
960 
961                 result = list;
962 
963                 TasksProposal tasksProposal = null;
964 
965                 if (list.isEmpty()) {
966                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
967                         finderArgs, list);
968                 }
969                 else {
970                     tasksProposal = list.get(0);
971 
972                     cacheResult(tasksProposal);
973 
974                     if ((tasksProposal.getClassNameId() != classNameId) ||
975                             (tasksProposal.getClassPK() == null) ||
976                             !tasksProposal.getClassPK().equals(classPK)) {
977                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
978                             finderArgs, tasksProposal);
979                     }
980                 }
981 
982                 return tasksProposal;
983             }
984             catch (Exception e) {
985                 throw processException(e);
986             }
987             finally {
988                 if (result == null) {
989                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
990                         finderArgs, new ArrayList<TasksProposal>());
991                 }
992 
993                 closeSession(session);
994             }
995         }
996         else {
997             if (result instanceof List<?>) {
998                 return null;
999             }
1000            else {
1001                return (TasksProposal)result;
1002            }
1003        }
1004    }
1005
1006    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1007        throws SystemException {
1008        Session session = null;
1009
1010        try {
1011            session = openSession();
1012
1013            dynamicQuery.compile(session);
1014
1015            return dynamicQuery.list();
1016        }
1017        catch (Exception e) {
1018            throw processException(e);
1019        }
1020        finally {
1021            closeSession(session);
1022        }
1023    }
1024
1025    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1026        int start, int end) throws SystemException {
1027        Session session = null;
1028
1029        try {
1030            session = openSession();
1031
1032            dynamicQuery.setLimit(start, end);
1033
1034            dynamicQuery.compile(session);
1035
1036            return dynamicQuery.list();
1037        }
1038        catch (Exception e) {
1039            throw processException(e);
1040        }
1041        finally {
1042            closeSession(session);
1043        }
1044    }
1045
1046    public List<TasksProposal> findAll() throws SystemException {
1047        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1048    }
1049
1050    public List<TasksProposal> findAll(int start, int end)
1051        throws SystemException {
1052        return findAll(start, end, null);
1053    }
1054
1055    public List<TasksProposal> findAll(int start, int end, OrderByComparator obc)
1056        throws SystemException {
1057        Object[] finderArgs = new Object[] {
1058                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1059            };
1060
1061        List<TasksProposal> list = (List<TasksProposal>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1062                finderArgs, this);
1063
1064        if (list == null) {
1065            Session session = null;
1066
1067            try {
1068                session = openSession();
1069
1070                StringBundler query = null;
1071                String sql = null;
1072
1073                if (obc != null) {
1074                    query = new StringBundler(2 +
1075                            (obc.getOrderByFields().length * 3));
1076
1077                    query.append(_SQL_SELECT_TASKSPROPOSAL);
1078
1079                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1080
1081                    sql = query.toString();
1082                }
1083
1084                else {
1085                    sql = _SQL_SELECT_TASKSPROPOSAL.concat(TasksProposalModelImpl.ORDER_BY_JPQL);
1086                }
1087
1088                Query q = session.createQuery(sql);
1089
1090                if (obc == null) {
1091                    list = (List<TasksProposal>)QueryUtil.list(q, getDialect(),
1092                            start, end, false);
1093
1094                    Collections.sort(list);
1095                }
1096                else {
1097                    list = (List<TasksProposal>)QueryUtil.list(q, getDialect(),
1098                            start, end);
1099                }
1100            }
1101            catch (Exception e) {
1102                throw processException(e);
1103            }
1104            finally {
1105                if (list == null) {
1106                    list = new ArrayList<TasksProposal>();
1107                }
1108
1109                cacheResult(list);
1110
1111                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1112
1113                closeSession(session);
1114            }
1115        }
1116
1117        return list;
1118    }
1119
1120    public void removeByGroupId(long groupId) throws SystemException {
1121        for (TasksProposal tasksProposal : findByGroupId(groupId)) {
1122            remove(tasksProposal);
1123        }
1124    }
1125
1126    public void removeByG_U(long groupId, long userId)
1127        throws SystemException {
1128        for (TasksProposal tasksProposal : findByG_U(groupId, userId)) {
1129            remove(tasksProposal);
1130        }
1131    }
1132
1133    public void removeByC_C(long classNameId, String classPK)
1134        throws NoSuchProposalException, SystemException {
1135        TasksProposal tasksProposal = findByC_C(classNameId, classPK);
1136
1137        remove(tasksProposal);
1138    }
1139
1140    public void removeAll() throws SystemException {
1141        for (TasksProposal tasksProposal : findAll()) {
1142            remove(tasksProposal);
1143        }
1144    }
1145
1146    public int countByGroupId(long groupId) throws SystemException {
1147        Object[] finderArgs = new Object[] { new Long(groupId) };
1148
1149        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1150                finderArgs, this);
1151
1152        if (count == null) {
1153            Session session = null;
1154
1155            try {
1156                session = openSession();
1157
1158                StringBundler query = new StringBundler(2);
1159
1160                query.append(_SQL_COUNT_TASKSPROPOSAL_WHERE);
1161
1162                query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1163
1164                String sql = query.toString();
1165
1166                Query q = session.createQuery(sql);
1167
1168                QueryPos qPos = QueryPos.getInstance(q);
1169
1170                qPos.add(groupId);
1171
1172                count = (Long)q.uniqueResult();
1173            }
1174            catch (Exception e) {
1175                throw processException(e);
1176            }
1177            finally {
1178                if (count == null) {
1179                    count = Long.valueOf(0);
1180                }
1181
1182                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1183                    finderArgs, count);
1184
1185                closeSession(session);
1186            }
1187        }
1188
1189        return count.intValue();
1190    }
1191
1192    public int countByG_U(long groupId, long userId) throws SystemException {
1193        Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
1194
1195        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
1196                finderArgs, this);
1197
1198        if (count == null) {
1199            Session session = null;
1200
1201            try {
1202                session = openSession();
1203
1204                StringBundler query = new StringBundler(3);
1205
1206                query.append(_SQL_COUNT_TASKSPROPOSAL_WHERE);
1207
1208                query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1209
1210                query.append(_FINDER_COLUMN_G_U_USERID_2);
1211
1212                String sql = query.toString();
1213
1214                Query q = session.createQuery(sql);
1215
1216                QueryPos qPos = QueryPos.getInstance(q);
1217
1218                qPos.add(groupId);
1219
1220                qPos.add(userId);
1221
1222                count = (Long)q.uniqueResult();
1223            }
1224            catch (Exception e) {
1225                throw processException(e);
1226            }
1227            finally {
1228                if (count == null) {
1229                    count = Long.valueOf(0);
1230                }
1231
1232                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
1233                    count);
1234
1235                closeSession(session);
1236            }
1237        }
1238
1239        return count.intValue();
1240    }
1241
1242    public int countByC_C(long classNameId, String classPK)
1243        throws SystemException {
1244        Object[] finderArgs = new Object[] { new Long(classNameId), classPK };
1245
1246        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1247                finderArgs, this);
1248
1249        if (count == null) {
1250            Session session = null;
1251
1252            try {
1253                session = openSession();
1254
1255                StringBundler query = new StringBundler(3);
1256
1257                query.append(_SQL_COUNT_TASKSPROPOSAL_WHERE);
1258
1259                query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1260
1261                if (classPK == null) {
1262                    query.append(_FINDER_COLUMN_C_C_CLASSPK_1);
1263                }
1264                else {
1265                    if (classPK.equals(StringPool.BLANK)) {
1266                        query.append(_FINDER_COLUMN_C_C_CLASSPK_3);
1267                    }
1268                    else {
1269                        query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1270                    }
1271                }
1272
1273                String sql = query.toString();
1274
1275                Query q = session.createQuery(sql);
1276
1277                QueryPos qPos = QueryPos.getInstance(q);
1278
1279                qPos.add(classNameId);
1280
1281                if (classPK != null) {
1282                    qPos.add(classPK);
1283                }
1284
1285                count = (Long)q.uniqueResult();
1286            }
1287            catch (Exception e) {
1288                throw processException(e);
1289            }
1290            finally {
1291                if (count == null) {
1292                    count = Long.valueOf(0);
1293                }
1294
1295                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1296                    count);
1297
1298                closeSession(session);
1299            }
1300        }
1301
1302        return count.intValue();
1303    }
1304
1305    public int countAll() throws SystemException {
1306        Object[] finderArgs = new Object[0];
1307
1308        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1309                finderArgs, this);
1310
1311        if (count == null) {
1312            Session session = null;
1313
1314            try {
1315                session = openSession();
1316
1317                Query q = session.createQuery(_SQL_COUNT_TASKSPROPOSAL);
1318
1319                count = (Long)q.uniqueResult();
1320            }
1321            catch (Exception e) {
1322                throw processException(e);
1323            }
1324            finally {
1325                if (count == null) {
1326                    count = Long.valueOf(0);
1327                }
1328
1329                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1330                    count);
1331
1332                closeSession(session);
1333            }
1334        }
1335
1336        return count.intValue();
1337    }
1338
1339    public void afterPropertiesSet() {
1340        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1341                    com.liferay.portal.util.PropsUtil.get(
1342                        "value.object.listener.com.liferay.portlet.tasks.model.TasksProposal")));
1343
1344        if (listenerClassNames.length > 0) {
1345            try {
1346                List<ModelListener<TasksProposal>> listenersList = new ArrayList<ModelListener<TasksProposal>>();
1347
1348                for (String listenerClassName : listenerClassNames) {
1349                    listenersList.add((ModelListener<TasksProposal>)Class.forName(
1350                            listenerClassName).newInstance());
1351                }
1352
1353                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1354            }
1355            catch (Exception e) {
1356                _log.error(e);
1357            }
1358        }
1359    }
1360
1361    @BeanReference(name = "com.liferay.portlet.tasks.service.persistence.TasksProposalPersistence")
1362    protected com.liferay.portlet.tasks.service.persistence.TasksProposalPersistence tasksProposalPersistence;
1363    @BeanReference(name = "com.liferay.portlet.tasks.service.persistence.TasksReviewPersistence")
1364    protected com.liferay.portlet.tasks.service.persistence.TasksReviewPersistence tasksReviewPersistence;
1365    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence")
1366    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1367    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence")
1368    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1369    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence")
1370    protected com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence mbMessagePersistence;
1371    @BeanReference(name = "com.liferay.portlet.social.service.persistence.SocialActivityPersistence")
1372    protected com.liferay.portlet.social.service.persistence.SocialActivityPersistence socialActivityPersistence;
1373    private static final String _SQL_SELECT_TASKSPROPOSAL = "SELECT tasksProposal FROM TasksProposal tasksProposal";
1374    private static final String _SQL_SELECT_TASKSPROPOSAL_WHERE = "SELECT tasksProposal FROM TasksProposal tasksProposal WHERE ";
1375    private static final String _SQL_COUNT_TASKSPROPOSAL = "SELECT COUNT(tasksProposal) FROM TasksProposal tasksProposal";
1376    private static final String _SQL_COUNT_TASKSPROPOSAL_WHERE = "SELECT COUNT(tasksProposal) FROM TasksProposal tasksProposal WHERE ";
1377    private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "tasksProposal.groupId = ?";
1378    private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "tasksProposal.groupId = ? AND ";
1379    private static final String _FINDER_COLUMN_G_U_USERID_2 = "tasksProposal.userId = ?";
1380    private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "tasksProposal.classNameId = ? AND ";
1381    private static final String _FINDER_COLUMN_C_C_CLASSPK_1 = "tasksProposal.classPK IS NULL";
1382    private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "tasksProposal.classPK = ?";
1383    private static final String _FINDER_COLUMN_C_C_CLASSPK_3 = "(tasksProposal.classPK IS NULL OR tasksProposal.classPK = ?)";
1384    private static final String _ORDER_BY_ENTITY_ALIAS = "tasksProposal.";
1385    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No TasksProposal exists with the primary key ";
1386    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No TasksProposal exists with the key {";
1387    private static Log _log = LogFactoryUtil.getLog(TasksProposalPersistenceImpl.class);
1388}