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.plugins.appstore.business;
35
36 import fr.paris.lutece.portal.service.plugin.Plugin;
37 import fr.paris.lutece.util.sql.DAOUtil;
38
39 import java.util.ArrayList;
40 import java.util.Collection;
41 import java.util.List;
42
43
44
45
46 public final class ComponentDAO implements IComponentDAO
47 {
48
49 private static final String SQL_QUERY_NEW_PK = "SELECT max( id_component ) FROM appstore_component";
50 private static final String SQL_QUERY_SELECT = "SELECT id_component, group_id, title, description, artifact_id, version, component_type FROM appstore_component WHERE id_component = ?";
51 private static final String SQL_QUERY_INSERT = "INSERT INTO appstore_component ( id_component, group_id, title, description, artifact_id, version, component_type ) VALUES ( ?, ?, ?, ?, ?, ?, ? ) ";
52 private static final String SQL_QUERY_DELETE = "DELETE FROM appstore_component WHERE id_component = ? ";
53 private static final String SQL_QUERY_UPDATE = "UPDATE appstore_component SET id_component = ?, group_id = ?, title = ?, description = ?, artifact_id = ?, version = ?, component_type = ? WHERE id_component = ?";
54 private static final String SQL_QUERY_SELECTALL = "SELECT id_component, group_id, title, description, artifact_id, version, component_type FROM appstore_component";
55 private static final String SQL_QUERY_SELECT_BY_APPLICATION = "SELECT a.id_component, a.group_id, a.title, a.description, a.artifact_id, a.version, a.component_type "
56 + " FROM appstore_component a , appstore_application_component b WHERE a.id_component = b.id_component AND b.id_application = ?";
57 private static final String SQL_QUERY_DELETE_APPLICATION = "DELETE FROM appstore_application_component WHERE id_component = ? ";
58
59
60
61
62
63
64
65
66 public int newPrimaryKey( Plugin plugin )
67 {
68 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_NEW_PK, plugin );
69 daoUtil.executeQuery( );
70
71 int nKey;
72
73 daoUtil.next( );
74
75 nKey = daoUtil.getInt( 1 ) + 1;
76 daoUtil.free( );
77
78 return nKey;
79 }
80
81
82
83
84
85
86
87
88
89 @Override
90 public void insert( Component component, Plugin plugin )
91 {
92 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin );
93
94 component.setId( newPrimaryKey( plugin ) );
95
96 daoUtil.setInt( 1, component.getId( ) );
97 daoUtil.setString( 2, component.getGroupId( ) );
98 daoUtil.setString( 3, component.getTitle( ) );
99 daoUtil.setString( 4, component.getDescription( ) );
100 daoUtil.setString( 5, component.getArtifactId( ) );
101 daoUtil.setString( 6, component.getVersion( ) );
102 daoUtil.setString( 7, component.getComponentType( ) );
103
104 daoUtil.executeUpdate( );
105 daoUtil.free( );
106 }
107
108
109
110
111
112
113
114
115
116
117 @Override
118 public Component load( int nId, Plugin plugin )
119 {
120 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT, plugin );
121 daoUtil.setInt( 1, nId );
122 daoUtil.executeQuery( );
123
124 Component component = null;
125
126 if ( daoUtil.next( ) )
127 {
128 component = new Component( );
129
130 component.setId( daoUtil.getInt( 1 ) );
131 component.setGroupId( daoUtil.getString( 2 ) );
132 component.setTitle( daoUtil.getString( 3 ) );
133 component.setDescription( daoUtil.getString( 4 ) );
134 component.setArtifactId( daoUtil.getString( 5 ) );
135 component.setVersion( daoUtil.getString( 6 ) );
136 component.setComponentType( daoUtil.getString( 7 ) );
137 }
138
139 daoUtil.free( );
140
141 return component;
142 }
143
144
145
146
147
148
149
150
151
152 @Override
153 public void delete( int nComponentId, Plugin plugin )
154 {
155 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE_APPLICATION, plugin );
156 daoUtil.setInt( 1, nComponentId );
157 daoUtil.executeUpdate( );
158 daoUtil.free( );
159
160 daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin );
161 daoUtil.setInt( 1, nComponentId );
162 daoUtil.executeUpdate( );
163 daoUtil.free( );
164 }
165
166
167
168
169
170
171
172
173
174 @Override
175 public void store( Component component, Plugin plugin )
176 {
177 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin );
178
179 daoUtil.setInt( 1, component.getId( ) );
180 daoUtil.setString( 2, component.getGroupId( ) );
181 daoUtil.setString( 3, component.getTitle( ) );
182 daoUtil.setString( 4, component.getDescription( ) );
183 daoUtil.setString( 5, component.getArtifactId( ) );
184 daoUtil.setString( 6, component.getVersion( ) );
185 daoUtil.setString( 7, component.getComponentType( ) );
186 daoUtil.setInt( 8, component.getId( ) );
187
188 daoUtil.executeUpdate( );
189 daoUtil.free( );
190 }
191
192
193
194
195
196
197
198
199 @Override
200 public Collection<Component> selectComponentsList( Plugin plugin )
201 {
202 Collection<Component> componentList = new ArrayList<Component>( );
203 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL, plugin );
204 daoUtil.executeQuery( );
205
206 while ( daoUtil.next( ) )
207 {
208 Component component = new Component( );
209
210 component.setId( daoUtil.getInt( 1 ) );
211 component.setGroupId( daoUtil.getString( 2 ) );
212 component.setTitle( daoUtil.getString( 3 ) );
213 component.setDescription( daoUtil.getString( 4 ) );
214 component.setArtifactId( daoUtil.getString( 5 ) );
215 component.setVersion( daoUtil.getString( 6 ) );
216 component.setComponentType( daoUtil.getString( 7 ) );
217
218 componentList.add( component );
219 }
220
221 daoUtil.free( );
222
223 return componentList;
224 }
225
226 @Override
227 public List<Component> selectByApplication( int nApplicationId, Plugin plugin )
228 {
229 List<Component> componentList = new ArrayList<Component>( );
230 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_BY_APPLICATION, plugin );
231 daoUtil.setInt( 1, nApplicationId );
232 daoUtil.executeQuery( );
233
234 while ( daoUtil.next( ) )
235 {
236 Component component = new Component( );
237
238 component.setId( daoUtil.getInt( 1 ) );
239 component.setGroupId( daoUtil.getString( 2 ) );
240 component.setTitle( daoUtil.getString( 3 ) );
241 component.setDescription( daoUtil.getString( 4 ) );
242 component.setArtifactId( daoUtil.getString( 5 ) );
243 component.setVersion( daoUtil.getString( 6 ) );
244 component.setComponentType( daoUtil.getString( 7 ) );
245
246 componentList.add( component );
247 }
248
249 daoUtil.free( );
250
251 return componentList;
252 }
253 }