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.document.business.attributes;
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 import java.util.List;
42 import java.util.Locale;
43
44
45
46
47 public final class AttributeTypeDAO implements IAttributeTypeDAO
48 {
49
50 private static final String SQL_QUERY_SELECT = " SELECT code_attr_type, name_key, description_key, manager_class FROM document_attr_type WHERE code_attr_type = ? ";
51 private static final String SQL_QUERY_INSERT = " INSERT INTO document_attr_type ( code_attr_type, name_key, description_key, manager_class ) VALUES ( ?, ?, ?, ? ) ";
52 private static final String SQL_QUERY_DELETE = " DELETE FROM document_attr_type WHERE code_attr_type = ? ";
53 private static final String SQL_QUERY_UPDATE = " UPDATE document_attr_type SET code_attr_type = ?, name_key = ?, description_key = ?, manager_class = ? WHERE code_attr_type = ? ";
54 private static final String SQL_QUERY_SELECTALL = " SELECT code_attr_type, name_key, description_key , manager_class FROM document_attr_type ";
55 private static final String SQL_QUERY_SELECT_MANAGERS = "SELECT code_attr_type , manager_class FROM document_attr_type";
56 private static final String SQL_QUERY_SELECT_PARAMETERS = "SELECT parameter_name, parameter_label_key, parameter_description_key, parameter_default_value FROM document_attr_type_parameter WHERE code_attr_type = ? ORDER BY parameter_index";
57
58
59
60
61
62
63
64 public void insert( AttributeType documentAttributeType )
65 {
66 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT ) )
67 {
68 daoUtil.setString( 1, documentAttributeType.getCode( ) );
69 daoUtil.setString( 2, documentAttributeType.getNameKey( ) );
70 daoUtil.setString( 3, documentAttributeType.getDescriptionKey( ) );
71 daoUtil.setString( 4, documentAttributeType.getClassName( ) );
72
73 daoUtil.executeUpdate( );
74 }
75 }
76
77
78
79
80
81
82
83
84 public AttributeType load( int nDocumentAttributeTypeId )
85 {
86 AttributeType documentAttributeType = null;
87 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT ) )
88 {
89 daoUtil.setInt( 1, nDocumentAttributeTypeId );
90 daoUtil.executeQuery( );
91
92 if ( daoUtil.next( ) )
93 {
94 documentAttributeType = new AttributeType( );
95 documentAttributeType.setCode( daoUtil.getString( 1 ) );
96 documentAttributeType.setNameKey( daoUtil.getString( 2 ) );
97 documentAttributeType.setDescriptionKey( daoUtil.getString( 3 ) );
98 documentAttributeType.setClassName( daoUtil.getString( 4 ) );
99 }
100 }
101 return documentAttributeType;
102 }
103
104
105
106
107
108
109
110 public void delete( AttributeType documentAttributeType )
111 {
112 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE ) )
113 {
114 daoUtil.setString( 1, documentAttributeType.getCode( ) );
115
116 daoUtil.executeUpdate( );
117 }
118 }
119
120
121
122
123
124
125
126 public void store( AttributeType documentAttributeType )
127 {
128 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE ) )
129 {
130 daoUtil.setString( 1, documentAttributeType.getCode( ) );
131 daoUtil.setString( 2, documentAttributeType.getNameKey( ) );
132 daoUtil.setString( 3, documentAttributeType.getDescriptionKey( ) );
133 daoUtil.setString( 4, documentAttributeType.getClassName( ) );
134 daoUtil.setString( 5, documentAttributeType.getCode( ) );
135
136 daoUtil.executeUpdate( );
137 }
138 }
139
140
141
142
143
144
145 public Collection<AttributeType> selectDocumentAttributeTypeList( )
146 {
147 Collection<AttributeType> listDocumentAttributeTypes = new ArrayList<>( );
148 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL ) )
149 {
150 daoUtil.executeQuery( );
151
152 while ( daoUtil.next( ) )
153 {
154 AttributeType/attributes/AttributeType.html#AttributeType">AttributeType documentAttributeType = new AttributeType( );
155 documentAttributeType.setCode( daoUtil.getString( 1 ) );
156 documentAttributeType.setNameKey( daoUtil.getString( 2 ) );
157 documentAttributeType.setDescriptionKey( daoUtil.getString( 3 ) );
158 documentAttributeType.setClassName( daoUtil.getString( 4 ) );
159
160 listDocumentAttributeTypes.add( documentAttributeType );
161 }
162 }
163 return listDocumentAttributeTypes;
164 }
165
166
167
168
169
170
171
172
173 public ReferenceList selectAttributeTypeList( Locale locale )
174 {
175 ReferenceList listAttributeTypes = new ReferenceList( );
176 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL ) )
177 {
178 daoUtil.executeQuery( );
179
180 while ( daoUtil.next( ) )
181 {
182 AttributeType/attributes/AttributeType.html#AttributeType">AttributeType documentAttributeType = new AttributeType( );
183 documentAttributeType.setLocale( locale );
184 documentAttributeType.setCode( daoUtil.getString( 1 ) );
185 documentAttributeType.setNameKey( daoUtil.getString( 2 ) );
186 listAttributeTypes.addItem( documentAttributeType.getCode( ), documentAttributeType.getName( ) );
187 }
188 }
189 return listAttributeTypes;
190 }
191
192
193
194
195
196
197
198
199
200 public ReferenceList getAttributeManagersList( )
201 {
202 ReferenceList listAttributeManagers = new ReferenceList( );
203 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_MANAGERS ) )
204 {
205 daoUtil.executeQuery( );
206
207 while ( daoUtil.next( ) )
208 {
209 listAttributeManagers.addItem( daoUtil.getString( 1 ), daoUtil.getString( 2 ) );
210 }
211 }
212 return listAttributeManagers;
213 }
214
215
216
217
218
219
220
221
222
223
224
225 public List<AttributeTypeParameter> selectAttributeTypeParameterList( String strAttributeTypeCode )
226 {
227 List<AttributeTypeParameter> listAttributeTypeParameters = new ArrayList<>( );
228 List<String> listDefaultValue = new ArrayList<>( );
229 String strDefaultValue;
230 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_PARAMETERS ) )
231 {
232 daoUtil.setString( 1, strAttributeTypeCode );
233 daoUtil.executeQuery( );
234
235 while ( daoUtil.next( ) )
236 {
237 AttributeTypeParameters/AttributeTypeParameter.html#AttributeTypeParameter">AttributeTypeParameter attributeTypeParameter = new AttributeTypeParameter( );
238 attributeTypeParameter.setName( daoUtil.getString( 1 ) );
239 attributeTypeParameter.setLabelKey( daoUtil.getString( 2 ) );
240 attributeTypeParameter.setDescriptionKey( daoUtil.getString( 3 ) );
241 strDefaultValue = daoUtil.getString( 4 );
242
243 if ( !strDefaultValue.equals( "" ) )
244 {
245 listDefaultValue.add( strDefaultValue );
246 }
247
248 attributeTypeParameter.setDefaultValue( listDefaultValue );
249 listDefaultValue.clear( );
250
251 listAttributeTypeParameters.add( attributeTypeParameter );
252 }
253 }
254 return listAttributeTypeParameters;
255 }
256 }