- Type Parameters:
T- the root table type (the entity from which the path originates).E- the field type of the designated element.
- All Known Subinterfaces:
Metamodel.Key<T,E>
- All Known Implementing Classes:
AbstractKeyMetamodel,AbstractMetamodel,Metamodel.KeyDelegate
User_ for a User entity) contain static fields representing each entity field, enabling
compile-time verification of field references.
Nested Paths (Fully Qualified)
Nested paths traverse from the root entity through relationships by chaining field accessors:
// Traverse User → City → Country → name
User_.city.country.name
Nested paths are always unambiguous because they explicitly specify the traversal from the root entity. Storm automatically generates the necessary JOINs based on the path.
Short Form
Short form references a table's metamodel directly without specifying the path:
// Reference Country directly
Country_.name
Short form works only when the table appears exactly once in the entity graph. If the table is referenced in multiple places, Storm cannot determine which occurrence you mean and throws an exception.
Short form is also used to reference tables added via custom joins, since those tables are not reachable through nested paths.
Path Resolution
When resolving a metamodel reference, Storm follows this order:
- Nested path — If a path is specified (e.g.,
User_.city.country), use the alias for that specific traversal - Unique table lookup — If short form (e.g.,
Country_), check if the table appears exactly once in the entity graph or registered joins - Error — If multiple paths exist, throw an exception indicating the ambiguity
- Since:
- 1.2
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceMetamodel.Key<T extends Data,E> Marker interface for metamodel fields that correspond to columns known to be unique.static final recordMetamodel.KeyDelegate<T extends Data,E> Delegating wrapper that adds theMetamodel.Keymarker to an existingMetamodelinstance. -
Method Summary
Modifier and TypeMethodDescriptionReturns the canonical metamodel for the field represented bythismetamodel.field()Returns the field name.default StringReturns the field path.Returns the field type of the designated element.flatten()Returns a flat list of leaf metamodels for this metamodel.Extracts the value from the given record as specified by this metamodel.booleanisColumn()Returnstrueif the metamodel corresponds to a database column, returnsfalseotherwise, for example, if the metamodel refers to the root metamodel or an inline record.booleanisIdentical(T a, T b) Checks whether the value extracted fromais identical to the value extracted fromb.booleanisInline()Returnstrueif the metamodel corresponds to an inline record, returnsfalseotherwise.booleanChecks whether the value extracted fromais the same as the value extracted fromb.static <T extends Data,E>
Metamodel.Key<T, E> Returns aKeyview of the given metamodel.Creates a new metamodel for the given root rootTable and path.path()Returns the path to the database table.root()Returns the root metamodel.Creates a new metamodel for the given record type.table()Returns the table that holds the column to which this metamodel is pointing.Returns the type of the table that holds the column to which this metamodel is pointing.
-
Method Details
-
root
Creates a new metamodel for the given record type.- Type Parameters:
T- the root table type.- Parameters:
table- the root table to create the metamodel for.- Returns:
- a new metamodel for the given record type.
-
of
Creates a new metamodel for the given root rootTable and path.This method is typically used to manually create a metamodel for a component of a record, which can be useful in cases where the metamodel cannot be generated automatically, for example, local records.
- Type Parameters:
T- the root rootTable type.E- the record component type of the designated component.- Parameters:
rootTable- the root rootTable to create the metamodel for.path- a dot separated path starting from the root table.- Returns:
- a new metamodel for the given root rootTable and path.
- Throws:
PersistenceException- if the metamodel cannot be created for the root rootTable and path.
-
canonical
Returns the canonical metamodel for the field represented bythismetamodel. The resulting metamodel captures only the table type and field.The result is independent of the position of this field within a table graph. This makes the normalized form suitable for equality checks, for example, to determine whether two metamodels refer to the same underlying field.
- Returns:
- the canonical metamodel for this metamodel.
- Since:
- 1.8
-
isColumn
boolean isColumn()Returnstrueif the metamodel corresponds to a database column, returnsfalseotherwise, for example, if the metamodel refers to the root metamodel or an inline record.Note that a column can also be a table, for example, in the case of a foreign key.
- Returns:
trueif this metamodel maps to a column,falseotherwise.
-
isInline
boolean isInline()Returnstrueif the metamodel corresponds to an inline record, returnsfalseotherwise.- Returns:
trueif this metamodel maps to an inline record,falseotherwise.
-
root
Returns the root metamodel. This is typically the table specified in the FROM clause of a query.- Returns:
- the root metamodel.
-
table
Returns the table that holds the column to which this metamodel is pointing. If the metamodel points to an inline record, the table is the parent table of the inline record. If the metamodel is a root metamodel, the root table is returned.- Returns:
- the table that holds the column to which this metamodel is pointing.
-
tableType
Returns the type of the table that holds the column to which this metamodel is pointing.- Returns:
- the type of the table that holds the column to which this metamodel is pointing.
- Since:
- 1.7
-
path
String path()Returns the path to the database table.- Returns:
- path to the database table.
-
fieldType
Returns the field type of the designated element.- Returns:
- the field type of the designated element.
-
field
String field()Returns the field name.- Returns:
- field name.
-
fieldPath
Returns the field path.- Returns:
- field path.
-
getValue
Extracts the value from the given record as specified by this metamodel.The returned value may be
nullif this metamodel represents a nullable field or if any parent metamodel in the access path resolves tonull(for example, when navigating through an optional or nullable nested record).Implementations may return a non-null value, but callers must not rely on that unless they statically know they are using a non-null metamodel variant.
- Parameters:
record- the root record from which the value is extracted.- Returns:
- the extracted value, or
nullif the value cannot be resolved. - Since:
- 1.7
-
flatten
Returns a flat list of leaf metamodels for this metamodel. If this metamodel is not an inline record, it returns a singleton list containingthis. If it is an inline record, it recursively expands all nested inline records and returns the individual column metamodels.This method is useful for operations like ORDER BY and GROUP BY, where inline records need to be expanded into their individual columns.
- Returns:
- a list of leaf metamodels.
- Since:
- 1.9
-
isIdentical
Checks whether the value extracted fromais identical to the value extracted fromb.Semantics: This method performs an identity comparison on the extracted field value. It returns
trueif and only if both extracted values refer to the same object instance.This operation is only meaningful for reference-typed fields. It is not defined for primitive-typed fields.
Performance guarantees:
- No boxing or unboxing is performed.
- No value coercion or conversion is performed.
- No
equals(...)or comparator logic is used.
- Parameters:
a- the instance from which the left-hand value is extracted, must not benull.b- the instance from which the right-hand value is extracted, must not benull.- Returns:
trueif both extracted values are the same object instance.- Since:
- 1.7
-
isSame
Checks whether the value extracted fromais the same as the value extracted fromb.Semantics: This method performs a value comparison on the extracted field value. The comparison is defined by the field type:
- For primitive-typed fields, values are compared using
==. - For reference-typed fields, values are compared using their defined value semantics
(for example
equals(...)or an equivalent comparator).
Performance guarantees:
- No boxing or unboxing is performed.
- No identity comparison is performed.
- The comparison operates directly on the extracted values.
- Parameters:
a- the instance from which the left-hand value is extracted, must not benull.b- the instance from which the right-hand value is extracted, must not benull.- Returns:
trueif both extracted values are equal by value.- Since:
- 1.7
- For primitive-typed fields, values are compared using
-
key
Returns aKeyview of the given metamodel. Ifmetamodelalready implementsMetamodel.Key, it is returned as-is; otherwise it is wrapped in a delegate that implementsKey.This factory is intended for cases where the generated metamodel does not carry the
Keymarker (for example, composite primary keys or dynamically constructed metamodels), or where a column is known to produce unique values in a particular query context (for example, a column that appears in aGROUP BYclause).Important: callers are responsible for ensuring that the column produces unique values in the context where the key is used. Using a non-unique column as a keyset pagination key will silently skip rows when duplicate values span page boundaries.
- Type Parameters:
T- the root table type.E- the field type.- Parameters:
metamodel- the metamodel to view as a key.- Returns:
- a
Keyinstance backed by the given metamodel. - Since:
- 1.9
-