java.lang.Object
bayern.steinbrecher.dbConnector.DBConnection
- All Implemented Interfaces:
java.lang.AutoCloseable
- Direct Known Subclasses:
SimpleConnection,SshConnection
public abstract class DBConnection
extends java.lang.Object
implements java.lang.AutoCloseable
- Since:
- 0.1
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDBConnection.Column<T>Represents a column that exists in a table which is accessible by this connection.classDBConnection.Table<T,E>Represents a table which exists and is accessible by this connection. -
Constructor Summary
Constructors Constructor Description DBConnection(@NotNull java.lang.String databaseName, @NotNull SupportedDatabases dbms) -
Method Summary
Modifier and Type Method Description abstract voidclose()voidcreateTableIfNotExists(@NotNull TableScheme<?,?> scheme)booleandatabaseExists()Checks if the connected database exists.abstract @NotNull java.util.List<java.util.List<java.lang.String>>execQuery(@NotNull java.lang.String sqlCode)Executes a query and returns the result.abstract voidexecUpdate(@NotNull java.lang.String sqlCode)Executes a command like INSERT INTO, UPDATE or CREATE.@NotNull java.util.Set<DBConnection.Column<?>>getAllColumns(@NotNull TableScheme<?,?> tableScheme)@NotNull java.util.Set<DBConnection.Table<?,?>>getAllTables()@NotNull java.lang.StringgetDatabaseName()@NotNull SupportedDatabasesgetDbms()@NotNull java.util.Set<SimpleColumnPattern<?,?>>getMissingColumns(@NotNull TableScheme<?,?> scheme)@NotNull java.util.Optional<DBConnection.Table<?,?>>getTable(@NotNull TableScheme<?,?> scheme)NOTE In theory the generic parameters of input and output have to match.<T> TgetTableContent(@NotNull TableScheme<T,?> tableScheme)Returns an object representing all current entries of the given table.booleantableExists(@NotNull TableScheme<?,?> tableScheme)
-
Constructor Details
-
DBConnection
public DBConnection(@NotNull @NotNull java.lang.String databaseName, @NotNull @NotNull SupportedDatabases dbms)- Since:
- 0.1
-
-
Method Details
-
close
public abstract void close()- Specified by:
closein interfacejava.lang.AutoCloseable- Since:
- 0.1
-
execQuery
@NotNull public abstract @NotNull java.util.List<java.util.List<java.lang.String>> execQuery(@NotNull @NotNull java.lang.String sqlCode) throws QueryFailedExceptionExecutes a query and returns the result.- Parameters:
sqlCode- The sql code to execute.- Returns:
- Table containing the results AND the headings of each column. First dimension rows; second columns.
- Throws:
QueryFailedException- Thrown if the sql code is invalid.- Since:
- 0.1
-
execUpdate
public abstract void execUpdate(@NotNull @NotNull java.lang.String sqlCode) throws QueryFailedExceptionExecutes a command like INSERT INTO, UPDATE or CREATE.- Parameters:
sqlCode- The sql code to execute.- Throws:
QueryFailedException- Thrown if the sql code is invalid.- Since:
- 0.1
-
databaseExists
Checks if the connected database exists.- Returns:
trueonly if the connected database exists.- Throws:
QueryFailedException- Since:
- 0.1
-
createTableIfNotExists
public void createTableIfNotExists(@NotNull @NotNull TableScheme<?,?> scheme) throws QueryFailedException- Throws:
QueryFailedException- Since:
- 0.1
-
getTableContent
public <T> T getTableContent(@NotNull @NotNull TableScheme<T,?> tableScheme) throws GenerationFailedException, QueryFailedExceptionReturns an object representing all current entries of the given table.- Type Parameters:
T- The type that represents the whole content of the given table.- Parameters:
tableScheme- The table to query all its data from.- Returns:
- The table to request all data from.
- Throws:
GenerationFailedExceptionQueryFailedException- Since:
- 0.1
-
getMissingColumns
@NotNull public @NotNull java.util.Set<SimpleColumnPattern<?,?>> getMissingColumns(@NotNull @NotNull TableScheme<?,?> scheme) throws QueryFailedException- Throws:
QueryFailedException- Since:
- 0.5
-
getAllColumns
@NotNull public @NotNull java.util.Set<DBConnection.Column<?>> getAllColumns(@NotNull @NotNull TableScheme<?,?> tableScheme) throws QueryFailedException- Throws:
QueryFailedException- Since:
- 0.5
-
getAllTables
@NotNull public @NotNull java.util.Set<DBConnection.Table<?,?>> getAllTables() throws QueryFailedException- Throws:
QueryFailedException- Since:
- 0.5
-
getTable
@NotNull public @NotNull java.util.Optional<DBConnection.Table<?,?>> getTable(@NotNull @NotNull TableScheme<?,?> scheme) throws QueryFailedExceptionNOTE In theory the generic parameters of input and output have to match. Due to type erasure of generic types this can not be guaranteed.- Throws:
QueryFailedException- Since:
- 0.6
-
tableExists
public boolean tableExists(@NotNull @NotNull TableScheme<?,?> tableScheme) throws QueryFailedException- Throws:
QueryFailedException- Since:
- 0.1
-
getDatabaseName
@NotNull public @NotNull java.lang.String getDatabaseName()- Since:
- 0.1
-
getDbms
- Since:
- 0.3
-