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/CustomQueries.java |   89 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 89 insertions(+), 0 deletions(-)

diff --git a/fdx-commons/fdxcommons-tools/src/main/java/com/megatim/fdxcommons/tools/database/queries/CustomQueries.java b/fdx-commons/fdxcommons-tools/src/main/java/com/megatim/fdxcommons/tools/database/queries/CustomQueries.java
new file mode 100644
index 0000000..e9fa997
--- /dev/null
+++ b/fdx-commons/fdxcommons-tools/src/main/java/com/megatim/fdxcommons/tools/database/queries/CustomQueries.java
@@ -0,0 +1,89 @@
+/*
+ * 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.fdxcommons.tools.database.queries;
+
+import com.megatim.fdxcommons.model.dataproduction.CommonDataProduction;
+import com.megatim.fdxcommons.tools.database.tables.appcolumns.DataProductionIdColumnDefinition;
+import com.megatim.fdxcommons.tools.database.tables.appcolumns.IndexColumnDefinition;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ * @author ASUS
+ */
+public class CustomQueries {
+
+    public Long selectMinIndexOfDataProduction(Long dataProdcutionId, String tableName, Connection connection) throws SQLException {
+        String query = "SELECT MIN(" + new IndexColumnDefinition().name() + ")"
+                + " FROM " + tableName
+                + " WHERE " + new DataProductionIdColumnDefinition().name() + " = " + dataProdcutionId;
+        Long min = null;
+
+        try ( PreparedStatement statement = connection.prepareStatement(query);  ResultSet resultSet = statement.executeQuery()) {
+            while (resultSet.next()) {
+                min = resultSet.getLong(1);
+            }
+        }
+        return min;
+    }
+
+    public boolean fdxIndexExists(Long index, String tableName, Connection connection) throws SQLException {
+        String query = "SELECT * FROM " + tableName + " WHERE " + new IndexColumnDefinition().name() + " = ?";
+
+        boolean exists = false;
+
+        try ( PreparedStatement statement = connection.prepareStatement(query);) {
+            statement.setLong(1, index);
+            ResultSet resultSet = statement.executeQuery();
+
+            if (resultSet.next()) {
+                exists = true;
+            }
+        }
+        return exists;
+    }
+
+    public void deleteWhereIndexLowerThan(Long fdx_index, String tableName, Connection connection) throws SQLException {
+        String query = "DELETE FROM " + tableName + " WHERE " + new IndexColumnDefinition().name() + " < ?";
+
+        try ( PreparedStatement statement = connection.prepareStatement(query);) {
+            statement.setLong(1, fdx_index);
+
+            statement.executeUpdate();
+        }
+    }
+
+    public Long countDataproductionElements(String token, Connection connection) throws SQLException {
+        String query = "SELECT COUNT(*) FROM " + CommonDataProduction.class.getSimpleName() + " WHERE token = ?";
+
+        try ( PreparedStatement statement = connection.prepareStatement(query);) {
+            statement.setString(1, token);
+            ResultSet result = statement.executeQuery();
+
+            result.next();
+            return result.getLong(1);
+        }
+    }
+
+    public List<Long> indexes(Long productionId, Connection connection) throws SQLException {
+        String query = "SELECT indexes FROM  productionMetaData_indexes WHERE productionId = ? ORDER BY indexes";
+        List<Long> indexes = new ArrayList<>();
+
+        try ( PreparedStatement statement = connection.prepareStatement(query);) {
+            statement.setLong(1, productionId);
+            ResultSet resultSet = statement.executeQuery();
+
+            while (resultSet.next()) {
+                indexes.add(resultSet.getLong(1));
+            }
+        }
+        return indexes;
+    }
+}

--
Gitblit v1.10.0