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