Java applications define the database classes to be managed in the eXtremeDB runtime using native Java class syntax and applying special annotations.
For example, the following code snippet would define a database with two classes Department and Employee:
@Persistent() class Department { @Indexable(Type = Database.IndexType.BTree, Unique = true) public String code; public String name; @Indexable(Type = Database.IndexType.Hashtable, Unique = true) public int dept_no; } @Index("byDept_EmployeeName", Keys = new String[] { "dept_no", "name" }, Unique = false) @Persistent() class Employee { @Indexable(Type = Database.IndexType.BTree, Unique = true) public String name; public int dept_no; }Note that the annotations
@Persistent(),@Indexable()and@Index()are used to specify the classes and indexes to be generated and maintained in the database.eXtremeDB JNI Database Annotations
The annotations that are recognized as eXtremeDB database specifications are as follows:
Persistent
Class annotation: Marks this class as “stored in the database” and optionally provides some attributes of this class:
Persistent(autoid=true)— Creates anautoidindex.Persistent(list=true)— Creates a list index.Persistent(large=true)— Declares the standard storage model (default).Persistent(compact=true)— Declares the compact storage model.Persistent(inmemory=true)— Declares this class as in-memory (default).Persistent(disk=true)— Declares this class as disk-based (i.e., on persistent storage media).Persistent(local=true)— Declares this class aslocalfor eXtremeDB High Availability partial replication.Index
Class annotation: Defines a compound (multi-field) index; possible properties are:name="indexName"Identifies this index.keys={Key(“field1”) [, Key(“field2”) …] }Lists the key fields.unique=trueCreates a b-tree index (the default);trueenforces uniqueness, whilefalseallows duplicates.thick=trueOptimizes the index for a large number of duplicates.descending=trueUsesascendingorder by default.initSize=NSpecifies the initial hash table size asNfor hash indexes.type=Database.IndexType.BTreePossible
Database.IndexTypevalues are:
BTree— Creates atreeindex (the default).Hashtable— Creates ahashindex.Patricia— Creates apatriciaindex.RTree— Creates anrtreeindex.RTreeOfPoint— Creates anrtreeindex.KDTree— Creates akdtreeindex.Trigram— Creates atrigramindex.For example:
@Index(name="byName", keys={ Key("lastName"), Key("firstName") }, unique=true ) class Employee { String firstName; String lastName; Address address; long salary; }Indexable
Field annotation: Specifies an index on the following field. The index will have the same name as the field. With the exception ofnameandkeysproperties, the possible properties are the same as for class attributeIndex(above).
For example:class Obj { @Indexable(Type=Database.IndexType.BTree, Unique=true) public int value; }Encoding
Field annotation: Specifies the encoding of string fields. Can be any valid encoding supported by the Java runtime.UTF-8is the default. Examples:@Encoding("UTF-16") String s1; @Encoding("ASCII") String s2;Blob
Field annotation: Uses eXtremeDB BLOB type for storing a byte array; for example:@Blob byte photo[];Dimension
Field annotation: Specifies the dimension for fixed-size arrays (char, scalar). An array without a dimension will be treated as avector(dynamic array).
Example:@Dimension(8) String prefix;Numeric
Field annotation: Specifies the width and precision for decimal fields.
Example:@Numeric(12,3) decimal d; // Equivalent to decimal<12,3> d;Binary
Field annotation: Specifies a fixed-length binary field.
Example:@Binary(100) byte[] dim100_binary; // A Binary array of 100 bytesVarbinary
Field annotation: Specifies a variable-length binary field.
Example:@Varbinary byte[] var_binary; // A Binary vector (dynamic array)Nullable
Field annotation: Specifies that this field can be null.
Example:@Nullable boolean isALive; // Explicitly declared nullable fieldOptionalStruct
Field annotation: Defines a structure field as optional; for example:@OptionalStruct NestedStruct opt_nested; // optional NestedStruct opt_nested;References
Field annotation: Used to declare a field of typerefwhich refers to a class in the schema; for example:@References(ClassA.class) long a;Sequence
Field annotation: Used to declare a field of typesequence; for example:Note that when an@Sequence(type=Sequence.Type.UInt8) OrderedSequence stamp;OrderedSequenceis declared, the default order isAscending. The default can be overridden explicitly:@Sequence(order=Sequence.Order.Descending, type=Sequence.Type.UInt8) OrderedSequence stamp;