Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public abstract class EntityDefinition
- Object
- 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 and set take the entity
they are working on.
Constructors
public EntityDefinition() |
Methods
public abstract Class type() | The entity class. |
public abstract String table() | The table name: @Entity(table) or the simple class name. |
public abstract ColumnDefinition[] columns() | Every persisted column, in a fixed order that indexes into get and set. |
public abstract Object newInstance() | A new, empty instance. |
public abstract Object get(Object entity, int index) | The value of column index on entity, already in the form a parameter is bound as: Long, Double, String, byte[] or null. |
public abstract void set(Object entity, int index, Object value)
throws IOException | Writes the value of column index into entity, converting whatever the engine sent into the field’s type. |
public final int idIndex() | The index of the primary key column, which every entity has exactly one of. |
public final int indexOfField(String name) | The index of the column whose field is name, or -1. |
public String toString() | Returns a string representation of the object. |
Inherited methods
Constructor details
EntityDefinition
public EntityDefinition()Method details
type
public abstract Class type()table
public abstract String table()columns
public abstract ColumnDefinition[] columns()newInstance
public abstract Object newInstance()get
public abstract Object get(Object entity, int index)index on entity, already in the form a
parameter is bound as: Long, Double, String, byte[] or null.set
public abstract void set(Object entity, int index, Object value)
throws IOExceptionWrites the value of column index into entity, converting
whatever the engine sent into the field’s type. See Values.
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
idIndex
public final int idIndex()indexOfField
public final int indexOfField(String name)name, or -1.toString
public String toString()