public final class TableUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
FIELD_MODIFIER_NULL
null
|
static java.lang.String |
FUNCTION_LENGTH
The length case function ( different for each database)
|
static java.lang.String |
FUNCTION_UPPER
The upper case function ( different for each database)
|
Modifier and Type | Method and Description |
---|---|
void |
addColumn(java.lang.String pTableName,
java.lang.String pColumnName,
java.lang.String type)
Add a column to a table.
|
void |
alterColumn(java.lang.String pTableName,
java.lang.String pColumnName,
java.lang.String type,
boolean nullable)
Add a column to a table.
|
void |
clearCache()
Clears all cached information about this database.
|
static void |
clearCacheAll()
Clears all cached information about ALL databases.
|
java.lang.String |
convertLong(java.lang.String column) |
java.lang.String |
convertNull(java.lang.String column,
int value)
ISNULL function
|
java.lang.String |
convertNull(java.lang.String column,
java.lang.String value) |
void |
createdTable(java.lang.String tableName)
If a table is created then clear what was known about the table.
|
void |
createIndex(java.lang.String tableName,
java.lang.String logicalIndexName,
boolean unique,
java.lang.String columns)
create an index on a table.
|
void |
createTable(java.lang.String tableName,
java.lang.String fieldList,
java.lang.String primaryKey)
create a table
|
boolean |
doesColumnExist(java.lang.String tableName,
java.lang.String columnName)
Does the column exist ?
|
boolean |
doesProcedureExist(java.lang.String procedure)
Does this procedure exist ?
|
boolean |
doesTableExist(java.lang.String tableName)
Does the table exist ?
|
boolean |
doesTableIndexExist(java.lang.String tableName,
java.lang.String indexName)
Does an index of this name exist on this table ?
|
void |
dropAllIndexes(java.lang.String tableName)
drop all the indexes for a table
|
void |
dropColumn(java.lang.String table,
java.lang.String column)
Drop a column.
|
void |
dropIndex(java.lang.String tableName,
java.lang.String indexName)
Drop an index for a table.
|
void |
dropTable(java.lang.String tableName)
Drop a table
|
void |
dropZZTables()
Drop temporary tables (starts with zz)
|
ColumnInfo |
fetchColumn(java.lang.String tableName,
java.lang.String columnName)
get the column.
|
IndexInfo |
fetchIndexInfo(java.lang.String tableName,
java.lang.String indexName)
fetch the index info
|
static TableUtil |
find(DataBase dBase)
Find the table utils for this database.
|
ColumnInfo |
getColumn(java.lang.String tableName,
java.lang.String columnName)
get the column.
|
ColumnType |
getColumnDataType(java.lang.String tableName,
java.lang.String columnName)
get the column type.
|
ColumnInfo[] |
getColumns(java.lang.String tableName)
Does the column exist ?
|
int |
getColumnScale(java.lang.String tableName,
java.lang.String columnName)
The column scale
|
int |
getColumnSize(java.lang.String tableName,
java.lang.String columnName)
The column size
|
java.lang.String |
getColumnStdTypeName(java.lang.String tableName,
java.lang.String columnName)
get the column type.
|
int |
getColumnType(java.lang.String tableName,
java.lang.String columnName)
get the column type.
|
DataBase |
getDataBase()
Get the database for this table utilities.
|
java.lang.String |
getDoubleTypeName()
get the double type.
|
java.lang.String |
getFieldModifier(java.lang.String modifier)
Get the field modifier for this database.
|
IndexInfo[] |
getIndexes(java.lang.String tableName)
List All tables names.
|
java.lang.String |
getLongTypeName()
get the long type.
|
java.lang.String |
getSQLFunction(java.lang.String name)
Get the function for this database.
|
java.lang.String |
getTextTypeName()
get the text type.
|
java.lang.String |
isBlankClause(java.lang.String column)
column IS NULL or blank ( only white space)
|
boolean |
isColumnNullable(java.lang.String tableName,
java.lang.String columnName)
get the column type.
|
java.lang.String[] |
listTables()
List All tables names.
|
java.lang.String |
mathTruncate(java.lang.String column)
truncate a column value
|
int |
maxClauses()
The maximum clauses for this database type.
|
java.lang.String |
notBlankClause(java.lang.String column)
column IS NOT NULL or and not blank ( only white space)
|
void |
renameColumn(java.lang.String tableName,
java.lang.String oldName,
java.lang.String newName,
java.lang.String def)
Rename a column
|
void |
renameIndex(java.lang.String tableName,
java.lang.String oldIndexName,
java.lang.String newIndexName)
Rename an index for a table.
|
void |
renameTable(java.lang.String oldTableName,
java.lang.String newTableName)
Rename a table.
|
void |
updateStats(java.lang.String tableName)
Update stats
|
public static final java.lang.String FUNCTION_UPPER
public static final java.lang.String FUNCTION_LENGTH
public static final java.lang.String FIELD_MODIFIER_NULL
@CheckReturnValue public int maxClauses()
@CheckReturnValue @Nonnull public static TableUtil find(@Nonnull DataBase dBase)
dBase
- The database.public void clearCache()
public static void clearCacheAll()
@CheckReturnValue public boolean doesProcedureExist(@Nonnull java.lang.String procedure) throws java.sql.SQLException
procedure
- the namejava.sql.SQLException
- a serious problem@CheckReturnValue public boolean doesTableExist(@Nonnull java.lang.String tableName) throws java.sql.SQLException
tableName
- The table to checkjava.sql.SQLException
- A SQL exception@CheckReturnValue @Nonnull public ColumnType getColumnDataType(@Nonnull java.lang.String tableName, @Nonnull java.lang.String columnName) throws java.sql.SQLException
tableName
- the table namecolumnName
- the column namejava.sql.SQLException
- A SQL exception@CheckReturnValue public int getColumnType(@Nonnull java.lang.String tableName, @Nonnull java.lang.String columnName) throws java.sql.SQLException
tableName
- the table namecolumnName
- the column namejava.sql.SQLException
- A SQL exception@CheckReturnValue @Nonnull public ColumnInfo getColumn(@Nonnull java.lang.String tableName, @Nonnull java.lang.String columnName) throws java.sql.SQLException
tableName
- the table namecolumnName
- the column namejava.sql.SQLException
- A SQL exception@CheckReturnValue @Nullable public ColumnInfo fetchColumn(@Nonnull java.lang.String tableName, @Nonnull java.lang.String columnName) throws java.sql.SQLException
tableName
- the table namecolumnName
- the column namejava.sql.SQLException
- A SQL exception@CheckReturnValue @Nonnull public java.lang.String getColumnStdTypeName(@Nonnull java.lang.String tableName, @Nonnull java.lang.String columnName) throws java.sql.SQLException
tableName
- the table namecolumnName
- the column namejava.sql.SQLException
- A SQL exception@CheckReturnValue public boolean isColumnNullable(@Nonnull java.lang.String tableName, @Nonnull java.lang.String columnName) throws java.sql.SQLException
tableName
- the table namecolumnName
- the column namejava.sql.SQLException
- A SQL exception@CheckReturnValue public int getColumnSize(@Nonnull java.lang.String tableName, @Nonnull java.lang.String columnName) throws java.sql.SQLException
tableName
- The table namecolumnName
- The column namejava.sql.SQLException
- A SQL exception@CheckReturnValue public int getColumnScale(@Nonnull java.lang.String tableName, @Nonnull java.lang.String columnName) throws java.sql.SQLException
tableName
- The table namecolumnName
- The column namejava.sql.SQLException
- A SQL exception@CheckReturnValue public boolean doesColumnExist(@Nonnull java.lang.String tableName, @Nonnull java.lang.String columnName) throws java.sql.SQLException
tableName
- The table namecolumnName
- The column namejava.sql.SQLException
- A SQL exception@CheckReturnValue @Nullable public IndexInfo fetchIndexInfo(@Nonnull java.lang.String tableName, @Nonnull java.lang.String indexName) throws java.sql.SQLException
tableName
- the table nameindexName
- the index namejava.sql.SQLException
- a problem@CheckReturnValue @Nonnull public ColumnInfo[] getColumns(@Nonnull java.lang.String tableName) throws java.sql.SQLException
tableName
- The table namejava.sql.SQLException
- A SQL exception@CheckReturnValue public boolean doesTableIndexExist(@Nonnull java.lang.String tableName, @Nonnull java.lang.String indexName) throws java.sql.SQLException
tableName
- the table nameindexName
- the index namejava.sql.SQLException
- A SQL exception@CheckReturnValue @Nonnull public DataBase getDataBase()
@CheckReturnValue @Nonnull public java.lang.String convertNull(@Nonnull java.lang.String column, @Nonnull java.lang.String value)
column
- the columnvalue
- the default value@CheckReturnValue @Nonnull public java.lang.String notBlankClause(@Nonnull java.lang.String column)
column
- the column@CheckReturnValue @Nonnull public java.lang.String isBlankClause(@Nonnull java.lang.String column)
column
- A text/varchar column@CheckReturnValue @Nonnull public java.lang.String convertNull(@Nonnull java.lang.String column, int value)
column
- the columnvalue
- the default value@CheckReturnValue @Nonnull public java.lang.String mathTruncate(@Nonnull java.lang.String column)
column
- the column@CheckReturnValue @Nonnull public java.lang.String convertLong(@Nonnull java.lang.String column)
column
- the column@CheckReturnValue @Nonnull public java.lang.String getSQLFunction(@Nonnull java.lang.String name)
name
- our function name@CheckReturnValue @Nonnull public java.lang.String getFieldModifier(@Nonnull java.lang.String modifier)
modifier
- the modifier@CheckReturnValue @Nonnull public java.lang.String[] listTables() throws java.sql.SQLException
java.sql.SQLException
- A SQL Exception@CheckReturnValue @Nonnull public IndexInfo[] getIndexes(@Nonnull java.lang.String tableName) throws java.sql.SQLException
tableName
- The table to checkjava.sql.SQLException
- A SQL exceptionpublic void alterColumn(@Nonnull java.lang.String pTableName, @Nonnull java.lang.String pColumnName, @Nonnull java.lang.String type, boolean nullable) throws java.sql.SQLException
pTableName
- The table to add the column.pColumnName
- The column to add.type
- The column type.nullable
- the field is nullablejava.sql.SQLException
- A SQL exceptionpublic void addColumn(@Nonnull java.lang.String pTableName, @Nonnull java.lang.String pColumnName, @Nonnull java.lang.String type) throws java.sql.SQLException
pTableName
- The table to add the column.pColumnName
- The column to add.type
- The column type.java.sql.SQLException
- A SQL exceptionpublic void updateStats(@Nonnull java.lang.String tableName) throws java.lang.Exception
tableName
- The table namejava.lang.Exception
- A serious problempublic void renameTable(@Nonnull java.lang.String oldTableName, @Nonnull java.lang.String newTableName) throws java.sql.SQLException
oldTableName
- The old table.newTableName
- The new tablejava.sql.SQLException
- A SQL exceptionpublic void dropColumn(@Nonnull java.lang.String table, @Nonnull java.lang.String column) throws java.sql.SQLException
table
- The table to drop the column fromcolumn
- The column to dropjava.sql.SQLException
- A serious problempublic void renameColumn(@Nonnull java.lang.String tableName, @Nonnull java.lang.String oldName, @Nonnull java.lang.String newName, @Nonnull java.lang.String def) throws java.lang.Exception
tableName
- The table to rename the column.oldName
- The old column namenewName
- The new column namedef
- The defjava.lang.Exception
- A serious problempublic void createTable(@Nonnull java.lang.String tableName, @Nonnull java.lang.String fieldList, @Nullable java.lang.String primaryKey) throws java.sql.SQLException
fieldList
- The field listtableName
- The table to create.primaryKey
- the primary keyjava.sql.SQLException
- a SQL exceptionpublic void createIndex(@Nonnull java.lang.String tableName, @Nonnull java.lang.String logicalIndexName, boolean unique, @Nonnull java.lang.String columns) throws java.sql.SQLException
tableName
- The table namelogicalIndexName
- the index nameunique
- is it unique ?columns
- The columnsjava.sql.SQLException
- A SQL exceptionpublic void dropTable(java.lang.String tableName) throws java.lang.Exception
tableName
- The table name to dropjava.lang.Exception
- A serious problempublic void dropZZTables() throws java.lang.Exception
java.lang.Exception
- A serious problempublic void dropAllIndexes(@Nonnull java.lang.String tableName) throws java.lang.Exception
tableName
- The table namejava.lang.Exception
- A serious problempublic void dropIndex(@Nonnull java.lang.String tableName, @Nonnull java.lang.String indexName) throws java.sql.SQLException
tableName
- The table name to drop the index from.indexName
- The index to dropjava.sql.SQLException
- A SQL exceptionpublic void renameIndex(@Nonnull java.lang.String tableName, @Nonnull java.lang.String oldIndexName, @Nonnull java.lang.String newIndexName)
tableName
- The table name to drop the index from.oldIndexName
- The old index namenewIndexName
- The new index name@CheckReturnValue public java.lang.String getTextTypeName()
@CheckReturnValue public java.lang.String getLongTypeName()
@CheckReturnValue public java.lang.String getDoubleTypeName()
public void createdTable(@Nonnull java.lang.String tableName) throws java.sql.SQLException
tableName
- the table is created.java.sql.SQLException
- A SQL exceptionstSoftware Copyright © 2001-2014 stSoftware All Rights Reserved.