Class EntityDefinition
What the build generated about one entity class: its table, its columns, and reflection-free access to its fields.
Application code never implements this. The Codename One Maven plugin reads
@Entity, @Id, @Column and @DbTransient out of the compiled entity and writes a
subclass whose get and set are switch statements over field access -- which is
the whole reason the ORM exists as a build step rather than as a library. This
runtime has no reflection: a field reached by name at run time is a field that
is not there after the translator has renamed it.
One instance exists per entity class and is shared by every request, so an
implementation holds no state: get(Object, int) and set(Object, int, Object) take the entity
they are working on.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract ColumnDefinition[]columns()Every persisted column, in a fixed order that indexes into get and set.abstract ObjectThe value of columnindexonentity, already in the form a parameter is bound as: Long, Double, String, byte[] or null.final intidIndex()The index of the primary key column, which every entity has exactly one of.final intindexOfField(String name) The index of the column whose field isname, or -1.abstract ObjectA new, empty instance.abstract voidWrites the value of columnindexintoentity, converting whatever the engine sent into the field's type.abstract Stringtable()The table name: @Entity(table) or the simple class name.toString()Returns a string representation of the object.abstract Classtype()The entity class.
-
Constructor Details
-
EntityDefinition
public EntityDefinition()
-
-
Method Details
-
type
The entity class. Used as the registry key. -
table
The table name: @Entity(table) or the simple class name. -
columns
Every persisted column, in a fixed order that indexes into get and set. -
newInstance
A new, empty instance. The entity's public no-arg constructor. -
get
-
set
Writes the value of column
indexintoentity, converting whatever the engine sent into the field's type. SeeValues.Declared to throw because the conversion can fail and the failure is worth reporting: a column holding text where the field is a number means the table is not the one this entity describes, and that is a message somebody can act on rather than a zero appearing in a field.
- Throws:
IOException
-
idIndex
public final int idIndex()The index of the primary key column, which every entity has exactly one of. -
indexOfField
The index of the column whose field isname, or -1. -
toString
Description copied from class:ObjectReturns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
-