blob: c9d795bbdaecaae76d99b5015684eb7282f9fb71 [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;19.&nbsp;Introduction</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-part4.html" title="Part&nbsp;IV.&nbsp;DB-First Flow"><link rel="prev" href="cayenne-guide-part4.html" title="Part&nbsp;IV.&nbsp;DB-First Flow"><link rel="next" href="re-filtering.html" title="Chapter&nbsp;20.&nbsp;Filtering"><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;19.&nbsp;Introduction</th><th></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="cayenne-guide-part4.html">Prev</a>&nbsp;</td><th width="60%" align="center"><a accesskey="u" href="cayenne-guide-part4.html">Part&nbsp;IV.&nbsp;DB-First Flow</a></th><td width="20%" align="right">&nbsp;<a accesskey="n" href="re-filtering.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a name="re-introduction"></a>Chapter&nbsp;19.&nbsp;Introduction</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="section"><a href="re-introduction.html#what-is-cdbimport">"DB-first" Flow</a></span></dt><dt><span class="section"><a href="re-introduction.html#re-configuration-file">Introduction to "cdbimport"</a></span></dt></dl></div><div class="section"><div class="titlepage"><div><div><h2 class="title"><a name="what-is-cdbimport"></a>"DB-first" Flow</h2></div></div></div><p>An ORM system consists of three parts: database, OR mapping and persistent Java classes.
These parts always need to be kept in sync with each other for the application to work.
"DB-first" flow is a common and practical approach to synchronization that assumes the
database to be the master source of the metadata, with other two parts synchronized from
the DB as the schema evolves. Cayenne provides a number of tools to automate and control
it. Here is how "DB-first" flow is typically implemented:</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p> A SQL migrations framework is used to bring a local DB to a certain
version. This is outside of the scope of Cayenne and is done with a
third-party tool, such as Liquibase or Flyway.</p></li><li class="listitem"><p>OR mapping model (Cayenne XML files) are synchronized with the state of the database
using <code class="code">"cdbimport"</code> tool provdied by Cayenne.</p></li><li class="listitem"><p>Object layer of the OR mapping model is customized to the developer liking, usually via
CayenneModeler. Subsequent runs of <code class="code">"cdbimport"</code> will not
override any customizations that you make.</p></li><li class="listitem"><p>Java classes are generated using <code class="code">"cgen"</code> tool provided by Cayenne.</p></li></ul></div><p>"cgen" and "cdbimport" tools can be invoked from Maven or Ant as discussed in the
"Including Cayenne in a Project" chapter or run from CayenneModeler. This chapter will
mostly focus on "cdbimport". </p><p>
Here is simple maven configuration to start with:
</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title"><a name="re-configuration-file"></a>Introduction to "cdbimport"</h2></div></div></div><p>Here is a simple Maven configuration of "cdbimport" (for details see <a class="link" href="including-cayenne-in-project.html#mvn-cdbimport" title="cdbimport">cayenne-maven-plugin</a> documentation)</p><p>
</p><pre class="programlisting">
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;plugin&gt;</span>
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;groupId&gt;</span>org.apache.cayenne.plugins<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;/groupId&gt;</span>
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;artifactId&gt;</span>cayenne-maven-plugin<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;/artifactId&gt;</span>
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;version&gt;</span>4.0.M5<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;/version&gt;</span>
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;configuration&gt;</span>
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;map&gt;</span>${project.basedir}/src/main/resources/datamap.map.xml<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;/map&gt;</span>
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;dataSource&gt;</span>
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;url&gt;</span><span xmlns="http://www.w3.org/1999/xhtml" class="hl-comment">&lt;!-- jdbc url --&gt;</span><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;/url&gt;</span>
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;driver&gt;</span><span xmlns="http://www.w3.org/1999/xhtml" class="hl-comment">&lt;!-- jdbc driver class --&gt;</span><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;/driver&gt;</span>
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;username&gt;</span>username<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;/username&gt;</span>
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;password&gt;</span>password<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;/password&gt;</span>
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;/dataSource&gt;</span>
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;dbimport&gt;</span>
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;defaultPackage&gt;</span>com.example.package<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;/defaultPackage&gt;</span>
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;includeTable&gt;</span>.*<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;/includeTable&gt;</span>
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;/dbimport&gt;</span>
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;/configuration&gt;</span>
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;dependencies&gt;</span>
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-comment">&lt;!-- jdbc driver dependency --&gt;</span>
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;/dependencies&gt;</span>
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">&lt;/plugin&gt;</span>
</pre><p>
</p><p>In the next chapters we will discuss various filtering and other reverse-engineering
options.</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="cayenne-guide-part4.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="cayenne-guide-part4.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="re-filtering.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Part&nbsp;IV.&nbsp;DB-First Flow&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;Chapter&nbsp;20.&nbsp;Filtering</td></tr></table></div></body></html>