com.judoscript.util
Class TableDump

java.lang.Object
  extended by com.judoscript.util.TableDump
All Implemented Interfaces:
java.io.Serializable

public class TableDump
extends java.lang.Object
implements java.io.Serializable

A dump file stores a part or whole of a database table. Dump files are gzipped. The contents are Java-serialized, which are all of basic data types:

 String      java.version
 String      java.vm.version
 String      java.class.version
 String[]    column attribute names -- titles for a TableData
 Object[][]  column attributes      -- data for a TableData
 (Object[])+ column values
 Boolean.FALSE
This class provides methods to read from a dump file.

Its static method dumpTable() dumps the content of a relational database table with a WHERE clause into a dump file.

There is also a convenience method, generateLoadScript(), * that generates JudoScript code to upload the data into a(nother) database table, based on the meta information of the columns.

See Also:
Serialized Form

Constructor Summary
TableDump(java.lang.String fileName)
          Takes a dump file name, opens it and reads in the meta information.
 
Method Summary
 void close()
           
static long dumpTable(java.sql.Connection con, java.lang.String tableName, java.lang.String fileName, java.lang.String whereClause, int limit, int promptSegment)
          Dumps whole or part of a database table to a dump file.
static long dumpTable(java.lang.String tableName, java.lang.String fileName, java.sql.ResultSet rs, int limit, int promptSegment)
           
 void generateLoadScript(java.io.PrintWriter pw, java.lang.String dumpFileName, java.lang.String tableName, boolean createTable)
          Generates a JudoScript program that optionally creates the database table and loads the data into it.
 TableData getColumnAttrs()
           
 java.lang.String getJavaClassVersion()
           
 java.lang.String getJavaVersion()
           
 java.lang.String getJavaVmVersion()
           
 java.lang.Object[] next()
           
 void reInit(java.lang.String fileName)
          Closes the current one if open, opens a new file and reads in the meta information.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TableDump

public TableDump(java.lang.String fileName)
          throws java.io.IOException,
                 java.lang.ClassNotFoundException
Takes a dump file name, opens it and reads in the meta information.

Throws:
java.io.IOException
java.lang.ClassNotFoundException
Method Detail

reInit

public void reInit(java.lang.String fileName)
            throws java.io.IOException,
                   java.lang.ClassNotFoundException
Closes the current one if open, opens a new file and reads in the meta information.

Throws:
java.io.IOException
java.lang.ClassNotFoundException

close

public void close()

getJavaVersion

public java.lang.String getJavaVersion()

getJavaVmVersion

public java.lang.String getJavaVmVersion()

getJavaClassVersion

public java.lang.String getJavaClassVersion()

getColumnAttrs

public TableData getColumnAttrs()

next

public java.lang.Object[] next()
                        throws java.io.IOException
Returns:
the next row or null if no more rows.
Throws:
java.io.IOException

generateLoadScript

public void generateLoadScript(java.io.PrintWriter pw,
                               java.lang.String dumpFileName,
                               java.lang.String tableName,
                               boolean createTable)
                        throws java.io.IOException
Generates a JudoScript program that optionally creates the database table and loads the data into it.

The generated code includes "connect.judi", which should have these connection parameters specified as url, username and password. You may modify the generated script to put in correct connection parameters, and also the CREATE TABLE statement for the column types.

Parameters:
pw - The print writer used for the generated script code.
dumpFileName - the dump file name. Can be null, where tableName.tdmp is used.
tableName - the database table name; must not be null.
createTable - flag indicating a CREATE TABLE statement need be generated.
Throws:
java.io.IOException

dumpTable

public static long dumpTable(java.sql.Connection con,
                             java.lang.String tableName,
                             java.lang.String fileName,
                             java.lang.String whereClause,
                             int limit,
                             int promptSegment)
                      throws java.sql.SQLException,
                             java.io.IOException
Dumps whole or part of a database table to a dump file.

Parameters:
con - the database connection.
tableName - the database table name. Must not be null.
fileName - the dump file name. If null, default use tableName.tdmp.
whereClause - the where clause for the internal SELECT statement. Can be null.
limit - if > 0, the maximum number of rows to dump.
promptSegment - if > 0, every so many rows written, a count is displayed to System.out as a prompt.
Throws:
java.sql.SQLException
java.io.IOException

dumpTable

public static long dumpTable(java.lang.String tableName,
                             java.lang.String fileName,
                             java.sql.ResultSet rs,
                             int limit,
                             int promptSegment)
                      throws java.sql.SQLException,
                             java.io.IOException
Throws:
java.sql.SQLException
java.io.IOException