Previous Table of Contents   Next  


19.6 Type Mapping Examples

   To promote understanding of the appropriate use of the CWM Foundation’s TypeMapping package for recording mappings between data types defined by different software systems, this section presents example instances illustrating how the CORBA IDL and Java primitive data types can be mapped to each other and how the Java and SQL-99 primitive data types can be mapped to each other. These mappings are obtained from relevant published standards documents: [IDL-Java], [Java-IDL] and [JDBC]. Although the CWM Relational package supports the SQL-99 standard, the type mappings between Java and SQL are derived from the JDBC specification which uses X/Open CLI SQL as its SQL language standard rather than SQL-99. Consequently, the Java/SQL mappings are not exactly equivalent to those that would be needed to map to SQL-99 but should serve to illustrate the mapping techniques required. SQL typeNumbers from the java.sql.Types file can be used to uniquely identify SQL types.

   The following tables present sample type mapping instances for CORBA IDL/Java and Java/SQL-99 mappings. Because TypeMapping instances are unidirectional, two instances -- one for each direction -- are required to indicate that a pair of data types can be mutually interchanged. To keep the size of the tables manageable, only type mapping instances with isBestMatch = True are shown; other, non-preferred mappings can be added as necessary to support particular implementation needs. Also, values for the isLossy attribute of TypeMapping instances are omitted because their precise values may be implementation dependent.

   Table 19-1 TypeMapping instances mapping CORBA IDL data types to Java data types

SourceType (IDL)

TargetType (Java)

boolean boolean
char char
wchar char
octet byte
string java.lang.String
wstring java.lang.String
short short
unsigned short unsigned short
long int
unsigned long int
long long long
unsigned long long long
float float
double double
fixed java.math.BigDecimal

   Table 19-2 TypeMapping instances mapping Java data types to CORBA IDL data types Table 19-3 TypeMapping instances mapping X/Open CLI SQL data types to Java data type

SourceType (Java)

TargetType (IDL)

void void
boolean boolean
char wchar
byte octet
short short
int long
long long long
float float
double double

SourceType (X/Open CLI SQL) TargetType (Java)
CHAR String
VARCHAR String
LONGVARCHAR String
NUMERIC java.math.BigDecimal
DECIMAL java.math.BigDecimal
BIT boolean
TINYINT byte
SMALLINT short
INTEGER int
BIGINT long
REAL float
FLOAT double
DOUBLE double
BINARY byte[]
VARBINARY byte[]
LONGVARBINARY byte[]
DATE java.sql.Date
TIME java.sql.Time
TIMESTAMP java.sql.Timestamp

   Table 19-4 TypeMapping instances mapping Java data types to X/Open CLI SQL data types Table 19-4 TypeMapping instances mapping Java data types to X/Open CLI SQL data types

SourceType (Java)

TargetType (X/Open CLI SQL)

String VARCHAR (or LONGVARCHAR)
java.math.BigDecimal NUMERIC
Boolean BIT
Integer INTEGER
Long BIGINT
Float REAL
Double DOUBLE

SourceType (Java)

TargetType (X/Open CLI SQL)

byte[] VARBINARY (or LONGVARBINARY)
java.sql.Date DATE
java.sql.Time TIME
java.sql.Timestamp TIMESTAMP