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
47 public final class ThemeDAO implements IThemeDAO
48 {
49 private static final String SQL_QUERY_SELECT = " SELECT code_theme, theme_description, path_images, path_css, theme_author, " +
50 " theme_author_url, theme_version, theme_licence, path_js FROM core_theme WHERE code_theme = ?";
51 private static final String SQL_QUERY_INSERT = " INSERT INTO core_theme ( code_theme, theme_description, path_images, path_css," +
52 " theme_author, theme_author_url, theme_version, theme_licence, path_js ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ? )";
53 private static final String SQL_QUERY_DELETE = " DELETE FROM core_theme WHERE code_theme = ?";
54 private static final String SQL_QUERY_UPDATE = " UPDATE core_theme SET theme_description = ?, path_images = ?, " +
55 " path_css = ? , theme_author = ?, theme_author_url = ?, theme_version = ?, " +
56 " theme_licence = ?, path_js = ? WHERE code_theme = ?";
57 private static final String SQL_QUERY_SELECTALL = " SELECT code_theme, theme_description, path_images, path_css, theme_author, " +
58 " theme_author_url, theme_version, theme_licence, path_js FROM core_theme ORDER BY code_theme";
59 private static final String SQL_QUERY_SELECT_THEME = " SELECT code_theme, theme_description FROM core_theme";
60 private static final String SQL_QUERY_SELECT_GLOBAL_THEME = " SELECT global_theme_code FROM core_theme_global ";
61 private static final String SQL_QUERY_UPDATE_GLOBAL_THEME = " UPDATE core_theme_global SET global_theme_code = ? ";
62
63
64
65
66 public synchronized void insert( Theme theme )
67 {
68 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT );
69
70 daoUtil.setString( 1, theme.getCodeTheme( ) );
71 daoUtil.setString( 2, theme.getThemeDescription( ) );
72 daoUtil.setString( 3, theme.getPathImages( ) );
73 daoUtil.setString( 4, theme.getPathCss( ) );
74 daoUtil.setString( 5, theme.getThemeAuthor( ) );
75 daoUtil.setString( 6, theme.getThemeAuthorUrl( ) );
76 daoUtil.setString( 7, theme.getThemeVersion( ) );
77 daoUtil.setString( 8, theme.getThemeLicence( ) );
78 daoUtil.setString( 9, theme.getPathJs( ) );
79
80 daoUtil.executeUpdate( );
81 daoUtil.free( );
82 }
83
84
85
86
87 public Theme load( String strCodeTheme )
88 {
89 Theme theme = null;
90 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT );
91 daoUtil.setString( 1, strCodeTheme );
92
93 daoUtil.executeQuery( );
94
95 if ( daoUtil.next( ) )
96 {
97 theme = new Theme( );
98 theme.setCodeTheme( daoUtil.getString( 1 ) );
99 theme.setThemeDescription( daoUtil.getString( 2 ) );
100 theme.setPathImages( daoUtil.getString( 3 ) );
101 theme.setPathCss( daoUtil.getString( 4 ) );
102 theme.setThemeAuthor( daoUtil.getString( 5 ) );
103 theme.setThemeAuthorUrl( daoUtil.getString( 6 ) );
104 theme.setThemeVersion( daoUtil.getString( 7 ) );
105 theme.setThemeLicence( daoUtil.getString( 8 ) );
106 theme.setPathJs( daoUtil.getString( 9 ) );
107 }
108
109 daoUtil.free( );
110
111 return theme;
112 }
113
114
115
116
117 public void delete( String strCodeTheme )
118 {
119 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE );
120 daoUtil.setString( 1, strCodeTheme );
121 daoUtil.executeUpdate( );
122 daoUtil.free( );
123 }
124
125
126
127
128 public void store( Theme theme )
129 {
130 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE );
131
132 daoUtil.setString( 1, theme.getThemeDescription( ) );
133 daoUtil.setString( 2, theme.getPathImages( ) );
134 daoUtil.setString( 3, theme.getPathCss( ) );
135 daoUtil.setString( 4, theme.getThemeAuthor( ) );
136 daoUtil.setString( 5, theme.getThemeAuthorUrl( ) );
137 daoUtil.setString( 6, theme.getThemeVersion( ) );
138 daoUtil.setString( 7, theme.getThemeLicence( ) );
139 daoUtil.setString( 8, theme.getPathJs( ) );
140 daoUtil.setString( 9, theme.getCodeTheme( ) );
141
142 daoUtil.executeUpdate( );
143 daoUtil.free( );
144 }
145
146
147
148
149 public Collection<Theme> selectThemesList( )
150 {
151 Collection<Theme> themeList = new ArrayList<Theme>( );
152 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL );
153 daoUtil.executeQuery( );
154
155 while ( daoUtil.next( ) )
156 {
157 Theme theme = new Theme( );
158
159 theme.setCodeTheme( daoUtil.getString( 1 ) );
160 theme.setThemeDescription( daoUtil.getString( 2 ) );
161 theme.setPathImages( daoUtil.getString( 3 ) );
162 theme.setPathCss( daoUtil.getString( 4 ) );
163 theme.setThemeAuthor( daoUtil.getString( 5 ) );
164 theme.setThemeAuthorUrl( daoUtil.getString( 6 ) );
165 theme.setThemeVersion( daoUtil.getString( 7 ) );
166 theme.setThemeLicence( daoUtil.getString( 8 ) );
167 theme.setPathJs( daoUtil.getString( 9 ) );
168
169 themeList.add( theme );
170 }
171
172 daoUtil.free( );
173
174 return themeList;
175 }
176
177
178
179
180 public ReferenceList getThemesList( )
181 {
182 ReferenceList themesList = new ReferenceList( );
183 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_THEME );
184
185 daoUtil.executeQuery( );
186
187 while ( daoUtil.next( ) )
188 {
189 themesList.addItem( daoUtil.getString( 1 ), daoUtil.getString( 2 ) );
190 }
191
192 daoUtil.free( );
193
194 return themesList;
195 }
196
197
198
199
200 public void setGlobalTheme( String strGlobalTheme )
201 {
202 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE_GLOBAL_THEME );
203
204 daoUtil.setString( 1, strGlobalTheme );
205
206 daoUtil.executeUpdate( );
207 daoUtil.free( );
208 }
209
210
211
212
213 public String getGlobalTheme( )
214 {
215 String strGlobalTheme = null;
216 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_GLOBAL_THEME );
217
218 daoUtil.executeQuery( );
219
220 if ( daoUtil.next( ) )
221 {
222 strGlobalTheme = daoUtil.getString( 1 );
223 }
224
225 daoUtil.free( );
226
227 return strGlobalTheme;
228 }
229 }