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.regularexpression.business;
35
36 import fr.paris.lutece.portal.business.regularexpression.RegularExpression;
37 import fr.paris.lutece.portal.service.plugin.Plugin;
38 import fr.paris.lutece.util.sql.DAOUtil;
39
40 import java.util.ArrayList;
41 import java.util.List;
42
43
44
45
46 public final class RegularExpressionDAO implements IRegularExpressionDAO
47 {
48
49 private static final String SQL_QUERY_NEW_PK = "SELECT max( id_expression ) FROM regularexpression_regular_expression";
50 private static final String SQL_QUERY_FIND_BY_PRIMARY_KEY = "SELECT id_expression,title,regular_expression_value,valid_exemple,information_message,error_message"
51 + " FROM regularexpression_regular_expression WHERE id_expression = ?";
52 private static final String SQL_QUERY_INSERT = "INSERT INTO regularexpression_regular_expression( id_expression,title,regular_expression_value,valid_exemple,information_message,error_message)"
53 + "VALUES(?,?,?,?,?,?)";
54 private static final String SQL_QUERY_DELETE = "DELETE FROM regularexpression_regular_expression WHERE id_expression = ? ";
55 private static final String SQL_QUERY_UPDATE = "UPDATE regularexpression_regular_expression SET "
56 + "id_expression=?,title=?,regular_expression_value=?,valid_exemple=?,information_message=?,error_message=? WHERE id_expression = ? ";
57 private static final String SQL_QUERY_SELECT = "SELECT id_expression,title,regular_expression_value,valid_exemple,information_message,error_message"
58 + " FROM regularexpression_regular_expression ";
59
60
61
62
63
64
65
66
67 public int newPrimaryKey( Plugin plugin )
68 {
69 int nKey = 1;
70 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_NEW_PK, plugin ) )
71 {
72 daoUtil.executeQuery( );
73 if ( daoUtil.next( ) )
74 {
75 nKey = daoUtil.getInt( 1 ) + 1;
76 }
77 }
78 return nKey;
79 }
80
81
82
83
84
85
86
87
88
89 public void insert( RegularExpression regularExpression, Plugin plugin )
90 {
91 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin ) )
92 {
93 regularExpression.setIdExpression( newPrimaryKey( plugin ) );
94 daoUtil.setInt( 1, regularExpression.getIdExpression( ) );
95 daoUtil.setString( 2, regularExpression.getTitle( ) );
96 daoUtil.setString( 3, regularExpression.getValue( ) );
97 daoUtil.setString( 4, regularExpression.getValidExemple( ) );
98 daoUtil.setString( 5, regularExpression.getInformationMessage( ) );
99 daoUtil.setString( 6, regularExpression.getErrorMessage( ) );
100 daoUtil.executeUpdate( );
101 }
102 }
103
104
105
106
107
108
109
110
111
112
113 public RegularExpression load( int nId, Plugin plugin )
114 {
115 RegularExpression regularExpression = null;
116 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_BY_PRIMARY_KEY, plugin ) )
117 {
118 daoUtil.setInt( 1, nId );
119 daoUtil.executeQuery( );
120
121 if ( daoUtil.next( ) )
122 {
123 regularExpression = new RegularExpression( );
124 regularExpression.setIdExpression( daoUtil.getInt( 1 ) );
125 regularExpression.setTitle( daoUtil.getString( 2 ) );
126 regularExpression.setValue( daoUtil.getString( 3 ) );
127 regularExpression.setValidExemple( daoUtil.getString( 4 ) );
128 regularExpression.setInformationMessage( daoUtil.getString( 5 ) );
129 regularExpression.setErrorMessage( daoUtil.getString( 6 ) );
130 }
131 }
132 return regularExpression;
133 }
134
135
136
137
138
139
140
141
142
143 public void delete( int nIdExpression, Plugin plugin )
144 {
145 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin ) )
146 {
147 daoUtil.setInt( 1, nIdExpression );
148 daoUtil.executeUpdate( );
149 }
150 }
151
152
153
154
155
156
157
158
159
160 public void store( RegularExpression regularExpression, Plugin plugin )
161 {
162 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin ) )
163 {
164 daoUtil.setInt( 1, regularExpression.getIdExpression( ) );
165 daoUtil.setString( 2, regularExpression.getTitle( ) );
166 daoUtil.setString( 3, regularExpression.getValue( ) );
167 daoUtil.setString( 4, regularExpression.getValidExemple( ) );
168 daoUtil.setString( 5, regularExpression.getInformationMessage( ) );
169 daoUtil.setString( 6, regularExpression.getErrorMessage( ) );
170 daoUtil.setInt( 7, regularExpression.getIdExpression( ) );
171 daoUtil.executeUpdate( );
172 }
173 }
174
175
176
177
178
179
180
181
182 public List<RegularExpression> selectListRegularExpression( Plugin plugin )
183 {
184 List<RegularExpression> regularExpressionList = new ArrayList<>( );
185 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT, plugin ) )
186 {
187 daoUtil.executeQuery( );
188
189 while ( daoUtil.next( ) )
190 {
191 RegularExpression regularExpression = new RegularExpression( );
192 regularExpression.setIdExpression( daoUtil.getInt( 1 ) );
193 regularExpression.setTitle( daoUtil.getString( 2 ) );
194 regularExpression.setValue( daoUtil.getString( 3 ) );
195 regularExpression.setValidExemple( daoUtil.getString( 4 ) );
196 regularExpression.setInformationMessage( daoUtil.getString( 5 ) );
197 regularExpression.setErrorMessage( daoUtil.getString( 6 ) );
198 regularExpressionList.add( regularExpression );
199 }
200 }
201 return regularExpressionList;
202 }
203 }