Kenmegne
7 days ago 23a46b4be35277e06ec89f48730eeb694e686be8
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
36
37
38
39
40
41
42
package com.megatim.fdxcommons.tools.database.queries;
 
import com.megatim.fdxcommons.model.dataproduction.CommonDataProduction;
import com.megatim.fdxcommons.tools.database.contrat.QueryMetaData;
import com.megatim.fdxcommons.tools.database.tables.appcolumns.*;
 
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Timestamp;
 
public class DataWithTokenToDataProductionQuery implements QueryMetaData<Void> {
 
    private final Connection connection;
    private final CommonDataProduction dataProduction;
    private final String token;
    private final String tableName;
 
    public DataWithTokenToDataProductionQuery(Connection connection, CommonDataProduction dataProduction, String token, String tableName) {
        this.connection = connection;
        this.dataProduction = dataProduction;
        this.token = token;
        this.tableName = tableName;
    }
 
    @Override
    public Void execute() throws Exception {
 
        String query = "UPDATE " + tableName + " SET " + new DataProductionIdColumnDefinition().name() + " = ?, " + new DateCreationColumnDefinition().name() + " = ?, "
                + new TokenColumnDefinition().name() + " = ?" + " WHERE " + new TokenColumnDefinition().name() + " = ?";
 
        try (PreparedStatement stmt = connection.prepareStatement(query)) {
            stmt.setLong(1, dataProduction.getId());
            stmt.setTimestamp(2, Timestamp.valueOf(dataProduction.getDateProduction()));
            stmt.setString(3, null);
            stmt.setString(4, token);
            stmt.executeUpdate();
        }
 
        return null;
    }
 
}