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