|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.townleyenterprises.persistence.PersistenceConfig
This class is used to provide a flexible mechanism to resolving the required database connection parameter values and encapsulate the differences between various database vendor connection URLs.
This class uses a set of properties to provide overridable values for making the connection to a specific server. The master property is the type of database to be used, as this value is used to provide overrides. This mechanism allows completely different database configurations to coexist enabling easy swapping of the connectivity information.
Property | Description |
---|---|
database.type |
The symbolic name of the database type. This name is entirely
dependent on the site, however the name or abbreviation of the
database vendor is generally used, e.g. postgresql .
|
database.user | The login name for the database connection. |
database.password | The password for the database connection. |
database.host | The host name for the database connection. |
database.name | The name of the database for the connection. |
${database.type}.user | The login name for the database connection for the given database type. This value overrides the default parameter. |
${database.type}.password | The password for the database connection for the given database type. This value overrides the default parameter. |
${database.type}.host | The host name for the database connection for the given database type. This value overrides the default parameter. |
${database.type}.database.name | The name of the database for the connection for the given database type. This value overrides the default parameter. |
${database.type}.jdbc.params |
The parameter names necessary to supply to the JDBC driver URL.
Parameter names can be anything, however the special parameter name
|
${database.type}.jdbc.url |
This property is a string processed by the java.text.MessageFormat
class to generate the correct JDBC URL for the connection based on
the parameter values specified by the
${database.type}.jdbc.params property.
|
${database.type}.jdbc.driver | This property specifies the fully-qualified class name of the JDBC driver for this database type. |
${database.type}.${param} |
For each token in the value of the
${database.type}.jdbc.params property, a parameter may be
defined based on the database type and the specific token. The
value of this parameter is used to specify the appropriate
arguments to the
${database.type}.jdbc.url property value.
|
The above description becomes clearer with a concrete example. Given the need to run an application against a test database server (PostgreSQL) and a production database server (Oracle), the following properties file could be supplied. Based on changing only the database type property value, the application can easily be switched from one configuration to another.
database.type=postgresql #database.type=oracle database.user=appname database.password=secret database.name=data postgresql.host=testbox.myco.com postgresql.port=5432 postgresql.jdbc.params=host port database postgresql.jdbc.url=jdbc:postgresql://{0}:{1}/{2} postgresql.jdbc.driver=org.postgresql.Driver oracle.host=production.myco.com oracle.port=1521 oracle.database.name=production oracle.jdbc.params=host port database oracle.jdbc.url=jdbc:oracle:thin:@{0}:{1}:{2} oracle.jdbc.driver=oracle.jdbc.OracleDriver
Constructor Summary | |
PersistenceConfig()
This version of the constructor works with the AppConfig class to provide
the property information. |
|
PersistenceConfig(java.util.Properties properties)
|
Method Summary | |
java.lang.String |
getConnectionURL()
This method returns the URL for the current connection, correctly populated with all of the parameter values. |
java.lang.String |
getDriverName()
This method returns the driver for the current connection. |
java.lang.String |
getHost()
This method returns the host for the current connection. |
java.lang.String |
getPassword()
This method returns the password for the current connection. |
java.lang.String |
getUser()
This method returns the username for the current connection. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public PersistenceConfig(java.util.Properties properties)
public PersistenceConfig()
AppConfig
class to provide
the property information.
Method Detail |
public java.lang.String getUser()
public java.lang.String getPassword()
public java.lang.String getHost()
public java.lang.String getDriverName()
public java.lang.String getConnectionURL()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |