The following table illustrates the mapping of Java object attribute types to SQL database field types as they are included in PriDE by default. The row 'Java function type' determines the function type being used for the specified attribute type to access results from a ResultSet or to pass inputs to a PreparedStatement. The 'SQL type' specifies the actual SQL row types, the attributes can usually be mapped to. Not all SQL databases support all the mentioned type identifiers and it may also depend on the JDBC driver's capabilities which mappings are supported. Primitive attribute types should of course only be used, if the corresponding row must not be NULL. Otherwise an exception will be thrown at runtime when attempting to process NULL values.
|Java attribute type||Java function type||SQL type|
|java.util.Date||java.sql.Timestamp||DATETIME, TIMESTAMP, TIME|
|java.sql.Timestamp||java.sql.Timestamp||DATETIME, TIMESTAMP, TIME|
|boolean||Boolean||BOOLEAN, INTEGER, SMALLINT, TINYINT, CHAR|
|Boolean||Boolean||BOOLEAN, INTEGER, SMALLINT, TINYINT, CHAR|
|long||Long||INTEGER, DECIMAL, NUMBER, BIGINT|
|Long||Long||INTEGER, DECIMAL, NUMBER, BIGINT|
|short||Short||INTEGER, SMALLINT, TINYINT, DECIMAL|
|Short||Short||INTEGER, SMALLINT, TINYINT, DECIMAL|
|byte||byte||BLOB, LONGVARBINARY, VARBINARY|
|Blob||Blob||BLOB, LONGVARBINARY, VARBINARY|
||HSTORE, Postgres only
||ARRAY, Postgres only
As it can be seen from the list above, java.util.Date
like a time stamp, assuming that the time information is relevant.
attributes play a special role among the ordinary SQL types as the
and formatting rules vary significantly between different SQL
PriDE's base class AbstractResourceAccessor
provides different formatting already based on the properties pride.dbtype,
pride.format.date and pride.format.time.
The database server's system time can be referred to by passing the return value of Database.getSystime() to the attribute of interest. The function does not actually return the current database system time but a java.util.Date being used as an indicator which is later replaced by the database' specific constants like CURRENT_TIMESTAMP or SYSDATE.
BLOBS and CLOBS can currently only be written to the database using prepared statements and are known to be incompatibly to use for different DB vendors (especially Oracle).
Enum types are generically mapped to strings, using Enum.name() rather than the toString() which ensures safe forth and back mapping. Arrays and Key-Value-Maps can only be mapped for Postgres as this database provides corresponding dynamic column types.
If there must a different attribute type be mapped to the database, it is recommended simply to provide additional get and set methods for this attribute, performing a conversion to one of the attribute types listed above and being referred to in the object type's RecordDescriptor. Adding access methods only for database interaction is of course a slight loss of transparence, but it is just simple. As an alternative the mappings can be extended in general by the following steps: