20-May-06 (Created: 20-May-06) | More in 'Data Access'

05.03 Aspire database definition examples

Oracle


Database.oracle-database-prod.jdbc_driver=oracle.jdbc.driver.OracleDriver
Database.oracle-database-prod.connection_string=jdbc:oracle:thin:@host:port:oracle_instance
Database.oracle-database-prod.userid=user
Database.oracle-database-prod.password=passwd

Microsoft Access


Database.accessDB-test.jdbc_driver=sun.jdbc.odbc.JdbcOdbcDriver
Database.accessDB-test.connection_string =jdbc:odbc:ptr.mdb
Database.accessDB-test.userid=access_user
Database.accessDB-test.password=access_password

MySQL


Database.mysql-database-dev.jdbc_driver=org.gjt.mm.mysql.Driver
Database.mysql-database-dev.connection_string=jdbc:mysql://11.11.11.11/CountryClub
Database.mysql-database-dev.userid=demo
Database.mysql-database-dev.password=demo

Databases aliases


database.alias.app1-database=mysql-database-dev
database.alias.app2-database=oracle-database-prod
database.alias.app3-database=accessDB-test

Databases aliases are used for changing your databases with out changing the rest of the code.

A sample sql statement


request.getEmployees.classname=com.ai.db.DBRequestExecuor2
request.getEmployees.db=app2-database
request.getEmployees.stmt=your-select-statement-goes-here

See how the app2-database alias could be pointing to any of the above databases. Changing this indirection will not impact the select query called "getEmployees". One can use this mechanism especially to move between development, testing, and production with out extensively changing code.

A note of caution or limitation

Currently there is no concept of a default database. This means with every select statement you have to use a database alias. You can not skip and assume a default one.

References

1. Aspire data access over view

2. Using aspire for relational data access. This article also goes into the number of ways one can use Aspire for queries, updates, and transactions. This artcile also talks about a tool for testing data access and validating your connection strings.