Return-Path:
- 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.
+
@@ -56,13 +62,16 @@
ojb-blank project is pre-configured (including all necessary jars).
Copy the
This will unpack it into the
Here's a quick rundown on what the individual directories and files are:
+ For our sample project, we should rename the directory to something more fitting,
+ like
+ Also, since we're using MySQL, we put the MySQL jar of the
+ jdbc driver, which is called something like
+
+ 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
+
@@ -193,7 +223,7 @@
+ 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.
ojb-blank.jar
file to your project directory and unpack it via
the command
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
+]]>
productmanager
.
+ mysql-connector-java-[version]-stable-bin.jar
, into the lib
+ subdirectory.
+ src/java
subdirectory.
+ build.properties
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 @@
build.xml
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.
+ First we change the database properties to these values (assuming that Torque will + be used to setup the database): +
+Property | +Value | +
---|---|
jcdAlias | +We leave the default value of default . |
+
databaseName | +Since the application manages products, we call the database
+ productmanager . |
+
databaseUser | +This depends on your setup. For the purposes of this guide, let's call him
+ steve . |
+
databasePassword | +Again depending on your setup. How about secret (you know that
+ you should not use this password in reality ?!). |
+
dbmsName | +MySQL |
+
jdbcRuntimeDriver | +Its called com.mysql.jdbc.Driver . |
+
jdbcLevel | +For the newer Mysql drivers this is 3.0. | +
urlProtocol | +The default of jdbc will do. |
+
urlSubprotocol | +For MySQL, we're using mysql . |
+
urlDbalias | +Assuming that the database runs locally on the default port, we have
+ //localhost/${databaseName} . |
+
torque.database | +We want to use Torque, so we put mysql here. |
+
torque.database.createUrl | +MySQL 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 +
+ ++ That was it. You now have your database setup properly. Go on, have a look: +
+ +
+ 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_
).
+
@@ -349,6 +591,7 @@ in them, though.
@@ -359,6 +602,7 @@
setup this file for you and place it in the build/resources
directory.
@@ -374,7 +618,97 @@ repository metadata and the database schema are generated.
+ 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:
+
--------------------------------------------------------------------- To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org For additional commands, e-mail: ojb-dev-help@db.apache.org