cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Cayenne Documentation > Tutorial Starting Project
Date Sun, 13 Feb 2011 20:28:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2036/9/1/_/styles/combined.css?spaceKey=CAYDOC&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAYDOC/Tutorial+Starting+Project">Tutorial
Starting Project</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~andrus">Andrus
Adamchik</a>
    </h4>
        <br/>
                         <h4>Changes (0)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-unchanged" >The goal of this section is to create
a new Java project in Eclipse containing a basic Cayenne mapping. It presents an introduction
to CayenneModeler GUI tool, showing how to create the initial mapping objects: DataDomain,
DataNode, DataMap. <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h3. Create a new Project in Eclipse
 <br></td></tr>
            <tr><td class="diff-unchanged" > <br>In Eclipse select {{&quot;File
&gt; New &gt; Other...&quot;}} and then {{&quot;Maven &gt; Maven Project&quot;}}.
Click &quot;Next&quot;. On the following screen check &quot;Create a simple project&quot;
checkbox and click &quot;Next&quot; again. In the dialog shown on the screenshot below,
fill the &quot;Group Id&quot; and &quot;Artifact Id&quot; fields and click
&quot;Finish&quot;.  <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p>The goal of this section is to create a new Java project in Eclipse containing
a basic Cayenne mapping. It presents an introduction to CayenneModeler GUI tool, showing how
to create the initial mapping objects: DataDomain, DataNode, DataMap.</p>

<h3><a name="TutorialStartingProject-CreateanewProjectinEclipse"></a>Create
a new Project in Eclipse </h3>

<p>In Eclipse select <tt>"File &gt; New &gt; Other..."</tt> and
then <tt>"Maven &gt; Maven Project"</tt>. Click "Next". On the following screen
check "Create a simple project" checkbox and click "Next" again. In the dialog shown on the
screenshot below, fill the "Group Id" and "Artifact Id" fields and click "Finish". <br/>
<span class="image-wrap" style=""><img src="/confluence/download/attachments/24186445/tutorial-eclipse-project.png?version=1&amp;modificationDate=1289713366000"
style="border: 0px solid black" /></span></p>

<p>Now you should have a new empty project in the Eclipse workspace. Check that the
project Java compiler settings are correct. Rightclick on the "tutorial" project, select <tt>"Properties
&gt; Java Compiler"</tt> and ensure that "Compiler compliance level" is at least
"1.5" (some versions of Maven plugin seem to be setting it to 1.4 by default).</p>

<h3><a name="TutorialStartingProject-DownloadandStartCayenneModeler"></a>Download
and Start CayenneModeler</h3>

<p>Although later in this tutorial we'll be using Maven to include Cayenne runtime jars
in the project, you'll still need to download Cayenne to get access to the CayenneModeler
tool. </p>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td>If you are really into Maven,
you can <a href="/confluence/display/CAYDOC/maven2-modeler" title="maven2-modeler">start
CayenneModeler from Maven</a> if you wish. We'll do it in a more traditional way here.</td></tr></table></div>
 

<p>Download the latest release <a href="http://cayenne.apache.org/download.html"
class="external-link" rel="nofollow">from here</a>. Unpack the distribution somewhere
in the file system and start CayenneModeler, following <a href="/confluence/display/CAYDOC/Running+CayenneModeler"
title="Running CayenneModeler">platform-specific instructions</a>. On most platforms
it is done simply by doubleclicking the Modeler icon. The welcome screen of the Modeler looks
like this:</p>

<p><span class="image-wrap" style=""><img src="/confluence/download/attachments/24186445/modeler-started.png?version=1&amp;modificationDate=1289713364000"
style="border: 0px solid black" /></span></p>

<h3><a name="TutorialStartingProject-CreateaNewMappingProjectinCayenneModeler"></a>Create
a New Mapping Project in CayenneModeler</h3>

<p>Click on the "New Project" button on Welcome screen. A new mapping project will appear
that contains a single <b>DataDomain</b>. The meaning of a DataDomain is explained
elsewhere in the User Guide. For now it is sufficient to understand that DataDomain is the
root of your mapping project.</p>

<h3><a name="TutorialStartingProject-CreateaDataNode"></a>Create a DataNode</h3>

<p>The next project object you will create is a <b>DataNode</b>. DataNode
is a descriptor of a single database your application will connect to. Cayenne mapping project
can use more than one database, but for now, we'll only use one. With "UntitledDomain" selected
on the left, click on "Create DataNode" button on the toolbar (or select <tt>"Project
&gt; Create DataNode"</tt> from the menu.</p>

<p>A new DataNode is displayed. Now you need to specify JDBC connection parameters.
For an in-memory Derby database you can enter the following settings: </p>

<ul>
	<li>JDBC Driver: <tt>org.apache.derby.jdbc.EmbeddedDriver</tt></li>
	<li>DB URL: <tt>jdbc:derby:memory:testdb;create=true</tt></li>
</ul>


<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td>We are creating an in-memory database
here. So when you stop your application, all the data will be lost. In most real-life cases
you'll be connecting to a database that actually persists its data on disk, but an in-memory
DB will do for the simple tutorial.</td></tr></table></div>

<p>Also you will need to change "Schema Update Strategy". Select <tt>"org.apache.cayenne.access.dbsync.CreateIfNoSchemaStrategy"</tt>
from the dropdown, so that Cayenne creates a new schema on Derby based on the ORM mapping
when the application starts.</p>

<p><span class="image-wrap" style=""><img src="/confluence/download/attachments/24186445/base-datanode.png?version=1&amp;modificationDate=1289713359000"
style="border: 0px solid black" /></span></p>


<h3><a name="TutorialStartingProject-CreateaDataMap"></a>Create a DataMap</h3>

<p>Now you will create a <b>DataMap</b>. DataMap is an object that holds
all the mapping information. To create it, click on "Create DataMap" button (or select a corresponding
menu item). Note that the newly created DataMap is automatically linked to the DataNode that
you created in the previous step. If there is more than one DataNode, you may need to link
a DataMap to the correct node manually. In other words a DataMap within DataDomain must point
to a database described by the map.</p>

<p>You can leave all the DataMap defaults unchanged except for one - "Java Package".
Enter "org.example.cayenne.persistent". This name will later be used for all persistent classes.</p>

<p><span class="image-wrap" style=""><img src="/confluence/download/attachments/24186445/base-datamap.png?version=1&amp;modificationDate=1289713358000"
style="border: 0px solid black" /></span></p>

<h3><a name="TutorialStartingProject-SavetheProject"></a>Save the Project</h3>

<p>Before you proceed with the actual mapping, let's save the project. Click on "Save"
button in the toolbar and navigate to the <tt>"tutorial"</tt> Eclipse project
folder that was created earlier in this section and its <tt>"src/main/resources"</tt>
subfolder and save the project there. Now go back to Eclipse, right click on "tutorial" project
and select "Refresh", you will see three Cayenne XML files.</p>

<p><span class="image-wrap" style=""><img src="/confluence/download/attachments/24186445/eclipse-xmlfiles.png?version=1&amp;modificationDate=1289713363000"
style="border: 0px solid black" /></span></p>

<p>Note that the location of the XML files is not coincidental. Cayenne runtime looks
for <tt>"cayenne.xml"</tt> file in the application CLASSPATH and <tt>"src/main/resources"</tt>
folder should already be a "class folder" in Eclipse for our project (and is also a standard
location that Maven would copy to a jar file, if we were using Maven from command-line).</p>

<hr />
<p><b>Next Step: <a href="/confluence/display/CAYDOC/Tutorial+Object+Relational+Mapping"
title="Tutorial Object Relational Mapping">Tutorial Object Relational Mapping</a></b></p>
<hr />
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CAYDOC/Tutorial+Starting+Project">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=24186445&revisedVersion=2&originalVersion=1">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAYDOC/Tutorial+Starting+Project?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message