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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.megatim.fdxconsultation.dao.impl.dataproduction.metadata;
 
import com.megatim.fdxcommons.tools.database.contrat.QueryMetaData;
import com.megatim.fdxconsultation.model.dataproduction.DataProduction;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import javax.naming.NamingException;
 
/**
 *
 * @author Gabuntu
 */
public class CreateDataProductionQuery implements QueryMetaData<Void> {
 
    private final DataProduction dataProduction;
    private final Connection connection;
 
    public CreateDataProductionQuery(DataProduction dataProduction, Connection connection) {
        this.dataProduction = dataProduction;
        this.connection = connection;
    }
 
    private String queryString() {
        return "INSERT INTO dataproduction(id, dateproduction, referentielversion, codetypefichier"
                + ", codeparticipant, source, filename, statutdataproduction"
                + ", filedate, dataProductionType, token, nbreElements"
                + ", tailleFichier, integrationFileName, dateMiseAJour)"
                + " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    }
 
    @Override
    public Void execute() throws NamingException, SQLException {
 
        System.out.println("<-------------------------------------------------------------------------->");
        System.out.println(queryString());
        System.out.println("<-------------------------------------------------------------------------->");
 
        try ( PreparedStatement statement = connection.prepareStatement(queryString())) {
 
            statement.setLong(1, dataProduction.getId());
            statement.setTimestamp(2, dataProduction.getDateProduction() != null ? Timestamp.valueOf(dataProduction.getDateProduction()) : null);
            statement.setString(3, dataProduction.getReferentielVersion());
            statement.setString(4, dataProduction.getCodeTypeFichier());
            statement.setString(5, dataProduction.getCodeParticipant());
            statement.setString(6, dataProduction.getSource().name());
            statement.setString(7, dataProduction.getFileName());
            statement.setString(8, dataProduction.getStatutDataProduction().name());
            statement.setTimestamp(9, dataProduction.getFileDate() != null ? Timestamp.valueOf(dataProduction.getFileDate()) : null);
            statement.setString(10, dataProduction.getDataProductionType().name());
            statement.setString(11, dataProduction.getToken());
            statement.setLong(12, dataProduction.getNbreElements());
            statement.setLong(13, dataProduction.getTailleFichier());
            statement.setString(14, dataProduction.getIntegrationFileName());
            statement.setTimestamp(15, dataProduction.getDateMiseAJour() != null ? Timestamp.valueOf(dataProduction.getDateMiseAJour()) : null);
 
            statement.executeUpdate();
 
            return null;
        }
    }
}