Castor Doclet - Types
 
 Overview
 

Type conversions are handled directly by Castor Doclet, except for Strings for which you must specify the column length.

However, you may have some special needs like converting a date or a boolean to a string format. @sql-type and @sql-size doclet tags can be used to handle such cases. You can even use the parameterized type converters proposed by Castor.

 Strings
 

For String bean properties, Castor Doclet can determine the correct type, but it has no way to know the database column size.

The sql-size tag is used to specify the size limit in the Database :

 
/**
 * @sql-size 50
 */
private String stringValue;

This will generate the following castor mapping (not that the size is not used) :

 
<field name="stringValue" type="string">
  <sql name="STRINGVALUE" />
  <bind-xml name="stringValue" />
</field>

... and the column definition (depending on the database used) :

 
STRINGVALUE VARCHAR(50) ,
 Dates
 

The java Date type is in fact a timestamp, it contains date and time information. if nothing is specified, Castor Doclet will map a Date to a timestamp :

 
<field name="dateValue" type="date">
  <sql name="DATEVALUE" type="timestamp" />
  <bind-xml name="dateValue" />
</field>

... and generate the corresponding DDL :

 
DATEVALUE TIMESTAMP ,

To keep just the date without time information, specify a date sql-type :

 
    /**
     * @sql-type date
     */
    private Date dateValue;

Obviouly, an sql-type of time will store only time.

If the date must be converted to a string in the database, change the sql-type. As the column type is now a string, the sql-size is also needed :

 
    /**
     * @sql-type char[dd/MM/yyyy]
     * @sql-size 10
     */
    private Date dateValue;

This will generate :

 
     <field name="dateValue" type="date">
      <sql type="char[dd/MM/yyyy]" name="DATEVALUE" />
      <bind-xml name="dateValue" />
    </field>

and

 
DATEVALUE VARCHAR(10) ,
 Numeric types
 

Numeric types have default conversion type and size in database specific files inside the Castor Doclet.

An Integer without any tags will be mapped to :
 
    <field name="integerValue" type="integer">
      <sql name="INTEGERVALUE" />
      <bind-xml name="integerValue" />
    </field>

and (with Hypersonic SQL)

 
INTEGERVALUE INT ,

A different size can be specified by using the @sql-size tag.