This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information

--Database Independent Configuration of the Application

Documents for the development of and with JVx.

--Database Independent Configuration of the Application

Postby Development@SIB » Thu Sep 16, 2010 12:05 pm



This article is outdated - please use our new system at

https://doc.sibvisions.com




JVx allows the development of database independent applications. However, access to the database requires specific information, such as host name, database port, database name, username, password, etc.

This information is usually saved in a configuration file. We use the applications configuration config.xml that is available for our application on the server side:

Example:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>

<application>
  <securitymanager>
    <class>com.sibvisions.apps.packung.security.AnonymousDBSecurityManager</class>
    <database>
      <url2>jdbc:oracle:thin:@localhost:1521:packung</url2>
      <url>jdbc:derby://localhost:1527/packung</url>
      <username>pack_user</username>
      <password>pack_password</password>
    </database>
  </securitymanager>
 
  <!-- predefined life-cycle object names -->
  <lifecycle>
    <mastersession>com.sibvisions.apps.packung.Session</mastersession>
  </lifecycle>
</application>

As this example shows, we use the url parameter to define access to the database. During the development of a database-independent application, the database has to be changed to test its functionality. For this purpose we replace the content of url with url2.

After the database has been defined, the application has to access it.

To access the database, an object of type IDBAccess is required. A number of different implementations exist, such as OracleDBAccess, DerbyDBAccess.

The developer could now use a specific implementation, such as OracleDBAccess to access only Oracle databases. Although this allows the use of special features provided by OracleDBAccess if the database is changed, the source code has to be altered as well.

In this case we chose a generic approach to access the database:

Code: Select all
DBAccess dba = DBAccess.getDBAccess(cfgSession.getProperty
                                    ("/application/securitymanager/database/url"));

dba.setUsername(cfgSession.getProperty("/application/securitymanager/database/username"));
dba.setPassword(cfgSession.getProperty("/application/securitymanager/database/password"));
dba.open();

This way we always receive the correct object for access to the configured database.
User avatar
Development@SIB
 
Posts: 325
Joined: Mon Sep 28, 2009 1:54 pm

Return to Documentation