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.pluginwizard.business;
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.Collection;
41
42
43
44
45 public final class ConfigurationKeyDAO implements IConfigurationKeyDAO
46 {
47
48 private static final String SQL_QUERY_NEW_PK = "SELECT max( id_key ) FROM pluginwizard_configuration_key";
49 private static final String SQL_QUERY_SELECT = "SELECT id_key, key_description, key_value FROM pluginwizard_configuration_key WHERE id_key = ?";
50 private static final String SQL_QUERY_INSERT = "INSERT INTO pluginwizard_configuration_key ( id_key, key_description, key_value ) VALUES ( ?, ?, ? ) ";
51 private static final String SQL_QUERY_DELETE = "DELETE FROM pluginwizard_configuration_key WHERE id_key = ? ";
52 private static final String SQL_QUERY_UPDATE = "UPDATE pluginwizard_configuration_key SET id_key = ?, key_description = ?, key_value = ? WHERE id_key = ?";
53 private static final String SQL_QUERY_SELECTALL = "SELECT id_key, key_description, key_value FROM pluginwizard_configuration_key";
54
55
56
57
58
59
60
61
62 public int newPrimaryKey( Plugin plugin )
63 {
64 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_NEW_PK, plugin ) )
65 {
66 daoUtil.executeQuery( );
67
68 int nKey;
69
70 if ( !daoUtil.next( ) )
71 {
72
73 nKey = 1;
74 }
75
76 nKey = daoUtil.getInt( 1 ) + 1;
77 daoUtil.free( );
78
79 return nKey;
80 }
81 }
82
83
84
85
86
87
88
89
90
91 public void insert( ConfigurationKey configurationKey, Plugin plugin )
92 {
93 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin ) )
94 {
95
96 configurationKey.setIdKey( newPrimaryKey( plugin ) );
97
98 daoUtil.setInt( 1, configurationKey.getIdKey( ) );
99 daoUtil.setString( 2, configurationKey.getKeyDescription( ) );
100 daoUtil.setString( 3, configurationKey.getKeyValue( ) );
101
102 daoUtil.executeUpdate( );
103 daoUtil.free( );
104 }
105 }
106
107
108
109
110
111
112
113
114
115
116 public ConfigurationKey load( int nId, Plugin plugin )
117 {
118 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT, plugin ) )
119 {
120 daoUtil.setInt( 1, nId );
121 daoUtil.executeQuery( );
122
123 ConfigurationKey configurationKey = null;
124
125 if ( daoUtil.next( ) )
126 {
127 configurationKey = new ConfigurationKey( );
128
129 configurationKey.setIdKey( daoUtil.getInt( 1 ) );
130 configurationKey.setKeyDescription( daoUtil.getString( 2 ) );
131 configurationKey.setKeyValue( daoUtil.getString( 3 ) );
132 }
133
134 daoUtil.free( );
135
136 return configurationKey;
137 }
138 }
139
140
141
142
143
144
145
146
147
148 public void delete( int nConfigurationKeyId, Plugin plugin )
149 {
150 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin ) )
151 {
152 daoUtil.setInt( 1, nConfigurationKeyId );
153 daoUtil.executeUpdate( );
154 daoUtil.free( );
155 }
156 }
157
158
159
160
161
162
163
164
165
166 public void store( ConfigurationKey configurationKey, Plugin plugin )
167 {
168 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin ) )
169 {
170
171 daoUtil.setInt( 1, configurationKey.getIdKey( ) );
172 daoUtil.setString( 2, configurationKey.getKeyDescription( ) );
173 daoUtil.setString( 3, configurationKey.getKeyValue( ) );
174 daoUtil.setInt( 4, configurationKey.getIdKey( ) );
175
176 daoUtil.executeUpdate( );
177 daoUtil.free( );
178 }
179 }
180
181
182
183
184
185
186
187
188 public Collection<ConfigurationKey> selectConfigurationKeysList( Plugin plugin )
189 {
190 Collection<ConfigurationKey> configurationKeyList = new ArrayList<>( );
191 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL, plugin ) )
192 {
193 daoUtil.executeQuery( );
194
195 while ( daoUtil.next( ) )
196 {
197 ConfigurationKeyess/ConfigurationKey.html#ConfigurationKey">ConfigurationKey configurationKey = new ConfigurationKey( );
198
199 configurationKey.setIdKey( daoUtil.getInt( 1 ) );
200 configurationKey.setKeyDescription( daoUtil.getString( 2 ) );
201 configurationKey.setKeyValue( daoUtil.getString( 3 ) );
202
203 configurationKeyList.add( configurationKey );
204 }
205
206 daoUtil.free( );
207
208 return configurationKeyList;
209 }
210 }
211 }