Package marauroa.server.db.adapter
Interface DatabaseAdapter
- All Known Implementing Classes:
AbstractDatabaseAdapter,H2DatabaseAdapter,MySQLDatabaseAdapter,PostgresDatabaseAdapter
public interface DatabaseAdapter
adapter for a database system
- Author:
- hendrik
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()closes the database connectionvoidcommit()commits the current transactionbooleandoesColumnExist(String table, String column)checks whether the specified column existsbooleandoesTableExist(String table)checks whether the specified table existsintexecutes an SQL statementintexecute(String sql, InputStream... inputStreams)executes an SQL statement with streamed parametersvoidexecuteBatch(String sql, InputStream... inputStreams)executes a batch of sql-statementsintgetColumnLength(String table, String column)Gets the length of the specified columnintgetLastInsertId(String table, String idcolumn)gets the id of the last insert.booleandetermine if the Exception indicates a connection error, so a retry of the transaction makes sense.prepareStatement(String sql)Prepares a statement for a batch operation.queries the database for informationintquerySingleCellInt(String sql)queries for a single row, single column integer response like a count-selectvoidrollback()rolls the current transaction back, undoing all the changes.booleanverifies that the connection i still working
-
Method Details
-
commit
commits the current transaction- Throws:
SQLException- in case of an database error
-
rollback
rolls the current transaction back, undoing all the changes.- Throws:
SQLException- in case of an database error
-
execute
executes an SQL statement- Parameters:
sql- sql-statement to execute- Returns:
- number of affected rows
- Throws:
SQLException- in case of an database error
-
execute
executes an SQL statement with streamed parameters- Parameters:
sql- sql-statement to executeinputStreams- parameters- Returns:
- number of affected rows
- Throws:
SQLException- in case of an database errorIOException- in case the stream cannot be read to the end
-
executeBatch
executes a batch of sql-statements- Parameters:
sql- sql-statement to executeinputStreams- a list of input stream. For each of them the statement is executed- Throws:
SQLException- in case of an database errorIOException- in case one of the streams cannot be read to the end
-
query
queries the database for information- Parameters:
sql- sql-statement to execute- Returns:
- ResultSet
- Throws:
SQLException- in case of an database error
-
querySingleCellInt
queries for a single row, single column integer response like a count-select- Parameters:
sql- sql-statement to execute- Returns:
- integer of the first column in the first row
- Throws:
SQLException- in case of an database error
-
getLastInsertId
gets the id of the last insert. Note: The table and idcolumn parameters must match the last insert statement. This is because on some database systems a SELECT IDENTITY is performed and on other database systems a SELECT curval(table_idcolumn_seq).- Parameters:
table- name of table on which the last insert was doneidcolumn- name autoincrement serial column of that table- Returns:
- generated id
- Throws:
SQLException- in case of an database error
-
close
closes the database connection- Throws:
SQLException- in case of an database error
-
prepareStatement
Prepares a statement for a batch operation.- Parameters:
sql- SQL statement- Returns:
- PreparedStatement
- Throws:
SQLException- in case of an database error
-
doesTableExist
checks whether the specified table exists- Parameters:
table- name of table- Returns:
- true, if the table exists, false otherwise
- Throws:
SQLException- in case of an database error
-
doesColumnExist
checks whether the specified column exists- Parameters:
table- name of tablecolumn- name of column- Returns:
- true, if the column exists, false otherwise
- Throws:
SQLException- in case of an database error
-
getColumnLength
Gets the length of the specified column- Parameters:
table- name of tablecolumn- name of column- Returns:
- the length of the column or -1 if no column with the given name in the given table exists
- Throws:
SQLException- in case of an database error
-
verifyConnection
boolean verifyConnection()verifies that the connection i still working- Returns:
- true, if the connection is valid; false otherwise
-
isConnectionError
determine if the Exception indicates a connection error, so a retry of the transaction makes sense.- Parameters:
e- Exception- Returns:
- true, if the exception indicates a connection error; false otherwise
-