org.apache.derby.impl.tools.optional
Class ForeignDBViews

java.lang.Object
  extended by org.apache.derby.impl.tools.optional.ForeignDBViews
All Implemented Interfaces:
OptionalTool

public class ForeignDBViews
extends java.lang.Object
implements OptionalTool

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


Field Summary
private static java.lang.String[] SAFE_DROP_SQLSTATES
           
private static int XML_TYPE
           
 
Constructor Summary
ForeignDBViews()
          0-arg constructor required by the OptionalTool contract
 
Method Summary
private  void createDerbySchema(java.sql.Connection derbyConn, java.lang.String derbySchemaName)
           Create a Derby schema if it does not already exist.
private  java.lang.String delimitedID(java.lang.String text)
           
private  java.lang.String dotSeparatedSchemaName(java.lang.String rawName)
           Turn a Derby schema name into a schema name suitable for use in a dot-separated object name.
private  void dropDerbySchema(java.sql.Connection derbyConn, java.lang.String derbySchemaName)
           Drop a Derby schema.
private  void dropObject(java.sql.Connection conn, java.lang.String schemaName, java.lang.String objectName, java.lang.String objectType, boolean restrict)
           Drop a schema object.
private  void executeDDL(java.sql.Connection conn, java.lang.String text)
           
private  java.sql.Connection getDerbyConnection()
           
private  java.lang.String getDerbySchemaName(java.lang.String schemaPrefix, java.lang.String foreignSchemaName)
           Get the name of the local Derby schema corresponding to a foreign schema name.
private  java.sql.Connection getForeignConnection(java.lang.String connectionURL)
           
private  java.sql.ResultSet getForeignTables(java.sql.DatabaseMetaData foreignDBMD)
           Get a cursor through the user tables in the foreign database.
 void loadTool(java.lang.String... configurationParameters)
           Creates a local Derby schema for every foreign schema which contains a user table.
private  java.lang.String mapType(int jdbcType, int precision, int scale, java.lang.String foreignTypeName)
           Get the type of an external database's column as a Derby type name.
private  java.lang.String precisionAndScale(int precision, int scale)
           Build a precision and scale designator.
private  java.lang.String precisionToLength(int precision)
           Turns precision into a length designator.
private  java.sql.PreparedStatement prepareStatement(java.sql.Connection conn, java.lang.String text)
           
private  void registerForeignTable(java.sql.DatabaseMetaData foreignDBMD, java.lang.String foreignSchemaName, java.lang.String foreignTableName, java.lang.String foreignConnectionURL, java.lang.String schemaPrefix, java.sql.Connection derbyConn)
           
private  java.lang.String stringLiteral(java.lang.String text)
           
 void unloadTool(java.lang.String... configurationParameters)
           Removes the schemas, table functions, and views created by loadTool().
private  java.sql.SQLException wrap(java.lang.String errorMessage)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XML_TYPE

private static final int XML_TYPE
See Also:
Constant Field Values

SAFE_DROP_SQLSTATES

private static final java.lang.String[] SAFE_DROP_SQLSTATES
Constructor Detail

ForeignDBViews

public ForeignDBViews()
0-arg constructor required by the OptionalTool contract

Method Detail

loadTool

public void loadTool(java.lang.String... configurationParameters)
              throws java.sql.SQLException

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:

Specified by:
loadTool in interface OptionalTool
Throws:
java.sql.SQLException

unloadTool

public void unloadTool(java.lang.String... configurationParameters)
                throws java.sql.SQLException

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

Specified by:
unloadTool in interface OptionalTool
Throws:
java.sql.SQLException

registerForeignTable

private void registerForeignTable(java.sql.DatabaseMetaData foreignDBMD,
                                  java.lang.String foreignSchemaName,
                                  java.lang.String foreignTableName,
                                  java.lang.String foreignConnectionURL,
                                  java.lang.String schemaPrefix,
                                  java.sql.Connection derbyConn)
                           throws java.sql.SQLException
Throws:
java.sql.SQLException

getForeignTables

private java.sql.ResultSet getForeignTables(java.sql.DatabaseMetaData foreignDBMD)
                                     throws java.sql.SQLException

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

Throws:
java.sql.SQLException

createDerbySchema

private void createDerbySchema(java.sql.Connection derbyConn,
                               java.lang.String derbySchemaName)
                        throws java.sql.SQLException

Create a Derby schema if it does not already exist.

Throws:
java.sql.SQLException

dropDerbySchema

private void dropDerbySchema(java.sql.Connection derbyConn,
                             java.lang.String derbySchemaName)
                      throws java.sql.SQLException

Drop a Derby schema.

Throws:
java.sql.SQLException

getDerbySchemaName

private java.lang.String getDerbySchemaName(java.lang.String schemaPrefix,
                                            java.lang.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.


dotSeparatedSchemaName

private java.lang.String dotSeparatedSchemaName(java.lang.String rawName)

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


mapType

private java.lang.String mapType(int jdbcType,
                                 int precision,
                                 int scale,
                                 java.lang.String foreignTypeName)
                          throws java.sql.SQLException

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

Throws:
java.sql.SQLException

precisionToLength

private java.lang.String precisionToLength(int precision)

Turns precision into a length designator.


precisionAndScale

private java.lang.String precisionAndScale(int precision,
                                           int scale)

Build a precision and scale designator.


dropObject

private void dropObject(java.sql.Connection conn,
                        java.lang.String schemaName,
                        java.lang.String objectName,
                        java.lang.String objectType,
                        boolean restrict)
                 throws java.sql.SQLException

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

Throws:
java.sql.SQLException

getForeignConnection

private java.sql.Connection getForeignConnection(java.lang.String connectionURL)
                                          throws java.sql.SQLException
Throws:
java.sql.SQLException

getDerbyConnection

private java.sql.Connection getDerbyConnection()
                                        throws java.sql.SQLException
Throws:
java.sql.SQLException

delimitedID

private java.lang.String delimitedID(java.lang.String text)

stringLiteral

private java.lang.String stringLiteral(java.lang.String text)

executeDDL

private void executeDDL(java.sql.Connection conn,
                        java.lang.String text)
                 throws java.sql.SQLException
Throws:
java.sql.SQLException

prepareStatement

private java.sql.PreparedStatement prepareStatement(java.sql.Connection conn,
                                                    java.lang.String text)
                                             throws java.sql.SQLException
Throws:
java.sql.SQLException

wrap

private java.sql.SQLException wrap(java.lang.String errorMessage)

Built on Wed 2013-06-12 15:21:56+0000, from revision ???

Apache Derby V10.10 Internals - Copyright © 2004,2013 The Apache Software Foundation. All Rights Reserved.