1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.calendar.business.notification;
35
36 import fr.paris.lutece.portal.service.plugin.Plugin;
37 import fr.paris.lutece.util.sql.DAOUtil;
38
39 import java.util.ArrayList;
40 import java.util.List;
41
42
43
44
45
46
47
48 public class CalendarNotificationDAO implements ICalendarNotificationDAO
49 {
50 private static final String SQL_QUERY_FIND_BY_PRIMARY_KEY = " SELECT key_email, email, id_agenda,date_expiry "
51 + " FROM calendar_notify_key WHERE key_email=?";
52 private static final String SQL_QUERY_INSERT = " INSERT INTO calendar_notify_key( "
53 + " key_email, email, id_agenda, date_expiry)" + " VALUES (?,?,?,?)";
54 private static final String SQL_QUERY_UPDATE = "UPDATE calendar_notify_key "
55 + " SET key_email = ?, email = ?, id_agenda = ?,date_expiry = ? WHERE key_email = ?";
56 private static final String SQL_QUERY_DELETE = " DELETE FROM calendar_notify_key WHERE key_email = ? ";
57 private static final String SQL_QUERY_SELECT_EXPIRY = " SELECT key_email, email, id_agenda,date_expiry FROM calendar_notify_key WHERE date_expiry < NOW( )";
58
59
60
61
62 @Override
63 public synchronized void insert( CalendarNotification calendarNotification, Plugin plugin )
64 {
65 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin );
66
67 int nPos = 0;
68
69 daoUtil.setString( ++nPos, calendarNotification.getKey( ) );
70 daoUtil.setString( ++nPos, calendarNotification.getEmail( ) );
71 daoUtil.setInt( ++nPos, calendarNotification.getIdAgenda( ) );
72 daoUtil.setTimestamp( ++nPos, calendarNotification.getDateExpiry( ) );
73
74 daoUtil.executeUpdate( );
75 daoUtil.free( );
76 }
77
78
79
80
81 @Override
82 public void store( CalendarNotification calendarNotification, Plugin plugin )
83 {
84 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin );
85
86 int nPos = 0;
87
88 daoUtil.setString( ++nPos, calendarNotification.getKey( ) );
89 daoUtil.setString( ++nPos, calendarNotification.getEmail( ) );
90 daoUtil.setInt( ++nPos, calendarNotification.getIdAgenda( ) );
91 daoUtil.setTimestamp( ++nPos, calendarNotification.getDateExpiry( ) );
92
93 daoUtil.setString( ++nPos, calendarNotification.getKey( ) );
94 daoUtil.executeUpdate( );
95 daoUtil.free( );
96 }
97
98
99
100
101 @Override
102 public CalendarNotification load( String strKey, Plugin plugin )
103 {
104 CalendarNotification calendarNotification = null;
105 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_BY_PRIMARY_KEY, plugin );
106
107 daoUtil.setString( 1, strKey );
108 daoUtil.executeQuery( );
109
110 int nPos = 0;
111
112 if ( daoUtil.next( ) )
113 {
114 calendarNotification = new CalendarNotification( );
115 calendarNotification.setKey( daoUtil.getString( ++nPos ) );
116 calendarNotification.setEmail( daoUtil.getString( ++nPos ) );
117 calendarNotification.setIdAgenda( daoUtil.getInt( ++nPos ) );
118 calendarNotification.setDateExpiry( daoUtil.getTimestamp( ++nPos ) );
119 }
120
121 daoUtil.free( );
122
123 return calendarNotification;
124 }
125
126
127
128
129 @Override
130 public void delete( String strKey, Plugin plugin )
131 {
132 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin );
133
134 daoUtil.setString( 1, strKey );
135 daoUtil.executeUpdate( );
136 daoUtil.free( );
137 }
138
139
140
141
142 @Override
143 public List<CalendarNotification> selectNotificationExpiry( Plugin plugin )
144 {
145 int nPos = 0;
146 List<CalendarNotification> listNotificationExpiry = new ArrayList<CalendarNotification>( );
147 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_EXPIRY, plugin );
148 daoUtil.executeQuery( );
149
150 while ( daoUtil.next( ) )
151 {
152 nPos = 0;
153
154 CalendarNotification calendarNotification = new CalendarNotification( );
155 calendarNotification.setKey( daoUtil.getString( ++nPos ) );
156 calendarNotification.setEmail( daoUtil.getString( ++nPos ) );
157 calendarNotification.setIdAgenda( daoUtil.getInt( ++nPos ) );
158 calendarNotification.setDateExpiry( daoUtil.getTimestamp( ++nPos ) );
159 listNotificationExpiry.add( calendarNotification );
160 }
161
162 daoUtil.free( );
163
164 return listNotificationExpiry;
165 }
166 }