org.apache.jetspeed.serializer
Class JetspeedDDLUtil

java.lang.Object
  extended by org.apache.jetspeed.serializer.JetspeedDDLUtil

public class JetspeedDDLUtil
extends Object

Jetspeed DDLUtil

The Jetspeed DDL Utility is capabale of extracting existing schema information as well as recreating databases.

Version:
$Id: $
Author:
Hajo Birthelmer

Field Summary
private  String _databaseName
          The database name.
private  boolean connected
           
private  DataSource dataSource
          The data source to test against.
static String DATASOURCE_CLASS
           
static String DATASOURCE_DATABASENAME
           
static String DATASOURCE_DRIVER
           
static String DATASOURCE_PASSWORD
           
static String DATASOURCE_URL
           
static String DATASOURCE_USERNAME
           
private static org.apache.commons.logging.Log log
          Logger
private  org.apache.ddlutils.model.Database model
          The database model.
(package private)  Map parameters
           
private  org.apache.ddlutils.Platform platform
           
(package private)  org.apache.ddlutils.model.JdbcTypeCategoryEnum temEnum
           
(package private)  org.apache.ddlutils.PlatformUtils utils
           
(package private)  StringWriter writer
           
 
Constructor Summary
JetspeedDDLUtil()
           
 
Method Summary
 void alterDatabase(org.apache.ddlutils.model.Database model)
          Alter an existing database from the given model.
protected  org.apache.ddlutils.Platform connectToDatabase(DataSource dataSource)
           Create a database connection (platform instance) from a data source
protected  org.apache.ddlutils.Platform connectToDatabase(String databaseType)
           Create a database connection (platform instance) from a (case insensitive) database type (like MySQL)
 void createDatabase(org.apache.ddlutils.model.Database model)
          Creates a new database from the given model.
protected  org.apache.ddlutils.model.Database createDatabaseSchemaFromString(String dbDef)
          Parses the database defined in the given XML definition String and creates a database schema (model) object
protected  org.apache.ddlutils.model.Database createDatabaseSchemaFromXML(String fileName)
          Parses the database defined in the given XML file and creates a database schema (model) object
protected  void dropDatabase()
          Drops the tables defined in the database model.
protected  void dropDatabaseTables(org.apache.ddlutils.model.Database model)
          Drops the tables defined in the database model on this connection.
 DataSource getDataSource()
           
protected  org.apache.ddlutils.model.Database getModel()
          Returns the database model.
 org.apache.ddlutils.Platform getPlatform()
           
protected  Object getPropertyValue(org.apache.commons.beanutils.DynaBean bean, String propName)
          Determines the value of the bean's property that has the given name.
 List getRows(String tableName)
           
 String getSelectQueryForAllString(org.apache.ddlutils.model.Table table)
           
 void init(Map parameters)
          Initializes the datasource and the connection (platform)
protected  org.apache.ddlutils.model.Database insertData(org.apache.ddlutils.model.Database model, String dataXml)
           Inserts data into the database.
protected  org.apache.ddlutils.model.Database insertData(String dataXml)
          Inserts data into the database.
 boolean isDatabaseSupported(String driverName, String jdbcConnectionUrl)
          Tries to determine whether a the jdbc driver and connection url re supported.
private  void modifyVarBinaryColumn(org.apache.ddlutils.model.Database targetModel, String tableName, String columnName)
           
 org.apache.ddlutils.model.Database readModelFromDatabase(String databaseName)
          Reads the database model from a live database.
 void startUp()
           
 void tearDown()
           
protected  void updateDatabaseSchema(org.apache.ddlutils.model.Database targetModel, boolean alterDb)
           Update a given database schema to match the schema of targetModel If alterDB is true, the routine attempts to modify the existing database shcema while preserving the data (as much as possible).
 void writeDatabaseSchematoFile(String fileName)
          Parses the database defined in the given XML file and creates a database schema (model) object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATASOURCE_DATABASENAME

public static final String DATASOURCE_DATABASENAME

DATASOURCE_CLASS

public static final String DATASOURCE_CLASS

DATASOURCE_DRIVER

public static final String DATASOURCE_DRIVER

DATASOURCE_URL

public static final String DATASOURCE_URL

DATASOURCE_USERNAME

public static final String DATASOURCE_USERNAME

DATASOURCE_PASSWORD

public static final String DATASOURCE_PASSWORD

log

private static final org.apache.commons.logging.Log log
Logger


temEnum

org.apache.ddlutils.model.JdbcTypeCategoryEnum temEnum

parameters

Map parameters

utils

org.apache.ddlutils.PlatformUtils utils

writer

StringWriter writer

platform

private org.apache.ddlutils.Platform platform

dataSource

private DataSource dataSource
The data source to test against.


_databaseName

private String _databaseName
The database name.


model

private org.apache.ddlutils.model.Database model
The database model.


connected

private boolean connected
Constructor Detail

JetspeedDDLUtil

public JetspeedDDLUtil()
Method Detail

startUp

public void startUp()

tearDown

public void tearDown()

isDatabaseSupported

public boolean isDatabaseSupported(String driverName,
                                   String jdbcConnectionUrl)
Tries to determine whether a the jdbc driver and connection url re supported.

Parameters:
driverName - The fully qualified name of the JDBC driver
jdbcConnectionUrl - The connection url
Returns:
True if this driver/url is supported

writeDatabaseSchematoFile

public void writeDatabaseSchematoFile(String fileName)
Parses the database defined in the given XML file and creates a database schema (model) object

Parameters:
fileName -

createDatabaseSchemaFromXML

protected org.apache.ddlutils.model.Database createDatabaseSchemaFromXML(String fileName)
Parses the database defined in the given XML file and creates a database schema (model) object

Parameters:
dbDef - The database XML definition
Returns:
The database model

createDatabaseSchemaFromString

protected org.apache.ddlutils.model.Database createDatabaseSchemaFromString(String dbDef)
Parses the database defined in the given XML definition String and creates a database schema (model) object

Parameters:
dbDef - The database XML definition
Returns:
The database model

connectToDatabase

protected org.apache.ddlutils.Platform connectToDatabase(DataSource dataSource)

Create a database connection (platform instance) from a data source

Parameters:
dataSource -

connectToDatabase

protected org.apache.ddlutils.Platform connectToDatabase(String databaseType)

Create a database connection (platform instance) from a (case insensitive) database type (like MySQL)

Parameters:
dataSource -

updateDatabaseSchema

protected void updateDatabaseSchema(org.apache.ddlutils.model.Database targetModel,
                                    boolean alterDb)
                             throws org.apache.jetspeed.serializer.SerializerException

Update a given database schema to match the schema of targetModel If alterDB is true, the routine attempts to modify the existing database shcema while preserving the data (as much as possible). If not, the existing tables are dropped prior to recreate

Parameters:
targetModel - The new database model
alterDb - if true, try to use alter database and preserve data
Throws:
org.apache.jetspeed.serializer.SerializerException

modifyVarBinaryColumn

private void modifyVarBinaryColumn(org.apache.ddlutils.model.Database targetModel,
                                   String tableName,
                                   String columnName)

alterDatabase

public void alterDatabase(org.apache.ddlutils.model.Database model)
                   throws org.apache.jetspeed.serializer.SerializerException
Alter an existing database from the given model. Data is preserved as much as possible

Parameters:
model - The new database model
Throws:
org.apache.jetspeed.serializer.SerializerException

createDatabase

public void createDatabase(org.apache.ddlutils.model.Database model)
                    throws org.apache.jetspeed.serializer.SerializerException
Creates a new database from the given model. Note that all data is LOST

Parameters:
model - The new database model
Throws:
org.apache.jetspeed.serializer.SerializerException

insertData

protected org.apache.ddlutils.model.Database insertData(org.apache.ddlutils.model.Database model,
                                                        String dataXml)
                                                 throws org.apache.ddlutils.DatabaseOperationException

Inserts data into the database. Data is expected to be in the format

Parameters:
model - The database model
dataXml - The data xml
Returns:
The database
Throws:
org.apache.ddlutils.DatabaseOperationException

dropDatabaseTables

protected void dropDatabaseTables(org.apache.ddlutils.model.Database model)
                           throws org.apache.ddlutils.DatabaseOperationException
Drops the tables defined in the database model on this connection.

Parameters:
model - The database model
Throws:
org.apache.ddlutils.DatabaseOperationException

readModelFromDatabase

public org.apache.ddlutils.model.Database readModelFromDatabase(String databaseName)
Reads the database model from a live database.

Parameters:
platform - The physical database connection
databaseName - The name of the resulting database
Returns:
The model

init

public void init(Map parameters)
Initializes the datasource and the connection (platform)


getModel

protected org.apache.ddlutils.model.Database getModel()
Returns the database model.

Returns:
The model

insertData

protected org.apache.ddlutils.model.Database insertData(String dataXml)
                                                 throws org.apache.ddlutils.DatabaseOperationException
Inserts data into the database.

Parameters:
dataXml - The data xml
Returns:
The database
Throws:
org.apache.ddlutils.DatabaseOperationException

dropDatabase

protected void dropDatabase()
                     throws org.apache.ddlutils.DatabaseOperationException
Drops the tables defined in the database model.

Throws:
org.apache.ddlutils.DatabaseOperationException

getPropertyValue

protected Object getPropertyValue(org.apache.commons.beanutils.DynaBean bean,
                                  String propName)
Determines the value of the bean's property that has the given name. Depending on the case-setting of the current builder, the case of teh name is considered or not.

Parameters:
bean - The bean
propName - The name of the property
Returns:
The value

getDataSource

public DataSource getDataSource()

getPlatform

public org.apache.ddlutils.Platform getPlatform()

getRows

public List getRows(String tableName)

getSelectQueryForAllString

public String getSelectQueryForAllString(org.apache.ddlutils.model.Table table)


Copyright © 1999-2007 Apache Software Foundation. All Rights Reserved.