public class DB2Engine extends DatabaseEngineImpl
| Modifier and Type | Field and Description |
|---|---|
static String |
DB2_DEFAULT_BLOB_SIZE
The default size of a BLOB in DB2.
|
protected static String |
DB2_DRIVER
The DB2 JDBC driver.
|
static String |
FOREIGN_ALREADY_EXISTS
Foreign key already exists
|
static String |
NAME_ALREADY_EXISTS
Name is already used by an existing object.
|
static String |
SEQUENCE_DOES_NOT_EXIST
Sequence does not exist.
|
static String |
TABLE_CAN_ONLY_HAVE_ONE_PRIMARY_KEY
Table can have only one primary key.
|
static String |
TABLE_OR_VIEW_DOES_NOT_EXIST
Table or view does not exist.
|
conn, dev, diaclect, entities, ESCAPE_CHARATER, logger, notificationLogger, properties, stmts| Constructor and Description |
|---|
DB2Engine(Properties properties)
Creates a new DB2 connection.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addColumn(DbEntity entity,
DbColumn... columns)
Adds the column to an existent table.
|
protected void |
addFks(DbEntity entity)
Adds the FKs.
|
protected void |
addIndexes(DbEntity entity)
Add the desired indexes.
|
protected void |
addPrimaryKey(DbEntity entity)
Add a primary key to the entity.
|
protected void |
addSequences(DbEntity entity)
Adds the necessary sequences.
|
protected boolean |
checkConnection(Connection conn)
Checks if the connection is alive.
|
protected MappedEntity |
createPreparedStatementForInserts(DbEntity entity)
Creates and gets the prepared statement that will be used for insertions.
|
protected ResultIterator |
createResultIterator(PreparedStatement ps)
Creates a specific
ResultIterator for the engine in place given given prepared statement. |
protected ResultIterator |
createResultIterator(Statement statement,
String sql)
Creates a specific
ResultIterator given the engine implementation. |
protected void |
createTable(DbEntity entity)
Creates the table.
|
protected void |
dropColumn(DbEntity entity,
String... columns)
Drops the column.
|
protected void |
dropSequences(DbEntity entity)
Drops the sequences of the entity.
|
protected void |
dropTable(DbEntity entity)
Drops the table.
|
protected int |
entityToPreparedStatement(DbEntity entity,
PreparedStatement ps,
EntityEntry entry,
boolean useAutoInc)
Translates the given entry entity to the prepared statement.
|
int |
executeUpdate(String query)
Executes a native query.
|
Map<String,DbColumnType> |
getMetadata(String name)
Gets the table metadata.
|
Long |
persist(String name,
EntityEntry entry)
Persists a given entry.
|
Long |
persist(String name,
EntityEntry entry,
boolean useAutoInc)
Persists a given entry.
|
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.
|
protected String |
translateType(DbColumn c)
Translates the type present in the given column.
|
void |
updateEntity(DbEntity entity)
Updates an entity in the engine.
|
addBatch, addEntity, beginTransaction, checkConnection, checkConnection, clearParameters, close, commentCharacter, commit, connect, containsEntity, createBatch, createPreparedStatement, createPreparedStatement, createPreparedStatement, createPreparedStatement, dropEntity, dropEntity, dropFks, duplicate, escapeCharacter, executePS, executePSUpdate, executeUpdate, flush, getConnection, getDialect, getEntities, getProperties, getPSIterator, getPSResultSet, getQueryMetadata, getQueryMetadata, isTransactionActive, iterator, iterator, objectToArray, preparedStatementExists, processResultIterator, query, query, removeEntity, removePreparedStatement, rollback, setTransactionIsolation, toPdbType, translateprotected static final String DB2_DRIVER
public static final String NAME_ALREADY_EXISTS
public static final String TABLE_CAN_ONLY_HAVE_ONE_PRIMARY_KEY
public static final String SEQUENCE_DOES_NOT_EXIST
public static final String TABLE_OR_VIEW_DOES_NOT_EXIST
public static final String FOREIGN_ALREADY_EXISTS
public static final String DB2_DEFAULT_BLOB_SIZE
public DB2Engine(Properties properties) throws DatabaseEngineException
properties - The properties for the database connection.DatabaseEngineException - When the connection fails.protected int entityToPreparedStatement(DbEntity entity, PreparedStatement ps, EntityEntry entry, boolean useAutoInc) throws DatabaseEngineException
DatabaseEngineImplentityToPreparedStatement in class DatabaseEngineImplentity - The entity.ps - The prepared statement.entry - The entry.DatabaseEngineException - if something occurs during the translation.protected void createTable(DbEntity entity) throws DatabaseEngineException
DatabaseEngineImplcreateTable in class DatabaseEngineImplentity - The entity.DatabaseEngineException - If something goes wrong while creating the table.protected void addPrimaryKey(DbEntity entity) throws DatabaseEngineException
DatabaseEngineImpladdPrimaryKey in class DatabaseEngineImplentity - The entity.DatabaseEngineException - If something goes wrong while creating the table.protected void addIndexes(DbEntity entity) throws DatabaseEngineException
DatabaseEngineImpladdIndexes in class DatabaseEngineImplentity - The entity.DatabaseEngineException - If something goes wrong while creating the table.protected void addSequences(DbEntity entity) throws DatabaseEngineException
DatabaseEngineImpladdSequences in class DatabaseEngineImplentity - The entity.DatabaseEngineException - If something goes wrong while creating the table.public int executeUpdate(String query) throws DatabaseEngineException
DatabaseEngineImplexecuteUpdate in interface DatabaseEngineexecuteUpdate in class DatabaseEngineImplquery - The query to execute.DatabaseEngineException - If something goes wrong executing the native query.protected MappedEntity createPreparedStatementForInserts(DbEntity entity) throws DatabaseEngineException
DatabaseEngineImplcreatePreparedStatementForInserts in class DatabaseEngineImplentity - The entity.DatabaseEngineException - If something goes wrong while creating the table.protected void dropSequences(DbEntity entity) throws DatabaseEngineException
DatabaseEngineImpldropSequences in class DatabaseEngineImplentity - The entity.DatabaseEngineException - If something goes wrong dropping the sequences.protected void dropTable(DbEntity entity) throws DatabaseEngineException
DatabaseEngineImpldropTable in class DatabaseEngineImplentity - The entity.DatabaseEngineException - If something goes wrong dropping the sequences.protected void dropColumn(DbEntity entity, String... columns) throws DatabaseEngineException
DatabaseEngineImpldropColumn in class DatabaseEngineImplentity - The entity.columns - The column name to drop.DatabaseEngineException - If something goes wrong dropping the sequences.public void updateEntity(DbEntity entity) throws DatabaseEngineException
DatabaseEngineImplUpdates an entity in the engine.
If the entity does not exists in the instance, the method DatabaseEngineImpl.addEntity(com.feedzai.commons.sql.abstraction.ddl.DbEntity) will be invoked.
The engine will compare the entity with the DatabaseEngineImpl.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.
updateEntity in interface DatabaseEngineupdateEntity in class DatabaseEngineImplentity - The entity to update.DatabaseEngineExceptionprotected void addColumn(DbEntity entity, DbColumn... columns) throws DatabaseEngineException
DatabaseEngineImpladdColumn in class DatabaseEngineImplentity - The entity that represents the table.columns - The db column to add.DatabaseEngineExceptionprotected String translateType(DbColumn c) throws DatabaseEngineException
DatabaseEngineImpltranslateType in class DatabaseEngineImplc - The column.DatabaseEngineException - If the type cannot be found.public Long persist(String name, EntityEntry entry) throws DatabaseEngineException
DatabaseEngineImplPersists 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.
persist in interface DatabaseEnginepersist in class DatabaseEngineImplname - The entity name.entry - The entry to persist.DatabaseEngineException - If something goes wrong while persisting data.public Long persist(String name, EntityEntry entry, boolean useAutoInc) throws DatabaseEngineException
DatabaseEngineImplPersists 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.
persist in interface DatabaseEnginepersist in class DatabaseEngineImplname - The entity name.entry - The entry to persist.useAutoInc - Use or not the autoinc.DatabaseEngineException - If something goes wrong while persisting data.protected void addFks(DbEntity entity) throws DatabaseEngineException
DatabaseEngineImpladdFks in class DatabaseEngineImplentity - The entity.DatabaseEngineException - If something goes wrong creating the FKs.protected boolean checkConnection(Connection conn)
DatabaseEngineImplcheckConnection in class DatabaseEngineImplconn - The connection to test.protected ResultIterator createResultIterator(Statement statement, String sql) throws DatabaseEngineException
DatabaseEngineImplResultIterator given the engine implementation.createResultIterator in class DatabaseEngineImplstatement - The statement.sql - The SQL sentence.DatabaseEngineException - If a database access error occurs.public Map<String,DbColumnType> getMetadata(String name) throws DatabaseEngineException
DatabaseEngineImplgetMetadata in interface DatabaseEnginegetMetadata in class DatabaseEngineImplDatabaseEngineException - If something occurs getting the metadata.public void setParameters(String name, Object... params) throws DatabaseEngineException, ConnectionResetException
DatabaseEnginesetParameters in interface DatabaseEnginesetParameters in class DatabaseEngineImplname - 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.public void setParameter(String name, int index, Object param) throws DatabaseEngineException, ConnectionResetException
DatabaseEnginesetParameter in interface DatabaseEnginesetParameter in class DatabaseEngineImplname - 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.protected ResultIterator createResultIterator(PreparedStatement ps) throws DatabaseEngineException
DatabaseEngineImplResultIterator for the engine in place given given prepared statement.createResultIterator in class DatabaseEngineImplps - The prepared statement.DatabaseEngineException - If a database access error occurs.Copyright © 2013. All Rights Reserved.