Speedo ORM examples


The ORM example provides several independant examples of O/R mapping using the JDO 2 dtd. This means no extension specific to Speedo is used in these examples to define the mapping. The examples are very simple, in order to show one particular point only. The examples come from the JDO 2 specification or from Speedo test suite. Here is an outline of page about ORM examples.

  1. How to compile ORM examples ?
  2. How to run an example ?
  3. Example descriptions

How to compile ORM examples ?

All ORM examples are compiled in same time. A ant build.xml is provided. The target compile is in charge of the compilation and the enhancement of persistent classes.

Be careful, to compile the ORM examples, the speedo.jar archive is required. This one must be build previously in the base of the Speedo distribution. It can be build by the ant build.xml file provided at the root of the distribution.

Here is the output of the compilation step :

~/workspace/speedo/output/dist/jdo/examples/orm#ant compile
Buildfile: build.xml

init:

build.speedo.archive:

archives:

archives-speedo.jar:
[speedo.jar] Building zip: /home/sebastien/workspace/speedo/output/dist/jdo/speedo.jar

archives-speedo_light.jar:
[speedo.jar] Building zip: /home/sebastien/workspace/speedo/output/dist/jdo/speedo_light.jar

archives-speedo_client.jar:
[speedo_client.jar] Building zip: /home/sebastien/workspace/speedo/output/dist/jdo/speedo_client.jar

archives-speedo_ra.rar:
[speedo_ra.rar] Building jar: /home/sebastien/workspace/speedo/output/dist/jdo/speedo_ra.rar

archives-jonas:
[speedo_for_jonas_ra.rar] Building zip: /home/sebastien/workspace/speedo/output/dist/jdo/speedo_for_jonas_ra.jar
[speedo_for_jonas_ra.rar] Building jar: /home/sebastien/workspace/speedo/output/dist/jdo/speedo_for_jonas_ra.rar

archives-weblogic:
[speedo_for_weblogic_ra.rar] Building jar: /home/sebastien/workspace/speedo/output/dist/jdo/speedo_for_weblogic_ra.rar

compile:
    [mkdir] Created dir: /home/sebastien/workspace/speedo/output/dist/jdo/examples/orm/build
    [mkdir] Created dir: /home/sebastien/workspace/speedo/output/dist/jdo/examples/orm/build/db
    [javac] Compiling 49 source files to /home/sebastien/workspace/speedo/output/dist/jdo/examples/orm/build
    [javac] Note: /home/sebastien/workspace/speedo/output/dist/jdo/examples/orm/src/map/Main.java uses or overrides a deprecated API.
    [javac] Note: Recompile with -deprecation for details.
[speedo-jdo] [INFO] Loading jdo2 descriptor files...
[speedo-jdo] [INFO] Computing classes requiring enhancement ...
[speedo-jdo] [INFO] Recompiling classes ...
[speedo-jdo] [INFO] Completing the meta data...
[speedo-jdo] [INFO] Auto O/R Mapping...
[speedo-jdo] [INFO] Building Jorm Meta Information...
[speedo-jdo] [INFO] Generating Jorm files...
[speedo-jdo] [INFO] Generating Speedo files...
[speedo-jdo] [WARN] No object id class defined for the class 'map.Address': use the generated class: 'map.Address_Id'
[speedo-jdo] [WARN] No object id class defined for the class 'compositepk.Address': use the generated class: 'compositepk.Address_Id'
[speedo-jdo] [WARN] No object id class defined for the class 'compositepk.Person': use the generated class: 'compositepk.Person_Id'
[speedo-jdo] [INFO] Serializing Meta Info...
[speedo-jdo] [INFO] Enhancing Persistent classes...
[speedo-jdo] [INFO] Enhancing Persistent aware classes...
[speedo-jdo] [INFO] Compiling Java files...
[speedo-jdo] [INFO] All Done in 12s 411ms

BUILD SUCCESSFUL
Total time: 18 seconds

How to run an example ?

To run ORM examples, firstly you have to configure your speedo-jdo.properties configuration file. It is located into the 'etc' directory of the distribution. For more information about the editing of this file, see the user manual of Speedo (included in Speedo documentation).

The ant build.xml file provide one target for each ORM examples and a target run executing all examples.

To know all targets available, execute ant -p:

~/workspace/speedo/output/dist/jdo/examples/orm#ant -p
Buildfile: build.xml

Main targets:

 createDataStruct                     Create the data structure for persistent classes
 run                                  Run all examples
 run.collection                       run the example 'simplecollection'
 run.compositepk                      run the example 'compositepk'
 run.inheritance.filtered.hidden      run the example 'inheritance.filtered.disc_hidden'
 run.inheritance.filtered.outofpk     run the example 'inheritance.filtered.disc_outof_pk'
 run.inheritance.filtered.pk          run the example 'inheritance.filtered.disc_in_pk'
 run.inheritance.horizontal.speedoid  run the example 'inheritance.horizontal.speedoid'
 run.map                              run the example 'map'
 run.ref                              run the example 'simplereference'
 run.rel.mm                           run the example 'rel_many_to_many'
 run.rel.om                           run the example 'rel_one_to_many'
 run.rel.oo                           run the example 'rel_one_to_one'
 run.secondarytable                   run the example 'secondaryTable'
 run.simpleclass                      run the example 'simpleclass'
Default target: compile

Example descriptions

Name Description Ant target
Simple class It shows a simple class stored on a table. the persistent class contains only primitive fields. run.simpleclass
Simple reference It shows a simple class referencing another one. It shows the declaration of foreign key colomn. run.simpleclass
Simple collection It shows a simple class referencing a collection of persistent instances corresponding to another class. As there is no bidirectional relationship between both classes, an intermediaite table is required. run.collection
Map It shows a simple class referencing a Map(Date,String). run.map
Composite Primary key This example is similar to 'simple reference' but with composite identifier of persistent classes. run.compositepk
Relation One-One It shows a bidirectional One-One relationship. run.rel.oo
Relation One-Many It shows a bidirectional One-Many relationship (no join table used). run.rel.om
Relation Many-Many It shows a bidirectional Many-Many relationship (join table required). run.rel.mm
Secondary table It shows a simple class stored on several tables. run.secondarytable
Inheritance Filtered with discriminator included in primary key It shows an inheritance tree using a field of the primary key as disriminator between classes of inheritance tree. This strategy is the most efficient. run.inheritance.filtered.pk
Inheritance Filtered with discriminator out of primary key It shows an inheritance tree using a column as disriminator between classes of inheritance tree. This column is not mapped on a persistent field. It is hidden from persistent model. run.inheritance.filtered.outofpk
Inheritance Filtered hidden column It shows an inheritance tree using a column as disriminator between classes of inheritance tree. This column is not mapped on a persistent field. It is hidden from persistent model. run.inheritance.filtered.hidden
Inheritance horizontal with speedo identifier It shows an inheritance tree map with the horizontal strategy: One table per class. Each table contains all fields of the class (including inherited fields). The identifier of the persistent class is managed by Speedo. By this way it permits to identifier the instance and the class. run.inheritance.horizontal.speedoid