Chapter 3. Database Connectivity

Apache Geronimo is used for hosting Java EE enterprise applications. All enterprise applications operate on data and in most of them, all or a part of this data is stored in a relational database. Therefore, it is important for an application server to provide an infrastructure for applications to simplify and optimize relational database access.

Java applications use the Java Database Connectivity (JDBC) API for SQL-based database access. This is an API that is independent of the underlying database. The database vendors provide JDBC drivers for their respective RDBMSes. The Java EE application server provides a mechanism for optimizing and simplifying database access through connection pools. The server creates a pool of connections so that the applications can reuse the connections in the pool. As a result, the applications are spared from creating and closing connections, and the connection reuse actually speeds up the process as it is more efficient than creating connections whenever required. Another advantage is that it ensures that the application code will not contain any RDBMS vendor-specific code, thereby making it possible to swap the RDBMS used without changing any code.

Apache Geronimo provides these features with the help of the TranQL framework. The TranQL framework wraps JDBC drivers in J2CA connectors, and so in Apache Geronimo, JDBC connectivity is also exposed through J2CA just like it is for JMS. This enables both database and JMS invocations to be part of a single transaction. Geronimo supports JDBC connection pools with local transaction support, and also ones with XA transaction support. All you have to do is configure the resource adapter with the JDBC properties that you would use to establish a JDBC connection directly, and the resource adapter will create the database pool. Creating a database connection upon each request is costly in terms of resource usage, and it holds on to resources unnecessarily. With a database pool, the created connections are placed in a pool and reused so that new connections need not be made unless the connections in the pool are all in use. This also reduces the waiting time of the application to obtain a connection to the database.

There are generic TranQL connectors in Geronimo that can support any relational database and there are also database-specific resource adapters. All of the XA connectors are database-specific and so XA support is provided only for a limited number of databases. The TranQL RAR files contain the connection pooling logic that is used by Geronimo.

In this chapter, you will learn:

  • The scope of database pools

  • Creating a server-wide database pool

  • Creating an application-scoped database pool

  • Creating a client-scoped database pool

  • Editing an existing database pool

  • Importing a database pool from another application server

  • Using a database pool in an application

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset