public class PostgreSqlEngine extends AbstractDatabaseEngine
Modifier and Type | Field and Description |
---|---|
static String |
CONSTRAINT_NAME_ALREADY_EXISTS
Table or view does not exist.
|
static String |
NAME_ALREADY_EXISTS
Name is already used by an existing object.
|
protected static String |
POSTGRESQL_DRIVER
The PostgreSQL JDBC driver.
|
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, eh, entities, injector, logger, notificationLogger, properties, stmts, translator
Constructor and Description |
---|
PostgreSqlEngine(PdbProperties properties)
Creates a new PostgreSql 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.
|
Map<String,DbColumnType> |
getMetadata(String name)
Gets the table metadata.
|
Class<? extends AbstractTranslator> |
getTranslatorClass()
Gets the class that translates SQL bound to this engine.
|
Long |
persist(String name,
EntityEntry entry)
Persists a given entry.
|
Long |
persist(String name,
EntityEntry entry,
boolean useAutoInc)
Persists a given entry.
|
protected String |
translateType(DbColumn c)
Translates the type present in the given column.
|
addBatch, addEntity, beginTransaction, checkConnection, checkConnection, clearParameters, close, commentCharacter, commit, connect, containsEntity, createBatch, createBatch, createPreparedStatement, createPreparedStatement, createPreparedStatement, createPreparedStatement, dropEntity, dropEntity, dropFks, duplicate, escapeCharacter, executePS, executePSUpdate, executeUpdate, executeUpdate, executeUpdateSilently, flush, getConnection, getDialect, getEntities, getFinalJdbcConnection, getProperties, getPSIterator, getPSResultSet, getQueryMetadata, getQueryMetadata, getSchema, handleOperation, hasIdentityColumn, inject, isTransactionActive, iterator, iterator, objectToArray, preparedStatementExists, processResultIterator, query, query, removeEntity, removePreparedStatement, rollback, setExceptionHandler, setParameter, setParameters, setTransactionIsolation, toPdbType, translate, updateEntity
protected static final String POSTGRESQL_DRIVER
public static final String NAME_ALREADY_EXISTS
public static final String TABLE_CAN_ONLY_HAVE_ONE_PRIMARY_KEY
public static final String TABLE_OR_VIEW_DOES_NOT_EXIST
public static final String CONSTRAINT_NAME_ALREADY_EXISTS
public PostgreSqlEngine(PdbProperties 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
AbstractDatabaseEngine
entityToPreparedStatement
in class AbstractDatabaseEngine
entity
- The entity.ps
- The prepared statement.entry
- The entry.DatabaseEngineException
- if something occurs during the translation.protected void createTable(DbEntity entity) throws DatabaseEngineException
AbstractDatabaseEngine
createTable
in class AbstractDatabaseEngine
entity
- The entity.DatabaseEngineException
- If something goes wrong while creating the table.protected void addPrimaryKey(DbEntity entity) throws DatabaseEngineException
AbstractDatabaseEngine
addPrimaryKey
in class AbstractDatabaseEngine
entity
- The entity.DatabaseEngineException
- If something goes wrong while creating the table.protected void addIndexes(DbEntity entity) throws DatabaseEngineException
AbstractDatabaseEngine
addIndexes
in class AbstractDatabaseEngine
entity
- The entity.DatabaseEngineException
- If something goes wrong while creating the table.protected void addSequences(DbEntity entity) throws DatabaseEngineException
AbstractDatabaseEngine
addSequences
in class AbstractDatabaseEngine
entity
- The entity.DatabaseEngineException
- If something goes wrong while creating the table.protected MappedEntity createPreparedStatementForInserts(DbEntity entity) throws DatabaseEngineException
AbstractDatabaseEngine
createPreparedStatementForInserts
in class AbstractDatabaseEngine
entity
- The entity.DatabaseEngineException
- If something goes wrong while creating the table.protected void dropSequences(DbEntity entity) throws DatabaseEngineException
AbstractDatabaseEngine
dropSequences
in class AbstractDatabaseEngine
entity
- The entity.DatabaseEngineException
- If something goes wrong dropping the sequences.protected void dropTable(DbEntity entity) throws DatabaseEngineException
AbstractDatabaseEngine
dropTable
in class AbstractDatabaseEngine
entity
- The entity.DatabaseEngineException
- If something goes wrong dropping the sequences.protected void dropColumn(DbEntity entity, String... columns) throws DatabaseEngineException
AbstractDatabaseEngine
dropColumn
in class AbstractDatabaseEngine
entity
- The entity.columns
- The column name to drop.DatabaseEngineException
- If something goes wrong dropping the sequences.protected void addColumn(DbEntity entity, DbColumn... columns) throws DatabaseEngineException
AbstractDatabaseEngine
addColumn
in class AbstractDatabaseEngine
entity
- The entity that represents the table.columns
- The db column to add.DatabaseEngineException
protected String translateType(DbColumn c) throws DatabaseEngineException
AbstractDatabaseEngine
translateType
in class AbstractDatabaseEngine
c
- The column.DatabaseEngineException
- If the type cannot be found.public Class<? extends AbstractTranslator> getTranslatorClass()
AbstractDatabaseEngine
getTranslatorClass
in class AbstractDatabaseEngine
public Long persist(String name, EntityEntry entry) throws DatabaseEngineException
AbstractDatabaseEngine
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.
persist
in interface DatabaseEngine
persist
in class AbstractDatabaseEngine
name
- 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
AbstractDatabaseEngine
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.
persist
in interface DatabaseEngine
persist
in class AbstractDatabaseEngine
name
- 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
AbstractDatabaseEngine
addFks
in class AbstractDatabaseEngine
entity
- The entity.DatabaseEngineException
- If something goes wrong creating the FKs.protected boolean checkConnection(Connection conn)
AbstractDatabaseEngine
checkConnection
in class AbstractDatabaseEngine
conn
- The connection to test.public Map<String,DbColumnType> getMetadata(String name) throws DatabaseEngineException
AbstractDatabaseEngine
getMetadata
in interface DatabaseEngine
getMetadata
in class AbstractDatabaseEngine
DatabaseEngineException
- If something occurs getting the metadata.protected ResultIterator createResultIterator(Statement statement, String sql) throws DatabaseEngineException
AbstractDatabaseEngine
ResultIterator
given the engine implementation.createResultIterator
in class AbstractDatabaseEngine
statement
- The statement.sql
- The SQL sentence.DatabaseEngineException
- If a database access error occurs.protected ResultIterator createResultIterator(PreparedStatement ps) throws DatabaseEngineException
AbstractDatabaseEngine
ResultIterator
for the engine in place given given prepared statement.createResultIterator
in class AbstractDatabaseEngine
ps
- The prepared statement.DatabaseEngineException
- If a database access error occurs.Copyright © 2014 Feedzai. All Rights Reserved.