|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sourceforge.jdbdump.dump.Table
public class Table
Represents a table in a database. Objects of this class should be created either by a
DatabaseConnector during the execution of dump() method, or by a DumpFileManager
while recreating a Dump from a saved backup file.
A table must have its name assigned, and should also have a number of columns (handled by
Column class). Optionally a table can also have one or more Triggers.
Table is different from other classes in this package in that it is the only one which
has the ability to download more information from the database after the Dump structure
is created. This is done to let a DumpFileManager download parts of data and immediately
store them in a file (or, in the same way, load data from a file and insert them into
database). Otherwise the entire contents of a database (often many megabytes or even
gigabytes) would have to be kept in memory.
Database data is loaded using methods initializeData() and getDataLine(). The former is
executed once per table to prepare the data stream, and the latter is called for each
record of data. Data can be saved to a dump file just after they are downloaded, so
only one record occupies the memory at the same time.
Example code:
DatabaseConnectorFactory factory = DatabaseConnectorFactory.getInstance(); if (connectorTypes.length > 0) { DatabaseConnector connector = factory.createConnector( "net.sourceforge.jdbdump.connect.connectors.MysqlConnector"); connector.connect("jdbc:mysql://localhost/base", "admin", "qwerty"); Dump dump = connector.dump(); File dumpFile = new File("dump.bin"); // ...write the structure to a file... for (Table t : dump.getTables()) { t.initializeData(); while (true) { String record[] = t.getDataLine(); if (record == null) break; // ...write one line with an insert command... } } connector.disconnect(); } else { // error - no connectors }
Constructor Summary | |
---|---|
Table(java.lang.String name,
Dump dump)
Creates a new table with specified name. |
Method Summary | |
---|---|
void |
addConstraint(Constraint constraint)
Adds a new constraint to this table. |
java.util.Vector<Column> |
getColumns()
Returns number of columns in the table. |
java.util.Vector<Constraint> |
getConstraints()
Returns a list of this table's constraints (including primary and foreign keys). |
java.lang.String[] |
getDataLine()
Downloads one record of data from this table in database or from a file (depending on the value of readFromDatabase attribute). |
java.lang.String[] |
getDataLineFromDatabase()
Downloads one record of data from this table in database. |
java.lang.String[] |
getDataLineFromFile()
Reads one record of data from a backup file. |
java.lang.String |
getName()
Returns table's name. |
void |
initializeData()
Prepares table's data for downloading using getDataLine(). |
void |
setDump(Dump dump)
Sets a reference to a Dump object which contains this Table. |
void |
setName(java.lang.String name)
Sets table's name. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Table(java.lang.String name, Dump dump)
name
- table's nameconnection
- database connection which will be used to dump table's dataMethod Detail |
---|
public void setDump(Dump dump)
dump
- a database dumppublic java.lang.String getName()
public void setName(java.lang.String name)
public java.util.Vector<Constraint> getConstraints()
public void addConstraint(Constraint constraint)
constraint
- a constraint to be added to the listpublic void initializeData() throws java.sql.SQLException
java.sql.SQLException
- if data download can't be initialized because of a connection
error or an error in the databasepublic java.lang.String[] getDataLine() throws java.lang.Exception
java.lang.Exception
- if data record can't be downloaded because of a connection error
or an error in the database, or because of an IO error during the reading from
a backup filepublic java.lang.String[] getDataLineFromDatabase() throws java.sql.SQLException
java.sql.SQLException
- if data record can't be downloaded because of a connection error
or an error in the databasepublic java.lang.String[] getDataLineFromFile() throws java.io.IOException, java.lang.ClassNotFoundException
java.io.IOException
- if data can't be read from the file
java.lang.ClassNotFoundException
- if the read object doesn't match the required classpublic java.util.Vector<Column> getColumns()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |