Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public abstract class EntityDefinition

  1. Object
  2. 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 IOExceptionWrites 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()
The entity class. Used as the registry key.

table

public abstract String table()
The table name: @Entity(table) or the simple class name.

columns

public abstract ColumnDefinition[] columns()
Every persisted column, in a fixed order that indexes into get and set.

newInstance

public abstract Object newInstance()
A new, empty instance. The entity’s public no-arg constructor.

get

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.

set

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. 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.

idIndex

public final int idIndex()
The index of the primary key column, which every entity has exactly one of.

indexOfField

public final int indexOfField(String name)
The index of the column whose field is name, or -1.

toString

public String toString()
Returns 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())