Class SFieldMeta

java.lang.Object
simpleorm.dataset.SFieldMeta
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
SFieldReference, SFieldScalar

public abstract class SFieldMeta extends Object implements Serializable
Each instance defines the meta data for a field in an SRecordMeta. Subclasses are used for specific data types, with SFieldObject being the most generic. Like JDBC, type conversions are made automatically.

Internally, the types are stored accurately. Ie. the SRecordInstance.getObject objects are the exact types as declared (String, Integer, Employee etc.) However, generous automatic conversions are performed both when accessing these from the application and when getting and setting columns in the database.

See Also:
  • Field Details

    • quoteName

      public boolean quoteName
  • Method Details

    • getFlags

      protected EnumSet<SFieldFlags> getFlags()
    • isUnqueried

      public boolean isUnqueried()
    • isDescriptive

      public boolean isDescriptive()
    • setQuoted

      public <T extends SFieldMeta> T setQuoted(boolean quoted)
      Causes the generated sql to quote ("") the column name. Makes it case sensitive, allows reserved words and odd characters. Beware that Postgresql (only) defaults to lower case, not upper case.
    • queryFieldValue

      public abstract Object queryFieldValue(ResultSet rs, int sqlIndex) throws Exception
      Issues a JDBC get*() on the result set for the field and converts the database type to the appropriate internal type, eg, Double for a double field. The first column has sqlIndex==1.
      Throws:
      Exception
    • convertToDataSetFieldType

      protected abstract Object convertToDataSetFieldType(Object raw) throws Exception
      Converts the parameter from the raw type parameter to the correct internal Object type that is stored in the data set. Returns the object if no conversion necessary. Used by SRecordInstance.setObject etc., Not getObject.
      Throws:
      Exception
    • writeFieldValue

      public void writeFieldValue(PreparedStatement ps, int sqlIndex, Object value)
      Places a value in a prepared statement in the database representation used during SRecordInstance.flush. Can convert between internal values and database values, eg. TRUE to "Y".

      (This does NOT need to handle NULL values (those are handled seperately by SRecordInstance))

    • writeFieldValue

      public Object writeFieldValue(Object value)
      Converts a single value from internal representation to database representation. Used primarily by the writeFieldValue above, but also used for converting optimistic lock values in SRecordInstance.flush.

      Overidden by SFieldBoolean. (not by SFieldString).

      NOTE: This does NOT need to handle NULL values (those are handled seperately by SRecordInstance)

    • toString

      public String toString()
      Lists the record and column name only. Useful in traces.
      Overrides:
      toString in class Object
    • toLongerString

      public abstract String toLongerString()
      Lists all the details of the field.
    • isForeignKey

      protected boolean isForeignKey()
    • nextGeneratedValue

      public long nextGeneratedValue(long minimum)
      This is used to fudge generation of key values for in databases that do not properly suport them. It is rough and fails if there are multiple JVMs, or the user switches schemas in Oracle etc.
    • readResolve

      protected Object readResolve() throws ObjectStreamException
      Reflected into during de-serialization to return any pre-existing SFieldMeta object
      Throws:
      ObjectStreamException
    • getFieldName

      public String getFieldName()
    • equals

      public boolean equals(Object that)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getRecordMeta

      public SRecordMeta getRecordMeta()
      Returns:
      the sRecordMeta
    • isMandatory

      public boolean isMandatory()
    • addValidator

      public <T extends SFieldMeta> T addValidator(SValidatorI val)
      Add a custom FieldValidator. Validator corresponding to data constaints (type, length, not null, ...) are added automatically.
    • addFlag

      public <T extends SFieldMeta> T addFlag(SFieldFlags flag)
      Add a FieldFlag as an afterthought. Allows conditional flags in a constructor.
    • getValidators

      public List<SValidatorI> getValidators()
      Get the list of validators that are bound to this field. Can be useful for UI to know allowed values, etc.
    • doValidate

      protected void doValidate(SRecordInstance instance)
      Called when individual field changed, or when record updated. (Default behaviour is to call all registered validators.)
      See Also:
    • putUserProperty

      public <T extends SFieldMeta> T putUserProperty(Object key, Object value)
    • getUserProperty

      public <T> T getUserProperty(Object key)
    • getUserProperties

      public Map getUserProperties()