public class DbLoader extends Object
A tool to set up a OSPI database. This tool was created so that OSPI developers would only have to maintain a single set of xml documents to define the OSPI database schema and data. Previously it was necessary to maintain different scripts for each database we wanted to support.
DbLoader reads the generic types that are specified in tables.xml and tries to map them to local types by querying the database metadata via methods implemented by the JDBC driver. Fallback mappings can be supplied in dbloader.xml for cases where the JDBC driver is not able to determine the appropriate mapping. Such cases will be reported to standard out.
An xsl transformation is used to produce the DROP TABLE and CREATE TABLE SQL statements. These statements can be altered by modifying tables.xsl
all table names should have lower case names
Generic data types (as defined in java.sql.Types) which may be specified
in tables.xml include:
BIT, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, REAL, DOUBLE,
NUMERIC, DECIMAL, CHAR, VARCHAR, LONGVARCHAR, DATE, TIME, TIMESTAMP,
BINARY, VARBINARY, LONGVARBINARY, NULL, OTHER, JAVA_OBJECT, DISTINCT,
STRUCT, ARRAY, BLOB, CLOB, REF
WARNING: YOU MAY WANT TO MAKE A BACKUP OF YOUR DATABASE BEFORE RUNNING DbLoader
DbLoader will perform the following steps:
Types| Modifier and Type | Field and Description |
|---|---|
protected org.apache.commons.logging.Log |
logger |
| Constructor and Description |
|---|
DbLoader(Connection con) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
alterTable(String alterTableStatement) |
protected void |
createTable(String createTableStatement) |
protected void |
dropTable(String dropTableStatement) |
Connection |
getCon() |
String |
getDbName() |
String |
getDbVersion() |
String |
getDriverName() |
String |
getDriverVersion() |
protected Element |
getFirstChildWithName(Element parent,
String name) |
protected int |
getJavaSqlDataTypeOfColumn(Document tablesDocGeneric,
String tableName,
String columnName) |
protected int |
getJavaSqlType(String genericDataTypeName) |
protected String |
getLocalDataTypeName(String genericDataTypeName) |
protected String |
getNodeValue(Node node) |
org.sakaiproject.warehouse.util.db.DbLoader.PropertiesHandler |
getPropertiesHandler() |
PreparedStatement |
getPstmt() |
Statement |
getStmt() |
Hashtable |
getTableColumnTypes() |
PrintWriter |
getTableScriptOut() |
Document |
getTablesDoc() |
Document |
getTablesDocGeneric() |
protected Element |
getTableWithName(Document tablesDoc,
String tableName) |
protected XMLReader |
getXMLReader() |
protected void |
indexTable(String indexTableStatement) |
protected void |
initTableScript() |
boolean |
isAlterTables() |
boolean |
isCreateTables() |
boolean |
isCreateTableScript() |
boolean |
isDropTables() |
boolean |
isIndexTables() |
boolean |
isPopulateTables() |
protected void |
printInfo() |
protected void |
readProperties(XMLReader parser,
InputStream properties) |
protected void |
replaceDataTypes(Document tablesDoc) |
void |
runLoader(InputStream tables) |
void |
setAlterTables(boolean alterTables) |
void |
setCon(Connection con) |
void |
setCreateTables(boolean createTables) |
void |
setCreateTableScript(boolean createTableScript) |
void |
setDbName(String dbName) |
void |
setDbVersion(String dbVersion) |
void |
setDriverName(String driverName) |
void |
setDriverVersion(String driverVersion) |
void |
setDropTables(boolean dropTables) |
void |
setIndexTables(boolean indexTables) |
void |
setPopulateTables(boolean populateTables) |
void |
setPropertiesHandler(org.sakaiproject.warehouse.util.db.DbLoader.PropertiesHandler propertiesHandler) |
void |
setPstmt(PreparedStatement pstmt) |
void |
setStmt(Statement stmt) |
void |
setTableColumnTypes(Hashtable tableColumnTypes) |
void |
setTableScriptOut(PrintWriter tableScriptOut) |
void |
setTablesDoc(Document tablesDoc) |
void |
setTablesDocGeneric(Document tablesDocGeneric) |
public DbLoader(Connection con)
public void runLoader(InputStream tables)
protected XMLReader getXMLReader() throws SAXException, ParserConfigurationException
protected void printInfo()
throws SQLException
SQLExceptionprotected void initTableScript()
throws IOException
IOExceptionprotected void replaceDataTypes(Document tablesDoc)
protected int getJavaSqlDataTypeOfColumn(Document tablesDocGeneric, String tableName, String columnName)
protected int getJavaSqlType(String genericDataTypeName)
protected void dropTable(String dropTableStatement)
protected void createTable(String createTableStatement)
protected void alterTable(String alterTableStatement)
protected void indexTable(String indexTableStatement)
protected void readProperties(XMLReader parser, InputStream properties) throws SAXException, IOException
SAXExceptionIOExceptionpublic Connection getCon()
public void setCon(Connection con)
public Statement getStmt()
public void setStmt(Statement stmt)
public PreparedStatement getPstmt()
public void setPstmt(PreparedStatement pstmt)
public Document getTablesDoc()
public void setTablesDoc(Document tablesDoc)
public Document getTablesDocGeneric()
public void setTablesDocGeneric(Document tablesDocGeneric)
public boolean isCreateTableScript()
public void setCreateTableScript(boolean createTableScript)
public boolean isPopulateTables()
public void setPopulateTables(boolean populateTables)
public PrintWriter getTableScriptOut()
public void setTableScriptOut(PrintWriter tableScriptOut)
public boolean isDropTables()
public void setDropTables(boolean dropTables)
public boolean isCreateTables()
public void setCreateTables(boolean createTables)
public String getDbName()
public void setDbName(String dbName)
public String getDbVersion()
public void setDbVersion(String dbVersion)
public String getDriverName()
public void setDriverName(String driverName)
public String getDriverVersion()
public void setDriverVersion(String driverVersion)
public boolean isAlterTables()
public void setAlterTables(boolean alterTables)
public boolean isIndexTables()
public void setIndexTables(boolean indexTables)
public Hashtable getTableColumnTypes()
public void setTableColumnTypes(Hashtable tableColumnTypes)
public org.sakaiproject.warehouse.util.db.DbLoader.PropertiesHandler getPropertiesHandler()
public void setPropertiesHandler(org.sakaiproject.warehouse.util.db.DbLoader.PropertiesHandler propertiesHandler)
Copyright © 2003-2014 Sakai Project. All Rights Reserved.