Chapter 2. Getting Started
Prev | Part IV. Kodo JDO Tutorial | Next

## Chapter 2. Getting Started

Let's compile the initial classes and see them in action. To do so, we must compile the .java files, as we would with any Java project, and then pass the resulting classes through the JDO enhancer:

1. Change to the `tutorial` directory

   All examples throughout the tutorial assume that you are in this directory.

2. Examine `Animal.java`, `Dog.java`, and `SeedDatabase.java`

   These files are good examples of the simplicity JDO engenders. As noted earlier, persisting an object or manipulating an object's persistent data requires almost no JDO specific code. For a very simple example of creating persistent objects, please see the main method of `SeedDatabase.java`. Note the objects are created with normal Java constructors. The files `Animal.java` and `Dog.java` are also good examples of how JDO allows you to manipulate persistent data without writing any specific JDO code.

3. Compile the .java files

   `javac *.java`

   You can use any java compiler instead of `javac`.

4. Enhance the JDO classes

   `jdoc tutorial.jdo` (or `java com.solarmetric.kodo.enhance.JDOEnhancer tutorial.jdo`)

   This step runs the Kodo JDO enhancer on the `tutorial.jdo` file mentioned above. The `tutorial.jdo` file contains an enumeration of all the classes that should be JDO enhanced. The Kodo JDO enhancer will examine the contents of this file and enhance all classes listed in it according to the metadata defined in the file. See the enhancer section of the Reference Guide for more information on the JDO enhancer.

Configure the data store

Now that we've compiled the source files and enhanced the JDO classes, we're ready to set up the database. Included in this distribution is Hypersonic SQL, a pure Java relational database. We have included this database because it is simple to set up and has a small memory footprint; however, you can use this tutorial with any of the relational databases that we support. You can also write your own plugin for any database that we do not support. For the sake of simplicity, this tutorial describes how to set up connectivity only to a Hypersonic SQL database. For more information on how to connect to a different database or how to add support for other databases, see the database section of the Reference Guide.

1. Create the database

   `schematool -action refresh tutorial.jdo` or `java com.solarmetric.kodo.impl.jdbc.schema.SchemaTool -action refresh tutorial.jdo`

   This command refreshes the database configured in `kodo.properties` with the classes listed in `tutorial.jdo`. If you are using the default Hyperson SQL setup, the first time you run the schema tool Hypersonic will create `tutorial_database.properties` and `tutorial_database.script` database files in your current directory. To delete the database, just delete these files.

2. Populate with sample data

   `java tutorial.SeedDatabase`

   This and all other commands except `schematool` output all SQL statements sent to the JDBC driver to `./sql.txt`. The logging configuration is specified by the `com.solarmetric.kodo.Logger` property in `kodo.properties`. Change the value of this property to `stdout` to log to standard output instead. Delete the property to disable logging.

Congratulations! You have now created a JDO-accessible persistent store, and seeded it with some sample data.

Prev | Up | Next
1.2. Important Utilities | Home | Chapter 3. Inventory Maintenance