Although the C++ binding is more complete than the Java binding - essentially according to the administrative operations - the Java bindings allow to manipulate data without limitations.
Using the Java binding is very similar to the C++ binding. The Java code is generated from the ODL schema definition using for instance the following command, to generate code for the person schema that we have already used:
% eyedbodl --gencode=Java --package=person person.odlThis command will generate a number of Java file in subdirectory person/, each generated file containing a Java class having the same name.
The Java binding support both the standalone applications and the applets.
To compile the Java code, you will need to pass to the Java compiler a classpath that contains eyedb.jar, located in directory «libdir»/eyedb/java/ where libdir is the library directory, usually /usr/lib.
Here is a simple example which show how to:
This example is located in the examples/GettingStarted subdirectory.
//
// Persontest.java
//
import person.*;
class PersonTest {
public static void main(String args[]) {
// Initialize the eyedb package and parse the default eyedb options
// on the command line
String[] outargs = org.eyedb.Root.init("PersonTest", args);
// Check that a database name is given on the command line
int argc = outargs.length;
if (argc != 1)
{
System.err.println("usage: java PersonTest dbname");
System.exit(1);
}
try {
// Initialize the person package
person.Database.init();
// Open the connection with the backend
org.eyedb.Connection conn = new org.eyedb.Connection();
// Open the database named outargs[0]
person.Database db = new person.Database(outargs[0]);
db.open(conn, org.eyedb.Database.DBRW);
db.transactionBegin();
// Create two persons john and mary
Person john = new Person(db);
john.setFirstname("john");
john.setLastname("travolta");
john.setAge(26);
Person mary = new Person(db);
mary.setFirstname("mary");
mary.setLastname("stuart");
mary.setAge(22);
// Mary them ;-)
john.setSpouse(mary);
// Store john and mary in the database
john.store(org.eyedb.RecMode.FullRecurs);
john.trace();
db.transactionCommit();
}
catch(org.eyedb.Exception e) { // Catch any eyedb exception
e.print();
System.exit(1);
}
}
}