blob: 88d479196896ae84d1013729cdcb35030b02e16e [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title xmlns:d="http://docbook.org/ns/docbook">Chapter&nbsp;3.&nbsp;CayenneModeler Application</title><link rel="stylesheet" type="text/css" href="css/cayenne-doc.css"><meta xmlns:d="http://docbook.org/ns/docbook" name="keywords" content="Cayenne 4.0 documentation"><meta xmlns:d="http://docbook.org/ns/docbook" name="description" content="User documentation for Apache Cayenne version 4.0"><link rel="home" href="index.html" title="Cayenne Guide"><link rel="up" href="cayenne-guide-part1.html" title="Part&nbsp;I.&nbsp;Object Relational Mapping with Cayenne"><link rel="prev" href="cayenne-mapping-structure.html" title="Chapter&nbsp;2.&nbsp;Cayenne Mapping Structure"><link rel="next" href="cayenne-guide-part2.html" title="Part&nbsp;II.&nbsp;Cayenne Framework"><script xmlns:d="http://docbook.org/ns/docbook" type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-7036673-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div xmlns:d="http://docbook.org/ns/docbook" class="navheader"><table width="100%" summary="Navigation header"><tr><th class="versioninfo">v.4.0 (4.0.M5)</th><th align="center">Chapter&nbsp;3.&nbsp;CayenneModeler Application</th><th></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="cayenne-mapping-structure.html">Prev</a>&nbsp;</td><th width="60%" align="center"><a accesskey="u" href="cayenne-guide-part1.html">Part&nbsp;I.&nbsp;Object Relational Mapping with Cayenne</a></th><td width="20%" align="right">&nbsp;<a accesskey="n" href="cayenne-guide-part2.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a name="cayennemodeler-application"></a>Chapter&nbsp;3.&nbsp;CayenneModeler Application</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="section"><a href="cayennemodeler-application.html#working-with-mapping-projects">Working with Mapping Projects</a></span></dt><dt><span class="section"><a href="cayennemodeler-application.html#reverse-engineering-database">Reverse Engineering Database</a></span></dt><dt><span class="section"><a href="cayennemodeler-application.html#generating-database-schema">Generating Database Schema</a></span></dt><dt><span class="section"><a href="cayennemodeler-application.html#migrations">Migrations</a></span></dt><dt><span class="section"><a href="cayennemodeler-application.html#generating-java-classes">Generating Java Classes</a></span></dt><dt><span class="section"><a href="cayennemodeler-application.html#modeling-inheritance">Modeling Inheritance</a></span></dt><dt><span class="section"><a href="cayennemodeler-application.html#modeling-generic-persistence-classes">Modeling Generic Persistent Classes</a></span></dt><dt><span class="section"><a href="cayennemodeler-application.html#mapping-objattributes-to-custom-classes">Mapping ObjAttributes to Custom Classes</a></span></dt><dt><span class="section"><a href="cayennemodeler-application.html#modeling-pk-generation-strategy">Modeling Primary Key Generation Strategy</a></span></dt></dl></div><div class="section"><div class="titlepage"><div><div><h2 class="title"><a name="working-with-mapping-projects"></a>Working with Mapping Projects</h2></div></div></div><p></p></div><div class="section"><div class="titlepage"><div><div><h2 class="title"><a name="reverse-engineering-database"></a>Reverse Engineering Database</h2></div></div></div><p>
See chapter <a class="link" href="re-modeler.html" title="Chapter&nbsp;22.&nbsp;Reverse Engineering in Cayenne Modeler">Reverse Engineering in Cayenne Modeler</a>
</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title"><a name="generating-database-schema"></a>Generating Database Schema</h2></div></div></div><p>
With Cayenne Modeler you can create simple database schemas without any additional database tools.
This is a good option for initial database setup if you completely created you model with the Modeler.
You can start SQL schema generation by selecting menu
<span class="strong"><strong>
<span class="guimenu">Tools</span> &gt; <span class="guimenuitem">Generate Database Schema</span>
</strong></span>
</p><p>
You can select what database parts should be generated and what tables you want
</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title"><a name="migrations"></a>Migrations</h2></div></div></div><p> </p></div><div class="section"><div class="titlepage"><div><div><h2 class="title"><a name="generating-java-classes"></a>Generating Java Classes</h2></div></div></div><p>
Before using Cayenne in you code you need to generate java source code for persistent objects.
This can be done with Modeler GUI or via <a class="link" href="including-cayenne-in-project.html#mvn-cgen" title="cgen">cgen</a> maven/ant plugin.
</p><p>
To generate classes in the modeler use
<span class="strong"><strong>
<span class="guimenu">Tools</span> &gt; <span class="guimenuitem">Generate Classes</span>
</strong></span>
</p><p>
There is three default types of code generation
</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p><span class="strong"><strong>Standard Persistent Objects</strong></span></p><p>
Default type of generation suitable for almost all cases.
Use this type unless you now what exactly you need to customize.
</p></li><li class="listitem"><p><span class="strong"><strong>Client Persistent Objects</strong></span></p><p>
</p></li><li class="listitem"><p><span class="strong"><strong>Advanced.</strong></span></p><p>
In advanced mode you can control almost all aspects of code generation including custom templates for java code.
See default Cayenne templates on
<a class="link" href="https://github.com/apache/cayenne/tree/master/cayenne-tools/src/main/resources/templates/v1_2" target="_top">GitHub</a>
as an example
</p></li></ul></div><p>
</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title"><a name="modeling-inheritance"></a>Modeling Inheritance</h2></div></div></div><p> </p></div><div class="section"><div class="titlepage"><div><div><h2 class="title"><a name="modeling-generic-persistence-classes"></a>Modeling Generic Persistent Classes</h2></div></div></div><p>Normally each ObjEntity is mapped to a specific Java class (such as Artist or
Painting) that explicitly declare all entity properties as pairs of getters and setters.
However Cayenne allows to map a completly generic class to any number of entities. The
only expectation is that a generic class implements
<span class="emphasis"><em>org.apache.cayenne.DataObject</em></span>. So an ideal candidate for a
generic class is CayenneDataObject, or some custom subclass of CayenneDataObject.</p><p>If you don't enter anything for Java Class of an ObjEntity, Cayenne assumes generic
mapping and uses the following implicit rules to determine a class of a generic object.
If DataMap "Custom Superclass" is set, runtime uses this class to instantiate new
objects. If not, org.apache.cayenne.CayenneDataObject is used.</p><p>Class generation procedures (either done in the Modeler or with Ant or Maven) would
skip entities that are mapped to CayenneDataObject explicitly or have no class
mapping.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title"><a name="mapping-objattributes-to-custom-classes"></a>Mapping ObjAttributes to Custom Classes</h2></div></div></div><p> </p></div><div class="section"><div class="titlepage"><div><div><h2 class="title"><a name="modeling-pk-generation-strategy"></a>Modeling Primary Key Generation Strategy</h2></div></div></div><p> </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="cayenne-mapping-structure.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="cayenne-guide-part1.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="cayenne-guide-part2.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter&nbsp;2.&nbsp;Cayenne Mapping Structure&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;Part&nbsp;II.&nbsp;Cayenne Framework</td></tr></table></div></body></html>