DODS 7.2 API

org.webdocwf.util.sql
Class SQLSplitter

java.lang.Object
  extended by org.webdocwf.util.sql.SQLSplitter

public class SQLSplitter
extends java.lang.Object

Class SQLSplitter copies all SQL commands from all SQL files which are situated in the working directory and all its subdirectories into new SQL files. Original SQL files are created by DODS - Enhydra. All SQL commands are copied into first sql file except sql commands which reference to foreign and primary key columns. In the second sql file class puts ALTER TABLE sql commands with adding foreign key references. In the third sql file class puts ALTER TABLE sql commands with adding primary keys. In the forth sql file class puts DROP TABLE sql commands for all tables which were created by create table SQL statements in the first file. In the fifth sql file class puts CREATE INDEX sql commands for all tables which were created by create table SQL statements in the first file. In the sixth sql file class puts DROP foreign key sql commands for all tables which were created by create table SQL statements in the first file. In the seventh sql file class puts DROP primary sql commands for all tables which created by create table SQL statements in the first file. All others Sql commands class puts into separate file.


Constructor Summary
SQLSplitter()
          Constructor SQLSplitter without parameters.
 
Method Summary
 void addForeignKeyValues(java.lang.String strTableName, java.lang.String strForeignTable, java.lang.String strForeignKey, java.lang.String strPrimaryKey, java.lang.String strReference, java.lang.String strConstraint, java.lang.String strRest)
          Method addForeignKeyValues adds values to global variables - vectors.
 void addIndexValues(java.lang.String strIndex)
          Method addIndexValues adds values to global variables - vectors.
 void addPrimaryKeyValues(java.lang.String strTableName, java.lang.String strPrimaryColumn, java.lang.String strConstraintPrimary)
          Method addPrimaryKeyValues adds values to global variables - vectors.
 void addStatisticsValues(java.lang.String strIndex)
          Method addIndexValues adds values to global variables - vectors.
 void addTableName(java.lang.String strTableName)
          Method addTableName adds values to global variables - vectors.
 void createSQLFile(java.io.File fInputSQLFile, java.io.File fCreateTable, java.io.File fOther)
          Method createSQLFile prepares SQL statements for all output files and creates SQL file (fOutputSQLFile) with CREATE TABLE statements.
 java.util.Vector findSQLFiles(java.io.File fDirectory)
          Method findSQLFiles finds all SQL files (all files which contain ".sql" in their name) in a working directory and all its subdirecories and puts their URL's into Vector.
 boolean isSplitSQLPrimary()
           
static void main(java.lang.String[] argv)
          Main method controls parameters, if they are OK, starts separateSqlCommands method, but if they aren't, makes alert.
 void separateSqlCommands(java.lang.String strDirectory, java.lang.String strOutputFile)
          Method separateSqlCommands analyses all SQL files in a working directory and all its subdirecories and puts all create table SQL statements without Foreign references and Primary keys into separate file.
 void setSplitSQLPrimary(boolean b)
           
 void writeAlterTableForeignKey(java.io.File fOutputAlterTable)
          Method writeAlterTableForeignKey creates SQL file with ALTER TABLE SQL commands (foreign key references).
 void writeAlterTableIndex(java.io.File fOutputAlterTableIndex)
          Method writeAlterTableIndex creates SQL file with CREATE INDEX SQL commands.
 void writeAlterTablePrimaryKey(java.io.File fOutputAlterTable)
          Method writeAlterTablePrimaryKey createss SQL file with ALTER TABLE SQL commands (primary keys for all tables).
 void writeAlterTableStatistics(java.io.File fOutputAlterTableIndex)
          Method writeAlterTableStatistics creates SQL file with CREATE INDEX SQL commands.
 void writeDropIntegrity(java.io.File fOutputDropIntegrity)
          Method writeDropIntegrity creates SQL file with ALTER TABLE SQL commands (drop foreign key references).
 void writeDropPrimary(java.io.File fOutputDropPrimary)
          Method writeDropPrimary creates SQL file with ALTER TABLE SQL commands (drop primary keys).
 void writeDropTable(java.io.File fOutputDropTable)
          Method writeDropTable creates SQL file with DROP TABLE SQL commands.
 void writeDropTableIndex(java.io.File fOutputDropTableIndex)
          Method writeDropTableIndex creates SQL file with DROP INDEX SQL commands.
 void writeDropTableStatistics(java.io.File fOutputDropTableIndex)
          Method writeDropTableIndex creates SQL file with DROP INDEX SQL commands.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLSplitter

public SQLSplitter()
Constructor SQLSplitter without parameters.

Method Detail

main

public static void main(java.lang.String[] argv)
Main method controls parameters, if they are OK, starts separateSqlCommands method, but if they aren't, makes alert. param argv[0] The URL of the 'target' directory. param argv[1] Basic name of output file.


separateSqlCommands

public void separateSqlCommands(java.lang.String strDirectory,
                                java.lang.String strOutputFile)
Method separateSqlCommands analyses all SQL files in a working directory and all its subdirecories and puts all create table SQL statements without Foreign references and Primary keys into separate file. File will be saved in the root of the strDirectory with adding "Create" at the end of output file name - strOutputFile. SQL statements which define foreign keys of tables this method puts into file strOutputFile+"Integrity". SQL statements which define primary keys of tables this method puts into file strOutputFile+"Primary". SQL statements which define indexes of tables this method puts into file strOutputFile+"Index". SQL statements which delete tables will be written into strOutputFile+"DropTable". SQL statements which delete foreign keys will be written into strOutputFile+"DropIntegrity". SQL statements which delete primary keys will be written into strOutputFile+"DropPrimary". Other SQL statements will be written into strOutputFile+"OtherSql".

Parameters:
strDirectory - The URL of the working directory.
strOutputFile - The Url and basic name of the output SQL files(example: c:\tmp\new_SQL.sql).

findSQLFiles

public java.util.Vector findSQLFiles(java.io.File fDirectory)
Method findSQLFiles finds all SQL files (all files which contain ".sql" in their name) in a working directory and all its subdirecories and puts their URL's into Vector. If there is an error Exception "Exception" is thrown.

Parameters:
fDirectory - The URL of the working directory.
Returns:
Vector The URLs of all output SQL files in working directory and in all its subdirectories.

createSQLFile

public void createSQLFile(java.io.File fInputSQLFile,
                          java.io.File fCreateTable,
                          java.io.File fOther)
Method createSQLFile prepares SQL statements for all output files and creates SQL file (fOutputSQLFile) with CREATE TABLE statements. Method ignores all comments, foreign keys references and primary keys SQL commands. If there is an error Exception "Exception" is thrown.

Parameters:
fInputSQLFile - The URL of the input SQL file.
fCreateTable - The URL of the output SQL file where we copy CREATE TABLE sql statements.
fOther - The URL of the output SQL file where we copy all other sql statements.
Throws:
Exception.

addForeignKeyValues

public void addForeignKeyValues(java.lang.String strTableName,
                                java.lang.String strForeignTable,
                                java.lang.String strForeignKey,
                                java.lang.String strPrimaryKey,
                                java.lang.String strReference,
                                java.lang.String strConstraint,
                                java.lang.String strRest)
Method addForeignKeyValues adds values to global variables - vectors. These variables are used for creating ALTER TABLE sql commands - foreign key references.

Parameters:
strTableName - Name of table where the foreign key SQL statement was found.
strForeignTable - 'Foreign table'.
strForeignKey - Column in the table 'strTablename' which is referenced by foreign key.
strPrimaryKey - Column in the table 'strForeignTable' - primary key.
strReference - Sql commands after foreign key columns (such as ON DELETE CASCADE).
strConstraint - Name of Foreign Key constraint.
strRest - ON DELETE ...

addPrimaryKeyValues

public void addPrimaryKeyValues(java.lang.String strTableName,
                                java.lang.String strPrimaryColumn,
                                java.lang.String strConstraintPrimary)
Method addPrimaryKeyValues adds values to global variables - vectors. These variables are used for creating ALTER TABLE sql commands - primary key.

Parameters:
strTableName - Name of table where the primary key SQL statement was found.
strPrimaryColumn - Name of column which is primary key.
strConstraintPrimary - Name of Primary key constraint.

addTableName

public void addTableName(java.lang.String strTableName)
Method addTableName adds values to global variables - vectors. These variables are used for creating DROP TABLE sql commands.

Parameters:
strTableName - Name of table which it will be deleted.

addIndexValues

public void addIndexValues(java.lang.String strIndex)
Method addIndexValues adds values to global variables - vectors. These variables are used for creating CREATE INDEX sql commands.

Parameters:
strIndex - All create index SQL statements.

addStatisticsValues

public void addStatisticsValues(java.lang.String strIndex)
Method addIndexValues adds values to global variables - vectors. These variables are used for creating CREATE INDEX sql commands.

Parameters:
strIndex - All create index SQL statements.

writeAlterTableForeignKey

public void writeAlterTableForeignKey(java.io.File fOutputAlterTable)
Method writeAlterTableForeignKey creates SQL file with ALTER TABLE SQL commands (foreign key references). If there is an error Exception "Exception" is thrown.

Parameters:
fOutputAlterTable - The URL of the output SQL file.
Throws:
Exception.

writeDropIntegrity

public void writeDropIntegrity(java.io.File fOutputDropIntegrity)
Method writeDropIntegrity creates SQL file with ALTER TABLE SQL commands (drop foreign key references). If there is an error Exception "Exception" is thrown.

Parameters:
fOutputDropIntegrity - The URL of the output SQL file.
Throws:
Exception.

writeDropPrimary

public void writeDropPrimary(java.io.File fOutputDropPrimary)
Method writeDropPrimary creates SQL file with ALTER TABLE SQL commands (drop primary keys). If there is an error Exception "Exception" is thrown.

Parameters:
fOutputDropPrimary - The URL of the output SQL file.
Throws:
Exception.

writeAlterTablePrimaryKey

public void writeAlterTablePrimaryKey(java.io.File fOutputAlterTable)
Method writeAlterTablePrimaryKey createss SQL file with ALTER TABLE SQL commands (primary keys for all tables). If there is an error Exception "Exception" is thrown.

Parameters:
fOutputAlterTable - The URL of the output SQL file.
Throws:
Exception.

writeDropTable

public void writeDropTable(java.io.File fOutputDropTable)
Method writeDropTable creates SQL file with DROP TABLE SQL commands. All tables will be deleted. If there is an error Exception "Exception" is thrown.

Parameters:
fOutputDropTable - The URL of the output SQL file.
Throws:
Exception.

writeAlterTableIndex

public void writeAlterTableIndex(java.io.File fOutputAlterTableIndex)
Method writeAlterTableIndex creates SQL file with CREATE INDEX SQL commands. If there is an error Exception "Exception" is thrown.

Parameters:
fOutputAlterTableIndex - The URL of the output SQL file.
Throws:
Exception.

writeAlterTableStatistics

public void writeAlterTableStatistics(java.io.File fOutputAlterTableIndex)
Method writeAlterTableStatistics creates SQL file with CREATE INDEX SQL commands. If there is an error Exception "Exception" is thrown.

Parameters:
fOutputAlterTableIndex - The URL of the output SQL file.
Throws:
Exception.

writeDropTableIndex

public void writeDropTableIndex(java.io.File fOutputDropTableIndex)
Method writeDropTableIndex creates SQL file with DROP INDEX SQL commands. If there is an error Exception "Exception" is thrown.

Parameters:
fOutputDropTableIndex - The URL of the output SQL file.
Throws:
Exception.

writeDropTableStatistics

public void writeDropTableStatistics(java.io.File fOutputDropTableIndex)
Method writeDropTableIndex creates SQL file with DROP INDEX SQL commands. If there is an error Exception "Exception" is thrown.

Parameters:
fOutputDropTableIndex - The URL of the output SQL file.
Throws:
Exception.

isSplitSQLPrimary

public boolean isSplitSQLPrimary()
Returns:
value of splitSQLPrimary.

setSplitSQLPrimary

public void setSplitSQLPrimary(boolean b)
Parameters:
b - new value for setSplitSQLPrimary

DODS 7.2 API