public abstract class DatabaseType extends Object
| Constructor and Description |
|---|
DatabaseType() |
| Modifier and Type | Method and Description |
|---|---|
void |
addColumn(Connection conn,
String table,
String column,
String generic_column,
Object precision)
Adds a column to a table.
|
abstract void |
alterColumn(Connection conn,
String table,
String column,
String generic_column_type,
String default_value,
String precision,
Boolean nullable,
Boolean reindex)
Alters an existing column.
|
boolean |
checkColumnExists(Connection conn,
String table,
String column)
Check to see if a column exists in a table.
|
boolean |
checkTableExists(Connection conn,
String table)
Determines if the given table exists in the database.
|
void |
closeConnection(Connection c)
Close a database connection.
|
void |
closeJDBCObjects(Connection c,
Statement s,
ResultSet rs)
Close a connection, statement, and result set in one method call.
|
void |
closeResultSet(ResultSet rs)
Close a database result set.
|
void |
closeStatement(Statement s)
Close a database statement.
|
int |
countRows(int num_rows_already_read,
ResultSet result_set)
Counts the number of rows in a result set.
|
void |
createSequence(Connection conn,
String name,
String initial,
String increment,
String seqIdCacheSize)
Creates a sequence with the given name.
|
void |
deleteColumn(Connection conn,
String table,
String column)
Deletes a column.
|
void |
dropSequence(Connection conn,
String sequence_name)
Drops the sequence with the given name.
|
void |
dropTable(Connection conn,
String table)
Drops a table.
|
List<Object[]> |
executeSelectSql(Connection conn,
String sql)
Executes the given SQL on the given connection.
|
void |
executeSql(Connection conn,
List<String> sql_list)
Executes each SQL string in the list.
|
void |
executeSql(Connection conn,
String sql)
Executes the given SQL on the given connection.
|
String |
getBooleanValue(boolean bool)
Get the value for a boolean as a string as required for the specific database.
|
String |
getDBTypeFromGenericType(String generic_type)
Given a generic type, this will return an analogous type that is specific to this database.
|
String |
getEscapeCharacter()
Provides the value to be used for the ESCAPE character in string literals.
|
abstract String |
getHibernateDialect()
Return the hibernate dialect, that can be used in <property name="hibernate.dialect" value="" / >
expressions within persistence.xml
|
Integer |
getInteger(Object number)
Get the Integer representation of the number type supplied by the db vendor for an integer field value.
|
String |
getLimitClause(int limit)
Return vendor-specific row limit clause to be appended to a native SQL SELECT statement.
|
Long |
getLong(Object number)
Get the Long representation of the number type supplied by the db vendor for a long field value.
|
abstract String |
getName()
Returns a vendor-specific, version-specific database name.
|
abstract int |
getNextSequenceValue(Connection conn,
String table,
String key)
A utility that returns the next value of a sequence.
|
String |
getSequenceInsertValue(Connection conn,
String sequenceName)
A utility that returns the string for sequence use in an Insert statement
|
abstract int |
getSequenceValue(Connection conn,
String table,
String key)
A utility that returns the last value of a sequence.
|
String |
getString(String varchar,
int maxLength)
Different vendors have different rules regarding varchar/varchar2 string storage.
|
abstract String |
getVendor()
Returns a vendor-specific database name.
|
abstract String |
getVersion()
Returns the version number of the database, as a String.
|
void |
insert(Connection conn,
String table,
String insert_cmd)
Inserts data into a table.
|
abstract boolean |
isTableNotFoundException(SQLException e)
Determines if the given SQL exception was caused by a "table not found" error.
|
boolean |
matches(String vendor,
String version)
Returns
true if this database type's vendor and version match those of the given vendor and given
version strings. |
abstract void |
reindexTable(Connection conn,
String table)
Reindexes the given table.
|
void |
setBooleanValue(boolean bool,
PreparedStatement ps,
int idx)
Fill out a
PreparedStatement correctly with a boolean. |
boolean |
supportsSelfReferringCascade()
Most vendors support foreign keys to itself that in fact perform cascade delete.
|
String |
toString() |
void |
update(Connection conn,
String table,
String column,
String where,
String value,
int jdbc_type_int)
Updates data in a particular column.
|
void |
updateColumn(Connection conn,
String table,
String column,
String modify_cmd)
Updates a column by altering its attributes.
|
public abstract String getName()
database-specific typemaps
for a specific version of the vendor's databases if this vendor/version-unique name is used in the mapping.public abstract String getVendor()
database-specific typemaps across all versions of the vendor's databases if this
vendor name is used in the mapping.public abstract String getVersion()
public abstract String getHibernateDialect()
public String toString()
toString in class ObjectObject.toString()public boolean matches(String vendor, String version)
true if this database type's vendor and version match those of the given vendor and given
version strings. If either the vendor or version strings do not match, false is returned. If either
vendor or version is null, that argument is ignored and not compared. If
you just want to compare vendor strings, for example, pass in a null version string. When comparing
the strings, the comparision will be case-insensitive.vendor - version - true if the given vendor and version match this database typepublic String getDBTypeFromGenericType(String generic_type)
generic_type - a generic type namepublic void closeConnection(Connection c)
c - The connection to close (may be null)public void closeStatement(Statement s)
s - The statement to close (may be null)public void closeResultSet(ResultSet rs)
rs - The result set to close (may be null)public void closeJDBCObjects(Connection c, Statement s, ResultSet rs)
null for any argument
to ignore it. No exception is thrown if any close fails, but warnings will be logged.c - The connection to close.s - The statement set to close.rs - The result set to close.public int countRows(int num_rows_already_read,
ResultSet result_set)
throws SQLException
num_rows_already_read - result_set - num_rows_already_readSQLExceptionpublic boolean checkColumnExists(Connection conn, String table, String column) throws SQLException
conn - The DB connection to use.table - The table to check.column - The column to look for. This is done in a case-insensitive manner.true if the column exists in the table, false otherwiseSQLExceptionpublic String getBooleanValue(boolean bool)
bool - the boolean value to be converted to the DB string version of the booleanpublic Integer getInteger(Object number)
number - public Long getLong(Object number)
number - public String getString(String varchar, int maxLength)
varchar - The String to be stored as a varchar/varchar2maxLength - max length of the DB field, in characters.public void setBooleanValue(boolean bool,
PreparedStatement ps,
int idx)
throws SQLException
PreparedStatement correctly with a boolean.bool - the boolean you wantps - the prepapred statement where the boolean will be storedidx - the index that corresponds to the boolean parameter in the statementSQLExceptionpublic boolean checkTableExists(Connection conn, String table) throws Exception
conn - connection to the database where the table to check istable - the table to check for existencetrue if the table exists in the database, false if the table does not exist AND
the implementation determined the information WITHOUT generating an SQLException (meaning the
transaction has not been invalidated. Otherwise, throws an exception which should be handled.IllegalStateException - if the check generated an expected "table does not exist SQLException (note, the
exception invalidates the transaction).Exception - if the table check failed for a reason other than a "table does not exist" error.public void updateColumn(Connection conn, String table, String column, String modify_cmd) throws SQLException
ALTER TABLE table MODIFY ( column modify_cmd )
conn - table - column - modify_cmd - SQLExceptionpublic void dropTable(Connection conn, String table) throws SQLException
conn - table - SQLExceptionpublic void deleteColumn(Connection conn, String table, String column) throws SQLException
conn - table - column - SQLExceptionpublic List<Object[]> executeSelectSql(Connection conn, String sql) throws SQLException
SST_JavaTask.conn - the connection to the database that will execute the SQLsql - the actual SQL to executeSQLExceptionpublic void executeSql(Connection conn, String sql) throws SQLException
conn - the connection to the database that will execute the SQLsql - the actual SQL to executeSQLExceptionpublic void executeSql(Connection conn, List<String> sql_list) throws SQLException
conn - sql_list - the list of SQL strings, each item is assumed to be a standalone and complete SQL statementSQLExceptionexecuteSql(Connection, String)public void dropSequence(Connection conn, String sequence_name) throws SQLException
conn - sequence_name - SQLExceptionpublic void insert(Connection conn, String table, String insert_cmd) throws SQLException
insert_cmd is the SQL that appears after the INSERT INTO
table.conn - table - insert_cmd - SQLExceptionpublic void update(Connection conn, String table, String column, String where, String value, int jdbc_type_int) throws SQLException
jdbc_type_int is the column's JDBC type as defined in
Types. The where clause is optional and may be null; if it is
non-null, it does not include the actual WHERE keyword.conn - table - column - where - value - jdbc_type_int - SQLExceptionpublic void addColumn(Connection conn, String table, String column, String generic_column, Object precision) throws SQLException
conn - the connection to the databasetable - the table where the column is to be addedcolumn - the new column namegeneric_column - the generic column type nameprecision - if the column type can take a precision, this can be non-nullSQLExceptionpublic abstract boolean isTableNotFoundException(SQLException e)
e - the SQL exception that occurredtrue if the given exception is the database's "table not found" exception.public abstract int getSequenceValue(Connection conn, String table, String key) throws SQLException
conn - The connection to use to get the sequence value.table - The table where the sequence is defined.key - The column on which the sequence is defined.SQLExceptionpublic abstract int getNextSequenceValue(Connection conn, String table, String key) throws SQLException
conn - The connection to use to get the sequence value.table - The table where the sequence is defined.key - The column on which the sequence is defined.SQLExceptionpublic String getSequenceInsertValue(Connection conn, String sequenceName)
conn - The connection to use to get the sequence value.sequenceName - The sequence name for the table.SQLExceptionpublic void createSequence(Connection conn, String name, String initial, String increment, String seqIdCacheSize) throws SQLException
conn - name - initial - increment - seqIdCacheSize - SQLExceptionpublic abstract void alterColumn(Connection conn, String table, String column, String generic_column_type, String default_value, String precision, Boolean nullable, Boolean reindex) throws SQLException
conn - connection to the databasetable - the name of the table where the column existscolumn - the name of the column to altergeneric_column_type - the new generic type of the columndefault_value - the new default valueprecision - the new precision of the columnnullable - the new nullable value (if true, it's value can now be NULL)reindex - if true, and the DB supports it, the table will be reindexedSQLExceptionpublic abstract void reindexTable(Connection conn, String table) throws SQLException
conn - table - SQLExceptionpublic String getEscapeCharacter()
public boolean supportsSelfReferringCascade()
public String getLimitClause(int limit)
limit - Copyright © 2008-2014 Red Hat, Inc.. All Rights Reserved.