/* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template */ package com.megatim.apifdxweb.dao.impl.audit; import com.megatim.apifdxweb.model.audit.AuditActionsParticipant; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; /** * * @author ASUS */ public class AuditActionsParticicipantsQuery { private final Connection connection; private final AuditActionsParticipant auditAction; public AuditActionsParticicipantsQuery(Connection connection, AuditActionsParticipant auditAction) { this.connection = connection; this.auditAction = auditAction; } public void insert() throws SQLException { String getNextIdQuery = "SELECT nextval('SEQ_AUDIT_ACTIONS_PARTICIPANT')"; try ( PreparedStatement statement = connection.prepareStatement(insertString()); PreparedStatement getIdStatement = connection.prepareStatement(getNextIdQuery)) { ResultSet resultSet = getIdStatement.executeQuery(); long generatedId = 0; if (resultSet.next()) { generatedId = resultSet.getLong(1); } statement.setTimestamp(1, Timestamp.valueOf(auditAction.getDateAction())); statement.setInt(2, auditAction.getLastIndexRead()); statement.setString(3, auditAction.getParticipantDemandeur()); statement.setString(4, auditAction.getTypeFichierConsulte()); statement.setLong(5, generatedId); statement.executeUpdate(); } } public void update() throws SQLException { try ( PreparedStatement statement = connection.prepareStatement(updateString())) { statement.setTimestamp(1, Timestamp.valueOf(auditAction.getDateAction())); statement.setInt(2, auditAction.getLastIndexRead()); statement.setLong(3, auditAction.getId()); statement.executeUpdate(); } } private String insertString() { return "INSERT INTO audit_actions_participant(date_action, last_index_read, participant_demandeur, type_fichier_consulte, id)" + " VALUES (?, ?, ?, ?, ?);"; } private String updateString() { return "UPDATE audit_actions_participant SET date_action = ?, last_index_read = ? WHERE id = ?"; } }