<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
   <title>Olaf Heimburger&apos;s Blog</title>
   <link rel="alternate" type="text/html" href="http://blogs.oracle.com/olaf/" />
   <link rel="self" type="application/atom+xml" href="http://blogs.oracle.com/olaf/xml/rss.xml" />
   <id>tag:blogs.oracle.com,2008:/olaf//78</id>
   <updated>2008-07-26T18:03:31Z</updated>
   <subtitle>Tips and Tricks for the Java SE, Java EE world</subtitle>
   <generator uri="http://www.sixapart.com/movabletype/">Movable Type Enterprise 1.52-en-voltron-r47459-20070213</generator>

<entry>
   <title>Book Review: Apache JMeter</title>
   <link rel="alternate" type="text/html" href="http://blogs.oracle.com/olaf/2008/07/book_review_apache_jmeter.html" />
   <id>tag:blogs.oracle.com,2008:/olaf//78.5543</id>
   
   <published>2008-07-26T18:53:12Z</published>
   <updated>2008-07-26T18:03:31Z</updated>
   
   <summary> 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...</summary>
   <author>
      <name>olaf.heimburger</name>
      
   </author>
   
   
   <content type="html" xml:lang="en" xml:base="http://blogs.oracle.com/olaf/">
      <![CDATA[
<p><em>Not necessarily part of the </em>ADF in Action<em> series, but we will see later how we can leverage the input from this book later...</em></p>
  <h2>Testing: The Missing Project Task  </h2>
  <p>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.</p>
  <h2>Apache JMeter: One of the Many Tools for the Trade</h2>
  <p>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&#160; that are implemented around SOAP, JMS, and HTTP. </p>
  <h2>The Author</h2>
  <p>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. </p>
  <h2>The Book</h2>
  <p>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.</p>
  <p>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 <em>Chapter 3 Installing Apache JMeter</em> is a quick and short one.</p>
  <p>Having finished these three chapters, you are ready for prime time. <em>Chapter 4, The Test Plan</em> 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 <em>Chapter 5, Load/Performance Testing of Website</em>s you learn how to do a load test efficiently and how to avoid penalties for Denial of Service attacks while testing. In the <em>Functional Testing</em> chapter you get ideas what parts are needed and how to combine them for the formal tests.</p>
  <p>If you think these three chapters are helpful for your next testing assignments you should also consider the <em>Advanced Features</em> 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.</p>
  <h2> Overall Impressions</h2>
  <p>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: <em>Apache JMeter: Advanced Techniques</em>. </p>
  <h2>Book Details</h2>
  <p> Emily H. Halili<br />
    <strong><a href="http://www.packtpub.com/beginning-apache-jmeter/book">Apache JMeter</a></strong><br />
    ISBN 978-1-847192-95-0
    <br />
    <a href="http://www.packtpub.com">Packt Publishing</a>    <br/>
  </p>
  ]]>
      
   </content>
</entry>
<entry>
   <title>ADF in Action: Building the Model Layer with ADF BC (BC4J)</title>
   <link rel="alternate" type="text/html" href="http://blogs.oracle.com/olaf/2008/07/adf_in_action_building_the_mod_2.html" />
   <id>tag:blogs.oracle.com,2008:/olaf//78.5242</id>
   
   <published>2008-07-08T18:28:04Z</published>
   <updated>2008-07-26T18:00:51Z</updated>
   
   <summary>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...</summary>
   <author>
      <name>olaf.heimburger</name>
      
   </author>
         <category term="ADF" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="en" xml:base="http://blogs.oracle.com/olaf/">
      <![CDATA[<em>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)...</em> 
        <h2>Oracle ADF Business Components</h2>
        <p>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. </p>
        <h3>Entities and Views and Application Modules </h3>
        <p>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.</p>
        <h3>Implementing the ADF BC Model Layer</h3>
        <p>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. <em>(As both approaches have their pros and cons, a seperate entry to show these is quite likely.)</em> Like before we're following the same order of steps for JDeveloper 10.1.3 and 11g:</p>
        <ul>
          <li>Create a Model Layer Project</li>
          <li>Import the Database Objects</li>
          </ul>
        <h3>Steps for JDeveloper 10.1.3</h3>
        <h4>Step 1: Create a Model Layer Project </h4>
        <ul>
          <li>To create a new Model Layer Project select <em>OnlineSurvey</em> in the <em>Application Navigator</em>, open the <em>Context Menu</em> and chose the <em>New Project...</em> menu entry.</li>
          <li>In the <em>New Gallery</em> select an <em>Empty Project</em> and click on <em>OK</em>.</li>
          <li>In the <em>Create Project</em> window set the <em>Project Name</em> to <em>ModelBC</em> and click on the <em>OK</em> button.</li>
          <li>Select the newly created <em>ModelBC</em> project in the <em>Application Navigator</em> and open the <em>Project Properties</em> window with a <em>double-click</em>.</li>
          <li>In the <em>Project Properties</em> window, check the values of <em>Project Content</em> and make sure that the <em>Default Package</em> is set to <em>demo.survey.model.bc</em>. Click <em>OK</em> to close this window.</li>
          <li>Click on the <em>Connections Navigator</em>. Expand the <em>Database</em> folder, select the <em>survey</em> entry and open the <em>Context Menu</em>. From it select the <em>Properties...</em> entry to open the <em>Edit Database Connection</em> window. Click on the <em>Authentication</em> tab and check whether the <em>Deploy Password</em> check box is checked. <strong><em>If not, make sure that it is checked!</em></strong> ADF BC relies on it. </li>
        </ul>
        <h4>Step 2: Import Business Components from Tables</h4>
        <p> Select the <em>ModelBC</em> project in the <em>Application Navigator</em>. Open the <em>New Gallery</em> from the <em>Context Menu -> New ...</em>. In the <em>New Gallery</em> expand the <em>Business Tier</em> and select  <em>ADF Business Components</em>. On the right-hand side select <em>Business Components  From Tables</em> and click on the <em>OK</em> button.<br />
</p>
        <ul>
          <li>In the <em>Initialize Business Components Project</em> window select the <em>survey</em> connection and accept the default values for the <em>SQL Flavor</em> and <em>Type Map</em> (both should be Oracle). Click <em>OK</em> and the <em>OK</em> button on the <em>Login</em> window. </li>
          <li>In the <em>Create Business Components From Tables</em> wizard step 1, click on the <em>Query</em> button to get all available tables. Once the table names appear, <em>select all of them</em>. Move all entries from <em>Available</em> to <em>Selected</em>, by clicking on the <em>>></em> button. Like in the other model projects we change the names from plural to singular names. <strong>Best is to do it right now</strong> by selecting each line in the list and change the appearing value in the <em>Entity Name</em> text field, eg <em>Answers</em> to <em>Answer</em>. </li>
          <li>Click Finish to end this wizard.</li>
          </ul>
        <p>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:</p>
        <ol>
          <li>Move the Associations and the Entities in separate package. </li>
          <li>Rename the Associations with better readable names.</li>
          </ol>
        <p><strong>Move the files in separate packages is quite easy</strong>. Select all Entities, the ones without the <em>Assoc</em> suffix (Click on the file while holding the <em>Ctrl</em>-key). From the <em>Context Menu</em> select <em>Refactor</em>-><em>Move...</em> and type in the name <em>demo.survey.model.bc.entities</em>. After clicking on <em>OK</em> all files will be moved in the new package. You might be asked for creating the new package directory. This is perfectly <em>OK</em>. Repeat this for the Associations and move them into the package <em>demo.survey.model.bc.links</em>. </p>
        <blockquote>
          <p><em><strong><font color="#FF0000">Warning!</font></strong><font color="#FF0000"> 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.</font> </em></p>
        </blockquote>
        <p><strong>Renaming the Associations to better readable names</strong> is as simple as moving the files. Only difference is that must do it file by file. In the <em>demo.survey.model.bc.links</em> package we select an <em>Association</em>, open the <em>Context Menu</em>, select <em>Refactor</em>, select <em>Rename...</em>, enter the new name and click on <em>OK</em>. We repeat this for all entries in the package and rename them according to the table below.</p>
        <table width="204" border="1" cellpadding="5" cellspacing="0" bordercolor="#CCCCCC">
          <tr valign="top">
            <th align="default" valign="top" scope="col">Old Name </th>
            <th align="default" valign="top" scope="col">New Name </th>
          </tr>
          <tr valign="top">
            <td align="default" valign="top">AnswersResponsesFKAssoc</td>
            <td align="default" valign="top">AnswersPerResponse</td>
          </tr>
          <tr valign="top">
            <td align="default" valign="top">ItemsQuestionsFKAssoc</td>
            <td align="default" valign="top">ItemsPerQuestion</td>
          </tr>
          <tr valign="top">
            <td align="default" valign="top">QuestionsSurveyFKAssoc</td>
            <td align="default" valign="top">QuestionsPerSurvey</td>
          </tr>
          <tr valign="top">
            <td align="default" valign="top">RepsonseSurveysFKAssoc</td>
            <td align="default" valign="top">ResponsesPerSurvey</td>
          </tr>
          <tr valign="top">
            <td align="default" valign="top">SurveysAuthorsFKAssoc</td>
            <td align="default" valign="top">SurveysPerAuthor</td>
          </tr>
        </table>
        <h3>Steps for JDeveloper 11g</h3>
        <blockquote>
          <p><em><strong>Note:</strong> 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.</em> </p>
        </blockquote>
        <h4>Step 1: Create a Model Layer Project </h4>
        <ul>
          <li> To create a new Model Layer Project select <em>OnlineSurvey</em> in the <em>Application Navigato</em>r, click on the <em>Applications Menu</em> on the right-hand side select the <em>New  Project...</em> menu entry.</li>
          <li>In the <em>New Gallery</em> select an <em>Empty Project</em> and  click on <em>OK</em>.</li>
          <li>In the <em>Create Project</em> window set the <em>Project Name</em> to <em>ModelBC</em> and click on the <em>OK</em> button.</li>
          <li>Select the newly created <em>ModelBC</em> project in the <em>Application Navigator</em> and open the <em>Project Properties</em> window with a <em>double-click</em>.</li>
          <li>In the <em>Project Properties</em> window, check the values of <em>Project Content</em> and make sure that the <em>Default Package</em> is set to <em>demo.survey.model.bc</em>. Click <em>OK</em> to close this window.</li>
          <li>Expand the Application Resources accordion, expand the Connections folderm andexpand the <em>Database</em> folder, select the <em>survey</em> entry and open the <em>Context Menu</em>. From it select the <em>Properties...</em> entry to open the <em>Edit Database Connection</em> window. Check whether the <em>Deploy Password</em> check box is checked. <strong><em>If not, make sure that it is checked!</em></strong> ADF BC relies on it. </li>
        </ul>
        <h4>Step 2: Import Business Components from Tables</h4>
        <p> Select the <em>ModelBC</em> project in the <em>Application Navigator</em>. Open the <em>New Gallery</em> from the <em>Context Menu -> New ...</em>. In the <em>New Gallery</em> expand the <em>Business Tier</em> and select <em>ADF Business Components</em>. On the right-hand side select <em>Business Components  From Tables</em> and click on the <em>OK</em> button.<br />
        </p>
        <ul>
          <li>In the <em>Initialize Business Components Project</em> window select the <em>survey</em> connection and accept the default values for the <em>SQL Flavor</em> and <em>Type Map</em> (both should be Oracle). Click <em>OK</em> and the <em>OK</em> button on the <em>Login</em> window. </li>
          <li>In the <em>Create Business Components From Tables</em> wizard step 1, click on the <em>Query</em> button to get all available tables. Once the table names appear, <em>select all of them</em>. Move all entries from <em>Available</em> to <em>Selected</em>, by clicking on the <em>>></em> button. Like in the other model projects we change the names from plural to singular names. <strong>Best is to do it right now</strong> by selecting each line in the list and change the appearing value in the <em>Entity Name</em> text field, eg <em>Answers</em> to <em>Answer</em>. </li>
          <li>Click Finish to end this wizard.</li>
        </ul>
        <p>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:</p>
        <ol>
          <li>Move the Associations and the Entities in separate package. </li>
          <li>Rename the Associations with better readable names.</li>
        </ol>
        <p><strong>Move the files in separate packages is quite easy</strong>. Select all Entities, the ones without the <em>Assoc</em> suffix (Click on the file while holding the <em>Ctrl</em>-key). From the <em>Context Menu</em> select <em>Refactor</em>-><em>Move...</em> and type in the name <em>demo.survey.model.bc.entities</em>. After clicking on <em>OK</em> all files will be moved in the new package. You might be asked for creating the new package directory. This is perfectly <em>OK</em>. Repeat this for the Associations and move them into the package <em>demo.survey.model.bc.links</em>. </p>
        <p><strong>Renaming the Associations to better readable names</strong> is as simple as moving the files. Only difference is that must do it file by file. In the <em>demo.survey.model.bc.links</em> package we select an <em>Association</em>, open the <em>Context Menu</em>, select <em>Refactor</em>, select <em>Rename...</em>, enter the new name and click on <em>OK</em>. We repeat this for all entries in the package and rename them according to the table below.</p>
        <table width="204" border="1" cellpadding="5" cellspacing="0" bordercolor="#CCCCCC">
          <tr valign="top">
            <th align="default" valign="top" scope="col">Old Name </th>
            <th align="default" valign="top" scope="col">New Name </th>
          </tr>
          <tr valign="top">
            <td align="default" valign="top">AnswersResponsesFkAssoc</td>
            <td align="default" valign="top">AnswersPerResponse</td>
          </tr>
          <tr valign="top">
            <td align="default" valign="top">ItemsQuestionsFkAssoc</td>
            <td align="default" valign="top">ItemsPerQuestion</td>
          </tr>
          <tr valign="top">
            <td align="default" valign="top">QuestionsSurveyFkAssoc</td>
            <td align="default" valign="top">QuestionsPerSurvey</td>
          </tr>
          <tr valign="top">
            <td align="default" valign="top">RepsonseSurveysFkAssoc</td>
            <td align="default" valign="top">ResponsesPerSurvey</td>
          </tr>
          <tr valign="top">
            <td align="default" valign="top">SurveysAuthorsFkAssoc</td>
            <td align="default" valign="top">SurveysPerAuthor</td>
          </tr>
        </table>
        <p>The final step in JDeveloper 11g is click on the <em>Save All</em> button in the button bar to save all the modified files. </p>
]]>
      
   </content>
</entry>
<entry>
   <title>Available: JDeveloper 11 Technical Preview 4</title>
   <link rel="alternate" type="text/html" href="http://blogs.oracle.com/olaf/2008/05/available_jdeveloper_11_techni.html" />
   <id>tag:blogs.oracle.com,2008:/olaf//78.574</id>
   
   <published>2008-05-02T07:06:18Z</published>
   <updated>2008-06-24T00:35:58Z</updated>
   
   <summary>In case you haven&apos;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...</summary>
   <author>
      <name>olaf.heimburger</name>
      
   </author>
   
   
   <content type="html" xml:lang="en" xml:base="http://blogs.oracle.com/olaf/">
      <![CDATA[<p>In case you haven't noticed. JDeveloper 11g Technical Preview is available from <a href="http://www.oracle.com/technology/products/jdev/11/index.html">OTN</a>. SOA Suite 11g is also available but you need a Customer Support Identifier (CSI#) and a <a href="http://metalink.oracle.com">Metalink</a> account to get the software. Anyway, right on time for JavaOne.<br></p>]]>
      
   </content>
</entry>
<entry>
   <title>ADF in Action: Building the Model Layer with Oracle TopLink</title>
   <link rel="alternate" type="text/html" href="http://blogs.oracle.com/olaf/2008/04/adf_in_action_building_the_mod.html" />
   <id>tag:blogs.oracle.com,2008:/olaf//78.578</id>
   
   <published>2008-04-15T14:36:34Z</published>
   <updated>2008-06-24T00:35:59Z</updated>
   
   <summary>Oracle TopLinkWhen 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...</summary>
   <author>
      <name>olaf.heimburger</name>
      
   </author>
         <category term="ADF" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="en" xml:base="http://blogs.oracle.com/olaf/">
      <![CDATA[<h3>Oracle TopLink</h3>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.<br><h3>Entities</h3>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.<br><h3>Implementing the TopLink Model Layer</h3>Similar to implementing the EJB Model Layer we're using the&nbsp;
existing Database Model as developed in the previous posts (see <a href="http://blogs.oracle.com/olaf/2008/01/26">Setting up the Gear</a>, <a href="http://blogs.oracle.com/olaf/2008/02/29">Creating the Database</a>, and <a href="http://blogs.oracle.com/olaf/2008/03/07">Deploying the Database Model</a>). Additionally you should make sure that your database is up and running and a <span style="font-style: italic;">Database Connection</span> called <span style="font-style: italic;">survey</span> configured. The steps in JDeveloper 10.1.3 and 11g are quite similar.<br><ol><li>Create a Model Layer Project</li><li>Import TopLink Entities from Database Tables</li><li>Check the generated files</li><li>Create a Session Facade</li><li>Create a Test Client</li></ol><h3>Steps for JDeveloper 10.1.3</h3><h4>Step 1: Create a Model Layer Project</h4><ul><li>To create a new Model Layer Project select <span style="font-style: italic;">OnlineSurvey</span> in the <span style="font-style: italic;">Application Navigator</span>, open the <span style="font-style: italic;">Context Menu</span> and chose the <span style="font-style: italic;">New Project...</span> menu entry.</li><li>In the <span style="font-style: italic;">New Gallery</span> select an <span style="font-style: italic;">Empty Project</span> and click on <span style="font-style: italic;">OK</span>.</li><li>In the <span style="font-style: italic;">Create Project</span> window set the <span style="font-style: italic;">Project Name</span> to <span style="font-style: italic;">ModelTopLink</span> and click on the <span style="font-style: italic;">OK</span> button.</li><li>Select the newly created <span style="font-style: italic;">ModelTopLink</span> project in the <span style="font-style: italic;">Application Navigator</span> and open the <span style="font-style: italic;">Project Properties</span> window with a <span style="font-style: italic;">double-click</span>.</li><li>In the <span style="font-style: italic;">Project Properties</span> window, check the values of <span style="font-style: italic;">Project Content</span> and make sure that the <span style="font-style: italic;">Default Package</span> is set to <span style="font-style: italic;">demo.survey.model.toplink</span>. Click <span style="font-style: italic;">OK</span> to close this window.</li></ul><h4>Step 2: Import TopLink Entities from Database Tables</h4>Select the <span style="font-style: italic;">ModelTopLink</span> project in the <span style="font-style: italic;">Application Navigator</span>. Open the <span style="font-style: italic;">New Gallery</span> from the <span style="font-style: italic;">Context Menu -&gt; New ...</span>. In the <span style="font-style: italic;">New Gallery</span> expand the <span style="font-style: italic;">Business Tier</span> and select <span style="font-style: italic;">TopLink</span>. On the right-hand side select <span style="font-style: italic;">Java Objects From Tables</span> and click on the <span style="font-style: italic;">OK</span> button.<br><ul><li>In the <span style="font-style: italic;">Create Java Objects From Tables</span> wizard step 1, select the <span style="font-style: italic;">survey</span> connection and <span style="font-style: italic;">Oracle 10g</span> for the <span style="font-style: italic;">Database Platform</span>. For the <span style="font-style: italic;">TopLink Map</span>, click on the <span style="font-style: italic;">New </span><span style="text-decoration: underline; font-style: italic;">.</span><span style="font-style: italic;">..</span> button (note the underscore under the first point of the elipses. Hard to read.). In the <span style="font-style: italic;">Create Object-Relational Map</span> window set the <span style="font-style: italic;">TopLink Map Name</span> to <span style="font-style: italic;">surveyMap</span> and click on the <span style="font-style: italic;">OK</span> button. This will create a new TopLink map. Click on <span style="font-style: italic;">Next</span> to go to the <span style="font-style: italic;">Select Tables</span> step.</li><li>In step 2 click on the <span style="font-style: italic;">Query</span>
button to get all available tables. Once the table names appear, <span style="font-style: italic;">select all of them</span>. Move all entries from <span style="font-style: italic;">Available</span> to <span style="font-style: italic;">Selected</span>, by clicking on the <span style="font-style: italic;">&gt;&gt;</span> button.</li><li>Click <span style="font-style: italic;">Next</span> to go to wizard step 3. In step 3, <span style="font-style: italic;">General Options,</span> <span style="font-style: italic;">accept</span> the default value, the package name, and click <span style="font-style: italic;">Next</span> to go to wizard step 4.</li><li>In step 4, <span style="font-style: italic;">Specify Object Details</span>, we can change the names of the Java Classes from plural to singular. This is a bit cumbersome as we have to select the <span style="font-style: italic;">Table Name</span>, change the <span style="font-style: italic;">Java Class</span> name and so on. Add the end of this step we should have a singular Java Class name for every Table Name.<br></li><li>Click <span style="font-style: italic;">Next</span> to go to the <span style="font-style: italic;">Summary</span> and click on <span style="font-style: italic;">Finish</span> to close the wizard. Now all six entities will be created.</li></ul>You can find them in the <span style="font-style: italic;">Application Navigator</span> under <span style="font-style: italic;">ModelTopLink-&gt;Application Sources-&gt;demo.survey.model.toplink</span>. Also notice some additional files like <span style="font-style: italic;">sessions.xml</span> and <span style="font-style: italic;">surveyMap</span> under <span style="font-style: italic;">ModelTopLink</span>-&gt;<span style="font-style: italic;">Application Sources</span>-&gt;<span style="font-style: italic;">TopLink</span>.<br><h4>Step 3: Check the generated files</h4>To check the generated files open them by selecting <span style="font-style: italic;">Answer.java</span>, <span style="font-style: italic;">hold </span>the <span style="font-style: italic;">Shift key</span>, select <span style="font-style: italic;">Survey.java</span>, and <span style="font-style: italic;">drag them</span> into the working area right to <span style="font-style: italic;">Application Navigator</span>. Every selected file will be opened in its own <span style="font-style: italic;">Code Editor</span>. Select the tab named <span style="font-style: italic;">Answer.java</span> to bring it to the front. You will see the completely generated code. This class has a small flaw, it is not <span style="font-style: italic;">Serializable</span>, ie. you can not move it between two JVMs. We have to change the code to get the lines below:<br><pre style="background-color: rgb(204, 204, 204);"><span style="font-weight: bold;">import java.io.Serializable;</span><br><br>import oracle.toplink.indirection.ValueHolder;<br>import oracle.toplink.indirection.ValueHolderInterface;<br><br>public class Answer <span style="font-weight: bold;">implements Serializable</span> {</pre>We do this by entering the<span style="font-style: italic;"> implements Serializable</span> part and let JDeveloper ask us to add the import statement via <span style="font-style: italic;">Alt-Enter</span>. Be sure to select <span style="font-style: italic;">Serializable (java.io)</span>. 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:<br><ul><li>Select the<span style="font-style: italic;"> implements Serializable</span> snippet (including the <span style="font-style: italic;">leading </span>blank) and copy into the clipboard (<span style="font-style: italic;">Ctrl-C</span>). Open <span style="font-style: italic;">Author.java</span>. Point your text cursor right after the class name, hit <span style="font-style: italic;">Ctrl-V</span> and you are done.</li><li>Repeat this for <span style="font-style: italic;">Item.java</span>, <span style="font-style: italic;">Question.java</span>, <span style="font-style: italic;">Response.java</span>, and <span style="font-style: italic;">Survey.java</span>.</li><li>Save your work.</li></ul>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 <span style="font-style: italic;">sessions.xml</span> and <span style="font-style: italic;">surveyMap</span>.<br><ul><li>In the <span style="font-style: italic;">Application Navigator</span> select <span style="font-style: italic;">sessions.xml</span>. In the <span style="font-style: italic;">Structure</span> window, <span style="font-style: italic;">double-click</span> on <span style="font-style: italic;">default </span>to open the <span style="font-style: italic;">Mapping Editor</span> for the <span style="font-style: italic;">sessions.xml</span>.</li><li>Click on the <span style="font-style: italic;">Login</span> tab and click on the <span style="font-style: italic;">Sequencing</span> sub-tab. The information in the <span style="font-style: italic;">General</span> sub-tab is good enough at the moment. In the <span style="font-style: italic;">Sequencing</span> sub-tab we change the <span style="font-style: italic;">Use Native Sequencing</span> to <span style="font-style: italic;">True</span>. Also check the <span style="font-style: italic;">Preallocation Size</span> check-box to make the number field <span style="font-style: italic;">editable</span>. Change the value to <span style="font-style: italic;">1</span> to make it work with the current database sequence increment.</li><li>Save your work.</li><li>Now click on the <span style="font-style: italic;">surveyMap</span>.</li><li>In the <span style="font-style: italic;">Structure</span> window expand <span style="font-style: italic;">demo.survey.model.toplink</span> to get all available Java Classes in this map.</li><li>Double-click on the <span style="font-style: italic;">Answer</span> mapping. This opens the <span style="font-style: italic;">Mapping Editor</span> for the Answer class.</li><li>In the <span style="font-style: italic;">Descriptor Info</span> tab check the <span style="font-style: italic;">Use Sequencing</span> check-box. This makes this block editable.</li><li>The values for <span style="font-style: italic;">Table</span> and <span style="font-style: italic;">Field</span> are correct. Set the value for <span style="font-style: italic;">Name</span> to <span style="font-style: italic;">SEQ_ANSWERS</span>.</li><li>Now repeat setting of the database sequence for the classes <span style="font-style: italic;">Author</span>, <span style="font-style: italic;">Item</span>, <span style="font-style: italic;">Question</span>, <span style="font-style: italic;">Response</span>, and <span style="font-style: italic;">Survey</span><span style="font-style: italic;">Sequencing Name</span> to <span style="font-style: italic;">SEQ_AUTHORS</span>, <span style="font-style: italic;">SEQ_ITEMS</span>, <span style="font-style: italic;">SEQ_QUESTIONS</span>, <span style="font-style: italic;">SEQ_RESPONSES</span>, and <span style="font-style: italic;">SEQ_SURVEYS</span>, respectively.</li><li>Save your work.</li></ul><h4> Step 4: Create a Session Facade</h4>Click on <span style="font-style: italic;">ModelTopLink</span> in the <span style="font-style: italic;">Application Navigator</span>. Any other entry of the <span style="font-style: italic;">ModelTopLink</span> project will do, also. Select <span style="font-style: italic;">New...</span> from the <span style="font-style: italic;">Context Menu</span> and navigate to <span style="font-style: italic;">Business Tier -&gt; EJB</span> in the <span style="font-style: italic;">New Gallery</span>. On the right-hand side select <span style="font-style: italic;">Session Bean (EJB 1.1/2.x/3.0)</span> and click on the <span style="font-style: italic;">OK</span> button to open the 4 step <span style="font-style: italic;">Create Session Bean</span> wizard.<br><ul><li>In wizard step 1 change the <span style="font-style: italic;">EJB Name</span> to <span style="font-style: italic;">SurveySession</span>, accept the pre-selected defaults. Note that JDeveloper already recognized the Entity implementation as TopLink POJOs. Click on <span style="font-style: italic;">Next. <br></span></li><li>In wizard step 2 make sure that all methods are checked (expand the tree to see which methods are available). Click <span style="font-style: italic;">Next</span> to go to the next wizard step.</li><li>Step 3 shows the default values for the bean class and step 4 - Click <span style="font-style: italic;">Next</span> to go from step 3 to step 4 - shows the implemented interfaces. <span style="font-style: italic;">Remote</span> and <span style="font-style: italic;">Local </span>interfaces are good enough for our scenario.</li><li>Clicking <span style="font-style: italic;">Next</span> in step 4 directs us to the wizard Summary window which we close by clicking on the <span style="font-style: italic;">Finish</span> to go to the next wizard step.<br></li></ul>A <span style="font-style: italic;">SurveySessionBean</span> will be added to the project. Double-click on it and you'll see the generated Session Facade in the <span style="font-style: italic;">Code Editor</span>.<br><h4>Step 5: Create a Test Client</h4>To finish the JDeveloper 10.1.3 tasks the creation of a test client needs to be done. Click on the <span style="font-style: italic;">SurveySessionBean</span> in the <span style="font-style: italic;">Application Navigator</span> and open the <span style="font-style: italic;">Context Menu</span>. Find the <span style="font-style: italic;">New Sample Java Client</span> entry and click on it. Accept all default values and click on the <span style="font-style: italic;">OK</span> button to generate the test client. Open it and change the main method as follows:<br><pre style="background-color: rgb(204, 204, 204);">&nbsp;&nbsp;&nbsp; public static void main(String[] args) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; final Context context = getInitialContext();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SurveySession surveySession = <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (SurveySession)context.lookup("SurveySession");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Author author = new Author();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; author.setName("Olaf Heimburger");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; surveySession.persistEntity(author);<br>            for (Author a : surveySession.queryAuthorFindAll()) {<br>                System.out.println("id = " + a.getId());<br>                System.out.println("name = " + a.getName());<br>            }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch (Exception ex) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ex.printStackTrace();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }</pre>To test the Session Facade and the Test Client do the following:<br><ol><li>Select the <span style="font-style: italic;">SurveySessionBean</span>, open the <span style="font-style: italic;">Context Menu</span> and select <span style="font-style: italic;">Run</span>. Wait until you see <span style="font-style: italic;">Oracle Containers for J2EE 10g (10.1.3.3.0)&nbsp; initialized</span>.</li><li>Select the <span style="font-style: italic;">SurveySessionClient</span>, open the <span style="font-style: italic;">Context Menu</span> and select <span style="font-style: italic;">Run</span>. You should get some output.</li></ol><h3>Steps for JDeveloper 11g</h3><h4>Step 1: Create a Model Layer Project</h4>
<ul><li>
To create a new Model Layer Project select <span style="font-style: italic;">OnlineSurvey</span> in the
<span style="font-style: italic;">Application Navigato</span>r, click on the <span style="font-style: italic;">Applications Menu</span> on the right-hand side select the <span style="font-style: italic;">New
Project...</span> menu entry.</li><li>In the <span style="font-style: italic;">New Gallery</span> select an <span style="font-style: italic;">Empty Project</span> and
click on <span style="font-style: italic;">OK</span>.</li><li>In the <span style="font-style: italic;">Create Project</span> window set the <span style="font-style: italic;">Project Name</span> to
<span style="font-style: italic;">ModelTopLink</span> and click on the <span style="font-style: italic;">OK</span> button.</li><li>Select the newly created
<span style="font-style: italic;">ModelTopLink</span> project in the <span style="font-style: italic;">Application Navigator</span> and open the <span style="font-style: italic;">Project
Properties</span> window with a double-click.</li><li>In the <span style="font-style: italic;">Project Source Paths</span>
window, check the values of <span style="font-style: italic;">Project Source Paths</span> and make sure that the
<span style="font-style: italic;">Default Package</span> is set to <span style="font-style: italic;">demo.survey.model.toplink</span>. Click <span style="font-style: italic;">OK</span> to close
this window.</li></ul>
<h4>Step 2: Import TopLink Entities from Database Tables</h4><ul><li>
Select the <span style="font-style: italic;">ModelTopLink</span> project in the <span style="font-style: italic;">Application Navigator</span>.</li><li>Open the <span style="font-style: italic;">New Gallery</span> from the <span style="font-style: italic;">Context Menu -&gt; New ...</span>.</li><li>In the <span style="font-style: italic;">New Gallery</span> expand the <span style="font-style: italic;">Business Tier</span> and select <span style="font-style: italic;">TopLink/JPA</span>. On the right-hand side select <span style="font-style: italic;">Java Objects From Tables</span> and click on the <span style="font-style: italic;">OK</span> button.</li><li>In the <span style="font-style: italic;">Create Java Objects From Tables</span> wizard step 1, <span style="font-style: italic;">Select Object-Relational TopLink Map</span>, click on the <span style="font-style: italic;">New ...</span> button. In the <span style="font-style: italic;">New TopLink Object Map</span> window set the <span style="font-style: italic;">TopLink Map Name</span> to <span style="font-style: italic;">surveyMap</span>. The window instantly complaints about the missing <span style="font-style: italic;">Offline Database</span> setting.</li><li>Click on the <span style="font-style: italic;">New ...</span> button to open the <span style="font-style: italic;">Create Offline Database</span> window. For <span style="font-style: italic;">Name</span> enter <span style="font-style: italic;">SURVEY,</span> for <span style="font-style: italic;">Default Schema</span> enter <span style="font-style: italic;">SURVEY</span> as well. <span style="font-style: italic;">Database to emulate</span> should be <span style="font-style: italic;">Oracle10g Express Edition Release 2</span>. Click on the <span style="font-style: italic;">OK</span> button to close this window.</li><li>Click on <span style="font-style: italic;">OK</span> to close the <span style="font-style: italic;">New TopLink Object Map</span> window.</li><li>Click on <span style="font-style: italic;">Next</span> to go to the <span style="font-style: italic;">Select Tables</span> step.</li><li>In this step click on the <span style="font-style: italic;">Query</span>
button to get all available tables. Once the table names appear, <span style="font-style: italic;">select all of them</span>. Move all entries from <span style="font-style: italic;">Available</span> to <span style="font-style: italic;">Selected</span>, by clicking on the <span style="font-style: italic;">&gt;&gt;</span> button.</li><li>Click <span style="font-style: italic;">Next</span> to go to step, <span style="font-style: italic;">Specify Default Package.</span> <span style="font-style: italic;">Accept</span> the default value, the package name, and click <span style="font-style: italic;">Next</span> to go to the next step.</li><li>In step <span style="font-style: italic;">Specify Object Details</span>, we can change the names of the Java Classes from plural to singular. Here we have table with <span style="font-style: italic;">Table Name</span> and <span style="font-style: italic;">Class Name</span> columns. To edit the <span style="font-style: italic;">Class Name</span> double-click in the <span style="font-style: italic;">Authors</span> cell and change the name to <span style="font-style: italic;">Author</span>. To finish this action click on the next cell.</li><li>Repeat this for every <span style="font-style: italic;">Class Name</span>.</li><li>Click <span style="font-style: italic;">Next</span> to go to the <span style="font-style: italic;">Specify Relationships to Generate</span>.<br></li><li>Click <span style="font-style: italic;">Next</span> to go to the <span style="font-style: italic;">Summary</span> and click on <span style="font-style: italic;">Finish</span> to close the wizard. Now all six entities will be created.You can find them in the <span style="font-style: italic;">Application Navigator</span> under <span style="font-style: italic;">ModelTopLink-&gt;Application Sources-&gt;demo.survey.model.toplink</span>. Also notice some additional files like <span style="font-style: italic;">sessions.xml</span> and <span style="font-style: italic;">surveyMap</span><span style="font-style: italic;">ModelTopLink</span>-&gt;<span style="font-style: italic;">Application Sources</span>-&gt;<span style="font-style: italic;">TopLink</span>.</li></ul>  
<h4>Step 3: Check the generated files</h4>
To check the generated files open them by selecting <span style="font-style: italic;">Answer.java</span>, <span style="font-style: italic;">hold </span>the <span style="font-style: italic;">Shift key</span>, select <span style="font-style: italic;">Survey.java</span>, and <span style="font-style: italic;">drag them</span> into the working area right to <span style="font-style: italic;">Application Navigator</span>. Every selected file will be opened in its own <span style="font-style: italic;">Code Editor</span>. Select the tab named <span style="font-style: italic;">Answer.java</span> to bring it to the front. You will see the completely generated code. Note that this class <span style="font-weight: bold;">implements Serializable already</span>!<br><br>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 <span style="font-style: italic;">sessions.xml</span> and <span style="font-style: italic;">surveyMap</span>.<br>
<ul><li>In the <span style="font-style: italic;">Application Navigator</span> select <span style="font-style: italic;">sessions.xml</span>. In the <span style="font-style: italic;">Structure</span> window, <span style="font-style: italic;">double-click</span> on <span style="font-style: italic;">default </span>to open the <span style="font-style: italic;">Mapping Editor</span> for the <span style="font-style: italic;">sessions.xml</span>.</li><li>Click on the <span style="font-style: italic;"> Login</span> tab and scroll down to the <span style="font-style: italic;">Sequencing</span> section. Here select the<span style="font-style: italic;"> Native Sequencing</span> radio button<span style="font-style: italic;"></span>. Also change the <span style="font-style: italic;">Preallocation Size</span> to <span style="font-style: italic;">1</span> to make it work with the current database sequence increment.</li><li>Save your work.</li><li>Now click on the <span style="font-style: italic;">surveyMap</span>.</li><li>In the <span style="font-style: italic;">Structure</span> window expand <span style="font-style: italic;">demo.survey.model.toplink</span> to get all available Java Classes in this map.</li><li>Double-click on the <span style="font-style: italic;">Answer</span> mapping. This opens the <span style="font-style: italic;">Mapping Editor</span> for the Answer class.</li><li>In the <span style="font-style: italic;">Descriptor Info</span> tab check the <span style="font-style: italic;">Use Sequencing</span> check-box. This makes this block editable.</li><li>The values for <span style="font-style: italic;">Table</span> and <span style="font-style: italic;">Field</span> are correct. Set the value for <span style="font-style: italic;">Name</span> to <span style="font-style: italic;">SEQ_ANSWERS</span>.</li><li>Now repeat setting of the database sequence for the classes <span style="font-style: italic;">Author</span>, <span style="font-style: italic;">Item</span>, <span style="font-style: italic;">Question</span>, <span style="font-style: italic;">Response</span>, and <span style="font-style: italic;">Survey</span><span style="font-style: italic;">Sequencing Name</span> to <span style="font-style: italic;">SEQ_AUTHORS</span>, <span style="font-style: italic;">SEQ_ITEMS</span>, <span style="font-style: italic;">SEQ_QUESTIONS</span>, <span style="font-style: italic;">SEQ_RESPONSES</span>, and <span style="font-style: italic;">SEQ_SURVEYS</span>, respectively.</li><li>Save your work.</li></ul>
<h4> Step 4: Create a Session Facade</h4>
Click on <span style="font-style: italic;">ModelTopLink</span> in the <span style="font-style: italic;">Application Navigator</span>. Any other entry of the <span style="font-style: italic;">ModelTopLink</span> project will do, also. Select <span style="font-style: italic;">New...</span> from the <span style="font-style: italic;">Context Menu</span> and navigate to <span style="font-style: italic;">Business Tier -&gt; EJB</span> in the <span style="font-style: italic;">New Gallery</span>. On the right-hand side select <span style="font-style: italic;">Session Bean</span> and click on the <span style="font-style: italic;">OK</span> button to open the <span style="font-style: italic;">Create Session Bean</span> wizard.<br><ul><li>In step <span style="font-style: italic;">Select EJB Version</span>, accept the <span style="font-style: italic;">Enterprise JavaBeans 3.0 (Java EE 5.0)</span> selection. Click <span style="font-style: italic;">Next</span> to continue.</li><li>In step <span style="font-style: italic;">EJB Name and Queries</span> change the <span style="font-style: italic;">EJB Name</span> to <span style="font-style: italic;">SurveySession</span>,
accept the pre-selected defaults. Note that JDeveloper already
recognized the <span style="font-style: italic;">Entity implementation</span> as <span style="font-style: italic;">TopLink POJOs</span>. Click on <span style="font-style: italic;">Next. <br></span></li><li>In step <span style="font-style: italic;">Session Facade - Select JPA Entity Methods</span> make sure that all methods are checked (expand the tree to see which methods are available). Click <span style="font-style: italic;">Next</span> to go to the next wizard step.</li><li>Step <span style="font-style: italic;">EJB Home and Component Interfaces</span> shows the implemented interfaces. <span style="font-style: italic;">Remote</span> and <span style="font-style: italic;">Local </span>interfaces are good enough for our scenario.</li><li>Clicking <span style="font-style: italic;">Next</span> directs us to the wizard Summary window which we close by clicking on the <span style="font-style: italic;">Finish</span> to go to the next wizard step.<br></li></ul>A <span style="font-style: italic;">SurveySessionBean</span> will be added to the project. Double-click on it and you'll see the generated Session Facade in the <span style="font-style: italic;">Code Editor</span>.<br>
<h4>Step 5: Create a Test Client</h4>
To finish the JDeveloper 11g tasks the creation of a test client needs to be done. Click on the <span style="font-style: italic;">SurveySessionBean</span> in the <span style="font-style: italic;">Application Navigator</span> and open the <span style="font-style: italic;">Context Menu</span>. Find the <span style="font-style: italic;">New Sample Java Client</span> entry and click on it. Accept all default values, select the <span style="font-style: italic;">Connect to OC4J Embedded in JDeveloper</span> and click on the <span style="font-style: italic;">OK</span> button to generate the test client. Open it and change the main method as follows:<br><pre style="background-color: rgb(204, 204, 204);">&nbsp;&nbsp;&nbsp; public static void main(String[] args) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; final Context context = getInitialContext();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SurveySession surveySession = <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (SurveySession)context.lookup("SurveySession");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Author author = new Author();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; author.setName("Olaf Heimburger 11g");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; surveySession.persistEntity(author);<br>            for (Author a : surveySession.queryAuthorFindAll()) {<br>                System.out.println("id = " + a.getId());<br>                System.out.println("name = " + a.getName());<br>            }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch (Exception ex) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ex.printStackTrace();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }</pre>To test the Session Facade and the Test Client do the following:<br><ol><li>
Select the <span style="font-style: italic;">SurveySessionBean</span>, open the <span style="font-style: italic;">Context Menu</span> and select <span style="font-style: italic;">Run</span>.
Wait until you see somethink like <span style="font-style: italic;">Embedded OC4J Server startup time: 83594 ms</span>.</li><li>
Select the <span style="font-style: italic;">SurveySessionClient</span>, open the <span style="font-style: italic;">Context Menu</span> and select <span style="font-style: italic;">Run</span>. You should get some output.</li></ol><h3>What have we done so far?</h3>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.<br><h3>A Note on EclipseLink</h3>EclipseLink is an open-sourced version of Oracle TopLink 11 and available from the Eclipse <a href="http://eclipse.org/eclipselink">site.</a><br>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.<br><h3>References</h3><a href="http://download.oracle.com/docs/cd/B25221_04/web.1013/b13594/toc.htm">Oracle TopLink Getting Started Guide</a><br><a href="http://download.oracle.com/docs/cd/B25221_04/web.1013/b13593/toc.htm">Oracle TopLink Developer's Guide</a><br><br><br>]]>
      
   </content>
</entry>
<entry>
   <title>ADF in Action: Building the Model Layer with EJB 3</title>
   <link rel="alternate" type="text/html" href="http://blogs.oracle.com/olaf/2008/03/adf_in_action_building_the_mod_1.html" />
   <id>tag:blogs.oracle.com,2008:/olaf//78.579</id>
   
   <published>2008-03-31T15:29:45Z</published>
   <updated>2008-06-24T00:36:00Z</updated>
   
   <summary>Enterprise Java Beans 3.0Although 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&apos;s and TopLink&apos;s Entity and Session Management. EJB 3...</summary>
   <author>
      <name>olaf.heimburger</name>
      
   </author>
         <category term="ADF" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="en" xml:base="http://blogs.oracle.com/olaf/">
      <![CDATA[<h3>Enterprise Java Beans 3.0</h3>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.<br><h4>EJB 3 Entities</h4>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.<br><h4>Java Persistence API</h4>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)).<br><h3>Implementing the EJB 3 Model Layer</h3>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 <a href="http://blogs.oracle.com/olaf/2008/01/26">Setting up the Gear</a>, <a href="http://blogs.oracle.com/olaf/2008/02/29">Creating the Database</a>, and <a href="http://blogs.oracle.com/olaf/2008/03/07">Deploying the Database Model</a>). Additionally you should make sure that your database is up and running and a <span style="font-style: italic;">Database Connection</span> called <span style="font-style: italic;">survey</span> configured. The steps in JDeveloper 10.1.3 and 11g are quite similar.<br><ol><li>Create a Model Layer Project</li><li>Import the EJB 3 from Database Tables</li><li>Check the generated files</li><li>Create a Session Facade</li><li>Create a Test Client</li></ol><h3>Steps for JDeveloper 10.1.3</h3><h4>Step 1: Create a Model Layer Project</h4>To create a new Model Layer Project select <span style="font-style: italic;">OnlineSurvey</span> in the <span style="font-style: italic;">Application Navigator</span>, open the <span style="font-style: italic;">Context Menu</span> and chose the <span style="font-style: italic;">New Project...</span> menu entry. In the <span style="font-style: italic;">New Gallery</span> select an <span style="font-style: italic;">Empty Project</span> and click on <span style="font-style: italic;">OK</span>. In the <span style="font-style: italic;">Create Project</span> window set the <span style="font-style: italic;">Project Name</span> to <span style="font-style: italic;">ModelEJB30</span> and click on the <span style="font-style: italic;">OK</span> button. Select the newly created <span style="font-style: italic;">ModelEJB30</span> project in the <span style="font-style: italic;">Application Navigator</span> and open the <span style="font-style: italic;">Project Properties</span> window with a <span style="font-style: italic;">double-click</span>. In the <span style="font-style: italic;">Project Properties</span> window, check the values of <span style="font-style: italic;">Project Content</span> and make sure that the <span style="font-style: italic;">Default Package</span> is set to <span style="font-style: italic;">demo.survey.model.ejb30</span>. Click <span style="font-style: italic;">OK</span> to close this window.<br><h4>Step 2: Import the EJB 3 from Datbase Tables</h4>Select the <span style="font-style: italic;">ModelEJB30</span> project in the <span style="font-style: italic;">Application Navigator</span>. Open the <span style="font-style: italic;">New Gallery</span> from the <span style="font-style: italic;">Context Menu -&gt; New ...</span>. In the <span style="font-style: italic;">New Gallery</span> expand the <span style="font-style: italic;">Business Tier</span> and select <span style="font-style: italic;">EJB</span>. On the right-hand side select <span style="font-style: italic;">Entities From Tables (JPA/EJB 3.0)</span> and click on the <span style="font-style: italic;">OK</span> button.<br><ul><li>In the <span style="font-style: italic;">Create Entities From Tables</span> wizard step 1 select the <span style="font-style: italic;">survey</span> connection. Click on <span style="font-style: italic;">Next</span> to get the database connection.</li><li>In step 2 click on the <span style="font-style: italic;">Query</span> button to get all available tables. Since we only have tables the check box for Tables is sufficient. Once the table names appear, <span style="font-style: italic;">select all of them</span>.</li><li>Move all entries from <span style="font-style: italic;">Available</span> to <span style="font-style: italic;">Selected</span>, by clicking on the <span style="font-style: italic;">&gt;&gt;</span> button. <span style="font-weight: bold;">Note</span> that all names have changed to typical Java type names but in plural (eg. <span style="font-style: italic;">Answers (SURVEY.ANSWERS)</span>). The values in parentheses tell you about the table relationship. Select every entry and see how the text field under the <span style="font-style: italic;">Selected</span> 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</li><li>Click <span style="font-style: italic;">Next</span> to go to wizard step 3. In step 3 of the wizard <span style="font-style: italic;">accept</span> the default values and click <span style="font-style: italic;">Next</span> to go to wizard step 4.</li><li>This step can be used for changing the names as well, but is less user-friendly. Click <span style="font-style: italic;">Next</span> to go to the <span style="font-style: italic;">Summary</span> and click on <span style="font-style: italic;">Finish</span> to close the wizard. Now all six entities will be created.</li></ul>You can find them in the <span style="font-style: italic;">Application Navigator</span> under <span style="font-style: italic;">ModelEJB30-&gt;Application Sources-&gt;demo.survey.model.ejb30</span>.<br><h4>Step 3: Check the generated files</h4>To check the generated files open them by selecting <span style="font-style: italic;">Answer.java</span>, <span style="font-style: italic;">hold </span>the <span style="font-style: italic;">Shift key</span>, select <span style="font-style: italic;">Survey.java</span>, open the <span style="font-style: italic;">Context Menu</span> and select <span style="font-style: italic;">Go To Bean Class</span>. Every selected file will be opened in a <span style="font-style: italic;">Code Editor</span>. Select the tab named <span style="font-style: italic;">Answer.java</span> to bring it to the front. Change the code to get the lines below:<br><pre style="background-color: rgb(204, 204, 204);">@Entity<br>@NamedQuery(name = "Answer.findAll", query = "select o from Answer o")<br><span style="font-weight: bold;">@SequenceGenerator(name = "SEQUENCE_ANSWERS", sequenceName = "SEQ_ANSWERS", allocationSize = 1)</span><br>@Table(name = "ANSWERS")<br>public class Answer implements Serializable {<br>&nbsp;&nbsp;&nbsp; @Id<br>&nbsp;&nbsp;&nbsp; <span style="font-weight: bold;">@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQUENCE_ANSWERS")</span><br>&nbsp;&nbsp;&nbsp; @Column(nullable = false)<br>&nbsp;&nbsp;&nbsp; private Long id;</pre><br>While adding this code, JDeveloper will suggest possible values and actions to be taken. Only import the types <span style="font-style: italic;">javax.persistence.SequenceGenerator</span>, <span style="font-style: italic;">javax.persistence.GeneratedValue</span> and <span style="font-style: italic;">javax.persistence.GenerationType</span>. You should explore how the <span style="font-style: italic;">Ctrl-Blank</span> short cut helps you to provide the correct annotation parameters.<br>Do the same for the other files <span style="font-style: italic;">Author.java</span>, <span style="font-style: italic;">Item.java</span>, <span style="font-style: italic;">Question.java</span>, <span style="font-style: italic;">Response.java</span>, <span style="font-style: italic;">Survey.java</span> but use <span style="font-style: italic;">SEQ_AUTHORS</span> with <span style="font-style: italic;">SEQUENCE_AUTHORS</span>, <span style="font-style: italic;">SEQ_ITEMS</span> with <span style="font-style: italic;">SEQUENCE_ITEMS</span>, <span style="font-style: italic;">SEQ_QUESTIONS</span> with <span style="font-style: italic;">SEQUENCE_QUESTIONS</span>, <span style="font-style: italic;">SEQ_RESPONSES</span> with <span style="font-style: italic;">SEQUENCE_RESPONSES</span>, and <span style="font-style: italic;">SEQ_SURVEYS</span> with <span style="font-style: italic;">SEQUENCE_SURVEYS</span>.<br><h4>Step 4: Create a Session Facade</h4>Click on <span style="font-style: italic;">ModelEJB30</span> in the <span style="font-style: italic;">Application Navigator</span>. Any other entry of the <span style="font-style: italic;">ModelEJB30</span> project will do, also. Select <span style="font-style: italic;">New...</span> from the <span style="font-style: italic;">Context Menu</span> and navigate to <span style="font-style: italic;">Business Tier -&gt; EJB</span> in the <span style="font-style: italic;">New Gallery</span>. On the right-hand side select <span style="font-style: italic;">Session Bean (EJB 1.1/2.x/3.0)</span> and click on the <span style="font-style: italic;">OK</span> button to open the 4 step <span style="font-style: italic;">Create Session Bean</span> wizard.<br><ul><li>In wizard step 1 change the <span style="font-style: italic;">EJB Name</span> to <span style="font-style: italic;">SurveySession</span>, accept the pre-selected defaults and click on <span style="font-style: italic;">Next</span></li><li>In wizard step 2 make sure that all methods are checked (expand the tree to see which methods are available). Click <span style="font-style: italic;">Next</span> to go to the next wizard step.</li><li>Step 3 shows the default values for the bean class and step 4 - Click <span style="font-style: italic;">Next</span> to go from step 3 to step 4 - shows the implemented interfaces. <span style="font-style: italic;">Remote</span> and <span style="font-style: italic;">Local </span>interfaces are good enough for our scenario.</li><li>Clicking <span style="font-style: italic;">Next</span> in step 4 directs us to the wizard Summary window which we close by clicking on the <span style="font-style: italic;">Finish</span> to go to the next wizard step.<br></li></ul>A <span style="font-style: italic;">SurveySessionBean</span> will be added to the project. Double-click on it and you'll see the generated Session Facade in the <span style="font-style: italic;">Code Editor</span>.<br><h4>Step 5: Create a Test Client</h4>To finish the JDeveloper 10.1.3 tasks the creation of a test client needs to be done. Click on the <span style="font-style: italic;">SurveySessionBean</span> in the <span style="font-style: italic;">Application Navigator</span> and open the <span style="font-style: italic;">Context Menu</span>. Find the <span style="font-style: italic;">New Sample Java Client</span> entry and click on it. Accept all default values and click on the <span style="font-style: italic;">OK</span> button to generate the test client. Open it and change the main method as follows:<br><pre style="background-color: rgb(204, 204, 204);">&nbsp;&nbsp;&nbsp; public static void main(String[] args) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; final Context context = getInitialContext();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SurveySession surveySession = <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (SurveySession)context.lookup("SurveySession");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Author author = new Author();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; author.setName("Olaf Heimburger");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; surveySession.persistEntity(author);<br>            for (Author author : <br>                 (List&amp;lt;Author&gt;)surveySession.queryAuthorFindAll()) {<br>                System.out.println("id = " + author.getId());<br>                System.out.println("name = " + author.getName());<br>            }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch (Exception ex) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ex.printStackTrace();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }</pre>To test the Session Facade and the Test Client do the following:<br><ol><li>Select the <span style="font-style: italic;">SurveySessionBean</span>, open the <span style="font-style: italic;">Context Menu</span> and select <span style="font-style: italic;">Run</span>. Wait until you see <span style="font-style: italic;">Oracle Containers for J2EE 10g (10.1.3.3.0)&nbsp; initialized</span>.</li><li>Select the <span style="font-style: italic;">SurveySessionClient</span>, open the <span style="font-style: italic;">Context Menu</span> and select <span style="font-style: italic;">Run</span>. You should get some output.<br></li></ol><h3>Steps for JDeveloper 11g</h3><h4>Step 1: Create a Model Layer Project</h4>
To create a new Model Layer Project select <span style="font-style: italic;">OnlineSurvey</span> in the
<span style="font-style: italic;">Application Navigato</span>r, click on the <span style="font-style: italic;">Applications Menu</span> on the right-hand side select the <span style="font-style: italic;">New
Project...</span> menu entry. In the <span style="font-style: italic;">New Gallery</span> select an <span style="font-style: italic;">Empty Project</span> and
click on <span style="font-style: italic;">OK</span>. In the <span style="font-style: italic;">Create Project</span> window set the <span style="font-style: italic;">Project Name</span> to
<span style="font-style: italic;">ModelEJB30</span> and click on the <span style="font-style: italic;">OK</span> button. Select the newly created
<span style="font-style: italic;">ModelEJB30</span> project in the <span style="font-style: italic;">Application Navigator</span> and open the <span style="font-style: italic;">Project
Properties</span> window with a double-click. In the <span style="font-style: italic;">Project Source Paths</span>
window, check the values of <span style="font-style: italic;">Project Source Paths</span> and make sure that the
<span style="font-style: italic;">Default Package</span> is set to <span style="font-style: italic;">demo.survey.model.ejb30</span>. Click <span style="font-style: italic;">OK</span> to close
this window.<br><h4>
Step 2: Import the EJB 3 from Datbase Tables</h4>
Select the <span style="font-style: italic;">ModelEJB30</span> project in the <span style="font-style: italic;">Application Navigator</span>. Open the
<span style="font-style: italic;">New Gallery</span> from the <span style="font-style: italic;">Context Menu -&gt; New ...</span>. In the <span style="font-style: italic;">New Gallery</span>
expand the <span style="font-style: italic;">Business Tier</span> and select <span style="font-style: italic;">EJB</span>. On the right-hand side select
<span style="font-style: italic;">Entities From Tables</span> and click on the <span style="font-style: italic;">OK</span> button.<br><ul><li>In the
<span style="font-style: italic;">Create Entities From Tables</span> wizard step 1 select <span style="font-style: italic;">EJB 3.0 - JPA Entities</span>.
Click on <span style="font-style: italic;">Next</span> to select the <span style="font-style: italic;">Persistence Unit</span>. Since we haven't created one yet, click on the <span style="font-style: italic;">New ...</span> button. In the <span style="font-style: italic;">New Persistence Unit</span> window set the <span style="font-style: italic;">Name</span> to <span style="font-style: italic;">survey</span> and the <span style="font-style: italic;">JTA Datasource Name</span> to <span style="font-style: italic;">jdbc/surveyDS. </span>Click <span style="font-style: italic;">OK</span> to close the window. Click <span style="font-style: italic;">Next</span> to go to the next step.</li><li>In step 3 make sure that the <span style="font-style: italic;">Online Database Connection</span> radio button is checked. Click <span style="font-style: italic;">Next</span> to go to the next step.</li><li>Step 4 lets you define the necessary details for the <span style="font-style: italic;">Database</span> connection and the Offline Database. The <span style="font-style: italic;">Connection</span> should be <span style="font-style: italic;">survey</span>. If this is not available click on the <span style="font-style: italic;">green plus</span> button to create a connection with <span style="font-style: italic;">survey</span> as the <span style="font-style: italic;">Connection Name</span>. For the <span style="font-style: italic;">Offline Database</span> click on the <span style="font-style: italic;">New</span> button and in the <span style="font-style: italic;">Create Offline Database</span> window set the <span style="font-style: italic;">Name</span> and <span style="font-style: italic;">Default Schema</span> to <span style="font-style: italic;">SURVEY</span>. From the <span style="font-style: italic;">Database to emulate</span><span style="font-style: italic;">Oracle10g Express Edition Release 2</span>. Click <span style="font-style: italic;">OK</span> to close this window. <span style="font-style: italic;">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.</span></li><li>Click <span style="font-style: italic;">Next</span> to go to step 5. Click on the
<span style="font-style: italic;">Query</span> button to get all available tables. Once the table names appear, select
all of them. Move all entries from <span style="font-style: italic;">Available</span> to <span style="font-style: italic;">Selected</span>, by clicking
on the <span style="font-style: italic;">&gt;&gt;</span> button.</li><li>Click <span style="font-style: italic;">Next</span> to go to wizard step 6. In this step accept the
default values and click <span style="font-style: italic;">Next</span> 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.<br><span style="font-style: italic;">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.</span></li><li>Click on <span style="font-style: italic;">Next</span> to go to the <span style="font-style: italic;">Summary</span> step. Click on <span style="font-style: italic;">Finish</span> to create all six entities.</li></ul>You can find them in the <span style="font-style: italic;">Application
Navigator</span> under <span style="font-style: italic;">ModelEJB30-&gt;Application
Sources-&gt;demo.survey.model.ejb30</span>.<br> drop-down select <h4>
Step 3: Check the generated files</h4>
To check the generated files open them by selecting <span style="font-style: italic;">Answer.java</span>, hold
the <span style="font-style: italic;">Shift key</span>, select <span style="font-style: italic;">Survey.java</span>, open the <span style="font-style: italic;">Context Menu</span> and select <span style="font-style: italic;">Go
To Bean Class</span>. Every selected file will be opened in the Code Editor.
Select the tab named <span style="font-style: italic;">Answer.java</span> to bring it to the front. Change the
code to get the lines below:<br>
<pre style="background-color: rgb(204, 204, 204);">@Entity<br>@NamedQuery(name = "Answer.findAll", query = "select o from Answer o")<br><span style="font-weight: bold;">@SequenceGenerator(name = "SEQUENCE_ANSWERS", sequenceName = "SEQ_ANSWERS", allocationSize = 1)</span><br>@Table(name = "ANSWERS")<br>public class Answer implements Serializable {<br>&nbsp;&nbsp;&nbsp; @Id<br>&nbsp;&nbsp;&nbsp; <span style="font-weight: bold;">@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQUENCE_ANSWERS")</span><br>&nbsp;&nbsp;&nbsp; @Column(nullable = false)<br>&nbsp;&nbsp;&nbsp; private Long id;</pre>
<br>
While adding this code, JDeveloper will suggest possible values and actions to be taken. Only import the types&nbsp;<span style="font-style: italic;"></span><span style="font-style: italic;"></span><span style="font-style: italic;">javax.persistence.GenerationType</span>. <span style="font-weight: bold;">A big improvement is that the EJB 3 Annotations are already known by JDeveloper and do not require any additional action</span>. You should explore how the <span style="font-style: italic;">Ctrl-Blank</span> short cut helps you to provide the correct annotation parameters.<br>
Do the same for the other files <span style="font-style: italic;">Author.java</span>, <span style="font-style: italic;">Item.java</span>, <span style="font-style: italic;">Question.java</span>,
<span style="font-style: italic;">Response.java</span>, <span style="font-style: italic;">Survey.java</span> but use <span style="font-style: italic;">SEQ_AUTHORS</span> with <span style="font-style: italic;">SEQUENCE_AUTHORS</span>,
<span style="font-style: italic;">SEQ_ITEMS</span> with <span style="font-style: italic;">SEQUENCE_ITEMS</span>, <span style="font-style: italic;">SEQ_QUESTIONS</span> with <span style="font-style: italic;">SEQUENCE_QUESTIONS</span>,
<span style="font-style: italic;">SEQ_RESPONSES</span> with <span style="font-style: italic;">SEQUENCE_RESPONSES</span>, and <span style="font-style: italic;">SEQ_SURVEYS</span> with
<span style="font-style: italic;">SEQUENCE_SURVEYS</span>.<br><h4>
Step 4: Create a Session Facade</h4>
Click on <span style="font-style: italic;">ModelEJB30</span> in the <span style="font-style: italic;">Application Navigator</span>. Any other entry of
the <span style="font-style: italic;">ModelEJB30</span> project will do, also. Select <span style="font-style: italic;">New...</span> from the <span style="font-style: italic;">Context
Menu</span> and navigate to <span style="font-style: italic;">Business Tier -&gt; EJB</span> in the <span style="font-style: italic;">New Gallery</span>. On the
right-hand side select <span style="font-style: italic;">Session Bean</span> and click on the
<span style="font-style: italic;">OK</span> button to open a 6 step <span style="font-style: italic;">Create Session Bean</span> wizard.<br><ul><li>Since the EJB version is already known the wizard starts a step 2, by using the <span style="font-style: italic;">Back</span> button you can go to step 1 but this is not needed.</li><li>In step 2 change the <span style="font-style: italic;">EJB Name</span> to <span style="font-style: italic;">SurveySession</span>, accept the pre-selected
defaults and click on <span style="font-style: italic;">Next</span> to go to the next wizard step.</li><li>In step 3 make sure that all methods are checked (expand the tree to see
which methods are available). Click <span style="font-style: italic;">Next</span> to go to the next wizard step.</li><li>Step 4 shows the default values for the bean class and Step 5 - Click
<span style="font-style: italic;">Next</span> to go from step 4 to step 5 - shows the implemented interfaces.
<span style="font-style: italic;">Remote</span> and <span style="font-style: italic;">Local</span> interfaces are good enough for our scenario. Clicking
<span style="font-style: italic;">Next</span> in Step 5 directs us to the wizard <span style="font-style: italic;">Summary</span> window which we close
by clicking on the <span style="font-style: italic;">Finish</span> button.</li></ul>A <span style="font-style: italic;">SurveySessionBean</span> will be added to
the project. Double-click on it and you'll see the generated Session
Facade in the Code Editor.<h4>
Step 5: Create a Test Client</h4>
To finish the JDeveloper 11g tasks, the creation of a test client
needs to be done. Click on the <span style="font-style: italic;">SurveySessionBean</span> in the <span style="font-style: italic;">Application
Navigator</span> and open the <span style="font-style: italic;">Context Menu</span>. Find the <span style="font-style: italic;">New Sample Java Client</span>
entry and click on it. Accept all default values and click on the <span style="font-style: italic;">OK</span>
button to generate the test client. Open it and change the <span style="font-style: italic;">main</span> method
as follows:<br>
<pre style="background-color: rgb(204, 204, 204);">&nbsp;&nbsp;&nbsp; public static void main(String[] args) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; final Context context = getInitialContext();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SurveySession surveySession = <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (SurveySession)context.lookup("SurveySession");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Author author = new Author();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; author.setName("Olaf Heimburger");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; surveySession.persistEntity(author);<br>            for (Author author : <br>                 (List&amp;lt;Author&gt;)surveySession.queryAuthorFindAll()) {<br>                System.out.println("id = " + author.getId());<br>                System.out.println("name = " + author.getName());<br>            }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch (Exception ex) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ex.printStackTrace();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }</pre>
To test the Session Facade and the Test Client do the following:<br><ol><li>
Select the <span style="font-style: italic;">SurveySessionBean</span>, open the <span style="font-style: italic;">Context Menu</span> and select <span style="font-style: italic;">Run</span>.
Wait until you see <span style="font-style: italic;">Embedded OC4J Server startup time: 83594 ms</span>.</li><li>
Select the <span style="font-style: italic;">SurveySessionClient</span>, open the <span style="font-style: italic;">Context Menu</span> and select <span style="font-style: italic;">Run</span>.</li></ol><h3>What Have We Done So Far?</h3>First of all we have created a number of <span style="font-style: italic;">Entities</span> for the <span style="font-style: italic;">Tables</span> that we created in the <span style="font-style: italic;">Database</span> project. Each <span style="font-style: italic;">Entity</span> has it's own <span style="font-style: italic;">Sequence Generator</span> assigned, using the <span style="font-style: italic;">@GeneratedValue</span> annotation. Since we used the default <span style="font-style: italic;">SEQUENCE</span> statement for the database, ie without an explicit <span style="font-style: italic;">INCREMENT</span> option, we had to adjust the default <span style="font-style: italic;">allocationSize</span> for JPA layer from <span style="font-style: italic;">50</span> to <span style="font-style: italic;">1</span> in the <span style="font-style: italic;">@SequenceGenerator</span> annotation. Finally we created a Session Facade for <span style="font-style: italic;">persisting</span>, <span style="font-style: italic;">retrieving</span> and <span style="font-style: italic;">updating</span> our <span style="font-style: italic;">Entities</span> conveniently. The very last step was to test the Facade with the Author class.<br><h3>References</h3><ul><li><span style="font-style: italic;">EJB 3 in Action</span>, Debu Panda, Reza Rahman, Derek Lane, Manning, ISBN 978-1-933988-34-4</li><li><span style="font-style: italic;">Java Persistence with Hibernate</span>, Christian Bauer, Gavin King, Manning, ISBN 1-932394-88-5</li></ul><br>]]>
      
   </content>
</entry>
<entry>
   <title>ADF in Action: The Model Layer</title>
   <link rel="alternate" type="text/html" href="http://blogs.oracle.com/olaf/2008/03/adf_in_action_the_model_layer.html" />
   <id>tag:blogs.oracle.com,2008:/olaf//78.575</id>
   
   <published>2008-03-31T15:21:21Z</published>
   <updated>2008-06-24T00:35:58Z</updated>
   
   <summary>Application LayersModern 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...</summary>
   <author>
      <name>olaf.heimburger</name>
      
   </author>
         <category term="ADF" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="en" xml:base="http://blogs.oracle.com/olaf/">
      <![CDATA[<h3>Application Layers</h3>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.<br><h3>The Model Layer</h3>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.<br><h4>Model Layer Choices</h4>Oracle ADF supports many ways to implement the model layer. We will have a look at these three possible choices:<br><ul><li>EJB 3.0 / Java Persistence API (JPA)</li><li>TopLink</li><li>ADF Business Components</li></ul>Each of these choices deserves a separate coverage as they tend to be different in many ways.<br><h3>General Considerations</h3>Before we go into the details we have to consider some things:<br><ul><li><span style="font-weight: bold;">Plural vs Singular Naming</span> - 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.</li><li><span style="font-weight: bold;">Using Existing Sequence Generators</span> - 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.</li></ul><br>]]>
      
   </content>
</entry>
<entry>
   <title>ADF in Action: Content of the Database Project, Iteration 1</title>
   <link rel="alternate" type="text/html" href="http://blogs.oracle.com/olaf/2008/03/adf_in_action_content_of_the_d.html" />
   <id>tag:blogs.oracle.com,2008:/olaf//78.576</id>
   
   <published>2008-03-11T18:52:22Z</published>
   <updated>2008-06-24T00:35:59Z</updated>
   
   <summary>Online Survey Application, Database Project, Iteration 1It 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.3Database Project In JDeveloper 11g...</summary>
   <author>
      <name>olaf.heimburger</name>
      
   </author>
         <category term="ADF" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="en" xml:base="http://blogs.oracle.com/olaf/">
      <![CDATA[<h3>Online Survey Application, Database Project, Iteration 1</h3>It is time to verify you are on the right track. Your <span style="font-style: italic;">database</span> project should like mine. Here are the screenshots for both JDeveloper versions.<br><h4>Database Project In JDeveloper 10.1.3</h4><img src="http://blogs.oracle.com/olaf/images/DB0110.jpg" height="465" width="262" border="0" alt="DB_01_10: "><br><h4>Database Project In JDeveloper 11g</h4><img src="http://blogs.oracle.com/olaf/images/DB0111.jpg" height="641" width="273" border="0" alt="DB_01_11: "><br><br>]]>
      
   </content>
</entry>
<entry>
   <title>ADF in Action: Deploying the Database Model</title>
   <link rel="alternate" type="text/html" href="http://blogs.oracle.com/olaf/2008/03/adf_in_action_deploying_the_da.html" />
   <id>tag:blogs.oracle.com,2008:/olaf//78.577</id>
   
   <published>2008-03-07T13:17:45Z</published>
   <updated>2008-06-24T00:35:59Z</updated>
   
   <summary>You may have noticed it, this is the missing step from the last post...Deploying the DatabaseOnce the database schema modeling is finished it needs to be deployed to the database. There are several options and a good database administrator (DBA)...</summary>
   <author>
      <name>olaf.heimburger</name>
      
   </author>
         <category term="ADF" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="en" xml:base="http://blogs.oracle.com/olaf/">
      <![CDATA[<p><span style="font-style: italic;">You may have noticed it, this is the missing step from the last post...</span><br><h3>Deploying the Database</h3>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.<br><h3>Scripts to Create the Database User</h3>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:<br><ol><li>Click on the <span style="font-style: italic;">Offline Database Sources</span></li><li>Open the <span style="font-style: italic;">Context Menu</span></li><li>Select <span style="font-style: italic;">New ...</span></li><li>Expand <span style="font-style: italic;">Database Tier</span></li><li>Select <span style="font-style: italic;">Database Files</span></li><li>On the right select <span style="font-style: italic;">SQL File</span></li><li>Click the <span style="font-style: italic;">OK</span> button</li><li>In the opening <span style="font-style: italic;">Create SQL File</span> window enter <span style="font-style: italic;">File Name</span>: <span style="font-style: italic;">create_survey_tablespace.sql</span> and make sure that the <span style="font-style: italic;">Directory Name</span> has <span style="font-style: italic;">OnlineSurvey/Database/database</span> (in JDeveloper 10.1.3) or <span style="font-style: italic;">OnlineSurvey/Database/database/SURVEY</span> (in JDeveloper 11g) <span style="font-weight: bold;">at the end</span>.</li><li>Click on the <span style="font-style: italic;">OK</span> button to create an empty file.</li><li>You will notice that the file appears right <span style="font-weight: bold;">below</span> the <span style="font-style: italic;">create_survey_schema.sql</span> file in the <span style="font-style: italic;">Application Navigator</span>.</li><li>In the tab named <span style="font-style: italic;">create_survey_tablespace.sql</span> enter the following line. You might need to change your file path!<br><pre style="background-color: rgb(204, 204, 204);">CREATE TABLESPACE survey datafile 'C:\oracle\xe\oradata\XEsurvey.dbf'<br>SIZE 500k reuse autoextend ON;</pre><br></li><li>Repeat steps -10 to create a file called create_survey_user.sql. Put the following code in this file:<br><pre style="background-color: rgb(204, 204, 204);">DROP USER survey;<br>CREATE USER survey IDENTIFIED BY survey DEFAULT TABLESPACE survey TEMPORARY<br>  TABLESPACE temp;<br>GRANT connect,resource TO survey;<br></pre></li></ol><h3>Running the SQL Files ...</h3>All we need to do is to run the SQL files to complete the database deployment.<br><h3>... In JDeveloper 10.1.3</h3>Before we can do this, we need to check whether JDeveloper is configured to use SQL*Plus to execute the SQL scripts:<br><ol><li>Open <span style="font-style: italic;">Tools</span>-&gt;<span style="font-style: italic;">Preferences</span></li><li>Select <span style="font-style: italic;">Database Connections</span></li><li>If the text field for <span style="font-style: italic;">SQL*Plus Executable</span> is completed you're done, otherwise we have to point it to the right executable.</li><li>Click on the <span style="font-style: italic;">Browse</span> button</li><li>In the new <span style="font-style: italic;">Open</span> file dialog navigate to the <span style="font-style: italic;">$ORACLE_HOME</span> directory for XE. In the <span style="font-style: italic;">$ORACLE_HOME/bin directory</span> you'll find an executable named <span style="font-style: italic;">sqlplus.exe</span> or <span style="font-style: italic;">sqlplus</span>.</li><li>Select <span style="font-style: italic;">sqlplus.exe</span> and click on <span style="font-style: italic;">Open</span></li><li>Once this is done, select the <span style="font-style: italic;">create_survey_tablespace.sql</span> and from the <span style="font-style: italic;">Context Menu</span> follow the <span style="font-style: italic;">Run in SQL</span> to select the <span style="font-style: italic;">sysXE</span> entry. This will open a terminal window for SQL*Plus. For <span style="font-style: italic;">security reasons</span> the <span style="font-style: italic;">password </span>of the <span style="font-style: italic;">sys </span>database user has to be <span style="font-style: italic;">entered</span>. When this is done the script will be run and creates the tablespace.</li><li>Now do the same with the <span style="font-style: italic;">create_survey_user.sql</span>.<br></li></ol>To use this new user for later connections we create another <span style="font-style: italic;">Database Connection</span> called <span style="font-style: italic;">surveyXE</span> in the <span style="font-style: italic;">Connection Navigator</span> (see <a href="http://blogs.oracle.com/olaf/2008/01/26">ADF in Action: Setting up the Gear, Verifying the Database Connection</a> for more details on this). With this connection we run the <span style="font-style: italic;">create_survey_schema.sql</span> to create the full schema.<br><h3>... In JDeveloper 11g</h3>In 11g things are slightly different. We have <span style="font-style: italic;">Global</span> <span style="font-style: italic;">Connections</span> in the <span style="font-style: italic;">Resource Palette</span> and <span style="font-style: italic;">Application-specific Connections</span> in the <span style="font-style: italic;">Application Resources</span> accordion.<br><br>To reuse the global database connection, we expand the <span style="font-style: italic;">sysXE</span> database connection from the <span style="font-style: italic;">Resource Palette</span> and <span style="font-weight: bold;">drag</span> it to the <span style="font-style: italic;">Application Resources Connections</span> entry. (<span style="font-style: italic;">This is really cool!</span>) It creates a <span style="font-style: italic;">Connections</span>-&gt;<span style="font-style: italic;">Database</span>-&gt;<span style="font-style: italic;">sysXE</span> structure for the application also.<br><br>The rest is similar to JDeveloper 10.1.3. Just try it.<br><br>You should now have the Survey schema in your database. If not post a comment...<br><br><br></p>]]>
      
   </content>
</entry>
<entry>
   <title>ADF In Action: Creating the Database</title>
   <link rel="alternate" type="text/html" href="http://blogs.oracle.com/olaf/2008/02/adf_in_action_creating_the_dat.html" />
   <id>tag:blogs.oracle.com,2008:/olaf//78.580</id>
   
   <published>2008-02-29T16:28:41Z</published>
   <updated>2008-06-24T00:36:00Z</updated>
   
   <summary>Huuh, creating a database? Why is that? I just want to display the data...The Online Survey ApplicationSince there are so many types of web-based applications we just pick one as a sample to implement. The demo application we are building...</summary>
   <author>
      <name>olaf.heimburger</name>
      
   </author>
   
   
   <content type="html" xml:lang="en" xml:base="http://blogs.oracle.com/olaf/">
      <![CDATA[<p><span style="font-style: italic;">Huuh, creating a database? Why is that? I just want to display the data...</span><br><h3>The Online Survey Application</h3>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:<br><ul><li>Have authors to create, update, and delete surveys.</li><li>A survey has a number of questions.</li><li>Each question may have a number of possible answers.</li><li>A question may be answered mandatory.</li><li>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.</li><li>Each applicant has it's own list of answers.</li><li>The author can request reports of the answers per survey.</li></ul><h3>The Overall Project Structure</h3>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 <span style="font-style: italic;">Application</span> which consists of a number of <span style="font-style: italic;">Projects</span>. No <span style="font-style: italic;">Project</span> can be used outside of an <span style="font-style: italic;">Application</span>. <span style="font-style: italic;">Applications</span> and <span style="font-style: italic;">Projects</span> are stored in different file types. When you examine your disk you will find a <span style="font-style: italic;">jws</span> file for the <span style="font-style: italic;">Application</span> and some<span style="font-style: italic;"> jpr</span> files for the <span style="font-style: italic;">Projects</span>.<br>The structure of the Online Survey application will look like this<br><ul><li>Online Survey Application</li><ul><li>Database Project</li><li>Model Project</li><li>etc.</li></ul></ul><h3>Creating the Project Structure</h3>To create this structure in JDeveloper, just start your favorite version and follow the steps below.<br><h4>In JDeveloper 10.1.3</h4><ol><li>Select the <span style="font-style: italic;">Applications</span> root in the <span style="font-style: italic;">Applications Navigator</span></li><li>Open the <span style="font-style: italic;">Context Menu</span> and select <span style="font-style: italic;">New Application ...</span></li><li>The <span style="font-style: italic;">Create Application</span> wizard opens</li><li>Set the <span style="font-style: italic;">Application Name</span> to <span style="font-style: italic;">OnlineSurvey</span>.</li><li>For the <span style="font-style: italic;">Application Package Prefix</span> we chose <span style="font-style: italic;">demo.survey</span>.</li><li>As <span style="font-style: italic;">Application Template</span> select the <span style="font-style: italic;">No Template [All Technologies]</span> template.</li><li>Click on the <span style="font-style: italic;">OK</span> button to finish the wizard.</li><li>Immediately after creating the application <span style="font-style: italic;">OnlineSurvey</span>, JDeveloper opens the <span style="font-style: italic;">Create Project</span> wizard for the first project in the application tree.</li><li>Enter <span style="font-style: italic;">Database</span> for the <span style="font-style: italic;">Database</span> project.</li><li>Click on the <span style="font-style: italic;">OK</span> button to finish the wizard.</li></ol><h4>In JDeveloper 11g</h4><ol><li>In the <span style="font-style: italic;">Application Navigator</span> click on the <span style="font-style: italic;">New Application ...</span> button.</li><li>The <span style="font-style: italic;">Create Application</span> wizard opens.</li><li>Enter the <span style="font-style: italic;">Application Name</span> as <span style="font-style: italic;">OnlineSurvey</span></li><li>For the <span style="font-style: italic;">Application Package Prefix</span> we chose <span style="font-style: italic;">demo.survey</span>.</li><li>As <span style="font-style: italic;">Application Template</span> we select the <span style="font-style: italic;">No Template [All Technologies]</span> template.</li><li>Click on the <span style="font-style: italic;">OK</span> button to finish the wizard.</li><li>Immediately after creating the application OnlineSurvey, JDeveloper<br />
opens the <span style="font-style: italic;">Create Project</span> wizard for the first project in the<br />
application tree.</li><li><br />
Enter <span style="font-style: italic;">Database</span> for the <span style="font-style: italic;">Database</span> project.</li><li><br />
Click on the <span style="font-style: italic;">OK</span> button to finish the wizard.</li></ol><br />
We now have the first parts of our project structure created, let's continue with the database design.<br><br />
<h3>The Data Model</h3>The dynamic nature of the Online Survey suggests to store the configuration of each survey into a database.&nbsp; 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:<br><ul><li>AUTHORS</li><li>SURVEYS</li><li>QUESTIONS</li><li>ITEMS</li><li>RESPONSES</li><li>ANSWERS</li></ul>Each of these tables has an <span style="font-style: italic;">id</span> column for a unique key (aka primary key). Some of them have foreign key relationships to other tables.<br><h3>The Database Diagrammer</h3>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 <span style="font-style: italic;">Database Diagrammer</span>, so the next task is to create a diagram for the Online Survey application:<br><ol><li>In your <span style="font-style: italic;">OnlineSurvey</span> application click on the <span style="font-style: italic;">Database</span> project.</li><li>From the Context Menu select <span style="font-style: italic;">New ...</span> to open the <span style="font-style: italic;">New Gallery</span>.</li><li>In the <span style="font-style: italic;">New Gallery</span> expand the <span style="font-style: italic;">General</span> group in the <span style="font-style: italic;">Categories</span> panel and select the <span style="font-style: italic;">Diagrams</span> entry. In the <span style="font-style: italic;">Items</span> area on the right all possible diagram types will be displayed.</li><li>Select <span style="font-style: italic;">Database Diagram</span> and click on the <span style="font-style: italic;">OK</span> button to open the <span style="font-style: italic;">Create Database Diagram</span> wizard.</li><li>Enter <span style="font-style: italic;">Online Survey</span> for the <span style="font-style: italic;">Name</span> field, set the <span style="font-style: italic;">Package</span> to <span style="font-style: italic;">demo.survey.db</span> and click on the <span style="font-style: italic;">OK</span> button to start the diagram creation.</li></ol><h4>JDeveloper 10.1.3 vs. 11g</h4>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.<br><h3>Creating the Database Model</h3>To create the database model for the Online Survey application, we use the <span style="font-style: italic;">Database Diagrammer</span> for modelling all the tables and columns we can imagine so far. To do this we need to select the <span style="font-style: italic;">Table</span> component from the <span style="font-style: italic;">Component Palette</span> and move it to the diagram.<br><h4>Tables In JDeveloper 10.1.3</h4>JDeveloper 10.1.3 allows to create a number of <span style="font-style: italic;">Table </span>components at once by holding the <span style="font-style: italic;">Shift </span>key and clicking in the diagram area. This way we create six <span style="font-style: italic;">Table </span>components. End this behaviour by selecting the <span style="font-style: italic;">Pointer </span>component.<br><h4>Tables In JDeveloper 11g</h4>JDeveloper 11g behaves a bit differently here. It does not assume anything and when the first component is placed on the diagram area, an <span style="font-style: italic;">Offline Database</span> wizard appears. Here the <span style="font-style: italic;">Offline Database</span> can be selected or created.<br><ol><li>To create a new <span style="font-style: italic;">Offline Database</span> click on the <span style="font-style: italic;">New...</span> button and a <span style="font-style: italic;">Create Offline Database</span> wizard window opens.</li><li>Complete the <span style="font-style: italic;">Properties</span> entry with <span style="font-style: italic;">Name: SURVEY</span> and <span style="font-style: italic;">Default Schema: SURVEY</span>.</li><li>For <span style="font-style: italic;">Database to emulate</span> select <span style="font-style: italic;">Oracle 10g Express Edition Release 2</span> from the drop down list.</li><li>Click on the <span style="font-style: italic;">OK</span> button to close the window.</li><li>The <span style="font-style: italic;">SURVEY</span> offline database will appear in the <span style="font-style: italic;">Offline Database</span> drop down list.</li><li>Click on the <span style="font-style: italic;">OK</span> to close the <span style="font-style: italic;">Offline Database</span> window.</li></ol>Now five additional <span style="font-style: italic;">Table </span>components can be added. Unlike JDeveloper 10.1.3 the <span style="font-style: italic;">Table</span> component must be selected from <span style="font-style: italic;">Component Palette</span> every time.<br><h4>Both Versions</h4>To change the name from the generic <span style="font-style: italic;">TABLEn</span> to a real one simply click on on the name and use one of the following for the table component names: <span style="font-style: italic;">AUTHORS</span>, <span style="font-style: italic;">SURVEYS</span>, <span style="font-style: italic;">QUESTIONS</span>, <span style="font-style: italic;">ITEMS</span>, <span style="font-style: italic;">RESPONSES</span>, and <span style="font-style: italic;">ANSWERS</span>.<br>For every <span style="font-style: italic;">Table</span> we have to add an <span style="font-style: italic;">ID</span> column which acts as the primary key. As an example the <span style="font-style: italic;">Table AUTHORS</span> will be used:<br><ol><li><br />
Double click on the <span style="font-style: italic;">Table AUTHORS</span>. The <span style="font-style: italic;">Edit Offline Table</span> window opens with the <span style="font-style: italic;">Column Information</span> selected.</li><li><br />
Clicking on the <span style="font-style: italic;">green plus</span> creates a new column named <span style="font-style: italic;">COLUMN1</span>.</li><li><br />
Since the name should be <span style="font-style: italic;">ID</span> the name <span style="font-style: italic;">COLUMN1</span> has to be changed to <span style="font-style: italic;">ID</span>.</li><li><br />
Now select the <span style="font-style: italic;">Type</span> as <span style="font-style: italic;">NUMBER</span> with a <span style="font-style: italic;">Precision</span> of <span style="font-style: italic;">38</span>.</li><li><br />
Finally, the <span style="font-style: italic;">Cannot be NULL</span> must be selected as this is the primary key with a known value.</li><li>To make the ID the primary key, click on the Primary Key category, select the ID column and moved it to the select part ...<br></li><li><br />
Clicking on <span style="font-style: italic;">OK</span> closes the window and the <span style="font-style: italic;">ID</span> column appears in the <span style="font-style: italic;">AUTHORS Table</span> component in the diagram area.</li></ol><br />
Do the same for the tables <span style="font-style: italic;">SURVEYS</span>, <span style="font-style: italic;">QUESTIONS</span>, <span style="font-style: italic;">ITEMS</span>, <span style="font-style: italic;">RESPONSES</span>, and <span style="font-style: italic;">ANSWERS</span>.<br><br />
<h4>Sequences</h4>To generate a table specific number for every table we create six Sequences:<br><ol><li><br />
Click on the <span style="font-style: italic;">Sequence</span> component and move it to the diagram area. Do this six times.</li><li><br />
Rename the just created sequences to <span style="font-style: italic;">SEQ_AUTHORS</span>, <span style="font-style: italic;">SEQ_SURVEYS</span>, <span style="font-style: italic;">SEQ_QUESTIONS</span>, <span style="font-style: italic;">SEQ_ITEMS</span>, <span style="font-style: italic;">SEQ_RESPONSES</span>, and <span style="font-style: italic;">SEQ_ANSWERS</span>.</li></ol><br />
To leverage the Oracle Database default behaviour of an unbounded<br />
sequence incrementing by 1 everything else could be left blank.<br><h4>Foreign Key Relationships</h4>To establish relationships between tables, <span style="font-style: italic;">Foreign Key Relationships</span> need to be modeled. In the database diagrammer a <span style="font-style: italic;">Foreign Key Relationship</span> has the semantics from <span style="font-style: italic;">One To Many</span>, one row in a table has a relationship to many rows in another table. For the <span style="font-style: italic;">Online Survey</span> model the following relationships need to be created:<br><ul><li>One <span style="font-style: italic;">Author</span> has Many <span style="font-style: italic;">Surveys</span> (<span style="font-style: italic;">AUTHORS to SURVEYS</span>)</li><li>One <span style="font-style: italic;">Survey</span> has Many <span style="font-style: italic;">Questions</span> (<span style="font-style: italic;">SURVEYS to QUESTIONS</span>)</li><li>One <span style="font-style: italic;">Question</span> has Many <span style="font-style: italic;">Items</span> (<span style="font-style: italic;">QUESTIONS to ITEMS</span>)</li><li>One <span style="font-style: italic;">Survey</span> has Many <span style="font-style: italic;">Responses</span> (<span style="font-style: italic;">SURVEYS to RESPONSES</span>)</li><li>One <span style="font-style: italic;">Response</span> has Many <span style="font-style: italic;">Answers</span> (<span style="font-style: italic;">RESPONSES to ANSWERS</span>)</li></ul><br>Using the <span style="font-style: italic;">AUTHORS to SURVEYS</span> foreign key relationship as an example for all:<br><ol><li>Select the <span style="font-style: italic;">Foreign Key</span> component from the <span style="font-style: italic;">Component Palette</span></li><li>Move the mouse to the <span style="font-style: italic;">AUTHORS</span> table and select it</li><li>Move the mouse to the <span style="font-style: italic;">SURVEYS</span> table and select it</li><li>A <span style="font-style: italic;">Create Foreign Key</span> window opens and shows the name of the foreign key (<span style="font-style: italic;">SURVEYS_AUTHORS_FK</span>) and the related table columns. This window helps to verify the correctness of the relationship, where the existing primary key column the <span style="font-style: italic;">One </span>part of the relation is and in the right column of the table appears, ie. <span style="font-style: italic;">ID</span> from <span style="font-style: italic;">AUTHORS</span> in this case. By clicking on the <span style="font-style: italic;">OK</span> button the defaults are accepted, the window closes and a line between <span style="font-style: italic;">AUTHORS</span> (with a <span style="font-style: italic;">0..1</span> on this end) and <span style="font-style: italic;">SURVEYS</span> (with a <span style="font-style: italic;">*</span> on this end) is drawn.</li></ol>Repeat this for the other relationships to build the complete picture.<br><h4>More Table Columns</h4>Finally, each table consists of a number of additional columns. These can be added by the same technique as the one used for the ID column above. The additional columns for the tables are as follows:<br><ul><li>AUTHORS</li><ul><li>name : VARCHAR(200)<br></li></ul><li>SURVEYS</li><ul><li>name : VARCHAR2(200)</li><li>introduction : VARCHAR2(400)<br></li><li>valid_from : TIMESTAMP</li><li>valid_to : TIMESTAMP</li></ul><li>QUESTIONS</li><ul><li>text : VARCHAR2(200)<br></li></ul><li>ITEMS</li><ul><li>text : VARCHAR2(200)</li></ul></ul><h4>A Note on JDeveloper 10.1.3</h4>You might have noticed it! By default JDeveloper creates every new <span style="font-style: italic;">Database Object</span> in the <span style="font-style: italic;">MYSCHEMA</span> schema. You can either<br><ol><li>Create all Objects (ie, Tables, Sequences, etc.) as described above and change the schema in every object by selecting the object in the <span style="font-style: italic;">Application Navigator</span>, selecting <span style="font-style: italic;">Properties...</span> from the <span style="font-style: italic;">Context Menu</span> and change the <span style="font-style: italic;">Schema Information</span> (eg. in the <span style="font-style: italic;">Table Information</span> section or <span style="font-style: italic;">Sequence Information</span>) to <span style="font-style: italic;">SURVEY.</span></li><li>Create only one object like a Table, <span style="font-style: italic;">change</span> the Schema as above and <span style="font-style: italic;">create</span> the all other objects from the <span style="font-style: italic;">Application Navigator</span> by selecting the <span style="font-style: italic;">SURVEY</span> node and choosing <span style="font-style: italic;">New Database Object ...</span> from the <span style="font-style: italic;">Context Menu</span>.</li></ol><h4>The Database Creation Script</h4>The last step is to create an SQL script for setting up the <span style="font-style: italic;">SURVEY </span>schema in the database. JDeveloper can do this online, but it is a good practice to create a script for reproducable code, source code control, and later reference.<br><br>There are two ways to start the SQL script generation for the database model (aka Data Definition Language)<br><h4>In JDeveloper 10.1.3</h4><ol><li>Open the <span style="font-style: italic;">Context Menu</span> on the <span style="font-style: italic;">SURVEY</span> database diagram and move to the <span style="font-style: italic;">Generate</span> -&gt; <span style="font-style: italic;">Data Definition Language for Diagram</span></li><li>In the <span style="font-style: italic;">Applications Navigator</span> expand the <span style="font-style: italic;">Database</span> project and the <span style="font-style: italic;">Offline Database Sources</span> folder, open the <span style="font-style: italic;">Context Menu</span> on the <span style="font-style: italic;">SURVEY </span>schema and move to <span style="font-style: italic;">Generate or Reconcile Database Objects ...</span></li></ol>Both steps open the <span style="font-style: italic;">Generate SQL from Offline Database Objects</span> wizard.<br><ol><li>The wizard Welcome page will be show on the first call of the wizard. Check the <span style="font-style: italic;">Skip this Page Next Time</span> checkbox. <br></li><li>Click on the <span style="font-style: italic;">Next </span>button to go to <span style="font-style: italic;">Step 1</span> (<span style="font-style: italic;">Select Objects</span>).</li><li>On the <span style="font-style: italic;">Selected </span>area you will find all the database objects that should be created.</li><li>Click on the Next button to go to <span style="font-style: italic;">Step 2</span> (<span style="font-style: italic;">Generate Objects</span>).</li><li>Select the <span style="font-style: italic;">Generation Type</span>: <span style="font-style: italic;">CREATE Objects</span><br></li><li>Click on the Next button to go to <span style="font-style: italic;">Step 3</span> (<span style="font-style: italic;">SQL Script Options</span>).</li><li>Select the <span style="font-style: italic;">Generate SQL Scripts</span>.<br></li><li>Select the <span style="font-style: italic;">Prefix object name with schema</span> option.</li><li>Set the <span style="font-style: italic;">SQL File Name</span> to <span style="font-style: italic;">create_survey_schema.sql</span></li><li>Click on the <span style="font-style: italic;">Next</span> button to go to <span style="font-style: italic;">Step 4</span> (<span style="font-style: italic;">Database Option</span>).</li><li><span style="font-weight: bold;">Do not select anything on this page!</span></li><li>Click on the <span style="font-style: italic;">Finish </span>button to create the SQL file.</li></ol><h4>In JDeveloper 11g</h4><ol><li>Open the <span style="font-style: italic;">Context Menu</span> on the <span style="font-style: italic;">SURVEY</span> database diagram and move to the <span style="font-style: italic;">Synchronize to Database -&gt; Generate To -&gt;&nbsp; SQL Script...</span><span style="font-style: italic;"></span></li><li>In the <span style="font-style: italic;">Applications Navigator</span> expand the <span style="font-style: italic;">Database</span> project and the <span style="font-style: italic;">Offline Database Sources</span> folder, open the <span style="font-style: italic;">Context Menu</span> on the <span style="font-style: italic;">SURVEY </span>schema and move to <span style="font-style: italic;">Generate&nbsp; ...</span></li></ol>Both steps open the <span style="font-style: italic;">Generate SQL from Offline Database Objects</span> wizard at <span style="font-style: italic;">Step 4</span> (<span style="font-style: italic;">Choose Operation</span>).<br><ol><li>For the first run the selected <span style="font-style: italic;">CREATE </span>action is the right choice. The other values are perfectly selected.</li><li>Click on the <span style="font-style: italic;">Next</span> button to go <span style="font-style: italic;">Step 5</span> (<span style="font-style: italic;">SQL Script Options</span>)</li><li>Select the <span style="font-style: italic;">Prefix object name with schema</span> option</li><li>Set the <span style="font-style: italic;">SQL File Name</span> to <span style="font-style: italic;">create_survey_schema.sql</span></li><li>Click on the <span style="font-style: italic;">Next</span> button to go to <span style="font-style: italic;">Step 6</span> (<span style="font-style: italic;">Finish</span>) which shows the <span style="font-style: italic;">Overview</span> of the selected options.</li><li>Click on the <span style="font-style: italic;">Finish</span> button to create the SQL file.</li><li><span style="font-style: italic;">Optional:</span> Check the <span style="font-style: italic;">Save settings for reuse</span> to reuse these settings.</li></ol><h3>So far so good</h3>We have created a basic data model for the Survey application. It is far from complete and will be refined incrementally during the interations of the application.<br><h3>What's Next?</h3>The next step is the O/R-mapping with a decent framework. JDeveloper supports TopLink, EJB 3, and ADF Business Components out of the box. Each one will be covered separately in the next posts.<br><br><br></p>]]>
      
   </content>
</entry>
<entry>
   <title>ADF In Action: Setting Up the Gear</title>
   <link rel="alternate" type="text/html" href="http://blogs.oracle.com/olaf/2008/01/adf_in_action_setting_up_the_g.html" />
   <id>tag:blogs.oracle.com,2008:/olaf//78.581</id>
   
   <published>2008-01-26T18:45:14Z</published>
   <updated>2008-06-24T00:36:00Z</updated>
   
   <summary>No fancy words this time, let&apos;s start.Setting Up the GearOK, you&apos;ve decided to learn to develop with ADF. Now is the time to get the minimal environment setup for you. Your toolbox should contain these tools:JDeveloper - This is the...</summary>
   <author>
      <name>olaf.heimburger</name>
      
   </author>
   
   
   <content type="html" xml:lang="en" xml:base="http://blogs.oracle.com/olaf/">
      <![CDATA[<p><span style="font-style: italic;">No fancy words this time, let's start.</span><br><h3>Setting Up the Gear</h3>OK, you've decided to learn to develop with ADF. Now is the time to get the minimal environment setup for you. Your toolbox should contain these tools:<br><ul><li><span style="font-style: italic;">JDeveloper</span> - This is the primary tool for developing with ADF, none gives you better support. Get it from <a href="http://www.oracle.com/technology/software/products/jdev/index.html">OTN</a>.</li><li><span style="font-style: italic;">Oracle XE Database</span> - To makes things much, much easier, I prefer to use the Oracle XE database. This is a stripped down data base, which behaves a lot like a normal Oracle database, but uses less memory and allows only 4 GB data files. Get it from <a href="http://www.oracle.com/technology/products/database/xe/index.html">OTN</a>.</li><li>On Linux you'll need to get a recent <a href="http://java.sun.com/javase/downloads/index_jdk5.jsp">JDK 5</a> before running JDeveloper.</li></ul>Once you've downloaded these tools. Install them.<br><div style="margin-left: 40px;"><h5>Note: Oracle XE Installation</h5>To speed up the boot time of my environments, I avoid the automatic XE startup. On <span style="font-style: italic;">Windows</span>, I've changed the startup type for the services <span style="font-style: italic;">OracleServiceXE</span>, <span style="font-style: italic;">OracleXETNSListener</span> to <span style="font-style: italic;">Manual</span>. On <span style="font-style: italic;">Linux</span>, while running the post-installation task <span style="font-style: italic;">/etc/init.d/oracle-xe configure</span>, you have to answer the question "<span style="font-style: italic;">Do you want Oracle Database 10g Express Edition to be started on boot (y/n) [y]:</span>" with <span style="font-style: italic;">N</span>.<br></div><div style="margin-left: 40px;"><h5>Note: JDeveloper - Which version?</h5>In this series I'll cover both JDeveloper 10.1.3.x and JDeveloper 11 Technical Preview 3 (TP 3). If you've to bet your project on it, start with JDeveloper 10.1.3.3. Migration options will be covered.<br></div><h3>Installation Verification</h3>Once everything is installed, we need to verify our setup.<br><h4>Verifying XE</h4>First start XE. On Windows and Linux you'll find an <span style="font-style: italic;">Oracle Database 10g Express Edition</span> menu with a <span style="font-style: italic;">Start Database</span> entry. After XE came up, you need to point your browser to the <span style="font-style: italic;">XE Homepage</span> (<span style="font-style: italic;">http://127.0.0.1:8080/apex/</span>). On the <span style="font-style: italic;">XE Homepage</span> you can log in to the XE management console and can check the data base settings. Log in by entering <span style="font-style: italic;">sys</span> and <span style="font-style: italic;">your password value </span>provided during the installation. To finish this step click on the <span style="font-style: italic;">Logout</span> link on the upper right corner.<br><h4>Verifying JDeveloper</h4>Now we're able to start JDeveloper. Depending on your JDeveloper download, you might be asked to supply the location of the JDK. On Windows, a window pops up and lets you browse to the java.exe file of your JDK. On Linux, you have to supply the home directory of the JDK installation (ie. /opt/java/jdk1.5.0_14 on my machine). Next, you'll see the JDeveloper splash screen which will be followed by the JDeveloper main window.<br><div style="margin-left: 40px;"><h5>Note: JDeveloper 11g TP 3</h5>The JDeveloper 11g TP3 release relies on the setting of the environment variable <span style="font-style: italic;">JDEV_USER_HOME</span> for your user directory. This is by default <span style="font-style: italic;">$HOME/JDeveloper</span>. On Windows this path includes white spaces (ie. <span style="font-style: italic;">c:\Documents and Settings\</span>) which is not recommended for this release.<br></div><h4>Verifying the Database Connection</h4>The last step for today is the setup of the database connection in JDeveloper.<br><h4>In 10.1.3.x</h4><ol><li>Click on the <span style="font-style: italic;">Connections Navigator</span> tab (upper left under the tool bar)</li><li>Select <span style="font-style: italic;">Database</span></li><li>Open the Context Menu and select <span style="font-style: italic;">New Database Connection...</span></li><li>A four step wizard appears.</li><li><span style="font-style: italic;">Step 1</span> - Enter the <span style="font-style: italic;">Connection Name</span> as sysXE</li><li><span style="font-style: italic;">Step 2</span> - Enter the <span style="font-style: italic;">Username</span> as sys, the <span style="font-style: italic;">Password</span> with your value, and the <span style="font-style: italic;">Role</span> as SYDBA</li><li><span style="font-style: italic;">Step 3</span> - Enter the <span style="font-style: italic;">Hostname</span> (localhost), the <span style="font-style: italic;">Port</span> (1521), and the <span style="font-style: italic;">SID</span> (XE)</li><li><span style="font-style: italic;">Step 4</span> - Test the connection by clicking on the <span style="font-style: italic;">Test Connection</span> button. This should show a <span style="font-style: italic;">Success!</span> message in the text area below.</li><li>Click on the <span style="font-style: italic;">Finish</span> button to close this wizard.</li></ol>Now you can find your newly created database connection in the Database folder in the <span style="font-style: italic;">Connection Navigator</span>.<br><h4>In 11g TP 3</h4><ol><li>Find the <span style="font-style: italic;">Resource Palette</span> (if not visible chose <span style="font-style: italic;">View-&gt;Resource Palette</span>)</li><li>Once available find the <span style="font-style: italic;">New</span> icon (a folder with a star on the upper right), click on it, a menu will appear.</li><li>Select the <span style="font-style: italic;">New Connection</span> sub-menu and select the <span style="font-style: italic;">Database</span> menu item.</li><li>In the <span style="font-style: italic;">Create Database Connection</span> window fill in the blanks with the similar values as above. <span style="font-style: italic;">Connection Name</span> sysXE, <span style="font-style: italic;">Username</span> sys, <span style="font-style: italic;">Password</span> your value, <span style="font-style: italic;">Role</span> SYSDBA from the drop down, <span style="font-style: italic;">Host Name </span>localhost, <span style="font-style: italic;">JDBC Port</span> 1521, <span style="font-style: italic;">SID</span> XE.</li><li>Click on the <span style="font-style: italic;">Test Connection</span> button and get the <span style="font-style: italic;">Success!</span> message in the text area below the button.</li><li>Before you close the window be sure to have the <span style="font-style: italic;">Create Connection In:</span><span style="font-style: italic;">IDE Connections (Resource Palette)</span> radio button checked.</li><li>Once everything is correct, click on the <span style="font-style: italic;">OK</span> button to close the window and create the connection in the <span style="font-style: italic;">Resource Palette</span>.</li></ol>   <h4>JDeveloper Differences So Far</h4>With this little setup chapter you have already seen a major difference between the JDeveloper 10.1.3.x and 11g TP3 versions:<br><ul><li>All connections are available as IDE-global in both versions.</li><li>11g adds application-specific connections which can differ from the global settings</li><li>In 11g the <span style="font-style: italic;">Create Database Connection</span> is now in one window only and much easier to use.</li></ul><h3>What's Next?</h3>So far so good, we have the gear ready now and are prepared to continue. In the next part we'll use JDeveloper's Database Modeler to create the database model and schema for the application we'll develop in this series. Stay tuned.<br><br></p>]]>
      
   </content>
</entry>
<entry>
   <title>ADF In Action: Starting a New Blog Series</title>
   <link rel="alternate" type="text/html" href="http://blogs.oracle.com/olaf/2008/01/adf_in_action_starting_a_new_b.html" />
   <id>tag:blogs.