Class CockroachDBEngine
- java.lang.Object
-
- com.feedzai.commons.sql.abstraction.engine.AbstractDatabaseEngine
-
- com.feedzai.commons.sql.abstraction.engine.impl.PostgreSqlEngine
-
- com.feedzai.commons.sql.abstraction.engine.impl.CockroachDBEngine
-
- All Implemented Interfaces:
DatabaseEngine,AutoCloseable
public class CockroachDBEngine extends PostgreSqlEngine
CockroachDB specific database implementation.- Since:
- 2.5.0
- Author:
- Mário Pereira (mario.arzileiro@feedzai.com)
-
-
Field Summary
Fields Modifier and Type Field Description protected static StringCOCKROACHDB_DRIVERThe Cockroach JDBC (PostgreSQL) driver.static StringCONSTRAINT_NAME_ALREADY_EXISTS_COCKROACHConstraint name already exists.-
Fields inherited from class com.feedzai.commons.sql.abstraction.engine.impl.PostgreSqlEngine
CONSTRAINT_NAME_ALREADY_EXISTS, NAME_ALREADY_EXISTS, PG_QUERY_EXCEPTION_HANDLER, POSTGRESQL_DRIVER, TABLE_CAN_ONLY_HAVE_ONE_PRIMARY_KEY, TABLE_OR_VIEW_DOES_NOT_EXIST
-
Fields inherited from class com.feedzai.commons.sql.abstraction.engine.AbstractDatabaseEngine
conn, currentSchema, DEFAULT_QUERY_EXCEPTION_HANDLER, dev, dialect, eh, entities, injector, logger, notificationLogger, properties, socketTimeoutExecutor, stmts, translator
-
-
Constructor Summary
Constructors Constructor Description CockroachDBEngine(PdbProperties properties)Creates a new CockroachDB connection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddFks(DbEntity entity, Set<DbFk> fks)Adds foreign key constraints to the table in the database that the provided entity represents.protected voidaddPrimaryKey(DbEntity entity)Add a primary key to the entity.protected voidaddSequences(DbEntity entity)Adds the necessary sequences.protected voidcreateTable(DbEntity entity)Creates the table.protected voiddropSequences(DbEntity entity)Drops the sequences of the entity.Map<String,DbColumnType>getMetadata(String schemaPattern, String tableNamePattern)Gets the table metadata (table must be in the current schema).Class<? extends AbstractTranslator>getTranslatorClass()Gets the class that translates SQL bound to this engine.protected voidupdatePersistAutoIncSequence(MappedEntity mappedEntity, long currentAutoIncVal)Updates the autoInc sequence value after a persist operation.-
Methods inherited from class com.feedzai.commons.sql.abstraction.engine.impl.PostgreSqlEngine
addColumn, addIndexes, checkConnection, createPreparedStatementForInserts, createResultIterator, createResultIterator, doPersist, dropColumn, dropTable, entityToPreparedStatement, getDBProperties, getQueryExceptionHandler, isStringAggDistinctCapable, setParameter, setSchema, toPdbType
-
Methods inherited from class com.feedzai.commons.sql.abstraction.engine.AbstractDatabaseEngine
addBatch, addEntity, addFks, beginTransaction, checkConnection, checkConnection, clearParameters, close, commentCharacter, commit, connect, containsEntity, createBatch, createBatch, createBatch, createBatch, createPreparedStatement, createPreparedStatement, createPreparedStatement, createPreparedStatement, createSelectStatement, dropEntity, dropEntity, dropFkQuery, dropFks, dropFks, dropView, duplicate, entityToPreparedStatementForBatch, escapeCharacter, executePS, executePSUpdate, executeUpdate, executeUpdate, executeUpdateSilently, flush, getConnection, getDialect, getEntities, getEntities, getFinalJdbcConnection, getImportedKeys, getMetadata, getPreparedStatementForPersist, getPrivateKey, getProperties, getPSIterator, getPSIterator, getPSResultSet, getQueryMetadata, getQueryMetadata, getSchema, handleOperation, hasIdentityColumn, inject, isTransactionActive, iterator, iterator, iterator, iterator, iterator, iterator, loadEntity, objectToArray, persist, persist, preparedStatementExists, processResultIterator, query, query, query, query, reconnectExceptionally, removeEntity, removePreparedStatement, rollback, setExceptionHandler, setParameter, setParameters, setParameterValues, setTransactionIsolation, translate, translateType, updateEntity
-
-
-
-
Field Detail
-
COCKROACHDB_DRIVER
protected static final String COCKROACHDB_DRIVER
The Cockroach JDBC (PostgreSQL) driver.
-
CONSTRAINT_NAME_ALREADY_EXISTS_COCKROACH
public static final String CONSTRAINT_NAME_ALREADY_EXISTS_COCKROACH
Constraint name already exists. Note: CockroachDB v19.2.x returns this SQL state when trying to add a foreign key relation that already exists. This constant is needed because PosgtgreSQL uses code 42710 - ERRCODE_DUPLICATE_OBJECT instead. In this situation CockroachDB v19.2.x uses code 23503 - ERRCODE_FOREIGN_KEY_VIOLATION (a column in a table has a value that is not present in the column of other table in the foreign key relation); in the same situation CockroachDB v19.1.x returns state 42830 - ERRCODE_INVALID_FOREIGN_KEY (which can occur for example when the types of columns in the relation have incompatible types).- See Also:
- CockroachDB issue #42858, Constant Field Values
-
-
Constructor Detail
-
CockroachDBEngine
public CockroachDBEngine(PdbProperties properties) throws DatabaseEngineException
Creates a new CockroachDB connection.- Parameters:
properties- The properties for the database connection.- Throws:
DatabaseEngineException- When the connection fails.
-
-
Method Detail
-
createTable
protected void createTable(DbEntity entity) throws DatabaseEngineException
Description copied from class:AbstractDatabaseEngineCreates the table.- Overrides:
createTablein classPostgreSqlEngine- Parameters:
entity- The entity.- Throws:
DatabaseEngineException- If something goes wrong while creating the table.
-
addPrimaryKey
protected void addPrimaryKey(DbEntity entity) throws DatabaseEngineException
Description copied from class:AbstractDatabaseEngineAdd a primary key to the entity.- Overrides:
addPrimaryKeyin classPostgreSqlEngine- Parameters:
entity- The entity.- Throws:
DatabaseEngineException- If something goes wrong while creating the table.
-
getTranslatorClass
public Class<? extends AbstractTranslator> getTranslatorClass()
Description copied from class:AbstractDatabaseEngineGets the class that translates SQL bound to this engine.- Overrides:
getTranslatorClassin classPostgreSqlEngine- Returns:
- The class that translates SQL bound to this engine.
-
updatePersistAutoIncSequence
protected void updatePersistAutoIncSequence(MappedEntity mappedEntity, long currentAutoIncVal)
Description copied from class:PostgreSqlEngineUpdates the autoInc sequence value after a persist operation.- Overrides:
updatePersistAutoIncSequencein classPostgreSqlEngine- Parameters:
mappedEntity- The mapped entity to for which to update the autoInc sequence.currentAutoIncVal- The current value for the autoInc column.
-
addFks
protected void addFks(DbEntity entity, Set<DbFk> fks) throws DatabaseEngineException
Description copied from class:AbstractDatabaseEngineAdds foreign key constraints to the table in the database that the provided entity represents.- Overrides:
addFksin classPostgreSqlEngine- Parameters:
entity- The entity.fks- The foreign keys to be added.- Throws:
DatabaseEngineException- If something goes wrong creating the FKs.
-
addSequences
protected void addSequences(DbEntity entity) throws DatabaseEngineException
Description copied from class:AbstractDatabaseEngineAdds the necessary sequences.- Overrides:
addSequencesin classPostgreSqlEngine- Parameters:
entity- The entity.- Throws:
DatabaseEngineException- If something goes wrong while creating the table.
-
dropSequences
protected void dropSequences(DbEntity entity) throws DatabaseEngineException
Description copied from class:AbstractDatabaseEngineDrops the sequences of the entity.- Overrides:
dropSequencesin classPostgreSqlEngine- Parameters:
entity- The entity.- Throws:
DatabaseEngineException- If something goes wrong dropping the sequences.
-
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- Overrides:
getMetadatain classAbstractDatabaseEngine- 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.
-
-