<html><head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<title xmlns:d="http://docbook.org/ns/docbook">Chapter 19. 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 IV. DB-First Flow"><link rel="prev" href="cayenne-guide-part4.html" title="Part IV. DB-First Flow"><link rel="next" href="re-filtering.html" title="Chapter 20. 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 19. Introduction</th><th></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="cayenne-guide-part4.html">Prev</a> </td><th width="60%" align="center"><a accesskey="u" href="cayenne-guide-part4.html">Part IV. DB-First Flow</a></th><td width="20%" align="right"> <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 19. 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"><plugin></span> | |
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><groupId></span>org.apache.cayenne.plugins<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></groupId></span> | |
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><artifactId></span>cayenne-maven-plugin<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></artifactId></span> | |
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><version></span>4.0.M5<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></version></span> | |
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><configuration></span> | |
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><map></span>${project.basedir}/src/main/resources/datamap.map.xml<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></map></span> | |
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><dataSource></span> | |
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><url></span><span xmlns="http://www.w3.org/1999/xhtml" class="hl-comment"><!-- jdbc url --></span><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></url></span> | |
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><driver></span><span xmlns="http://www.w3.org/1999/xhtml" class="hl-comment"><!-- jdbc driver class --></span><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></driver></span> | |
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><username></span>username<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></username></span> | |
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><password></span>password<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></password></span> | |
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></dataSource></span> | |
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><dbimport></span> | |
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><defaultPackage></span>com.example.package<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></defaultPackage></span> | |
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><includeTable></span>.*<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></includeTable></span> | |
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></dbimport></span> | |
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></configuration></span> | |
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><dependencies></span> | |
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-comment"><!-- jdbc driver dependency --></span> | |
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></dependencies></span> | |
<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></plugin></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> </td><td width="20%" align="center"><a accesskey="u" href="cayenne-guide-part4.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="re-filtering.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Part IV. DB-First Flow </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 20. Filtering</td></tr></table></div></body></html> |