Java applications use the
new
operator to instantiate an object and the assignment operator to modify the objects values. To create the database store of the object the Connection methodinsert()
is called within a transaction. For example:@Persistent // Class Record will be stored in eXtremeDB database class Record { @Indexable(unique=true) // Create unique (tree) eXtremeDB index by "id" field int id; public String str; } ... Connection con = new Connection(db); con.startTransaction(Database.TransactionType.ReadWrite); // Start RW transaction Record rec = new Record(); rec.id = 3; rec.str = "Record 3"; con.insert(rec); con.commitTransaction();To update an object, it is first found with a Cursor navigation, then its fields are modified and the Cursor method
update()
is called with the object handle. For example:cursor = new Cursor<Record>(con, "id"); // find record with id == 3 rec = cursor.find(3); rec.str = "Updated string"; cursor.update(); cursor.close(); //release cursor con.CommitTransaction();To delete an object from the database, the object is first found with a Cursor navigation, then the Cursor method
remove()
is called with the object handle. For example:cursor = new Cursor<Record>(con, "id"); // find record with id == 3 rec = cursor.Find(3); cursor.remove(); // remove current object (pointed to by the cursor) cursor.close(); //release cursor con.CommitTransaction();Strings and Arrays
The
Length
property ofString
fields can be used to determine their actual size in bytes. Also, sincevectors
(aka dynamic arrays) in eXtremeDB are simply declared with the native language array syntax, the fieldsLength
property gives the number ofvector
elements.In Java applications, the elements of
vector
(array) fields are accessed using the normal array element operator[]
and specifying the index of the desired element.Nullable Fields
A Java class field can be explicitly declared nullable with the
@nullable
annotation. For example:class Record { @Indexable(Unique=true) // Create unique (tree) eXtremeDB index by "id" field public int id; @Nullable public int weight; }Here field weight may have
null
values.Please see the Nullable Fields and Indexes page for an explanation of the behavior of nullable fields included in indexes.
Blob Support
Java applications use the
@Blob
field annotation to define a BLOB field.Date, Time and Datetime Fields
Please refer to the Datetime FIelds page for a detailed description of the eXtremeDB
date
,time
anddatetime
database field types. The Java APIs for determining precision and accessingdate
,time
anddatetime
fields are described in the Managing Datetime Fields in Java page.