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.directory.business;
35
36 import fr.paris.lutece.plugins.directory.utils.DirectoryUtils;
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 IndexerActionDAO implements IIndexerActionDAO
47 {
48
49 private static final String SQL_QUERY_NEW_PK = "SELECT max( id_action ) FROM directory_indexer_action";
50 private static final String SQL_QUERY_FIND_BY_PRIMARY_KEY = "SELECT id_action,id_record,id_task" + " FROM directory_indexer_action WHERE id_action = ?";
51 private static final String SQL_QUERY_INSERT = "INSERT INTO directory_indexer_action( id_action,id_record,id_task)" + " VALUES(?,?,?)";
52 private static final String SQL_QUERY_DELETE = "DELETE FROM directory_indexer_action WHERE id_action = ? ";
53 private static final String SQL_QUERY_UPDATE = "UPDATE directory_indexer_action SET id_action=?,id_record=?,id_task=? WHERE id_action = ? ";
54 private static final String SQL_QUERY_SELECT = "SELECT id_action,id_record,id_task" + " FROM directory_indexer_action ";
55 private static final String SQL_FILTER_ID_TASK = " id_task = ? ";
56
57
58
59
60 @Override
61 public int newPrimaryKey( Plugin plugin )
62 {
63 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_NEW_PK, plugin );
64 daoUtil.executeQuery( );
65
66 int nKey;
67
68 if ( !daoUtil.next( ) )
69 {
70
71 nKey = 1;
72 }
73
74 nKey = daoUtil.getInt( 1 ) + 1;
75 daoUtil.free( );
76
77 return nKey;
78 }
79
80
81
82
83 @Override
84 public synchronized void insert( IndexerAction indexerAction, Plugin plugin )
85 {
86 indexerAction.setIdAction( newPrimaryKey( plugin ) );
87
88 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin );
89 daoUtil.setInt( 1, indexerAction.getIdAction( ) );
90 daoUtil.setInt( 2, indexerAction.getIdRecord( ) );
91 daoUtil.setInt( 3, indexerAction.getIdTask( ) );
92
93 daoUtil.executeUpdate( );
94
95 daoUtil.free( );
96 }
97
98
99
100
101 @Override
102 public IndexerAction load( int nId, Plugin plugin )
103 {
104 IndexerAction indexerAction = null;
105
106 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_BY_PRIMARY_KEY, plugin );
107 daoUtil.setInt( 1, nId );
108 daoUtil.executeQuery( );
109
110 if ( daoUtil.next( ) )
111 {
112 indexerAction = new IndexerAction( );
113 indexerAction.setIdAction( daoUtil.getInt( 1 ) );
114 indexerAction.setIdRecord( daoUtil.getInt( 2 ) );
115 indexerAction.setIdTask( daoUtil.getInt( 3 ) );
116 }
117
118 daoUtil.free( );
119
120 return indexerAction;
121 }
122
123
124
125
126 @Override
127 public void delete( int nId, Plugin plugin )
128 {
129 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin );
130 daoUtil.setInt( 1, nId );
131 daoUtil.executeUpdate( );
132 daoUtil.free( );
133 }
134
135
136
137
138 @Override
139 public void store( IndexerAction indexerAction, Plugin plugin )
140 {
141 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin );
142 daoUtil.setInt( 1, indexerAction.getIdAction( ) );
143 daoUtil.setInt( 2, indexerAction.getIdRecord( ) );
144 daoUtil.setInt( 3, indexerAction.getIdTask( ) );
145
146 daoUtil.setInt( 4, indexerAction.getIdAction( ) );
147
148 daoUtil.executeUpdate( );
149 daoUtil.free( );
150 }
151
152
153
154
155 @Override
156 public List<IndexerAction> selectList( IndexerActionFilter filter, Plugin plugin )
157 {
158 List<IndexerAction> indexerActionList = new ArrayList<IndexerAction>( );
159 IndexerAction indexerAction = null;
160 List<String> listStrFilter = new ArrayList<String>( );
161
162 if ( filter.containsIdTask( ) )
163 {
164 listStrFilter.add( SQL_FILTER_ID_TASK );
165 }
166
167 String strSQL = DirectoryUtils.buildRequetteWithFilter( SQL_QUERY_SELECT, listStrFilter, null );
168
169 DAOUtil daoUtil = new DAOUtil( strSQL, plugin );
170
171 int nIndex = 1;
172
173 if ( filter.containsIdTask( ) )
174 {
175 daoUtil.setInt( nIndex, filter.getIdTask( ) );
176 nIndex++;
177 }
178
179 daoUtil.executeQuery( );
180
181 while ( daoUtil.next( ) )
182 {
183 indexerAction = new IndexerAction( );
184 indexerAction.setIdAction( daoUtil.getInt( 1 ) );
185 indexerAction.setIdRecord( daoUtil.getInt( 2 ) );
186 indexerAction.setIdTask( daoUtil.getInt( 3 ) );
187
188 indexerActionList.add( indexerAction );
189 }
190
191 daoUtil.free( );
192
193 return indexerActionList;
194 }
195 }