String sTypeName = rs.getString("TYPE_NAME");
int nType = rs.getInt("DATA_TYPE");
int nPrecision = rs.getInt("COLUMN_SIZE");
int nScale = rs.getInt("DECIMAL_DIGITS");
byte nAllocation = Column.FIXED;
Primitive type = null;
switch (nType)
{
case Types.BIGINT:
type = Primitive.LONG;
nPrecision = 0;
nScale = 0;
break;
case Types.BINARY:
type = Primitive.BINARY;
nScale = 0;
break;
case Types.BIT:
case Types.BOOLEAN:
type = Primitive.BOOLEAN;
nPrecision = 0;
nScale = 0;
break;
case Types.BLOB:
case Types.LONGVARBINARY:
type = Primitive.BINARY;
if (nPrecision <= 0x4000)
{
nPrecision = Integer.MAX_VALUE;
}
nScale = 0;
nAllocation = (nType == Types.BLOB) ? Column.LOCATOR : Column.VARYING;
break;
case Types.CHAR:
sTypeName = sTypeName.toLowerCase(Locale.ENGLISH);
if (sTypeName.equals("uniqueidentifier"))
{
type = Primitive.BINARY;
nPrecision = 16;
nScale = 0;
}
else
{
type = Primitive.STRING;
nScale = 0;
}
break;
case Types.CLOB:
case Types.LONGVARCHAR:
type = Primitive.STRING;
if (nPrecision <= 0x4000)
{
nPrecision = Integer.MAX_VALUE;
}
nScale = 0;
nAllocation = (nType == Types.CLOB) ? Column.LOCATOR : Column.VARYING;
break;
case Types.DATE:
case Types.TIME:
case Types.TIMESTAMP:
type = Primitive.TIMESTAMP;
nPrecision = 0;
nScale = 0;
break;
case Types.DECIMAL:
case Types.NUMERIC:
type = Primitive.DECIMAL;
if (nScale == 0 && nPrecision <= 20)
{
if (nPrecision <= 10)
{
type = Primitive.INTEGER;
if (nPrecision <= 3)
{
nPrecision = 1;
}
else if (nPrecision <= 5)
{
nPrecision = 2;
}
else
{
nPrecision = 0;
}
}
else
{
type = Primitive.LONG;
nPrecision = 0;
}
}
break;
case Types.DOUBLE:
case Types.FLOAT:
type = Primitive.DOUBLE;
nPrecision = 0;
nScale = 0;
break;
case Types.INTEGER:
type = Primitive.INTEGER;
nPrecision = 0;
nScale = 0;
break;
case Types.SMALLINT:
type = Primitive.INTEGER;
nPrecision = 2;
nScale = 0;
break;
case Types.TINYINT:
type = Primitive.INTEGER;
nPrecision = 1;
nScale = 0;
break;
case Types.REAL:
type = Primitive.FLOAT;
nPrecision = 0;
nScale = 0;
break;
case Types.VARBINARY:
type = Primitive.BINARY;
nScale = 0;
nAllocation = Column.VARYING;
break;
case Types.VARCHAR:
type = Primitive.STRING;
nScale = 0;
nAllocation = Column.VARYING;
break;
default:
sTypeName = sTypeName.toLowerCase(Locale.ENGLISH);
if (sTypeName.equals("nchar"))
{
type = Primitive.STRING;
nPrecision >>= 1;
nScale = 0;
}
else if (sTypeName.equals("nvarchar2") || sTypeName.equals("nvarchar"))
{
type = Primitive.STRING;
nPrecision >>= 1;
nScale = 0;
nAllocation = Column.VARYING;
}
else if (sTypeName.equals("binary_double"))
{
type = Primitive.DOUBLE;
nPrecision = 0;
nScale = 0;
}
else if (sTypeName.equals("binary_float"))
{
type = Primitive.FLOAT;
nPrecision = 0;
nScale = 0;
}
else if (sTypeName.startsWith("timestamp"))
{
type = Primitive.TIMESTAMP;
nPrecision = 0;
nScale = 0;
}
else if (sTypeName.equals("nclob") || sTypeName.equals("clob"))
{
type = Primitive.STRING;
if (nPrecision <= 0x4000)
{
nPrecision = Integer.MAX_VALUE;
}
nScale = 0;
nAllocation = Column.LOCATOR;
}
else if (sTypeName.equals("blob"))
{
type = Primitive.BINARY;
if (nPrecision <= 0x4000)
{
nPrecision = Integer.MAX_VALUE;
}
nScale = 0;
nAllocation = Column.LOCATOR;
}
break;
}
if (nPrecision < 0)
{
nPrecision = 0;
}
if (s_logger.isDebugEnabled())
{
s_logger.debug("Read column \"" + table.getName() + "." + column.getName() + "\" " +
sTypeName + "(" + rs.getInt("COLUMN_SIZE") + "," + rs.getInt("DECIMAL_DIGITS") +
"), SQLType=" + nType + " -> " + ((type == null) ? "ignored: unsupported type" : type.getName() +
"(" + nPrecision + "," + nScale + "), allocation=" + nAllocation));
}
if (type != null)
{