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.portal.business.stylesheet.StyleSheet;
37 import fr.paris.lutece.util.ReferenceList;
38 import fr.paris.lutece.util.sql.DAOUtil;
39
40 import java.util.ArrayList;
41 import java.util.Collection;
42
43
44
45
46 public final class StyleDAO implements IStyleDAO
47 {
48
49 private static final String SQL_QUERY_SELECT = " SELECT DISTINCT a.id_portlet_type , a.id_portal_component, a.description_style , "
50 + " b.name, c.name , id_style FROM core_style a " + " INNER JOIN core_portal_component c ON a.id_portal_component = c.id_portal_component "
51 + " LEFT JOIN core_portlet_type b ON a.id_portlet_type = b.id_portlet_type WHERE a.id_style = ? ";
52 private static final String SQL_QUERY_INSERT = " INSERT INTO core_style ( id_style , id_portlet_type , id_portal_component, description_style ) "
53 + " VALUES ( ?, ?, ?, ? )";
54 private static final String SQL_QUERY_DELETE = " DELETE FROM core_style WHERE id_style = ? ";
55 private static final String SQL_QUERY_UPDATE = " UPDATE core_style SET id_portlet_type = ?, id_portal_component = ?, description_style = ? "
56 + " WHERE id_style = ?";
57 private static final String SQL_QUERY_SELECTALL = " SELECT a.id_style , a.id_portlet_type , a.id_portal_component, a.description_style , "
58 + " b.name, c.name FROM core_style a " + " INNER JOIN core_portal_component c ON a.id_portal_component = c.id_portal_component "
59 + " LEFT JOIN core_portlet_type b ON a.id_portlet_type = b.id_portlet_type " + " ORDER BY a.id_portal_component, a.id_style ";
60 private static final String SQL_QUERY_SELECT_STYLESHEET = " SELECT a.id_stylesheet, a.description, a.file_name "
61 + " FROM core_stylesheet a , core_style_mode_stylesheet b" + " WHERE b.id_stylesheet = a.id_stylesheet " + " AND b.id_style = ? ";
62 private static final String SQL_CHECK_STYLE_PORTLETCOMPONENT = " SELECT id_style FROM core_style WHERE id_portal_component = ? ";
63 private static final String SQL_QUERY_SELECT_PORTLETCOMPONENT = " SELECT id_portal_component , name FROM core_portal_component ORDER BY name ";
64
65
66
67
68
69
70
71
72
73
74 public void insert( Style style )
75 {
76 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT ) )
77 {
78
79 daoUtil.setInt( 1, style.getId( ) );
80 daoUtil.setString( 2, style.getPortletTypeId( ) );
81 daoUtil.setInt( 3, style.getPortalComponentId( ) );
82 daoUtil.setString( 4, style.getDescription( ) );
83
84 daoUtil.executeUpdate( );
85 }
86 }
87
88
89
90
91
92
93
94
95 public Style load( int nStyleId )
96 {
97 Style style = null;
98 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT ) )
99 {
100 daoUtil.setInt( 1, nStyleId );
101
102 daoUtil.executeQuery( );
103
104 if ( daoUtil.next( ) )
105 {
106 style = new Style( );
107 style.setId( nStyleId );
108 style.setPortletTypeId( daoUtil.getString( 1 ) );
109 style.setPortalComponentId( daoUtil.getInt( 2 ) );
110 style.setDescription( daoUtil.getString( 3 ) );
111 style.setPortletTypeName( daoUtil.getString( 4 ) );
112 style.setPortalComponentName( daoUtil.getString( 5 ) );
113 }
114
115 }
116
117 return style;
118 }
119
120
121
122
123
124
125
126 public void delete( int nStyleId )
127 {
128 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE ) )
129 {
130 daoUtil.setInt( 1, nStyleId );
131 daoUtil.executeUpdate( );
132 }
133 }
134
135
136
137
138
139
140
141 public void store( Style style )
142 {
143 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE ) )
144 {
145
146 daoUtil.setString( 1, style.getPortletTypeId( ) );
147 daoUtil.setInt( 2, style.getPortalComponentId( ) );
148 daoUtil.setString( 3, style.getDescription( ) );
149 daoUtil.setInt( 4, style.getId( ) );
150
151 daoUtil.executeUpdate( );
152 }
153 }
154
155
156
157
158
159
160 public Collection<Style> selectStylesList( )
161 {
162 Collection<Style> styleList = new ArrayList<>( );
163 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL ) )
164 {
165 daoUtil.executeQuery( );
166
167 while ( daoUtil.next( ) )
168 {
169 Styleal/business/style/Style.html#Style">Style style = new Style( );
170
171 style.setId( daoUtil.getInt( 1 ) );
172 style.setPortletTypeId( daoUtil.getString( 2 ) );
173 style.setPortalComponentId( daoUtil.getInt( 3 ) );
174 style.setDescription( daoUtil.getString( 4 ) );
175 style.setPortletTypeName( daoUtil.getString( 5 ) );
176 style.setPortalComponentName( daoUtil.getString( 6 ) );
177
178 styleList.add( style );
179 }
180
181 }
182
183 return styleList;
184 }
185
186
187
188
189
190
191 public ReferenceList selectPortalComponentList( )
192 {
193 ReferenceListerenceList">ReferenceList portletComponentList = new ReferenceList( );
194 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_PORTLETCOMPONENT ) )
195 {
196 daoUtil.executeQuery( );
197
198 while ( daoUtil.next( ) )
199 {
200 portletComponentList.addItem( daoUtil.getInt( 1 ), daoUtil.getString( 2 ) );
201 }
202
203 }
204
205 return portletComponentList;
206 }
207
208
209
210
211
212
213
214
215 public Collection<StyleSheet> selectStyleSheetList( int nStyleId )
216 {
217 Collection<StyleSheet> stylesheetList = new ArrayList<>( );
218 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_STYLESHEET ) )
219 {
220
221 daoUtil.setInt( 1, nStyleId );
222 daoUtil.executeQuery( );
223
224 while ( daoUtil.next( ) )
225 {
226 StyleSheets/stylesheet/StyleSheet.html#StyleSheet">StyleSheet stylesheet = new StyleSheet( );
227
228 stylesheet.setId( daoUtil.getInt( 1 ) );
229 stylesheet.setDescription( daoUtil.getString( 2 ) );
230 stylesheet.setFile( daoUtil.getString( 3 ) );
231
232 stylesheetList.add( stylesheet );
233 }
234
235 }
236
237 return stylesheetList;
238 }
239
240
241
242
243
244
245
246
247 public boolean checkStylePortalComponent( int nPortalComponentId )
248 {
249 boolean check = false;
250 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_CHECK_STYLE_PORTLETCOMPONENT ) )
251 {
252
253 daoUtil.setInt( 1, nPortalComponentId );
254 daoUtil.executeQuery( );
255
256 if ( daoUtil.next( ) )
257 {
258 check = true;
259 }
260
261 }
262
263 return check;
264 }
265 }