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.profanityfilter.business;
35
36 import fr.paris.lutece.portal.service.plugin.Plugin;
37 import fr.paris.lutece.util.sql.DAOUtil;
38
39 import java.util.ArrayList;
40 import java.util.Collection;
41
42
43
44
45 public final class CounterDAO implements ICounterDAO
46 {
47
48 private static final String SQL_QUERY_NEW_PK = "SELECT max( id_counter ) FROM profanityfilter_counter";
49 private static final String SQL_QUERY_SELECT = "SELECT id_counter, resouece_type, counter FROM profanityfilter_counter WHERE resouece_type = ?";
50 private static final String SQL_QUERY_INSERT = "INSERT INTO profanityfilter_counter ( id_counter, resouece_type, counter ) VALUES ( ?, ?, ? ) ";
51 private static final String SQL_QUERY_DELETE = "DELETE FROM profanityfilter_counter WHERE id_counter = ? ";
52 private static final String SQL_QUERY_UPDATE = "UPDATE profanityfilter_counter SET id_counter = ?, resouece_type = ?, counter = ? WHERE resouece_type = ?";
53 private static final String SQL_QUERY_SELECTALL = "SELECT id_counter, resouece_type, counter FROM profanityfilter_counter";
54 private static final String SQL_QUERY_SELECTALL_ID = "SELECT id_counter FROM profanityfilter_counter";
55
56
57
58
59
60
61
62
63 public int newPrimaryKey( Plugin plugin )
64 {
65 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_NEW_PK, plugin );
66 daoUtil.executeQuery( );
67
68 int nKey = 1;
69
70 if ( daoUtil.next( ) )
71 {
72 nKey = daoUtil.getInt( 1 ) + 1;
73 }
74
75 daoUtil.free( );
76
77 return nKey;
78 }
79
80
81
82
83 @Override
84 public void insert( Counter counter, Plugin plugin )
85 {
86 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin );
87
88 counter.setId( newPrimaryKey( plugin ) );
89
90 daoUtil.setInt( 1, counter.getId( ) );
91 daoUtil.setString( 2, counter.getResourceType( ) );
92 daoUtil.setInt( 3, counter.getCounter( ) );
93
94 daoUtil.executeUpdate( );
95 daoUtil.free( );
96 }
97
98
99
100
101 @Override
102 public Counter load( String strResourceType, Plugin plugin )
103 {
104 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT, plugin );
105 daoUtil.setString( 1, strResourceType );
106 daoUtil.executeQuery( );
107
108 Counter counter = null;
109
110 if ( daoUtil.next( ) )
111 {
112 counter = new Counter( );
113 counter.setId( daoUtil.getInt( 1 ) );
114 counter.setResourceType( daoUtil.getString( 2 ) );
115 counter.setCounter( daoUtil.getInt( 3 ) );
116 }
117
118 daoUtil.free( );
119
120 return counter;
121 }
122
123
124
125
126 @Override
127 public void delete( int nKey, Plugin plugin )
128 {
129 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin );
130 daoUtil.setInt( 1, nKey );
131 daoUtil.executeUpdate( );
132 daoUtil.free( );
133 }
134
135
136
137
138 @Override
139 public void store( Counter counter, Plugin plugin )
140 {
141 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin );
142
143 daoUtil.setInt( 1, counter.getId( ) );
144 daoUtil.setString( 2, counter.getResourceType( ) );
145 daoUtil.setInt( 3, counter.getCounter( ) );
146
147 daoUtil.setString( 4, counter.getResourceType( ) );
148
149 daoUtil.executeUpdate( );
150 daoUtil.free( );
151 }
152
153
154
155
156 @Override
157 public Collection<Counter> selectCounterList( Plugin plugin )
158 {
159 Collection<Counter> counterList = new ArrayList<Counter>( );
160 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL, plugin );
161 daoUtil.executeQuery( );
162
163 while ( daoUtil.next( ) )
164 {
165 Counterprofanityfilter/business/Counter.html#Counter">Counter counter = new Counter( );
166 counter.setId( daoUtil.getInt( 1 ) );
167 counter.setResourceType( daoUtil.getString( 2 ) );
168 counter.setCounter( daoUtil.getInt( 3 ) );
169
170 counterList.add( counter );
171 }
172
173 daoUtil.free( );
174
175 return counterList;
176 }
177
178
179
180
181 @Override
182 public Collection<Integer> selectIdCounterList( Plugin plugin )
183 {
184 Collection<Integer> counterList = new ArrayList<Integer>( );
185 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL_ID, plugin );
186 daoUtil.executeQuery( );
187
188 while ( daoUtil.next( ) )
189 {
190 counterList.add( daoUtil.getInt( 1 ) );
191 }
192
193 daoUtil.free( );
194
195 return counterList;
196 }
197 }