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