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 Generate Database and Java Classes
Date Sun, 20 Dec 2009 17:50:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAYDOC&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><s>Tutorial Generate Database and Java Classes</s></h2>
     <h4>Page <b>removed</b> by             <a href="http://cwiki.apache.org/confluence/display/~andrus">Andrus
Adamchik</a>
    </h4>
     <br/>
     <div class="notificationGreySide">
         
<p>CayenneModeler can be used to generate both database schema and Java classes from
the single XML model. Very often the database already exists and is maintained independently
(e.g., by a DBA). In this case you won't have to go through the first part of this procedure.</p>

<h3><a name="TutorialGenerateDatabaseandJavaClasses-CreatingtheDatabase"></a>Creating
the Database</h3>

<ul>
	<li>Click on the DataMap node on the left and then select <tt>"Tools &gt;
Create Database Schema"</tt> from the menu. A connection dialog pops up with fields
prefilled with the data you entered for the DataNode.</li>
</ul>


<ul>
	<li>Leave it unchanged and click "Continue" - this will open a dialog with a SQL script
and several generation options.</li>
</ul>


<ul>
	<li>Leave the defaults on ("Create Tables", "Create FK Support", "Create Primary Key
Support") and click "Generate" - the database with the tables mapped during previous steps
will be created in the specified location. Since Derby uses a filesystem directory for the
database, you can actually navigate to it and see that the database is there.</li>
</ul>


<p><img src="/confluence/download/attachments/10627/db-generator.jpg" align="absmiddle"
border="0" /></p>

<h3><a name="TutorialGenerateDatabaseandJavaClasses-CreatingtheJavaClasses"></a>Creating
the Java Classes</h3>

<ul>
	<li>Now select <tt>"Tools &gt; Generate Classes"</tt> menu.</li>
	<li>For "Type" select "Standard Persistent Objects" if it is not already selected.</li>
	<li>For the output directory select "cayenne-tutorial/src" directory of your Eclipse
project</li>
	<li>Click "Generate"</li>
</ul>


<p><img src="/confluence/download/attachments/10627/class-generator.jpg" align="absmiddle"
border="0" /></p>

<p>Note that often you start by generating classes from the Modeler, but at the later
stages of the project the generation is usually automated via <a href="/confluence/display/CAYDOC/cgen"
title="cgen">Ant cgen task</a>. Both methods are interchangeable.</p>

<p>Now go back to Eclipse, right click on "cayenne-tutorial" project and select "Refresh"
- you should see a pair of classes generated for each mapped entity. Note that you should
not modify the classes whose names start with "_" (underscore), as they will be replaced on
subsequent generator runs. Instead all custom logic should be placed in their subclasses located
in <tt>"cayenne.tutorial"</tt> package - those will never be overwritten by the
class generator.</p>

<p><img src="/confluence/download/attachments/10627/eclipse-classes.jpg" align="absmiddle"
border="0" /></p>

<hr />
<p><b>Next Step: <a href="/confluence/display/CAYDOC/Tutorial+DataContext"
title="Tutorial DataContext">Tutorial DataContext</a></b></p>
<hr />
     </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message