Return-Path: Delivered-To: apmail-db-ojb-dev-archive@www.apache.org Received: (qmail 34548 invoked from network); 20 Jun 2004 20:58:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 20 Jun 2004 20:58:22 -0000 Received: (qmail 24513 invoked by uid 500); 20 Jun 2004 20:58:23 -0000 Delivered-To: apmail-db-ojb-dev-archive@db.apache.org Received: (qmail 24465 invoked by uid 500); 20 Jun 2004 20:58:22 -0000 Mailing-List: contact ojb-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "OJB Developers List" Reply-To: "OJB Developers List" Delivered-To: mailing list ojb-dev@db.apache.org Received: (qmail 24429 invoked by uid 500); 20 Jun 2004 20:58:21 -0000 Received: (qmail 24403 invoked by uid 99); 20 Jun 2004 20:58:21 -0000 Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.27.1) with SMTP; Sun, 20 Jun 2004 13:58:21 -0700 Received: (qmail 34531 invoked by uid 1797); 20 Jun 2004 20:58:16 -0000 Date: 20 Jun 2004 20:58:16 -0000 Message-ID: <20040620205816.34530.qmail@minotaur.apache.org> From: tomdz@apache.org To: db-ojb-cvs@apache.org Subject: cvs commit: db-ojb/src/doc/forrest/src/documentation/content/xdocs/docu getting-started.xml X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N tomdz 2004/06/20 13:58:16 Modified: src/doc/forrest/src/documentation/content/xdocs site.xml src/doc/forrest/src/documentation/content/xdocs/docu getting-started.xml Log: Added sample to "Getting started" Revision Changes Path 1.3 +4 -1 db-ojb/src/doc/forrest/src/documentation/content/xdocs/site.xml Index: site.xml =================================================================== RCS file: /home/cvs/db-ojb/src/doc/forrest/src/documentation/content/xdocs/site.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- site.xml 20 Jun 2004 18:59:50 -0000 1.2 +++ site.xml 20 Jun 2004 20:58:16 -0000 1.3 @@ -268,6 +268,9 @@ + + + 1.3 +344 -10 db-ojb/src/doc/forrest/src/documentation/content/xdocs/docu/getting-started.xml Index: getting-started.xml =================================================================== RCS file: /home/cvs/db-ojb/src/doc/forrest/src/documentation/content/xdocs/docu/getting-started.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- getting-started.xml 20 Jun 2004 18:59:50 -0000 1.2 +++ getting-started.xml 20 Jun 2004 20:58:16 -0000 1.3 @@ -28,10 +28,16 @@

- This document will guide you through the very first steps of setting up a project with OJB. To - make this easier, OJB comes with a blank project template called ojb-blank which you're - encouraged to use. You can download it here.
+ This document will guide you through the very first steps of setting up a project with OJB. To + make this easier, OJB comes with a blank project template called ojb-blank which you're + encouraged to use. You can download it here.

+

+ For the purpose of this guide, we'll be showing you how to setup the project for a + simple application that handles products and uses MySQL. This is continued later on + in the next tutorial parts. +

+
Acquiring ojb-blank

@@ -56,13 +62,16 @@ ojb-blank project is pre-configured (including all necessary jars).

+
Contents of ojb-blank

Copy the ojb-blank.jar file to your project directory and unpack it via the command

- +

This will unpack it into the ojb-blank directory under wherever you unpacked it from. You can move things out of that directory into your project directory, or, more @@ -81,7 +90,8 @@ \java \resources \schema - \test]]> + \test +]]>

Here's a quick rundown on what the individual directories and files are:

@@ -129,10 +139,30 @@ Place your unit tests in here. +
+ Sample project +

+ For our sample project, we should rename the directory to something more fitting, + like productmanager. +

+

+ Also, since we're using MySQL, we put the MySQL jar of the + jdbc driver, which is called something like + mysql-connector-java-[version]-stable-bin.jar, into the lib + subdirectory. +

+

+ The only other thing missing is the source code, but since that's what the other + tutorials are dealing with, we will silently assume that it is already present in the + src/java subdirectory. +

+
+
The build files +
Configuration via <code>build.properties</code>

@@ -193,7 +223,7 @@ urlProtocol - The protocol of the database url (see below), usually jdbc + The protocol of the database url (see below), usually jdbc. urlSubprotocol @@ -259,6 +289,7 @@

+
Building via <code>build.xml</code> @@ -301,7 +332,7 @@ xdoclet Creates the runtime configuration files that describe the repository, from javadoc comments embedded in your java source files. Details on how to - this are given in the tutorials + this are given in the tutorials and in the documentation of the XDoclet OJB module. @@ -321,15 +352,225 @@ If you want to create the database as well, and you have javadoc comments in your source code that describe the repository, then you would call Ant this way:

- +

This will perform in that order the actions build, xdoclet - and setup-db.
+ (invoked automatically from the next action) and setup-db.
Of course, you do not need to use Torque to setup your database, but it is a convenient way to do so.

+ +
+ Sample project +

+ First we change the database properties to these values (assuming that Torque will + be used to setup the database): +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PropertyValue
jcdAliasWe leave the default value of default.
databaseNameSince the application manages products, we call the database + productmanager.
databaseUserThis depends on your setup. For the purposes of this guide, let's call him + steve.
databasePasswordAgain depending on your setup. How about secret (you know that + you should not use this password in reality ?!).
dbmsNameMySQL
jdbcRuntimeDriverIts called com.mysql.jdbc.Driver.
jdbcLevelFor the newer Mysql drivers this is 3.0.
urlProtocolThe default of jdbc will do.
urlSubprotocolFor MySQL, we're using mysql.
urlDbaliasAssuming that the database runs locally on the default port, we have + //localhost/${databaseName}.
torque.databaseWe want to use Torque, so we put mysql here.
torque.database.createUrlMySQL allows to create a database via jdbc. The url that we should use + to do so, is the normal url used to access the database minus the database + name. So the value here is: + ${urlProtocol}:${urlSubProtocol}://localhost/. + Please note that the trailing slash is important.
+

+ Ok, now we have everything configured for building. The build.properties + file now looks like this (the comments have been removed for brevity): +

+ +

+ Looks like we're ready for building. Again, we're assuming that the source code is + already present. So we're invoking Ant now in the top-level folder + productmanager: +

+ +

+ which should (assuming five java classes) produce an output like this +

+ +[ojbdoclet] Generating ojb repository descriptor (build/resources//repository_user.xml) +[ojbdoclet] Type test.Project +[ojbdoclet] Processed 5 types +[ojbdoclet] Processed 5 types +[ojbdoclet] (XDocletMain.start 47 ) Running +[ojbdoclet] Generating torque schema (build/resources//project-schema.xml) +[ojbdoclet] Processed 5 types + +setup-db: + +check-use-classpath: + +check-run-only-on-schema-change: + +sql-check: + +sql: + [echo] +------------------------------------------+ + [echo] | | + [echo] | Generating SQL for YOUR Torque project! | + [echo] | Woo hoo! | + [echo] | | + [echo] +------------------------------------------+ + +sql-classpath: +[torque-sql] Using contextProperties file: + /home/steve/projects/productmanager/build.properties +[torque-sql] Using classpath +[torque-sql] Generating to file + /home/steve/projects/productmanager/build/resources/report.productmanager.sql.generation +[torque-sql] Parsing file: 'ojbcore-schema.xml' +[torque-sql] (transform.DTDResolver 128 ) Resolver: used database.dtd from + org.apache.torque.engine.database.transform package +[torque-sql] Parsing file: 'project-schema.xml' +[torque-sql] (transform.DTDResolver 140 ) Resolver: used + http://jakarta.apache.org/turbine/dtd/database.dtd + +sql-template: + +create-db-check: + +create-db: +[torque-data-model] Using classpath +[torque-data-model] Generating to file + /home/steve/projects/productmanager/build/resources/create-db.sql +[torque-data-model] Parsing file: 'ojbcore-schema.xml' +[torque-data-model] (transform.DTDResolver 128 ) Resolver: used database.dtd from + org.apache.torque.engine.database.transform package +[torque-data-model] Parsing file: 'project-schema.xml' +[torque-data-model] (transform.DTDResolver 140 ) Resolver: used + http://jakarta.apache.org/turbine/dtd/database.dtd + [echo] + [echo] Executing the create-db.sql script ... + [echo] + [sql] Executing file: + /home/steve/projects/productmanager/build/resources/create-db.sql + [sql] 2 of 2 SQL statements executed successfully + +insert-sql: +[torque-sql-exec] Our new url -> jdbc:mysql://localhost/productmanager +[torque-sql-exec] Executing file: + /home/steve/projects/productmanager/build/resources/project-schema.sql +[torque-sql-exec] Executing file: + /home/steve/projects/productmanager/build/resources/ojbcore-schema.sql +[torque-sql-exec] 50 of 50 SQL statements executed successfully + +BUILD SUCCESSFUL]]> +

+ That was it. You now have your database setup properly. Go on, have a look: +

+ show tables; +]]> +

+ There, all tables for your project, as well as the tables required for some + OJB functionality which we also used in the above process (you can recognize + them by their names which start with ojb_). +

+
+
The runtime configuration files @@ -339,6 +580,7 @@ to be provided: configuration of the OJB runtime, description of the database connection, and description of the repository.

+
Configuring the OJB runtime

@@ -349,6 +591,7 @@ in them, though.

+
Configuring the database connection

@@ -359,6 +602,7 @@ setup this file for you and place it in the build/resources directory.

+
Configuring the repository

@@ -374,7 +618,97 @@ repository metadata and the database schema are generated.

+ +
+ Sample project +

+ Actually, there is not much to do here. For our simple sample application + the default properties of OJB work just fine, so we leave OJB.properties + and OJB-logging.properties untouched. +

+

+ Also, the build file generated the connection descriptor for us, and we were using the + XDoclet OJB module and Torque to generate the repository metadata and database for us. + For instance, the processed connection descriptor (file + build/resources/repository_database.xml) looks like this: +

+ + + + + + + + + + + + + +]]> +

+ If you're curious as to what this stuff means, check this + reference guide. +

+

+ The repository metadata (file build/resources/repository_user.xml) + starts like: +

+ + + + + + + + + + +... +]]> +
+
Learning More

--------------------------------------------------------------------- To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org For additional commands, e-mail: ojb-dev-help@db.apache.org