You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by tf...@apache.org on 2010/09/23 06:06:48 UTC
svn commit: r1000304 - in
/db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial: index.xml
orm/step1-ant.xml orm/step2.xml orm/step3-ant.xml orm/step4.xml
orm/step5.xml orm/step6-ant.xml
Author: tfischer
Date: Thu Sep 23 04:06:48 2010
New Revision: 1000304
URL: http://svn.apache.org/viewvc?rev=1000304&view=rev
Log:
- fixed the ant tutorial
- changed some wording in the tutorial
Modified:
db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/index.xml
db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step1-ant.xml
db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step2.xml
db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step3-ant.xml
db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step4.xml
db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step5.xml
db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step6-ant.xml
Modified: db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/index.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/index.xml?rev=1000304&r1=1000303&r2=1000304&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/index.xml (original)
+++ db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/index.xml Thu Sep 23 04:06:48 2010
@@ -41,7 +41,7 @@
<p>
Both parts include how to obtain and install the relevant parts of Torque.
The ORM part then contains setting up a database
- and writing a sample application to demonstrate the power of Torque.
+ and writing a sample application.
The code generation part shows how the Torque generator can be used
for custom code generation.<br/>
The tutorial is not a reference. Refer to the
@@ -57,8 +57,8 @@
In this tutorial, it is assumed that you have experience
in programming in Java. It is also assumed that you have already been using
either <a href="http://ant.apache.org">ant</a> or
- <a href="http://maven.apache.org">maven2</a>. If you do not know one of these
- build systems, please look at one of the introductions at their home pages.
+ <a href="http://maven.apache.org">maven2</a> (if you do not know one of these
+ build systems, please look at one of the introductions at their home pages).
It is expected that you have a working installation of the
JDK, Version 1.5 or higher.
<br/>
@@ -114,7 +114,7 @@
The Torque Maven plugin integrates the generator into
<a href="http://maven.apache.org">Maven 2</a>, a software
project management tool. In other words, the maven plugin is
- a frontend for the generator.
+ a maven frontend for the generator.
</li>
<li>
The Torque ant tasks integrate the generator into
@@ -126,8 +126,8 @@
They also include SQL scripts to create all the necessary tables,
constraints etc. in your database.
The information about the database structure
- is contained in an XML file read by the Torque generator,
- which structure is also defined in the Torque templates.
+ is contained in an XML file read by the Torque generator.
+ The structure of this file is also defined in the Torque templates.
</li>
<li>
The Torque runtime has to be included in ORM projects to use the classes
Modified: db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step1-ant.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step1-ant.xml?rev=1000304&r1=1000303&r2=1000304&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step1-ant.xml (original)
+++ db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step1-ant.xml Thu Sep 23 04:06:48 2010
@@ -54,8 +54,8 @@
As a starting point for the build file in your project,
use the following template and save it
as build.xml in the project's base directory.
- Then edit it to reflect your specific needs (
- typically you need to change the database urls,
+ Then edit it to reflect your specific needs
+ (typically you need to change the database urls,
the database host, the database user and password):
</p>
@@ -116,10 +116,9 @@
driver="org.gjt.mm.mysql.Driver"
url="jdbc:mysql://localhost:3306/bookstore"
userid="root"
- password="mysql"
+ password="password"
onerror="continue"
- src="target/generated-sql/schema.sql"
- />
+ src="target/generated-sql/bookstore-schema.sql"/>
</target>
<target name="clean">
@@ -137,11 +136,10 @@
<ul>
<li>
The runtime dependencies of your project to Torque
- in the main dependencies section of the pom
(needed when you compile and use the generated java sources)
</li>
<li>
- The definition configuration of the Torque ant task
+ The definition and configuration of the Torque ant task
</li>
<li>
The configuration of ant's SQL task
@@ -173,7 +171,7 @@
<section name="Library set-up">
<p>
For the Torque generator and SQL ant tasks to work correctly,
- you need to provide them with some addidional libraries.
+ you need to provide them with some additional libraries.
This is done as follows:
</p>
<ul>
@@ -181,8 +179,14 @@
Create the directory lib/ant in your project.
</li>
<li>
- Download the binary distribution of torque-ant-tasks
- and put all libraries from the lib directory
+ Download the binary distribution of torque-templates.
+ Put all libraries from its lib directory
+ plus the torque-templates-${version}.jar from its root directory
+ in the lib/ant directory of your project.
+ </li>
+ <li>
+ Download the binary distribution of torque-ant-tasks.
+ Put the torque-ant-tasks-${version}.jar from its root directory
in the lib/ant directory of your project.
</li>
<li>
Modified: db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step2.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step2.xml?rev=1000304&r1=1000303&r2=1000304&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step2.xml (original)
+++ db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step2.xml Thu Sep 23 04:06:48 2010
@@ -42,7 +42,7 @@
<p>
Your database schema file is typically located in the
<em>src/main/schema</em> directory under the base of your project.
- In this directory, you will create the file <em>project-schema.xml</em>
+ In this directory, you will create the file <em>bookstore-schema.xml</em>
which defines your database schema. The name of
your database schema file must end with
‘schema.xml’ because Torque will only
@@ -62,16 +62,17 @@
ISBN). The author id and publisher id will be
foreign keys in the book table. The schema
representation for this database is stored
- in the file <em>project-schema.xml</em>, which should
- be created in the <em>src/schema</em> directory
+ in the file <em>bookstore-schema.xml</em>, which should
+ be created in the <em>src/main/schema</em> directory
and contain the following:
</p>
<source><![CDATA[
<?xml version="1.0" encoding="ISO-8859-1" ?>
-<!-- TODO: add xsd schema definition here -->
-
-<database
+<database xmlns="http://db.apache.org/torque/4.0/templates/database"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://db.apache.org/torque/4.0/templates/database
+ http://db.apache.org/torque/4.0/templates/database-strict.xsd"
name="bookstore"
defaultIdMethod="native">
Modified: db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step3-ant.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step3-ant.xml?rev=1000304&r1=1000303&r2=1000304&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step3-ant.xml (original)
+++ db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step3-ant.xml Thu Sep 23 04:06:48 2010
@@ -70,7 +70,7 @@ ant generate
<p>
A successful build will be indicated by the
- ‘BUILD SUCCESSFUL’ message.
+ BUILD SUCCESSFUL message.
</p>
<p>
@@ -126,7 +126,7 @@ ant generate
<p>
To create the database tables, you first need to create the schema
- (mysql: database) which you want to use for the tables.
+ (in mysql speak: database) which you want to use for the tables.
E.g. in mysql, execute the following command as root user:
</p>
<source>
@@ -138,7 +138,8 @@ ant generate
make sure that this user has sufficient privileges on the database bookstore
to create tables. Alternatively, you can just use the root user
to create the database tables.
- In both cases, type the following commands in
+ In both cases, check again that the username, password and url
+ of your mysql database is correct in the build.xml, and type the following command in
the top-level directory of your project:
</p>
@@ -149,12 +150,12 @@ ant execute-sql
<p>
Success will be indicated by the message
8 of 8 SQL statements executed successfully
- ‘BUILD SUCCESSFUL’. You can also validate
- this by checking your database. For example, the
- <em>bookstore-schema.xml</em> defined in this
+ BUILD SUCCESSFUL;. You can also validate
+ this by checking your database using the sql commands
+ use bookstore; show tables;.
+ For example, the <em>bookstore-schema.xml</em> defined in this
tutorial should have created the following tables:
- <em>author</em>, <em>book</em>,
- and <em>publisher</em>.
+ <em>author</em>, <em>book</em>, and <em>publisher</em>.
</p>
<p>
Modified: db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step4.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step4.xml?rev=1000304&r1=1000303&r2=1000304&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step4.xml (original)
+++ db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step4.xml Thu Sep 23 04:06:48 2010
@@ -124,12 +124,12 @@ torque.dsfactory.bookstore.connection.pa
</td>
</tr>
<tr>
- <td>torque.database.XXX.connection.username</td>
+ <td>torque.database.XXX.connection.user</td>
<td>
The username that has sufficient privileges
to access your database. This user does not
require privileges to create and drop
- tables, unlike the username that was
+ tables, unlike the user that was
specified in <em>project.properties</em>.
</td>
</tr>
@@ -142,7 +142,7 @@ torque.dsfactory.bookstore.connection.pa
</table>
<p>
- It is worth re-iterating that these run-time
+ It is worth re-iterating that these runtime
properties are not used by Torque when generating
your object model and creating your database. They
are used only by the application utilizing the
Modified: db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step5.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step5.xml?rev=1000304&r1=1000303&r2=1000304&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step5.xml (original)
+++ db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step5.xml Thu Sep 23 04:06:48 2010
@@ -63,11 +63,11 @@ You might be asking yourself, what is th
between the Peer classes (<em>BookPeer</em> and
<em>BaseBookPeer</em>) and their counterparts
(<em>Book</em> and <em>BaseBook</em>), also known as
-Data Objects? The Peer classes “wrap” their
+Data Objects? The Peer classes "wrap" their
associated database tables and provide static methods to
manipulate those tables such as <em>doSelect</em> and
<em>doDelete</em>. Data Objects,
-on the other hand, “wrap” individual rows
+on the other hand, "wrap" individual rows
within those tables and provide getters/mutators for each
column defined in those tables as well as a
<em>save</em> method. Both Peer and Data Objects have a
@@ -451,10 +451,10 @@ PublisherPeer.doDelete(addison);
be used to print the Data Objects without adding
unnecessary code to the core of the application.
The following are the modified <em>Book</em>,
- <em>Author</em>, and <em>Publisher</em> classes,
- which are located in a directory hierarchy matching
- that of the <em>targetPackage</em> you specified in
- your Torque <em>build.properties</em>:
+ <em>Author</em>, and <em>Publisher</em> classes
+ (located under the
+ src/main/generated-java/org/apache/torque/tutorial/om
+ directory):
</p>
<source><![CDATA[
@@ -589,12 +589,19 @@ public class PublisherPeer extends BaseP
initialization of Torque using the <code>torque.properties</code>
file we created earlier.
</p>
+<p>
+ Create a file src/main/java/org/apache/torque/tutorial/om/Bookstore.java
+ with the following content
+</p>
<source><![CDATA[
-package org.apache.torque.tutorial;
+package org.apache.torque.tutorial.om;
+
+import java.io.InputStream;
+import java.util.List;
-import java.util.*;
-import org.apache.torque.tutorial.om.*;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.log4j.*;
import org.apache.torque.Torque;
import org.apache.torque.util.Criteria;
@@ -604,12 +611,17 @@ public class Bookstore
{
try
{
- /*
- * Initializing Torque
- */
- TODO read from classpath
- Torque.init("torque.properties");
- TODO init logging
+ // Initializing Logging
+ BasicConfigurator.configure();
+ Logger.getRootLogger().setLevel(Level.WARN);
+
+ // Initializing Torque
+ InputStream torqueConfigStream
+ = Bookstore.class.getResourceAsStream("/torque.properties");
+ PropertiesConfiguration torqueConfiguration
+ = new PropertiesConfiguration();
+ torqueConfiguration.load(torqueConfigStream);
+ Torque.init(torqueConfiguration);
/*
* Creating new objects. These will be inserted into your database
@@ -720,7 +732,7 @@ public class Bookstore
*/
private static void printBooklist(List<Book> booklist)
{
- for (Book book : books)
+ for (Book book : booklist)
{
System.out.println(book);
}
@@ -728,16 +740,6 @@ public class Bookstore
}
]]></source>
-<p>
- Save this code in the <em>src/main/java</em>
- directory hierarchy with a filename of
- <em>Bookstore.java</em>. The above example must be
- placed in <em>src/main/java/com/kazmier</em>
- directory because of its package definition. Your
- application might go elsewhere depending on the
- package that you've selected.
-</p>
-
</section>
<section name="Where to next">
Modified: db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step6-ant.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step6-ant.xml?rev=1000304&r1=1000303&r2=1000304&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step6-ant.xml (original)
+++ db/torque/torque4/trunk/torque-site/src/site/xdoc/tutorial/orm/step6-ant.xml Thu Sep 23 04:06:48 2010
@@ -39,14 +39,14 @@
create the directory lib/runtime
in the top level directory of the project.
Add all libraries from the lib dir of the torque-runtime binary distribution
- and also the torque-runtime.jar from there.
+ and also the torque-runtime-${version}.jar from its root directory.
Additionally copy the mysql driver jar from lib/ant to lib/runtime.
</p>
<p>
<b>
Note: There is no need to include the torque-generator
- or torque-templates dependencies in your project.
+ or torque-templates dependencies to the runtime of your project.
</b>
</p>
@@ -90,15 +90,16 @@ ant
The classpath almo must include all of your application
and object model classes located in <em>target/classes</em>.
To run the application, change into the root directory
- of the application and type
+ of the application and type (exchange the mysql driver jar for the one
+ which you are actually using)
</p>
<source><![CDATA[
linux:
-java -cp target/classes:lib/runtime/commons-beanutils-1.7.0.jar:lib/runtime/commons-dbcp-1.2.2.jar:lib/runtime/commons-collections-3.2.jar:lib/runtime/commons-configuration-1.4.jar:lib/runtime/commons-lang-2.3.jar:lib/runtime/commons-logging-1.1.jar:lib/runtime/commons-pool-1.3.jar:lib/runtime/log4j-1.2.11.jar:lib/runtime/mysql-connector-java-5.0.4.jar:lib/runtime/torque-runtime-4.0-alpha1-SNAPSHOT.jar:lib/runtime/village-3.3.jar org.apache.torque.tutorial.Bookstore
+java -cp target/classes:lib/runtime/commons-beanutils-1.7.0.jar:lib/runtime/commons-dbcp-1.2.2.jar:lib/runtime/commons-collections-3.2.jar:lib/runtime/commons-configuration-1.4.jar:lib/runtime/commons-lang-2.3.jar:lib/runtime/commons-logging-1.1.jar:lib/runtime/commons-pool-1.3.jar:lib/runtime/log4j-1.2.11.jar:lib/runtime/mysql-connector-java-5.0.4.jar:lib/runtime/torque-runtime-4.0-alpha1-SNAPSHOT.jar:lib/runtime/village-3.3.jar org.apache.torque.tutorial.om.Bookstore
windows:
-java -cp target/classes;lib/runtime/commons-beanutils-1.7.0.jar;lib/runtime/commons-dbcp-1.2.2.jar;lib/runtime/commons-collections-3.2.jar;lib/runtime/commons-configuration-1.4.jar;lib/runtime/commons-lang-2.3.jar;lib/runtime/commons-logging-1.1.jar;lib/runtime/commons-pool-1.3.jar;lib/runtime/log4j-1.2.11.jar;lib/runtime/mysql-connector-java-5.0.4.jar;lib/runtime/torque-runtime-4.0-alpha1-SNAPSHOT.jar;lib/runtime/village-3.3.jar org.apache.torque.tutorial.Bookstore
+java -cp target/classes;lib/runtime/commons-beanutils-1.7.0.jar;lib/runtime/commons-dbcp-1.2.2.jar;lib/runtime/commons-collections-3.2.jar;lib/runtime/commons-configuration-1.4.jar;lib/runtime/commons-lang-2.3.jar;lib/runtime/commons-logging-1.1.jar;lib/runtime/commons-pool-1.3.jar;lib/runtime/log4j-1.2.11.jar;lib/runtime/mysql-connector-java-5.0.4.jar;lib/runtime/torque-runtime-4.0-alpha1-SNAPSHOT.jar;lib/runtime/village-3.3.jar org.apache.torque.tutorial.om.Bookstore
]]></source>
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org