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.botpress.business;
35
36 import fr.paris.lutece.portal.service.plugin.Plugin;
37 import fr.paris.lutece.util.ReferenceList;
38 import fr.paris.lutece.util.sql.DAOUtil;
39
40 import java.sql.Statement;
41
42 import java.util.ArrayList;
43 import java.util.List;
44
45
46
47
48 public final class BPBotDAO implements IBPBotDAO
49 {
50
51 private static final String SQL_QUERY_SELECT = "SELECT id_b_p_bot, bot_key, botpress_key, name, description, avatar_url, avatar_renderer_key, language, bot_status, is_standalone, welcome_message, error_message, server_url, api_version FROM botpress_bots WHERE id_b_p_bot = ?";
52 private static final String SQL_QUERY_INSERT = "INSERT INTO botpress_bots ( bot_key, botpress_key, name, description, avatar_url, avatar_renderer_key,language, bot_status, is_standalone, welcome_message, error_message, server_url, api_version ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) ";
53 private static final String SQL_QUERY_DELETE = "DELETE FROM botpress_bots WHERE id_b_p_bot = ? ";
54 private static final String SQL_QUERY_UPDATE = "UPDATE botpress_bots SET id_b_p_bot = ?, bot_key = ?, botpress_key = ?, name = ?, description = ?, avatar_url = ?, avatar_renderer_key = ?,language = ?, bot_status = ?, is_standalone = ?, welcome_message = ?, error_message = ?, server_url = ?, api_version = ? WHERE id_b_p_bot = ?";
55 private static final String SQL_QUERY_SELECTALL = "SELECT id_b_p_bot, bot_key, botpress_key, name, description, avatar_url, avatar_renderer_key, language, bot_status, is_standalone, welcome_message, error_message, server_url, api_version FROM botpress_bots";
56
57
58
59
60 @Override
61 public void insert( BPBot bPBot, Plugin plugin )
62 {
63 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, Statement.RETURN_GENERATED_KEYS, plugin );
64
65 try
66 {
67 int nIndex = 1;
68 daoUtil.setString( nIndex++, bPBot.getBotKey( ) );
69 daoUtil.setString( nIndex++, bPBot.getBotPressKey( ) );
70 daoUtil.setString( nIndex++, bPBot.getName( ) );
71 daoUtil.setString( nIndex++, bPBot.getDescription( ) );
72 daoUtil.setString( nIndex++, bPBot.getAvatarUrl( ) );
73 daoUtil.setString( nIndex++, bPBot.getAvatarRendererKey( ) );
74 daoUtil.setString( nIndex++, bPBot.getLanguage( ) );
75 daoUtil.setInt( nIndex++, bPBot.getBotStatus( ) );
76 daoUtil.setInt( nIndex++, bPBot.getIsStandalone( ) );
77 daoUtil.setString( nIndex++, bPBot.getWelcomeMessage( ) );
78 daoUtil.setString( nIndex++, bPBot.getErrorMessage( ) );
79 daoUtil.setString( nIndex++, bPBot.getServerUrl( ) );
80 daoUtil.setInt( nIndex++, bPBot.getApiVersion( ) );
81
82 daoUtil.executeUpdate( );
83
84 if ( daoUtil.nextGeneratedKey( ) )
85 {
86 bPBot.setId( daoUtil.getGeneratedKeyInt( 1 ) );
87 }
88 }
89 finally
90 {
91 daoUtil.free( );
92 }
93 }
94
95
96
97
98 @Override
99 public BPBot load( int nKey, Plugin plugin )
100 {
101 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT, plugin );
102 daoUtil.setInt( 1, nKey );
103 daoUtil.executeQuery( );
104
105 BPBot bPBot = null;
106
107 if ( daoUtil.next( ) )
108 {
109 bPBot = new BPBot( );
110
111 int nIndex = 1;
112
113 bPBot.setId( daoUtil.getInt( nIndex++ ) );
114 bPBot.setBotKey( daoUtil.getString( nIndex++ ) );
115 bPBot.setBotPressKey( daoUtil.getString( nIndex++ ) );
116 bPBot.setName( daoUtil.getString( nIndex++ ) );
117 bPBot.setDescription( daoUtil.getString( nIndex++ ) );
118 bPBot.setAvatarUrl( daoUtil.getString( nIndex++ ) );
119 bPBot.setAvatarRendererKey( daoUtil.getString( nIndex++ ) );
120 bPBot.setLanguage( daoUtil.getString( nIndex++ ) );
121 bPBot.setBotStatus( daoUtil.getInt( nIndex++ ) );
122 bPBot.setIsStandalone( daoUtil.getInt( nIndex++ ) );
123 bPBot.setWelcomeMessage( daoUtil.getString( nIndex++ ) );
124 bPBot.setErrorMessage( daoUtil.getString( nIndex++ ) );
125 bPBot.setServerUrl( daoUtil.getString( nIndex++ ) );
126 bPBot.setApiVersion( daoUtil.getInt( nIndex++ ) );
127 }
128
129 daoUtil.free( );
130
131 return bPBot;
132 }
133
134
135
136
137 @Override
138 public void delete( int nKey, Plugin plugin )
139 {
140 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin );
141 daoUtil.setInt( 1, nKey );
142 daoUtil.executeUpdate( );
143 daoUtil.free( );
144 }
145
146
147
148
149 @Override
150 public void store( BPBot bPBot, Plugin plugin )
151 {
152 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin );
153 int nIndex = 1;
154
155 daoUtil.setInt( nIndex++, bPBot.getId( ) );
156 daoUtil.setString( nIndex++, bPBot.getBotKey( ) );
157 daoUtil.setString( nIndex++, bPBot.getBotPressKey( ) );
158 daoUtil.setString( nIndex++, bPBot.getName( ) );
159 daoUtil.setString( nIndex++, bPBot.getDescription( ) );
160 daoUtil.setString( nIndex++, bPBot.getAvatarUrl( ) );
161 daoUtil.setString( nIndex++, bPBot.getAvatarRendererKey( ) );
162 daoUtil.setString( nIndex++, bPBot.getLanguage( ) );
163 daoUtil.setInt( nIndex++, bPBot.getBotStatus( ) );
164 daoUtil.setInt( nIndex++, bPBot.getIsStandalone( ) );
165 daoUtil.setString( nIndex++, bPBot.getWelcomeMessage( ) );
166 daoUtil.setString( nIndex++, bPBot.getErrorMessage( ) );
167 daoUtil.setString( nIndex++, bPBot.getServerUrl( ) );
168 daoUtil.setInt( nIndex++, bPBot.getApiVersion( ) );
169 daoUtil.setInt( nIndex, bPBot.getId( ) );
170
171 daoUtil.executeUpdate( );
172 daoUtil.free( );
173 }
174
175
176
177
178 @Override
179 public List<BPBot> selectBPBotsList( Plugin plugin )
180 {
181 List<BPBot> bPBotList = new ArrayList<BPBot>( );
182 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL, plugin );
183 daoUtil.executeQuery( );
184
185 while ( daoUtil.next( ) )
186 {
187 BPBotins/botpress/business/BPBot.html#BPBot">BPBot bPBot = new BPBot( );
188 int nIndex = 1;
189
190 bPBot.setId( daoUtil.getInt( nIndex++ ) );
191 bPBot.setBotKey( daoUtil.getString( nIndex++ ) );
192 bPBot.setBotPressKey( daoUtil.getString( nIndex++ ) );
193 bPBot.setName( daoUtil.getString( nIndex++ ) );
194 bPBot.setDescription( daoUtil.getString( nIndex++ ) );
195 bPBot.setAvatarUrl( daoUtil.getString( nIndex++ ) );
196 bPBot.setAvatarRendererKey( daoUtil.getString( nIndex++ ) );
197 bPBot.setLanguage( daoUtil.getString( nIndex++ ) );
198 bPBot.setBotStatus( daoUtil.getInt( nIndex++ ) );
199 bPBot.setIsStandalone( daoUtil.getInt( nIndex++ ) );
200 bPBot.setWelcomeMessage( daoUtil.getString( nIndex++ ) );
201 bPBot.setErrorMessage( daoUtil.getString( nIndex++ ) );
202 bPBot.setServerUrl( daoUtil.getString( nIndex++ ) );
203 bPBot.setApiVersion( daoUtil.getInt( nIndex++ ) );
204
205 bPBotList.add( bPBot );
206 }
207
208 daoUtil.free( );
209
210 return bPBotList;
211 }
212
213
214
215
216 @Override
217 public ReferenceList selectBPBotsReferenceList( Plugin plugin )
218 {
219 ReferenceList bPBotList = new ReferenceList( );
220 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL, plugin );
221 daoUtil.executeQuery( );
222
223 while ( daoUtil.next( ) )
224 {
225 bPBotList.addItem( daoUtil.getInt( 1 ), daoUtil.getString( 2 ) );
226 }
227
228 daoUtil.free( );
229
230 return bPBotList;
231 }
232 }