Class ForeignDBViews
- All Implemented Interfaces:
OptionalTool
OptionalTool to create wrapper functions and views for all of the user tables in a foreign database.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String[]private static final int///////////////////////////////////////////////////////////////////// -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcreateDerbySchema(Connection derbyConn, String derbySchemaName) Create a Derby schema if it does not already exist.private StringdelimitedID(String text) /////////////////////////////////////////////////////////////////////private StringdotSeparatedSchemaName(String rawName) Turn a Derby schema name into a schema name suitable for use in a dot-separated object name.private voiddropDerbySchema(Connection derbyConn, String derbySchemaName) Drop a Derby schema.private voiddropObject(Connection conn, String schemaName, String objectName, String objectType, boolean restrict) Drop a schema object.private voidexecuteDDL(Connection conn, String text) private Connectionprivate StringgetDerbySchemaName(String schemaPrefix, String foreignSchemaName) Get the name of the local Derby schema corresponding to a foreign schema name.private ConnectiongetForeignConnection(String connectionURL) /////////////////////////////////////////////////////////////////////private ResultSetgetForeignTables(DatabaseMetaData foreignDBMD) Get a cursor through the user tables in the foreign database.voidCreates a local Derby schema for every foreign schema which contains a user table.private StringGet the type of an external database's column as a Derby type name.private StringprecisionAndScale(int precision, int scale) Build a precision and scale designator.private StringprecisionToLength(int precision) Turns precision into a length designator.private PreparedStatementprepareStatement(Connection conn, String text) private voidregisterForeignTable(DatabaseMetaData foreignDBMD, String foreignSchemaName, String foreignTableName, String foreignConnectionURL, String schemaPrefix, Connection derbyConn) ////////////////////////////////////////////////////////////////////////////////private StringstringLiteral(String text) voidunloadTool(String... configurationParameters) Removes the schemas, table functions, and views created by loadTool().private SQLException
-
Field Details
-
XML_TYPE
private static final int XML_TYPE/////////////////////////////////////////////////////////////////////- See Also:
-
SAFE_DROP_SQLSTATES
-
-
Constructor Details
-
ForeignDBViews
public ForeignDBViews()0-arg constructor required by the OptionalTool contract
-
-
Method Details
-
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.
- Specified by:
loadToolin interfaceOptionalTool- Throws:
SQLException
-
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.
- Specified by:
unloadToolin interfaceOptionalTool- Throws:
SQLException
-
registerForeignTable
private void registerForeignTable(DatabaseMetaData foreignDBMD, String foreignSchemaName, String foreignTableName, String foreignConnectionURL, String schemaPrefix, Connection derbyConn) throws SQLException ////////////////////////////////////////////////////////////////////////////////- Throws:
SQLException
-
getForeignTables
Get a cursor through the user tables in the foreign database.
- Throws:
SQLException
-
createDerbySchema
Create a Derby schema if it does not already exist.
- Throws:
SQLException
-
dropDerbySchema
Drop a Derby schema.
- Throws:
SQLException
-
getDerbySchemaName
-
dotSeparatedSchemaName
-
mapType
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.
- Throws:
SQLException
-
precisionToLength
Turns precision into a length designator.
-
precisionAndScale
Build a precision and scale designator.
-
dropObject
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.
- Throws:
SQLException
-
getForeignConnection
/////////////////////////////////////////////////////////////////////- Throws:
SQLException
-
getDerbyConnection
- Throws:
SQLException
-
delimitedID
-
stringLiteral
-
executeDDL
- Throws:
SQLException
-
prepareStatement
- Throws:
SQLException
-
wrap
-