Class ForeignDBViews

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

public class ForeignDBViews extends Object implements OptionalTool

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

  • Field Details

    • XML_TYPE

      private static final int XML_TYPE
      See Also:
    • SAFE_DROP_SQLSTATES

      private static final String[] SAFE_DROP_SQLSTATES
  • Constructor Details

    • ForeignDBViews

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

    • loadTool

      public void loadTool(String... configurationParameters) throws 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:

      • 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 interface OptionalTool
      Throws:
      SQLException
    • unloadTool

      public void unloadTool(String... configurationParameters) throws SQLException

      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 interface OptionalTool
      Throws:
      SQLException
    • registerForeignTable

      private void registerForeignTable(DatabaseMetaData foreignDBMD, String foreignSchemaName, String foreignTableName, String foreignConnectionURL, String schemaPrefix, Connection derbyConn) throws SQLException
      Throws:
      SQLException
    • getForeignTables

      private ResultSet getForeignTables(DatabaseMetaData foreignDBMD) throws SQLException

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

      Throws:
      SQLException
    • createDerbySchema

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

      Create a Derby schema if it does not already exist.

      Throws:
      SQLException
    • dropDerbySchema

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

      Drop a Derby schema.

      Throws:
      SQLException
    • getDerbySchemaName

      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.

    • dotSeparatedSchemaName

      private String dotSeparatedSchemaName(String rawName)

      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

      private String precisionToLength(int precision)

      Turns precision into a length designator.

    • precisionAndScale

      private String precisionAndScale(int precision, int scale)

      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

      private Connection getForeignConnection(String connectionURL) throws SQLException
      Throws:
      SQLException
    • getDerbyConnection

      private Connection getDerbyConnection() throws SQLException
      Throws:
      SQLException
    • delimitedID

      private String delimitedID(String text)
    • stringLiteral

      private String stringLiteral(String text)
    • executeDDL

      private void executeDDL(Connection conn, String text) throws SQLException
      Throws:
      SQLException
    • prepareStatement

      private PreparedStatement prepareStatement(Connection conn, String text) throws SQLException
      Throws:
      SQLException
    • wrap

      private SQLException wrap(String errorMessage)