Package helma.objectmodel.db
Class DbSource
java.lang.Object
helma.objectmodel.db.DbSource
This class describes a releational data source (URL, driver, user and password).
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDbSource
(String name, ResourceProperties props) Creates a new DbSource object. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Indicates whether some other object is "equal to" this one.Get a JDBC connection to the db source.protected DbMapping
getDbMapping
(String tablename) Look up a DbMapping instance for the given table name.Return the class name of the JDBC drivergetName()
Return the name of the db dourceint
hashCode()
Returns a hash code value for the object.boolean
isH2()
Check if this DbSource represents a H2 databaseboolean
isMySQL()
Check if this DbSource represents a MySQL databaseboolean
isOracle()
Check if this DbSource represents an Oracle databaseboolean
Check if this DbSource represents a PostgreSQL databaseprotected void
registerDbMapping
(DbMapping dbmap) Register a dbmapping by its table name.static void
Set the default (server-wide) propertiesswitchProperties
(ResourceProperties newProps) Set the db properties to newProps, and return the old properties.
-
Field Details
-
url
-
-
Constructor Details
-
DbSource
Creates a new DbSource object.- Parameters:
name
- the db source nameprops
- the properties- Throws:
ClassNotFoundException
- if the JDBC driver couldn't be loaded
-
-
Method Details
-
getConnection
Get a JDBC connection to the db source.- Returns:
- a JDBC connection
- Throws:
ClassNotFoundException
- if the JDBC driver couldn't be loadedSQLException
- 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
Return the class name of the JDBC driver- Returns:
- the class name of the JDBC driver
-
getName
Return the name of the db dource- Returns:
- the name of the db dource
-
setDefaultProps
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
Register a dbmapping by its table name.- Parameters:
dbmap
- the DbMapping instance to register
-
getDbMapping
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. -
equals
Indicates whether some other object is "equal to" this one.
-