Excel (OOXML) datastore support assumes that objects of a class are persisted to a particular
"sheet" of a spreadsheet. Similarly a field of a class is persisted to a particular "column"
index of that "sheet". This provides the basis for Excel persistence.
When persisting a Java object to an Excel spreadsheet clearly the user would like some control
over what worksheet a class is persisted to, and to what column number a field is persisted.
DataNucleus provides extension metadata tags to allow this control.
Here's an example, using JDO XML metadata
<jdo>
<package name="org.datanucleus.samples.models.company">
<class name="Person" detachable="true" table="People">
<field name="personNum" >
<extension vendor-name="datanucleus" key="index" value="0"/>
</field>
<field name="firstName">
<extension vendor-name="datanucleus" key="index" value="1"/>
</field>
<field name="lastName">
<extension vendor-name="datanucleus" key="index" value="2"/>
</field>
</class>
</package>
</jdo>
Note the following metadata usages (all are optional)
-
The
table
defines the name of the worksheet to use for that class.
-
The
column
defines the column name to use for the field.
-
index
is specified for a field, and defines that field "personNum"
will be persisted as the first column in the worksheet etc.
Again, this is optional and the default is to put the fields in alphabetical order.
Here's the same example using JDO Annotations
@PersistenceCapable(table="People")
public class Person
{
@Extension(vendorName="datanucleus", key="index", value="0")
long personNum;
@Extension(vendorName="datanucleus", key="index", value="1")
String firstName;
@Extension(vendorName="datanucleus", key="index", value="2")
String lastName;
}
Here's the same example using JPA Annotations (with DataNucleus @Extension/@Extensions
annotations)
@Entity
@Table(name="People")
public class Person
{
@Identity
@Extension(key="index", value="0")
long personNum;
@Extension(key="index", value="1")
String firstName;
@Extension(key="index", value="2")
String lastName;
}
Obviously a spreadsheet cannot store related objects directly since each object
is a row of a particular spreadsheet table. DataNucleus gets around this by storing the
String-form of the identity of the related object in the relation cell.
We also support using @Embedded to embed an object within the worksheet of another object.