@Service(value=Backend.class) public class Postgres extends AbstractSql92Backend
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_SCHEMA
postgres' default schema.
|
static String[] |
RESERVED_WORDS_PG
array of additional reserved words.
|
static String |
SQL_LIMIT
LIMIT string.
|
static String |
SQL_LIMIT_PAR
LIMIT ? string.
|
static String |
SQL_OFFSET
OFFSET string.
|
static String |
SQL_OFFSET_PAR
OFFSET ? string.
|
RESERVED_WORDS_SQL92, SQL_COALESCE, SQL_FOR_UPDATEEMPTY_STRING, TYPE_BIGINT, TYPE_BIT, TYPE_BLOB, TYPE_BOOL, TYPE_BOOLEAN, TYPE_BYTE, TYPE_BYTEA, TYPE_CHAR_1, TYPE_DATE, TYPE_DATETIME, TYPE_DATETIME_YEAR_TO_SECOND, TYPE_DECIMAL, TYPE_DECIMAL_19, TYPE_DOUBLE, TYPE_FLOAT, TYPE_FLOAT4, TYPE_FLOAT8, TYPE_INT, TYPE_INT2, TYPE_INT4, TYPE_INT8, TYPE_INTEGER, TYPE_NCHAR_1, TYPE_NUMBER, TYPE_NUMBER_1, TYPE_NUMBER_10, TYPE_NUMBER_19, TYPE_NUMBER_5, TYPE_NVARCHAR, TYPE_NVARCHAR_MAX, TYPE_REAL, TYPE_SMALLFLOAT, TYPE_SMALLINT, TYPE_TEXT, TYPE_TIME, TYPE_TIMESTAMP, TYPE_TINYINT, TYPE_VARBINARY_MAX, TYPE_VARCHARSQL_ALLSTAR, SQL_ALTER_COLUMN, SQL_ALTER_TABLE, SQL_AND, SQL_ANDNOT, SQL_COMMA, SQL_COMMA_PAR, SQL_DELETE, SQL_EQUAL, SQL_EQUAL_PAR, SQL_EQUAL_PAR_COMMA, SQL_EQUAL_ZERO, SQL_EXISTS, SQL_FROM, SQL_GREATER, SQL_GREATER_PAR, SQL_GREATEROREQUAL, SQL_GREATEROREQUAL_PAR, SQL_GROUPBY, SQL_IF_EXISTS, SQL_INSERT_INTO, SQL_INSERT_VALUES, SQL_ISNOTNULL, SQL_ISNULL, SQL_LEFT_PARENTHESIS, SQL_LESS, SQL_LESS_PAR, SQL_LESSOREQUAL, SQL_LESSOREQUAL_PAR, SQL_LIKE, SQL_LIKE_PAR, SQL_MAX, SQL_MIN, SQL_NOT, SQL_NOTEQUAL, SQL_NOTEQUAL_PAR, SQL_NOTEQUAL_ZERO, SQL_NOTLIKE, SQL_NOTLIKE_PAR, SQL_OR, SQL_ORDERBY, SQL_ORNOT, SQL_PAR, SQL_PAR_COMMA, SQL_PLUS_ONE, SQL_RIGHT_PARENTHESIS, SQL_SELECT, SQL_SELECT_ALL_FROM, SQL_SET, SQL_SORTASC, SQL_SORTDESC, SQL_UPDATE, SQL_WHERE, SQL_WHEREALL, SQL_WHEREAND, SQL_WHERENOTHING, SQL_WHEREOR| Constructor and Description |
|---|
Postgres() |
| Modifier and Type | Method and Description |
|---|---|
void |
buildSelectSql(StringBuilder sqlBuilder,
boolean writeLock,
int limit,
int offset)
Creates a select statement string from an inner sql string.
|
ColumnMetaData |
createColumnMetaData(TableMetaData tableMetaData)
Creates a column meta data instance.
|
IndexMetaData |
createIndexMetaData(TableMetaData tableMetaData)
Creates an index meta data instance.
|
protected String |
extractWhereClause(String sql,
int whereOffset)
Extracts the where clause from a given sql.
|
String |
getBackendId(Connection connection)
Determines the unique id or name used by the backend for a given connection.
|
String |
getDefaultSchema()
Gets the default schema name.
Some backends store the objects in a default schema, if no explicit schema is given. |
int |
getDefaultSize(SqlType sqlType)
Gets the default size if no size given in model.
|
String |
getDriverClassName()
Gets the JDBC driver class name.
|
int |
getMaxSize(SqlType sqlType)
Returns the maximum size for a given SQL-type.
|
MigrationStrategy[] |
getMigrationStrategy(ColumnMetaData column,
String columnName,
String comment,
SqlType sqlType,
int size,
int scale,
boolean nullable,
Object defaultValue)
Determines the best migration strategy.
|
String |
getName()
Gets the name of the backend.
|
Set<String> |
getReservedWords()
Gets the list of reserved words for this backend.
|
protected boolean |
isDropIfExistsSupported()
Adds "IF EXISTS" to drop clauses, if supported by the backend.
Makes migration a little more robust in case the same SQL scripts are applied to different databases than those used to generate the migration scripts for. |
boolean |
isMatchingUrl(String url)
Checks whether the backend belongs to the given jdbc url.
|
boolean |
isReleaseSavepointSupported()
Returns whether the backend supports releasing savepoints explicitly.
|
SqlType[] |
jdbcTypeToSqlType(int jdbcType,
int size,
int scale)
Converts the JDBC data type integer to a tentackle backend SqlTypes.
|
boolean |
needAliasForSubselect()
Returns whether backend needs an alias for a subselect.
|
boolean |
needTxForFetchsize()
Checks for the (postgres) bug that fetchsize is ignored if not within a new transaction.
|
int |
setLeadingSelectParameters(BackendPreparedStatement stmt,
int limit,
int offset)
Sets optional parameters before applying the original parameters.
|
int |
setTrailingSelectParameters(BackendPreparedStatement stmt,
int index,
int limit,
int offset)
Sets optional parameters after applying the original parameters.
|
String |
sqlAlterColumnNullConstraint(String tableName,
String columnName,
boolean nullable)
Generates sql code to change the null-constraint of a column.
|
String |
sqlAlterColumnType(String tableName,
String columnName,
String comment,
SqlType sqlType,
int size,
int scale,
boolean nullable,
Object defaultValue)
Generates sql code to change the datatype of a column.
|
String |
sqlCreateColumnComment(String tableName,
String columnName,
String comment)
Generates SQL code to create the comment for an attribute.
|
String |
sqlCreateTableComment(String tableName,
String comment)
Generates SQL code to create the comment for a table.
|
String |
sqlNextFromSequene(String name)
Creates the SQL string to retrieve the next id from a sequence.
|
String |
sqlTypeToString(SqlType sqlType,
int size)
Converts the java SQL-type to the database type name.
|
boolean |
supportsSequences()
True if backend provides transactionless sequences.
|
getCoalesceKeyword, sqlCreateForeignKey, sqlDropForeignKeyallowsExpressionsReferringToTablesBeingUpdated, assertValidName, buildSelectSql, columnTypeNullDefaultToString, columnTypeToString, createConnection, createIndexColumnMetaData, createTableMetaData, getEmptyString, getMaxScale, getMetaData, getModelMetaData, getTableMetaData, isCommunicationLinkException, isConstraintException, isDefaultEqual, isDropIfExistsEnabled, isMatchingName, isTemporaryName, needSetLongWorkaround, normalizeDefault, optimizeSql, setDropIfExistsEnabled, sqlAddColumn, sqlAlterColumnComment, sqlAlterColumnDefault, sqlAlterTableComment, sqlAsBeforeTableAlias, sqlComment, sqlCreateColumn, sqlCreateIndex, sqlCreateTableAttributeWithoutComment, sqlCreateTableClosing, sqlCreateTableIntro, sqlCreateTableIntroWithoutComment, sqlDropColumn, sqlDropIndex, sqlFunction, sqlJoin, sqlJoinSelects, sqlJoinSelects, sqlRenameAndAlterColumnType, sqlRenameColumn, sqlRequiresExtraCommit, sqlResultSetIsClosedSupported, sqlUpdateToNotNull, toQuotedString, toString, valueToLiteralpublic static final String DEFAULT_SCHEMA
public static final String SQL_LIMIT
public static final String SQL_OFFSET
public static final String SQL_LIMIT_PAR
public static final String SQL_OFFSET_PAR
public static final String[] RESERVED_WORDS_PG
public Set<String> getReservedWords()
BackendgetReservedWords in interface BackendgetReservedWords in class AbstractSql92Backendpublic boolean isMatchingUrl(String url)
Backendurl - the jdbc urlpublic String getName()
Backendpublic String getDriverClassName()
Backendpublic String getBackendId(Connection connection)
Backend
Useful to figure out the corresponding ManagedConnection from the backend's logfiles.
connection - the jdbc connectionpublic boolean isReleaseSavepointSupported()
BackendisReleaseSavepointSupported in interface BackendisReleaseSavepointSupported in class AbstractBackendpublic boolean needTxForFetchsize()
BackendneedTxForFetchsize in interface BackendneedTxForFetchsize in class AbstractBackendpublic boolean needAliasForSubselect()
BackendneedAliasForSubselect in interface BackendneedAliasForSubselect in class AbstractBackendpublic void buildSelectSql(StringBuilder sqlBuilder, boolean writeLock, int limit, int offset)
Backend
sqlBuilder is anything as FROM... WHERE... ORDER BY....
It is decorated with a leading SELECT plus optional clauses
like for the given parameters.
buildSelectSql in interface BackendbuildSelectSql in class AbstractSql92BackendsqlBuilder - the sql builder, initially containing the inner sql without leading SELECT.writeLock - true select should write locklimit - the limit value, ≤ 0 if no limit clauseoffset - the offset value, ≤ 0 if no offset clausepublic int setLeadingSelectParameters(BackendPreparedStatement stmt, int limit, int offset)
BackendsetLeadingSelectParameters in interface BackendsetLeadingSelectParameters in class AbstractSql92Backendstmt - the prepared statementlimit - the limit value, ≤ 0 if no limit clauseoffset - the offset value, ≤ 0 if no offset clausepublic int setTrailingSelectParameters(BackendPreparedStatement stmt, int index, int limit, int offset)
BackendsetTrailingSelectParameters in interface BackendsetTrailingSelectParameters in class AbstractSql92Backendstmt - the prepared statementindex - the first parameter indexlimit - the limit value, ≤ 0 if no limit clauseoffset - the offset value, ≤ 0 if no offset clausepublic ColumnMetaData createColumnMetaData(TableMetaData tableMetaData)
BackendcreateColumnMetaData in interface BackendcreateColumnMetaData in class AbstractBackendtableMetaData - the table meta data this column belongs topublic IndexMetaData createIndexMetaData(TableMetaData tableMetaData)
BackendcreateIndexMetaData in interface BackendcreateIndexMetaData in class AbstractBackendtableMetaData - the table meta data this index belongs topublic int getMaxSize(SqlType sqlType)
BackendgetMaxSize in interface BackendgetMaxSize in class AbstractBackendsqlType - the SQL-typepublic int getDefaultSize(SqlType sqlType)
BackendgetDefaultSize in interface BackendgetDefaultSize in class AbstractBackendsqlType - the SQL-typepublic String getDefaultSchema()
BackendgetDefaultSchema in interface BackendgetDefaultSchema in class AbstractBackendpublic SqlType[] jdbcTypeToSqlType(int jdbcType, int size, int scale)
BackendThere may be more than one sqltype returned!
jdbcTypeToSqlType in interface BackendjdbcTypeToSqlType in class AbstractBackendjdbcType - the jdbc data typesize - the column sizescale - the column's scaleTypespublic String sqlTypeToString(SqlType sqlType, int size)
BackendsqlTypeToString in interface BackendsqlTypeToString in class AbstractBackendsqlType - the java sql typesize - the column's sizepublic boolean supportsSequences()
BackendsupportsSequences in interface BackendsupportsSequences in class AbstractSql92Backendpublic String sqlNextFromSequene(String name)
BackendsqlNextFromSequene in interface BackendsqlNextFromSequene in class AbstractSql92Backendname - the name of the sequencepublic String sqlCreateTableComment(String tableName, String comment)
BackendsqlCreateTableComment in interface BackendsqlCreateTableComment in class AbstractBackendtableName - the table namecomment - optional comment, null if noneBackend.sqlCreateTableIntro(java.lang.String, java.lang.String) or Backend.sqlCreateTableClosing(java.lang.String, java.lang.String)public String sqlCreateColumnComment(String tableName, String columnName, String comment)
BackendsqlCreateColumnComment in interface BackendsqlCreateColumnComment in class AbstractBackendtableName - the table namecolumnName - the column namecomment - optional comment, null if noneBackend.sqlCreateColumn(java.lang.String, java.lang.String, org.tentackle.sql.SqlType, int, int, boolean, java.lang.Object, boolean, boolean)public String sqlAlterColumnType(String tableName, String columnName, String comment, SqlType sqlType, int size, int scale, boolean nullable, Object defaultValue)
BackendsqlAlterColumnType in interface BackendsqlAlterColumnType in class AbstractBackendtableName - the tablenamecolumnName - the new column namecomment - optional comment, null if nonesqlType - the JDBC sql typesize - the optional sizescale - the optional scalenullable - true if NULL, else NOT NULLdefaultValue - the optional default valuepublic String sqlAlterColumnNullConstraint(String tableName, String columnName, boolean nullable)
BackendsqlAlterColumnNullConstraint in interface BackendsqlAlterColumnNullConstraint in class AbstractBackendtableName - the tablenamecolumnName - the new column namenullable - true if NULL, else NOT NULLBackend.sqlAlterColumnType(java.lang.String, java.lang.String, java.lang.String, org.tentackle.sql.SqlType, int, int, boolean, java.lang.Object)public MigrationStrategy[] getMigrationStrategy(ColumnMetaData column, String columnName, String comment, SqlType sqlType, int size, int scale, boolean nullable, Object defaultValue)
BackendgetMigrationStrategy in interface BackendgetMigrationStrategy in class AbstractBackendcolumn - old column meta datacolumnName - new column namecomment - new commentsqlType - new sql typesize - new sizescale - new scalenullable - new nullabledefaultValue - new defaultprotected String extractWhereClause(String sql, int whereOffset)
AbstractBackendextractWhereClause in class AbstractBackendsql - the sql statementwhereOffset - the location of WHERE in sqlprotected boolean isDropIfExistsSupported()
AbstractBackendisDropIfExistsSupported in class AbstractBackendTentackle - distributed, domain- and model-driven