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.directories.business;
35
36 import fr.paris.lutece.portal.service.plugin.Plugin;
37 import fr.paris.lutece.util.ReferenceList;
38 import fr.paris.lutece.util.sql.DAOUtil;
39 import java.sql.Statement;
40 import java.util.ArrayList;
41 import java.util.List;
42
43
44
45
46 public final class DirectoryEntityDAO implements IDirectoryEntityDAO
47 {
48
49 private static final String SQL_QUERY_SELECT = "SELECT id_reference, id_directory, id_creator, date_creation, id_modificator, date_update, title FROM directories_directory_entity WHERE id_reference = ?";
50 private static final String SQL_QUERY_INSERT = "INSERT INTO directories_directory_entity ( id_directory, id_creator, date_creation, title ) VALUES ( ?, ?, ?, ? ) ";
51 private static final String SQL_QUERY_DELETE = "DELETE FROM directories_directory_entity WHERE id_reference = ? ";
52 private static final String SQL_QUERY_UPDATE = "UPDATE directories_directory_entity SET id_reference = ?, id_directory = ?, id_creator = ?, date_creation = ?,id_modificator = ?, date_update = ?, title = ? WHERE id_reference = ?";
53 private static final String SQL_QUERY_SELECTALL = "SELECT id_reference, id_directory, id_creator, date_creation, id_modificator, date_update, title FROM directories_directory_entity";
54 private static final String SQL_QUERY_SELECTALL_BY_DIRECTORY = "SELECT id_reference, id_directory, id_creator, date_creation, id_modificator, date_update, title FROM directories_directory_entity WHERE id_directory = ?";
55 private static final String SQL_QUERY_SELECTALL_ID = "SELECT id_reference FROM directories_directory_entity";
56
57
58
59
60 @Override
61 public void insert( DirectoryEntity directoryEntity, Plugin plugin )
62 {
63 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, Statement.RETURN_GENERATED_KEYS, plugin ) )
64 {
65 int nIndex = 1;
66 daoUtil.setInt( nIndex++, directoryEntity.getIdDirectory( ) );
67 daoUtil.setInt( nIndex++, directoryEntity.getIdCreator( ) );
68 daoUtil.setTimestamp( nIndex++, directoryEntity.getCreation( ) );
69 daoUtil.setString( nIndex++, directoryEntity.getTitle( ) );
70 daoUtil.executeUpdate( );
71 if ( daoUtil.nextGeneratedKey( ) )
72 {
73 directoryEntity.setId( daoUtil.getGeneratedKeyInt( 1 ) );
74 }
75 }
76 }
77
78
79
80
81 @Override
82 public DirectoryEntity load( int nKey, Plugin plugin )
83 {
84 DirectoryEntity directoryEntity = null;
85 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT, plugin ) )
86 {
87 daoUtil.setInt( 1, nKey );
88 daoUtil.executeQuery( );
89 if ( daoUtil.next( ) )
90 {
91 directoryEntity = new DirectoryEntity( );
92 int nIndex = 1;
93 directoryEntity.setId( daoUtil.getInt( nIndex++ ) );
94 directoryEntity.setIdDirectory( daoUtil.getInt( nIndex++ ) );
95 directoryEntity.setIdCreator( daoUtil.getInt( nIndex++ ) );
96 directoryEntity.setDateCreation( daoUtil.getTimestamp( nIndex++ ) );
97 directoryEntity.setIdModificator( daoUtil.getInt( nIndex++ ) );
98 directoryEntity.setUpdate( daoUtil.getTimestamp( nIndex++ ) );
99 directoryEntity.setTitle( daoUtil.getString( nIndex++ ) );
100 }
101 }
102 return directoryEntity;
103 }
104
105
106
107
108 @Override
109 public void delete( int nKey, Plugin plugin )
110 {
111 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin ) )
112 {
113 daoUtil.setInt( 1, nKey );
114 daoUtil.executeUpdate( );
115 }
116 }
117
118
119
120
121 @Override
122 public void store( DirectoryEntity directoryEntity, Plugin plugin )
123 {
124 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin ) )
125 {
126 int nIndex = 1;
127 daoUtil.setInt( nIndex++, directoryEntity.getId( ) );
128 daoUtil.setInt( nIndex++, directoryEntity.getIdDirectory( ) );
129 daoUtil.setInt( nIndex++, directoryEntity.getIdCreator( ) );
130 daoUtil.setTimestamp( nIndex++, directoryEntity.getCreation( ) );
131 daoUtil.setInt( nIndex++, directoryEntity.getIdModificator( ) );
132 daoUtil.setTimestamp( nIndex++, directoryEntity.getUpdate( ) );
133 daoUtil.setString( nIndex++, directoryEntity.getTitle( ) );
134 daoUtil.setInt( nIndex, directoryEntity.getId( ) );
135 daoUtil.executeUpdate( );
136 }
137 }
138
139
140
141
142 @Override
143 public List<DirectoryEntity> selectDirectoryEntitiesList( Plugin plugin )
144 {
145 List<DirectoryEntity> directoryEntityList = new ArrayList<>( );
146 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL, plugin ) )
147 {
148 daoUtil.executeQuery( );
149 while ( daoUtil.next( ) )
150 {
151 DirectoryEntityness/DirectoryEntity.html#DirectoryEntity">DirectoryEntity directoryEntity = new DirectoryEntity( );
152 int nIndex = 1;
153 directoryEntity.setId( daoUtil.getInt( nIndex++ ) );
154 directoryEntity.setIdDirectory( daoUtil.getInt( nIndex++ ) );
155 directoryEntity.setIdCreator( daoUtil.getInt( nIndex++ ) );
156 directoryEntity.setDateCreation( daoUtil.getTimestamp( nIndex++ ) );
157 directoryEntity.setIdModificator( daoUtil.getInt( nIndex++ ) );
158 directoryEntity.setUpdate( daoUtil.getTimestamp( nIndex++ ) );
159 directoryEntity.setTitle( daoUtil.getString( nIndex++ ) );
160 directoryEntityList.add( directoryEntity );
161 }
162 }
163 return directoryEntityList;
164 }
165
166
167
168
169 @Override
170 public List<Integer> selectIdDirectoryEntitiesList( Plugin plugin )
171 {
172 List<Integer> directoryEntityList = new ArrayList<>( );
173 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL_ID, plugin ) )
174 {
175 daoUtil.executeQuery( );
176 while ( daoUtil.next( ) )
177 {
178 directoryEntityList.add( daoUtil.getInt( 1 ) );
179 }
180 }
181 return directoryEntityList;
182 }
183
184
185
186
187 @Override
188 public ReferenceList selectDirectoryEntitiesReferenceList( Plugin plugin )
189 {
190 ReferenceList directoryEntityList = new ReferenceList( );
191 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL, plugin ) )
192 {
193 daoUtil.executeQuery( );
194 while ( daoUtil.next( ) )
195 {
196 directoryEntityList.addItem( daoUtil.getInt( 1 ), daoUtil.getString( 2 ) );
197 }
198 }
199 return directoryEntityList;
200 }
201
202
203
204
205 @Override
206 public List<DirectoryEntity> selectDirectoryEntitiesListByIdDirectory( int nKey, Plugin plugin )
207 {
208 List<DirectoryEntity> directoryEntityList = new ArrayList<>( );
209 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL_BY_DIRECTORY, plugin ) )
210 {
211 daoUtil.setInt( 1, nKey );
212 daoUtil.executeQuery( );
213 while ( daoUtil.next( ) )
214 {
215 DirectoryEntityness/DirectoryEntity.html#DirectoryEntity">DirectoryEntity directoryEntity = new DirectoryEntity( );
216 int nIndex = 1;
217 directoryEntity.setId( daoUtil.getInt( nIndex++ ) );
218 directoryEntity.setIdDirectory( daoUtil.getInt( nIndex++ ) );
219 directoryEntity.setIdCreator( daoUtil.getInt( nIndex++ ) );
220 directoryEntity.setDateCreation( daoUtil.getTimestamp( nIndex++ ) );
221 directoryEntity.setIdModificator( daoUtil.getInt( nIndex++ ) );
222 directoryEntity.setUpdate( daoUtil.getTimestamp( nIndex++ ) );
223 directoryEntity.setTitle( daoUtil.getString( nIndex++ ) );
224 directoryEntityList.add( directoryEntity );
225 }
226 }
227 return directoryEntityList;
228 }
229 }