July 26, 2008

Book Review: Apache JMeter

Not necessarily part of the ADF in Action series, but we will see later how we can leverage the input from this book later...

Testing: The Missing Project Task

For many, testing is one of the most tedious and time consuming parts of software development. This is true and in many projects this will be the first victim to get more buffer time for the overdue development tasks. Any attempt to make it more comfortable and repeatable helps, to keep this task back on the project plan.

Apache JMeter: One of the Many Tools for the Trade

There are a number of tools, open-source, free, and commercial ones, available on the market to help each of us to lower the pain and reducing the time and need for manual testing. Apache JMeter is one of my all-time favourites and also an open-source and free tool. I have seen it in use in many projects, set to action by more or less skilled team members. Its usages are from load to functional testing during the developer and the user-acceptance tests also. JMeter's extensible architecture easily allows it to adopt recent trends in development and makes it even useful for Service-Oriented Architecture  that are implemented around SOAP, JMS, and HTTP.

The Author

Emily H. Halili works as a quality-assurance engineer in Malaysia and has a lot of hands-on experiences to guide the reader into the usefulness of testing in general and Apache JMeter in particular.

The Book

When I first had the book in my hands, I was a bit disappointed because I am used to those hefty 500+ page monsters that keep me awake for hours and days. This 140 pages and 8 chapters beauty is a very handy book for Apache JMeter beginners and for me to carry around. It is about the right amount of text and topics to get started with the topics of load testing and functional testing.

But before you can get your hands dirty with Apache JMeter, a short introductary chapter how automated testing pays off. This valuable chapter, at least when your project managers wants to cut the testing time again, is followed by a quick introduction to JMeter with all the tool specific concepts like Test Plan, ThreadGroup, Listeners, Controllers, Timers, Assertions, and Configuration Elements. As an experienced developer you might be able to install JMeter quickly, but for the beginner Chapter 3 Installing Apache JMeter is a quick and short one.

Having finished these three chapters, you are ready for prime time. Chapter 4, The Test Plan shows you all the parts of JMeter test plan. This is by far the most important chapter of the book. It sets the scene for the following chapters by explaining all parts of a good test plan and how they interact together. In Chapter 5, Load/Performance Testing of Websites you learn how to do a load test efficiently and how to avoid penalties for Denial of Service attacks while testing. In the Functional Testing chapter you get ideas what parts are needed and how to combine them for the formal tests.

If you think these three chapters are helpful for your next testing assignments you should also consider the Advanced Features chapter which tells you how to extend the Web test by using loops or how to reference variables from the configuration steps, as well as testing a Database or an FTP server.

Overall Impressions

The book is an easy read and you can do it in your lunch break or in the first few hours of your testing assignment. It is a perfect companion book for a pretty useful tool and a nice introduction for every Apache JMeter beginner. I wish this book was available years before I started to use JMeter. With the first chapter it should be on the desk of every test or quality assurance engineer. Personally I can not wait for the sequel: Apache JMeter: Advanced Techniques.

Book Details

Emily H. Halili
Apache JMeter
ISBN 978-1-847192-95-0
Packt Publishing

July 8, 2008

ADF in Action: Building the Model Layer with ADF BC (BC4J)

It has been a while. Being busy is a lame excuse, I was also investigating some other things and worked a lot with Oracle Application Diagnostics for Java (AD4J)...

Oracle ADF Business Components

The first version of Oracle ADF Business Components say the light of the world with JDeveloper 3. It was created to address the deficiencies of the EJB 1.1 specification. Although named Business Components this is a framework to create Business Components (for Java). ADF Business Components are usually referred ADF BC or BC4J. I will try be consistent but bear with me if I mix both.

Entities and Views and Application Modules

Like any other ORM framework ADF BC has its own names for the same concepts. The primary concepts are Entities, Views and Application Modules. Entities are usually considered as the representation of a table row in the database, while Views are manipulating the Entities (creating, updating, retrieving, and deleting). While Views work on Entities you need an Application Module to work with the Views and with the data in the database. The Application Module contains all the Views that are need for this module and the necessary information of the underlying database.

Implementing the ADF BC Model Layer

As in the two previous model layers we are reusing the data model created in the database. This is also a strength of ADF BC, working with existing database model instead of creating it from scratch. (As both approaches have their pros and cons, a seperate entry to show these is quite likely.) Like before we're following the same order of steps for JDeveloper 10.1.3 and 11g:

  • Create a Model Layer Project
  • Import the Database Objects

Steps for JDeveloper 10.1.3

Step 1: Create a Model Layer Project

  • To create a new Model Layer Project select OnlineSurvey in the Application Navigator, open the Context Menu and chose the New Project... menu entry.
  • In the New Gallery select an Empty Project and click on OK.
  • In the Create Project window set the Project Name to ModelBC and click on the OK button.
  • Select the newly created ModelBC project in the Application Navigator and open the Project Properties window with a double-click.
  • In the Project Properties window, check the values of Project Content and make sure that the Default Package is set to demo.survey.model.bc. Click OK to close this window.
  • Click on the Connections Navigator. Expand the Database folder, select the survey entry and open the Context Menu. From it select the Properties... entry to open the Edit Database Connection window. Click on the Authentication tab and check whether the Deploy Password check box is checked. If not, make sure that it is checked! ADF BC relies on it.

Step 2: Import Business Components from Tables

Select the ModelBC project in the Application Navigator. Open the New Gallery from the Context Menu -> New .... In the New Gallery expand the Business Tier and select ADF Business Components. On the right-hand side select Business Components From Tables and click on the OK button.

  • In the Initialize Business Components Project window select the survey connection and accept the default values for the SQL Flavor and Type Map (both should be Oracle). Click OK and the OK button on the Login window.
  • In the Create Business Components From Tables wizard step 1, click on the Query button to get all available tables. Once the table names appear, select all of them. Move all entries from Available to Selected, by clicking on the >> button. Like in the other model projects we change the names from plural to singular names. Best is to do it right now by selecting each line in the list and change the appearing value in the Entity Name text field, eg Answers to Answer.
  • Click Finish to end this wizard.

The wizard will now create the Entities and Association files in a single package. This is quite good at the first sight but really tedious if return to the project in three weeks. The naming for the Associations is hardly readable or memorable. Therefore we need to do two things:

  1. Move the Associations and the Entities in separate package.
  2. Rename the Associations with better readable names.

Move the files in separate packages is quite easy. Select all Entities, the ones without the Assoc suffix (Click on the file while holding the Ctrl-key). From the Context Menu select Refactor->Move... and type in the name demo.survey.model.bc.entities. After clicking on OK all files will be moved in the new package. You might be asked for creating the new package directory. This is perfectly OK. Repeat this for the Associations and move them into the package demo.survey.model.bc.links.

Warning! In JDeveloper 11g TP4 this might not finish. If this happens to you, the easiest bet is to kill JDeveloper 11g TP 4 and continue where it stopped.

Renaming the Associations to better readable names is as simple as moving the files. Only difference is that must do it file by file. In the demo.survey.model.bc.links package we select an Association, open the Context Menu, select Refactor, select Rename..., enter the new name and click on OK. We repeat this for all entries in the package and rename them according to the table below.

Old Name New Name
AnswersResponsesFKAssoc AnswersPerResponse
ItemsQuestionsFKAssoc ItemsPerQuestion
QuestionsSurveyFKAssoc QuestionsPerSurvey
RepsonseSurveysFKAssoc ResponsesPerSurvey
SurveysAuthorsFKAssoc SurveysPerAuthor

Steps for JDeveloper 11g

Note: During the course of this series a new version of the JDeveloper 11g has been released on OTN. I will follow every official release and you should do the same. If you've created the projects with an earlier version of JDeveloper 11g and reopen them in a newer release, it is possible that the project files have to be migrated. if JDeveloper asks you to do this, simply accept it.

Step 1: Create a Model Layer Project

  • To create a new Model Layer Project select OnlineSurvey in the Application Navigator, click on the Applications Menu on the right-hand side select the New Project... menu entry.
  • In the New Gallery select an Empty Project and click on OK.
  • In the Create Project window set the Project Name to ModelBC and click on the OK button.
  • Select the newly created ModelBC project in the Application Navigator and open the Project Properties window with a double-click.
  • In the Project Properties window, check the values of Project Content and make sure that the Default Package is set to demo.survey.model.bc. Click OK to close this window.
  • Expand the Application Resources accordion, expand the Connections folderm andexpand the Database folder, select the survey entry and open the Context Menu. From it select the Properties... entry to open the Edit Database Connection window. Check whether the Deploy Password check box is checked. If not, make sure that it is checked! ADF BC relies on it.

Step 2: Import Business Components from Tables

Select the ModelBC project in the Application Navigator. Open the New Gallery from the Context Menu -> New .... In the New Gallery expand the Business Tier and select ADF Business Components. On the right-hand side select Business Components From Tables and click on the OK button.

  • In the Initialize Business Components Project window select the survey connection and accept the default values for the SQL Flavor and Type Map (both should be Oracle). Click OK and the OK button on the Login window.
  • In the Create Business Components From Tables wizard step 1, click on the Query button to get all available tables. Once the table names appear, select all of them. Move all entries from Available to Selected, by clicking on the >> button. Like in the other model projects we change the names from plural to singular names. Best is to do it right now by selecting each line in the list and change the appearing value in the Entity Name text field, eg Answers to Answer.
  • Click Finish to end this wizard.

The wizard will now create the Entities and Association files in a single package. This is quite good at the first sight but really tedious if return to the project in three weeks. The naming for the Associations is hardly readable or memorable. Therefore we need to do two things:

  1. Move the Associations and the Entities in separate package.
  2. Rename the Associations with better readable names.

Move the files in separate packages is quite easy. Select all Entities, the ones without the Assoc suffix (Click on the file while holding the Ctrl-key). From the Context Menu select Refactor->Move... and type in the name demo.survey.model.bc.entities. After clicking on OK all files will be moved in the new package. You might be asked for creating the new package directory. This is perfectly OK. Repeat this for the Associations and move them into the package demo.survey.model.bc.links.

Renaming the Associations to better readable names is as simple as moving the files. Only difference is that must do it file by file. In the demo.survey.model.bc.links package we select an Association, open the Context Menu, select Refactor, select Rename..., enter the new name and click on OK. We repeat this for all entries in the package and rename them according to the table below.

Old Name New Name
AnswersResponsesFkAssoc AnswersPerResponse
ItemsQuestionsFkAssoc ItemsPerQuestion
QuestionsSurveyFkAssoc QuestionsPerSurvey
RepsonseSurveysFkAssoc ResponsesPerSurvey
SurveysAuthorsFkAssoc SurveysPerAuthor

The final step in JDeveloper 11g is click on the Save All button in the button bar to save all the modified files.

May 2, 2008

Available: JDeveloper 11 Technical Preview 4

In case you haven't noticed. JDeveloper 11g Technical Preview is available from OTN. SOA Suite 11g is also available but you need a Customer Support Identifier (CSI#) and a Metalink account to get the software. Anyway, right on time for JavaOne.

April 15, 2008

ADF in Action: Building the Model Layer with Oracle TopLink

Oracle TopLink

When looking around for O/R mapping frameworks, Oracle TopLink will appear as one of the most mature frameworks. Oracle TopLink builds high-performance applications that store persistent object-oriented data in a relational database. It successfully transforms object-oriented data into either relational data or Extensible Markup Language (XML) elements.

Entities

In TopLink Entities are defined as Plain Old Java Objects (POJOs) with additional files containing the mapping information. These files hold the meta data for the connection and mapping information.

Implementing the TopLink Model Layer

Similar to implementing the EJB Model Layer we're using the  existing Database Model as developed in the previous posts (see Setting up the Gear, Creating the Database, and Deploying the Database Model). Additionally you should make sure that your database is up and running and a Database Connection called survey configured. The steps in JDeveloper 10.1.3 and 11g are quite similar.
  1. Create a Model Layer Project
  2. Import TopLink Entities from Database Tables
  3. Check the generated files
  4. Create a Session Facade
  5. Create a Test Client

Steps for JDeveloper 10.1.3

Step 1: Create a Model Layer Project

  • To create a new Model Layer Project select OnlineSurvey in the Application Navigator, open the Context Menu and chose the New Project... menu entry.
  • In the New Gallery select an Empty Project and click on OK.
  • In the Create Project window set the Project Name to ModelTopLink and click on the OK button.
  • Select the newly created ModelTopLink project in the Application Navigator and open the Project Properties window with a double-click.
  • In the Project Properties window, check the values of Project Content and make sure that the Default Package is set to demo.survey.model.toplink. Click OK to close this window.

Step 2: Import TopLink Entities from Database Tables

Select the ModelTopLink project in the Application Navigator. Open the New Gallery from the Context Menu -> New .... In the New Gallery expand the Business Tier and select TopLink. On the right-hand side select Java Objects From Tables and click on the OK button.
  • In the Create Java Objects From Tables wizard step 1, select the survey connection and Oracle 10g for the Database Platform. For the TopLink Map, click on the New ... button (note the underscore under the first point of the elipses. Hard to read.). In the Create Object-Relational Map window set the TopLink Map Name to surveyMap and click on the OK button. This will create a new TopLink map. Click on Next to go to the Select Tables step.
  • In step 2 click on the Query button to get all available tables. Once the table names appear, select all of them. Move all entries from Available to Selected, by clicking on the >> button.
  • Click Next to go to wizard step 3. In step 3, General Options, accept the default value, the package name, and click Next to go to wizard step 4.
  • In step 4, Specify Object Details, we can change the names of the Java Classes from plural to singular. This is a bit cumbersome as we have to select the Table Name, change the Java Class name and so on. Add the end of this step we should have a singular Java Class name for every Table Name.
  • Click Next to go to the Summary and click on Finish to close the wizard. Now all six entities will be created.
You can find them in the Application Navigator under ModelTopLink->Application Sources->demo.survey.model.toplink. Also notice some additional files like sessions.xml and surveyMap under ModelTopLink->Application Sources->TopLink.

Step 3: Check the generated files

To check the generated files open them by selecting Answer.java, hold the Shift key, select Survey.java, and drag them into the working area right to Application Navigator. Every selected file will be opened in its own Code Editor. Select the tab named Answer.java to bring it to the front. You will see the completely generated code. This class has a small flaw, it is not Serializable, ie. you can not move it between two JVMs. We have to change the code to get the lines below:
import java.io.Serializable;

import oracle.toplink.indirection.ValueHolder;
import oracle.toplink.indirection.ValueHolderInterface;

public class Answer implements Serializable {
We do this by entering the implements Serializable part and let JDeveloper ask us to add the import statement via Alt-Enter. Be sure to select Serializable (java.io). This is the right package. We have to do this for every class, but rely on JDeveloper's support for knowing which import statement is the correct one for a specific piece of code:
  • Select the implements Serializable snippet (including the leading blank) and copy into the clipboard (Ctrl-C). Open Author.java. Point your text cursor right after the class name, hit Ctrl-V and you are done.
  • Repeat this for Item.java, Question.java, Response.java, and Survey.java.
  • Save your work.
Now is the right time to add the database sequences to the layer. This is not done automatically and must be configured in the TopLink configuration files sessions.xml and surveyMap.
  • In the Application Navigator select sessions.xml. In the Structure window, double-click on default to open the Mapping Editor for the sessions.xml.
  • Click on the Login tab and click on the Sequencing sub-tab. The information in the General sub-tab is good enough at the moment. In the Sequencing sub-tab we change the Use Native Sequencing to True. Also check the Preallocation Size check-box to make the number field editable. Change the value to 1 to make it work with the current database sequence increment.
  • Save your work.
  • Now click on the surveyMap.
  • In the Structure window expand demo.survey.model.toplink to get all available Java Classes in this map.
  • Double-click on the Answer mapping. This opens the Mapping Editor for the Answer class.
  • In the Descriptor Info tab check the Use Sequencing check-box. This makes this block editable.
  • The values for Table and Field are correct. Set the value for Name to SEQ_ANSWERS.
  • Now repeat setting of the database sequence for the classes Author, Item, Question, Response, and SurveySequencing Name to SEQ_AUTHORS, SEQ_ITEMS, SEQ_QUESTIONS, SEQ_RESPONSES, and SEQ_SURVEYS, respectively.
  • Save your work.

Step 4: Create a Session Facade

Click on ModelTopLink in the Application Navigator. Any other entry of the ModelTopLink project will do, also. Select New... from the Context Menu and navigate to Business Tier -> EJB in the New Gallery. On the right-hand side select Session Bean (EJB 1.1/2.x/3.0) and click on the OK button to open the 4 step Create Session Bean wizard.
  • In wizard step 1 change the EJB Name to SurveySession, accept the pre-selected defaults. Note that JDeveloper already recognized the Entity implementation as TopLink POJOs. Click on Next.
  • In wizard step 2 make sure that all methods are checked (expand the tree to see which methods are available). Click Next to go to the next wizard step.
  • Step 3 shows the default values for the bean class and step 4 - Click Next to go from step 3 to step 4 - shows the implemented interfaces. Remote and Local interfaces are good enough for our scenario.
  • Clicking Next in step 4 directs us to the wizard Summary window which we close by clicking on the Finish to go to the next wizard step.
A SurveySessionBean will be added to the project. Double-click on it and you'll see the generated Session Facade in the Code Editor.

Step 5: Create a Test Client

To finish the JDeveloper 10.1.3 tasks the creation of a test client needs to be done. Click on the SurveySessionBean in the Application Navigator and open the Context Menu. Find the New Sample Java Client entry and click on it. Accept all default values and click on the OK button to generate the test client. Open it and change the main method as follows:
    public static void main(String[] args) {
        try {
            final Context context = getInitialContext();
            SurveySession surveySession =
                (SurveySession)context.lookup("SurveySession");
            Author author = new Author();
            author.setName("Olaf Heimburger");
            surveySession.persistEntity(author);
for (Author a : surveySession.queryAuthorFindAll()) {
System.out.println("id = " + a.getId());
System.out.println("name = " + a.getName());
}
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
To test the Session Facade and the Test Client do the following:
  1. Select the SurveySessionBean, open the Context Menu and select Run. Wait until you see Oracle Containers for J2EE 10g (10.1.3.3.0)  initialized.
  2. Select the SurveySessionClient, open the Context Menu and select Run. You should get some output.

Steps for JDeveloper 11g

Step 1: Create a Model Layer Project

  • To create a new Model Layer Project select OnlineSurvey in the Application Navigator, click on the Applications Menu on the right-hand side select the New Project... menu entry.
  • In the New Gallery select an Empty Project and click on OK.
  • In the Create Project window set the Project Name to ModelTopLink and click on the OK button.
  • Select the newly created ModelTopLink project in the Application Navigator and open the Project Properties window with a double-click.
  • In the Project Source Paths window, check the values of Project Source Paths and make sure that the Default Package is set to demo.survey.model.toplink. Click OK to close this window.

Step 2: Import TopLink Entities from Database Tables

  • Select the ModelTopLink project in the Application Navigator.
  • Open the New Gallery from the Context Menu -> New ....
  • In the New Gallery expand the Business Tier and select TopLink/JPA. On the right-hand side select Java Objects From Tables and click on the OK button.
  • In the Create Java Objects From Tables wizard step 1, Select Object-Relational TopLink Map, click on the New ... button. In the New TopLink Object Map window set the TopLink Map Name to surveyMap. The window instantly complaints about the missing Offline Database setting.
  • Click on the New ... button to open the Create Offline Database window. For Name enter SURVEY, for Default Schema enter SURVEY as well. Database to emulate should be Oracle10g Express Edition Release 2. Click on the OK button to close this window.
  • Click on OK to close the New TopLink Object Map window.
  • Click on Next to go to the Select Tables step.
  • In this step click on the Query button to get all available tables. Once the table names appear, select all of them. Move all entries from Available to Selected, by clicking on the >> button.
  • Click Next to go to step, Specify Default Package. Accept the default value, the package name, and click Next to go to the next step.
  • In step Specify Object Details, we can change the names of the Java Classes from plural to singular. Here we have table with Table Name and Class Name columns. To edit the Class Name double-click in the Authors cell and change the name to Author. To finish this action click on the next cell.
  • Repeat this for every Class Name.
  • Click Next to go to the Specify Relationships to Generate.
  • Click Next to go to the Summary and click on Finish to close the wizard. Now all six entities will be created.You can find them in the Application Navigator under ModelTopLink->Application Sources->demo.survey.model.toplink. Also notice some additional files like sessions.xml and surveyMapModelTopLink->Application Sources->TopLink.

Step 3: Check the generated files

To check the generated files open them by selecting Answer.java, hold the Shift key, select Survey.java, and drag them into the working area right to Application Navigator. Every selected file will be opened in its own Code Editor. Select the tab named Answer.java to bring it to the front. You will see the completely generated code. Note that this class implements Serializable already!

Now is the right time to add the database sequences to the layer. This is not done automatically and must be configured in the TopLink configuration files sessions.xml and surveyMap.
  • In the Application Navigator select sessions.xml. In the Structure window, double-click on default to open the Mapping Editor for the sessions.xml.
  • Click on the Login tab and scroll down to the Sequencing section. Here select the Native Sequencing radio button. Also change the Preallocation Size to 1 to make it work with the current database sequence increment.
  • Save your work.
  • Now click on the surveyMap.
  • In the Structure window expand demo.survey.model.toplink to get all available Java Classes in this map.
  • Double-click on the Answer mapping. This opens the Mapping Editor for the Answer class.
  • In the Descriptor Info tab check the Use Sequencing check-box. This makes this block editable.
  • The values for Table and Field are correct. Set the value for Name to SEQ_ANSWERS.
  • Now repeat setting of the database sequence for the classes Author, Item, Question, Response, and SurveySequencing Name to SEQ_AUTHORS, SEQ_ITEMS, SEQ_QUESTIONS, SEQ_RESPONSES, and SEQ_SURVEYS, respectively.
  • Save your work.

Step 4: Create a Session Facade

Click on ModelTopLink in the Application Navigator. Any other entry of the ModelTopLink project will do, also. Select New... from the Context Menu and navigate to Business Tier -> EJB in the New Gallery. On the right-hand side select Session Bean and click on the OK button to open the Create Session Bean wizard.
  • In step Select EJB Version, accept the Enterprise JavaBeans 3.0 (Java EE 5.0) selection. Click Next to continue.
  • In step EJB Name and Queries change the EJB Name to SurveySession, accept the pre-selected defaults. Note that JDeveloper already recognized the Entity implementation as TopLink POJOs. Click on Next.
  • In step Session Facade - Select JPA Entity Methods make sure that all methods are checked (expand the tree to see which methods are available). Click Next to go to the next wizard step.
  • Step EJB Home and Component Interfaces shows the implemented interfaces. Remote and Local interfaces are good enough for our scenario.
  • Clicking Next directs us to the wizard Summary window which we close by clicking on the Finish to go to the next wizard step.
A SurveySessionBean will be added to the project. Double-click on it and you'll see the generated Session Facade in the Code Editor.

Step 5: Create a Test Client

To finish the JDeveloper 11g tasks the creation of a test client needs to be done. Click on the SurveySessionBean in the Application Navigator and open the Context Menu. Find the New Sample Java Client entry and click on it. Accept all default values, select the Connect to OC4J Embedded in JDeveloper and click on the OK button to generate the test client. Open it and change the main method as follows:
    public static void main(String[] args) {
        try {
            final Context context = getInitialContext();
            SurveySession surveySession =
                (SurveySession)context.lookup("SurveySession");
            Author author = new Author();
            author.setName("Olaf Heimburger 11g");
            surveySession.persistEntity(author);
for (Author a : surveySession.queryAuthorFindAll()) {
System.out.println("id = " + a.getId());
System.out.println("name = " + a.getName());
}
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
To test the Session Facade and the Test Client do the following:
  1. Select the SurveySessionBean, open the Context Menu and select Run. Wait until you see somethink like Embedded OC4J Server startup time: 83594 ms.
  2. Select the SurveySessionClient, open the Context Menu and select Run. You should get some output.

What have we done so far?

Essentially the same as for the EJB 3.0 Model Layer. The generation was quite similar but the setup of the sequencing was different. Configuration files vs. Annotations in the source code.

A Note on EclipseLink

EclipseLink is an open-sourced version of Oracle TopLink 11 and available from the Eclipse site.
EclipseLink is interesting because it will be the JPA 2.0 reference implementation and although not covered in this entry, I'll definitely give it a try.

References

Oracle TopLink Getting Started Guide
Oracle TopLink Developer's Guide


March 31, 2008

ADF in Action: Building the Model Layer with EJB 3

Enterprise Java Beans 3.0

Although named after the ill-fated Enterprise Java Beans standards up to 2.1, the latest version specifies many state-of-the-art technologies and leverages lessons learned from technologies like dependency injection, Hibernate's and TopLink's Entity and Session Management. EJB 3 implements Configuration by Exception, where default values apply as long as these are deduceable from provide information. This results in an easier to develop habit which very often uses a single file per bean including every definition needed.

EJB 3 Entities

To mark the change to earlier versions, EJB 3 removed the Bean from the term Entity Bean and uses Entity. Entities are not bound to the container anymore and can move between the different layers (Model to View to Model and so on) without a specific impact. As a result some design patterns of the EJB 2.x world are not fully applicable (eg. Data Transfer Objects) while others are a possible candidates for an update (eg. Data Access Object). EJB 3 Entities implement the Java Persistence API.

Java Persistence API

The authors of the Java Persistence API (JPA) have learned a lot from ORM frameworks like TopLink or Hibernate and other techniques. The JPA is much more complete then the previous EJB definitions in terms of attribute mapping, inheritance and the query language (JPA Query Language (JQL)).

Implementing the EJB 3 Model Layer

A very easy way to implement the EJB 3 Model Layer is by using the existing Database Model as developed in the previous posts (see Setting up the Gear, Creating the Database, and Deploying the Database Model). Additionally you should make sure that your database is up and running and a Database Connection called survey configured. The steps in JDeveloper 10.1.3 and 11g are quite similar.
  1. Create a Model Layer Project
  2. Import the EJB 3 from Database Tables
  3. Check the generated files
  4. Create a Session Facade
  5. Create a Test Client

Steps for JDeveloper 10.1.3

Step 1: Create a Model Layer Project

To create a new Model Layer Project select OnlineSurvey in the Application Navigator, open the Context Menu and chose the New Project... menu entry. In the New Gallery select an Empty Project and click on OK. In the Create Project window set the Project Name to ModelEJB30 and click on the OK button. Select the newly created ModelEJB30 project in the Application Navigator and open the Project Properties window with a double-click. In the Project Properties window, check the values of Project Content and make sure that the Default Package is set to demo.survey.model.ejb30. Click OK to close this window.

Step 2: Import the EJB 3 from Datbase Tables

Select the ModelEJB30 project in the Application Navigator. Open the New Gallery from the Context Menu -> New .... In the New Gallery expand the Business Tier and select EJB. On the right-hand side select Entities From Tables (JPA/EJB 3.0) and click on the OK button.
  • In the Create Entities From Tables wizard step 1 select the survey connection. Click on Next to get the database connection.
  • In step 2 click on the Query button to get all available tables. Since we only have tables the check box for Tables is sufficient. Once the table names appear, select all of them.
  • Move all entries from Available to Selected, by clicking on the >> button. Note that all names have changed to typical Java type names but in plural (eg. Answers (SURVEY.ANSWERS)). The values in parentheses tell you about the table relationship. Select every entry and see how the text field under the Selected list changes its value. Here we can change the names from plural to singular names. Change the names accordingly. You should have these names: Answer, Author, Item, Question, Response, Survey
  • Click Next to go to wizard step 3. In step 3 of the wizard accept the default values and click Next to go to wizard step 4.
  • This step can be used for changing the names as well, but is less user-friendly. Click Next to go to the Summary and click on Finish to close the wizard. Now all six entities will be created.
You can find them in the Application Navigator under ModelEJB30->Application Sources->demo.survey.model.ejb30.

Step 3: Check the generated files

To check the generated files open them by selecting Answer.java, hold the Shift key, select Survey.java, open the Context Menu and select Go To Bean Class. Every selected file will be opened in a Code Editor. Select the tab named Answer.java to bring it to the front. Change the code to get the lines below:
@Entity
@NamedQuery(name = "Answer.findAll", query = "select o from Answer o")
@SequenceGenerator(name = "SEQUENCE_ANSWERS", sequenceName = "SEQ_ANSWERS", allocationSize = 1)
@Table(name = "ANSWERS")
public class Answer implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQUENCE_ANSWERS")
    @Column(nullable = false)
    private Long id;

While adding this code, JDeveloper will suggest possible values and actions to be taken. Only import the types javax.persistence.SequenceGenerator, javax.persistence.GeneratedValue and javax.persistence.GenerationType. You should explore how the Ctrl-Blank short cut helps you to provide the correct annotation parameters.
Do the same for the other files Author.java, Item.java, Question.java, Response.java, Survey.java but use SEQ_AUTHORS with SEQUENCE_AUTHORS, SEQ_ITEMS with SEQUENCE_ITEMS, SEQ_QUESTIONS with SEQUENCE_QUESTIONS, SEQ_RESPONSES with SEQUENCE_RESPONSES, and SEQ_SURVEYS with SEQUENCE_SURVEYS.

Step 4: Create a Session Facade

Click on ModelEJB30 in the Application Navigator. Any other entry of the ModelEJB30 project will do, also. Select New... from the Context Menu and navigate to Business Tier -> EJB in the New Gallery. On the right-hand side select Session Bean (EJB 1.1/2.x/3.0) and click on the OK button to open the 4 step Create Session Bean wizard.
  • In wizard step 1 change the EJB Name to SurveySession, accept the pre-selected defaults and click on Next
  • In wizard step 2 make sure that all methods are checked (expand the tree to see which methods are available). Click Next to go to the next wizard step.
  • Step 3 shows the default values for the bean class and step 4 - Click Next to go from step 3 to step 4 - shows the implemented interfaces. Remote and Local interfaces are good enough for our scenario.
  • Clicking Next in step 4 directs us to the wizard Summary window which we close by clicking on the Finish to go to the next wizard step.
A SurveySessionBean will be added to the project. Double-click on it and you'll see the generated Session Facade in the Code Editor.

Step 5: Create a Test Client

To finish the JDeveloper 10.1.3 tasks the creation of a test client needs to be done. Click on the SurveySessionBean in the Application Navigator and open the Context Menu. Find the New Sample Java Client entry and click on it. Accept all default values and click on the OK button to generate the test client. Open it and change the main method as follows:
    public static void main(String[] args) {
        try {
            final Context context = getInitialContext();
            SurveySession surveySession =
                (SurveySession)context.lookup("SurveySession");
            Author author = new Author();
            author.setName("Olaf Heimburger");
            surveySession.persistEntity(author);
for (Author author :
(List<Author>)surveySession.queryAuthorFindAll()) {
System.out.println("id = " + author.getId());
System.out.println("name = " + author.getName());
}
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
To test the Session Facade and the Test Client do the following:
  1. Select the SurveySessionBean, open the Context Menu and select Run. Wait until you see Oracle Containers for J2EE 10g (10.1.3.3.0)  initialized.
  2. Select the SurveySessionClient, open the Context Menu and select Run. You should get some output.

Steps for JDeveloper 11g

Step 1: Create a Model Layer Project

To create a new Model Layer Project select OnlineSurvey in the Application Navigator, click on the Applications Menu on the right-hand side select the New Project... menu entry. In the New Gallery select an Empty Project and click on OK. In the Create Project window set the Project Name to ModelEJB30 and click on the OK button. Select the newly created ModelEJB30 project in the Application Navigator and open the Project Properties window with a double-click. In the Project Source Paths window, check the values of Project Source Paths and make sure that the Default Package is set to demo.survey.model.ejb30. Click OK to close this window.

Step 2: Import the EJB 3 from Datbase Tables

Select the ModelEJB30 project in the Application Navigator. Open the New Gallery from the Context Menu -> New .... In the New Gallery expand the Business Tier and select EJB. On the right-hand side select Entities From Tables and click on the OK button.
  • In the Create Entities From Tables wizard step 1 select EJB 3.0 - JPA Entities. Click on Next to select the Persistence Unit. Since we haven't created one yet, click on the New ... button. In the New Persistence Unit window set the Name to survey and the JTA Datasource Name to jdbc/surveyDS. Click OK to close the window. Click Next to go to the next step.
  • In step 3 make sure that the Online Database Connection radio button is checked. Click Next to go to the next step.
  • Step 4 lets you define the necessary details for the Database connection and the Offline Database. The Connection should be survey. If this is not available click on the green plus button to create a connection with survey as the Connection Name. For the Offline Database click on the New button and in the Create Offline Database window set the Name and Default Schema to SURVEY. From the Database to emulateOracle10g Express Edition Release 2. Click OK to close this window. Note that this is not really convenient as we did this in the Database project already. So far I didn't found a way to reuse the definitions from the Database project and hope for a dependency-like implementation in the future.
  • Click Next to go to step 5. Click on the Query button to get all available tables. Once the table names appear, select all of them. Move all entries from Available to Selected, by clicking on the >> button.
  • Click Next to go to wizard step 6. In this step accept the default values and click Next to go to wizard step 7. In step 7 we have to change the names from plural to singular names. From the drop-down list select one entry after another and remove the last letter s from the Entity Name.
    Do this carefully and slowly. In 11g TP 3 chances are that you do it to quick or go to far and you are not able to change anything afterwards. Only solution is start again with the whole wizard. I speak from experience.
  • Click on Next to go to the Summary step. Click on Finish to create all six entities.
You can find them in the Application Navigator under ModelEJB30->Application Sources->demo.survey.model.ejb30.
drop-down select

Step 3: Check the generated files

To check the generated files open them by selecting Answer.java, hold the Shift key, select Survey.java, open the Context Menu and select Go To Bean Class. Every selected file will be opened in the Code Editor. Select the tab named Answer.java to bring it to the front. Change the code to get the lines below:
@Entity
@NamedQuery(name = "Answer.findAll", query = "select o from Answer o")
@SequenceGenerator(name = "SEQUENCE_ANSWERS", sequenceName = "SEQ_ANSWERS", allocationSize = 1)
@Table(name = "ANSWERS")
public class Answer implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQUENCE_ANSWERS")
    @Column(nullable = false)
    private Long id;

While adding this code, JDeveloper will suggest possible values and actions to be taken. Only import the types javax.persistence.GenerationType. A big improvement is that the EJB 3 Annotations are already known by JDeveloper and do not require any additional action. You should explore how the Ctrl-Blank short cut helps you to provide the correct annotation parameters.
Do the same for the other files Author.java, Item.java, Question.java, Response.java, Survey.java but use SEQ_AUTHORS with SEQUENCE_AUTHORS, SEQ_ITEMS with SEQUENCE_ITEMS, SEQ_QUESTIONS with SEQUENCE_QUESTIONS, SEQ_RESPONSES with SEQUENCE_RESPONSES, and SEQ_SURVEYS with SEQUENCE_SURVEYS.

Step 4: Create a Session Facade

Click on ModelEJB30 in the Application Navigator. Any other entry of the ModelEJB30 project will do, also. Select New... from the Context Menu and navigate to Business Tier -> EJB in the New Gallery. On the right-hand side select Session Bean and click on the OK button to open a 6 step Create Session Bean wizard.
  • Since the EJB version is already known the wizard starts a step 2, by using the Back button you can go to step 1 but this is not needed.
  • In step 2 change the EJB Name to SurveySession, accept the pre-selected defaults and click on Next to go to the next wizard step.
  • In step 3 make sure that all methods are checked (expand the tree to see which methods are available). Click Next to go to the next wizard step.
  • Step 4 shows the default values for the bean class and Step 5 - Click Next to go from step 4 to step 5 - shows the implemented interfaces. Remote and Local interfaces are good enough for our scenario. Clicking Next in Step 5 directs us to the wizard Summary window which we close by clicking on the Finish button.
A SurveySessionBean will be added to the project. Double-click on it and you'll see the generated Session Facade in the Code Editor.

Step 5: Create a Test Client

To finish the JDeveloper 11g tasks, the creation of a test client needs to be done. Click on the SurveySessionBean in the Application Navigator and open the Context Menu. Find the New Sample Java Client entry and click on it. Accept all default values and click on the OK button to generate the test client. Open it and change the main method as follows:
    public static void main(String[] args) {
        try {
            final Context context = getInitialContext();
            SurveySession surveySession =
                (SurveySession)context.lookup("SurveySession");
            Author author = new Author();
            author.setName("Olaf Heimburger");
            surveySession.persistEntity(author);
for (Author author :
(List<Author>)surveySession.queryAuthorFindAll()) {
System.out.println("id = " + author.getId());
System.out.println("name = " + author.getName());
}
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
To test the Session Facade and the Test Client do the following:
  1. Select the SurveySessionBean, open the Context Menu and select Run. Wait until you see Embedded OC4J Server startup time: 83594 ms.
  2. Select the SurveySessionClient, open the Context Menu and select Run.

What Have We Done So Far?

First of all we have created a number of Entities for the Tables that we created in the Database project. Each Entity has it's own Sequence Generator assigned, using the @GeneratedValue annotation. Since we used the default SEQUENCE statement for the database, ie without an explicit INCREMENT option, we had to adjust the default allocationSize for JPA layer from 50 to 1 in the @SequenceGenerator annotation. Finally we created a Session Facade for persisting, retrieving and updating our Entities conveniently. The very last step was to test the Facade with the Author class.

References

  • EJB 3 in Action, Debu Panda, Reza Rahman, Derek Lane, Manning, ISBN 978-1-933988-34-4
  • Java Persistence with Hibernate, Christian Bauer, Gavin King, Manning, ISBN 1-932394-88-5

ADF in Action: The Model Layer

Application Layers

Modern computer applications are composed of several layers to make the different application tasks better manageable. The most prominent and widely used ... is the Model-View-Controller (MVC) Pattern. This pattern was introduced by the Smalltalk language. The MVC is one of the best understood and widely used implementation strategies. The same applies to most ADF applications and we will use it in this series as well.

The Model Layer

After having completed the database model, it is time to have some thoughts about the model layer. The model layer acts as the data holding layer. It arranges the data objects with their attributes and relationships. Methods for adding, deleting and modifying these objects are supplied. Very often this layer also supplies methods for retrieving and persisting the data.

Model Layer Choices

Oracle ADF supports many ways to implement the model layer. We will have a look at these three possible choices:
  • EJB 3.0 / Java Persistence API (JPA)
  • TopLink
  • ADF Business Components
Each of these choices deserves a separate coverage as they tend to be different in many ways.

General Considerations

Before we go into the details we have to consider some things:
  • Plural vs Singular Naming - Database designers use conventions different from Java designers. Most visible is the naming convention. While database designers use plural names, Java designers use singular names. The Model Layer should take care of that.
  • Using Existing Sequence Generators - To make the database model as useful as possible Oracle database designers often use Sequences for generating primary keys. This is particularly useful if more than one application accesses the database. The model layer should be able to use the existing Sequences.

March 11, 2008

ADF in Action: Content of the Database Project, Iteration 1

Online Survey Application, Database Project, Iteration 1

It is time to verify you are on the right track. Your database project should like mine. Here are the screenshots for both JDeveloper versions.

Database Project In JDeveloper 10.1.3

DB_01_10:

Database Project In JDeveloper 11g

DB_01_11:

March 7, 2008

ADF in Action: Deploying the Database Model

You may have noticed it, this is the missing step from the last post...

Deploying the Database

Once the database schema modeling is finished it needs to be deployed to the database. There are several options and a good database administrator (DBA) could improve the database behaviour considerably. Since this is not a DBA blog we leave this as an exercise to the reader.

Scripts to Create the Database User

In an Oracle Database a database user is the same as the schema user by default. It is also a good habit to create a tablespace for that user. First, we create a script for creating the tablespace:
  1. Click on the Offline Database Sources
  2. Open the Context Menu
  3. Select New ...
  4. Expand Database Tier
  5. Select Database Files
  6. On the right select SQL File
  7. Click the OK button
  8. In the opening Create SQL File window enter File Name: create_survey_tablespace.sql and make sure that the Directory Name has OnlineSurvey/Database/database (in JDeveloper 10.1.3) or OnlineSurvey/Database/database/SURVEY (in JDeveloper 11g) at the end.
  9. Click on the OK button to create an empty file.
  10. You will notice that the file appears right below the create_survey_schema.sql file in the Application Navigator.
  11. In the tab named create_survey_tablespace.sql enter the following line. You might need to change your file path!
    CREATE TABLESPACE survey datafile 'C:\oracle\xe\oradata\XEsurvey.dbf'
    SIZE 500k reuse autoextend ON;

  12. Repeat steps -10 to create a file called create_survey_user.sql. Put the following code in this file:
    DROP USER survey;
    CREATE USER survey IDENTIFIED BY survey DEFAULT TABLESPACE survey TEMPORARY
    TABLESPACE temp;
    GRANT connect,resource TO survey;

Running the SQL Files ...

All we need to do is to run the SQL files to complete the database deployment.

... In JDeveloper 10.1.3

Before we can do this, we need to check whether JDeveloper is configured to use SQL*Plus to execute the SQL scripts:
  1. Open Tools->Preferences
  2. Select Database Connections
  3. If the text field for SQL*Plus Executable is completed you're done, otherwise we have to point it to the right executable.
  4. Click on the Browse button
  5. In the new Open file dialog navigate to the $ORACLE_HOME directory for XE. In the $ORACLE_HOME/bin directory you'll find an executable named sqlplus.exe or sqlplus.
  6. Select sqlplus.exe and click on Open
  7. Once this is done, select the create_survey_tablespace.sql and from the Context Menu follow the Run in SQL to select the sysXE entry. This will open a terminal window for SQL*Plus. For security reasons the password of the sys database user has to be entered. When this is done the script will be run and creates the tablespace.
  8. Now do the same with the create_survey_user.sql.
To use this new user for later connections we create another Database Connection called surveyXE in the Connection Navigator (see ADF in Action: Setting up the Gear, Verifying the Database Connection for more details on this). With this connection we run the create_survey_schema.sql to create the full schema.

... In JDeveloper 11g

In 11g things are slightly different. We have Global Connections in the Resource Palette and Application-specific Connections in the Application Resources accordion.

To reuse the global database connection, we expand the sysXE database connection from the Resource Palette and drag it to the Application Resources Connections entry. (This is really cool!) It creates a Connections->Database->sysXE structure for the application also.

The rest is similar to JDeveloper 10.1.3. Just try it.

You should now have the Survey schema in your database. If not post a comment...


February 29, 2008

ADF In Action: Creating the Database

Huuh, creating a database? Why is that? I just want to display the data...

The Online Survey Application

Since there are so many types of web-based applications we just pick one as a sample to implement. The demo application we are building during this series is an Online Survey. The Online Survey has these requirements:
  • Have authors to create, update, and delete surveys.
  • A survey has a number of questions.
  • Each question may have a number of possible answers.
  • A question may be answered mandatory.
  • An answer of a question can be a text field, a single value from a multiple-choice list or multiple values from a multiple-choice list.
  • Each applicant has it's own list of answers.
  • The author can request reports of the answers per survey.

The Overall Project Structure

Before we start to create a data model according to the requirements above, we need to plan the project setup for a good project work. In JDeveloper we have the concept of an Application which consists of a number of Projects. No Project can be used outside of an Application. Applications and Projects are stored in different file types. When you examine your disk you will find a jws file for the Application and some jpr files for the Projects.
The structure of the Online Survey application will look like this
  • Online Survey Application
    • Database Project
    • Model Project
    • etc.

Creating the Project Structure

To create this structure in JDeveloper, just start your favorite version and follow the steps below.

In JDeveloper 10.1.3

  1. Select the Applications root in the Applications Navigator
  2. Open the Context Menu and select New Application ...
  3. The Create Application wizard opens
  4. Set the Application Name to OnlineSurvey.
  5. For the Application Package Prefix we chose demo.survey.
  6. As Application Template select the No Template [All Technologies] template.
  7. Click on the OK button to finish the wizard.
  8. Immediately after creating the application OnlineSurvey, JDeveloper opens the Create Project wizard for the first project in the application tree.
  9. Enter Database for the Database project.
  10. Click on the OK button to finish the wizard.

In JDeveloper 11g

  1. In the Application Navigator click on the New Application ... button.
  2. The Create Application wizard opens.
  3. Enter the Application Name as OnlineSurvey
  4. For the Application Package Prefix we chose demo.survey.
  5. As Application Template we select the No Template [All Technologies] template.
  6. Click on the OK button to finish the wizard.
  7. Immediately after creating the application OnlineSurvey, JDeveloper
    opens the Create Project wizard for the first project in the
    application tree.

  8. Enter Database for the Database project.

  9. Click on the OK button to finish the wizard.

We now have the first parts of our project structure created, let's continue with the database design.

The Data Model

The dynamic nature of the Online Survey suggests to store the configuration of each survey into a database.  The current status as well as the results of the survey need to be stored in the same database. According to the requirements above the following tables need to be created:
  • AUTHORS
  • SURVEYS
  • QUESTIONS
  • ITEMS
  • RESPONSES
  • ANSWERS
Each of these tables has an id column for a unique key (aka primary key). Some of them have foreign key relationships to other tables.

The Database Diagrammer

For better visualisation and understanding, building a diagram in the JDeveloper Database Diagrammer is a good approach for design and verification with others. Both versions of JDeveloper support the Database Diagrammer, so the next task is to create a diagram for the Online Survey application:
  1. In your OnlineSurvey application click on the Database project.
  2. From the Context Menu select New ... to open the New Gallery.
  3. In the New Gallery expand the General group in the Categories panel and select the Diagrams entry. In the Items area on the right all possible diagram types will be displayed.
  4. Select Database Diagram and click on the OK button to open the Create Database Diagram wizard.
  5. Enter Online Survey for the Name field, set the Package to demo.survey.db and click on the OK button to start the diagram creation.

JDeveloper 10.1.3 vs. 11g

Although the differences between 10.1.3 and 11g are minimal, you will notice them immediately. The obvious differences for the Database Diagrammer are in the Component Palette. First the ordering is a bit different and there are more components. With 11g it is now possible to differentiate between Public and Private Synonyms, create Materialized Views and Join Objects. A minor change is the different icon for the Foreign Key relationship.

Creating the Database Model

To create the database model for the Online Survey application, we use the Database Diagrammer for modelling all the tables and columns we can imagine so far. To do this we need to select the Table component from the Component Palette and move it to the diagram.

Tables In JDeveloper 10.1.3

JDeveloper 10.1.3 allows to create a number of Table components at once by holding the Shift key and clicking in the diagram area. This way we create six Table components. End this behaviour by selecting the Pointer component.

Tables In JDeveloper 11g

JDeveloper 11g behaves a bit differently here. It does not assume anything and when the first component is placed on the diagram area, an Offline Database wizard appears. Here the Offline Database can be selected or created.
  1. To create a new Offline Database click on the New... button and a Create Offline Database wizard window opens.
  2. Complete the Properties entry with Name: SURVEY and Default Schema: SURVEY.
  3. For Database to emulate select Oracle 10g Express Edition Release 2 from the drop down list.
  4. Click on the OK button to close the window.
  5. The SURVEY offline database will appear in the Offline Database drop down list.
  6. Click on the OK to close the Offline Database window.
Now five additional Table components can be added. Unlike JDeveloper 10.1.3 the Table component must be selected from Component Palette every time.

Both Versions

To change the name from the generic TABLEn to a real one simply click on on the name and use one of the following for the table component names: AUTHORS, SURVEYS, QUESTIONS, ITEMS, RESPONSES, and ANSWERS.
For every Table we have to add an ID column which acts as the primary key. As an example the Table AUTHORS will be used:

  1. Double click on the Table AUTHORS. The Edit Offline Table window opens with the Column Information selected.

  2. Clicking on the green plus creates a new column named COLUMN1.

  3. Since the name should be ID the name COLUMN1 has to be changed to ID.

  4. Now select the Type as NUMBER with a Precision of 38.

  5. Finally, the Cannot be NULL must be selected as this is the primary key with a known value.
  6. To make the ID the primary key, click on the Primary Key category, select the ID column and moved it to the select part ...

  7. Clicking on OK closes the window and the ID column appears in the AUTHORS Table component in the diagram area.

Do the same for the tables SURVEYS, QUESTIONS, ITEMS, RESPONSES, and ANSWERS.

Sequences

To generate a table specific number for every table we create six Sequences:

  1. Click on the Sequence component and move it to the diagram area. Do this six times.

  2. Rename the just created sequences to SEQ_AUTHORS, SEQ_SURVEYS, SEQ_QUESTIONS, SEQ_ITEMS, SEQ_RESPONSES, and SEQ_ANSWERS.

To leverage the Oracle Database default behaviour of an unbounded
sequence incrementing by 1 everything else could be left blank.

Foreign Key Relationships

To establish relationships between tables, Foreign Key Relationships need to be modeled. In the database diagrammer a Foreign Key Relationship has the semantics from One To Many, one row in a table has a relationship to many rows in another table. For the Online Survey model the following relationships need to be created:
  • One Author has Many Surveys (AUTHORS to SURVEYS)
  • One Survey has Many Questions (SURVEYS to QUESTIONS)
  • One Question has Many Items (QUESTIONS to ITEMS)
  • One Survey has Many Responses (SURVE