org.brains2b.sql.meta
Class SQLMetaData

java.lang.Object
  extended by org.brains2b.sql.meta.SQLMetaData

public class SQLMetaData
extends java.lang.Object

Main DatabaseMetaData class for describing database, table and column properties on the basis of a supplied connection

Since:
22-06-2007
Version:
0.22.4
Author:
Dennis Groenendijk

Constructor Summary
SQLMetaData()
          Default Constructor
SQLMetaData(java.sql.Connection connection)
          Constructor for SqlMetadata
 
Method Summary
 java.util.List getCatalogs()
          get the catalog names which can be retrieved for this database
 java.util.List getColumns(java.lang.String catalog, java.lang.String schemaPattern, java.lang.String tablePattern, java.lang.String columnPattern)
          get a List of SqlColumModels for each colum that can be found for the parameters supplied.
 java.sql.Connection getConnection()
          get the connection to the Database
 java.util.List getConstraints(java.lang.String catalog, java.lang.String schema, java.lang.String table, java.lang.String type)
          get a List of Constraints (Primary | Foreign ) defined in this database for the given catalog,schema and pattern.
 java.util.List getIndices(java.lang.String catalog, java.lang.String schemaPattern, java.lang.String tablePattern, boolean onlyUnique)
          get a list of Indices for the given parameters.
 java.sql.DatabaseMetaData getMetaData()
          get the DatabaseMetaData object associated with the connection used
 java.util.List getParameters(java.lang.String catalog, java.lang.String schema, java.lang.String procName)
          get the parameters belonging to the procedure
 java.util.List getProcedures(java.lang.String catalog, java.lang.String schema, java.lang.String pattern)
          get a List of Procedures defined in this database without possible parameters for the given catalog,schema and pattern.
 java.util.List getProcedures(java.lang.String catalog, java.lang.String schema, java.lang.String pattern, boolean includeParms)
          get a List of Procedures defined in this database for the given catalog,schema and pattern.
 java.util.List getSchemas()
          get the schema names which can be retrieved for this database
 java.util.List getTables(java.lang.String catalog, java.lang.String schemaPattern, java.lang.String tablePattern)
          get a List of TableModel objects, without their columns dependant on the parameters supplied.
 java.util.List getTables(java.lang.String catalog, java.lang.String schemaPattern, java.lang.String tablePattern, java.lang.String type)
          get a List of TableModel objects for a specific type, without their columns dependant on the parameters supplied.
 java.util.List getTablesWithColumns(java.lang.String catalog, java.lang.String schemaPattern, java.lang.String tablePattern)
          get a List of TableModel objects, including their columns dependant on the parameters supplied.
 java.util.List getTableTypes()
          get the table types supported by the database
 TypesInfo getTypeInfo()
          get a Types2Java object for transforming types between the database and Java
 void setColumns(TableModel table)
          set the columns for this table
 void setConnection(java.sql.Connection con)
          set the connection to the Database to use for the MetaData
 void setIndices(TableModel table, boolean onlyUnique)
          set the Indexes for this table
 void setParameters(ProcedureModel proc)
          set the parameters for this procedure
 void setPrimaryKey(TableModel tm)
          set the primary key belonging to a table
 void setPrimaryKey(TableModel tm, boolean forceRowid)
          set the primary key belonging to a table
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLMetaData

public SQLMetaData()
Default Constructor

Use setConnection(Connection) prior to using any of the methods


SQLMetaData

public SQLMetaData(java.sql.Connection connection)
Constructor for SqlMetadata

Parameters:
connection - Connection, the database connection used
Method Detail

getMetaData

public java.sql.DatabaseMetaData getMetaData()
                                      throws java.sql.SQLException
get the DatabaseMetaData object associated with the connection used

Returns:
DatabaseMetaData
Throws:
SQLException, - from the connection
java.sql.SQLException

getCatalogs

public java.util.List getCatalogs()
                           throws java.sql.SQLException
get the catalog names which can be retrieved for this database

Returns:
List of Strings, always returns a List even when empty
Throws:
java.sql.SQLException

getSchemas

public java.util.List getSchemas()
                          throws java.sql.SQLException
get the schema names which can be retrieved for this database

Returns:
List of Strings, always returns a List even when empty
Throws:
java.sql.SQLException

getTableTypes

public java.util.List getTableTypes()
                             throws java.sql.SQLException
get the table types supported by the database

Note:Types does not return synonym

Returns:
List of Strings, always returns a List even when empty
Throws:
java.sql.SQLException

getTablesWithColumns

public java.util.List getTablesWithColumns(java.lang.String catalog,
                                           java.lang.String schemaPattern,
                                           java.lang.String tablePattern)
                                    throws java.sql.SQLException
get a List of TableModel objects, including their columns dependant on the parameters supplied.

Setting any of the parameters to null will ignore them. Setting either catalog or schemaPattern is usually necessary.

Parameters:
catalog - String, a possible catalog name, null if not used
schemaPattern - String, a possible schemaPattern, null if not used
tablePattern, - a possible tablePattern, null if not used.
Returns:
List of TableModels, always returns a List even when empty
Throws:
java.sql.SQLException
See Also:
#getTables, #getColumns, for information on catalogs and patterns

getTables

public java.util.List getTables(java.lang.String catalog,
                                java.lang.String schemaPattern,
                                java.lang.String tablePattern)
                         throws java.sql.SQLException
get a List of TableModel objects, without their columns dependant on the parameters supplied.

Setting any of the parameters to null will ignore them. Setting either catalog or schemaPattern is usually necessary.

Parameters:
catalog - String, a possible catalog name, null if not used
schemaPattern - String, a possible schemaPattern, null if not used
tablePattern, - a possible tablePattern, null if not used.
Returns:
List, a List of SqlTableModels, always returns a List even when empty
Throws:
java.sql.SQLException
See Also:
for information on catalogs and patterns

getTables

public java.util.List getTables(java.lang.String catalog,
                                java.lang.String schemaPattern,
                                java.lang.String tablePattern,
                                java.lang.String type)
                         throws java.sql.SQLException
get a List of TableModel objects for a specific type, without their columns dependant on the parameters supplied.

Setting any of the parameters to null will ignore them. Setting either catalog or schemaPattern is usually necessary.

Parameters:
catalog - String, a possible catalog name, null if not used
schemaPattern - String, a possible schemaPattern, null if not used
tablePattern, - a possible tablePattern, null if not used.
Returns:
List, a List of SqlTableModels, always returns a List even when empty
Throws:
java.sql.SQLException
See Also:
for information on catalogs and patterns, #getTableTypes()}

setColumns

public void setColumns(TableModel table)
                throws java.sql.SQLException
set the columns for this table

Parameters:
proc - ProcedureModel, the model to set the parameters to
Throws:
java.sql.SQLException
See Also:
#getColumns(String, String, String, String)}

getColumns

public java.util.List getColumns(java.lang.String catalog,
                                 java.lang.String schemaPattern,
                                 java.lang.String tablePattern,
                                 java.lang.String columnPattern)
                          throws java.sql.SQLException
get a List of SqlColumModels for each colum that can be found for the parameters supplied.

Setting any of the parameters to null will ignore them. Setting either catalog or schemaPattern is usually necessary.

Parameters:
catalog - String, a possible catalog name, null if not used
schemaPattern - String, a possible schemaPattern, null if not used
tablePattern, - a possible tablePattern, null if not used.
columnPattern, - a possible columnPattern, null if not used.
Returns:
Vector, a List of SqlTableModels, always returns a Vector even when empty
Throws:
java.sql.SQLException
See Also:
for information on catalogs and patterns

setPrimaryKey

public void setPrimaryKey(TableModel tm)
                   throws java.sql.SQLException
set the primary key belonging to a table

The method returns the table model enriched with a possible primary key. If no primary key can be found a primary key is constructed from possiblem unique indexes. If no unique indexes where defined a pseudo column called ROWID is created.

Parameters:
tm - TableModel, the table to find the primary key for
Throws:
java.sql.SQLException

setPrimaryKey

public void setPrimaryKey(TableModel tm,
                          boolean forceRowid)
                   throws java.sql.SQLException
set the primary key belonging to a table

The method enriches the TableModel with a possible primary key. If no primary key can be found a primary key is constructed from possiblem unique indexes. If no unique indexes where defined a pseudo column called ROWID is created.

Parameters:
tm - TableModel, the table to find the primary key for
Throws:
java.sql.SQLException

setIndices

public void setIndices(TableModel table,
                       boolean onlyUnique)
                throws java.sql.SQLException
set the Indexes for this table

Parameters:
proc - ProcedureModel, the model to set the parameters to
Throws:
java.sql.SQLException
See Also:
#getColumns(String, String, String, String)}

getIndices

public java.util.List getIndices(java.lang.String catalog,
                                 java.lang.String schemaPattern,
                                 java.lang.String tablePattern,
                                 boolean onlyUnique)
                          throws java.sql.SQLException
get a list of Indices for the given parameters.

Parameters:
catalog - String, a possible catalog name, null if not used
schemaPattern - String, a possible schemaPattern, null if not used
tablePattern, - a possible tablePattern matching the name of the TableModel
onlyUnique, - true if only unique indexes should be retrieved
Returns:
List of IndexModels, returns a List even if no indices where found
Throws:
java.sql.SQLException

getProcedures

public java.util.List getProcedures(java.lang.String catalog,
                                    java.lang.String schema,
                                    java.lang.String pattern)
                             throws java.sql.SQLException
get a List of Procedures defined in this database without possible parameters for the given catalog,schema and pattern.

Setting any of the parameters to null will ignore them. Setting either catalog or schemaPattern is usually necessary.

Parameters:
catalog - String, a possible catalog name, null if not used
schema - String, a possible schemaPattern, null if not used
pattern - String, a possible tablePattern, null if not used.
Returns:
List of ProcedureModel, returns a List even if no procedures where found
Throws:
java.sql.SQLException

getProcedures

public java.util.List getProcedures(java.lang.String catalog,
                                    java.lang.String schema,
                                    java.lang.String pattern,
                                    boolean includeParms)
                             throws java.sql.SQLException
get a List of Procedures defined in this database for the given catalog,schema and pattern.

Setting any of the parameters to null will ignore them. Setting either catalog or schemaPattern is usually necessary.

Parameters:
catalog - String, a possible catalog name, null if not used
schema - String, a possible schemaPattern, null if not used
pattern - String, a possible tablePattern, null if not used.
includeParms - boolean, true if you want the parameters for this procedure loaded as well, false otherwise.

Note: Setting this to true might slow down the result

Returns:
List of ProcedureModel, returns a List even if no procedures where found
Throws:
java.sql.SQLException

setParameters

public void setParameters(ProcedureModel proc)
                   throws java.sql.SQLException
set the parameters for this procedure

Parameters:
proc - ProcedureModel, the model to set the parameters to
Throws:
java.sql.SQLException
See Also:
#getParameters(String, String, String)}

getParameters

public java.util.List getParameters(java.lang.String catalog,
                                    java.lang.String schema,
                                    java.lang.String procName)
                             throws java.sql.SQLException
get the parameters belonging to the procedure

Parameters:
catalog - String, catalog or null
schema - String, schema or null
procName - String, the name of the procedure, leaving this blank will return the parameters of all procedures
Returns:
List of ParameterModel
Throws:
java.sql.SQLException

getConnection

public java.sql.Connection getConnection()
get the connection to the Database

Returns:
Connection, the connection to the Database

setConnection

public void setConnection(java.sql.Connection con)
set the connection to the Database to use for the MetaData

Parameters:
con - Connection, the connection to the Database

getConstraints

public java.util.List getConstraints(java.lang.String catalog,
                                     java.lang.String schema,
                                     java.lang.String table,
                                     java.lang.String type)
                              throws java.sql.SQLException
get a List of Constraints (Primary | Foreign ) defined in this database for the given catalog,schema and pattern.

Setting any of the parameters to null will ignore them. Setting either catalog or schemaPattern is usually necessary.

Parameters:
catalog - String, a possible catalog name, null if not used
schema - String, a possible schemaPattern, null if not used
pattern - String, a possible tablePattern, null if not used.
type - String, the type of constraint to get ( ConstraintModel.PRIMARY_KEY | Constraint.FOREIGN_KEY ) or null for both types
Returns:
List of ProcedureModel, returns a List even if no procedures where found
Throws:
java.sql.SQLException

getTypeInfo

public TypesInfo getTypeInfo()
get a Types2Java object for transforming types between the database and Java

Returns:
Types2Java, null if the Connection or DatabaseMetaData cannot be found
Since:
1.00