Class EntityDefinition

java.lang.Object
com.codename1.backend.orm.EntityDefinition

public abstract class EntityDefinition extends Object

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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract ColumnDefinition[]
    Every persisted column, in a fixed order that indexes into get and set.
    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.
    final int
    The index of the primary key column, which every entity has exactly one of.
    final int
    The index of the column whose field is name, or -1.
    abstract Object
    A new, empty instance.
    abstract void
    set(Object entity, int index, Object value)
    Writes the value of column index into entity, converting whatever the engine sent into the field's type.
    abstract String
    The table name: @Entity(table) or the simple class name.
    Returns a string representation of the object.
    abstract Class
    The entity class.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 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.

      Throws:
      IOException
    • 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()
      Description copied from class: Object
      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())
      Overrides:
      toString in class Object