Skip Headers

Oracle® Application Development Framework Case Manual 10g Release 2 (10.1.2) B19163-01 |
| Library | Product | Contents

Previous | Next |

# 2 Setting Up the Oracle ADF Toy Store Application

This chapter contains the following sections:

- Section 2.1, "Introduction"

- Section 2.2, "Downloading and Extracting the Oracle ADF Toy Store Application"

- Section 2.3, "Setting Up the Oracle ADF Toy Store Database Users"

- Section 2.4, "Creating the Oracle ADF Toy Store Database Tables"

- Section 2.5, "Creating the Oracle JDeveloper Data Connections"

- Section 2.6, "Installing the Oracle JDeveloper JUnit Extension"

## 2.1 Introduction

These instructions assume that you are running `Oracle JDeveloper 10g` production, version 10.1.2.0.2. Although the Oracle ADF Toy Store application will work with JDeveloper 10.1.2.0.1 or 9.0.5.x, we recommend using the specified production version to follow along with the case study. The application will not work with earlier versions of JDeveloper.

We also assume that you have access to an Oracle database, and privileges to create new user accounts to set up the sample data.

Note: Oracle ADF is designed to work with any relational database, and has been tested with Oracle, Oracle Lite, DB2, and SQLServer. The `Using Oracle ADF with Foreign Datasources` whitepaper covers the details. However, for the purposes of this case study we assume that you will use the Oracle database, version 8.1.7 or later.

## 2.2 Downloading and Extracting the Oracle ADF Toy Store Application

Download the `adftoystore_10_1_2.zip` file if you haven't already.

Extract the contents of the `adftoystore_10_1_2.zip` file with the standard JDK jar utility into a convenient directory:

`jar -xvf adftoystore_10_1_2.zip`

The above command will create a directory `adftoystore` and subdirectories. (For these instructions, we assume that you have extracted the `adftoystore_10_1_2.zip` file into the root directory `C:\`, thus creating a "root" directory of `C:\adftoystore`.)

Note: If the `jar` command does not work on your system, double-check that you have included the `<JDKHOME>``/bin` subdirectory in your system path. If you downloaded the full version of Oracle JDeveloper 10g, then you will have a 1.4.2 JDK in the `<JDEVHOME>``/jdk` directory.

## 2.3 Setting Up the Oracle ADF Toy Store Database Users

Using the SQL script provided, create the `TOYSTORE` and `TOYSTORE_STATEMGMT` user accounts in the database.

Run the create user accounts SQL script like this:

`cd C:\adftoystore\DatabaseSetup sqlplus /nolog @CreateToyStoreUsers.sql`

After you enter your SYS account's password, the script will create the `TOYSTORE` and `TOYSTORE_STATEMGMT` user accounts. The `TOYSTORE` schema will contain the Oracle ADF Toy Store application tables, while the `TOYSTORE_STATEMGMT` schema will be used by the Oracle ADF state management facility to store pending data across web pages.

## 2.4 Creating the Oracle ADF Toy Store Database Tables

Run the database setup SQL script `./adftoystore/DatabaseSetup/ToyStore.sql` like this:

`sqlplus toystore/toystore @ToyStore.sql`

Note: If you have a version of the Oracle database prior to Oracle Database 10g, the command `purge recyclebin` at the end of this script will yield an error, which you can safely ignore.

## 2.5 Creating the Oracle JDeveloper Data Connections

In JDeveloper 10g, create two database connections to correspond to the two database accounts created above.

Define two connections in JDeveloper 10g:

- `toystore`, corresponding to the `TOYSTORE` user (password `TOYSTORE` )

- `toystore_statemgmt`, corresponding to the `TOYSTORE_STATEMGMT` user (password `TOYSTORE` )

Note: The two connection names are case-sensitive and should be typed in lowercase, as shown.

To save some typing, you can import these two connections from the supplied `jdev_toystore_connections.xml` file in the `./adftoystore/DatabaseSetup` directory. To do so, select the Database category folder in the Connection Navigator and choose Import Connections from the context menu. Supply the `jdev_toystore_connections.xml` filename as the file to import from. After importing the two named connections, you should test each connection by selecting it, double-clicking to bring up the Edit Database Connection dialog, and selecting the Test tab. If clicking the Test Connection button does not yield a "Success!" message, then correct the connection details on the Connection page to work for the database you want to connect to. By default, the connections are defined against a database on your local machine, listening on port `1521`, with a SID of `ORCL`.

## 2.6 Installing the Oracle JDeveloper JUnit Extension

Optionally, ensure that the JUnit Extension for JDeveloper is installed.

`JUnit` is the standard tool for building regression tests for Java applications. Oracle JDeveloper 10g features native support for creating and running JUnit tests, but this feature is installed as a separately downloadable IDE extension. You can tell if you already have the JUnit extension installed by choosing File > New from the JDeveloper main menu and verifying that you have a Unit Tests (JUnit) category under the General top-level category in the New Gallery.

If you do not already have the JUnit extension installed, then `download it` now. You'll find it along with all the other extensions available for JDeveloper in the `JDeveloper Extension Exchange` on OTN. To complete the installation of the extension, first exit JDeveloper if you are currently running it. With JDeveloper not running, extract the contents of the downloaded ZIP file into the `./jdev/lib/ext` subdirectory under your JDeveloper installation home directory. Then restart JDeveloper.

Finally, you should verify that the `junit3.8.1` subdirectory exists in your JDeveloper installation home. This directory will be automatically created the first time you run any JUnit wizard from the Unit Tests (JUnit) category of the New Gallery. However, even if you are not ready to create any JUnit tests, you may wish to perform the following steps to ensure the directory is set up correctly.

Assuming that your current directory is the JDeveloper installation home directory, run these two commands:

`jar -xvf jdev/lib/ext/junit_addin.jar junit3.8.1.zip`

The first command extracts the `junit3.8.1.zip` file from the `junit_addin.jar` archive. The ZIP file contains the distribution of JUnit that JDeveloper has been tested with.

`jar -xvf junit3.8.1.zip`

The second command extracts the contents of the junit3.8.1.zip file into the JDeveloper installation home directory.

Open the `./adftoystore/ADFToyStore.jws` workspace in JDeveloper 10g.

Run the application in JDeveloper 10g by selecting index.jsp in the ToyStoreViewController project and choosing Run, as shown in Figure 2-1, "Running the Oracle ADF Toy Store Application Inside JDeveloper".

Figure 2-1 Running the Oracle ADF Toy Store Application Inside JDeveloper

Note: Since `index.jsp` is configured as the default run target on the Runner page of the Project Properties dialog for the ToyStoreViewController project, you can also simply click the Run icon in the JDeveloper toolbar when this project is active, or right-click the project and choose Run. To see the project's properties, select the project in the navigator, right-click, and choose Property Properties.

Running the `index.jsp` page from inside JDeveloper will start the embedded Oracle Application Server 10g Oracle Containers for J2EE (OC4J) server, launch your default browser, and cause it to request the following URL:

`http://yourmachine:8988/ADFToyStore/index.jsp`

If everything is working correctly, you will see the home page of the Oracle ADF Toy Store application, as shown in Figure 2-2, "Oracle ADF Toy Store Application Home Page".

Figure 2-2 Oracle ADF Toy Store Application Home Page

The next chapter provides a quick tour of the application and helps you to become familiar with the web pages that are the subject of this case study.