Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

This sample illustrates direct use of JDBC connections from a servlet. For details on outbound connection support see Connectors and Transaction Management (JDBC, JMS, J2CA, DataSource, Connection Pool, EIS). Generally direct use of JDBC is not advised unless you have performance constraints or need for dynamic jdbc (such as in a database browser) that make the use of JPA impractical.

...

  • org.apache.geronimo.samples.inventory
    • Item - represents Item in the Inventory.
  • org.apache.geronimo.samples.inventory.services
    • InventoryManager - represents list of services offered by the inventory.
  • org.apache.geronimo.samples.inventory.dao
    • ItemDAO - contains all database access methods.
  • org.apache.geronimo.samples.inventory.exception
    • DuplicateItemIdException - custom exception to handle duplication item id scenario.
    • ItemException - wraps data access exceptions (NamingException, SQLException).
    • NotSufficientQuantityException - Custom exception to handle not sufficient quantity situation.
  • org.apache.geronimo.samples.inventory.web
    • AddItemServlet - dispatch add item information to service layer.
    • IssueingServlet - dispatch issuing items information to service layer.
    • RecievingServlet ReceivingServlet - dispatch receiving items information to service layer.

...

Code Block
xml
xml
borderStylesolid
titleweb.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
	 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
         version="2.4">

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

    <servlet>
        <display-name>AddItemServlet</display-name>
        <servlet-name>AddItemServlet</servlet-name>
        <servlet-class>org.apache.geronimo.samples.inventory.web.AddItemServlet</servlet-class>
    </servlet>
    <servlet>
        <display-name>IssueingServlet</display-name>
        <servlet-name>IssueingServlet</servlet-name>
        <servlet-class>org.apache.geronimo.samples.inventory.web.IssueingServlet</servlet-class>
    </servlet>
    <servlet>
        <display-name>RecievingServlet<name>ReceivingServlet</display-name>
        <servlet-name>ReceivingServlet</servlet-name>
        <servlet-class>org.apache.geronimo.samples.inventory.web.ReceivingServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>AddItemServlet</servlet-name>
        <url-pattern>/add_item</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>IssueingServlet</servlet-name>
        <url-pattern>/issue</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>ReceivingServlet</servlet-name>
        <url-pattern>/recv</url-pattern>
    </servlet-mapping>

    <!-- reference name exposed as a datasource -->
    <resource-ref>
        <res-ref-name>jdbc/InventoryDS</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>

</web-app>

...

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:

svn co http://svn.apache.org/repos/asf/geronimo/samples/branches/2.1/samples/inventory/Image Removed inventory_home

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.

  1. Select DB Manager link from the Console Navigation panel on the left.
  2. Give the database name as InventoryDB and click Create button.
  3. Select InventoryDB to the Use DB field.
  4. Open InventoryDB.sql in the <sample_home>/inventory-ear/src/main/resources directory from a text editor.
  5. Paste the content InventoryDB.sql to the SQL Commands text area and press Run SQL button.

...

borderStylesolid
titleInventoryDB.sql

...

item

...

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.

...

.

...

Testing of the Sample Application

To test the sample application, open a browser and type http://localhost:8080/inventoryImage Removed. 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.

The highlights of this article are:

...

.