1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.calendar.service.persistence;
24  
25  import com.liferay.portal.SystemException;
26  import com.liferay.portal.spring.hibernate.CustomSQLUtil;
27  import com.liferay.portal.spring.hibernate.HibernateUtil;
28  import com.liferay.portlet.calendar.model.impl.CalEventImpl;
29  import com.liferay.util.cal.CalendarUtil;
30  import com.liferay.util.dao.hibernate.QueryPos;
31  
32  import java.sql.Timestamp;
33  
34  import java.util.Date;
35  import java.util.List;
36  
37  import org.hibernate.SQLQuery;
38  import org.hibernate.Session;
39  
40  /**
41   * <a href="CalEventFinder.java.html"><b><i>View Source</i></b></a>
42   *
43   * @author Brian Wing Shun Chan
44   *
45   */
46  public class CalEventFinder {
47  
48      public static String FIND_BY_G_SD =
49          CalEventFinder.class.getName() + ".findByG_SD";
50  
51      public static String FIND_BY_REMINDBY =
52          CalEventFinder.class.getName() + ".findByRemindBy";
53  
54      public static List findByG_SD(
55              long groupId, Date startDateGT, Date startDateLT,
56              boolean timeZoneSensitive)
57          throws SystemException {
58  
59          Timestamp startDateGT_TS = CalendarUtil.getTimestamp(startDateGT);
60          Timestamp startDateLT_TS = CalendarUtil.getTimestamp(startDateLT);
61  
62          Session session = null;
63  
64          try {
65              session = HibernateUtil.openSession();
66  
67              String sql = CustomSQLUtil.get(FIND_BY_G_SD);
68  
69              SQLQuery q = session.createSQLQuery(sql);
70  
71              q.addEntity("CalEvent", CalEventImpl.class);
72  
73              QueryPos qPos = QueryPos.getInstance(q);
74  
75              qPos.add(groupId);
76              qPos.add(startDateGT_TS);
77              qPos.add(startDateLT_TS);
78              qPos.add(timeZoneSensitive);
79              qPos.add(false);
80  
81              return q.list();
82          }
83          catch (Exception e) {
84              throw new SystemException(e);
85          }
86          finally {
87              HibernateUtil.closeSession(session);
88          }
89      }
90  
91      public static List findByRemindBy() throws SystemException {
92          Session session = null;
93  
94          try {
95              session = HibernateUtil.openSession();
96  
97              String sql = CustomSQLUtil.get(FIND_BY_REMINDBY);
98  
99              SQLQuery q = session.createSQLQuery(sql);
100 
101             q.addEntity("CalEvent", CalEventImpl.class);
102 
103             QueryPos qPos = QueryPos.getInstance(q);
104 
105             qPos.add(CalEventImpl.REMIND_BY_NONE);
106 
107             return q.list();
108         }
109         catch (Exception e) {
110             throw new SystemException(e);
111         }
112         finally {
113             HibernateUtil.closeSession(session);
114         }
115     }
116 
117 }