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.datastore;
35
36 import fr.paris.lutece.util.sql.DAOUtil;
37
38 import java.util.ArrayList;
39 import java.util.List;
40
41
42
43
44
45 public final class DataEntityDAO implements IDataEntityDAO
46 {
47
48 private static final String SQL_QUERY_SELECT = "SELECT entity_key, entity_value FROM core_datastore WHERE entity_key = ?";
49 private static final String SQL_QUERY_INSERT = "INSERT INTO core_datastore ( entity_key, entity_value ) VALUES ( ?, ? ) ";
50 private static final String SQL_QUERY_DELETE = "DELETE FROM core_datastore WHERE entity_key = ? ";
51 private static final String SQL_QUERY_UPDATE = "UPDATE core_datastore SET entity_value = ? WHERE entity_key = ?";
52 private static final String SQL_QUERY_SELECTALL = "SELECT entity_key, entity_value FROM core_datastore";
53
54
55
56
57
58 @Override
59 public void insert( DataEntity entity )
60 {
61 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT );
62
63 daoUtil.setString( 1, entity.getKey( ) );
64 daoUtil.setString( 2, entity.getValue( ) );
65
66 daoUtil.executeUpdate( );
67 daoUtil.free( );
68 }
69
70
71
72
73
74
75 @Override
76 public DataEntity load( String strKey )
77 {
78 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT );
79 daoUtil.setString( 1, strKey );
80 daoUtil.executeQuery( );
81
82 DataEntity entity = null;
83
84 if ( daoUtil.next( ) )
85 {
86 entity = new DataEntity( );
87
88 entity.setKey( daoUtil.getString( 1 ) );
89 entity.setValue( daoUtil.getString( 2 ) );
90 }
91
92 daoUtil.free( );
93
94 return entity;
95 }
96
97
98
99
100
101 @Override
102 public void delete( String strKey )
103 {
104 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE );
105 daoUtil.setString( 1, strKey );
106 daoUtil.executeUpdate( );
107 daoUtil.free( );
108 }
109
110
111
112
113
114 @Override
115 public void store( DataEntity entity )
116 {
117 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE );
118
119 daoUtil.setString( 1, entity.getValue( ) );
120 daoUtil.setString( 2, entity.getKey( ) );
121
122 daoUtil.executeUpdate( );
123 daoUtil.free( );
124 }
125
126
127
128
129
130 @Override
131 public List<DataEntity> selectEntitiesList( )
132 {
133 List<DataEntity> entityList = new ArrayList<DataEntity>( );
134 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL );
135 daoUtil.executeQuery( );
136
137 while ( daoUtil.next( ) )
138 {
139 DataEntity entity = new DataEntity( );
140
141 entity.setKey( daoUtil.getString( 1 ) );
142 entity.setValue( daoUtil.getString( 2 ) );
143
144 entityList.add( entity );
145 }
146
147 daoUtil.free( );
148
149 return entityList;
150 }
151 }