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.tools.database.contrat.QueryMetaData;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
 
/**
 *
 * @author Gabuntu
 */
public class CurrentDataProductionQuery implements QueryMetaData<Long> {
 
    private final String codeTypeFichier;
    private final String referentielVersion;
    private final Connection connection;
 
    public CurrentDataProductionQuery(String codeTypeFichier, String referentielVersion, Connection connection) {
        this.codeTypeFichier = codeTypeFichier;
        this.referentielVersion = referentielVersion;
        this.connection = connection;
    }
 
    @Override
    public Long execute() throws Exception {
        String query = "SELECT MAX(id) FROM dataproduction WHERE codetypefichier  = ? AND referentielversion = ?";
        Long id = null;
 
        try (PreparedStatement statement = connection.prepareStatement(query);) {
 
            statement.setString(1, codeTypeFichier);
            statement.setString(2, referentielVersion);
            ResultSet resultSet = statement.executeQuery();
 
            if (resultSet.next()) {
                id = resultSet.getLong(1);
            }
        }
        return id;
    }
 
}