ReferenceValue

public class ReferenceValue implements SingleValue

A ReferenceValue represents the value of a reference property to another entity.

Differently from other properties, they may be versioned, i.e. they may reference to a specific version of an entity.

Ways to specify a reference value: {id}@{version} using either the version id (a hex’ed sha256 string) or “HEAD”, “HEAD~1”, “HEAD~2” and so on. Note: “HEAD” always means the “HEAD” after the transaction. So, if you are changing the referenced entity in the same transaction and you want to reference the entity in the version before the change you need to use “HEAD~1” because that is the old version of the future.

Author:

Timm Fitschen

Constructors

ReferenceValue

public ReferenceValue(EntityInterface entity, boolean versioned)

ReferenceValue

public ReferenceValue(EntityID id)

ReferenceValue

public ReferenceValue(EntityID id, String version)

ReferenceValue

public ReferenceValue(String name)

If the reference is given by name, versioning is not possible (at the moment).

ReferenceValue

public ReferenceValue(String name, String version)

Methods

addToElement

public void addToElement(Element e)

equals

public boolean equals(Object obj)

equals

public boolean equals(Value val)

Test if this is equal to the other object.

Two references are equal, if 1) they both have IDs and their content is equal or 2) at least one does not have an ID, but their names are equal. Otherwise they are considered unequal.

Parameters:
  • val – The other object.

getEntity

public final EntityInterface getEntity()

getId

public final EntityID getId()

getIdVersion

public String getIdVersion()

getName

public final String getName()

getTable

public Table getTable()

getVersion

public final String getVersion()

parseFromString

public static ReferenceValue parseFromString(String str)

Create a ReferenceValue from a string.

If the string looks like a valid “entityID@version” string, the result will have the corresponding entity and version parts.

parseIdVersion

public static ReferenceValue parseIdVersion(String str)

Split a reference string into an entity part and a version part, if there is a version part.

If parsing the entity ID part to an integer fails, a NumberFormatException may be thrown.

parseReference

public static ReferenceValue parseReference(EntityID reference)

parseReference

public static ReferenceValue parseReference(Object reference)

setEntity

public final void setEntity(EntityInterface entity, boolean versioned)

setId

public final void setId(EntityID id)

setName

public void setName(String name)

toDatabaseString

public String toDatabaseString()

toString

public String toString()

Produce a nice but short string:

Case 1 “versioned” (reference to an entity without specifying that entity’s version): Produces a string like “1234” or “Experiment”. Note that referencing via name is never versioned.

Case 2 “unversioned” (reference to an entity with a specified version): Produces a string like “1234@ab987f”.