public interface DatabaseEngine extends AutoCloseable
| Modifier and Type | Method and Description |
|---|---|
void |
addBatch(String name,
EntityEntry entry)
Adds an entry to the batch.
|
void |
addEntity(DbEntity entity)
Adds an entity to the engine.
|
void |
beginTransaction()
Starts a transaction.
|
boolean |
checkConnection()
Checks if the connection is alive.
|
boolean |
checkConnection(boolean forceReconnect)
Checks if the connection is alive.
|
void |
clearParameters(String name)
Clears the prepared statement parameters.
|
void |
close()
Closes the connection to the database.
|
String |
commentCharacter() |
void |
commit()
Commits the current transaction.
|
boolean |
containsEntity(String name)
Returns if the current engine contains the entity.
|
AbstractBatch |
createBatch(int batchSize,
long batchTimeout)
Creates a new batch that periodically flushes a batch.
|
AbstractBatch |
createBatch(int batchSize,
long batchTimeout,
String batchName)
Creates a new batch that periodically flushes a batch.
|
default AbstractBatch |
createBatch(int batchSize,
long batchTimeout,
String batchName,
BatchListener batchListener)
Creates a new batch that periodically flushes a batch.
|
default AbstractBatch |
createBatch(int batchSize,
long batchTimeout,
String batchName,
BatchListener batchListener,
org.slf4j.Logger confidentialLogger)
Creates a new batch that periodically flushes a batch.
|
AbstractBatch |
createBatch(int batchSize,
long batchTimeout,
String batchName,
FailureListener failureListener)
Deprecated.
Use
createBatch(int, long, String, BatchListener) instead. |
void |
createPreparedStatement(String name,
Expression query)
Creates a prepared statement.
|
void |
createPreparedStatement(String name,
Expression query,
int timeout)
Creates a prepared statement.
|
void |
createPreparedStatement(String name,
String query)
Creates a prepared statement.
|
void |
createPreparedStatement(String name,
String query,
int timeout)
Creates a prepared statement.
|
void |
dropEntity(DbEntity entity)
Drops everything that belongs to the entity.
|
void |
dropEntity(String entity)
Drops an entity.
|
void |
dropView(String view)
Drops a view.
|
DatabaseEngine |
duplicate(Properties mergeProperties,
boolean copyEntities)
Duplicates a connection.
|
String |
escapeCharacter() |
void |
executePS(String name)
Executes the specified prepared statement.
|
Integer |
executePSUpdate(String name)
Executes update on the specified prepared statement.
|
int |
executeUpdate(Expression query)
Executes the given update.
|
int |
executeUpdate(String query)
Executes a native query.
|
void |
flush()
Flushes the batches for all the registered entities.
|
Connection |
getConnection()
Checks if the connection is available and returns it.
|
Dialect |
getDialect()
Gets the dialect being used.
|
Map<String,DbEntityType> |
getEntities()
Gets the database entities for the current schema.
|
Map<String,DbEntityType> |
getEntities(String schemaPattern)
Gets the database entities for the specified schema.
|
Map<String,DbColumnType> |
getMetadata(String tableNamePattern)
Gets the table metadata (table must be in the current schema).
|
Map<String,DbColumnType> |
getMetadata(String schemaPattern,
String tableNamePattern)
Gets the table metadata (table must be in the current schema).
|
PdbProperties |
getProperties()
Gets the properties in use.
|
ResultIterator |
getPSIterator(String name)
Creates an iterator for the
PreparedStatement bound to the given name. |
ResultIterator |
getPSIterator(String name,
int fetchSize)
Creates an iterator for the
PreparedStatement bound to the given name. |
List<Map<String,ResultColumn>> |
getPSResultSet(String name)
Gets the result set of the specified prepared statement.
|
Map<String,DbColumnType> |
getQueryMetadata(Expression query)
Gets the query metadata.
|
Map<String,DbColumnType> |
getQueryMetadata(String query)
Gets the query metadata.
|
boolean |
isStringAggDistinctCapable()
Checks if the engine supports using DISTINCT inside a string aggregation.
|
boolean |
isTransactionActive()
Checks if a transaction is active.
|
ResultIterator |
iterator(Expression query)
Creates an iterator for the given SQL expression.
|
ResultIterator |
iterator(Expression query,
int fetchSize)
Creates an iterator for the given SQL expression.
|
default ResultIterator |
iterator(Expression query,
int fetchSize,
int readTimeoutOverride)
Creates an iterator for the given SQL expression overriding the configured query
timeout (see
PdbProperties.getSelectQueryTimeout()) if the underlying engine
supports query timeouts. |
ResultIterator |
iterator(String query)
Creates an iterator for the given SQL sentence.
|
ResultIterator |
iterator(String query,
int fetchSize)
Creates an iterator for the given SQL sentence.
|
default ResultIterator |
iterator(String query,
int fetchSize,
int readTimeoutOverride)
Creates an iterator for the given SQL sentence overriding the configured query
timeout (see
PdbProperties.getSelectQueryTimeout()) if the underlying engine
supports query timeouts. |
void |
loadEntity(DbEntity entity)
Loads an entity into the engine.
|
Long |
persist(String name,
EntityEntry entry)
Persists a given entry.
|
Long |
persist(String name,
EntityEntry entry,
boolean useAutoInc)
Persists a given entry.
|
boolean |
preparedStatementExists(String name)
Checks if there's a prepared statement with the given name.
|
List<Map<String,ResultColumn>> |
query(Expression query)
Executes the given query.
|
default List<Map<String,ResultColumn>> |
query(Expression query,
int readTimeoutOverride)
Executes the given query overriding the configured query timeout (see
PdbProperties.getSelectQueryTimeout())
if the underlying engine supports query timeouts. |
List<Map<String,ResultColumn>> |
query(String query)
Executes the given native query.
|
default List<Map<String,ResultColumn>> |
query(String query,
int readTimeoutOverride)
Executes the given native query overriding the configured query timeout (see
PdbProperties.getSelectQueryTimeout()
if the underlying engine supports query timeouts. |
DbEntity |
removeEntity(String name)
Removes the entity given the name.
|
void |
removePreparedStatement(String name)
Removes the given prepared statement.
|
void |
rollback()
Rolls back a transaction.
|
void |
setExceptionHandler(ExceptionHandler eh)
Sets the given exception handler in the engine.
|
void |
setParameter(String name,
int index,
Object param)
Sets the parameter on the specified index.
|
void |
setParameter(String name,
int index,
Object param,
DbColumnType paramType)
Sets the parameter on the specified index given its type.
|
void |
setParameters(String name,
Object... params)
Sets the parameters on the specified prepared statement.
|
String |
translate(Expression query)
Translates the given expression to the current dialect.
|
void |
updateEntity(DbEntity entity)
Updates an entity in the engine.
|
void close()
close in interface AutoCloseablevoid beginTransaction()
throws DatabaseEngineRuntimeException
Connection.getAutoCommit()).DatabaseEngineRuntimeException - If something goes wrong while beginning transaction.void addEntity(DbEntity entity) throws DatabaseEngineException
entity - The entity to add.DatabaseEngineException - If something goes wrong while creating the structures.void loadEntity(DbEntity entity) throws DatabaseEngineException
No DDL commands will be executed, only prepared statements will be created in order to persist
data into the entities.
entity - The entity to load into the connection.DatabaseEngineException - If something goes wrong while loading the entity.void updateEntity(DbEntity entity) throws DatabaseEngineException
Updates an entity in the engine.
If the entity does not exists in the instance, the method addEntity(com.feedzai.commons.sql.abstraction.ddl.DbEntity) will be invoked.
The engine will compare the entity with the getMetadata(String) information and update the schema of the table.
ATTENTION: This method will only add new columns or drop removed columns in the database table. Primary Keys, Foreign Keys, Indexes and column types changes will not be updated.
entity - The entity to update.DatabaseEngineException - If something goes wrong while updating the entity.DbEntity removeEntity(String name)
name - The name of the entity to remove.boolean containsEntity(String name)
name - The entity name.void dropEntity(String entity) throws DatabaseEngineException
entity - The entity name.DatabaseEngineException - If something goes wrong while dropping the entity.void dropEntity(DbEntity entity) throws DatabaseEngineException
entity - The entity.DatabaseEngineException - If something goes wrong while dropping the structures.void dropView(String view) throws DatabaseEngineException
view - The view name.DatabaseEngineException - If something goes wrong while dropping the view.Long persist(String name, EntityEntry entry) throws DatabaseEngineException
If you are inside of an explicit transaction, changes will only be visible upon explicit commit, otherwise a commit will immediately take place.
name - The entity name.entry - The entry to persist.null if there's no auto generated value.DatabaseEngineException - If something goes wrong while persisting data.Long persist(String name, EntityEntry entry, boolean useAutoInc) throws DatabaseEngineException
Persists a given entry. Persisting a query implies executing the statement. If define useAutoInc as false, PDB will disable the auto increments for the current insert and advance the sequences if needed.
If you are inside of an explicit transaction, changes will only be visible upon explicit commit, otherwise a commit will immediately take place.
name - The entity name.entry - The entry to persist.useAutoInc - Use or not the autoinc.null if there's no auto generated value.DatabaseEngineException - If something goes wrong while persisting data.void flush()
throws DatabaseEngineException
DatabaseEngineException - If something goes wrong while persisting data.void commit()
throws DatabaseEngineRuntimeException
beginTransaction().DatabaseEngineRuntimeException - If something goes wrong while committing transaction.void rollback()
throws DatabaseEngineRuntimeException
beginTransaction().DatabaseEngineRuntimeException - If the rollback fails.boolean isTransactionActive()
throws DatabaseEngineRuntimeException
true if the transaction is active, false otherwise.DatabaseEngineRuntimeException - If the access to the database fails.int executeUpdate(String query) throws DatabaseEngineException
query - The query to execute.DatabaseEngineException - If something goes wrong executing the native query.int executeUpdate(Expression query) throws DatabaseEngineException
query - The update to execute.DatabaseEngineException - If something goes wrong executing the update.String translate(Expression query)
query - The query to translate.Dialect getDialect()
AbstractBatch createBatch(int batchSize, long batchTimeout)
AbstractBatch.destroy() before closing the session with the database.batchSize - The batch size.batchTimeout - If inserts do not occur after the specified time, a flush will be performed.AbstractBatch createBatch(int batchSize, long batchTimeout, String batchName)
AbstractBatch.destroy() before closing the session with the database.batchSize - The batch size.batchTimeout - If inserts do not occur after the specified time, a flush will be performed.batchName - The batch name.default AbstractBatch createBatch(int batchSize, long batchTimeout, String batchName, BatchListener batchListener, org.slf4j.Logger confidentialLogger)
AbstractBatch.destroy() before closing the session with the database.
The default implementation of this method throws an UnsupportedOperationException
for backward-compatibility reasons. If this method is supposed to be called, it must be explicitly overridden.batchSize - The batch size.batchTimeout - If inserts do not occur after the specified time, a flush will be performed.batchName - The batch name.batchListener - Batch listener to execute custom behavior when the batch fails or succeeds to persist.confidentialLogger - The confidential logger.@Deprecated AbstractBatch createBatch(int batchSize, long batchTimeout, String batchName, FailureListener failureListener)
createBatch(int, long, String, BatchListener) instead.
If desired you may provide an Optional FailureListener that will be invoked when the batch
fails to persist data.
AbstractBatch.destroy() before closing the session with the database.batchSize - The batch size.batchTimeout - If inserts do not occur after the specified time, a flush will be performed.batchName - The batch name.failureListener - Failure listener to execute custom behavior when the batch fails to persist.default AbstractBatch createBatch(int batchSize, long batchTimeout, String batchName, @Nullable BatchListener batchListener)
If desired you may provide a BatchListener that will be invoked when a batch operation
fails or succeeds to persist data.
AbstractBatch.destroy() before closing the session with the database.batchSize - The batch size.batchTimeout - If inserts do not occur after the specified time, a flush will be performed.batchName - The batch name.batchListener - Batch listener to execute custom behavior when the batch fails or succeeds to persist.boolean checkConnection(boolean forceReconnect)
forceReconnect - true to force the connection in case of failure, false otherwise.true if the connection is valid, false otherwise.boolean checkConnection()
true if the connection is valid, false otherwise.void addBatch(String name, EntityEntry entry) throws DatabaseEngineException
name - The entity name.entry - The entry to persist.DatabaseEngineException - If something goes wrong while persisting data.List<Map<String,ResultColumn>> query(Expression query) throws DatabaseEngineException
query - The query to execute.DatabaseEngineException - If something goes wrong executing the query.default List<Map<String,ResultColumn>> query(Expression query, int readTimeoutOverride) throws DatabaseEngineException
PdbProperties.getSelectQueryTimeout())
if the underlying engine supports query timeouts.query - The query to execute.readTimeoutOverride - The query timeout to use.DatabaseEngineException - If something goes wrong executing the query.List<Map<String,ResultColumn>> query(String query) throws DatabaseEngineException
query - The query to execute.DatabaseEngineException - If something goes wrong executing the query.default List<Map<String,ResultColumn>> query(String query, int readTimeoutOverride) throws DatabaseEngineException
PdbProperties.getSelectQueryTimeout()
if the underlying engine supports query timeouts.query - The query to execute.readTimeoutOverride - The query timeout to use.DatabaseEngineException - If something goes wrong executing the query.Map<String,DbEntityType> getEntities() throws DatabaseEngineException
DatabaseEngineException - If something occurs getting the existing tables.Map<String,DbEntityType> getEntities(String schemaPattern) throws DatabaseEngineException
schemaPattern - A schema name pattern; must match the schema name as it is stored in the database;
"" retrieves those without a schema; null means that the schema name
should not be used to narrow the search.DatabaseEngineException - If something occurs getting the existing tables.Map<String,DbColumnType> getMetadata(String tableNamePattern) throws DatabaseEngineException
tableNamePattern - A table name pattern; must match the table name as it is stored in the database.DatabaseEngineException - If something occurs getting the metadata.Map<String,DbColumnType> getMetadata(String schemaPattern, String tableNamePattern) throws DatabaseEngineException
tableNamePattern - A table name pattern; must match the table name as it is stored in the database.schemaPattern - A schema name pattern; must match the schema name as it is stored in the database;
"" retrieves those without a schema; null means that the schema name
should not be used to narrow the search.DatabaseEngineException - If something occurs getting the metadata.Map<String,DbColumnType> getQueryMetadata(Expression query) throws DatabaseEngineException
query - The query to retrieve the metadata from.DatabaseEngineException - If something occurs getting the metadata.Map<String,DbColumnType> getQueryMetadata(String query) throws DatabaseEngineException
query - The query to retrieve the metadata from.DatabaseEngineException - If something occurs getting the metadata.DatabaseEngine duplicate(Properties mergeProperties, boolean copyEntities) throws DuplicateEngineException
mergeProperties - Merge properties with the ones already existing.copyEntities - true to include the entities in the new connection, false otherwise.DuplicateEngineException - If policy is set to other than 'create' or 'none' or duplication fails for some reason.PdbProperties getProperties()
void createPreparedStatement(String name, Expression query) throws NameAlreadyExistsException, DatabaseEngineException
name - The prepared statement name.query - The query.NameAlreadyExistsException - If the name already exists.DatabaseEngineException - If something goes wrong creating the statement.void createPreparedStatement(String name, String query) throws NameAlreadyExistsException, DatabaseEngineException
name - The prepared statement name.query - The query.NameAlreadyExistsException - If the name already exists.DatabaseEngineException - If something goes wrong creating the statement.void createPreparedStatement(String name, Expression query, int timeout) throws NameAlreadyExistsException, DatabaseEngineException
name - The prepared statement name.query - The query.timeout - The timeout (in seconds) for the query to execute.NameAlreadyExistsException - If the name already exists.DatabaseEngineException - If something goes wrong creating the statement.void createPreparedStatement(String name, String query, int timeout) throws NameAlreadyExistsException, DatabaseEngineException
name - The prepared statement name.query - The query.timeout - The timeout (in seconds) for the query to execute.NameAlreadyExistsException - If the name already exists.DatabaseEngineException - If something goes wrong creating the statement.void removePreparedStatement(String name)
name - The prepared statement name.List<Map<String,ResultColumn>> getPSResultSet(String name) throws DatabaseEngineException, ConnectionResetException
name - The prepared statement name.DatabaseEngineException - If something occurs getting the result.ConnectionResetExceptionvoid setParameters(String name, Object... params) throws DatabaseEngineException, ConnectionResetException
name - The prepared statement name.params - The parameters to set.DatabaseEngineException - If something occurs setting the parameters.ConnectionResetException - If the connection was reset while trying to set parameters.void setParameter(String name, int index, Object param) throws DatabaseEngineException, ConnectionResetException
name - The prepared statement name.index - The index to set.param - The parameter to set.DatabaseEngineException - If something occurs setting the parameters.ConnectionResetException - If the connection was reset while trying to set the parameter.void setParameter(String name, int index, Object param, DbColumnType paramType) throws DatabaseEngineException, ConnectionResetException
name - The prepared statement name.index - The index to set.param - The parameter to set.paramType - The type of the parameter being set.DatabaseEngineException - If something occurs setting the parameters.ConnectionResetException - If the connection was reset while trying to set the parameter.void executePS(String name) throws DatabaseEngineException, ConnectionResetException
name - The prepared statement name.DatabaseEngineException - If something goes wrong while executing.ConnectionResetException - If the connection is down and reestablishment occurs. If this happens, the user must reset the
parameters and re-execute the query.void clearParameters(String name) throws DatabaseEngineException, ConnectionResetException
name - The prepared statement name.DatabaseEngineException - If something occurs while clearing the parameters.ConnectionResetException - If the connection was reset.boolean preparedStatementExists(String name)
name - The name to test.true if it exists, false otherwise.Integer executePSUpdate(String name) throws DatabaseEngineException, ConnectionResetException
name - The prepared statement name.DatabaseEngineException - If the prepared statement does not exist or something goes wrong while executing.ConnectionResetException - If the connection is down and reestablishment occurs. If this happens, the user must reset the
parameters and re-execute the query.String commentCharacter()
String escapeCharacter()
Connection getConnection() throws RetryLimitExceededException, InterruptedException, RecoveryException
RetryLimitExceededException - If the retry limit is exceeded.InterruptedException - If the thread is interrupted during reconnection.RecoveryExceptionResultIterator iterator(String query) throws DatabaseEngineException
query - The query.DatabaseEngineException - If a database access error occurs.ResultIterator iterator(Expression query) throws DatabaseEngineException
query - The expression that represents the query.DatabaseEngineException - If a database access error occurs.ResultIterator iterator(String query, int fetchSize) throws DatabaseEngineException
query - The query.fetchSize - The number of rows to fetch each time.DatabaseEngineException - If a database access error occurs.default ResultIterator iterator(String query, int fetchSize, int readTimeoutOverride) throws DatabaseEngineException
PdbProperties.getSelectQueryTimeout()) if the underlying engine
supports query timeouts.query - The query.fetchSize - The number of rows to fetch each time.readTimeoutOverride - The query timeout to use.DatabaseEngineException - If a database access error occurs.ResultIterator iterator(Expression query, int fetchSize) throws DatabaseEngineException
query - The expression that represents the query.fetchSize - The number of rows to fetch each time.DatabaseEngineException - If a database access error occurs.default ResultIterator iterator(Expression query, int fetchSize, int readTimeoutOverride) throws DatabaseEngineException
PdbProperties.getSelectQueryTimeout()) if the underlying engine
supports query timeouts.query - The expression that represents the query.fetchSize - The number of rows to fetch each time.readTimeoutOverride - The query timeout to use.DatabaseEngineException - If a database access error occurs.ResultIterator getPSIterator(String name) throws DatabaseEngineException, ConnectionResetException
PreparedStatement bound to the given name.name - The name of the prepared statement.DatabaseEngineException - If a database access error occurs.ConnectionResetExceptionResultIterator getPSIterator(String name, int fetchSize) throws DatabaseEngineException, ConnectionResetException
PreparedStatement bound to the given name.name - The name of the prepared statement.fetchSize - The number of rows to fetch each time.DatabaseEngineException - If a database access error occurs.ConnectionResetExceptionvoid setExceptionHandler(ExceptionHandler eh)
eh - The reference for exception callbacks.boolean isStringAggDistinctCapable()
Copyright © 2021 Feedzai. All rights reserved.