public abstract class BaseLiaison extends Object implements DatabaseLiaison
Constructor and Description |
---|
BaseLiaison() |
Modifier and Type | Method and Description |
---|---|
boolean |
addColumn(Connection conn,
String table,
String column,
ColumnDefinition newColumnDef,
boolean check)
Adds a column to a table with the given definition.
|
boolean |
addColumn(Connection conn,
String table,
String column,
String definition,
boolean check)
Adds a column to a table with the given definition.
|
boolean |
addIndexToTable(Connection conn,
String table,
List<String> columns,
String ixName,
boolean unique)
Adds a named index to a table on the given columns.
|
void |
addPrimaryKey(Connection conn,
String table,
List<String> columns)
Adds a primary key to a table of the given name and on the given columns.
|
boolean |
changeColumn(Connection conn,
String table,
String column,
String type,
Boolean nullable,
Boolean unique,
String defaultValue)
Alter the definition, but not the name, of a given column on a given table.
|
abstract String |
columnSQL(String column)
Returns the proper SQL to identify a column.
|
abstract void |
createGenerator(Connection conn,
String tableName,
String columnName,
int initialValue)
Initializes the column value auto-generator described in
DatabaseLiaison.lastInsertedId(java.sql.Connection, java.lang.String, java.lang.String) . |
boolean |
createTableIfMissing(Connection conn,
String table,
List<String> columns,
List<ColumnDefinition> definitions,
List<List<String>> uniqueConstraintColumns,
List<String> primaryKeyColumns)
Created a new table of the given name with the given column names and column definitions;
the given set of unique constraints (or null) and the given primary key columns (or null).
|
boolean |
createTableIfMissing(Connection conn,
String table,
List<String> columns,
List<ColumnDefinition> declarations,
List<String> primaryKeyColumns)
Created a new table of the given name with the given column names and column definitions;
the given set of unique constraints (or null) and the given primary key columns (or null).
|
abstract void |
deleteGenerator(Connection conn,
String tableName,
String columnName)
Deletes the column value auto-generator described in
DatabaseLiaison.lastInsertedId(java.sql.Connection, java.lang.String, java.lang.String) . |
boolean |
dropColumn(Connection conn,
String table,
String column)
Drops the given column from the given table.
|
void |
dropIndex(Connection conn,
String table,
String index)
Drops the named index from the given table.
|
void |
dropPrimaryKey(Connection conn,
String table,
String pkName)
Deletes the primary key from a table, if it exists.
|
boolean |
dropTable(Connection conn,
String name)
Drops the given table and returns true if the table exists, else returns false.
|
String |
expandDefinition(ColumnDefinition def)
Create an SQL string that summarizes a column definition in that format generally accepted
in table creation and column addition statements, e.g.
|
abstract String |
indexSQL(String index)
Returns the proper SQL to identify an index.
|
abstract boolean |
isDuplicateRowException(SQLException sqe)
Determines whether or not the supplied SQL exception was caused by a duplicate row being
inserted into a table with a unique key.
|
abstract boolean |
isTransientException(SQLException sqe)
Determines whether or not the supplied SQL exception is a transient failure, meaning one
that is not related to the SQL being executed, but instead to the environment at the time of
execution, like the connection to the database having been lost.
|
int |
lastInsertedId(Connection conn,
Statement istmt,
String table,
String column)
Attempts as dialect-agnostic an interface as possible to the ability of certain databases to
auto-generated numerical values for i.e.
|
int |
lastInsertedId(Connection conn,
String table,
String column)
Deprecated.
|
abstract boolean |
matchesURL(String url)
Indicates whether or not this database liaison is the proper liaison for the specified
database URL.
|
boolean |
renameColumn(Connection conn,
String table,
String from,
String to,
ColumnDefinition newColumnDef)
Alter the name, but not the definition, of a given column on a given table.
|
boolean |
tableContainsColumn(Connection conn,
String table,
String column)
Returns true if the specified table exists and contains a column with the specified name;
false if either condition does not hold true.
|
boolean |
tableContainsIndex(Connection conn,
String table,
String index)
Returns true if the specified table exists and contains an index of the specified name;
false if either conditions does not hold true.
|
boolean |
tableExists(Connection conn,
String name)
Returns true if the table with the specified name exists, false if it does not.
|
abstract String |
tableSQL(String table)
Returns the proper SQL to identify a table.
|
public abstract boolean matchesURL(String url)
DatabaseLiaison
matchesURL
in interface DatabaseLiaison
public abstract boolean isDuplicateRowException(SQLException sqe)
DatabaseLiaison
isDuplicateRowException
in interface DatabaseLiaison
public abstract boolean isTransientException(SQLException sqe)
DatabaseLiaison
isTransientException
in interface DatabaseLiaison
@Deprecated public int lastInsertedId(Connection conn, String table, String column) throws SQLException
lastInsertedId
in interface DatabaseLiaison
SQLException
public int lastInsertedId(Connection conn, Statement istmt, String table, String column) throws SQLException
DatabaseLiaison
lastInsertedId
in interface DatabaseLiaison
istmt
- the insert statement that generated the keys. May be null if the ORM doesn't
have the statement handy.SQLException
- if we are unable to obtain the last inserted id.public boolean tableExists(Connection conn, String name) throws SQLException
DatabaseLiaison
tableExists
in interface DatabaseLiaison
SQLException
public boolean tableContainsColumn(Connection conn, String table, String column) throws SQLException
DatabaseLiaison
tableContainsColumn
in interface DatabaseLiaison
SQLException
public boolean tableContainsIndex(Connection conn, String table, String index) throws SQLException
DatabaseLiaison
tableContainsIndex
in interface DatabaseLiaison
SQLException
public boolean addIndexToTable(Connection conn, String table, List<String> columns, String ixName, boolean unique) throws SQLException
DatabaseLiaison
addIndexToTable
in interface DatabaseLiaison
SQLException
public void addPrimaryKey(Connection conn, String table, List<String> columns) throws SQLException
DatabaseLiaison
addPrimaryKey
in interface DatabaseLiaison
SQLException
public void dropIndex(Connection conn, String table, String index) throws SQLException
DatabaseLiaison
dropIndex
in interface DatabaseLiaison
SQLException
public void dropPrimaryKey(Connection conn, String table, String pkName) throws SQLException
DatabaseLiaison
dropPrimaryKey
in interface DatabaseLiaison
SQLException
public boolean addColumn(Connection conn, String table, String column, String definition, boolean check) throws SQLException
DatabaseLiaison
addColumn
in interface DatabaseLiaison
SQLException
public boolean addColumn(Connection conn, String table, String column, ColumnDefinition newColumnDef, boolean check) throws SQLException
DatabaseLiaison
addColumn
in interface DatabaseLiaison
SQLException
public boolean changeColumn(Connection conn, String table, String column, String type, Boolean nullable, Boolean unique, String defaultValue) throws SQLException
DatabaseLiaison
changeColumn
in interface DatabaseLiaison
SQLException
public boolean renameColumn(Connection conn, String table, String from, String to, ColumnDefinition newColumnDef) throws SQLException
DatabaseLiaison
renameColumn
in interface DatabaseLiaison
newColumnDef
- the full definition of the new column, including its new name (MySQL
requires this for a column rename).SQLException
public abstract void createGenerator(Connection conn, String tableName, String columnName, int initialValue) throws SQLException
DatabaseLiaison
DatabaseLiaison.lastInsertedId(java.sql.Connection, java.lang.String, java.lang.String)
. This
should be idempotent (meaning the generator may already exist in which case this method
should have no negative effect like resetting it).createGenerator
in interface DatabaseLiaison
SQLException
public abstract void deleteGenerator(Connection conn, String tableName, String columnName) throws SQLException
DatabaseLiaison
DatabaseLiaison.lastInsertedId(java.sql.Connection, java.lang.String, java.lang.String)
.deleteGenerator
in interface DatabaseLiaison
SQLException
public boolean dropColumn(Connection conn, String table, String column) throws SQLException
DatabaseLiaison
dropColumn
in interface DatabaseLiaison
SQLException
public boolean createTableIfMissing(Connection conn, String table, List<String> columns, List<ColumnDefinition> declarations, List<String> primaryKeyColumns) throws SQLException
DatabaseLiaison
createTableIfMissing
in interface DatabaseLiaison
SQLException
public boolean createTableIfMissing(Connection conn, String table, List<String> columns, List<ColumnDefinition> definitions, List<List<String>> uniqueConstraintColumns, List<String> primaryKeyColumns) throws SQLException
DatabaseLiaison
createTableIfMissing
in interface DatabaseLiaison
SQLException
public boolean dropTable(Connection conn, String name) throws SQLException
DatabaseLiaison
dropTable
in interface DatabaseLiaison
SQLException
public abstract String tableSQL(String table)
DatabaseLiaison
tableSQL
in interface DatabaseLiaison
public abstract String columnSQL(String column)
DatabaseLiaison
columnSQL
in interface DatabaseLiaison
public abstract String indexSQL(String index)
DatabaseLiaison
indexSQL
in interface DatabaseLiaison
public String expandDefinition(ColumnDefinition def)
INTEGER UNIQUE NOT NULL
DEFAULT 100
.expandDefinition
in interface DatabaseLiaison
Copyright © 2015. All rights reserved.