Note
This section assumes some knowledge of the ODMG binding, mainly the SOD2 specific parts are explained. The complete ODMG reference can be found at the Object Data Management Group. Also the tools package of SOD2 includes a manual which described the API.

Purpose
This tutorial will explain how to start using SOD2. As an example we will create a rectangle object which contains some attributes and two corner points. More complex examples can be found in the packages for the language bindings.

The ODL specification

The object definition language (ODL) is used to describe the schema of the objects to be stored in the database. This definition is language independent, it can be used for Java, C++ and C#:

 
class Rectangle {
attribute string name;
attribute Point upperLeft;
attribute Point lowerRight;
};
class Point {
attribute long x;
attribute long y;
};

Java

The ODL definition is used to generate the corresponding Java-Code:

sod2odlpp -java Rect.odl 

This creates the files Rectangle.java and Point.java, which contain the corresponding class definition. An object can be added to the database like this:

 
using org.odmg.*:
class Store {
public static void main(String[] args) throws Exception {
Implementation impl=de.tneumann.sod2.SOD2.getImplementation();
Database db=impl.newDatabase();
db.open("sod://test:password@localhost/test");
Transaction trans=impl.newTransaction();
trans.begin();

Point p1=new Point(); p1.x=1; p1.y=7;
Point p2=new Point(); p2.x=5; p2.y=2;
Rectangle r=new Rectangle(); r.name="funny";
r.upperLeft=p1; r.lowerRight=p2;
db.bind(r,"a rect");

trans.commit();
db.close();
}
}

Notice that the objects can be created and modified without considering the database, the bind method makes sure that the rectangle is stored in the database. For a more detailed description see the SOD2 manual.

C#

The C# binding can be used very similar to the Java binding. Again the ODL definition is used to generate the C#-Code:

sod2odlpp -cs Rect.odl 

This creates the files Rectangle.cs and Point.cs, which contain the corresponding class definition. An object can be added to the database like this:

 
using odmg:
class Store {
public static void Main() {
IImplementation impl=sod2.SOD2.GetImplementation();
IDatabase db=impl.NewDatabase();
db.Open("sod://test:password@localhost/test");
ITransaction trans=impl.NewTransaction();
trans.Begin();

Point p1=new Point(); p1.x=1; p1.y=7;
Point p2=new Point(); p2.x=5; p2.y=2;
Rectangle r=new Rectangle(); r.name="funny";
r.upperLeft=p1; r.lowerRight=p2;
db.Bind(r,"a rect");

trans.Commit();
db.Close();
}
}

Actually the different bindings can share data; as long as the ODL definition is the same accessing the same objects is no problem.