Chapter 2. Kodo JDO Tutorial

2.1. The Pet Shop
2.1.1. Included Files
2.1.2. Important Utilities
2.2. Getting Started
2.2.1. Configuring the Data Store
2.3. Inventory Maintenance
2.3.1. Persisting Objects
2.3.2. Deleting Objects
2.4. Inventory Growth
2.5. Behavioral Analysis
2.5.1. Complex Queries
2.6. Extra Features

In this tutorial you will become familiar with the basic tools and development processes under Kodo by creating a simple JDO application.

2.1. The Pet Shop

Imagine that you have decided to create a software toolkit to be used by pet shop operators. This toolkit must provide a number of solutions to common problems encountered at pet shops. Industry analysts indicate that the three most desired features are inventory maintenance, inventory growth simulation, and behavioral analysis. Not one to question the sage advice of experts, you choose to attack these three problems first.

According to the aforementioned experts, most pet shops focus on three types of animals only: dogs, rabbits, and snakes. This ontology suggests the following class hierarchy:

               |         |          |
              Dog      Rabbit     Snake

2.1.1. Included Files

We have provided an implementation of Animal and Dog classes, plus some helper classes and files to create the initial schema and populate the database with some sample dogs. Let's take a closer look at these classes.

  • tutorial.AnimalMaintenance: Provides some utility methods for examining and manipulating the animals stored in the database. We will fill in method definitions in Section 2.3, “Inventory Maintenance”.

  • tutorial.Animal: This is the superclass of all animals that this pet store software can handle.

  • tutorial.Dog : Contains data and methods specific to dogs.

  • tutorial.Rabbit: Contains data and methods specific to rabbits. It will be used in Section 2.4, “Inventory Growth”.

  • tutorial.Snake: Contains data and methods specific to snakes. It will be used in Section 2.5, “Behavioral Analysis”.

  • package.jdo: This is a JDO metadata file that defines which types should be enhanced into persistence-capable or persistence-aware classes. For more information on JDO metadata, consult Chapter 5, Metadata of the JDO Overview.

  • This properties file contains Kodo-specific and standard JDO configuration settings.


    You must specify a valid Kodo license key in the file.

  • solutions: The solutions directory contains the complete solutions to this tutorial, including finished versions of the .java files listed above and a correct package.jdo metadata file.

2.1.2. Important Utilities

  • java: Runs main methods in specified Java classes.

  • javac: Compiles .java files into .class files that can be executed by java.

  • jdoc: Runs the Kodo JDO enhancer against the specified classes. More information is available in Section 5.5, “Enhancement” of the Reference Guide.

  • mappingtool -action refresh: A utility that can be used to create and maintain the object-relational mappings and schema of all persistent classes in a JDBC-compliant data store. This functionality allows the underlying mappings and schema to be easily kept up-to-date with the Java classes in the system. See Chapter 7, Object-Relational Mapping of the Reference Guide for more information.