From 23a46b4be35277e06ec89f48730eeb694e686be8 Mon Sep 17 00:00:00 2001
From: Kenmegne <stephanie.kenmegne@gmail.com>
Date: Thu, 18 Jun 2026 15:40:06 +0000
Subject: [PATCH] add fdx-commons and fdx-consultation

---
 fdx-commons/fdxcommons-tools/src/main/java/com/megatim/fdxcommons/tools/database/queries/CreateDataProductionQuery.java |   73 ++++++++++++++++++++++++++++++++++++
 1 files changed, 73 insertions(+), 0 deletions(-)

diff --git a/fdx-commons/fdxcommons-tools/src/main/java/com/megatim/fdxcommons/tools/database/queries/CreateDataProductionQuery.java b/fdx-commons/fdxcommons-tools/src/main/java/com/megatim/fdxcommons/tools/database/queries/CreateDataProductionQuery.java
new file mode 100644
index 0000000..7df1a81
--- /dev/null
+++ b/fdx-commons/fdxcommons-tools/src/main/java/com/megatim/fdxcommons/tools/database/queries/CreateDataProductionQuery.java
@@ -0,0 +1,73 @@
+package com.megatim.fdxcommons.tools.database.queries;
+
+import com.megatim.fdxcommons.model.dataproduction.CommonDataProduction;
+import com.megatim.fdxcommons.tools.database.contrat.QueryMetaData;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import javax.naming.NamingException;
+
+/**
+ *
+ * @author Gabuntu
+ */
+public class CreateDataProductionQuery implements QueryMetaData<Long> {
+
+    private final CommonDataProduction dataProduction;
+    private final Connection connection;
+
+    public CreateDataProductionQuery(CommonDataProduction 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, tokenDirectory)"
+                + " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+    }
+
+    @Override
+    public Long execute() throws NamingException, SQLException {
+
+        System.out.println("<-------------------------------------------------------------------------->");
+        System.out.println(queryString());
+        System.out.println("<-------------------------------------------------------------------------->");
+
+        String getNextIdQuery = "SELECT nextval('SEQ_DATA_PRODUCTION')";
+
+        try (
+                 PreparedStatement statement = connection.prepareStatement(queryString());  PreparedStatement getIdStatement = connection.prepareStatement(getNextIdQuery);// Fetch the next sequence value
+                ) {
+
+            long generatedId = dataProduction.getId() != null ? dataProduction.getId() : 0;
+
+            if (dataProduction.getId() == null || dataProduction.getId() <= 0) {//Si l'id de la production n'est pas encore initialisé (FdxApi)
+                ResultSet resultSet = getIdStatement.executeQuery();
+                if (resultSet.next()) {
+                    generatedId = resultSet.getLong(1);
+                }
+            }
+
+            statement.setLong(1, generatedId);
+            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.getTokenDirectory());
+
+            statement.executeUpdate();
+
+            return generatedId;
+        }
+    }
+}

--
Gitblit v1.10.0