Package simpleorm.dataset
Class SFieldMeta
- java.lang.Object
-
- simpleorm.dataset.SFieldMeta
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
SFieldReference
,SFieldScalar
public abstract class SFieldMeta extends java.lang.Object implements java.io.Serializable
Each instance defines the meta data for a field in anSRecordMeta
. Subclasses are used for specific data types, withSFieldObject
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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description boolean
quoteName
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <T extends SFieldMeta>
TaddFlag(SFieldFlags flag)
Add a FieldFlag as an afterthought.<T extends SFieldMeta>
TaddValidator(SValidatorI val)
Add a custom FieldValidator.protected abstract java.lang.Object
convertToDataSetFieldType(java.lang.Object raw)
Converts the parameter from the raw type parameter to the correct internal Object type that is stored in the data set.protected void
doValidate(SRecordInstance instance)
Called when individual field changed, or when record updated.boolean
equals(java.lang.Object that)
java.lang.String
getFieldName()
protected java.util.EnumSet<SFieldFlags>
getFlags()
SRecordMeta
getRecordMeta()
java.util.Map
getUserProperties()
<T> T
getUserProperty(java.lang.Object key)
java.util.List<SValidatorI>
getValidators()
Get the list of validators that are bound to this field.int
hashCode()
boolean
isDescriptive()
protected boolean
isForeignKey()
boolean
isMandatory()
boolean
isUnqueried()
long
nextGeneratedValue(long minimum)
This is used to fudge generation of key values for in databases that do not properly suport them.<T extends SFieldMeta>
TputUserProperty(java.lang.Object key, java.lang.Object value)
abstract java.lang.Object
queryFieldValue(java.sql.ResultSet rs, int sqlIndex)
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.protected java.lang.Object
readResolve()
Reflected into during de-serialization to return any pre-existing SFieldMeta object<T extends SFieldMeta>
TsetQuoted(boolean quoted)
Causes the generated sql to quote ("") the column name.abstract java.lang.String
toLongerString()
Lists all the details of the field.java.lang.String
toString()
Lists the record and column name only.java.lang.Object
writeFieldValue(java.lang.Object value)
Converts a single value from internal representation to database representation.void
writeFieldValue(java.sql.PreparedStatement ps, int sqlIndex, java.lang.Object value)
Places a value in a prepared statement in the database representation used during SRecordInstance.flush.
-
-
-
Method Detail
-
getFlags
protected java.util.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 java.lang.Object queryFieldValue(java.sql.ResultSet rs, int sqlIndex) throws java.lang.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:
java.lang.Exception
-
convertToDataSetFieldType
protected abstract java.lang.Object convertToDataSetFieldType(java.lang.Object raw) throws java.lang.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 bySRecordInstance.setObject
etc., Not getObject.- Throws:
java.lang.Exception
-
writeFieldValue
public void writeFieldValue(java.sql.PreparedStatement ps, int sqlIndex, java.lang.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 java.lang.Object writeFieldValue(java.lang.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 java.lang.String toString()
Lists the record and column name only. Useful in traces.- Overrides:
toString
in classjava.lang.Object
-
toLongerString
public abstract java.lang.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 java.lang.Object readResolve() throws java.io.ObjectStreamException
Reflected into during de-serialization to return any pre-existing SFieldMeta object- Throws:
java.io.ObjectStreamException
-
getFieldName
public java.lang.String getFieldName()
-
equals
public boolean equals(java.lang.Object that)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.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 java.util.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.)
-
putUserProperty
public <T extends SFieldMeta> T putUserProperty(java.lang.Object key, java.lang.Object value)
-
getUserProperty
public <T> T getUserProperty(java.lang.Object key)
-
getUserProperties
public java.util.Map getUserProperties()
-
-