timestampValueMethod = timestampClass.getMethod("timestampValue");
} catch (Exception e)
{
String errMsg = "Cannot convert " + databaseFieldValue.getClass()
+ " to long for field " + schemaFieldName + " Unable to get oracle datatypes " + e.getMessage();
throw new EventCreationException(errMsg);
}
if(databaseFieldValue instanceof Timestamp)
{
long time = ((Timestamp) databaseFieldValue).getTime();
record.put(schemaFieldName, time);
}
else if(databaseFieldValue instanceof Date)
{
long time = ((Date) databaseFieldValue).getTime();
record.put(schemaFieldName, time);
}
else if(timestampClass.isInstance(databaseFieldValue))
{
try
{
Object tsc = timestampClass.cast(databaseFieldValue);
Timestamp tsValue = (Timestamp) timestampValueMethod.invoke(tsc);
long time = tsValue.getTime();
record.put(schemaFieldName, time);
}
catch(Exception ex)
{
throw new EventCreationException("SQLException reading oracle.sql.TIMESTAMP value for field "
+ schemaFieldName, ex);
}
}
else if(dateClass.isInstance(databaseFieldValue))
{
try
{
Object dsc = dateClass.cast(databaseFieldValue);
Timestamp tsValue = (Timestamp) timestampValueMethod.invoke(dsc);
long time = tsValue.getTime();
record.put(schemaFieldName, time);
}
catch(Exception ex)
{
throw new EventCreationException("SQLException reading oracle.sql.TIMESTAMP value for field "
+ schemaFieldName, ex);
}
}
/**
* This needs to stay after Oracle.sql.Timestamp because the timestamp class extends/implements the Number,BigDecimal classes,
* so it will pass as a number in the instanceof check. To avoid this we stick to this order.
*/
else if(databaseFieldValue instanceof Number)
{
long lvalue = ((Number) databaseFieldValue).longValue();
record.put(schemaFieldName, lvalue);
}
else
{
throw new EventCreationException("Cannot convert " + databaseFieldValue.getClass()
+ " to long for field " + schemaFieldName);
}
break;
case STRING:
if(databaseFieldValue instanceof Clob)
{
String text = extractClobText((Clob)databaseFieldValue, schemaFieldName);
record.put(schemaFieldName, text);
}
else if (databaseFieldValue instanceof SQLXML)
{
SQLXML xmlInst = (SQLXML) databaseFieldValue;
try
{
record.put(schemaFieldName,xmlInst.getString());
}
catch (SQLException e)
{
throw new EventCreationException("Cannot convert " + databaseFieldValue.getClass() +
" to string field " + schemaFieldName + " cause: " + e);
}
}
else
{
String text = databaseFieldValue.toString();
record.put(schemaFieldName, text);
}
break;
case NULL:
record.put(schemaFieldName, null);
break;
default:
throw new EventCreationException("unknown simple type " + avroFieldType.toString() +
" for field " + schemaFieldName);
}
}