/* * 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.metadata; import com.megatim.fdxcommons.model.enumeration.TypeDonnee; import com.megatim.fdxcommons.model.integration.json.JsonStructure; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import javax.naming.NamingException; /** * * @author ASUS */ public class JsonFdxTableStructure { private final String referentielVersion; private final String codeTypeFichier; private final Connection connection; public JsonFdxTableStructure(String referentielVersion, String codeTypeFichier, Connection connection) { this.referentielVersion = referentielVersion; this.codeTypeFichier = codeTypeFichier; this.connection = connection; } public JsonStructure jsonStructure() throws NamingException, SQLException { JsonStructure jsonStructure = null; Long jsonStructureId = jsonStructureId(); if (jsonStructureId != null) { String query = "SELECT * FROM JsonStructure j where j.id = ?"; try ( PreparedStatement stmt = connection.prepareStatement(query)) { stmt.setLong(1, jsonStructureId); ResultSet resultSet = stmt.executeQuery(); if (resultSet.next()) { jsonStructure = new JsonStructure(); jsonStructure.setId(resultSet.getLong("id")); jsonStructure.setLengthh(resultSet.getInt("lengthh")); jsonStructure.setTypeDonnee(TypeDonnee.fromValeur(resultSet.getString("typedonnee"))); jsonStructure.setName(resultSet.getString("name")); jsonStructure.setRequired(resultSet.getBoolean("required")); jsonStructure.setCollection(resultSet.getBoolean("collection")); jsonStructure.setFormatDate(resultSet.getString("formatdate")); } } } return jsonStructure; } private Long jsonStructureId() throws SQLException { String query = "SELECT json_structure_id FROM typeFichierJson t WHERE t.type_fichier_code = ? AND t.referentiel_version = ?"; try ( PreparedStatement stmt = connection.prepareStatement(query)) { stmt.setString(1, codeTypeFichier); stmt.setString(2, referentielVersion); ResultSet resultSet = stmt.executeQuery(); if (resultSet.next()) { return resultSet.getLong(1); } } return null; } }