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.portal.business.securityheader;
35
36 import java.sql.Statement;
37 import java.util.ArrayList;
38 import java.util.List;
39
40 import fr.paris.lutece.util.sql.DAOUtil;
41
42
43
44
45 public final class SecurityHeaderDAO implements ISecurityHeaderDAO
46 {
47
48 private static final String SQL_QUERY_SELECT = "SELECT id_security_header, name, value, description, type, page_category, is_active FROM core_admin_security_header WHERE id_security_header = ?";
49 private static final String SQL_QUERY_INSERT = "INSERT INTO core_admin_security_header ( name, value, description, type, page_category ) VALUES ( ?, ?, ?, ?, ? ) ";
50 private static final String SQL_QUERY_DELETE = "DELETE FROM core_admin_security_header WHERE id_security_header = ? ";
51 private static final String SQL_QUERY_UPDATE = "UPDATE core_admin_security_header SET value = ?, description = ?, type = ?, page_category = ? WHERE id_security_header = ?";
52 private static final String SQL_QUERY_UPDATE_IS_ACTIVE = "UPDATE core_admin_security_header SET is_active = ? WHERE id_security_header = ?";
53 private static final String SQL_QUERY_SELECTALL = "SELECT id_security_header, name, value, description, type, page_category, is_active FROM core_admin_security_header";
54 private static final String SQL_QUERY_SELECT_ACTIVE_BY_TYPE = "SELECT id_security_header, name, value, description, type, page_category, is_active FROM core_admin_security_header WHERE is_active = 'true' and type = ? ";
55
56
57
58
59
60
61
62 @Override
63 public void insert( SecurityHeader securityHeader )
64 {
65 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, Statement.RETURN_GENERATED_KEYS ) )
66 {
67 int nIndex = 1;
68 daoUtil.setString( nIndex++, securityHeader.getName( ) );
69 daoUtil.setString( nIndex++, securityHeader.getValue( ) );
70 daoUtil.setString( nIndex++, securityHeader.getDescription( ) );
71 daoUtil.setString( nIndex++, securityHeader.getType( ) );
72 daoUtil.setString( nIndex, securityHeader.getPageCategory() );
73
74 daoUtil.executeUpdate( );
75
76 if ( daoUtil.nextGeneratedKey( ) )
77 {
78 securityHeader.setId( daoUtil.getGeneratedKeyInt( 1 ) );
79 }
80 }
81 }
82
83
84
85
86
87
88
89
90 @Override
91 public SecurityHeader load( int nId )
92 {
93 SecurityHeader securityHeader = null;
94 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT ) )
95 {
96 daoUtil.setInt( 1, nId );
97 daoUtil.executeQuery( );
98
99 if ( daoUtil.next( ) )
100 {
101 securityHeader = new SecurityHeader( );
102
103 securityHeader.setId( daoUtil.getInt( 1 ) );
104 securityHeader.setName( daoUtil.getString( 2 ) );
105 securityHeader.setValue( daoUtil.getString( 3 ) );
106 securityHeader.setDescription( daoUtil.getString( 4 ) );
107 securityHeader.setType( daoUtil.getString( 5 ) );
108 securityHeader.setPageCategory(daoUtil.getString( 6 ));
109 securityHeader.setActive( daoUtil.getBoolean( 7 ) );
110 }
111
112 }
113
114 return securityHeader;
115 }
116
117
118
119
120
121
122
123 @Override
124 public void delete( int nSecurityHeaderId )
125 {
126 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE ) )
127 {
128 daoUtil.setInt( 1, nSecurityHeaderId );
129 daoUtil.executeUpdate( );
130 }
131 }
132
133
134
135
136
137
138
139 @Override
140 public void store( SecurityHeader securityHeader )
141 {
142 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE ) )
143 {
144
145 daoUtil.setString( 1, securityHeader.getValue( ) );
146 daoUtil.setString( 2, securityHeader.getDescription( ) );
147 daoUtil.setString( 3, securityHeader.getType( ) );
148 daoUtil.setString( 4, securityHeader.getPageCategory( ) );
149 daoUtil.setInt( 5, securityHeader.getId( ) );
150
151 daoUtil.executeUpdate( );
152 }
153 }
154
155
156
157
158
159
160
161
162
163 @Override
164 public void updateIsActive( int nSecurityHeaderId, boolean isActiveValue )
165 {
166 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE_IS_ACTIVE ) )
167 {
168
169 daoUtil.setBoolean( 1, isActiveValue );
170 daoUtil.setInt( 2, nSecurityHeaderId );
171
172 daoUtil.executeUpdate( );
173 }
174 }
175
176
177
178
179
180
181 @Override
182 public List<SecurityHeader> selectAll( )
183 {
184 List<SecurityHeader> securityHeadersList = new ArrayList<SecurityHeader>( );
185 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL ) )
186 {
187 daoUtil.executeQuery( );
188
189 while ( daoUtil.next( ) )
190 {
191 SecurityHeader securityHeader = new SecurityHeader( );
192
193 securityHeader.setId( daoUtil.getInt( 1 ) );
194 securityHeader.setName( daoUtil.getString( 2 ) );
195 securityHeader.setValue( daoUtil.getString( 3 ) );
196 securityHeader.setDescription( daoUtil.getString( 4 ) );
197 securityHeader.setType( daoUtil.getString( 5 ) );
198 securityHeader.setPageCategory(daoUtil.getString( 6 ) );
199 securityHeader.setActive( daoUtil.getBoolean( 7 ) );
200
201 securityHeadersList.add( securityHeader );
202 }
203
204 }
205
206 return securityHeadersList;
207 }
208
209
210
211
212
213
214
215
216 @Override
217 public List<SecurityHeader> selectActiveByType( String strType )
218 {
219 List<SecurityHeader> securityHeadersList = new ArrayList<>( );
220 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_ACTIVE_BY_TYPE ) )
221 {
222 daoUtil.setString( 1, strType );
223 daoUtil.executeQuery( );
224
225 while ( daoUtil.next( ) )
226 {
227 SecurityHeader securityHeader = new SecurityHeader( );
228
229 securityHeader.setId( daoUtil.getInt( 1 ) );
230 securityHeader.setName( daoUtil.getString( 2 ) );
231 securityHeader.setDescription( daoUtil.getString( 3 ) );
232 securityHeader.setValue( daoUtil.getString( 4 ) );
233 securityHeader.setType( daoUtil.getString( 5 ) );
234 securityHeader.setPageCategory(daoUtil.getString( 6 ) );
235 securityHeader.setActive( daoUtil.getBoolean( 7 ) );
236
237 securityHeadersList.add( securityHeader );
238 }
239 }
240
241 return securityHeadersList;
242 }
243 }