org.ejen.ext.db
Class BasicMetaDataConnection

java.lang.Object
  |
  +--org.ejen.ext.db.MetaDataNodeBuilder
        |
        +--org.ejen.ext.db.TableMetaDataNodeBuilder
              |
              +--org.ejen.ext.db.BasicMetaDataConnection

public class BasicMetaDataConnection
extends TableMetaDataNodeBuilder

JDBC connections utility (static methods).

Usage (XSL stylesheet)

  <?xml version="1.0" encoding="iso-8859-1"?>

  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  ...
                  xmlns:mta="org.ejen.ext.db.BasicMetaDataConnection"
                  extension-element-prefixes="mta ..."
                  exclude-result-prefixes="mta ..."
                  version="1.0">

    <xsl:output method="xml" encoding="iso-8859-1"/>

    <xsl:template match="ejen">

      <mta:open name="connection1" select="connections/connection[1]"/>
      <xsl:if test="not(mta:open('connection3',connections/connection[3]))">
        ...
      </xsl:if>
      <mta:setActive name="connection1"/>
      <mta:close name="connection1"/>
      <xsl:if test="not(mta:close('connection3'))">
        ...
      </xsl:if>
      <mta:closeAll/>
      <xsl:if test="not(mta:closeAll())">
        ...
      </xsl:if>

      <xsl:copy-of select="mta:getTableMetaData('ADDRESS')"/>
      <xsl:copy-of select="mta:getTableMetaData('CAT','SCH','ADDRESS')"/>

      <xsl:variable name="errors" select="mta:getErrors()"/>
      <xsl:copy-of select="mta:getDatabaseInformation()/@*"/>
      <xsl:copy-of select="mta:getResultSetMetaData('ADDRESS')"/>
      <xsl:copy-of select="mta:getResultSetMetaData('ADDRESS','COL1,COL2')"/>
      <xsl:copy-of select="mta:getPrimaryKeys('ADDRESS')"/>
      <xsl:copy-of select="mta:getPrimaryKeys('CAT','SCH','ADDRESS')"/>
      <xsl:copy-of select="mta:getImportedKeys('ADDRESS')"/>
      <xsl:copy-of select="mta:getImportedKeys('CAT','SCH','ADDRESS')"/>
      <xsl:copy-of select="mta:getExportedKeys('ADDRESS')"/>
      <xsl:copy-of select="mta:getExportedKeys('CAT','SCH','ADDRESS')"/>
      <xsl:copy-of select="mta:getIndexInfo('ADDRESS')"/>
      <xsl:copy-of select="mta:getIndexInfo('CAT','SCH','ADDRESS')"/>

    </xsl:template>

  </xsl:stylesheet>
 

Version:
1.0
Author:
F. Wolff

Field Summary
protected static Hashtable _conns
          Connections table
static String S_CI_CONNECTION_NODE_NAME
           
static String S_CI_DRIVER
           
static String S_CI_URL
           
 
Fields inherited from class org.ejen.ext.db.TableMetaDataNodeBuilder
S_TABLE_METADATA_NODE_NAME
 
Fields inherited from class org.ejen.ext.db.MetaDataNodeBuilder
_activeConn, _errors, S_DI_DATABASE_PRODUCT_NAME, S_DI_DATABASE_PRODUCT_VERSION, S_DI_NODE_NAME, S_EIK_DEFERRABILITY, S_EIK_DELETE_RULE, S_EIK_EK_NODE_NAME, S_EIK_FK_NAME, S_EIK_FKCOLUMN_NAME, S_EIK_FKTABLE_CAT, S_EIK_FKTABLE_NAME, S_EIK_FKTABLE_SCHEM, S_EIK_IK_NODE_NAME, S_EIK_KEY_SEQ, S_EIK_PK_NAME, S_EIK_PKCOLUMN_NAME, S_EIK_PKTABLE_CAT, S_EIK_PKTABLE_NAME, S_EIK_PKTABLE_SCHEM, S_EIK_UPDATE_RULE, S_EXCEPTION_CLASS_NAME, S_EXCEPTION_CODE, S_EXCEPTION_NODE_NAME, S_II_ASC_OR_DESC, S_II_CARDINALITY, S_II_COLUMN_NAME, S_II_FILTER_CONDITION, S_II_INDEX_NAME, S_II_INDEX_QUALIFIER, S_II_NODE_NAME, S_II_NON_UNIQUE, S_II_ORDINAL_POSITION, S_II_PAGES, S_II_TABLE_CAT, S_II_TABLE_NAME, S_II_TABLE_SCHEM, S_II_TYPE, S_NOT_SUPPORTED, S_NULL, S_PK_COLUMN_NAME, S_PK_KEY_SEQ, S_PK_NODE_NAME, S_PK_PK_NAME, S_PK_TABLE_CAT, S_PK_TABLE_NAME, S_PK_TABLE_SCHEM, S_RS_AUTO_INCREMENT, S_RS_CASE_SENSITIVE, S_RS_CATALOG_NAME, S_RS_COLUMN_CLASS_NAME, S_RS_COLUMN_DISPLAY_SIZE, S_RS_COLUMN_LABEL, S_RS_COLUMN_NAME, S_RS_COLUMN_NO_NULLS, S_RS_COLUMN_NODE_NAME, S_RS_COLUMN_NULLABLE, S_RS_COLUMN_NULLABLE_UNKNOWN, S_RS_COLUMN_TYPE, S_RS_COLUMN_TYPE_NAME, S_RS_CURRENCY, S_RS_DEFINITELY_WRITABLE, S_RS_NULLABLE, S_RS_PRECISION, S_RS_READ_ONLY, S_RS_SCALE, S_RS_SCHEMA_NAME, S_RS_SEARCHABLE, S_RS_SIGNED, S_RS_TABLE_NAME, S_RS_WRITABLE
 
Constructor Summary
protected BasicMetaDataConnection()
          Prevents instanciation.
 
Method Summary
static boolean close(ExpressionContext context, String name)
          Closes a JDBC connection and removes it from the connections table.
static void close(XSLProcessorContext context, ElemExtensionCall elem)
          Closes a JDBC connection and removes it from the connections table.
static boolean closeAll(ExpressionContext context)
          Closes all JDBC connections.
static void closeAll(XSLProcessorContext context, ElemExtensionCall elem)
          Closes all JDBC connections.
static boolean open(ExpressionContext context, String name, NodeIterator connectionNi)
          Opens a JDBC connection and puts it in the connections table.
static void open(XSLProcessorContext context, ElemExtensionCall elem)
          Opens a JDBC connection and puts it in the connections table.
static void setActive(XSLProcessorContext context, ElemExtensionCall elem)
          Sets the current active JDBC connection.
 
Methods inherited from class org.ejen.ext.db.TableMetaDataNodeBuilder
getTableMetaData, getTableMetaData, getTableMetaData
 
Methods inherited from class org.ejen.ext.db.MetaDataNodeBuilder
appendErrorNode, getConnection, getDatabaseInformation, getErrors, getExportedKeys, getExportedKeys, getExportedKeys, getImportedKeys, getImportedKeys, getImportedKeys, getImportedOrExportedKeys, getIndexInfo, getIndexInfo, getIndexInfo, getPrimaryKeys, getPrimaryKeys, getPrimaryKeys, getResultSetMetaData, getResultSetMetaData, getResultSetMetaData, noNull
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

S_CI_CONNECTION_NODE_NAME

public static final String S_CI_CONNECTION_NODE_NAME
See Also:
Constant Field Values

S_CI_DRIVER

public static final String S_CI_DRIVER
See Also:
Constant Field Values

S_CI_URL

public static final String S_CI_URL
See Also:
Constant Field Values

_conns

protected static Hashtable _conns
Connections table

Constructor Detail

BasicMetaDataConnection

protected BasicMetaDataConnection()
Prevents instanciation.

Method Detail

open

public static void open(XSLProcessorContext context,
                        ElemExtensionCall elem)
Opens a JDBC connection and puts it in the connections table. If a connection is already registered with the same name, closes it before.


  <mta:open name="connection1" select="connections/connection[1]"/>
 

The selected connection Node must have the following format:


  <connection url="jdbc:hsqldb:hsql://localhost:1476"
              driver="org.hsqldb.jdbcDriver">
    <property name="user" value="sa"/>
    <property name="password" value=""/>
    [...any number of other JDBC properties]
  </connection>
 

The <property...> nodes are all passed to the DriverManager.getConnection(String,Properties) method.

Connections errors (SQLException) are not thrown. Instead, an errors NodeSet is built that can be retreived by the MetaDataNodeBuilder.getErrors(ExpressionContext) method.

XSLT Attributes:
name [Mantatory/AVT] name of the connection to be opened.
name [Mantatory] connection Node to use.

Parameters:
context - automatically passed by the xalan extension mechanism.
elem - automatically passed by the xalan extension mechanism.
Returns:
true if connection succeed, false otherwise.
Throws:
RuntimeException - if the 'name' or 'select' attribute is missing or incorrect.
WrappedRuntimeException - if the 'select' result is not a NodeIterator.

open

public static boolean open(ExpressionContext context,
                           String name,
                           NodeIterator connectionNi)
Opens a JDBC connection and puts it in the connections table. If a connection is already registered with the same name, closes it before.


  <xsl:if test="not(mta:open('connection3',connections/connection[3]))">
    ...
  </xsl:if>
 

See open(XSLProcessorContext,ElemExtensionCall).

XSLT parameters:
[Mandatory/AVT] name of the connection to be opened.
[Mandatory] connection Node to use.

Parameters:
context - automatically passed by the xalan extension mechanism.
name - name of the connection.
connectionNi - connection Node.
Returns:
true if connection succeed, false otherwise.
Throws:
RuntimeException - if the connection Node incorrect.

close

public static void close(XSLProcessorContext context,
                         ElemExtensionCall elem)
Closes a JDBC connection and removes it from the connections table.


  <mta:close name="connection1"/>
 

Connections errors (SQLException) are not thrown. Instead, an errors NodeSet is built that can be retreived by the MetaDataNodeBuilder.getErrors(ExpressionContext) method.

XSLT Attributes:
name [Mantatory/AVT] name of the connection to be closed.

Parameters:
context - automatically passed by the xalan extension mechanism.
elem - automatically passed by the xalan extension mechanism.
Returns:
true if closing connection succeed, false otherwise.
Throws:
RuntimeException - if the 'name' attribute is missing or does not match a registered connection.

close

public static boolean close(ExpressionContext context,
                            String name)
Closes a JDBC connection and removes it from the connections table.


  <xsl:if test="not(mta:close('connection3'))">
    ...
  </xsl:if>
 

Connections errors (SQLException) are not thrown. Instead, an errors NodeSet is built that can be retreived by the MetaDataNodeBuilder.getErrors(ExpressionContext) method.

XSLT parameters:
[Mandatory/AVT] name of the connection to be closed.

Parameters:
context - automatically passed by the xalan extension mechanism.
name - connection name.
Returns:
true if closing connection succeed, false otherwise.
Throws:
RuntimeException - if the 'name' parameter does not match a registered connection.

setActive

public static void setActive(XSLProcessorContext context,
                             ElemExtensionCall elem)
Sets the current active JDBC connection.


  <mta:setActive name="connection1"/>
 

XSLT Attributes:
name [Mantatory/AVT] name of the connection to be activated.

Parameters:
context - automatically passed by the xalan extension mechanism.
elem - automatically passed by the xalan extension mechanism.
Throws:
RuntimeException - if the 'name' attribute is missing or does not match a registered connection.

closeAll

public static void closeAll(XSLProcessorContext context,
                            ElemExtensionCall elem)
Closes all JDBC connections.


  <mta:closeAll/>
 

Connections errors (SQLException) are not thrown. Instead, an errors NodeSet is built that can be retreived by the MetaDataNodeBuilder.getErrors(ExpressionContext) method.

Parameters:
context - automatically passed by the xalan extension mechanism.
elem - automatically passed by the xalan extension mechanism.
Returns:
true if closing all connections succeed, false otherwise.

closeAll

public static boolean closeAll(ExpressionContext context)
Closes all JDBC connections.


  <xsl:if test="not(mta:closeAll())">
    ...
  </xsl:if>
 

Connections errors (SQLException) are not thrown. Instead, an errors NodeSet is built that can be retreived by the MetaDataNodeBuilder.getErrors(ExpressionContext) method.

Parameters:
context - automatically passed by the xalan extension mechanism.
Returns:
true if closing all connections succeed, false otherwise.