Class ADatabase

java.lang.Object
de.julianweinelt.datacat.dbx.database.ADatabase
Direct Known Subclasses:
DBMariaDB, DBMSSQL, DBMySQL

public abstract class ADatabase extends Object
  • Field Details

  • Constructor Details

    • ADatabase

      protected ADatabase(String host, int port, String username, String password)
  • Method Details

    • of

      public static ADatabase of(String type, String host, int port, String username, String password)
    • internalName

      public abstract String internalName()
    • connect

      public boolean connect()
      Connect to the database using the default parameters of this database type
      Returns:
      true if connection was successful, otherwise false
    • connect

      public boolean connect(ADatabase.ParameterBuilder builder)
      Connect to the database using custom parameters
      Parameters:
      builder - A ADatabase.ParameterBuilder object containing all parameters
      Returns:
      true if connection was successful, otherwise false
    • disconnect

      public void disconnect()
      Disconnect from database
    • setStreaming

      public abstract void setStreaming(boolean streaming)
      Set the database connecting to streaming mode.
      Parameters:
      streaming - streaming mode
    • useDatabase

      public void useDatabase(String database)
      Execute the USE [dbname]; statement on the database connection.
      Parameters:
      database - The name of the database to use
      Throws:
      IllegalArgumentException - if the database name is invalid
      DatabaseSchemaNotFoundException - if the database doesn't exist
    • prepareStatement

      public PreparedStatement prepareStatement(String sql) throws SQLException
      Prepare a statement for execution.
      Parameters:
      sql - The SQL statement(s).
      Returns:
      A PreparedStatement for use with escaping parameters
      Throws:
      SQLException - When something went wrong
    • getDatabases

      public abstract List<String> getDatabases()
      Get all database schemas on this database server.
      Returns:
      A List of String objects with the names of the database schemas
    • getTables

      public abstract List<String> getTables(String database)
    • getTableData

      public abstract ResultSet getTableData(String database, String table) throws SQLException
      Throws:
      SQLException
    • getSchemaInfo

      public abstract ADatabase.SchemaInfo getSchemaInfo(String database)
    • getDatabaseProductName

      public abstract String getDatabaseProductName()
    • getDatabaseProductVersion

      public abstract String getDatabaseProductVersion()
    • createDatabaseIfNotExists

      public void createDatabaseIfNotExists(String db)
    • extractTableMeta

      public TableDefinition extractTableMeta(String database, String table) throws SQLException
      Throws:
      SQLException
    • commit

      public void commit()
    • rollback

      public void rollback()