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 | |
|
35 | |
package fr.paris.lutece.plugins.releaser.business; |
36 | |
|
37 | |
import fr.paris.lutece.portal.service.plugin.Plugin; |
38 | |
import fr.paris.lutece.util.ReferenceList; |
39 | |
import fr.paris.lutece.util.sql.DAOUtil; |
40 | |
|
41 | |
import java.util.ArrayList; |
42 | |
import java.util.List; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | 1 | public final class ClusterDAO implements IClusterDAO |
48 | |
{ |
49 | |
|
50 | |
private static final String SQL_QUERY_NEW_PK = "SELECT max( id_cluster ) FROM releaser_cluster"; |
51 | |
private static final String SQL_QUERY_SELECT = "SELECT id_cluster, name, description FROM releaser_cluster WHERE id_cluster = ?"; |
52 | |
private static final String SQL_QUERY_INSERT = "INSERT INTO releaser_cluster ( id_cluster, name, description ) VALUES ( ?, ?, ? ) "; |
53 | |
private static final String SQL_QUERY_DELETE = "DELETE FROM releaser_cluster WHERE id_cluster = ? "; |
54 | |
private static final String SQL_QUERY_UPDATE = "UPDATE releaser_cluster SET id_cluster = ?, name = ?, description = ? WHERE id_cluster = ?"; |
55 | |
private static final String SQL_QUERY_SELECTALL = "SELECT id_cluster, name, description FROM releaser_cluster"; |
56 | |
private static final String SQL_QUERY_SELECTALL_ID = "SELECT id_cluster FROM releaser_cluster"; |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
public int newPrimaryKey( Plugin plugin ) |
66 | |
{ |
67 | 1 | DAOUtil daoUtil = new DAOUtil( SQL_QUERY_NEW_PK, plugin ); |
68 | 1 | daoUtil.executeQuery( ); |
69 | 1 | int nKey = 1; |
70 | |
|
71 | 1 | if ( daoUtil.next( ) ) |
72 | |
{ |
73 | 1 | nKey = daoUtil.getInt( 1 ) + 1; |
74 | |
} |
75 | |
|
76 | 1 | daoUtil.free( ); |
77 | 1 | return nKey; |
78 | |
} |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
@Override |
84 | |
public void insert( Cluster cluster, Plugin plugin ) |
85 | |
{ |
86 | 1 | DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin ); |
87 | 1 | cluster.setId( newPrimaryKey( plugin ) ); |
88 | 1 | int nIndex = 1; |
89 | |
|
90 | 1 | daoUtil.setInt( nIndex++, cluster.getId( ) ); |
91 | 1 | daoUtil.setString( nIndex++, cluster.getName( ) ); |
92 | 1 | daoUtil.setString( nIndex++, cluster.getDescription( ) ); |
93 | |
|
94 | 1 | daoUtil.executeUpdate( ); |
95 | 1 | daoUtil.free( ); |
96 | 1 | } |
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
@Override |
102 | |
public Cluster load( int nKey, Plugin plugin ) |
103 | |
{ |
104 | 3 | DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT, plugin ); |
105 | 3 | daoUtil.setInt( 1, nKey ); |
106 | 3 | daoUtil.executeQuery( ); |
107 | 3 | Cluster cluster = null; |
108 | |
|
109 | 3 | if ( daoUtil.next( ) ) |
110 | |
{ |
111 | 2 | cluster = new Cluster( ); |
112 | 2 | int nIndex = 1; |
113 | |
|
114 | 2 | cluster.setId( daoUtil.getInt( nIndex++ ) ); |
115 | 2 | cluster.setName( daoUtil.getString( nIndex++ ) ); |
116 | 2 | cluster.setDescription( daoUtil.getString( nIndex++ ) ); |
117 | |
} |
118 | |
|
119 | 3 | daoUtil.free( ); |
120 | 3 | return cluster; |
121 | |
} |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
@Override |
127 | |
public void delete( int nKey, Plugin plugin ) |
128 | |
{ |
129 | 1 | DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin ); |
130 | 1 | daoUtil.setInt( 1, nKey ); |
131 | 1 | daoUtil.executeUpdate( ); |
132 | 1 | daoUtil.free( ); |
133 | 1 | } |
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
@Override |
139 | |
public void store( Cluster cluster, Plugin plugin ) |
140 | |
{ |
141 | 1 | DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin ); |
142 | 1 | int nIndex = 1; |
143 | |
|
144 | 1 | daoUtil.setInt( nIndex++, cluster.getId( ) ); |
145 | 1 | daoUtil.setString( nIndex++, cluster.getName( ) ); |
146 | 1 | daoUtil.setString( nIndex++, cluster.getDescription( ) ); |
147 | 1 | daoUtil.setInt( nIndex, cluster.getId( ) ); |
148 | |
|
149 | 1 | daoUtil.executeUpdate( ); |
150 | 1 | daoUtil.free( ); |
151 | 1 | } |
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
@Override |
157 | |
public List<Cluster> selectClustersList( Plugin plugin ) |
158 | |
{ |
159 | 1 | List<Cluster> clusterList = new ArrayList<Cluster>( ); |
160 | 1 | DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL, plugin ); |
161 | 1 | daoUtil.executeQuery( ); |
162 | |
|
163 | 4 | while ( daoUtil.next( ) ) |
164 | |
{ |
165 | 3 | Cluster cluster = new Cluster( ); |
166 | 3 | int nIndex = 1; |
167 | |
|
168 | 3 | cluster.setId( daoUtil.getInt( nIndex++ ) ); |
169 | 3 | cluster.setName( daoUtil.getString( nIndex++ ) ); |
170 | 3 | cluster.setDescription( daoUtil.getString( nIndex++ ) ); |
171 | |
|
172 | 3 | clusterList.add( cluster ); |
173 | 3 | } |
174 | |
|
175 | 1 | daoUtil.free( ); |
176 | 1 | return clusterList; |
177 | |
} |
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
@Override |
183 | |
public List<Integer> selectIdClustersList( Plugin plugin ) |
184 | |
{ |
185 | 0 | List<Integer> clusterList = new ArrayList<Integer>( ); |
186 | 0 | DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL_ID, plugin ); |
187 | 0 | daoUtil.executeQuery( ); |
188 | |
|
189 | 0 | while ( daoUtil.next( ) ) |
190 | |
{ |
191 | 0 | clusterList.add( daoUtil.getInt( 1 ) ); |
192 | |
} |
193 | |
|
194 | 0 | daoUtil.free( ); |
195 | 0 | return clusterList; |
196 | |
} |
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
@Override |
202 | |
public ReferenceList selectClustersReferenceList( Plugin plugin ) |
203 | |
{ |
204 | 0 | ReferenceList clusterList = new ReferenceList( ); |
205 | 0 | DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL, plugin ); |
206 | 0 | daoUtil.executeQuery( ); |
207 | |
|
208 | 0 | while ( daoUtil.next( ) ) |
209 | |
{ |
210 | 0 | clusterList.addItem( daoUtil.getInt( 1 ), daoUtil.getString( 2 ) ); |
211 | |
} |
212 | |
|
213 | 0 | daoUtil.free( ); |
214 | 0 | return clusterList; |
215 | |
} |
216 | |
} |