Added: cayenne/site/cms/trunk/content/docs/4.0/cayenne-guide/re-filtering.html URL: http://svn.apache.org/viewvc/cayenne/site/cms/trunk/content/docs/4.0/cayenne-guide/re-filtering.html?rev=1774214&view=auto ============================================================================== --- cayenne/site/cms/trunk/content/docs/4.0/cayenne-guide/re-filtering.html (added) +++ cayenne/site/cms/trunk/content/docs/4.0/cayenne-guide/re-filtering.html Wed Dec 14 13:19:08 2016 @@ -0,0 +1,257 @@ +<html><head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> + <title xmlns:d="http://docbook.org/ns/docbook">Chapter 20. Filtering</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="re-introduction.html" title="Chapter 19. Introduction"><link rel="next" href="re-relationships-loading-control.html" title="Chapter 21. Other Settings"><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-SNAPSHOT)</th><th align="center">Chapter 20. Filtering</th><th></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="re-introduction.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-relationships-loading-control.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a name="re-filtering"></a>Chapter 20. Filtering</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="section"><a href="re-filtering.html#everything-schema-catalog">Proces s everything from schema/catalog</a></span></dt><dt><span class="section"><a href="re-filtering.html#combine-schema-catalog">Combine Schema and Catalog filters</a></span></dt><dt><span class="section"><a href="re-filtering.html#including-excluding-tables-columns-procedures">Including and Excluding tables, columns and procedures</a></span></dt><dt><span class="section"><a href="re-filtering.html#complete-filtering-example">Complete filtering example</a></span></dt><dt><span class="section"><a href="re-filtering.html#d0e3286">Ant configuration example</a></span></dt></dl></div><p> + The first thing you usually want to control during reverse engineering is what exactly should be loaded from database and + what not. One of the most common cases is excluding system tables, as you usually don't want to map them. + </p><p> + Briefly, you are able to include/exclude tables, columns and procedures and do it at several levels: default, catalog, schema. + Although everything defined at the top level (default rules) will be applied for the nested elements, all rules from the most specific + areas will override general rules (i.e. rules from schemas override rules from catalogs and even more override default rules). + </p><p> + The following use-cases will provide you a better understanding of how filtering works and how you could use it. + </p><div class="section"><div class="titlepage"><div><div><h2 class="title"><a name="everything-schema-catalog"></a>Process everything from schema/catalog</h2></div></div></div><p> + The simplest example of reverse engineering is processing tables from one schema of catalog and there are several options to do this. + Basic syntax is described below: + </p><pre class="programlisting"><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><reverseEngineering></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-comment"><!-- Ant/Maven in case you only want to specify the schema to import --></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><schema></span>SCHEMA_NAME<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></schema></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-comment"><!-- Maven way in case you have nested elements in the schema --></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><schema></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><name></span>SCHEMA_NAME<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></name></span> + ... + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></schema></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-comment"><!-- Ant way in case you have nested elements in the schema --></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><schema</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-attribute">name</span>=<span xmlns="http://www.w3.org/1999/xhtml" class="hl-value">"SCHEMA_NAME"</span><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">></span> + ... + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></schema></span> +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></reverseEngineering></span> </pre><p> + The same options are available for catalogs: + </p><pre class="programlisting"> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><reverseEngineering></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-comment"><!-- Ant/Maven in case you only want to specify the catalog to import --></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><catalog></span>CATALOG_NAME<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></catalog></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-comment"><!-- Maven way in case you have nested elements in the catalog --></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><catalog></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><name></span>CATALOG_NAME<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></name></span> + ... + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></catalog></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-comment"><!-- Ant way in case you have nested elements in the catalog --></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><catalog</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-attribute">name</span>=<span xmlns="http://www.w3.org/1999/xhtml" class="hl-value">"CATALOG_NAME"</span><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">></span> + ... + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></catalog></span> +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></reverseEngineering></span></pre><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>Current version of reverse engineering doesn't support catalog filtering for Postgres database.</p></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title"><a name="combine-schema-catalog"></a>Combine Schema and Catalog filters</h2></div></div></div><p> + Cayenne supports combination of different schemas and catalogs, and it filters data according to your requirements. + You could achieve this by the following example of reverse engineering configuration: + </p><pre class="programlisting"><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><reverseEngineering></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><catalog></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><name></span>shop_01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></name></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><schema></span>schema-name-01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></schema></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><schema></span>schema-name-02<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></schema></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><schema></span>schema-name-03<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></schema></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></catalog></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><catalog></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><name></span>shop_02<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></name></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><schema></span>schema-name-01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></schema></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></catalog></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><catalog></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><name></span>shop_03<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></name></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><schema></span>schema-name-01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></schema></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><schema></span>schema-name-02<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></schema></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><schema></span>schema-name-03<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></schema></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></catalog></span> + +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></reverseEngineering></span></pre><p> + In the example above, Cayenne reverse engineering process contains three catalogs named as shop_01, shop_02 and shop_03, + each of wich has their own schemas. Cayenne will load all data only from the declared catalogs and schemas. + </p><p> + If you want to load everything from database, you could simply declare catalog specification alone. + </p><pre class="programlisting"><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><reverseEngineering></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><catalog></span>shop_01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></catalog></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><catalog></span>shop_02<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></catalog></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><catalog></span>shop_03<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></catalog></span> + +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></reverseEngineering></span></pre><p> + If you want to do reverse engineering for specific schemas, just remove unwanted schemas from the catalog section. + For example, if you want to process schema-name-01 and schema-name-03 schemas only, then you should change reverse engineering section like this. + </p><pre class="programlisting"><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><reverseEngineering></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><catalog></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><name></span>shop_01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></name></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><schema></span>schema-name-01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></schema></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><schema></span>schema-name-03<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></schema></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></catalog></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><catalog></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><name></span>shop_02<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></name></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><schema></span>schema-name-01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></schema></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></catalog></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><catalog></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><name></span>shop_03<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></name></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><schema></span>schema-name-01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></schema></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><schema></span>schema-name-03<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></schema></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></catalog></span> + +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></reverseEngineering></span></pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title"><a name="including-excluding-tables-columns-procedures"></a>Including and Excluding tables, columns and procedures</h2></div></div></div><p> + Cayenne reverse engineering let you fine tune table, columns and stored procedures names that you need to import + to your model file. In every filter you can use regexp syntax. Here is some examples of configuration + for common tasks. + </p><p> + </p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"><p>Include tables with ‘CRM_’ prefix if you are working in that domain of application:</p><pre class="programlisting"><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><includeTable></span>CRM_.*<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></includeTable></span></pre></li><li class="listitem"><p>Include tables with ‘_LOOKUP’ suffix</p><pre class="programlisting"><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><includeTable></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><pattern></span>.*_LOOKUP<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></pattern></span> +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></includeTable></span></pre></li><li class="listitem"><p>Exclude tables with ‘CRM_’ prefix if you are not working only in that domain of application:</p><pre class="programlisting"><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><excludeTable></span>CRM_.*<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></excludeTable></span></pre></li><li class="listitem"><p>Include only specific columns that follows specific naming convention:</p><pre class="programlisting"><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><includeColumn></span>includeColumn01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></includeColumn></span> +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><includeColumn></span>includeColumn03<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></includeColumn></span></pre></li><li class="listitem"><p>Exclude system or obsolete columns:</p><pre class="programlisting"><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><excludeColumn></span>excludeColumn01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></excludeColumn></span> +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><excludeColumn></span>excludeColumn03<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></excludeColumn></span></pre></li><li class="listitem"><p>Include/Exclude columns for particular table or group of tables:</p><pre class="programlisting"><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><includeTable></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><pattern></span>table pattern<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></pattern></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><includeColumn></span>includeColumn01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></includeColumn></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><excludeColumn></span>excludeColumn01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></excludeColumn></span> +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></includeTable></span></pre></li><li class="listitem"><p>Include stored procedures:</p><pre class="programlisting"><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><includeProcedure></span>includeProcedure01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></includeProcedure></span> +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><includeProcedure></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><pattern></span>includeProcedure03<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></pattern></span> +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></includeProcedure></span></pre></li><li class="listitem"><p>Exclude stored procedures by pattern:</p><pre class="programlisting"><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><excludeProcedure></span>excludeProcedure01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></excludeProcedure></span> +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><excludeProcedure></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><pattern></span>excludeProcedure03<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></pattern></span> +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></excludeProcedure></span></pre></li></ol></div><p> + </p><p> All filtering tags <code class="code"><includeTable></code>, + <code class="code"><excludeTable></code>, <code class="code"><includeColumn></code>, + <code class="code"><excludeColumn></code>, <code class="code"><includeProcedure></code> and + <code class="code"><excludeProcedure></code> have 2 ways to pass filtering RegExp. + </p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"><p>text inside tag</p><pre class="programlisting"> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><includeTable></span>CRM_.*<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></includeTable></span></pre></li><li class="listitem"><p>pattern inner tag</p><pre class="programlisting"> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><includeTable></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><pattern></span>.*_LOOKUP<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></pattern></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></includeTable></span></pre></li></ol></div><p> + </p><p> + All filtering tags can be placed inside schema and catalog tags, but also inside <code class="code"><reverseEngineering></code> tag. It means that filtering rules + will be applied for all schemas and catalogs. + </p></div><div class="section"><div class="titlepage"><div><div><h2 class="title"><a name="complete-filtering-example"></a>Complete filtering example</h2></div></div></div><p> + Initially, let’s make a small sample. Consider the following reverse engineering configuration. + </p><pre class="programlisting"><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><reverseEngineering></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><catalog></span>shop-01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></catalog></span> +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></reverseEngineering></span> </pre><p> + In this case reverse engineering will not filter anything from the shop-01 catalog. If you really want to filter database columns, tables, + stored procedures and relationships, you could do it in the following way. + </p><pre class="programlisting"><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><reverseEngineering></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><catalog></span>shop-01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></catalog></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><catalog></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><name></span>shop-02<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></name></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><includeTable></span>includeTable-01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></includeTable></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></catalog></span> +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></reverseEngineering></span></pre><p> + Then Cayenne will do reverse engineering for both shop-01 and shop-02 catalogs. First catalog will not be processed for filtering, + but the second catalog will be processed with “includeTable-01” filter. + </p><p> + Let’s assume you have a lot of table prefixes with the same names. Cayenne allows you to mention a pattern as regular expression. + Using regular expressions is easier way to handle a big amount of database entities than writing filter config for each use-case. + They make your configuration more readable, understandable and straightforward. There is not complex. + Let’s see how to use patterns in reverse engineering configuration with complete example. + </p><pre class="programlisting"><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><reverseEngineering></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><catalog></span>shop-01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></catalog></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><catalog></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><name></span>shop-02<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></name></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></catalog></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><catalog></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><name></span>shop-03<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></name></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><includeTable></span>includeTable-01<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"><pattern></span>includeTable-02<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></pattern></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"><pattern></span>includeTable-03<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></pattern></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><includeColumn></span>includeColumn-01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></includeColumn></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><excludeColumn></span>excludeColumn-01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></excludeColumn></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"><excludeTable></span>excludeTable-01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></excludeTable></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><excludeTable></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><pattern></span>excludeTable-02<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></pattern></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></excludeTable></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><includeColumn></span>includeColumn-01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></includeColumn></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><includeColumn></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><pattern></span>includeColumn-02<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></pattern></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></includeColumn></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><excludeColumn></span>excludeColumn-01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></excludeColumn></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><excludeColumn></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><pattern></span>excludeColumn-02<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></pattern></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></excludeColumn></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><includeProcedure></span>includeProcedure-01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></includeProcedure></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><includeProcedure></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><pattern></span>includeProcedure-02<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></pattern></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></includeProcedure></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><excludeProcedure></span>excludeProcedure-01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></excludeProcedure></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><excludeProcedure></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><pattern></span>excludeProcedure-02<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></pattern></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></excludeProcedure></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></catalog></span> +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></reverseEngineering></span></pre><p>The example above should provide you more idea about how to use filtering and patterns + in Cayenne reverse engineering. You could notice that this example demonstrates you the + "name" and "pattern" configurations. Yes, you could use these as separates xml element + and xml attributes. </p><p> + The cdbimport will execute reverse engineering task for all entities from “shop-01” and “shop-02”, including tables, views, stored procedures + and table columns. As “shop-03” has variety filter tags, entities from this catalog will be filtered by cdbimport. + </p></div><div class="section"><div class="titlepage"><div><div><h2 class="title"><a name="d0e3286"></a>Ant configuration example</h2></div></div></div><p> Here is config sample for <code class="code">Ant</code> task: + </p><pre class="programlisting"><span xmlns="http://www.w3.org/1999/xhtml" class="hl-comment"><!-- inside <cdbimport> tag --></span> +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><catalog></span>shop-01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></catalog></span> + +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><catalog</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-attribute">name</span>=<span xmlns="http://www.w3.org/1999/xhtml" class="hl-value">"shop-02"</span><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">/></span> + +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><catalog</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-attribute">name</span>=<span xmlns="http://www.w3.org/1999/xhtml" class="hl-value">"shop-03"</span><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><includeTable></span>includeTable-01<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-attribute">pattern</span>=<span xmlns="http://www.w3.org/1999/xhtml" class="hl-value">"includeTable-02"</span><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">/></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><includeTable</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-attribute">pattern</span>=<span xmlns="http://www.w3.org/1999/xhtml" class="hl-value">"includeTable-03"</span><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><includeColumn></span>includeColumn-01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></includeColumn></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><excludeColumn></span>excludeColumn-01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></excludeColumn></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"><excludeTable></span>excludeTable-01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></excludeTable></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><excludeTable</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-attribute">pattern</span>=<span xmlns="http://www.w3.org/1999/xhtml" class="hl-value">"excludeTable-02"</span><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">/></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><includeColumn></span>includeColumn-01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></includeColumn></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><includeColumn</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-attribute">pattern</span>=<span xmlns="http://www.w3.org/1999/xhtml" class="hl-value">"includeColumn-02"</span><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">/></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><excludeColumn></span>excludeColumn-01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></excludeColumn></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><excludeColumn</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-attribute">pattern</span>=<span xmlns="http://www.w3.org/1999/xhtml" class="hl-value">"excludeColumn-02"</span><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">/></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><includeProcedure></span>includeProcedure-01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></includeProcedure></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><includeProcedure</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-attribute">pattern</span>=<span xmlns="http://www.w3.org/1999/xhtml" class="hl-value">"includeProcedure-02"</span><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">/></span> + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><excludeProcedure></span>excludeProcedure-01<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></excludeProcedure></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><excludeProcedure</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-attribute">pattern</span>=<span xmlns="http://www.w3.org/1999/xhtml" class="hl-value">"excludeProcedure-02"</span><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag">/></span> + +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></catalog></span></pre><p> + </p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p> + In Ant task configuration all filter tags located inside root tag <code class="code"><cdbimport></code> as there is no <code class="code"><reverseEngineering></code> tag. + </p></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="re-introduction.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-relationships-loading-control.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 19. Introduction </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 21. Other Settings</td></tr></table></div></body></html> \ No newline at end of file
Added: cayenne/site/cms/trunk/content/docs/4.0/cayenne-guide/re-introduction.html URL: http://svn.apache.org/viewvc/cayenne/site/cms/trunk/content/docs/4.0/cayenne-guide/re-introduction.html?rev=1774214&view=auto ============================================================================== --- cayenne/site/cms/trunk/content/docs/4.0/cayenne-guide/re-introduction.html (added) +++ cayenne/site/cms/trunk/content/docs/4.0/cayenne-guide/re-introduction.html Wed Dec 14 13:19:08 2016 @@ -0,0 +1,52 @@ +<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-SNAPSHOT)</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">maven-cayenne-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>maven-cayenne-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-SNAPSHOT<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"><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"><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"><reverseEngineering></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"></reverseEngineering></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> \ No newline at end of file Added: cayenne/site/cms/trunk/content/docs/4.0/cayenne-guide/re-modeler.html URL: http://svn.apache.org/viewvc/cayenne/site/cms/trunk/content/docs/4.0/cayenne-guide/re-modeler.html?rev=1774214&view=auto ============================================================================== --- cayenne/site/cms/trunk/content/docs/4.0/cayenne-guide/re-modeler.html (added) +++ cayenne/site/cms/trunk/content/docs/4.0/cayenne-guide/re-modeler.html Wed Dec 14 13:19:08 2016 @@ -0,0 +1,42 @@ +<html><head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> + <title xmlns:d="http://docbook.org/ns/docbook">Chapter 22. Reverse Engineering in Cayenne Modeler</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="re-relationships-loading-control.html" title="Chapter 21. Other Settings"><link rel="next" href="configuration-properties.html" title="Appendix A. Configuration Properties"><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-SNAPSHOT)</th><th align="center">Chapter 22. Reverse Engineering in Cayenne Modeler</th><th></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="re-relationships-loading-control.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="configuration-properties.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a name="re-modeler"></a>Chapter 22. Reverse Engineering in Cayenne Modeler</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="sect ion"><a href="re-modeler.html#modeler-re-datasource">DataSource selection</a></span></dt><dt><span class="section"><a href="re-modeler.html#modeler-re-options">Reverse engineering options</a></span></dt></dl></div><p>Alternative aproach to using <a class="link" href="re-introduction.html#what-is-cdbimport" title=""DB-first" Flow">cdbimport </a> is doing + reverse engineering from <a class="link" href="setup.html#running-cayennemodeler" title="Running CayenneModeler">Cayenne Modeler</a>. + Currently modeler GUI doesn't support all features of ant/maven tasks but it suffice for + general DB import. Especially it's a good place to quickly start working on your data model. </p><p> + You can find reverse engineering tool in main modeler menu + <span class="strong"><strong> + <span class="guimenu">Tools</span> > <span class="guimenuitem">Reengineer Database Schema</span> + </strong></span> + </p><div class="section"><div class="titlepage"><div><div><h2 class="title"><a name="modeler-re-datasource"></a>DataSource selection</h2></div></div></div><p>First you should select DataSource. If you don't have any DataSource + yet you can create one from this menu. + </p><div class="mediaobject"><img src="images/re-modeler-datasource-select.png" alt="Datasource selection dialog"><div class="caption"><p>Datasource selection dialog.</p></div></div><p> + </p></div><div class="section"><div class="titlepage"><div><div><h2 class="title"><a name="modeler-re-options"></a>Reverse engineering options</h2></div></div></div><p>Once DataSource is selected you can proceed to reverse engineering + options. + </p><div class="mediaobject"><img src="images/re-modeler-reverseengineering-dialog.png" alt="Reverse Engineering dialog"><div class="caption"><p>Reverse Engineering dialog.</p></div></div><p> + </p><p> + Here is a list of options to tune what will be processed by reverse engineering: + </p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p><span class="strong"><strong>Select Catalog</strong></span>: + catalog to process + </p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>You can only select one catalog. If you need to import multiple catalogs you need to run process several times.</p></div><p> + </p></li><li class="listitem"><p><span class="strong"><strong>Table Name Pattern</strong></span>: + RegExp to filter tables. Default pattern <code class="code">.*</code> includes all tables. + </p></li><li class="listitem"><p><span class="strong"><strong>Procedure Name Pattern</strong></span>: + RegExp to filter procedures. Default pattern <code class="code">.*</code> includes all stored procedures. + </p></li><li class="listitem"><p><span class="strong"><strong>Naming Strategy</strong></span>: + Currently there is only one naming strategy available. + See ant/maven tools <a class="link" href="">documentation</a> for details about naming strategy. + </p></li><li class="listitem"><p><span class="strong"><strong>Tables with Meaningful PK Pattern</strong></span>: + Comma separated list of RegExp's for tables that you want to have meaningful primary keys. + By default no meaningful PKs are created. + </p></li></ul></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="re-relationships-loading-control.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="configuration-properties.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 21. Other Settings </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Appendix A. Configuration Properties</td></tr></table></div></body></html> \ No newline at end of file Added: cayenne/site/cms/trunk/content/docs/4.0/cayenne-guide/re-relationships-loading-control.html URL: http://svn.apache.org/viewvc/cayenne/site/cms/trunk/content/docs/4.0/cayenne-guide/re-relationships-loading-control.html?rev=1774214&view=auto ============================================================================== --- cayenne/site/cms/trunk/content/docs/4.0/cayenne-guide/re-relationships-loading-control.html (added) +++ cayenne/site/cms/trunk/content/docs/4.0/cayenne-guide/re-relationships-loading-control.html Wed Dec 14 13:19:08 2016 @@ -0,0 +1,39 @@ +<html><head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> + <title xmlns:d="http://docbook.org/ns/docbook">Chapter 21. Other Settings</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="re-filtering.html" title="Chapter 20. Filtering"><link rel="next" href="re-modeler.html" title="Chapter 22. Reverse Engineering in Cayenne Modeler"><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-SNAPSHOT)</th><th align="center">Chapter 21. Other Settings</th><th></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="re-filtering.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-modeler.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a name="re-relationships-loading-control"></a>Chapter 21. Other Settings</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="section"><a href="re-relationships-loading-control.html#skip-rel ationships-loading">Skip Relationships Loading</a></span></dt><dt><span class="section"><a href="re-relationships-loading-control.html#skip-pk-loading">Skip Primary Keys Loading</a></span></dt><dt><span class="section"><a href="re-relationships-loading-control.html#d0e3332">Table Types</a></span></dt></dl></div><p> + In databases relations are defined via foreign keys and there are a lot of different politics according to the level of relationships and + ways how those relationships could be modeled in database. Anyway, cdbimport is able to recognize basic patterns of relationships, such as + OneToMany, OneToOne and ManyToMany. + </p><div class="section"><div class="titlepage"><div><div><h2 class="title"><a name="skip-relationships-loading"></a>Skip Relationships Loading</h2></div></div></div><p> + You are able to skip relationships loading by the <code class="code"><skipRelationshipsLoading></code> element. + </p><pre class="programlisting"> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><reverseEngineering></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><skipRelationshipsLoading></span>true<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><skipRelationshipsLoading></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></reverseEngineering></span></pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title"><a name="skip-pk-loading"></a>Skip Primary Keys Loading</h2></div></div></div><p> + Another useful Cayenne reverse engineering property is <code class="code"><skipPrimaryKeyLoading></code>. If you decide to support all relationships at the application layer + and avoid their management in database, you’ll find useful to turn off primary keys synchronization at all. + </p><pre class="programlisting"> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><reverseEngineering></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><skipPrimaryKeyLoading></span>true<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><skipPrimaryKeyLoading></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></reverseEngineering></span></pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title"><a name="d0e3332"></a>Table Types</h2></div></div></div><p>By default, cdbimport imports tables and views. Some databases may support other + table-like objects, e.g. <code class="code">SYSTEM TABLE, GLOBAL TEMPORARY, LOCAL TEMPORARY, ALIAS, + SYNONYM</code>, etc. To control which types should be included <code class="code"><tableType></tableType></code> element is used. Some examples:</p><p> Import tables only (skip views and others and other + types):</p><pre class="programlisting"> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><reverseEngineering></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><tableType></span>TABLE<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></tableType></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></reverseEngineering></span></pre><p> + </p><p> Tables and views (<span class="emphasis"><em>the default + option</em></span>):</p><pre class="programlisting"> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><reverseEngineering></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><tableType></span>TABLE<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></tableType></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><tableType></span>VIEWS<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></tableType></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></reverseEngineering></span></pre></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="re-filtering.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-modeler.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 20. Filtering </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 22. Reverse Engineering in Cayenne Modeler</td></tr></table></div></body></html> \ No newline at end of file Added: cayenne/site/cms/trunk/content/docs/4.0/tutorial-reverse-engineering/ch01.html URL: http://svn.apache.org/viewvc/cayenne/site/cms/trunk/content/docs/4.0/tutorial-reverse-engineering/ch01.html?rev=1774214&view=auto ============================================================================== --- cayenne/site/cms/trunk/content/docs/4.0/tutorial-reverse-engineering/ch01.html (added) +++ cayenne/site/cms/trunk/content/docs/4.0/tutorial-reverse-engineering/ch01.html Wed Dec 14 13:19:08 2016 @@ -0,0 +1,244 @@ +<html><head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> + <title xmlns:d="http://docbook.org/ns/docbook">Chapter 1. Introduction and Basic Usage</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="Getting Started with Cayenne Reverse Engineering"><link rel="up" href="index.html" title="Getting Started with Cayenne Reverse Engineering"><link rel="prev" href="index.html" title="Getting Started with Cayenne Reverse Engineering"><link rel="next" href="ch02.html" title="Chapter 2. A few hands-on examples"><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.M4-SNAPSHOT)</th><th align="center">Chapter 1. Introduction and Basic Usage</th><th></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="index.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ch02.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="d0e20"></a>Chapter 1. Introduction and Basic Usage</h1></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="section"><a href="ch01.html#introduction">Introduction</a></span></dt><dt><span class="section"><a href="ch01.html#basic-usage">Basic Usage</a></span></dt></ dl></div><div class="section"><div class="titlepage"><div><div><h2 class="title"><a name="introduction"></a>Introduction</h2></div></div></div><p>In Java development there is a well known problem about synchronization Java domain + model and relationship model in database. Let’s assume you are working on one of + a shopping application, some of your domain model classes would be Product, Order, + Shopping Cart and Customer. Considering the above sentence, we have a Java class and database + table name called “Customer”.</p><p>Java Class:</p><pre class="programlisting"><span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">public</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">class</span> Customer { + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">private</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">int</span> id; + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">private</span> String name; + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">public</span> Customer(){ + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-comment">// to do your instance initialization stuff here</span> + } + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">public</span> Customer(<span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">int</span> id,String name){ + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">this</span>.id = id; + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">this</span>.name = name; + } + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-comment">// getter and setter method goes here</span> + +}</pre><p>Database:</p><pre class="programlisting"><span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">CREATE</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">TABLE</span> `customer` ( +`id` <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">INT</span>(<span xmlns="http://www.w3.org/1999/xhtml" class="hl-number">11</span>) <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">NOT</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">NULL</span>, +`<span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">name</span>` <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">VARCHAR</span>(<span xmlns="http://www.w3.org/1999/xhtml" class="hl-number">45</span>) <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">DEFAULT</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">NULL</span>, +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">PRIMARY</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">KEY</span> (`id`));</pre><p> + <span class="inlinemediaobject"><img src="images/customer1.png"></span> + </p><p>Let’s assume you have to split Customer model “name” field as First name and Last Name + due to the client requirement. In that case you have to update both Java class and table model manually. + </p><p>Java Class:</p><pre class="programlisting"><span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">public</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">class</span> Customer { + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">private</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">int</span> id; + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">private</span> String firstname; + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">private</span> String lastname; + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">public</span> Customer(){ + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-comment">// to do your instance initialization stuff here</span> + } + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">public</span> Customer(<span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">int</span> id,String fname,String lname){ + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">this</span>.id = id; + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">this</span>.firstname = fname; + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">this</span>.lastname = lname; + } + + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-comment">// getter and setter method goes here</span> +}</pre><p>Database:</p><pre class="programlisting"><span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">CREATE</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">TABLE</span> `customer` ( +`id` <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">INT</span>(<span xmlns="http://www.w3.org/1999/xhtml" class="hl-number">11</span>) <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">NOT</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">NULL</span>, +`firstname` <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">VARCHAR</span>(<span xmlns="http://www.w3.org/1999/xhtml" class="hl-number">45</span>) <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">DEFAULT</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">NULL</span>, +`lastname` <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">VARCHAR</span>(<span xmlns="http://www.w3.org/1999/xhtml" class="hl-number">45</span>) <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">DEFAULT</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">NULL</span>, +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">PRIMARY</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">KEY</span> (`id`));</pre><p> + <span class="inlinemediaobject"><img src="images/customer2.png"></span> + </p><p> + In the above example, synchronization of domain model and database relationship model is manually + updated by Java developers. In this situation we have to keep both copies of Java classes and + database tables up to date manually. If you change something in db, that changes should be reflected + in Java classes. Likewise all Java classes changes should be reflected in database. + Although it can be automated manually, it will take some cost of time. + </p><p> + However, Cayenne automates this process with a minimum cost of time. It has two options for this automation process: + </p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>Forward Engineering - Generating db schema according to the Java classes.</p></li><li class="listitem"><p>Reverse Engineering - Updating Java classes according to the database schema.</p></li></ul></div><p> + + The reverse engineering tool is called CDBImport. + </p></div><div class="section"><div class="titlepage"><div><div><h2 class="title"><a name="basic-usage"></a>Basic Usage</h2></div></div></div><p> + CDBImport is a Maven/Ant plugin that helps you to do reverse engineering. In other words it helps you to synchronize + database structure with your Cayenne mapping config. It does not update Java classes by itself, but it synchronizes db + and data access layer representation in Cayenne mapping file with actual database state. + Most common practice to complete reverse engineering is to use CDBImport followed by CGen Maven plugin, + which does class generation according to the Cayenne mapping file updates. + </p><p> + You could use CDBImport Maven plugin by declaring and configuring it in your pom.xml. + See an example with comments below: + </p><pre class="programlisting"><span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><profile></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-comment"><!-- Here we define a profile with cdbimport and cgen configurations. + For sure you could define all plugins in general build section, but it will be time consuming + during each build to load database structure and check it for changes. Also, you will probably want to + control when exactly reverse engineering happens in order to correct its results if necessary. --></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><id></span>ormsync<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></id></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><build></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><plugins></span> + <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>maven-cayenne-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.M4-SNAPSHOT<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></version></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><executions></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><execution></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><id></span>ormsync<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></id></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><goals></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-comment"><!-- Again, cdbimport is a part of reverse engineering process. + Next step is generating Java classes according to their mapping by cgen. --></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><goal></span>cdbimport<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></goal></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><goal></span>cgen<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></goal></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></goals></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><configuration></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-comment"><!-- At first, we have to define database connection information + from which the structure will be loaded. --></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><driver></span>com.mysql.jdbc.Driver<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></driver></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><url></span>jdbc:mysql://127.0.0.1:3306/test<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></url></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><username></span>root<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></username></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-comment"><!--<password>password</password>--></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-comment"><!-- Next step is to define mapping file, which we are going to use. + If it doesn't exist, it will be created automatically after the first plugin execution. + Here you could also define some mapping properties. It isn't necessary for cdbimport task, but it will be used by cgen. --></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><map></span>${project.basedir}/src/main/resources/shopping.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"><defaultPackage></span>org.apache.cayenne.shopping<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></defaultPackage></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><superPkg></span>org.apache.cayenne.shopping.auto<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></superPkg></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-comment"><!-- Last part of configuration is reverse engineering tuning. + Here we just define which catalogs we want to process and which tables should be excluded. + You could find detailed description of possible configurations in the </span><a class="link" href="http://cayenne.apache.org/docs/4.0/cayenne-guide/including-cayenne-in-project.html#mvn-cdbimport" target="_top">documentation</a>. --> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><reverseEngineering></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><catalog></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><name></span>test<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></name></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><excludeTable></span>system_patch<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></excludeTable></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><excludeTable></span>v_*<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></excludeTable></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><excludeTable></span>*_view<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></excludeTable></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></catalog></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></reverseEngineering></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"></execution></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></executions></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"><!-- Also, you have to add JDBC driver dependency. --></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><dependency></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"><groupId></span>mysql<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>mysql-connector-java<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>5.1.28<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></version></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></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> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></plugins></span> + <span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></build></span> +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-tag"></profile></span></pre><p> + Let’s consider that shopping application consists of the following tables and relationships in database. + Initially, we are going to take customer, order tables and one foreign key relationship between them. + </p><p>Database:</p><pre class="programlisting"><span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">CREATE</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">TABLE</span> `customer` ( +`id` <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">INT</span>(<span xmlns="http://www.w3.org/1999/xhtml" class="hl-number">11</span>) <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">NOT</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">NULL</span>, +`<span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">name</span>` <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">VARCHAR</span>(<span xmlns="http://www.w3.org/1999/xhtml" class="hl-number">50</span>) <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">DEFAULT</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">NULL</span>, +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">PRIMARY</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">KEY</span> (`id`)); + +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">CREATE</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">TABLE</span> `<span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">order</span>` ( +`id` <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">INT</span>(<span xmlns="http://www.w3.org/1999/xhtml" class="hl-number">11</span>) <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">NOT</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">NULL</span>, +`amount` <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">DECIMAL</span>(<span xmlns="http://www.w3.org/1999/xhtml" class="hl-number">6</span>,<span xmlns="http://www.w3.org/1999/xhtml" class="hl-number">2</span>) <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">DEFAULT</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">NULL</span>, +`customer_id` <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">INT</span>(<span xmlns="http://www.w3.org/1999/xhtml" class="hl-number">11</span>) <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">DEFAULT</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">NULL</span>, +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">PRIMARY</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">KEY</span> (`id`), +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">KEY</span> `fk_customers_id_idx` (`customer_id`), +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">CONSTRAINT</span> `fk_customers_id_refference` <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">FOREIGN</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">KEY</span> (`customer_id`) <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">REFERENCES</span> `customer` (`id`) +<span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">ON</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">DELETE</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">CASCADE</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">ON</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">UPDATE</span> <span xmlns="http://www.w3.org/1999/xhtml" class="hl-keyword">CASCADE</span>);</pre><p> + <span class="inlinemediaobject"><img src="images/customer-order.png"></span> + </p><p> + Now, please arrange the profile above for your custom DB settings. That’s all you need to do for reverse + engineering with Cayenne. Now you are able to run the reverse engineering task as described below. + </p><pre class="screen"><code class="prompt">$</code> mvn compile -Pormsync</pre><p>The output should look like this:</p><pre class="screen">[INFO] Scanning for projects... +[INFO] +[INFO] ------------------------------------------------------------------------ +[INFO] Building MySQLTest 0.0.1-SNAPSHOT +[INFO] ------------------------------------------------------------------------ +[INFO] +[INFO] --- maven-cayenne-plugin:4.0.M3:cdbimport (ormsync) @ MySQLTest --- +Aug 16, 2016 3:36:41 PM org.apache.cayenne.datasource.DriverDataSource logConnect +INFO: Connecting to 'jdbc:mysql://127.0.0.1:3306/test' as 'root' +Aug 16, 2016 3:36:41 PM org.apache.cayenne.datasource.DriverDataSource getConnection +INFO: +++ Connecting: SUCCESS. +Aug 16, 2016 3:36:41 PM org.apache.cayenne.log.CommonsJdbcEventLogger log +INFO: Detected and installed adapter: org.apache.cayenne.dba.mysql.MySQLAdapter +Aug 16, 2016 3:36:41 PM org.apache.cayenne.datasource.DriverDataSource logConnect +INFO: Connecting to 'jdbc:mysql://127.0.0.1:3306/test' as 'root' +Aug 16, 2016 3:36:41 PM org.apache.cayenne.datasource.DriverDataSource getConnection +INFO: +++ Connecting: SUCCESS. +Aug 16, 2016 3:36:41 PM org.apache.cayenne.access.DbLoader load +INFO: Schema loading... +Aug 16, 2016 3:36:41 PM org.apache.cayenne.datasource.DriverDataSource logConnect +INFO: Connecting to 'jdbc:mysql://127.0.0.1:3306/test' as 'root' +Aug 16, 2016 3:36:41 PM org.apache.cayenne.datasource.DriverDataSource getConnection +INFO: +++ Connecting: SUCCESS. +Aug 16, 2016 3:36:41 PM org.apache.cayenne.log.CommonsJdbcEventLogger log +INFO: Detected and installed adapter: org.apache.cayenne.dba.mysql.MySQLAdapter +[INFO] Table: test.customer +[INFO] Table: test.order +[INFO] Db Relationship : toOne (order.customer_id, customer.id) +[INFO] Db Relationship : toMany (customer.id, order.customer_id) +[INFO] +[INFO] Map file does not exist. Loaded db model will be saved into '**/MySQLTest/src/main/resources/shopping.map.xml' +[INFO] +[INFO] --- maven-cayenne-plugin:4.0.M3:cgen (ormsync) @ MySQLTest --- +[INFO] Generating superclass file: **/MySQLTest/src/main/java/org/apache/cayenne/shopping/auto/_Customer.java +[INFO] Generating class file:**/MySQLTest/src/main/java/org/apache/cayenne/shopping/Customer.java +[INFO] Generating superclass file: **/MySQLTest/src/main/java/org/apache/cayenne/shopping/auto/_Order.java +[INFO] Generating class file: **/MySQLTest/src/main/java/org/apache/cayenne/shopping/Order.java +[INFO]</pre><p> + Above output demonstrates what was loaded from database (test.order, test.customer tables and customer_id relationships) + by cdbimport task and which classes was generated by cgen task. + </p><p> + In the example we assume that you don't have a mapping file. But if you have, it will contain the relationship between + Java class and database table. Note that if there is no mapping file, Cayenne will generate it automatically and store it + under the resource folder specified by <map> property. + </p><p> + Notice that cdbimport updates only one file in your source code: mapping file that you pointed in <map> maven option. + If you do reverse engineering again (mvn compile -Pormsync), plug-in will load all information from database but say that + no changes are detected. On the other hand, cgen task will regenerate superclasses (_Customer.java, _Order.java), + but not subclasses (Customer.java, Order.java). + </p><p>Console will provide the following output:</p><pre class="screen">[INFO] Scanning for projects... +[INFO] +[INFO] ------------------------------------------------------------------------ +[INFO] Building MySQLTest 0.0.1-SNAPSHOT +[INFO] ------------------------------------------------------------------------ +[INFO] +[INFO] --- maven-cayenne-plugin:4.0.M3:cdbimport (ormsync) @ MySQLTest --- +Aug 16, 2016 4:44:33 PM org.apache.cayenne.datasource.DriverDataSource logConnect +INFO: Connecting to 'jdbc:mysql://127.0.0.1:3306/test' as 'root' +Aug 16, 2016 4:44:33 PM org.apache.cayenne.datasource.DriverDataSource getConnection +INFO: +++ Connecting: SUCCESS. +Aug 16, 2016 4:44:33 PM org.apache.cayenne.log.CommonsJdbcEventLogger log +INFO: Detected and installed adapter: org.apache.cayenne.dba.mysql.MySQLAdapter +Aug 16, 2016 4:44:33 PM org.apache.cayenne.datasource.DriverDataSource logConnect +INFO: Connecting to 'jdbc:mysql://127.0.0.1:3306/test' as 'root' +Aug 16, 2016 4:44:33 PM org.apache.cayenne.datasource.DriverDataSource getConnection +INFO: +++ Connecting: SUCCESS. +Aug 16, 2016 4:44:33 PM org.apache.cayenne.access.DbLoader load +INFO: Schema loading... +Aug 16, 2016 4:44:33 PM org.apache.cayenne.datasource.DriverDataSource logConnect +INFO: Connecting to 'jdbc:mysql://127.0.0.1:3306/test' as 'root' +Aug 16, 2016 4:44:34 PM org.apache.cayenne.datasource.DriverDataSource getConnection +INFO: +++ Connecting: SUCCESS. +Aug 16, 2016 4:44:34 PM org.apache.cayenne.log.CommonsJdbcEventLogger log +INFO: Detected and installed adapter: org.apache.cayenne.dba.mysql.MySQLAdapter +[INFO] Table: test.customer +[INFO] Table: test.order +[INFO] Db Relationship : toOne (order.customer_id, customer.id) +[INFO] Db Relationship : toMany (customer.id, order.customer_id) +[INFO] +[INFO] Detected changes: No changes to import. +[INFO] +[INFO] --- maven-cayenne-plugin:4.0.M3:cgen (ormsync) @ MySQLTest --- +[INFO] Generating superclass file: **/MySQLTest/src/main/java/org/apache/cayenne/shopping/auto/_Customer.java +[INFO] Generating superclass file: **/MySQLTest/src/main/java/org/apache/cayenne/shopping/auto/_Order.java +[INFO]</pre></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="index.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="ch02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Getting Started with Cayenne Reverse Engineering </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 2. A few hands-on examples</td></tr></table></div></body></html> \ No newline at end of file