Types

The Type Object holds properties about a particular type, in the database. Each column can access it's own
underlying Type object.

Basic Types

JGenerator has a complete set of basic SQL Type mappings. The mappings between SQL and Java are enumerated below

SQL Type Type Name Additional Java Type Java Object
type.getSQLType() type.getTypeName() type.getXXXX() type.getJavaClass() type.getJavaObject()
java.sql.Types.BIGINT BIGINT   Long.TYPE Long.class
java.sql.Types.BINARY BINARY length byte[].class byte[].class
java.sql.Types.BIT BIT   Boolean.TYPE Boolean.class
java.sql.Types.CHAR CHAR length String.class String.class
Type.NCHAR NCHAR length String.class String.class
java.sql.Types.DATE DATE   java.sql.Date.class java.sql.Date.class
java.sql.Types.DECIMAL DECIMAL precision,scale java.math.BigDecimal.class java.math.BigDecimal.class
java.sql.Types.DOUBLE DOUBLE   Double.TYPE Double.class
java.sql.Types.FLOAT FLOAT   Float.TYPE Float.class
java.sql.Types.INTEGER INTEGER   Integer.TYPE Integer.class
java.sql.Types.LONGVARBINARY LONGVARBINARY length byte[].class byte[].class
java.sql.Types.LONGVARCHAR LONGVARCHAR length String.class String.class
Type.NTEXT NTEXT   String.class String.class
java.sql.Types.NULL NULL   Void.class Void.class
java.sql.Types.NUMERIC NUMERIC   Double.TYPE Double.class
java.sql.Types.OTHER OTHER   null null
java.sql.Types.REAL REAL   Float.TYPE Float.class
java.sql.Types.SMALLINT SMALLINT   Short.TYPE Short.class
java.sql.Types.TIME TIME   java.sql.Time.class java.sql.Time.class
java.sql.Types.TIMESTAMP TIMESTAMP   java.sql.Timestamp.class java.sql.Timestamp.class
java.sql.Types.TINYINT TINYINT   Byte.TYPE Byte.class
java.sql.Types.VARBINARY VARBINARY   byte[].class byte[].class
java.sql.Types.VARCHAR VARCHAR length String.class String.class
Type.NVARCHAR NVARCHAR length String.class String.class

N.B. The sql.types have been added to for NVARCHAR, which are used to represent unicode characters.

Each type is treated as a seperate type in the dictionary. The type name is used to specify generic type names
when the types are referred to.

Java Types

The following Java type information is held on the dictionary for each type to help generate the code.

SQL Type

Java Object name

Primitive
Method Name

Java Class
Name

Cast string Default value
type.getSQLType() getJdbcType() getToPrimitiveMethod() getJavaPrimitiveType() getCastString() getDefaultValue()
java.sql.Types.BIGINT Long longValue long (long) 0L
java.sql.Types.BINARY BinaryStream   byte[]   null
java.sql.Types.BIT Boolean booleanValue boolean   false
java.sql.Types.CHAR String toString String   null
Type.NCHAR String toString String   null
java.sql.Types.DATE Date getTime long   null
java.sql.Types.DECIMAL BigDecimal doubleValue double   null
java.sql.Types.DOUBLE Double doubleValue double (double) 0.0
java.sql.Types.FLOAT Double doubleValue double (double) 0.0
java.sql.Types.INTEGER Int intValue int   0
java.sql.Types.LONGVARBINARY BinaryStream   byte[]   null
java.sql.Types.LONGVARCHAR AsciiStream toString String   null
Type.NTEXT AsciiStream toString String   null
java.sql.Types.NULL Null       null
java.sql.Types.NUMERIC Double doubleValue double (double) 0.0
java.sql.Types.OTHER Object       null
java.sql.Types.REAL Float floatValue float (float) 0.0f
java.sql.Types.SMALLINT Short shortValue short (short) (short)0
java.sql.Types.TIME Time getTime long   null
java.sql.Types.TIMESTAMP Timestamp getTime long   null
java.sql.Types.TINYINT Byte byteValue byte (byte) (byte)0
java.sql.Types.VARBINARY Bytes   byte[]   null
java.sql.Types.VARCHAR String toString String   null
Type.NVARCHAR String toString String   null

SQL Types

The following canonical database naming is written, using the vendor.getCanonicalName(type) method.

SQL Type MS/SQL Oracle Interbase
type.getSQLType() vendor.getCanonicalName() vendor.getCanonicalName() vendor.getCanonicalName()
java.sql.Types.BIGINT      
java.sql.Types.BINARY      
java.sql.Types.BIT     SMALLINT
java.sql.Types.CHAR      
Type.NCHAR      
java.sql.Types.DATE DATETIME DATE DATE
java.sql.Types.DECIMAL      
java.sql.Types.DOUBLE FLOAT DECIMAL DOUBLE PRECISION
java.sql.Types.FLOAT REAL FLOAT FLOAT
java.sql.Types.INTEGER INT INTEGER INTEGER
java.sql.Types.LONGVARBINARY IMAGE LONG BINARY BLOB SUB_TYPE 0
java.sql.Types.LONGVARCHAR TEXT LONG VARCHAR BLOB SUB_TYPE 1
Type.NTEXT NTEXT   BLOB SUB_TYPE 1
java.sql.Types.NULL      
java.sql.Types.NUMERIC      
java.sql.Types.OTHER      
java.sql.Types.REAL      
java.sql.Types.SMALLINT     DATE
java.sql.Types.TIME DATETIME DATE DATE
java.sql.Types.TIMESTAMP DATETIME DATE  
java.sql.Types.TINYINT      
java.sql.Types.VARBINARY      
java.sql.Types.VARCHAR   VARCHAR2  
Type.NVARCHAR   VARCHAR2  

User Types

User Types can be used to define types in the property files, such as integers. The user type is decoration which can be used to hang other properties, usch as validation rules.

The syntax for defining a UserType using the following syntax: -

<user Type Name>.userType=<Type Name>

For example: -

POSITIVE_INT.userType=INTEGER

This user type can then be set on the column as a type, for example: -

Person.readColumn.2=age POSITIVE_INT NOT NULL

The userType for a Column can be accessed as a property on the Column Bean.

 

Writing Example

Types can be used to write our information about the underlying property and column types.

Print the fully qualified name of the underlying java primitive type: -

writer.print( column.getType().getJavaClass().getName() );

Print the fully qualified name of the underlying java object type: -

writer.print( column.getType().getJavaObject().getName() );

Print the short name of the underlying java primitvetype: -

writer.print( column.getType().getJavaClassName() );

Print the short name of the underlying java object type: -

writer.print( column.getType().getJavaObjectName() );

Print the short name of the type for a Bean, this will print the Bean, Object, Enumerated Type or primitive type: -

writer.print( column.getLogicalTypeName() );

Print the short name of the type for the jdbc mapping, this will be an object or a primitive type: -

writer.print( column.getPhysicalTypeName() );

Print a sql vendors canonical name for a type: -

writer.print( column.getVendor().getCanonicalName( column.getType() ) );