public interface DatabaseEngine
Provides a set of functions to interact with the database.
| Modifier and Type | Method and Description |
|---|---|
void |
addBatch(String name,
EntityEntry entry)
Add 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.
|
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.
|
void |
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.
|
Dialect |
getDialect() |
Map<String,DbEntityType> |
getEntities()
Gets the database entities.
|
Map<String,DbColumnType> |
getMetadata(String name)
Gets the table metadata.
|
PdbProperties |
getProperties() |
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() |
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 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 |
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.DatabaseEngineRuntimeExceptionvoid 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.DatabaseEngineExceptionDbEntity 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.DatabaseEngineExceptionLong 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.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.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.DatabaseEngineRuntimeExceptionvoid rollback()
throws DatabaseEngineRuntimeException
beginTransaction().DatabaseEngineRuntimeException - If the rollback fails.boolean isTransactionActive()
throws DatabaseEngineRuntimeException
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)
Creates a new batch that periodically flushes a batch. A flush will also occur when the maximum number of statements in the batch is reached.
Please be sure to call 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.boolean checkConnection(boolean forceReconnect)
forceReconnect - True to force the connection in case of failure.boolean checkConnection()
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.void 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()
Copyright © 2013. All Rights Reserved.