Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: prefix pages with app name so order is the same as in svn

...

This article is organized in to following sections.

Table of Contents

Overview of JDBC Features

JDBC implementation in application servers vary from application server to other. Following table gives a feature list of JDBC in Apache Geronimo.

Feature

Description

JDBC access

Geronimo does not have any direct integration with JDBC but supports access through the generic J2CA framework. The TranQL project has J2CA adapters for various databases.

JCA implementation

Geronimo supports the JCA 1.5 specification and is backward compatible to the JCA 1.0 specification.

Data sources supported

TranQL has generic wrappers for each data sources.

Data source failover

TranQL has specialized drivers for certain databases (including Apache Derby, Oracle and DB2) that provide a tighter integration with the advanced features of the driver.
It is at this level that features such as load-balancing and failover would be provided. You can also use a C-JDBC wrapper for providing database clustering and failover.

XA support

Supports XA transactions, Local Transactions, and No transaction.

Connection Manager Configurability

The J2CA framework is interceptor based which allows different parts of the connection framework to be plugged in.

JTA implementation

Transaction support is provided through Geronimo Specific Transaction Managing Framework and HOWL.

Connection pooling and management

Custom Geronimo Code and TranQL used for connection pooling and management.

Legacy driver support

Geronimo provides this through the TranQL- connector JDBC to JCA wrapper in Geronimo. Supports JDBC 3.0 and 2.1.

Application Overview

The Inventory application in this article only supports three basic usecases of such applications.

...

Welcome page of the application acting as a notice board which displays current stock of each item. Through the Welcome page users can access Add Item, Receive Goods or Issue Goods Pages. Upon successful completion of each activity, the page will be redirected back to the Welcome page with updated stock information. Add Item helps to define items in the stock, then 0 number of items will be added to the stock. Receive and Issue Goods pages represent Goods Receiving and Issuing activities of the application respectively.

Application contents

The Inventory application consist of following list of packages and classes.

...

Code Block
java
java
borderStylesolid
titleDBManager.java
package org.apache.geronimo.samples.inventory.util;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;


public class DBManager {
	
	public static Connection getConnection(){
		Connection con = null;

		try {
			Context context = new InitialContext();
			DataSource ds = (DataSource)context.lookup("java:comp/env/jdbc/InventoryDS");
			con = ds.getConnection();
		} catch (NamingException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return con;
	}

}

Sample Database

The sample database that is being used to demonstrate this application is in-built Derby database. The name of the sample database is InventoryDB and it consists of two tables, namely ITEM and ITEM_MASTER. The fields for each of these tables are described below.

...

The ITEM table stores the data related to the items while ITEM_MASTER stores the quantity in hand of each item.

Tools used

The tools used for developing and building the Inventory sample application are:

Apache Derby

Apache Derby, an Apache DB subproject, is a relational database implemented in Java. Its footprint is so small you can easily embed it in any Java-based solution. In addition to its embedded framework, Derby supports a more familiar client/server framework with the Derby Network Server.
http://db.apache.org/derby/index.html

Apache Maven 2

Maven is a popular open source build tool for enterprise Java projects, designed to take much of the hard work out of the build process. Maven uses a declarative approach, where the project structure and contents are described, rather than the task-based approach used in Ant or in traditional make files, for example. This helps enforce company-wide development standards and reduces the time needed to write and maintain build scripts. The declarative, lifecycle-based approach used by Maven 1 is, for many, a radical departure from more traditional build techniques, and Maven 2 goes even further in this regard. Maven 2 can be download from the following URL:
http://maven.apache.org

Configuring, building and deploying

Currently this sample application is available from our subversion repository, use the following svn command to retrieve the content:

...

A directory named inventory_home will be created when you check out from the source, you can choose a directory name and location convenient to you. We will generically refer to this directory as <sample_home>.

Configuring

Configuration of the application consists of creating the database and defining the connection pool to access it.

Creating and Populating Database

After starting Apache Geronimo log into the console and follow the given steps to create the InventoryDB database.

...

No Format
borderStylesolid
titleInventoryDB.sql
CREATE TABLE item(
	item_id VARCHAR(10) PRIMARY KEY,
	item_name VARCHAR(25),
	description VARCHAR(100)	
);

CREATE TABLE item_master(
	item_id VARCHAR(10) PRIMARY KEY,
	quantity INTEGER
);

INSERT INTO item VALUES('001', 'Item 1', 'Test Item 1');
INSERT INTO item VALUES('002', 'Item 2', 'Test Item 2');
INSERT INTO item VALUES('003', 'Item 3', 'Test Item 3');
INSERT INTO item VALUES('004', 'Item 4', 'Test Item 4');


INSERT INTO item_master VALUES('001', 12);
INSERT INTO item_master VALUES('002', 8);
INSERT INTO item_master VALUES('003', 49);
INSERT INTO item_master VALUES('004', 34);

Building

Inventory application comes with an pom.xml script to help users to build from source code. Use the command prompt to navigate into the inventory directory and just give mvn install command to build. It will create the inventory-ear-2.1-SNAPSHOT.ear file under the <sample_home> directory. Now, you are ready to deploy Inventory web application in to the Geronimo Application server.

Deploying

Deploying sample application is pretty straight forward as we are going to use the Geronimo Console.

  1. Click the Deploy New link on the Console Navigation panel.
  2. Load inventory-ear-2.1-SNAPSHOT.ear file from <sample_home> directory into the Archive input box.
  3. Press Install button to deploy the application in the server.

Testing of the Sample Application

To test the sample application, open a browser and type http://localhost:8080/inventory. The Welcome page of Inventory application which is acts as a notice board will be loaded.

...

The user can directly access Add Items, Receive Goods and Issue Goods functionalities from the Welcome page.

Summary

This article has shown you how to use JDBC features inside the Geronimo Application Server. You followed step-by-step instructions to build, deploy and test a sample application to elaborate these features.

...