Package de.chojo.sadu.core.databases
Interface Database<T extends JdbcConfig<?>,U extends UpdaterBuilder<T,?>>
- Type Parameters:
T
- type of the database defined by theDatabase
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 Summary
Modifier and TypeMethodDescriptiondefault String[]
alias()
Get the alias for the database name.default String[]
cleanStatements
(String[] queries) Function supposed to clean statements by removing empty statementsdefault String
createSchema
(String schema) Returns a query to create a schema with this name.createVersionTableQuery
(String table) Creates a query to create a version table on the database.deleteVersion
(String table) Creates a query to delete all entries from the version table.default boolean
Indicates if this type supports schemas.insertVersion
(String table) Creates a query to insert a version into the version table.Returns theJdbcConfig
implementation for this databasedefault boolean
name()
Get a unique name to identify the database.Instantiates an implementation ofUpdaterBuilder
default String
Returns a query which returns a boolean indicating if a schema with this name exists.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.versionQuery
(String table) Gets a query to read the version from the version table
-
Method Details
-
createVersionTableQuery
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
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
Get the alias for the database name.- Returns:
- array of aliases
-
matches
- Parameters:
name
- name to check- Returns:
- true if any match was found
-
insertVersion
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
Creates a query to delete all entries from the version table.- Parameters:
table
- table name- Returns:
- query to clear version table
-
schemaExists
Returns a query which returns a boolean indicating if a schema with this name exists.- Returns:
- query to check for schema
-
createSchema
Returns a query to create a schema with this name.- Parameters:
schema
- schema- Returns:
- query to create schema
-
jdbcBuilder
T jdbcBuilder()Returns theJdbcConfig
implementation for this database- Returns:
- jdbc builder
-
splitStatements
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
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)
andschemaExists()
needs to be implemented.- Returns:
- true when schemas are supported
-
newSqlUpdaterBuilder
Instantiates an implementation ofUpdaterBuilder
- Returns:
- the instance
-