Top Description Fields Constructors Methods
org.apache.derby.impl.tools.optional

public Class ForeignDBViews

extends Object
implements OptionalTool
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.sql.dictionary.OptionalTool
Imports
java.sql.Connection, .DatabaseMetaData, .DriverManager, .PreparedStatement, .ResultSet, .SQLException, .Types, java.util.HashSet, org.apache.derby.iapi.sql.dictionary.OptionalTool, org.apache.derby.iapi.tools.i18n.LocalizedResource, org.apache.derby.iapi.util.IdUtil, .StringUtil, org.apache.derby.vti.ForeignTableVTI

OptionalTool to create wrapper functions and views for all of the user tables in a foreign database.

Field Summary

Modifier and TypeField and Description
private static final String[]
private static final int

Constructor Summary

AccessConstructor and Description
public
ForeignDBViews()

0-arg constructor required by the OptionalTool contract

Method Summary

Modifier and TypeMethod and Description
private void
createDerbySchema(Connection derbyConn, String derbySchemaName)

Create a Derby schema if it does not already exist.

private String
private String
dotSeparatedSchemaName(String rawName)

Turn a Derby schema name into a schema name suitable for use in a dot-separated object name.

private void
dropDerbySchema(Connection derbyConn, String derbySchemaName)

Drop a Derby schema.

private void
dropObject(Connection conn, String schemaName, String objectName, String objectType, boolean restrict)

Drop a schema object.

private void
private Connection
private String
getDerbySchemaName(String schemaPrefix, String foreignSchemaName)

Get the name of the local Derby schema corresponding to a foreign schema name.

private Connection
private ResultSet
getForeignTables(DatabaseMetaData foreignDBMD)

Get a cursor through the user tables in the foreign database.

public void
loadTool(String... configurationParameters)

Implements org.apache.derby.iapi.sql.dictionary.OptionalTool.loadTool.

Creates a local Derby schema for every foreign schema which contains a user table.

private String
mapType(int jdbcType, int precision, int scale, String foreignTypeName)

Get the type of an external database's column as a Derby type name.

private String
precisionAndScale(int precision, int scale)

Build a precision and scale designator.

private String
precisionToLength(int precision)

Turns precision into a length designator.

private PreparedStatement
private void
registerForeignTable(DatabaseMetaData foreignDBMD, String foreignSchemaName, String foreignTableName, String foreignConnectionURL, String schemaPrefix, Connection derbyConn)

private String
public void
unloadTool(String... configurationParameters)

Implements org.apache.derby.iapi.sql.dictionary.OptionalTool.unloadTool.

Removes the schemas, table functions, and views created by loadTool().

private SQLException
wrap(String errorMessage)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

SAFE_DROP_SQLSTATESback to summary
private static final String[] SAFE_DROP_SQLSTATES
XML_TYPEback to summary
private static final int XML_TYPE

Constructor Detail

ForeignDBViewsback to summary
public ForeignDBViews()

0-arg constructor required by the OptionalTool contract

Method Detail

createDerbySchemaback to summary
private void createDerbySchema(Connection derbyConn, String derbySchemaName) throws SQLException

Create a Derby schema if it does not already exist.

delimitedIDback to summary
private String delimitedID(String text)
dotSeparatedSchemaNameback to summary
private String dotSeparatedSchemaName(String rawName)

Turn a Derby schema name into a schema name suitable for use in a dot-separated object name.

dropDerbySchemaback to summary
private void dropDerbySchema(Connection derbyConn, String derbySchemaName) throws SQLException

Drop a Derby schema.

dropObjectback to summary
private void dropObject(Connection conn, String schemaName, String objectName, String objectType, boolean restrict) throws SQLException

Drop a schema object. If the object does not exist, silently swallow the error.

executeDDLback to summary
private void executeDDL(Connection conn, String text) throws SQLException
getDerbyConnectionback to summary
private Connection getDerbyConnection() throws SQLException
getDerbySchemaNameback to summary
private String getDerbySchemaName(String schemaPrefix, String foreignSchemaName)

Get the name of the local Derby schema corresponding to a foreign schema name. Returns null if the default (current) schema is to be used.

getForeignConnectionback to summary
private Connection getForeignConnection(String connectionURL) throws SQLException
getForeignTablesback to summary
private ResultSet getForeignTables(DatabaseMetaData foreignDBMD) throws SQLException

Get a cursor through the user tables in the foreign database.

loadToolback to summary
public void loadTool(String... configurationParameters) throws SQLException

Implements org.apache.derby.iapi.sql.dictionary.OptionalTool.loadTool.

Creates a local Derby schema for every foreign schema which contains a user table. Then creates a table function and convenience view for every user table found in the foreign database. The parameters to this method are:

  • foreignConnectionURL (required) - URL to connect to the foreign database
  • schemaPrefix (optional) - If not specified, then the local Derby schema which is created has the same name as the foreign schema. Otherwise, this prefix is prepended to the names of the local Derby schemas which are created.
mapTypeback to summary
private String mapType(int jdbcType, int precision, int scale, String foreignTypeName) throws SQLException

Get the type of an external database's column as a Derby type name.

precisionAndScaleback to summary
private String precisionAndScale(int precision, int scale)

Build a precision and scale designator.

precisionToLengthback to summary
private String precisionToLength(int precision)

Turns precision into a length designator.

prepareStatementback to summary
private PreparedStatement prepareStatement(Connection conn, String text) throws SQLException
registerForeignTableback to summary
private void registerForeignTable(DatabaseMetaData foreignDBMD, String foreignSchemaName, String foreignTableName, String foreignConnectionURL, String schemaPrefix, Connection derbyConn) throws SQLException
stringLiteralback to summary
private String stringLiteral(String text)
unloadToolback to summary
public void unloadTool(String... configurationParameters) throws SQLException

Implements org.apache.derby.iapi.sql.dictionary.OptionalTool.unloadTool.

Removes the schemas, table functions, and views created by loadTool().

  • connectionURL (required) - URL to connect to the foreign database
  • schemaPrefix (optional) - See loadTool() for more information on this argument.
wrapback to summary
private SQLException wrap(String errorMessage)