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.style;
35
36 import fr.paris.lutece.util.ReferenceList;
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 ModeDAO implements IModeDAO
46 {
47
48 private static final String SQL_QUERY_NEW_PK = " SELECT max( id_mode ) FROM core_mode";
49 private static final String SQL_QUERY_SELECT = " SELECT id_mode, description_mode, path, output_xsl_method, output_xsl_version, "
50 + " output_xsl_media_type, output_xsl_encoding, output_xsl_indent, output_xsl_omit_xml_dec, "
51 + " output_xsl_standalone FROM core_mode WHERE id_mode = ?";
52 private static final String SQL_QUERY_INSERT = " INSERT INTO core_mode ( id_mode, description_mode, path, output_xsl_method, output_xsl_version, output_xsl_media_type, output_xsl_encoding, output_xsl_indent, output_xsl_omit_xml_dec, output_xsl_standalone ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
53 private static final String SQL_QUERY_DELETE = " DELETE FROM core_mode WHERE id_mode = ?";
54 private static final String SQL_QUERY_UPDATE = " UPDATE core_mode SET description_mode = ?, path = ?, "
55 + " output_xsl_method = ? , output_xsl_version = ?, output_xsl_media_type = ?, output_xsl_encoding = ?, "
56 + " output_xsl_indent = ?, output_xsl_omit_xml_dec = ?, output_xsl_standalone = ?" + " WHERE id_mode = ?";
57 private static final String SQL_QUERY_SELECTALL = " SELECT id_mode, description_mode, path, output_xsl_method, output_xsl_version, output_xsl_media_type, "
58 + " output_xsl_encoding, output_xsl_indent, output_xsl_omit_xml_dec, output_xsl_standalone " + " FROM core_mode ORDER BY id_mode";
59 private static final String SQL_QUERY_SELECT_MODES = " SELECT id_mode , description_mode FROM core_mode";
60
61
62
63
64
65
66
67
68
69 int newPrimaryKey( )
70 {
71 int nKey;
72 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_NEW_PK ) )
73 {
74 daoUtil.executeQuery( );
75
76 if ( !daoUtil.next( ) )
77 {
78
79 nKey = 1;
80 }
81
82 nKey = daoUtil.getInt( 1 ) + 1;
83
84 }
85
86 return nKey;
87 }
88
89
90
91
92
93
94
95 public synchronized void insert( Mode mode )
96 {
97 mode.setId( newPrimaryKey( ) );
98
99 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT ) )
100 {
101
102 daoUtil.setInt( 1, mode.getId( ) );
103 daoUtil.setString( 2, mode.getDescription( ) );
104 daoUtil.setString( 3, mode.getPath( ) );
105 daoUtil.setString( 4, mode.getOutputXslPropertyMethod( ) );
106 daoUtil.setString( 5, mode.getOutputXslPropertyVersion( ) );
107 daoUtil.setString( 6, mode.getOutputXslPropertyMediaType( ) );
108 daoUtil.setString( 7, mode.getOutputXslPropertyEncoding( ) );
109 daoUtil.setString( 8, mode.getOutputXslPropertyIndent( ) );
110 daoUtil.setString( 9, mode.getOutputXslPropertyOmitXmlDeclaration( ) );
111 daoUtil.setString( 10, mode.getOutputXslPropertyStandalone( ) );
112
113 daoUtil.executeUpdate( );
114 }
115 }
116
117
118
119
120
121
122
123
124 public Mode load( int nIdMode )
125 {
126 Mode mode = null;
127 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT ) )
128 {
129 daoUtil.setInt( 1, nIdMode );
130
131 daoUtil.executeQuery( );
132
133 if ( daoUtil.next( ) )
134 {
135 mode = new Mode( );
136 mode.setId( daoUtil.getInt( 1 ) );
137 mode.setDescription( daoUtil.getString( 2 ) );
138 mode.setPath( daoUtil.getString( 3 ) );
139 mode.setOutputXslPropertyMethod( daoUtil.getString( 4 ) );
140 mode.setOutputXslPropertyVersion( daoUtil.getString( 5 ) );
141 mode.setOutputXslPropertyMediaType( daoUtil.getString( 6 ) );
142 mode.setOutputXslPropertyEncoding( daoUtil.getString( 7 ) );
143 mode.setOutputXslPropertyIndent( daoUtil.getString( 8 ) );
144 mode.setOutputXslPropertyOmitXmlDeclaration( daoUtil.getString( 9 ) );
145 mode.setOutputXslPropertyStandalone( daoUtil.getString( 10 ) );
146 }
147
148 }
149
150 return mode;
151 }
152
153
154
155
156
157
158
159 public void delete( int nModeId )
160 {
161 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE ) )
162 {
163 daoUtil.setInt( 1, nModeId );
164 daoUtil.executeUpdate( );
165 }
166 }
167
168
169
170
171
172
173
174 public void store( Mode mode )
175 {
176 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE ) )
177 {
178
179 daoUtil.setString( 1, mode.getDescription( ) );
180 daoUtil.setString( 2, mode.getPath( ) );
181 daoUtil.setString( 3, mode.getOutputXslPropertyMethod( ) );
182 daoUtil.setString( 4, mode.getOutputXslPropertyVersion( ) );
183 daoUtil.setString( 5, mode.getOutputXslPropertyMediaType( ) );
184 daoUtil.setString( 6, mode.getOutputXslPropertyEncoding( ) );
185 daoUtil.setString( 7, mode.getOutputXslPropertyIndent( ) );
186 daoUtil.setString( 8, mode.getOutputXslPropertyOmitXmlDeclaration( ) );
187 daoUtil.setString( 9, mode.getOutputXslPropertyStandalone( ) );
188 daoUtil.setInt( 10, mode.getId( ) );
189
190 daoUtil.executeUpdate( );
191 }
192 }
193
194
195
196
197
198
199 public Collection<Mode> selectModesList( )
200 {
201 Collection<Mode> modeList = new ArrayList<>( );
202 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL ) )
203 {
204 daoUtil.executeQuery( );
205
206 while ( daoUtil.next( ) )
207 {
208 Modertal/business/style/Mode.html#Mode">Mode mode = new Mode( );
209
210 mode.setId( daoUtil.getInt( 1 ) );
211 mode.setDescription( daoUtil.getString( 2 ) );
212 mode.setPath( daoUtil.getString( 3 ) );
213 mode.setOutputXslPropertyMethod( daoUtil.getString( 4 ) );
214 mode.setOutputXslPropertyVersion( daoUtil.getString( 5 ) );
215 mode.setOutputXslPropertyMediaType( daoUtil.getString( 6 ) );
216 mode.setOutputXslPropertyEncoding( daoUtil.getString( 7 ) );
217 mode.setOutputXslPropertyIndent( daoUtil.getString( 8 ) );
218 mode.setOutputXslPropertyOmitXmlDeclaration( daoUtil.getString( 9 ) );
219 mode.setOutputXslPropertyStandalone( daoUtil.getString( 10 ) );
220
221 modeList.add( mode );
222 }
223
224 }
225
226 return modeList;
227 }
228
229
230
231
232
233
234 public ReferenceList getModesList( )
235 {
236 ReferenceListst.html#ReferenceList">ReferenceList modesList = new ReferenceList( );
237 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_MODES ) )
238 {
239
240 daoUtil.executeQuery( );
241
242 while ( daoUtil.next( ) )
243 {
244 modesList.addItem( daoUtil.getInt( 1 ), daoUtil.getString( 2 ) );
245 }
246
247 }
248
249 return modesList;
250 }
251 }