Class SchemaReader

java.lang.Object
org.ivoa.dm.tapschema.utils.SchemaReader
All Implemented Interfaces:
AutoCloseable

public final class SchemaReader extends Object implements AutoCloseable
Builds a TAP_SCHEMA model from JDBC metadata. Note that this fills the TAPSchema in a way that is suitable for XML serialization, rather than that desirable for database storage.
  • Constructor Details

    • SchemaReader

      public SchemaReader(String jdbcUrl) throws SQLException
      Constructs a new SchemaReader with a JDBC URL. The connection will be owned and closed by this reader.
      Parameters:
      jdbcUrl - the JDBC URL to connect to the database. This should include any necessary credentials and parameters.
      Throws:
      SQLException
    • SchemaReader

      public SchemaReader(DataSource dataSource) throws SQLException
      Constructs a SchemaReader with a DataSource. The connection will be owned and closed by this reader.
      Parameters:
      dataSource - the configured dataSource.
      Throws:
      SQLException - if a problem with creating the database connection.
    • SchemaReader

      public SchemaReader(String jdbcUrl, String user, String password) throws SQLException
      Contructs a new SchemaReader with a JDBC URL and credentials. The connection will be owned and closed by this reader.
      Parameters:
      jdbcUrl - the JDBC URL to connect to the database. This should include any necessary parameters, but not credentials.
      user - the username for the database connection.
      password - the password for the database connection
      Throws:
      SQLException - if a problem with creating the database connection.
    • SchemaReader

      public SchemaReader(String jdbcUrl, Properties properties) throws SQLException
      Constructs a new SchemaReader with JDBC URL and properties.
      Parameters:
      jdbcUrl - the JDBC URL to connect to the database. This should include any necessary parameters, but not credentials.
      properties - the properties for the database connection, including credentials if necessary.
      Throws:
      SQLException - if a problem with creating the database connection.
    • SchemaReader

      public SchemaReader(Connection connection)
      constructs a new SchemaReader with an existing JDBC connection. The connection will not be closed by this reader, and is the responsibility of the caller.
      Parameters:
      connection -
  • Method Details

    • translate

      public TapschemaModel translate() throws SQLException
      Translate the database metadata into a TAP_SCHEMA model. By default, system schemas are excluded and only tables and views are included. See SchemaReader.Options for more control.
      Returns:
      the translated metadata model.Note with schema, table and column names are qualified suitable for immediate XML serialization, rather than for database storage. See XMLNormalizer for normalizing the model for database storage.
      Throws:
      SQLException - if there is a problem reading the database metadata.
    • translate

      public TapschemaModel translate(SchemaReader.Options options) throws SQLException
      Translate the database metadata into a TAP_SCHEMA model. By default, system schemas are excluded and only tables and views are included. See SchemaReader.Options for more control.
      Parameters:
      options - translation options.
      Returns:
      the translated metadata model.Note with schema, table and column names are qualified suitable for immediate XML serialization, rather than for database storage. See XMLNormalizer for normalizing the model for database storage.
      Throws:
      SQLException - if there is a problem reading the database metadata.
    • close

      public void close() throws SQLException
      Specified by:
      close in interface AutoCloseable
      Throws:
      SQLException
    • writeSchemas

      public void writeSchemas(TapschemaModel model, OutputStream out) throws IOException, jakarta.xml.bind.JAXBException
      Throws:
      IOException
      jakarta.xml.bind.JAXBException