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
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
createDerbySchema
(Connection derbyConn, String derbySchemaName) Create a Derby schema if it does not already exist.private String
delimitedID
(String text) 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
executeDDL
(Connection conn, String text) 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
getForeignConnection
(String connectionURL) private ResultSet
getForeignTables
(DatabaseMetaData foreignDBMD) Get a cursor through the user tables in the foreign database.void
Creates a local Derby schema for every foreign schema which contains a user table.private String
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
prepareStatement
(Connection conn, String text) private void
registerForeignTable
(DatabaseMetaData foreignDBMD, String foreignSchemaName, String foreignTableName, String foreignConnectionURL, String schemaPrefix, Connection derbyConn) private String
stringLiteral
(String text) void
unloadTool
(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:
loadTool
in 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:
unloadTool
in 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
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
Turn a Derby schema name into a schema name suitable for use in a dot-separated object name.
-
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
-