org.clazzes.jdbc2xml.schema.impl
Class SchemaEngineImpl

java.lang.Object
  extended by org.clazzes.jdbc2xml.schema.SchemaEngine
      extended by org.clazzes.jdbc2xml.schema.impl.SchemaEngineImpl

public class SchemaEngineImpl
extends SchemaEngine

The default implementation of the schema engine.

Author:
wglas

Constructor Summary
SchemaEngineImpl()
          Default constructor.
 
Method Summary
 TableInfo addColumn(TableInfo ti, ColumnInfo columnInfo)
          Add a column to an existing table.
 TableInfo addForeignKey(TableInfo ti, ForeignKeyInfo foreignKeyInfo)
          Add a foreign key to an existing table.
 TableInfo addIndex(TableInfo ti, IndexInfo indexInfo)
          Add an index to an existing table.
 TableInfo changeColumn(TableInfo ti, java.lang.String oldColumnName, ColumnInfo columnInfo)
          Rename an existing column of an existing table and possibly change it's type.
 void commit()
          Perform all pending schema modifications and discard the rollback history.
 void createForeignKeys(TableInfo ti)
          Create foreign keys of an existing table in the database.
 void createIndices(TableInfo ti)
          Calls addIndex for each index
 java.sql.PreparedStatement createInsertStatement(TableInfo ti)
          Create an insert statement for all column in the given table.
 void createTable(TableInfo ti, boolean addForeignKeys)
          Create a table in the database, including primary key and indices (which must have been added already).
 TableInfo dropColumn(TableInfo ti, java.lang.String columnName, boolean force)
          Drop an existing column of an existing table.
 TableInfo dropForeignKey(TableInfo ti, java.lang.String fkName)
          Drop an existing foreign key of an existing table.
 TableInfo dropForeignKeys(TableInfo ti)
          Drop all existing foreign keys of an existing table.
 TableInfo dropIndex(TableInfo ti, java.lang.String indexName)
          Drop an index from an existing table.
 void dropStaleBackupTables()
          Some operations like drop table or drop column create backup tables for performing rollback operations.
 void dropTable(TableInfo ti, boolean force)
          Drop an existing table.
 void dropTables(java.util.List<TableInfo> tables, boolean force)
          Drop a list of existing table.
 TableInfo fetchTableInfo(java.lang.String tableName, IndexFilter filter)
          Retrieve the current layout of the given table in the database.
 java.util.List<TableInfo> fetchTableInfos(TableFilter filter)
          Return the layout of multiple table in the database.
 TableInfo modifyColumn(TableInfo ti, ColumnInfo columnInfo)
          Change an existing column of an existing table.
 void rollback()
          Roll back all schema operations undertaken since the last call to SchemaEngine.commit() or SchemaEngine.rollback().
 
Methods inherited from class org.clazzes.jdbc2xml.schema.SchemaEngine
getConnection, getDialect, getSchema, getTimeZone, newInstance, setConnection, setDialect, setSchema, setTimeZone
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SchemaEngineImpl

public SchemaEngineImpl()
Default constructor.

Method Detail

fetchTableInfo

public TableInfo fetchTableInfo(java.lang.String tableName,
                                IndexFilter filter)
                         throws java.sql.SQLException
Description copied from class: SchemaEngine
Retrieve the current layout of the given table in the database.

Specified by:
fetchTableInfo in class SchemaEngine
Parameters:
tableName - The name of the table to search.
filter - The filter retrieval configuration. If a null value is passed, a default filter will be used, which skips internal indices.
Returns:
The complete table information.
Throws:
java.sql.SQLException - Upon database errors.
See Also:
IndexFilter.isKeepInternalIndices()

fetchTableInfos

public java.util.List<TableInfo> fetchTableInfos(TableFilter filter)
                                          throws java.sql.SQLException
Description copied from class: SchemaEngine
Return the layout of multiple table in the database.

Specified by:
fetchTableInfos in class SchemaEngine
Parameters:
filter - If null, return all tables of the configured schema. Otherwise return only those tables, for which TableFilter.processTable(String) returns true. Additionally, a null value incurs default table filtering, which means to fetch all table infos.
Returns:
The list of table informations.
Throws:
java.sql.SQLException - Upon database errors.

createInsertStatement

public java.sql.PreparedStatement createInsertStatement(TableInfo ti)
                                                 throws java.sql.SQLException
Description copied from class: SchemaEngine
Create an insert statement for all column in the given table. The placeholders in the insert statement are in the order of the ColumnInfo object inside the TableInfo's list of column

Specified by:
createInsertStatement in class SchemaEngine
Parameters:
ti - The table metadata.
Returns:
A Prepared statement that may be used to insert data into the database.
Throws:
java.sql.SQLException - Upon database errors.

createTable

public void createTable(TableInfo ti,
                        boolean addForeignKeys)
                 throws java.sql.SQLException
Description copied from class: SchemaEngine
Create a table in the database, including primary key and indices (which must have been added already).

Specified by:
createTable in class SchemaEngine
Parameters:
ti - The table metadata.
addForeignKeys - If this parameter is true, all foreign keys are generated together with the table structure. If set to false, you may create the foreign keys later on using SchemaEngine.createForeignKeys(TableInfo).
Throws:
java.sql.SQLException - upon database errors.

createIndices

public void createIndices(TableInfo ti)
                   throws java.sql.SQLException
Calls addIndex for each index

Parameters:
ti -
Throws:
java.sql.SQLException

createForeignKeys

public void createForeignKeys(TableInfo ti)
                       throws java.sql.SQLException
Description copied from class: SchemaEngine
Create foreign keys of an existing table in the database.

Specified by:
createForeignKeys in class SchemaEngine
Parameters:
ti - The table metadata.
Throws:
java.sql.SQLException - Upon database errors.

dropForeignKeys

public TableInfo dropForeignKeys(TableInfo ti)
                          throws java.sql.SQLException
Description copied from class: SchemaEngine
Drop all existing foreign keys of an existing table.

Specified by:
dropForeignKeys in class SchemaEngine
Parameters:
ti - TableInfo describing the table containing the foreign keys to drop.
Returns:
The updated TableInfo without foreign keys.
Throws:
java.sql.SQLException - Upon database errors.

dropTable

public void dropTable(TableInfo ti,
                      boolean force)
               throws java.sql.SQLException
Description copied from class: SchemaEngine
Drop an existing table.

Specified by:
dropTable in class SchemaEngine
Parameters:
ti - TableInfo describing the table to be dropped.
force - If set to true, the data is not backed up before dropping the table. Consequently, rollback is not supported, if force is set to true.
Throws:
java.sql.SQLException - Upon database errors.

dropTables

public void dropTables(java.util.List<TableInfo> tables,
                       boolean force)
                throws java.sql.SQLException
Description copied from class: SchemaEngine
Drop a list of existing table.

Specified by:
dropTables in class SchemaEngine
Parameters:
tables - A list of TableInfo objects describing the tables to be dropped.
force - If set to true, the data is not backed up before dropping the table. Consequently, rollback is not supported, if force is set to true.
Throws:
java.sql.SQLException - Upon database errors.

addColumn

public TableInfo addColumn(TableInfo ti,
                           ColumnInfo columnInfo)
                    throws java.sql.SQLException
Description copied from class: SchemaEngine
Add a column to an existing table.

Specified by:
addColumn in class SchemaEngine
Parameters:
ti - TableInfo describing the table to add column to.
columnInfo - ColumnInfo holding data for the column to be added.
Returns:
The updated TableInfo.
Throws:
java.sql.SQLException - Upon database errors.

modifyColumn

public TableInfo modifyColumn(TableInfo ti,
                              ColumnInfo columnInfo)
                       throws java.sql.SQLException
Description copied from class: SchemaEngine
Change an existing column of an existing table.

Specified by:
modifyColumn in class SchemaEngine
Parameters:
ti - TableInfo describing the table containing the column to change.
columnInfo - ColumnInfo holding new definition data for the column.
Returns:
The updated TableInfo.
Throws:
java.sql.SQLException - Upon database errors.

changeColumn

public TableInfo changeColumn(TableInfo ti,
                              java.lang.String oldColumnName,
                              ColumnInfo columnInfo)
                       throws java.sql.SQLException
Description copied from class: SchemaEngine
Rename an existing column of an existing table and possibly change it's type.

Specified by:
changeColumn in class SchemaEngine
Parameters:
ti - TableInfo describing the table containing the column to change.
oldColumnName - The original name of the column.
columnInfo - ColumnInfo holding the new name and the new definition data for the column.
Returns:
The updated TableInfo.
Throws:
java.sql.SQLException - Upon database errors.

dropColumn

public TableInfo dropColumn(TableInfo ti,
                            java.lang.String columnName,
                            boolean force)
                     throws java.sql.SQLException
Description copied from class: SchemaEngine
Drop an existing column of an existing table.

Specified by:
dropColumn in class SchemaEngine
Parameters:
ti - TableInfo describing the table containing the column to drop.
columnName - Name of the column to drop.
force - If set to true, the data is not backed up before dropping the column. Consequently, rollback is not supported, if force is set to true.
Returns:
The updated TableInfo.
Throws:
java.sql.SQLException - Upon database errors.

addForeignKey

public TableInfo addForeignKey(TableInfo ti,
                               ForeignKeyInfo foreignKeyInfo)
                        throws java.sql.SQLException
Description copied from class: SchemaEngine
Add a foreign key to an existing table.

Specified by:
addForeignKey in class SchemaEngine
Parameters:
ti - TableInfo describing the table to add the foreign key to.
foreignKeyInfo - The ForeignKeyInfo to add.
Returns:
The updated TableInfo.
Throws:
java.sql.SQLException - Upon database errors.

dropForeignKey

public TableInfo dropForeignKey(TableInfo ti,
                                java.lang.String fkName)
                         throws java.sql.SQLException
Description copied from class: SchemaEngine
Drop an existing foreign key of an existing table.

Specified by:
dropForeignKey in class SchemaEngine
Parameters:
ti - TableInfo describing the table to drop the foreign key from.
fkName - The ForeignKeyInfo to drop.
Returns:
The updated TableInfo.
Throws:
java.sql.SQLException - Upon database errors.

addIndex

public TableInfo addIndex(TableInfo ti,
                          IndexInfo indexInfo)
                   throws java.sql.SQLException
Description copied from class: SchemaEngine
Add an index to an existing table.

Specified by:
addIndex in class SchemaEngine
Parameters:
ti - TableInfo describing the table to add the index.
indexInfo - The IndexInfo to add.
Returns:
The updated TableInfo.
Throws:
java.sql.SQLException - Upon database errors.

dropIndex

public TableInfo dropIndex(TableInfo ti,
                           java.lang.String indexName)
                    throws java.sql.SQLException
Description copied from class: SchemaEngine
Drop an index from an existing table.

Specified by:
dropIndex in class SchemaEngine
Parameters:
ti - TableInfo describing the table to drop the index from.
indexName - The name of the IndexInfo to drop.
Returns:
The updated TableInfo.
Throws:
java.sql.SQLException - Upon database errors.

dropStaleBackupTables

public void dropStaleBackupTables()
                           throws java.sql.SQLException
Description copied from class: SchemaEngine
Some operations like drop table or drop column create backup tables for performing rollback operations. If a rollback of such an operation fails or a user does not SchemaEngine.commit() after such operations, these backup tables remain in the target database. This call searches these tables, which are named like JDBC2XML__* and drops them, if necessary.

Specified by:
dropStaleBackupTables in class SchemaEngine
Throws:
java.sql.SQLException

commit

public void commit()
            throws java.sql.SQLException
Description copied from class: SchemaEngine
Perform all pending schema modifications and discard the rollback history.

Specified by:
commit in class SchemaEngine
Throws:
java.sql.SQLException - Upon database errors.

rollback

public void rollback()
              throws java.sql.SQLException
Description copied from class: SchemaEngine
Roll back all schema operations undertaken since the last call to SchemaEngine.commit() or SchemaEngine.rollback().

Specified by:
rollback in class SchemaEngine
Throws:
java.sql.SQLException - Upon database errors or when a rollback of a schema operation is not supported.


Copyright © 2008. All Rights Reserved.