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-consultation/fdxconsultation-dao-impl/src/main/java/com/megatim/fdxconsultation/dao/impl/dataproduction/metadata/CreateProductionMetaDataQuery.java | 85 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 85 insertions(+), 0 deletions(-)
diff --git a/fdx-consultation/fdxconsultation-dao-impl/src/main/java/com/megatim/fdxconsultation/dao/impl/dataproduction/metadata/CreateProductionMetaDataQuery.java b/fdx-consultation/fdxconsultation-dao-impl/src/main/java/com/megatim/fdxconsultation/dao/impl/dataproduction/metadata/CreateProductionMetaDataQuery.java
new file mode 100644
index 0000000..f578a1e
--- /dev/null
+++ b/fdx-consultation/fdxconsultation-dao-impl/src/main/java/com/megatim/fdxconsultation/dao/impl/dataproduction/metadata/CreateProductionMetaDataQuery.java
@@ -0,0 +1,85 @@
+package com.megatim.fdxconsultation.dao.impl.dataproduction.metadata;
+
+import com.megatim.fdxcommons.model.dataproduction.DataProductionType;
+import com.megatim.fdxcommons.model.dataproduction.metadata.ProductionMetaData;
+import com.megatim.fdxcommons.tools.database.contrat.QueryMetaData;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import javax.naming.NamingException;
+
+/**
+ *
+ * @author Gabuntu
+ */
+public class CreateProductionMetaDataQuery implements QueryMetaData<Void> {
+
+ private final ProductionMetaData pmd;
+ private final DataProductionType dataProductionType;
+ private final Connection connection;
+ private final int BATCH_SIZE = 100_000;
+
+ public CreateProductionMetaDataQuery(ProductionMetaData pmd, DataProductionType dataProductionType, Connection connection) {
+ this.pmd = pmd;
+ this.dataProductionType = dataProductionType;
+ this.connection = connection;
+ }
+
+ @Override
+ public Void execute() throws NamingException, SQLException {
+
+ if (dataProductionType.equals(DataProductionType.ADD)) {
+ executeAddDataType();
+
+ } else if (dataProductionType.equals(DataProductionType.UPDATE)) {
+ executeUpdateDataType();
+ }
+ return null;
+ }
+
+ private void executeAddDataType() throws SQLException {
+ System.out.println("--------------------- pmd.getNbreElts() = " + pmd.getNbreElts());
+ try ( PreparedStatement statement = connection.prepareStatement(productionMetaDataQueryString())) {
+
+ statement.setLong(1, pmd.getProductionId());
+ statement.setLong(2, pmd.getStartIndex());
+ statement.setLong(3, pmd.getNbreElts());
+ statement.setString(4, pmd.getDataProductionType());
+
+ statement.executeUpdate();
+
+ }
+ }
+
+ private void executeUpdateDataType() throws SQLException {
+ try ( PreparedStatement metaDataStatement = connection.prepareStatement(productionMetaDataQueryString()); PreparedStatement indexesStatement = connection.prepareStatement(productionMetaDataIndexesQuery())) {
+ metaDataStatement.executeUpdate();
+ executeInBatch(indexesStatement);
+ indexesStatement.executeBatch();
+ }
+ }
+
+ private String productionMetaDataQueryString() {
+ return "INSERT INTO ProductionMetaData(productionId, startIndex, nbreElts, dataProductionType)"
+ + " VALUES(?, ?, ?, ?)";
+ }
+
+ private String productionMetaDataIndexesQuery() {
+ return "INSERT INTO productionMetaData_indexes(productionId, indexes) VALUES(?, ?)";
+ }
+
+ private void executeInBatch(PreparedStatement preparedStatement) throws SQLException {
+ int count = 0;
+
+ for (Long l : pmd.getIndexes()) {
+ preparedStatement.setLong(1, pmd.getProductionId());
+ preparedStatement.setLong(2, l);
+ preparedStatement.addBatch();
+
+ if (++count % BATCH_SIZE == 0) {
+ preparedStatement.executeBatch();
+ }
+ }
+ }
+
+}
--
Gitblit v1.10.0