public interface DatabaseEngine
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.
|
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(String entity)
Drops an entity.
|
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.
|
Map<String,DbColumnType> |
getMetadata(String name)
Gets the table metadata.
|
PdbProperties |
getProperties()
Gets the properties in use.
|
ResultIterator |
getPSIterator(String name)
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 |
isTransactionActive()
Checks if a transaction is active.
|
ResultIterator |
iterator(Expression query)
Creates an iterator for the given SQL expression.
|
ResultIterator |
iterator(String query)
Creates an iterator for the given SQL sentence.
|
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.
|
List<Map<String,ResultColumn>> |
query(String query)
Executes the given native query.
|
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 |
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()
void beginTransaction() throws DatabaseEngineRuntimeException
Connection.getAutoCommit()
).DatabaseEngineException
- If something goes wrong while persisting data.DatabaseEngineRuntimeException
void addEntity(DbEntity entity) throws DatabaseEngineException
entity
- The entity to add.DatabaseEngineException
- If something goes wrong while creating the structures.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
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
Long persist(String name, EntityEntry entry) throws DatabaseEngineException
Persists a given entry. Persisting a query implies executing the statement.
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()
.DatabaseEngineException
- If something goes wrong while persisting data.DatabaseEngineRuntimeException
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.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.List<Map<String,ResultColumn>> query(String query) throws DatabaseEngineException
query
- The query to execute.DatabaseEngineException
- If something goes wrong executing the query.Map<String,DbEntityType> getEntities() throws DatabaseEngineException
DatabaseEngineException
- If something occurs getting the existing tables.Map<String,DbColumnType> getMetadata(String name) throws DatabaseEngineException
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
name
- The prepared statement name.DatabaseEngineException
- If something occurs getting the result.void 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 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.RecoveryException
ResultIterator 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 getPSIterator(String name) throws DatabaseEngineException
PreparedStatement
bound to the given name.name
- The name of the prepared statement.DatabaseEngineException
void setExceptionHandler(ExceptionHandler eh)
eh
- The reference for exception callbacks.Copyright © 2014 Feedzai. All Rights Reserved.