void |
createTable(java.lang.String tableName,
java.lang.String... colNameThenType)
Creates a table using Sql of format:
CREATE TABLE ( , ...
void |
deleteColumnFromTable(java.lang.String tableName,
java.lang.String columnName)
Deletes the specified column from the table.
|
void |
executeSql(java.lang.String sql)
Execute the passed sql.
|
void |
finalize() |
SqlConnection |
getConnection()
Returns fire to play with.
|
java.lang.String |
getTableName()
Returns the stored table name.
|
void |
setColumnInTableToValue(java.lang.String tableName,
java.lang.String columnName,
java.lang.Object defValue)
Sets all column entries of the passed name in the passed table to the passed value.
|
void |
setTableName(java.lang.String table)
Sets a table name to be stored.
|
void |
simpleChangeType(java.lang.String tableName,
java.lang.String columnName,
java.lang.String sqlType)
Attempts to change a column type through SQL.
|
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
DatabaseMigrationTool
public DatabaseMigrationTool(SqlDatabase config)
throws java.sql.SQLException
Creates a new DatabaseMigrationTool connected to the database the passed configuration
referes to. Opens a connection to database after creation.
- Throws:
java.sql.SQLException
-
DatabaseMigrationTool
public DatabaseMigrationTool(SqlConnection connection)
throws java.sql.SQLException
Creates a new DatabaseMigrationTool connected to the database the passed configuration
referes to. Opens a connection to database after creation.
- Throws:
java.sql.SQLException
-
Method Detail
-
addColumnToTable
public void addColumnToTable(java.lang.String tableName,
java.lang.String columnName,
java.lang.String columnType)
throws java.sql.SQLException
Add a new column to the connected database.
- Parameters:
tableName - - Name of table to add column to.columnName - - Name of column to create.columnType - - Sql type of column to create, used directly in SQL statement.
- Throws:
java.sql.SQLException
-
addColumnToTable
public void addColumnToTable(java.lang.String tableName,
java.lang.String columnName,
java.lang.String columnType,
java.lang.Object defValue)
throws java.sql.SQLException
Adds a column to the specified table in the connected database. Every entry in the table is set
to the passed default value.
- Parameters:
tableName - - Name of table to add column to.columnName - - Name of column to create.columnType - - SQL type of column to create, used directly in SQL.defValue - - Default value to set each entry to.
- Throws:
java.sql.SQLException
-
setColumnInTableToValue
public void setColumnInTableToValue(java.lang.String tableName,
java.lang.String columnName,
java.lang.Object defValue)
throws java.sql.SQLException
Sets all column entries of the passed name in the passed table to the passed value.
- Parameters:
tableName - - Name of table to add column to.columnName - - Name of column to create.defValue - - Default value to set each entry to.
- Throws:
java.sql.SQLException
-
deleteColumnFromTable
public void deleteColumnFromTable(java.lang.String tableName,
java.lang.String columnName)
throws java.sql.SQLException
Deletes the specified column from the table.
- Parameters:
tableName - columnName -
- Throws:
java.sql.SQLException
-
copyColumnDataToColumn
public void copyColumnDataToColumn(java.lang.String tableName,
java.lang.String targetColumn,
java.lang.String destColumn)
throws java.sql.SQLException
Copies all data from column matching targetColumn name to destColumn in the passed table.
- Parameters:
tableName - - Table to copy data.targetColumn - - Column to copy from.destColumn - - Column to copy to.
- Throws:
java.sql.SQLException
-
changeColumnName
public void changeColumnName(java.lang.String tableName,
java.lang.String origName,
java.lang.String newName,
java.lang.String sqlType)
throws java.sql.SQLException
Renames a column. Does not change the type or handle changing data. Simply renames.
- Parameters:
tableName - - Table name to rename column.origName - - Original column name.newName - - New Column name.sqlType - - Current SQL type of column.
- Throws:
java.sql.SQLException
-
simpleChangeType
public void simpleChangeType(java.lang.String tableName,
java.lang.String columnName,
java.lang.String sqlType)
throws java.sql.SQLException
Attempts to change a column type through SQL. Conversion is handled by the database.
Note: Never has worked with HSQLDBs.
- Parameters:
tableName - columnName - sqlType -
- Throws:
java.sql.SQLException
|