Overview | Package | Class | Tree | Deprecated | Index | Help
| ContactCenters V. 0.9.9.
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## umontreal.iro.lecuyer.xmlconfig
Class DBConnectionParam

    java.lang.Object
      umontreal.iro.lecuyer.xmlconfig.AbstractParam
          umontreal.iro.lecuyer.xmlconfig.DBConnectionParam

All Implemented Interfaces:
  Cloneable, Param, StorableParam

    public class DBConnectionParam

extends AbstractParam
implements StorableParam, Cloneable

Represents the parameters for a database connection established using JDBC. A connection can be established using a JNDI name corresponding to a `DataSource`, or using a JDBC URI intended for the `DriverManager`. Connection information is given using attributes. For example, the following code gives parameters for a JDBC connection using MySQL.

     ...
        <db jdbcDriverClass="com.mysql.jdbc.Driver"
            jdbcURI="jdbc:mysql://mysql.iro.umontreal.ca/database">
           <property name="user" value="foo"/>
           <property name="password" value="bar"/>
        </db>

Constructor Summary
`DBConnectionParam()` Nullary constructor for the parameter reader.
`DBConnectionParam(Class<? extends Driver> jdbcDriverClass, URI jdbcURI)` Constructs parameters for a JDBC connection using the driver manager, with URI `jdbcURI`, and driver class `jdbcDriverClass`.
`DBConnectionParam(String jndiDataSourceName)` Constructs parameters for a JDBC connection using a data source obtained via JNDI, with name `jndiDataSourceName`.

Method Summary
`void` | `addProperty(PropertyParam p)` Adds a new connection property.
`DBConnectionParam` | `clone()`
`Connection` | `createConnection()` Creates the database connection from the parameters stored in this object.
`Class<? extends Driver>` | `getJdbcDriverClass()` Returns the JDBC driver class.
`URI` | `getJdbcURI()` Returns the JDBC URI.
`String` | `getJndiDataSourceName()` Returns the JNDI name of the data source that will be used to obtain the connection.
`Set<PropertyParam>` | `getProperties()` Returns the properties used by this parameter object.
`void` | `setJdbcDriverClass(Class<? extends Driver> jdbcDriverClass)` Sets the JDBC driver class to `jdbcDriverClass`.
`void` | `setJdbcURI(URI jdbcURI)` Sets the JDBC URI to `jdbcURI`.
`void` | `setJndiDataSourceName(String jndiDataSourceName)` Sets the JNDI name of the data source to `jndiDataSourceName`.
`Element` | `toElement(ClassFinder finder, Node parent, String elementName, int spc)` Converts this parameter object to a DOM element using the class finder `finder` for formatting class names, with parent node `parent`, element name `elementName`, and `spc` spaces for each indentation level.

Methods inherited from class umontreal.iro.lecuyer.xmlconfig.AbstractParam
`check, createDocument, getId, getXref, setId, setXref, toString, write, write, write, write, write, write, write, write`

Methods inherited from class java.lang.Object
`equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### DBConnectionParam

    public DBConnectionParam()

  Nullary constructor for the parameter reader.

### DBConnectionParam

    public DBConnectionParam(String jndiDataSourceName)

  Constructs parameters for a JDBC connection using a data source obtained via JNDI, with name `jndiDataSourceName`.

  Parameters:
    `jndiDataSourceName` - the name of the data source.
  Throws:
    `NullPointerException` - if `jndiDataSourceName` is `null`.

### DBConnectionParam

    public DBConnectionParam(Class<? extends Driver> jdbcDriverClass,
                             URI jdbcURI)

  Constructs parameters for a JDBC connection using the driver manager, with URI `jdbcURI`, and driver class `jdbcDriverClass`.

  Parameters:
    `jdbcDriverClass` - the driver class, can be `null`.
    `jdbcURI` - the JDBC URI.
  Throws:
    `NullPointerException` - if `jdbcURI` is `null`.

Method Detail

### createConnection

    public Connection createConnection()
                                throws SQLException

  Creates the database connection from the parameters stored in this object. This method first constructs a `Properties` object from the properties in this object. If a JNDI name is specified, these properties are used as an environment for the `InitialContext` constructor, the constructed context is used to look for a data source, and the connection is obtained. Otherwise, the driver is loaded if its class is not `null`, and the connection is established using the URI and properties.

  Returns:
    the established database connection.
  Throws:
    `SQLException` - if a connection error occurred.

### getJdbcDriverClass

    public Class<? extends Driver> getJdbcDriverClass()

  Returns the JDBC driver class.

  Returns:
    the JDBC driver class.

### setJdbcDriverClass

    public void setJdbcDriverClass(Class<? extends Driver> jdbcDriverClass)

  Sets the JDBC driver class to `jdbcDriverClass`.

  Parameters:
    `jdbcDriverClass` - the new JDBC driver class.
  Throws:
    `IllegalArgumentException` - if the driver class is non-`null`, and does not implement the `Driver` interface.

### getJdbcURI

    public URI getJdbcURI()

  Returns the JDBC URI.

  Returns:
    the JDBC URI.

### setJdbcURI

    public void setJdbcURI(URI jdbcURI)

  Sets the JDBC URI to `jdbcURI`.

  Parameters:
    `jdbcURI` - the new JDBC URI.

### getJndiDataSourceName

    public String getJndiDataSourceName()

  Returns the JNDI name of the data source that will be used to obtain the connection.

  Returns:
    the JNDI name of the data source.

### setJndiDataSourceName

    public void setJndiDataSourceName(String jndiDataSourceName)

  Sets the JNDI name of the data source to `jndiDataSourceName`.

  Parameters:
    `jndiDataSourceName` -

### getProperties

    public Set<PropertyParam> getProperties()

  Returns the properties used by this parameter object. The properties are used as an environment for configuring JNDI, or as parameters to the driver manager, depending on how the connection is established.

  Returns:
    the connection properties.

### addProperty

    public void addProperty(PropertyParam p)

  Adds a new connection property.

  Parameters:
    `p` - the new property.

### toElement

    public Element toElement(ClassFinder finder,
                             Node parent,
                             String elementName,
                             int spc)

  Description copied from interface: `StorableParam`
  Converts this parameter object to a DOM element using the class finder `finder` for formatting class names, with parent node `parent`, element name `elementName`, and `spc` spaces for each indentation level. The method must create an `Element` instance with name `elementName` and add it to the node `parent` of the DOM tree. It is recommended to use `DOMUtils` helper methods for this. After the element is created, attributes can be set and nested contents can be added. The configured DOM element is then returned.

  Specified by:
    `toElement` in interface `StorableParam`
  Parameters:
    `finder` - the class finder used to format class names.
    `parent` - the parent of the new element.
    `elementName` - the name of the constructed element.
    `spc` - the number of spaces for each indentation level.
  Returns:
    the newly-constructed element.

### clone

    public DBConnectionParam clone()

  Overrides:
    `clone` in class `Object`

Overview | Package | Class | Tree | Deprecated | Index | Help
| ContactCenters V. 0.9.9.
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

To submit a bug or ask questions, send an e-mail to Richard Simard.