Tuple#

com.zitlab.palmyra.store.Tuple

Overview#

Tuple is the base data carrier for every Palmyra operation. It holds the incoming JSON as a flat attribute map plus explicit parent and children maps for related records, and it travels unchanged from the request parser all the way to the database layer. Tuple extends RecordImpl and is Serializable.

Typical lifecycle: the framework hydrates a Tuple from the request, your handler mutates it in preXxx / onXxx, the SQL layer writes it, and postXxx sees the post-write state. On updates the original DB snapshot is available via getDbTuple().

Constants#

Name Value Meaning (via isDbExists())
DB_UNKNOWN 0 Existence not yet checked
DB_NOT_EXISTS 1 Row is new
DB_EXISTS 2 Row exists in DB

Constructors#

Signature
Tuple()
Tuple(int size)
Tuple(String type)
Tuple(String type, int size)
Tuple(String type, int size, Object id)
Tuple(String type, String id)

Methods#

Method Signature
getId / setId Object getId() · void setId(Object id)
get Object get(String key) — dot-notation resolves parent attributes
getAttribute / setAttribute / removeAttribute inherited from RecordImpl — flat attribute access
getParent Map<String, Tuple> getParent() · Tuple getParent(String key)
setParent / addParent / removeParent void setParent(Map<String, Tuple>) · void addParent(String, Tuple) · void removeParent(String) · void setParent(String field, Tuple) (dot-notation)
setParentAttribute void setParentAttribute(String field, Object value) · void setParentAttribute(String ref, String field, Tuple value)
getParentAttribute Object getParentAttribute(String field) · Object getParentAttribute(String parent, String field)
removeParentAttribute Object removeParentAttribute(String attribute)
getParentAttributeAs… typed converters: BigDecimal, Double, Float, Integer, Long, String, LocalDate, LocalDateTime
getChildren Map<String, List<Tuple>> getChildren() · List<Tuple> getChildren(String key)
setChildren / addChildren void setChildren(Map…) · void setChildren(String, List<Tuple>) · void addChildren(String, Tuple)
isDbExists / setDbExists int isDbExists() · void setDbExists(int)
getDbTuple / setDbTuple Tuple getDbTuple() · void setDbTuple(Tuple) — setting also updates dbExists
isEmpty boolean isEmpty() — true when attributes, parents and children are all empty
getPreferredKey / setPreferredKey String getPreferredKey() · void setPreferredKey(String)
getTupleType / setTupleType TupleType getTupleType() · void setTupleType(TupleType)
addAclFieldRight / getAclFieldMap void addAclFieldRight(String, AclFieldRight) · Map<String, AclFieldRight> getAclFieldMap()

Example#

// inside an UpdateHandler.onUpdate
Tuple onUpdate(Tuple tuple, Tuple dbTuple, HandlerContext ctx) {
    // flat attributes
    String login = (String) tuple.get("loginName");
    tuple.setAttribute("loginName", login.toLowerCase());

    // parent reference (dot-notation walks parentMap)
    String tenantName = (String) tuple.get("tenant.name");

    // add/mutate a child collection
    Tuple newRole = new Tuple("Role");
    newRole.setAttribute("code", "VIEWER");
    tuple.addChildren("roles", newRole);

    // diff against the DB snapshot
    if (!Objects.equals(tuple.get("email"), dbTuple.get("email"))) {
        tuple.setAttribute("emailVerified", false);
    }
    return tuple;
}