Dynamic Access

Home > Object Persistency API > API Reference > Dynamic Access

Apart from a static API, OOMEGA offers dynamic access to objects whose structure is not known until runtime execution.

The DataObject interface is implemented by every entity class and attribute class; it offers generic getter and setter methods.

package org.oomega.base;

public interface DataObject extends Serializable, EvaluationObject {
    public <T> Collection<T> mget(Property<T> property);
    public <T> void mset(Property<T> property, Collection<? extends T> value) throws NoSingletonException, ClassCastException;

    public <T extends EntityObject> Collection<OId<T>> mgetIdsOf(Property<T> property);
    public <T extends EntityObject> void msetIdsOf(Property<T> property, Collection<OId<T>> oids) throws NoSingletonException, ClassCastException;

    public <T> T eget(Property<T> property) throws NoSingletonException;
    public <T> void eset(Property<T> property, T value) throws ClassCastException;
}

Class fields are referenced via properties. A Property object can be created statically or dynamically.

  • Static reference to the field spouse: Person.P.spouse
  • Dynamic reference to the field spouse: Property.get("spouse")

These properties can be used when calling generic getter and setter methods:

  • mget is the generic getter for multi-valued properties. It can be applied to single-valued properties as well, but it will always return a collection.
  • mset is the generic setter for multi-valued properties. It can be applied to single-valued properties as well, but there's always a collection parameter needed.
  • mgetIdsOf is the pendant to mget but will return a collection of OIDs.
  • msetIdsOf is the pendant to mset but will accept a collection of OIDs.
  • eget is the generic getter for single-valued properties. It can be applied to multi-valued properties as well, but it will fail if the size of the collection is greater than 1.
  • eset is the generic setter for single-valued properties. It can be applied to multi-valued properties as well.

Here’s a simple example. Let's query for the name of dad's spouse.

Person dad = (Person) eocSession.execute(Query(from(Person.CID), where(like(lower(P(Person.P.name)), "lauro*")))).iterator().next();
System.out.println("spouse.name: " + dad.eget(Person.P.spouse).eget(Person.P.name);

> spouse.name: Roswitha Merenda

You might have noticed that this example is in fact not dynamic because the properties are created statically. As mentioned before we can change this.

Person dad = (Person) eocSession.execute(Query(from(Person.CID), where(like(lower(P(Person.P.name)), "lauro*")))).iterator().next();
System.out.println("spouse.name: " + dad.eget(Property.get("spouse")).eget(Property.get("name"));

> spouse.name: Roswitha Merenda

Next chapter: Streaming

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.