Added: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne
Guide/Tutorial/Tutorial Starting Project/index.html
URL:
http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne%20Guide/Tutorial/Tutorial%20Starting%20Project/index.html?rev=1034943&view=auto
==============================================================================
--- cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne
Guide/Tutorial/Tutorial Starting Project/index.html (added)
+++ cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne
Guide/Tutorial/Tutorial Starting Project/index.html Sun Nov 14 07:05:50 2010
@@ -0,0 +1,133 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<html>
+ <head>
+ <title>Apache Cayenne Documentation - Tutorial Starting Project</title>
+ <style type="text/css">@import "../../../../style.css";</style>
+ </head>
+<body>
+ <div class="header">
+ <div style="float: left;"><a href="http://cayenne.apache.org/"><img
src="../../../../images/logo.gif" align="absmiddle" border="0"></a></div>
+ <span class="logoSpaceLink"><a href="../../../../index.html">Cayenne User
Documentation</a></span><br />
+ <span class="pagetitle">Tutorial Starting Project</span>
+ </div>
+<div id="cayenne_toc">
+<ul>
+<li><a href="../../../../Documentation/Cayenne
Guide/Introduction/index.html">Introduction</a></li>
+<li><a href="../../../../Documentation/Cayenne
Guide/Installation/index.html">Installation</a></li>
+<li><a href="../../../../Documentation/Cayenne
Guide/Tutorial/index.html">Tutorial</a><ul>
+<li><a href="../../../../Documentation/Cayenne Guide/Tutorial/Tutorial
Setup/index.html">Tutorial Setup</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Tutorial/Tutorial
Starting Project/index.html">Tutorial Starting Project</a><ul>
+</ul>
+</li>
+<li><a href="../../../../Documentation/Cayenne Guide/Tutorial/Tutorial Object
Relational Mapping/index.html">Tutorial Object Relational Mapping</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Tutorial/Tutorial Java
Classes/index.html">Tutorial Java Classes</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Tutorial/Tutorial
ObjectContext/index.html">Tutorial ObjectContext</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Tutorial/Tutorial
Persistent Objects/index.html">Tutorial Persistent Objects</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Tutorial/Tutorial
SelectQuery/index.html">Tutorial SelectQuery</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Tutorial/Tutorial
Delete/index.html">Tutorial Delete</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Tutorial/Tutorial
Webapp/index.html">Tutorial Webapp</a></li>
+</ul>
+</li>
+<li><a href="../../../../Documentation/Cayenne
Guide/Design/index.html">Design</a></li>
+<li><a href="../../../../Documentation/Cayenne
Guide/DataContext/index.html">DataContext</a></li>
+<li><a href="../../../../Documentation/Cayenne
Guide/Queries/index.html">Queries</a></li>
+<li><a href="../../../../Documentation/Cayenne
Guide/DataObjects/index.html">DataObjects</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Stored
Procedures/index.html">Stored Procedures</a></li>
+<li><a href="../../../../Documentation/Cayenne
Guide/Expressions/index.html">Expressions</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Lifecycle
Callbacks/index.html">Lifecycle Callbacks</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Performance
Tuning/index.html">Performance Tuning</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Caching and Fresh
Data/index.html">Caching and Fresh Data</a></li>
+<li><a href="../../../../Documentation/Cayenne
Guide/Deployment/index.html">Deployment</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Ant Tasks/index.html">Ant
Tasks</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Maven2
Plugins/index.html">Maven2 Plugins</a></li>
+<li><a href="../../../../Documentation/Cayenne
Guide/Customization/index.html">Customization</a></li>
+</ul>
+</div>
+<div id="ConfluenceContent"><p>The goal of this section is to create a new
Java project in Eclipse containing a basic Cayenne mapping. It presents an
introduction to CayenneModeler GUI tool, showing how to create the initial
mapping objects: DataDomain, DataNode, DataMap.</p>
+
+<h3><a name="TutorialStartingProject-CreateanewProjectinEclipse"></a>Create a
new Project in Eclipse</h3>
+
+<p>In Eclipse select <tt>"File > New > Other..."</tt> and then
<tt>"Maven > Maven Project"</tt>. Click "Next". On the following screen
check "Create a simple project" checkbox and click "Next" again. In the dialog
shown on the screenshot below, fill the "Group Id" and "Artifact Id" fields and
click "Finish". <br/>
+<span class="image-wrap" style=""><img
src="tutorial-eclipse-project.png?version=1&modificationDate=1289713366735"
style="border: 0px solid black" /></span></p>
+
+<p>Now you should have a new empty project in the Eclipse workspace. Check
that the project Java compiler settings are correct. Rightclick on the
"tutorial" project, select <tt>"Properties > Java Compiler"</tt> and ensure
that "Compiler compliance level" is at least "1.5" (some versions of Maven
plugin seem to be setting it to 1.4 by default).</p>
+
+<h3><a
name="TutorialStartingProject-DownloadandStartCayenneModeler"></a>Download and
Start CayenneModeler</h3>
+
+<p>Although later in this tutorial we'll be using Maven to include Cayenne
runtime jars in the project, you'll still need to download Cayenne to get
access to the CayenneModeler tool. </p>
+
+<div class='panelMacro'><table class='noteMacro'><colgroup><col
width='24'><col></colgroup><tr><td valign='top'><img
src="../../../../images/emoticons/warning.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td>If you are really into Maven, you
can <a href="../../../../Documentation/Cayenne Guide/Maven2
Plugins/maven2-modeler/index.html" title="maven2-modeler">start CayenneModeler
from Maven</a> if you wish. We'll do it in a more traditional way
here.</td></tr></table></div>
+
+<p>Download the latest release <a
href="http://cayenne.apache.org/download.html" class="external-link"
rel="nofollow">from here</a>. Unpack the distribution somewhere in the file
system and start CayenneModeler, following <a
href="../../../../Documentation/Modeler Guide/Introduction to
CayenneModeler/Running CayenneModeler/index.html" title="Running
CayenneModeler">platform-specific instructions</a>. On most platforms it is
done simply by doubleclicking the Modeler icon. The welcome screen of the
Modeler looks like this:</p>
+
+<p><span class="image-wrap" style=""><img
src="modeler-started.png?version=1&modificationDate=1289713364249"
style="border: 0px solid black" /></span></p>
+
+<h3><a
name="TutorialStartingProject-CreateaNewMappingProjectinCayenneModeler"></a>Create
a New Mapping Project in CayenneModeler</h3>
+
+<p>Click on the "New Project" button on Welcome screen. A new mapping project
will appear that contains a single <b>DataDomain</b>. The meaning of a
DataDomain is explained elsewhere in the User Guide. For now it is sufficient
to understand that DataDomain is the root of your mapping project.</p>
+
+<h3><a name="TutorialStartingProject-CreateaDataNode"></a>Create a
DataNode</h3>
+
+<p>The next project object you will create is a <b>DataNode</b>. DataNode is a
descriptor of a single database your application will connect to. Cayenne
mapping project can use more than one database, but for now, we'll only use
one. With "UntitledDomain" selected on the left, click on "Create DataNode"
button on the toolbar (or select <tt>"Project > Create DataNode"</tt> from
the menu.</p>
+
+<p>A new DataNode is displayed. Now you need to specify JDBC connection
parameters. For an in-memory Derby database you can enter the following
settings: </p>
+
+<ul>
+ <li>JDBC Driver: <tt>org.apache.derby.jdbc.EmbeddedDriver</tt></li>
+ <li>DB URL: <tt>jdbc:derby:memory:testdb;create=true</tt></li>
+</ul>
+
+
+<div class='panelMacro'><table class='noteMacro'><colgroup><col
width='24'><col></colgroup><tr><td valign='top'><img
src="../../../../images/emoticons/warning.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td>We are creating an in-memory
database here. So when you stop your application, all the data will be lost. In
most real-life cases you'll be connecting to a database that actually persists
its data on disk, but an in-memory DB will do for the simple
tutorial.</td></tr></table></div>
+
+<p>Also you will need to change "Schema Update Strategy". Select
<tt>"org.apache.cayenne.access.dbsync.CreateIfNoSchemaStrategy"</tt> from the
dropdown, so that Cayenne creates a new schema on Derby based on the ORM
mapping when the application starts.</p>
+
+<p><span class="image-wrap" style=""><img
src="base-datanode.png?version=1&modificationDate=1289713359050"
style="border: 0px solid black" /></span></p>
+
+
+<h3><a name="TutorialStartingProject-CreateaDataMap"></a>Create a DataMap</h3>
+
+<p>Now you will create a <b>DataMap</b>. DataMap is an object that holds all
the mapping information. To create it, click on "Create DataMap" button (or
select a corresponding menu item). Note that the newly created DataMap is
automatically linked to the DataNode that you created in the previous step. If
there is more than one DataNode, you may need to link a DataMap to the correct
node manually. In other words a DataMap within DataDomain must point to a
database described by the map.</p>
+
+<p>You can leave all the DataMap defaults unchanged except for one - "Java
Package". Enter "org.example.cayenne.persistent". This name will later be used
for all persistent classes.</p>
+
+<p><span class="image-wrap" style=""><img
src="base-datamap.png?version=1&modificationDate=1289713358895"
style="border: 0px solid black" /></span></p>
+
+<h3><a name="TutorialStartingProject-SavetheProject"></a>Save the Project</h3>
+
+<p>Before you proceed with the actual mapping, let's save the project. Click
on "Save" button in the toolbar and navigate to the <tt>"tutorial"</tt> Eclipse
project folder that was created earlier in this section and its
<tt>"src/main/resources"</tt> subfolder and save the project there. Now go back
to Eclipse, right click on "tutorial" project and select "Refresh", you will
see three Cayenne XML files.</p>
+
+<p><span class="image-wrap" style=""><img
src="eclipse-xmlfiles.png?version=1&modificationDate=1289713363197"
style="border: 0px solid black" /></span></p>
+
+<p>Note that the location of the XML files is not coincidental. Cayenne
runtime looks for <tt>"cayenne.xml"</tt> file in the application CLASSPATH and
<tt>"src/main/resources"</tt> folder should already be a "class folder" in
Eclipse for our project (and is also a standard location that Maven would copy
to a jar file, if we were using Maven from command-line).</p>
+
+<hr />
+<p><b>Next Step: <a href="../../../../Documentation/Cayenne
Guide/Tutorial/Tutorial Object Relational Mapping/index.html" title="Tutorial
Object Relational Mapping">Tutorial Object Relational Mapping</a></b></p>
+<hr /></div>
+</div>
+ <div class="clearer">.</div>
+ <div style="height: 12px; background-image:
url('../../../../images/border_bottom.gif'); background-repeat:
repeat-x;"></div>
+
+ <div class="smalltext copyright">
+ Copyright ©2001-2010 Apache Software Foundation
+ </div>
+
+</body>
+</html>
Propchange:
cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne
Guide/Tutorial/Tutorial Starting Project/index.html
------------------------------------------------------------------------------
svn:eol-style = native
Added: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne
Guide/Tutorial/Tutorial Starting Project/modeler-started.png
URL:
http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne%20Guide/Tutorial/Tutorial%20Starting%20Project/modeler-started.png?rev=1034943&view=auto
==============================================================================
Files cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne
Guide/Tutorial/Tutorial Starting Project/modeler-started.png (added) and
cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne
Guide/Tutorial/Tutorial Starting Project/modeler-started.png Sun Nov 14
07:05:50 2010 differ
Added: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne
Guide/Tutorial/Tutorial Starting Project/tutorial-eclipse-project.png
URL:
http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne%20Guide/Tutorial/Tutorial%20Starting%20Project/tutorial-eclipse-project.png?rev=1034943&view=auto
==============================================================================
Files cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne
Guide/Tutorial/Tutorial Starting Project/tutorial-eclipse-project.png (added)
and cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne
Guide/Tutorial/Tutorial Starting Project/tutorial-eclipse-project.png Sun Nov
14 07:05:50 2010 differ
Added: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne
Guide/Tutorial/Tutorial Webapp/eclipse-mvnrun.png
URL:
http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne%20Guide/Tutorial/Tutorial%20Webapp/eclipse-mvnrun.png?rev=1034943&view=auto
==============================================================================
Files cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne
Guide/Tutorial/Tutorial Webapp/eclipse-mvnrun.png (added) and
cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne
Guide/Tutorial/Tutorial Webapp/eclipse-mvnrun.png Sun Nov 14 07:05:50 2010
differ
Added: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne
Guide/Tutorial/Tutorial Webapp/firefox-webapp.png
URL:
http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne%20Guide/Tutorial/Tutorial%20Webapp/firefox-webapp.png?rev=1034943&view=auto
==============================================================================
Files cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne
Guide/Tutorial/Tutorial Webapp/firefox-webapp.png (added) and
cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne
Guide/Tutorial/Tutorial Webapp/firefox-webapp.png Sun Nov 14 07:05:50 2010
differ
Added: cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne
Guide/Tutorial/Tutorial Webapp/index.html
URL:
http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne%20Guide/Tutorial/Tutorial%20Webapp/index.html?rev=1034943&view=auto
==============================================================================
--- cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne
Guide/Tutorial/Tutorial Webapp/index.html (added)
+++ cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne
Guide/Tutorial/Tutorial Webapp/index.html Sun Nov 14 07:05:50 2010
@@ -0,0 +1,346 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<html>
+ <head>
+ <title>Apache Cayenne Documentation - Tutorial Webapp</title>
+ <style type="text/css">@import "../../../../style.css";</style>
+ </head>
+<body>
+ <div class="header">
+ <div style="float: left;"><a href="http://cayenne.apache.org/"><img
src="../../../../images/logo.gif" align="absmiddle" border="0"></a></div>
+ <span class="logoSpaceLink"><a href="../../../../index.html">Cayenne User
Documentation</a></span><br />
+ <span class="pagetitle">Tutorial Webapp</span>
+ </div>
+<div id="cayenne_toc">
+<ul>
+<li><a href="../../../../Documentation/Cayenne
Guide/Introduction/index.html">Introduction</a></li>
+<li><a href="../../../../Documentation/Cayenne
Guide/Installation/index.html">Installation</a></li>
+<li><a href="../../../../Documentation/Cayenne
Guide/Tutorial/index.html">Tutorial</a><ul>
+<li><a href="../../../../Documentation/Cayenne Guide/Tutorial/Tutorial
Setup/index.html">Tutorial Setup</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Tutorial/Tutorial
Starting Project/index.html">Tutorial Starting Project</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Tutorial/Tutorial Object
Relational Mapping/index.html">Tutorial Object Relational Mapping</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Tutorial/Tutorial Java
Classes/index.html">Tutorial Java Classes</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Tutorial/Tutorial
ObjectContext/index.html">Tutorial ObjectContext</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Tutorial/Tutorial
Persistent Objects/index.html">Tutorial Persistent Objects</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Tutorial/Tutorial
SelectQuery/index.html">Tutorial SelectQuery</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Tutorial/Tutorial
Delete/index.html">Tutorial Delete</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Tutorial/Tutorial
Webapp/index.html">Tutorial Webapp</a><ul>
+</ul>
+</li>
+</ul>
+</li>
+<li><a href="../../../../Documentation/Cayenne
Guide/Design/index.html">Design</a></li>
+<li><a href="../../../../Documentation/Cayenne
Guide/DataContext/index.html">DataContext</a></li>
+<li><a href="../../../../Documentation/Cayenne
Guide/Queries/index.html">Queries</a></li>
+<li><a href="../../../../Documentation/Cayenne
Guide/DataObjects/index.html">DataObjects</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Stored
Procedures/index.html">Stored Procedures</a></li>
+<li><a href="../../../../Documentation/Cayenne
Guide/Expressions/index.html">Expressions</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Lifecycle
Callbacks/index.html">Lifecycle Callbacks</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Performance
Tuning/index.html">Performance Tuning</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Caching and Fresh
Data/index.html">Caching and Fresh Data</a></li>
+<li><a href="../../../../Documentation/Cayenne
Guide/Deployment/index.html">Deployment</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Ant Tasks/index.html">Ant
Tasks</a></li>
+<li><a href="../../../../Documentation/Cayenne Guide/Maven2
Plugins/index.html">Maven2 Plugins</a></li>
+<li><a href="../../../../Documentation/Cayenne
Guide/Customization/index.html">Customization</a></li>
+</ul>
+</div>
+<div id="ConfluenceContent"><p>This sections shows how to work with Cayenne in
a web application.</p>
+
+<h3><a
name="TutorialWebapp-ConvertingTutorialtoaWebApplication"></a>Converting
Tutorial to a Web Application</h3>
+
+<p>The web part of the web application tutorial is done in JSP, which is the
least common denominator of the Java web technologies, and is intentionally
simplistic from the UI perspective, to concentrate on Cayenne integration
aspect, rather than the interface. A typical Cayenne web application works like
this:</p>
+
+<ul>
+ <li>Cayenne configuiration is loaded when an application context is
started, using a special servlet filter.</li>
+ <li>User requests are intercepted by the filter, and the DataContext is
bound to the request thread, so the application can access it easily from
anywhere.</li>
+ <li>The same DataContext instance is reused within a single user
session; different sessions use different DataContexts (and therefore different
sets of objects). <em>However see "ObjectContext Scope" section of the <a
href="../../../../Documentation/Cayenne Guide/Deployment/Web
Applications/index.html" title="Web Applications">Web Applications</a> page.
The context can be scoped differently depending on the app specifics. For the
tutorial we'll be using a session-scoped context.</em></li>
+</ul>
+
+
+<p>For more information on the web application deployment, check <a
href="../../../../Documentation/Cayenne Guide/Deployment/Web
Applications/index.html" title="Web Applications">Web Applications</a> page.</p>
+
+<p>So let's convert the tutorial that we created to a web application:</p>
+
+<ul>
+ <li>In Eclipse under "tutorial" project folder create a new folder
"src/main/webapp/WEB-INF".</li>
+ <li>Under "WEB-INF" create a new file "web.xml" (a standard web app
descriptor):</li>
+</ul>
+
+
+<div class="code panel" style="border-width: 1px;"><div class="codeHeader
panelHeader" style="border-bottom-width: 1px;"><b>web.xml</b></div><div
class="codeContent panelContent">
+<pre class="code-java"><?xml version=<span class="code-quote">"1.0"</span>
encoding=<span class="code-quote">"utf-8"</span>?>
+ <!DOCTYPE web-app
+ PUBLIC <span class="code-quote">"-<span class="code-comment">//Sun
Microsystems, Inc.//DTD Web Application 2.3//EN"</span>
+</span> <span class="code-quote">"http:<span
class="code-comment">//java.sun.com/dtd/web-app_2_3.dtd"</span>>
+</span><web-app>
+ <display-name>Cayenne Tutorial</display-name>
+
+ <!-- This filter bootstraps ServerRuntime and then provides each
request thread
+ with a session-bound DataContext. Note that the name of the filter is
important,
+ as it points it to the right named configuration file.
+ -->
+ <filter>
+ <filter-name>cayenne-UntitledDomain</filter-name>
+
<filter-class>org.apache.cayenne.configuration.web.CayenneFilter</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>cayenne-UntitledDomain</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+ <welcome-file-list>
+ <welcome-file>index.jsp</welcome-file>
+ </welcome-file-list>
+</web-app></pre>
+</div></div>
+
+<ul>
+ <li>Create the artist browser page <tt>src/main/webapp/index.jsp</tt>
file with the following contents:</li>
+</ul>
+
+
+<div class="code panel" style="border-width: 1px;"><div class="codeHeader
panelHeader" style="border-bottom-width:
1px;"><b>webapp/index.jsp</b></div><div class="codeContent panelContent">
+<pre class="code-java"><%@ page language=<span
class="code-quote">"java"</span> contentType=<span
class="code-quote">"text/html"</span> %>
+<%@ page <span class="code-keyword">import</span>=<span
class="code-quote">"org.example.cayenne.persistent.*"</span> %>
+<%@ page <span class="code-keyword">import</span>=<span
class="code-quote">"org.apache.cayenne.*"</span> %>
+<%@ page <span class="code-keyword">import</span>=<span
class="code-quote">"org.apache.cayenne.query.*"</span> %>
+<%@ page <span class="code-keyword">import</span>=<span
class="code-quote">"org.apache.cayenne.exp.*"</span> %>
+<%@ page <span class="code-keyword">import</span>=<span
class="code-quote">"java.util.*"</span> %>
+
+<%
+ SelectQuery query = <span class="code-keyword">new</span>
SelectQuery(Artist.class);
+ query.addOrdering(Artist.NAME_PROPERTY, SortOrder.ASCENDING);
+
+ ObjectContext context = BaseContext.getThreadObjectContext();
+ List<Artist> artists = context.performQuery(query);
+%>
+<html>
+ <head>
+ <title>Main</title>
+ </head>
+ <body>
+ <h2>Artists:</h2>
+
+ <% <span class="code-keyword">if</span>(artists.isEmpty()) {%>
+ <p>No artists found</p>
+ <% } <span class="code-keyword">else</span> {
+ <span class="code-keyword">for</span>(Artist a : artists) {
+ %>
+ <p><a href=<span
class="code-quote">"detail.jsp?id=<%=Cayenne.intPKForObject(a)%>"</span>>
<%=a.getName()%> </a></p>
+ <%
+ }
+ } %>
+ <hr>
+ <p><a href=<span
class="code-quote">"detail.jsp"</span>>Create <span
class="code-keyword">new</span> artist...</a></p>
+ </body>
+</html></pre>
+</div></div>
+
+<ul>
+ <li>Create the artist editor page <tt>src/main/webapp/detail.jsp</tt>
with the following content:</li>
+</ul>
+
+
+<div class="code panel" style="border-width: 1px;"><div class="codeHeader
panelHeader" style="border-bottom-width:
1px;"><b>webapp/detail.jsp</b></div><div class="codeContent panelContent">
+<pre class="code-java"><%@ page language=<span
class="code-quote">"java"</span> contentType=<span
class="code-quote">"text/html"</span> %>
+<%@ page <span class="code-keyword">import</span>=<span
class="code-quote">"org.example.cayenne.persistent.*"</span> %>
+<%@ page <span class="code-keyword">import</span>=<span
class="code-quote">"org.apache.cayenne.*"</span> %>
+<%@ page <span class="code-keyword">import</span>=<span
class="code-quote">"java.util.*"</span> %>
+<%@ page <span class="code-keyword">import</span>=<span
class="code-quote">"java.text.*"</span> %>
+
+<%
+ ObjectContext context = BaseContext.getThreadObjectContext();
+ <span class="code-object">String</span> id = request.getParameter(<span
class="code-quote">"id"</span>);
+
+ <span class="code-comment">// find artist <span
class="code-keyword">for</span> id
+</span> Artist artist = <span class="code-keyword">null</span>;
+ <span class="code-keyword">if</span>(id != <span
class="code-keyword">null</span> && id.trim().length() > 0) {
+ artist = Cayenne.objectForPK(context, Artist.class, <span
class="code-object">Integer</span>.parseInt(id));
+ }
+
+ <span class="code-keyword">if</span>(<span
class="code-quote">"POST"</span>.equals(request.getMethod())) {
+ <span class="code-comment">// <span class="code-keyword">if</span> no
id is saved in the hidden field, we are dealing with
+</span> <span class="code-comment">// create <span
class="code-keyword">new</span> artist request
+</span> <span class="code-keyword">if</span>(artist == <span
class="code-keyword">null</span>) {
+ artist = context.newObject(Artist.class);
+ }
+
+ <span class="code-comment">// note that in a real application we would
so dome validation ...
+</span> <span class="code-comment">// here we just hope the input is
correct
+</span> artist.setName(request.getParameter(<span
class="code-quote">"name"</span>));
+ artist.setDateOfBirthString(request.getParameter(<span
class="code-quote">"dateOfBirth"</span>));
+
+ context.commitChanges();
+
+ response.sendRedirect(<span class="code-quote">"index.jsp"</span>);
+ }
+
+ <span class="code-keyword">if</span>(artist == <span
class="code-keyword">null</span>) {
+ <span class="code-comment">// create <span
class="code-keyword">transient</span> artist <span
class="code-keyword">for</span> the form response rendering
+</span> artist = <span class="code-keyword">new</span> Artist();
+ }
+
+ <span class="code-object">String</span> name = artist.getName() == <span
class="code-keyword">null</span> ? "" : artist.getName();
+ <span class="code-object">String</span> dob = artist.getDateOfBirth() ==
<span class="code-keyword">null</span>
+ ? <span class="code-quote">"" : <span
class="code-keyword">new</span>
SimpleDateFormat("</span>yyyyMMdd").format(artist.getDateOfBirth());
+%>
+<html>
+ <head>
+ <title>Artist Details</title>
+ </head>
+ <body>
+ <h2>Artists Details</h2>
+ <form name=<span class="code-quote">"EditArtist"</span>
action=<span class="code-quote">"detail.jsp"</span> method=<span
class="code-quote">"POST"</span>>
+ <input type=<span class="code-quote">"hidden"</span> name=<span
class="code-quote">"id"</span> value=<span class="code-quote">"<%= id !=
<span class="code-keyword">null</span> ? id : "</span><span
class="code-quote">" %>"</span> />
+ <table border=<span class="code-quote">"0"</span>>
+ <tr>
+ <td>Name:</td>
+ <td><input type=<span
class="code-quote">"text"</span> name=<span class="code-quote">"name"</span>
value=<span class="code-quote">"<%= name %>"</span>/></td>
+ </tr>
+ <tr>
+ <td>Date of Birth (yyyyMMdd):</td>
+ <td><input type=<span
class="code-quote">"text"</span> name=<span
class="code-quote">"dateOfBirth"</span> value=<span class="code-quote">"<%=
dob %>"</span>/></td>
+ </tr>
+ <tr>
+ <td></td>
+ <td align=<span
class="code-quote">"right"</span>><input type=<span
class="code-quote">"submit"</span> value=<span class="code-quote">"Save"</span>
/></td>
+ </tr>
+ </table>
+ </form>
+ </body>
+</html></pre>
+</div></div>
+
+<h3><a name="TutorialWebapp-RunningWebApplication"></a>Running Web
Application</h3>
+
+<p>To run the web application we'll use "maven-jetty-plugin". To activate it,
let's add the following piece of code to the "pom.xml" file, following the
"dependencies" section and save the POM:</p>
+
+<div class="code panel" style="border-width: 1px;"><div class="codeContent
panelContent">
+<pre class="code-java"><build>
+ <plugins>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>maven-jetty-plugin</artifactId>
+ <version>6.1.22</version>
+ </plugin>
+ </plugins>
+</build></pre>
+</div></div>
+
+<ul>
+ <li>Go to "Run > Run Configurations..." menu, select "Maven Build",
right click and select "New"</li>
+ <li>Make sure you fill "Name", "Base directory" and "Goals" fields as
shown on the screenshot:</li>
+</ul>
+
+
+<p><span class="image-wrap" style=""><img
src="eclipse-mvnrun.png?version=1&modificationDate=1289712767171"
style="border: 0px solid black" /></span></p>
+
+<ul>
+ <li>Click "Apply" and "Run". On the first execution it may take a few
minutes for Jetty plugin to download all dependencies, but eventually you'll
see the logs like this:</li>
+</ul>
+
+
+<div class="preformatted panel" style="border-width: 1px;"><div
class="preformattedContent panelContent">
+<pre>[INFO] Scanning for projects...
+[INFO] ------------------------------------------------------------------------
+[INFO] Building Unnamed - org.example.cayenne:tutorial:jar:0.0.1-SNAPSHOT
+[INFO]
+[INFO] Id: org.example.cayenne:tutorial:jar:0.0.1-SNAPSHOT
+[INFO] task-segment: [jetty:run]
+[INFO] ------------------------------------------------------------------------
+...
+[INFO] [jetty:run]
+[INFO] Configuring Jetty for project: Unnamed -
org.example.cayenne:tutorial:jar:0.0.1-SNAPSHOT
+[INFO] Webapp source directory =
/.../tutorial/Desktop/work/tutorial/src/main/webapp
+...
+[INFO] Starting jetty 6.1.22 ...
+2009-12-22 14:08:06.301::INFO: jetty-6.1.22
+2009-12-22 14:08:06.474::INFO: No Transaction manager found - if your webapp
requires one, please configure one.
+INFO: started configuration loading.
+INFO: loaded domain: UntitledDomain
+INFO: loaded <map name='UntitledDomainMap'
location='UntitledDomainMap.map.xml'>.
+INFO: loading <node name='UntitledDomainNode'
datasource='UntitledDomainNode.driver.xml'
+factory='org.apache.cayenne.conf.DriverDataSourceFactory' schema-update-
+strategy='org.apache.cayenne.access.dbsync.CreateIfNoSchemaStrategy'>.
+INFO: using factory: org.apache.cayenne.conf.DriverDataSourceFactory
+INFO: loading driver information from 'UntitledDomainNode.driver.xml'.
+INFO: loading driver org.apache.derby.jdbc.EmbeddedDriver
+INFO: loading user name and password.
+INFO: Created connection pool: jdbc:derby:memory:testdb;create=true
+ Driver class: org.apache.derby.jdbc.EmbeddedDriver
+ Min. connections in the pool: 1
+ Max. connections in the pool: 1
+INFO: loaded datasource.
+INFO: no adapter set, using automatic adapter.
+INFO: loaded map-ref: UntitledDomainMap.
+INFO: finished configuration loading in 355 ms.
+2009-12-22 14:08:07.081::INFO: Started [email protected]:8080
+[INFO] Started Jetty Server</pre>
+</div></div>
+
+<ul>
+ <li>So the Jetty container just started and loaded Cayenne.</li>
+ <li>Now go to <a href="http://localhost:8080/tutorial/"
class="external-link" rel="nofollow">http://localhost:8080/tutorial/</a> URL.
You should see "No artists found message" in the web browser and the following
output in the Eclipse console:</li>
+</ul>
+
+
+<div class="preformatted panel" style="border-width: 1px;"><div
class="preformattedContent panelContent">
+<pre>INFO: --- will run 1 query.
+INFO: Opening connection: jdbc:derby:memory:testdb;create=true
+ Login: null
+ Password: *******
+INFO: +++ Connecting: SUCCESS.
+INFO: --- transaction started.
+INFO: Detected and installed adapter: org.apache.cayenne.dba.derby.DerbyAdapter
+INFO: No schema detected, will create mapped tables
+INFO: CREATE TABLE GALLERY (ID INTEGER NOT NULL GENERATED BY DEFAULT AS
IDENTITY,
+NAME VARCHAR (200), PRIMARY KEY (ID))
+INFO: CREATE TABLE ARTIST (DATE_OF_BIRTH DATE, ID INTEGER NOT NULL GENERATED
+BY DEFAULT AS IDENTITY, NAME VARCHAR (200), PRIMARY KEY (ID))
+INFO: CREATE TABLE PAINTING (ARTIST_ID INTEGER, GALLERY_ID INTEGER,
+ID INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY, NAME VARCHAR (200),
PRIMARY KEY (ID))
+INFO: ALTER TABLE PAINTING ADD FOREIGN KEY (ARTIST_ID) REFERENCES ARTIST (ID)
+INFO: ALTER TABLE PAINTING ADD FOREIGN KEY (GALLERY_ID) REFERENCES GALLERY (ID)
+INFO: CREATE TABLE AUTO_PK_SUPPORT ( TABLE_NAME CHAR(100) NOT NULL, NEXT_ID
BIGINT NOT NULL, PRIMARY KEY(TABLE_NAME))
+INFO: DELETE FROM AUTO_PK_SUPPORT WHERE TABLE_NAME IN ('ARTIST', 'GALLERY',
'PAINTING')
+INFO: INSERT INTO AUTO_PK_SUPPORT (TABLE_NAME, NEXT_ID) VALUES ('ARTIST', 200)
+INFO: INSERT INTO AUTO_PK_SUPPORT (TABLE_NAME, NEXT_ID) VALUES ('GALLERY', 200)
+INFO: INSERT INTO AUTO_PK_SUPPORT (TABLE_NAME, NEXT_ID) VALUES ('PAINTING',
200)
+INFO: SELECT t0.DATE_OF_BIRTH, t0.ID, t0.NAME FROM ARTIST t0 ORDER BY t0.NAME
- prepared in 35 ms.
+INFO: === returned 0 rows. - took 53 ms.
+INFO: +++ transaction committed.</pre>
+</div></div>
+
+<ul>
+ <li>You can click on "Create new artist" link to create artists.
Existing artists can be edited by clicking on their name:</li>
+</ul>
+
+
+<p><span class="image-wrap" style=""><img
src="firefox-webapp.png?version=1&modificationDate=1289712761139"
style="border: 0px solid black" /></span></p>
+
+<p>You are done with the tutorial!</p></div>
+</div>
+ <div class="clearer">.</div>
+ <div style="height: 12px; background-image:
url('../../../../images/border_bottom.gif'); background-repeat:
repeat-x;"></div>
+
+ <div class="smalltext copyright">
+ Copyright ©2001-2010 Apache Software Foundation
+ </div>
+
+</body>
+</html>
Propchange:
cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne
Guide/Tutorial/Tutorial Webapp/index.html
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne
Guide/Tutorial/index.html
URL:
http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne%20Guide/Tutorial/index.html?rev=1034943&r1=1034942&r2=1034943&view=diff
==============================================================================
--- cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne
Guide/Tutorial/index.html (original)
+++ cayenne/main/trunk/docs/doc/src/main/resources/doc/Documentation/Cayenne
Guide/Tutorial/index.html Sun Nov 14 07:05:50 2010
@@ -32,6 +32,15 @@
<li><a href="../../../Documentation/Cayenne
Guide/Introduction/index.html">Introduction</a></li>
<li><a href="../../../Documentation/Cayenne
Guide/Installation/index.html">Installation</a></li>
<li><a href="../../../Documentation/Cayenne
Guide/Tutorial/index.html">Tutorial</a><ul>
+<li><a href="../../../Documentation/Cayenne Guide/Tutorial/Tutorial
Setup/index.html">Tutorial Setup</a></li>
+<li><a href="../../../Documentation/Cayenne Guide/Tutorial/Tutorial Starting
Project/index.html">Tutorial Starting Project</a></li>
+<li><a href="../../../Documentation/Cayenne Guide/Tutorial/Tutorial Object
Relational Mapping/index.html">Tutorial Object Relational Mapping</a></li>
+<li><a href="../../../Documentation/Cayenne Guide/Tutorial/Tutorial Java
Classes/index.html">Tutorial Java Classes</a></li>
+<li><a href="../../../Documentation/Cayenne Guide/Tutorial/Tutorial
ObjectContext/index.html">Tutorial ObjectContext</a></li>
+<li><a href="../../../Documentation/Cayenne Guide/Tutorial/Tutorial Persistent
Objects/index.html">Tutorial Persistent Objects</a></li>
+<li><a href="../../../Documentation/Cayenne Guide/Tutorial/Tutorial
SelectQuery/index.html">Tutorial SelectQuery</a></li>
+<li><a href="../../../Documentation/Cayenne Guide/Tutorial/Tutorial
Delete/index.html">Tutorial Delete</a></li>
+<li><a href="../../../Documentation/Cayenne Guide/Tutorial/Tutorial
Webapp/index.html">Tutorial Webapp</a></li>
</ul>
</li>
<li><a href="../../../Documentation/Cayenne
Guide/Design/index.html">Design</a></li>
@@ -49,7 +58,34 @@
<li><a href="../../../Documentation/Cayenne
Guide/Customization/index.html">Customization</a></li>
</ul>
</div>
-<div id="ConfluenceContent"><div class='panelMacro'><table
class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="../../../images/emoticons/warning.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td>There's no Cayenne 3.1
tutorial yet, as 3.1 is still under active development. You may want to check
<a
href="https://cwiki.apache.org/confluence/confluence/display/CAYDOC30/Tutorial"
title="Tutorial">a tutorial for Cayenne 3.0</a>
instead.</td></tr></table></div></div>
+<div id="ConfluenceContent"><h2><a name="Tutorial-Tutorial"></a>Tutorial</h2>
+
+<p>This is a step-by-step tutorial showing how to write a database application
with Cayenne. When you are done with it, you should have an understanding of
the basics of object-relational mapping using CayenneModeler and how to use the
Cayenne framework in standalone (command-line or otherwise) and web
applications. The tutorial uses Maven, Eclipse IDE and Derby database, however
it can be easily recreated with another combination of a database, an IDE and a
build system. Full tutorial source code in a form of Eclipse project is
distributed with Cayenne (see <tt>"tutorials/tutorial"</tt> folder).</p>
+
+<div class='panelMacro'><table class='noteMacro'><colgroup><col
width='24'><col></colgroup><tr><td valign='top'><img
src="../../../images/emoticons/warning.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td><b>Note about Maven</b><br />The
only potentially controversial choice here is Maven. Not everybody is familiar
with Maven, and not everybody likes it. However we decided that the benefits of
the setup simplicity outweigh any downsides. Note that the tutorial is using
<tt>m2eclipse</tt> plugin and doesn't even require a command-line Maven
installation. Moreover most of the useful Cayenne Maven hackery is presented in
boxed inserts throughout the text, while a Maven-agnostic alternative is shown
in the main text.</td></tr></table></div>
+
+<h3><a name="Tutorial-Sections"></a>Sections</h3>
+
+<ol>
+ <li><a href="../../../Documentation/Cayenne Guide/Tutorial/Tutorial
Setup/index.html" title="Tutorial Setup">Setting up the environment...</a></li>
+ <li>Learning mapping basics
+ <ol>
+ <li><a href="../../../Documentation/Cayenne
Guide/Tutorial/Tutorial Starting Project/index.html" title="Tutorial Starting
Project">Starting a project...</a></li>
+ <li><a href="../../../Documentation/Cayenne
Guide/Tutorial/Tutorial Object Relational Mapping/index.html" title="Tutorial
Object Relational Mapping">Getting started with Object Relational Mapping
(ORM)...</a></li>
+ <li><a href="../../../Documentation/Cayenne
Guide/Tutorial/Tutorial Java Classes/index.html" title="Tutorial Java
Classes">Creating Java classes...</a></li>
+ </ol>
+ </li>
+ <li>Learning Cayenne API
+ <ol>
+ <li><a href="../../../Documentation/Cayenne
Guide/Tutorial/Tutorial ObjectContext/index.html" title="Tutorial
ObjectContext">Getting started with ObjectContext...</a></li>
+ <li><a href="../../../Documentation/Cayenne
Guide/Tutorial/Tutorial Persistent Objects/index.html" title="Tutorial
Persistent Objects">Getting started with persistent objects...</a></li>
+ <li><a href="../../../Documentation/Cayenne
Guide/Tutorial/Tutorial SelectQuery/index.html" title="Tutorial
SelectQuery">Selecting objects...</a></li>
+ <li><a href="../../../Documentation/Cayenne
Guide/Tutorial/Tutorial Delete/index.html" title="Tutorial Delete">Deleting
objects...</a></li>
+ </ol>
+ </li>
+ <li><a href="../../../Documentation/Cayenne Guide/Tutorial/Tutorial
Webapp/index.html" title="Tutorial Webapp">Converting to web
application...</a></li>
+</ol>
+</div>
</div>
<div class="clearer">.</div>
<div style="height: 12px; background-image:
url('../../../images/border_bottom.gif'); background-repeat: repeat-x;"></div>