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 into the following sections :

Table of Contents

Application overview

The sample application covered in this article will help you to test the Database connection pools deployed in your Geronimo server. One can consider this as an extension to the Geronimo console because the current version does not contain the ability to test connections to database pools after they have been deployed.

...

Welcome page of the application acts as a notice board which displays list of Database connection pools deployed in the Geronimo application server. Users can directly test those connection pools from the first page. If that particular connection pool requires a username and a password to get a connection, enter those details in the pop up window that appears. The list of database schemas and the tables associated with the connection pool will be displayed in the Schemas and Tables page. The contents of each table can be accessed from there on.

Application contents

The Inventory application consists of following list of packages.

...

Code Block
java
java
borderStylesolid
titleExcerpt from DBManagerBean.java
	public Map getTableList(String poolName) throws SQLException {
		
		tableMap = new HashMap();
		
		if(poolMap.containsKey(poolName)){
			DataSource ds = (DataSource)poolMap.get(poolName);
			Connection con = null;
			try {
				
				con = ds.getConnection();
				
				DatabaseMetaData metaData = con.getMetaData();
				String[] tableTypes = {"TABLE"};
				ResultSet rs = metaData.getTables(null, null, null, tableTypes);
				
				while(rs.next()){
					String schemaName = rs.getString("TABLE_SCHEM");
					String tableName = rs.getString("TABLE_NAME"); 
					ArrayList tableList = null;
					
					if(tableMap.containsKey(schemaName)){
						tableList = (ArrayList)tableMap.get(schemaName);
						tableList.add(tableName);
					}else {
						tableList = new ArrayList();
						tableList.add(tableName);
					}
					tableMap.put(schemaName, tableList);
				}
			} catch (SQLException e) {
				throw e;
			}finally {
				if(con != null){
					try {
						con.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
			}
		}
		
		return tableMap;
	}

Tools used

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

Eclipse

The Eclipse IDE was used for development of the this sample application. This is a very powerful and popular open source development tool. Integration plug-ins are available for the Geronimo application server too. Eclipse can be downloaded from the following URL:
http://www.eclipse.org

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

Building and Deploying the Sample Application

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

...

A directory named dbtester_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 <dbtester_home>.

Building

The dbtester application comes with a Maven 2 pom.xml script file to help users to build from source code. Open a command prompt window, navigate to the <dbtester_home> directory and run the mvn install command. This will create a dbtester-war-2.1-SNAPSHOT.war file, the application is now ready to be deployed on the Geronimo Application server.

Deploying

Deploying this sample application is pretty straight forward, since we will be using Geronimo Administration Console.

  1. Navigate to Deploy New link from the Console Navigation panel.
  2. Browse to the dbtester-war-2.1-SNAPSHOT.war file from the <dbtester_home> directory in 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/dbtester. This will load the index page of dbtester application which acts as a notice board, with the list of database pools deployed in Geronimo.

The user can directly test the listed database pools with this sample application. Furthermore, the application can be used to list the contents of the databases.

Summary

This article has shown you how to access Geronimo related features from a J2EE application. You followed step-by-step instructions to build, deploy and test a sample application to elaborate these features. This sample application can be used as tester for database connection pools deployed in Geronimo.