|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jdesktop.dataset.util.DataSetUtility
public class DataSetUtility
DataSetUtility
holds static methods for working with the org.jdesktop.dataset
package. Currently there are methods
for importing or exporting a DataSet
schema.
Constructor Summary | |
---|---|
DataSetUtility()
|
Method Summary | |
---|---|
static DataSet |
createDataSetSchema(JDBCDataConnection conn,
java.lang.String... names)
Creates a DataSet that contains a DataTable for each table that has been specified in the given names Set. |
static void |
createDataTableSchema(JDBCDataConnection jdbcConn,
DataSet ds,
java.lang.String tableName,
java.lang.String statement)
Creates a new DataTable in the specified DataSet that maps directly to one returned from a custom SELECT query. |
static void |
createRelations(JDBCDataConnection jdbcConn,
DataSet ds)
Creates any relations that exist between the tables in the given DataSet using the database metadata that can be retrieved using the given SQL Connection. |
static void |
main(java.lang.String[] args)
|
static DataSet |
readDataSet(DataSetSchemaReader reader)
Loads a DataSet schema using a schema reader, for all tables and relations declared in the schema. |
static DataSet |
readDataSet(DataSetSchemaReader reader,
java.lang.String... tableNames)
Loads a DataSet schema using a schema reader, for the tables listed in the tableNames argument, and their
relations. |
static DataSet |
readDataSetFromJDBC(JDBCDataConnection jdbcConn)
Loads a DataSet schema from a JDBC data connection, using JDBC metadata, for all tables and relations declared in the schema. |
static DataSet |
readDataSetFromJDBC(JDBCDataConnection jdbcConn,
java.lang.String... tableNames)
Loads a DataSet schema from a JDBC data connection, using JDBC metadata, for the list of tables passed as an argument,
and their relations. |
static DataSet |
readDataSetFromXml(java.io.InputStream is,
java.lang.String... tableNames)
Loads a DataSet schema from a XML Schema, for all tables and relations declared in the schema. |
static DataSet |
readDataSetFromXml(java.io.Reader reader,
java.lang.String... tableNames)
Loads a DataSet schema from a XML Schema, for all tables and relations declared in the schema. |
static DataSet |
setProviderConnection(DataSet ds,
JDBCDataConnection conn)
Utility method that facilitates using a JDBCDataConnection
to set the connection for each DataProvider in each
DataTable contained in the DataSet . |
static void |
writeDataSet(DataSetSchemaWriter writer,
DataSet ds)
Exports a DataSet's schema using a schema writer, for all tables in the DataSet , and their relations. |
static void |
writeDataSet(DataSetSchemaWriter writer,
DataSet ds,
java.lang.String... tableNames)
Exports a DataSet's schema using a schema writer, for the list of tables passed as an argument,
and their relations. |
static void |
writeDataSetAsXml(java.io.OutputStream out,
DataSet ds)
Exports a DataSet's schema as an XML Schema, for all tables in the DataSet , and their relations. |
static void |
writeDataSetAsXml(java.io.Writer writer,
DataSet ds)
Exports a DataSet's schema as an XML Schema, for all tables in the DataSet , and their relations. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DataSetUtility()
Method Detail |
---|
public static DataSet setProviderConnection(DataSet ds, JDBCDataConnection conn)
JDBCDataConnection
to set the connection for each DataProvider
in each
DataTable
contained in the DataSet
.
ds
- The DataSet
to add providers to.conn
- The JDBCDataConnection
to set as a provider for the tables in the DataSet
.
DataSet
provided as a parameter.public static DataSet readDataSet(DataSetSchemaReader reader) throws SchemaReaderException
DataSet
schema using a schema reader, for all tables and relations declared in the schema.
It is recommended that the DataSet
be empty before calling this method. TODO: document what happens if tables
or relations already exist in the DataSet.
reader
- The schema instance from which to read the schema.
SchemaReaderException
- If an error occurs while reading the schema.public static DataSet readDataSet(DataSetSchemaReader reader, java.lang.String... tableNames) throws SchemaReaderException
DataSet
schema using a schema reader, for the tables listed in the tableNames argument, and their
relations. It is recommended that the DataSet
be empty before calling this method. TODO: document what happens if tables
or relations already exist in the DataSet.
reader
- The schema reader to use.tableNames
- Array of table names to read from the schema. Each element can be an unqualified table name, or a table.columnname
entry, where only the columns listed for the table are read from the schema. Only tables listed in this argument
are read from the schema, along with their relations.
DataSet
with its schema configured.
SchemaReaderException
- If an error occurs while reading the schema.public static DataSet readDataSetFromJDBC(JDBCDataConnection jdbcConn) throws SchemaReaderException
DataSet
schema from a JDBC data connection, using JDBC metadata, for all tables and relations declared in the schema.
The accuracy of the schema loading depends on the quality of the metadata returned by the JDBC driver; test carefully to make
sure you get the results you want. It is recommended that the DataSet
be empty before calling this method. TODO: document what happens if tables
or relations already exist in the DataSet.
jdbcConn
- The connection from which to read the JDBC metadata.
DataSet
, with its schema configured.
SchemaReaderException
- If an error occurs while reading the schema.public static DataSet readDataSetFromJDBC(JDBCDataConnection jdbcConn, java.lang.String... tableNames) throws SchemaReaderException
DataSet
schema from a JDBC data connection, using JDBC metadata, for the list of tables passed as an argument,
and their relations. The accuracy of the schema loading depends on the quality of the metadata returned by the JDBC driver;
test carefully to make sure you get the results you want. It is recommended that the DataSet
be empty before
calling this method. TODO: document what happens if tables or relations already exist in the DataSet.
jdbcConn
- The connection from which to read the schema.tableNames
- Array of table names to read from the schema. Each element can be an unqualified table name, or a table.columnname
entry, where only the columns listed for the table are read from the schema. Only tables listed in this argument
are read from the schema, along with their relations.
DataSet
with its schema configured.
SchemaReaderException
- If an error occurs while reading the schema.public static DataSet readDataSetFromXml(java.io.InputStream is, java.lang.String... tableNames) throws SchemaReaderException
DataSet
schema from a XML Schema, for all tables and relations declared in the schema.
It is recommended that the DataSet
be empty before calling this method. TODO: document what happens if tables
or relations already exist in the DataSet.
is
- An InputStream from which to read the schema; this should be open before calling this method, and closed by the
caller.tableNames
- Array of table names to read from the schema. Each element can be an unqualified table name, or a table.columnname
entry, where only the columns listed for the table are read from the schema. Only tables listed in this argument
are read from the schema, along with their relations.
DataSet
with its schema configured.
SchemaReaderException
- If an error occurs while reading the schema.public static DataSet readDataSetFromXml(java.io.Reader reader, java.lang.String... tableNames) throws SchemaReaderException
DataSet
schema from a XML Schema, for all tables and relations declared in the schema.
It is recommended that the DataSet
be empty before calling this method. TODO: document what happens if tables
or relations already exist in the DataSet.
reader
- A Reader from which to read the schema; this should be open before calling this method, and closed by the
caller.tableNames
- Array of table names to read from the schema. Each element can be an unqualified table name, or a table.columnname
entry, where only the columns listed for the table are read from the schema. Only tables listed in this argument
are read from the schema, along with their relations.
DataSet
with its schema configured.
SchemaReaderException
- If an error occurs while reading the schema.public static void writeDataSet(DataSetSchemaWriter writer, DataSet ds) throws SchemaWriterException
DataSet's
schema using a schema writer, for all tables in the DataSet
, and their relations.
writer
- The schema writer to use.ds
- The DataSet
to export a schema for.
SchemaWriterException
- If an error occurs while writing the schema.public static void writeDataSet(DataSetSchemaWriter writer, DataSet ds, java.lang.String... tableNames) throws SchemaWriterException
DataSet's
schema using a schema writer, for the list of tables passed as an argument,
and their relations.
writer
- The schema writer to use.ds
- The DataSet
to export a schema for.tableNames
- Array of table names to export the schema for. Each element can be an unqualified table name, or a table.columnname
entry, where only the columns listed for the table are written out. Only tables listed in this argument
are exported, along with their relations.
SchemaWriterException
- If an error occurs while writing the schema.public static void writeDataSetAsXml(java.io.OutputStream out, DataSet ds) throws SchemaWriterException
DataSet's
schema as an XML Schema, for all tables in the DataSet
, and their relations.
out
- The OutputStream
to write the XML to.ds
- The DataSet
to export.
SchemaWriterException
- If an error occurs while writing the schema.public static void writeDataSetAsXml(java.io.Writer writer, DataSet ds) throws SchemaWriterException
DataSet's
schema as an XML Schema, for all tables in the DataSet
, and their relations.
writer
- The Writer
to write the XML to.ds
- The DataSet
to export.
SchemaWriterException
- If an error occurs while writing the schema.public static void createDataTableSchema(JDBCDataConnection jdbcConn, DataSet ds, java.lang.String tableName, java.lang.String statement) throws SchemaCreationException
Unlike the readDataSetFromJDBC(JDBCDataConnection, String[])
method
the data relations are not set up, as typically the links would be within
the table itself (i.e. due to a JOIN statement on a foreign key)
To avoid expensive queries that will have to be executed twice (to create
and then load the table) the statement passed in here should use a
LIMIT 0
statement to avoid returning any real data, as
only the metadata is required for analysis.
It should be noted that only one catalog is currently supported and therefore the query should only select tables from one catalog. A SchemaCreationException will be thrown if more than one catalog is used.
If at any point during the creation of the new table a problem occurs an exception will be thrown to indicate this problem, and no new table will be added to the DataSet.
ds
- The DataSet
to import schema information into.jdbcConn
- a valid connection to a database that is used to generate the
queries and metadata, that must be opened prior to
calling this methodtableName
- The new table's name that is to be createdstatement
- The custom query that is to be used to generate the table
SchemaCreationException
- if a problem occurs at any time during the creation of the
schemareadDataSetFromJDBC(JDBCDataConnection, String[])
public static DataSet createDataSetSchema(JDBCDataConnection conn, java.lang.String... names) throws SchemaCreationException
table
or table.column
As the definition of each DataTable created refers only to a physical
table and is therefore backed up by a physical representation in the
database an SQLDataProvider
implementation is created for
each table that will create the required statements for updating the
table. The DataConnection
will be set to the given
jdbcConn
parameter.
This method delegates the work of actualy creating the schema to the
createDataTableSchema(JDBCDataConnection, DataSet, String, String)
method, which should be referred to for details of the work actually
performed.
NB: The catalog used to retrieve the information is the 'current' one as set by the database system, one that is automatically used when a query is sent to the database without explicity stating a catalog.
conn
- a valid connection to a database that is used to generate the
queries and metadata, that must be opened prior to
calling this methodnames
- A list of all tables to be included (plus optional explicit
column names for each table)
SchemaCreationException
- if a problem occurs at any time during the creation of the
schemacreateDataTableSchema(JDBCDataConnection, DataSet, String, String)
,
createRelations(JDBCDataConnection, DataSet)
public static void createRelations(JDBCDataConnection jdbcConn, DataSet ds) throws SchemaCreationException
NB: The catalog used to retrieve the information is the 'current' one as set by the database system, one that is automatically used when a query is sent to the database without explicity stating a catalog.
jdbcConn
- a valid connection to a database that is used to generate the
queries and metadata, that must be opened prior to
calling this methodds
- the DataSet that contains the DataTables which are to be
analysed for relations
SchemaCreationException
- if a problem occurs at any time during the creation of the
schemapublic static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |