Class AbstractDatabaseEngine
- java.lang.Object
-
- com.feedzai.commons.sql.abstraction.engine.AbstractDatabaseEngine
-
- All Implemented Interfaces:
DatabaseEngine,AutoCloseable
- Direct Known Subclasses:
DB2Engine,H2Engine,MySqlEngine,OracleEngine,PostgreSqlEngine,SqlServerEngine
public abstract class AbstractDatabaseEngine extends Object implements DatabaseEngine
Provides a set of functions to interact with the database.This Engine already provides thread safeness to all public exposed methods
- Since:
- 2.0.0
- Author:
- Rui Vilao (rui.vilao@feedzai.com)
-
-
Field Summary
Fields Modifier and Type Field Description protected ConnectionconnThe database connection.protected StringcurrentSchemaThe current schema that's being used by the engine.static QueryExceptionHandlerDEFAULT_QUERY_EXCEPTION_HANDLERThe default instance ofQueryExceptionHandlerto be used in disambiguating SQL exceptions.protected static org.slf4j.MarkerdevThe dev Marker.protected DialectdialectThe dialect.protected ExceptionHandlerehThe exception handler to control the flow when defining new entities.protected Map<String,MappedEntity>entitiesMap of entities.protected com.google.inject.InjectorinjectorThe Guice injector.protected org.slf4j.LoggerloggerThe logger that will be used.protected org.slf4j.LoggernotificationLoggerThe notification logger for administration.protected PdbPropertiespropertiesThe configuration.protected ExecutorServicesocketTimeoutExecutorAnExecutorServiceto be used by the DB drivers to break a connection if it has been blocked for longer than the specified socket timeoutprotected Map<String,PreparedStatementCapsule>stmtsMap of prepared statements.protected AbstractTranslatortranslatorThe translator in place.
-
Constructor Summary
Constructors Constructor Description AbstractDatabaseEngine(String driver, PdbProperties properties, Dialect dialect)Creates a new instance ofAbstractDatabaseEngine.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddBatch(String name, EntityEntry entry)Add an entry to the batch.protected abstract voidaddColumn(DbEntity entity, DbColumn... columns)Adds the column to an existent table.voidaddEntity(DbEntity entity)Adds an entity to the engine.protected voidaddFks(DbEntity entity)Adds all foreign keys defined in the entity to the table in the database.protected voidaddFks(DbEntity entity, Set<DbFk> fks)Adds foreign key constraints to the table in the database that the provided entity represents.protected abstract voidaddIndexes(DbEntity entity)Add the desired indexes.protected abstract voidaddPrimaryKey(DbEntity entity)Add a primary key to the entity.protected abstract voidaddSequences(DbEntity entity)Adds the necessary sequences.voidbeginTransaction()Starts a transaction.booleancheckConnection()Checks if the connection is alive.booleancheckConnection(boolean forceReconnect)Checks if the connection is alive.protected booleancheckConnection(Connection conn)Checks if the connection is alive.voidclearParameters(String name)Clears the prepared statement parameters.voidclose()Closes the connection to the database.StringcommentCharacter()voidcommit()Commits the current transaction.protected voidconnect()Connects to the database.booleancontainsEntity(String name)Returns if the current engine contains the entity.AbstractBatchcreateBatch(int batchSize, long batchTimeout)Creates a new batch that periodically flushes a batch.AbstractBatchcreateBatch(int batchSize, long batchTimeout, String batchName)Creates a new batch that periodically flushes a batch.AbstractBatchcreateBatch(int batchSize, long batchTimeout, String batchName, FailureListener failureListener)Creates a new batch that periodically flushes a batch.AbstractBatchcreateBatch(int batchSize, long batchTimeout, String batchName, BatchListener batchListener)Creates a new batch that periodically flushes a batch.voidcreatePreparedStatement(String name, Expression query)Creates a prepared statement.voidcreatePreparedStatement(String name, Expression query, int timeout)Creates a prepared statement.voidcreatePreparedStatement(String name, String query)Creates a prepared statement.voidcreatePreparedStatement(String name, String query, int timeout)Creates a prepared statement.protected abstract MappedEntitycreatePreparedStatementForInserts(DbEntity entity)Creates and gets the prepared statement that will be used for insertions.protected abstract ResultIteratorcreateResultIterator(PreparedStatement ps)Creates a specificResultIteratorfor the engine in place given a prepared statement.protected abstract ResultIteratorcreateResultIterator(Statement statement, String sql)Creates a specificResultIteratorgiven the engine implementation.protected StatementcreateSelectStatement(int readTimeout)Creates aStatementthat will be used for selects, i.e., may have an associated read timeout.protected abstract voidcreateTable(DbEntity entity)Creates the table.protected abstract longdoPersist(PreparedStatement ps, MappedEntity me, boolean useAutoInc, int lastBindPosition)DB engine specific auxiliary method forpersist(String, EntityEntry, boolean)to effectively perform the persist action.protected abstract voiddropColumn(DbEntity entity, String... columns)Drops the column.voiddropEntity(DbEntity entity)Drops everything that belongs to the entity.voiddropEntity(String entity)Drops an entity.protected StringdropFkQuery(String table, String fkName)Gets the query to drop a foreign key.protected voiddropFks(String table)Drops all foreign keys from the table.protected voiddropFks(String table, Set<String> fks)Drops foreign keys from a table.protected abstract voiddropSequences(DbEntity entity)Drops the sequences of the entity.protected abstract voiddropTable(DbEntity entity)Drops the table.voiddropView(String view)Drops a view.DatabaseEngineduplicate(Properties mergeProperties, boolean copyEntities)Duplicates a connection.protected abstract intentityToPreparedStatement(DbEntity entity, PreparedStatement ps, EntityEntry entry, boolean useAutoIncs)Translates the given entry entity to the prepared statement.protected intentityToPreparedStatementForBatch(DbEntity entity, PreparedStatement ps, EntityEntry entry, boolean useAutoIncs)Translates the given entry entity to the prepared statement when used in the context of batch updates.StringescapeCharacter()voidexecutePS(String name)Executes the specified prepared statement.IntegerexecutePSUpdate(String name)Executes update on the specified prepared statement.intexecuteUpdate(Expression query)Executes the given update.intexecuteUpdate(String query)Executes a native query.protected voidexecuteUpdateSilently(String statement)Executes the given statement.voidflush()Flushes the batches for all the registered entities.ConnectiongetConnection()Checks if the connection is available and returns it.protected PropertiesgetDBProperties()Get the properties to be passed to the database connection that will be created.DialectgetDialect()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.protected StringgetFinalJdbcConnection(String jdbc)Gets the final JDBC connection.protected ResultSetgetImportedKeys(String entityName)Gets a description of the columns that are referenced by the given table's foreign key columns.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).protected PreparedStatementgetPreparedStatementForPersist(boolean useAutoInc, MappedEntity mappedEntity)Gets thePreparedStatementto use in a persist operation, depending on whether autoInc is to be used or not.protected StringgetPrivateKey()Reads the private key from the secret location.PdbPropertiesgetProperties()Gets the properties in use.ResultIteratorgetPSIterator(String name)Creates an iterator for thePreparedStatementbound to the given name.ResultIteratorgetPSIterator(String name, int fetchSize)Creates an iterator for thePreparedStatementbound to the given name.List<Map<String,ResultColumn>>getPSResultSet(String name)Gets the result set of the specified prepared statement.protected QueryExceptionHandlergetQueryExceptionHandler()Gets the instance ofQueryExceptionHandlerto be used in disambiguating SQL exceptions.Map<String,DbColumnType>getQueryMetadata(Expression query)Gets the query metadata.Map<String,DbColumnType>getQueryMetadata(String query)Gets the query metadata.StringgetSchema()Gets the schema being used in the currentconnection.abstract Class<? extends AbstractTranslator>getTranslatorClass()Gets the class that translates SQL bound to this engine.protected voidhandleOperation(OperationFault opFault, Exception exception)Controls if the given faulty operation must be silenced or not.booleanhasIdentityColumn(DbEntity entity)Check if the entity has an identity column.protected voidinject(Expression... objs)booleanisTransactionActive()Checks if a transaction is active.ResultIteratoriterator(Expression query)Creates an iterator for the given SQL expression.ResultIteratoriterator(Expression query, int fetchSize)Creates an iterator for the given SQL expression.ResultIteratoriterator(Expression query, int fetchSize, int readTimeoutOverride)Creates an iterator for the given SQL expression overriding the configured query timeout (seePdbProperties.getSelectQueryTimeout()) if the underlying engine supports query timeouts.ResultIteratoriterator(String query)Creates an iterator for the given SQL sentence.ResultIteratoriterator(String query, int fetchSize)Creates an iterator for the given SQL sentence.ResultIteratoriterator(String query, int fetchSize, int readTimeoutOverride)Creates an iterator for the given SQL sentence overriding the configured query timeout (seePdbProperties.getSelectQueryTimeout()) if the underlying engine supports query timeouts.voidloadEntity(DbEntity entity)Loads an entity into the engine.protected byte[]objectToArray(Object val)Converts an object to byte array.Longpersist(String name, EntityEntry entry)Persists a given entry.Longpersist(String name, EntityEntry entry, boolean useAutoInc)Persists a given entry.booleanpreparedStatementExists(String name)Checks if there's a prepared statement with the given name.protected List<Map<String,ResultColumn>>processResultIterator(ResultIterator it)Process a wholeResultIterator.List<Map<String,ResultColumn>>query(Expression query)Executes the given query.List<Map<String,ResultColumn>>query(Expression query, int readTimeoutOverride)Executes the given query overriding the configured query timeout (seePdbProperties.getSelectQueryTimeout()) if the underlying engine supports query timeouts.List<Map<String,ResultColumn>>query(String query)Executes the given query.List<Map<String,ResultColumn>>query(String query, int readTimeoutOverride)Executes the given native query overriding the configured query timeout (seePdbProperties.getSelectQueryTimeout()if the underlying engine supports query timeouts.protected voidreconnectExceptionally(String message)Verifies if a connection to the database is available, if not, an attempts to reestablished it are made by thegetConnection().DbEntityremoveEntity(String name)Removes the entity given the name.voidremovePreparedStatement(String name)Removes the given prepared statement.voidrollback()Rolls back a transaction.voidsetExceptionHandler(ExceptionHandler eh)Sets the given exception handler in the engine.voidsetParameter(String name, int index, Object param)Sets the parameter on the specified index.voidsetParameter(String name, int index, Object param, DbColumnType paramType)Sets the parameter on the specified index given its type.voidsetParameters(String name, Object... params)Sets the parameters on the specified prepared statement.protected voidsetParameterValues(PreparedStatement ps, int index, Object param)Sets the value of a parameter inindexto the value provided inparam.protected voidsetSchema(String schema)Sets the schema for the currentconnection.protected voidsetTransactionIsolation()Sets the transaction isolation level.protected DbColumnTypetoPdbType(int type, String typeName)Maps the database type toDbColumnType.Stringtranslate(Expression query)Translates the given expression to the current dialect.protected StringtranslateType(DbColumn column)Translates the type present in the given column.voidupdateEntity(DbEntity entity)Updates an entity in the engine.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.feedzai.commons.sql.abstraction.engine.DatabaseEngine
isStringAggDistinctCapable
-
-
-
-
Field Detail
-
injector
@Inject protected com.google.inject.Injector injector
The Guice injector.
-
translator
@Inject protected AbstractTranslator translator
The translator in place.
-
conn
protected Connection conn
The database connection.
-
dev
protected static final org.slf4j.Marker dev
The dev Marker.
-
logger
protected final org.slf4j.Logger logger
The logger that will be used.
-
notificationLogger
protected final org.slf4j.Logger notificationLogger
The notification logger for administration.
-
entities
protected final Map<String,MappedEntity> entities
Map of entities.
-
stmts
protected final Map<String,PreparedStatementCapsule> stmts
Map of prepared statements.
-
currentSchema
protected String currentSchema
The current schema that's being used by the engine.- Since:
- 2.1.13
-
properties
protected final PdbProperties properties
The configuration.
-
dialect
protected final Dialect dialect
The dialect.
-
eh
protected ExceptionHandler eh
The exception handler to control the flow when defining new entities.
-
socketTimeoutExecutor
protected final ExecutorService socketTimeoutExecutor
AnExecutorServiceto be used by the DB drivers to break a connection if it has been blocked for longer than the specified socket timeout
-
DEFAULT_QUERY_EXCEPTION_HANDLER
public static final QueryExceptionHandler DEFAULT_QUERY_EXCEPTION_HANDLER
The default instance ofQueryExceptionHandlerto be used in disambiguating SQL exceptions.- Since:
- 2.5.1
-
-
Constructor Detail
-
AbstractDatabaseEngine
public AbstractDatabaseEngine(String driver, PdbProperties properties, Dialect dialect) throws DatabaseEngineException
Creates a new instance ofAbstractDatabaseEngine.- Parameters:
driver- The driver to connect to the database.properties- The properties of the connection.dialect- The dialect in use.- Throws:
DatabaseEngineException- When errors occur trying to set up the database connection.
-
-
Method Detail
-
getPrivateKey
protected String getPrivateKey() throws Exception
Reads the private key from the secret location.- Returns:
- A string with the private key.
- Throws:
Exception- If something occurs while reading.
-
getDBProperties
protected Properties getDBProperties()
Get the properties to be passed to the database connection that will be created. Since these properties are specific to the database engine, it is up to theAbstractDatabaseEngineimplementation to specify them. This is used, for instance, to set the database connection timeout.- Returns:
- the properties of the connection to the database.
-
connect
protected void connect() throws ExceptionConnects to the database.- Throws:
Exception- If connection is not possible, or failed to decrypt username/password if encryption was provided.
-
getFinalJdbcConnection
protected String getFinalJdbcConnection(String jdbc)
Gets the final JDBC connection.Implementations might override this method in order to change the JDBC connection.
- Parameters:
jdbc- The current JDBC connection.- Returns:
- The final JDBC connection.
-
setTransactionIsolation
protected void setTransactionIsolation() throws SQLExceptionSets the transaction isolation level.- Throws:
SQLException- If a database access error occurs.
-
getTranslatorClass
public abstract Class<? extends AbstractTranslator> getTranslatorClass()
Gets the class that translates SQL bound to this engine.- Returns:
- The class that translates SQL bound to this engine.
-
getConnection
public Connection getConnection() throws RetryLimitExceededException, InterruptedException, RecoveryException
Checks if the connection is available and returns it. If the connection is not available, it tries to reconnect (the number of times defined in the properties with the delay there specified).- Specified by:
getConnectionin interfaceDatabaseEngine- Returns:
- The connection.
- Throws:
RetryLimitExceededException- If the retry limit is exceeded.InterruptedException- If the thread is interrupted during reconnection.RecoveryException
-
close
public void close()
Closes the connection to the database.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceDatabaseEngine
-
beginTransaction
public void beginTransaction() throws DatabaseEngineRuntimeExceptionStarts a transaction. Doing this will set auto commit to false (Connection.getAutoCommit()).- Specified by:
beginTransactionin interfaceDatabaseEngine- Throws:
DatabaseEngineRuntimeException- If something goes wrong while beginning transaction.
-
addEntity
public void addEntity(DbEntity entity) throws DatabaseEngineException
Adds an entity to the engine. It will create tables and everything necessary so persistence can work.- Specified by:
addEntityin interfaceDatabaseEngine- Parameters:
entity- The entity to add.- Throws:
DatabaseEngineException- If something goes wrong while creating the structures.
-
loadEntity
public void loadEntity(DbEntity entity) throws DatabaseEngineException
Description copied from interface:DatabaseEngineLoads an entity into the engine.No DDL commands will be executed, only prepared statements will be created in order to
persistdata into the entities.- Specified by:
loadEntityin interfaceDatabaseEngine- Parameters:
entity- The entity to load into the connection.- Throws:
DatabaseEngineException- If something goes wrong while loading the entity.
-
updateEntity
public void updateEntity(DbEntity entity) throws DatabaseEngineException
Updates an entity in the engine.If the entity does not exist in the instance, the method
addEntity(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. It will also drop and create foreign keys. Primary Keys, Indexes and column types changes will not be updated.
- Specified by:
updateEntityin interfaceDatabaseEngine- Parameters:
entity- The entity to update.- Throws:
DatabaseEngineException- If something goes wrong while updating the entity.- Since:
- 2.0.0
-
getImportedKeys
protected ResultSet getImportedKeys(String entityName) throws DatabaseEngineException, SQLException
Gets a description of the columns that are referenced by the given table's foreign key columns.- Parameters:
entityName- The entity name.- Returns:
- A
ResultSetcontaining information about columns referenced by a foreign key. - Throws:
DatabaseEngineException- If it isn't possible to get current database metadata.SQLException- If a database access error occurs when getting key information.
-
removeEntity
public DbEntity removeEntity(String name)
Description copied from interface:DatabaseEngineRemoves the entity given the name. If the schema is drop-create then the entity will be dropped.- Specified by:
removeEntityin interfaceDatabaseEngine- Parameters:
name- The name of the entity to remove.- Returns:
- The entity removed or null if there's no entity with the given name.
-
containsEntity
public boolean containsEntity(String name)
Description copied from interface:DatabaseEngineReturns if the current engine contains the entity.- Specified by:
containsEntityin interfaceDatabaseEngine- Parameters:
name- The entity name.- Returns:
- True if the engine has the entity, false otherwise.
-
dropEntity
public void dropEntity(String entity) throws DatabaseEngineException
Drops an entity.- Specified by:
dropEntityin interfaceDatabaseEngine- Parameters:
entity- The entity name.- Throws:
DatabaseEngineException- If something goes wrong while dropping the entity.
-
dropEntity
public void dropEntity(DbEntity entity) throws DatabaseEngineException
Drops everything that belongs to the entity.- Specified by:
dropEntityin interfaceDatabaseEngine- Parameters:
entity- The entity.- Throws:
DatabaseEngineException- If something goes wrong while dropping the structures.
-
dropView
public void dropView(String view) throws DatabaseEngineException
Description copied from interface:DatabaseEngineDrops a view.- Specified by:
dropViewin interfaceDatabaseEngine- Parameters:
view- The view name.- Throws:
DatabaseEngineException- If something goes wrong while dropping the view.
-
persist
public 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.
- Specified by:
persistin interfaceDatabaseEngine- Parameters:
name- The entity name.entry- The entry to persist.- Returns:
- The ID of the auto generated value, null if there's no auto generated value.
- Throws:
DatabaseEngineException- If something goes wrong while persisting data.
-
persist
public final 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.
- Specified by:
persistin interfaceDatabaseEngine- Parameters:
name- The entity name.entry- The entry to persist.useAutoInc- Use or not the autoinc.- Returns:
- The ID of the auto generated value, null if there's no auto generated value.
- Throws:
DatabaseEngineException- If something goes wrong while persisting data.
-
getPreparedStatementForPersist
protected PreparedStatement getPreparedStatementForPersist(boolean useAutoInc, MappedEntity mappedEntity)
Gets thePreparedStatementto use in a persist operation, depending on whether autoInc is to be used or not.- Parameters:
useAutoInc- Whether to use autoInc.mappedEntity- The mapped entity for which to get the prepared statement.- Returns:
- the
PreparedStatement. - Since:
- 2.5.1
-
doPersist
protected abstract long doPersist(PreparedStatement ps, MappedEntity me, boolean useAutoInc, int lastBindPosition) throws Exception
DB engine specific auxiliary method forpersist(String, EntityEntry, boolean)to effectively perform the persist action.- Parameters:
ps- ThePreparedStatementto use in the persist operationme- The mapped entity on which to persist.useAutoInc- Whether to use autoInc.lastBindPosition- The position (1-based) of the last bind parameter that was filled in the prepared statement.- Returns:
- The ID of the auto generated value (
0if there's no auto generated value). If the table has more than 1 column with auto generated values, then it will return the first column found. - Throws:
Exception- if any problem occurs while persisting.- Since:
- 2.5.1
-
flush
public void flush() throws DatabaseEngineExceptionFlushes the batches for all the registered entities.- Specified by:
flushin interfaceDatabaseEngine- Throws:
DatabaseEngineException- If something goes wrong while persisting data.
-
commit
public void commit() throws DatabaseEngineRuntimeExceptionCommits the current transaction. You should only call this method if you've previously calledbeginTransaction().- Specified by:
commitin interfaceDatabaseEngine- Throws:
DatabaseEngineRuntimeException- If something goes wrong while persisting data.
-
rollback
public void rollback() throws DatabaseEngineRuntimeExceptionRolls back a transaction. You should only call this method if you've previously calledbeginTransaction().- Specified by:
rollbackin interfaceDatabaseEngine- Throws:
DatabaseEngineRuntimeException- If the rollback fails.
-
isTransactionActive
public boolean isTransactionActive() throws DatabaseEngineRuntimeExceptionDescription copied from interface:DatabaseEngineChecks if a transaction is active.- Specified by:
isTransactionActivein interfaceDatabaseEngine- Returns:
- True if the transaction is active.
- Throws:
DatabaseEngineRuntimeException- If the access to the database fails.
-
executeUpdate
public int executeUpdate(String query) throws DatabaseEngineException
Executes a native query.- Specified by:
executeUpdatein interfaceDatabaseEngine- Parameters:
query- The query to execute.- Returns:
- The number of rows updated.
- Throws:
DatabaseEngineException- If something goes wrong executing the native query.
-
createSelectStatement
protected Statement createSelectStatement(int readTimeout) throws SQLException
Creates aStatementthat will be used for selects, i.e., may have an associated read timeout.- Parameters:
readTimeout- The timeout.- Returns:
- The
Statement - Throws:
SQLException- If there is an error creating the statement.
-
executeUpdate
public int executeUpdate(Expression query) throws DatabaseEngineException
Executes the given update.- Specified by:
executeUpdatein interfaceDatabaseEngine- Parameters:
query- The update to execute.- Throws:
DatabaseEngineException- If something goes wrong executing the update.
-
translate
public String translate(Expression query)
Translates the given expression to the current dialect.- Specified by:
translatein interfaceDatabaseEngine- Parameters:
query- The query to translate.- Returns:
- The translation result.
-
getDialect
public Dialect getDialect()
Description copied from interface:DatabaseEngineGets the dialect being used.- Specified by:
getDialectin interfaceDatabaseEngine- Returns:
- The dialect being in use.
-
createBatch
public 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- Specified by:
createBatchin interfaceDatabaseEngine- Parameters:
batchSize- The batch size.batchTimeout- If inserts do not occur after the specified time, a flush will be performed.- Returns:
- The batch.
-
createBatch
public AbstractBatch createBatch(int batchSize, long batchTimeout, String batchName)
Description copied from interface:DatabaseEngineCreates 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 callAbstractBatch.destroy()before closing the session with the database.- Specified by:
createBatchin interfaceDatabaseEngine- Parameters:
batchSize- The batch size.batchTimeout- If inserts do not occur after the specified time, a flush will be performed.batchName- The batch name.- Returns:
- The batch.
-
createBatch
public AbstractBatch createBatch(int batchSize, long batchTimeout, String batchName, FailureListener failureListener)
Description copied from interface:DatabaseEngineCreates a new batch that periodically flushes a batch. A flush will also occur when the maximum number of statements in the batch is reached.If desired you may provide an
Please be sure to callOptionalFailureListenerthat will be invoked when the batch fails to persist data.AbstractBatch.destroy()before closing the session with the database.- Specified by:
createBatchin interfaceDatabaseEngine- Parameters:
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.- Returns:
- The batch.
-
createBatch
public AbstractBatch createBatch(int batchSize, long batchTimeout, String batchName, @Nullable BatchListener batchListener)
Description copied from interface:DatabaseEngineCreates a new batch that periodically flushes a batch. A flush will also occur when the maximum number of statements in the batch is reached.If desired you may provide a
Please be sure to callBatchListenerthat will be invoked when a batch operation fails or succeeds to persist data.AbstractBatch.destroy()before closing the session with the database.- Specified by:
createBatchin interfaceDatabaseEngine- Parameters:
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.- Returns:
- The batch.
-
checkConnection
protected boolean checkConnection(Connection conn)
Checks if the connection is alive.- Parameters:
conn- The connection to test.- Returns:
- True if the connection is valid, false otherwise.
-
checkConnection
public boolean checkConnection(boolean forceReconnect)
Checks if the connection is alive.- Specified by:
checkConnectionin interfaceDatabaseEngine- Parameters:
forceReconnect- True to force the connection in case of failure.- Returns:
- True if the connection is valid, false otherwise.
-
checkConnection
public boolean checkConnection()
Checks if the connection is alive.- Specified by:
checkConnectionin interfaceDatabaseEngine- Returns:
- True if the connection is valid, false otherwise.
-
addBatch
public void addBatch(String name, EntityEntry entry) throws DatabaseEngineException
Add an entry to the batch.- Specified by:
addBatchin interfaceDatabaseEngine- Parameters:
name- The entity name.entry- The entry to persist.- Throws:
DatabaseEngineException- If something goes wrong while persisting data.
-
entityToPreparedStatementForBatch
protected int entityToPreparedStatementForBatch(DbEntity entity, PreparedStatement ps, EntityEntry entry, boolean useAutoIncs) throws DatabaseEngineException
Translates the given entry entity to the prepared statement when used in the context of batch updates. This is to be overriden on engines where a distinct treatment is required for these situations.- Parameters:
entity- The entity.ps- The prepared statement.entry- The entry.- Returns:
- The position (1-based) of the last bind parameter that was filled in a prepared statement.
- Throws:
DatabaseEngineException- if something occurs during the translation.- Since:
- 2.4.2
-
entityToPreparedStatement
protected abstract int entityToPreparedStatement(DbEntity entity, PreparedStatement ps, EntityEntry entry, boolean useAutoIncs) throws DatabaseEngineException
Translates the given entry entity to the prepared statement.- Parameters:
entity- The entity.ps- The prepared statement.entry- The entry.- Returns:
- The position (1-based) of the last bind parameter that was filled in a prepared statement.
- Throws:
DatabaseEngineException- if something occurs during the translation.
-
query
public List<Map<String,ResultColumn>> query(Expression query) throws DatabaseEngineException
Executes the given query.- Specified by:
queryin interfaceDatabaseEngine- Parameters:
query- The query to execute.- Throws:
DatabaseEngineException- If something goes wrong executing the query.
-
query
public List<Map<String,ResultColumn>> query(Expression query, int readTimeoutOverride) throws DatabaseEngineException
Description copied from interface:DatabaseEngineExecutes the given query overriding the configured query timeout (seePdbProperties.getSelectQueryTimeout()) if the underlying engine supports query timeouts.- Specified by:
queryin interfaceDatabaseEngine- Parameters:
query- The query to execute.readTimeoutOverride- The query timeout to use.- Throws:
DatabaseEngineException- If something goes wrong executing the query.
-
query
public List<Map<String,ResultColumn>> query(String query) throws DatabaseEngineException
Executes the given query.- Specified by:
queryin interfaceDatabaseEngine- Parameters:
query- The query to execute.- Throws:
DatabaseEngineException- If something goes wrong executing the query.
-
query
public List<Map<String,ResultColumn>> query(String query, int readTimeoutOverride) throws DatabaseEngineException
Description copied from interface:DatabaseEngineExecutes the given native query overriding the configured query timeout (seePdbProperties.getSelectQueryTimeout()if the underlying engine supports query timeouts.- Specified by:
queryin interfaceDatabaseEngine- Parameters:
query- The query to execute.readTimeoutOverride- The query timeout to use.- Throws:
DatabaseEngineException- If something goes wrong executing the query.
-
processResultIterator
protected List<Map<String,ResultColumn>> processResultIterator(ResultIterator it) throws DatabaseEngineException
Process a wholeResultIterator.- Parameters:
it- The iterator.- Returns:
- A list of rows in the form of
Map. - Throws:
DatabaseEngineException- If a database access error occurs.
-
iterator
public ResultIterator iterator(String query) throws DatabaseEngineException
Description copied from interface:DatabaseEngineCreates an iterator for the given SQL sentence.- Specified by:
iteratorin interfaceDatabaseEngine- Parameters:
query- The query.- Returns:
- An iterator for the results of the given SQL query.
- Throws:
DatabaseEngineException- If a database access error occurs.
-
iterator
public ResultIterator iterator(Expression query) throws DatabaseEngineException
Description copied from interface:DatabaseEngineCreates an iterator for the given SQL expression.- Specified by:
iteratorin interfaceDatabaseEngine- Parameters:
query- The expression that represents the query.- Returns:
- An iterator for the results of the given SQL expression.
- Throws:
DatabaseEngineException- If a database access error occurs.
-
iterator
public ResultIterator iterator(String query, int fetchSize) throws DatabaseEngineException
Description copied from interface:DatabaseEngineCreates an iterator for the given SQL sentence.- Specified by:
iteratorin interfaceDatabaseEngine- Parameters:
query- The query.fetchSize- The number of rows to fetch each time.- Returns:
- An iterator for the results of the given SQL query.
- Throws:
DatabaseEngineException- If a database access error occurs.
-
iterator
public ResultIterator iterator(Expression query, int fetchSize) throws DatabaseEngineException
Description copied from interface:DatabaseEngineCreates an iterator for the given SQL expression.- Specified by:
iteratorin interfaceDatabaseEngine- Parameters:
query- The expression that represents the query.fetchSize- The number of rows to fetch each time.- Returns:
- An iterator for the results of the given SQL expression.
- Throws:
DatabaseEngineException- If a database access error occurs.
-
iterator
public ResultIterator iterator(Expression query, int fetchSize, int readTimeoutOverride) throws DatabaseEngineException
Description copied from interface:DatabaseEngineCreates an iterator for the given SQL expression overriding the configured query timeout (seePdbProperties.getSelectQueryTimeout()) if the underlying engine supports query timeouts.- Specified by:
iteratorin interfaceDatabaseEngine- Parameters:
query- The expression that represents the query.fetchSize- The number of rows to fetch each time.readTimeoutOverride- The query timeout to use.- Returns:
- An iterator for the results of the given SQL expression.
- Throws:
DatabaseEngineException- If a database access error occurs.
-
iterator
public ResultIterator iterator(String query, int fetchSize, int readTimeoutOverride) throws DatabaseEngineException
Description copied from interface:DatabaseEngineCreates an iterator for the given SQL sentence overriding the configured query timeout (seePdbProperties.getSelectQueryTimeout()) if the underlying engine supports query timeouts.- Specified by:
iteratorin interfaceDatabaseEngine- Parameters:
query- The query.fetchSize- The number of rows to fetch each time.readTimeoutOverride- The query timeout to use.- Returns:
- An iterator for the results of the given SQL query.
- Throws:
DatabaseEngineException- If a database access error occurs.
-
createResultIterator
protected abstract ResultIterator createResultIterator(Statement statement, String sql) throws DatabaseEngineException
Creates a specificResultIteratorgiven the engine implementation.- Parameters:
statement- The statement.sql- The SQL sentence.- Returns:
- An iterator for the specific engine.
- Throws:
DatabaseEngineException- If a database access error occurs.
-
createResultIterator
protected abstract ResultIterator createResultIterator(PreparedStatement ps) throws DatabaseEngineException
Creates a specificResultIteratorfor the engine in place given a prepared statement.- Parameters:
ps- The prepared statement.- Returns:
- The result iterator.
- Throws:
DatabaseEngineException- If a database access error occurs.
-
createTable
protected abstract void createTable(DbEntity entity) throws DatabaseEngineException
Creates the table.- Parameters:
entity- The entity.- Throws:
DatabaseEngineException- If something goes wrong while creating the table.
-
addPrimaryKey
protected abstract void addPrimaryKey(DbEntity entity) throws DatabaseEngineException
Add a primary key to the entity.- Parameters:
entity- The entity.- Throws:
DatabaseEngineException- If something goes wrong while creating the table.
-
addIndexes
protected abstract void addIndexes(DbEntity entity) throws DatabaseEngineException
Add the desired indexes.- Parameters:
entity- The entity.- Throws:
DatabaseEngineException- If something goes wrong while creating the table.
-
addSequences
protected abstract void addSequences(DbEntity entity) throws DatabaseEngineException
Adds the necessary sequences.- Parameters:
entity- The entity.- Throws:
DatabaseEngineException- If something goes wrong while creating the table.
-
dropSequences
protected abstract void dropSequences(DbEntity entity) throws DatabaseEngineException
Drops the sequences of the entity.- Parameters:
entity- The entity.- Throws:
DatabaseEngineException- If something goes wrong dropping the sequences.
-
dropTable
protected abstract void dropTable(DbEntity entity) throws DatabaseEngineException
Drops the table.- Parameters:
entity- The entity.- Throws:
DatabaseEngineException- If something goes wrong dropping the sequences.
-
dropColumn
protected abstract void dropColumn(DbEntity entity, String... columns) throws DatabaseEngineException
Drops the column.- Parameters:
entity- The entity.columns- The column name to drop.- Throws:
DatabaseEngineException- If something goes wrong dropping the sequences.- Since:
- 2.0.0
-
addColumn
protected abstract void addColumn(DbEntity entity, DbColumn... columns) throws DatabaseEngineException
Adds the column to an existent table.- Parameters:
entity- The entity that represents the table.columns- The db column to add.- Throws:
DatabaseEngineException- If something goes wrong adding columns.- Since:
- 2.0.0
-
addFks
protected void addFks(DbEntity entity) throws DatabaseEngineException
Adds all foreign keys defined in the entity to the table in the database.- Parameters:
entity- The entity.- Throws:
DatabaseEngineException- If something goes wrong creating the FKs.
-
addFks
protected void addFks(DbEntity entity, Set<DbFk> fks) throws DatabaseEngineException
Adds foreign key constraints to the table in the database that the provided entity represents.- Parameters:
entity- The entity.fks- The foreign keys to be added.- Throws:
DatabaseEngineException- If something goes wrong creating the FKs.- Since:
- 2.8.1
-
createPreparedStatementForInserts
protected abstract MappedEntity createPreparedStatementForInserts(DbEntity entity) throws DatabaseEngineException
Creates and gets the prepared statement that will be used for insertions.- Parameters:
entity- The entity.- Throws:
DatabaseEngineException- If something goes wrong while creating the table.
-
translateType
protected String translateType(DbColumn column) throws DatabaseEngineException
Translates the type present in the given column.- Parameters:
column- The column.- Returns:
- The translation.
- Throws:
DatabaseEngineException- If the type cannot be found.
-
dropFks
protected void dropFks(String table) throws DatabaseEngineException
Drops all foreign keys from the table.- Parameters:
table- The table name.- Throws:
DatabaseEngineException- If something goes wrong dropping the FKs.
-
dropFkQuery
protected String dropFkQuery(String table, String fkName)
Gets the query to drop a foreign key.- Parameters:
table- The table name.fkName- The foreign key name.- Returns:
- The query to drop the foreign key.
- Since:
- 2.8.1
-
dropFks
protected void dropFks(String table, Set<String> fks) throws DatabaseEngineException
Drops foreign keys from a table.- Parameters:
table- The table.fks- The foreign key names to be dropped.- Throws:
DatabaseEngineException- If a foreign key can't be dropped.- Since:
- 2.8.1
-
getEntities
public Map<String,DbEntityType> getEntities() throws DatabaseEngineException
Description copied from interface:DatabaseEngineGets the database entities for the current schema.- Specified by:
getEntitiesin interfaceDatabaseEngine- Returns:
- The list of database entities and types (tables, views, and so on).
- Throws:
DatabaseEngineException- If something occurs getting the existing tables.
-
getEntities
public Map<String,DbEntityType> getEntities(String schemaPattern) throws DatabaseEngineException
Description copied from interface:DatabaseEngineGets the database entities for the specified schema.- Specified by:
getEntitiesin interfaceDatabaseEngine- Parameters:
schemaPattern- A schema name pattern; must match the schema name as it is stored in the database;""retrieves those without a schema;nullmeans that the schema name should not be used to narrow the search.- Returns:
- The list of database entities and types (tables, views, and so on).
- Throws:
DatabaseEngineException- If something occurs getting the existing tables.
-
executeUpdateSilently
protected void executeUpdateSilently(String statement)
Executes the given statement.If the statement for some reason fails to execute, the error is logged but no exception is thrown.
- Parameters:
statement- The statement.
-
getSchema
public String getSchema() throws DatabaseEngineException
Gets the schema being used in the currentconnection.- Returns:
- The current schema name or
nullif there is none. - Throws:
DatabaseEngineException- If a database access error occurs or this method is called on a closed connection.
-
setSchema
protected void setSchema(String schema) throws DatabaseEngineException
Sets the schema for the currentconnection.- Throws:
DatabaseEngineException- If schema doesn't exist, a database access error occurs or this method is called on a closed connection.- Since:
- 2.1.13
-
getMetadata
public Map<String,DbColumnType> getMetadata(String tableNamePattern) throws DatabaseEngineException
Description copied from interface:DatabaseEngineGets the table metadata (table must be in the current schema).- Specified by:
getMetadatain interfaceDatabaseEngine- Parameters:
tableNamePattern- A table name pattern; must match the table name as it is stored in the database.- Returns:
- A representation of the table columns and types.
- Throws:
DatabaseEngineException- If something occurs getting the metadata.
-
getMetadata
public Map<String,DbColumnType> getMetadata(String schemaPattern, String tableNamePattern) throws DatabaseEngineException
Description copied from interface:DatabaseEngineGets the table metadata (table must be in the current schema).- Specified by:
getMetadatain interfaceDatabaseEngine- Parameters:
schemaPattern- A schema name pattern; must match the schema name as it is stored in the database;""retrieves those without a schema;nullmeans that the schema name should not be used to narrow the search.tableNamePattern- A table name pattern; must match the table name as it is stored in the database.- Returns:
- A representation of the table columns and types.
- Throws:
DatabaseEngineException- If something occurs getting the metadata.
-
getQueryMetadata
public Map<String,DbColumnType> getQueryMetadata(Expression query) throws DatabaseEngineException
Gets the query metadata.- Specified by:
getQueryMetadatain interfaceDatabaseEngine- Parameters:
query- The query to retrieve the metadata from.- Returns:
- A representation of the table columns and types.
- Throws:
DatabaseEngineException- If something occurs getting the metadata.
-
getQueryMetadata
public Map<String,DbColumnType> getQueryMetadata(String query) throws DatabaseEngineException
Gets the query metadata.- Specified by:
getQueryMetadatain interfaceDatabaseEngine- Parameters:
query- The query to retrieve the metadata from.- Returns:
- A representation of the table columns and types.
- Throws:
DatabaseEngineException- If something occurs getting the metadata.
-
toPdbType
protected DbColumnType toPdbType(int type, String typeName)
Maps the database type toDbColumnType. If there's no mapping aDbColumnType.UNMAPPEDis returned.- Parameters:
type- The SQL type fromTypes.typeName- The native database type name. It provides additional information for derived classes to resolve types unmapped here.- Returns:
- The
DbColumnType.
-
duplicate
public DatabaseEngine duplicate(Properties mergeProperties, boolean copyEntities) throws DuplicateEngineException
Duplicates a connection.- Specified by:
duplicatein interfaceDatabaseEngine- Parameters:
mergeProperties- Merge properties with the ones already existing.copyEntities- True to include the entities in the new connection, false otherwise.- Returns:
- The new connection.
- Throws:
DuplicateEngineException- If policy is set to other than 'create' or 'none' or duplication fails for some reason.
-
getProperties
public PdbProperties getProperties()
Description copied from interface:DatabaseEngineGets the properties in use.- Specified by:
getPropertiesin interfaceDatabaseEngine- Returns:
- A clone of the properties in use.
-
createPreparedStatement
public void createPreparedStatement(String name, Expression query) throws NameAlreadyExistsException, DatabaseEngineException
Description copied from interface:DatabaseEngineCreates a prepared statement.- Specified by:
createPreparedStatementin interfaceDatabaseEngine- Parameters:
name- The prepared statement name.query- The query.- Throws:
NameAlreadyExistsException- If the name already exists.DatabaseEngineException- If something goes wrong creating the statement.
-
createPreparedStatement
public void createPreparedStatement(String name, String query) throws NameAlreadyExistsException, DatabaseEngineException
Description copied from interface:DatabaseEngineCreates a prepared statement.- Specified by:
createPreparedStatementin interfaceDatabaseEngine- Parameters:
name- The prepared statement name.query- The query.- Throws:
NameAlreadyExistsException- If the name already exists.DatabaseEngineException- If something goes wrong creating the statement.
-
createPreparedStatement
public void createPreparedStatement(String name, Expression query, int timeout) throws NameAlreadyExistsException, DatabaseEngineException
Description copied from interface:DatabaseEngineCreates a prepared statement.- Specified by:
createPreparedStatementin interfaceDatabaseEngine- Parameters:
name- The prepared statement name.query- The query.timeout- The timeout (in seconds) for the query to execute.- Throws:
NameAlreadyExistsException- If the name already exists.DatabaseEngineException- If something goes wrong creating the statement.
-
createPreparedStatement
public void createPreparedStatement(String name, String query, int timeout) throws NameAlreadyExistsException, DatabaseEngineException
Description copied from interface:DatabaseEngineCreates a prepared statement.- Specified by:
createPreparedStatementin interfaceDatabaseEngine- Parameters:
name- The prepared statement name.query- The query.timeout- The timeout (in seconds) for the query to execute.- Throws:
NameAlreadyExistsException- If the name already exists.DatabaseEngineException- If something goes wrong creating the statement.
-
removePreparedStatement
public void removePreparedStatement(String name)
Description copied from interface:DatabaseEngineRemoves the given prepared statement.- Specified by:
removePreparedStatementin interfaceDatabaseEngine- Parameters:
name- The prepared statement name.
-
getPSResultSet
public List<Map<String,ResultColumn>> getPSResultSet(String name) throws DatabaseEngineException, ConnectionResetException
Gets the result set of the specified prepared statement.- Specified by:
getPSResultSetin interfaceDatabaseEngine- Parameters:
name- The prepared statement name.- Returns:
- The result.
- Throws:
DatabaseEngineException- If something occurs getting the result.ConnectionResetException- If the first Result Iterated fails to create.
-
getPSIterator
public ResultIterator getPSIterator(String name) throws DatabaseEngineException, ConnectionResetException
Description copied from interface:DatabaseEngineCreates an iterator for thePreparedStatementbound to the given name.- Specified by:
getPSIteratorin interfaceDatabaseEngine- Parameters:
name- The name of the prepared statement.- Returns:
- An iterator for the results of the prepared statement of the given name.
- Throws:
DatabaseEngineException- If a database access error occurs.ConnectionResetException
-
getPSIterator
public ResultIterator getPSIterator(String name, int fetchSize) throws DatabaseEngineException, ConnectionResetException
Description copied from interface:DatabaseEngineCreates an iterator for thePreparedStatementbound to the given name.- Specified by:
getPSIteratorin interfaceDatabaseEngine- Parameters:
name- The name of the prepared statement.fetchSize- The number of rows to fetch each time.- Returns:
- An iterator for the results of the prepared statement of the given name.
- Throws:
DatabaseEngineException- If a database access error occurs.ConnectionResetException
-
setParameters
public void setParameters(String name, Object... params) throws DatabaseEngineException, ConnectionResetException
Description copied from interface:DatabaseEngineSets the parameters on the specified prepared statement.- Specified by:
setParametersin interfaceDatabaseEngine- Parameters:
name- The prepared statement name.params- The parameters to set.- Throws:
DatabaseEngineException- If something occurs setting the parameters.ConnectionResetException- If the connection was reset while trying to set parameters.
-
setParameter
public void setParameter(String name, int index, Object param) throws DatabaseEngineException, ConnectionResetException
Description copied from interface:DatabaseEngineSets the parameter on the specified index.- Specified by:
setParameterin interfaceDatabaseEngine- Parameters:
name- The prepared statement name.index- The index to set.param- The parameter to set.- Throws:
DatabaseEngineException- If something occurs setting the parameters.ConnectionResetException- If the connection was reset while trying to set the parameter.
-
setParameter
public void setParameter(String name, int index, Object param, DbColumnType paramType) throws DatabaseEngineException, ConnectionResetException
Description copied from interface:DatabaseEngineSets the parameter on the specified index given its type. This is for situations where the java type of the parameter alone is not enough to determine the corresponding database type; for example, Strings can be used to represent both actual Strings and Json values, so if we have an update statement that updates a json column we need to specify that the bind parameter is of type json.- Specified by:
setParameterin interfaceDatabaseEngine- Parameters:
name- The prepared statement name.index- The index to set.param- The parameter to set.paramType- The type of the parameter being set.- Throws:
DatabaseEngineException- If something occurs setting the parameters.ConnectionResetException- If the connection was reset while trying to set the parameter.
-
executePS
public void executePS(String name) throws DatabaseEngineException, ConnectionResetException
Executes the specified prepared statement.- Specified by:
executePSin interfaceDatabaseEngine- Parameters:
name- The prepared statement name.- Throws:
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.
-
clearParameters
public void clearParameters(String name) throws DatabaseEngineException, ConnectionResetException
Clears the prepared statement parameters.- Specified by:
clearParametersin interfaceDatabaseEngine- Parameters:
name- The prepared statement name.- Throws:
DatabaseEngineException- If something occurs while clearing the parameters.ConnectionResetException- If the connection was reset.
-
preparedStatementExists
public boolean preparedStatementExists(String name)
Checks if there's a prepared statement with the given name.- Specified by:
preparedStatementExistsin interfaceDatabaseEngine- Parameters:
name- The name to test.- Returns:
- True if it exists, false otherwise.
-
executePSUpdate
public Integer executePSUpdate(String name) throws DatabaseEngineException, ConnectionResetException
Executes update on the specified prepared statement.- Specified by:
executePSUpdatein interfaceDatabaseEngine- Parameters:
name- The prepared statement name.- Throws:
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.
-
commentCharacter
public String commentCharacter()
- Specified by:
commentCharacterin interfaceDatabaseEngine- Returns:
- The comment character of this engine implementation.
-
escapeCharacter
public String escapeCharacter()
- Specified by:
escapeCharacterin interfaceDatabaseEngine- Returns:
- The escape character of this engine implementation.
-
setExceptionHandler
public void setExceptionHandler(ExceptionHandler eh)
Description copied from interface:DatabaseEngineSets the given exception handler in the engine.- Specified by:
setExceptionHandlerin interfaceDatabaseEngine- Parameters:
eh- The reference for exception callbacks.
-
handleOperation
protected void handleOperation(OperationFault opFault, Exception exception) throws DatabaseEngineException
Controls if the given faulty operation must be silenced or not. The decision can be controlled by an external party using for that matter thesetExceptionHandler(ExceptionHandler)method to provide a specific implementation.- Parameters:
opFault- The operation that originated the exception.exception- The exception.- Throws:
DatabaseEngineException- If the faulty operation must stop the execution.
-
objectToArray
protected final byte[] objectToArray(Object val) throws IOException
Converts an object to byte array.- Parameters:
val- The object to convert.- Returns:
- The byte array representation of the object.
- Throws:
IOException- If the buffer is not enough to make the conversion.
-
hasIdentityColumn
public boolean hasIdentityColumn(DbEntity entity)
Check if the entity has an identity column.- Parameters:
entity- The entity to check.- Returns:
- True if the entity has an identity column and false otherwise.
-
inject
protected void inject(Expression... objs)
-
setParameterValues
protected void setParameterValues(PreparedStatement ps, int index, Object param) throws SQLException
Sets the value of a parameter inindexto the value provided inparam.- Parameters:
ps- ThePreparedStatementto insert the association between index and the param.index- The index to set the value to.param- The value to be set at the provided index.- Throws:
SQLException- If something goes wrong accessing the database.
-
getQueryExceptionHandler
protected QueryExceptionHandler getQueryExceptionHandler()
Gets the instance ofQueryExceptionHandlerto be used in disambiguating SQL exceptions.- Returns:
- the
QueryExceptionHandler. - Since:
- 2.5.1
-
reconnectExceptionally
protected void reconnectExceptionally(String message) throws DatabaseEngineException
Verifies if a connection to the database is available, if not, an attempts to reestablished it are made by thegetConnection().- Parameters:
message- The exception message.- Throws:
DatabaseEngineException- if an error occurs while reestablishing the connection.- Since:
- 2.7.0
-
-