Package helma.objectmodel.db

# Class DbSource

java.lang.Object
helma.objectmodel.db.DbSource

public class DbSource extends Object
This class describes a releational data source (URL, driver, user and password).

## Field Summary

Fields
Modifier and Type
Field
Description
`protected String`
`url`

## Constructor Summary

Constructors
Constructor
Description
`DbSource(String name, ResourceProperties props)`
Creates a new DbSource object.

## Method Summary

Modifier and Type
Method
Description
`boolean`
`equals(Object obj)`
Indicates whether some other object is "equal to" this one.
`Connection`
`getConnection()`
Get a JDBC connection to the db source.
`protected DbMapping`
`getDbMapping(String tablename)`
Look up a DbMapping instance for the given table name.
`String`
`getDriverName()`
Return the class name of the JDBC driver
`String`
`getName()`
Return the name of the db dource
`int`
`hashCode()`
Returns a hash code value for the object.
`boolean`
`isH2()`
Check if this DbSource represents a H2 database
`boolean`
`isMySQL()`
Check if this DbSource represents a MySQL database
`boolean`
`isOracle()`
Check if this DbSource represents an Oracle database
`boolean`
`isPostgreSQL()`
Check if this DbSource represents a PostgreSQL database
`protected void`
`registerDbMapping(DbMapping dbmap)`
Register a dbmapping by its table name.
`static void`
`setDefaultProps(ResourceProperties props)`
Set the default (server-wide) properties
`ResourceProperties`
`switchProperties(ResourceProperties newProps)`
Set the db properties to newProps, and return the old properties.

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### url

protected String url

## Constructor Details

### DbSource

public DbSource(String name, ResourceProperties props) throws ClassNotFoundException
Creates a new DbSource object.

Parameters:
  `name` - the db source name
  `props` - the properties
Throws:
  `ClassNotFoundException` - if the JDBC driver couldn't be loaded

## Method Details

### getConnection

public Connection getConnection() throws ClassNotFoundException, SQLException
Get a JDBC connection to the db source.

Returns:
  a JDBC connection
Throws:
  `ClassNotFoundException` - if the JDBC driver couldn't be loaded
  `SQLException` - if the connection couldn't be created

### switchProperties

public ResourceProperties switchProperties(ResourceProperties newProps) throws ClassNotFoundException
Set the db properties to newProps, and return the old properties.

Parameters:
  `newProps` - the new properties to use for this db source
Returns:
  the old properties
Throws:
  `ClassNotFoundException` - if jdbc driver class couldn't be found

### getDriverName

public String getDriverName()
Return the class name of the JDBC driver

Returns:
  the class name of the JDBC driver

### getName

public String getName()
Return the name of the db dource

Returns:
  the name of the db dource

### setDefaultProps

public static void setDefaultProps(ResourceProperties props)
Set the default (server-wide) properties

Parameters:
  `props` - server default db.properties

### isOracle

public boolean isOracle()
Check if this DbSource represents an Oracle database

Returns:
  true if we're using an oracle JDBC driver

### isMySQL

public boolean isMySQL()
Check if this DbSource represents a MySQL database

Returns:
  true if we're using a MySQL JDBC driver

### isPostgreSQL

public boolean isPostgreSQL()
Check if this DbSource represents a PostgreSQL database

Returns:
  true if we're using a PostgreSQL JDBC driver

### isH2

public boolean isH2()
Check if this DbSource represents a H2 database

Returns:
  true if we're using a H2 JDBC driver

### registerDbMapping

protected void registerDbMapping(DbMapping dbmap)
Register a dbmapping by its table name.

Parameters:
  `dbmap` - the DbMapping instance to register

### getDbMapping

protected DbMapping getDbMapping(String tablename)
Look up a DbMapping instance for the given table name.

Parameters:
  `tablename` - the table name
Returns:
  the matching DbMapping instance

### hashCode

public int hashCode()
Returns a hash code value for the object.

Overrides:
  `hashCode` in class `Object`

### equals

public boolean equals(Object obj)
Indicates whether some other object is "equal to" this one.

Overrides:
  `equals` in class `Object`