Interface Database<T extends JdbcConfig<?>,U extends UpdaterBuilder<T,?>>

Type Parameters:
T - type of the database defined by the Database
U - type of the BaseSqlUpdater
All Known Subinterfaces:
DefaultDatabase<T,U>
All Known Implementing Classes:
MariaDb, MySql, PostgreSql, SqLite

public interface Database<T extends JdbcConfig<?>,U extends UpdaterBuilder<T,?>>
Defines a sql type and handles RDBMS specific actions.

Every type should implement two static methods, which provide the driver by name and one by get.


 class MySqlType extends SqlType<MySqlTypeJdbc> {
      private static final MySqlType type = MySqlType();

      public static MySqlType mysqltype() {
          return type;
      }

      public static MySqlType get() {
          return type;
      }

      private MySqlType(){}
 }
 
  • Method Details

    • createVersionTableQuery

      String createVersionTableQuery(String table)
      Creates a query to create a version table on the database.

      The query needs to handle errors when the table exists.

      Parameters:
      table - table name
      Returns:
      query to create a version table
    • versionQuery

      String versionQuery(String table)
      Gets a query to read the version from the version table
      Parameters:
      table - table name
      Returns:
      query to read the version table
    • name

      String name()
      Get a unique name to identify the database.
      Returns:
      database name
    • alias

      default String[] alias()
      Get the alias for the database name.
      Returns:
      array of aliases
    • matches

      default boolean matches(String name)
      Checks if the given name matches the name() or any alias(). case-insensitive.
      Parameters:
      name - name to check
      Returns:
      true if any match was found
    • insertVersion

      String insertVersion(String table)
      Creates a query to insert a version into the version table.

      Versions are always inserted and not updated.

      Parameters:
      table - table name
      Returns:
      query to insert the version.
    • deleteVersion

      String deleteVersion(String table)
      Creates a query to delete all entries from the version table.
      Parameters:
      table - table name
      Returns:
      query to clear version table
    • schemaExists

      default String schemaExists()
      Returns a query which returns a boolean indicating if a schema with this name exists.
      Returns:
      query to check for schema
    • createSchema

      default String createSchema(String schema)
      Returns a query to create a schema with this name.
      Parameters:
      schema - schema
      Returns:
      query to create schema
    • jdbcBuilder

      T jdbcBuilder()
      Returns the JdbcConfig implementation for this database
      Returns:
      jdbc builder
    • splitStatements

      default String[] splitStatements(String queries)
      The split queries, if the db does not allow to execute multiple queries this function should return every query in one string.

      Otherwise, this array will only contain one entry.

      Parameters:
      queries - queries
      Returns:
      queries
    • cleanStatements

      default String[] cleanStatements(String[] queries)
      Function supposed to clean statements by removing empty statements
      Parameters:
      queries - queries
      Returns:
      a new array
    • hasSchemas

      default boolean hasSchemas()
      Indicates if this type supports schemas.

      When schemas are supported the methods createSchema(String) and schemaExists() needs to be implemented.

      Returns:
      true when schemas are supported
    • newSqlUpdaterBuilder

      @Internal UpdaterBuilder<T,U> newSqlUpdaterBuilder()
      Instantiates an implementation of UpdaterBuilder
      Returns:
      the instance