5. The Middle Tier
Prev |  | Next

## 5. The Middle Tier

## 5.1 Introduction

GreenPages’ middle-tier provides implementations of the `Directory` and `Listing` interfaces that can be used by the Web bundle. The implementation will use EclipseLink JPA to access a database via a `DataSource` published in the OSGi service registry.

### The database

The GreenPages application uses a very simple database that contains a single table. The table, named `LISTING`, consists of four columns:

LISTING_NUMBER | FIRST_NAME | LAST_NAME | EMAIL_ADDRESS

Scripts are provided with the sample source code (in `$GREENPAGES_HOME/db`) to start, create, and populate the database. These will be used during the creation of the middle tier.

### Using JPA

The middle tier will provide JPA-based implementations of the `Directory` and `Listing` interfaces with the four attributes of a `Listing` (first name, last name, email address, and id) being mapped to the corresponding columns in the `LISTING`. JPA will be used to implement the queries that search the database and return `Listings`.

### Structure

The middle tier consists of two bundles, `greenpages.jpa` that publishes a `Directory` implementation for consumption by the Web bundle, and `greenpages.db` to configure and publish the `DataSource` used to access the database.

Prev |  | Next
4.7 Publishing an OSGi Service | Home | 5.2 Creating the DataSource project