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 { 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; } }