((PreparedStatement)ps).setNull(param, getTypeInfo().getDataType());
}
}
catch (SQLException sqle)
{
throw new NucleusDataStoreException(LOCALISER_RDBMS.msg("055001","Object", "" + param, column, sqle.getMessage()),sqle);
}
}
else
{
try
{
// Use Java serialisation, else byte-streaming, and if not determined then Java serialisation
if (getJavaTypeMapping().isSerialised())
{
// Serialised field so just perform basic Java serialisation for retrieval
if (!(value instanceof Serializable))
{
throw new NucleusDataStoreException(LOCALISER_RDBMS.msg("055005", value.getClass().getName()));
}
BlobImpl b = new BlobImpl(value);
((PreparedStatement) ps).setBytes(param, b.getBytes(0, (int) b.length()));
}
else if (value instanceof boolean[])
{
byte[] data = TypeConversionHelper.getByteArrayFromBooleanArray(value);
((PreparedStatement) ps).setBytes(param, data);
}
else if (value instanceof char[])
{
byte[] data = TypeConversionHelper.getByteArrayFromCharArray(value);
((PreparedStatement) ps).setBytes(param, data);
}
else if (value instanceof double[])
{
byte[] data = TypeConversionHelper.getByteArrayFromDoubleArray(value);
((PreparedStatement) ps).setBytes(param, data);
}
else if (value instanceof float[])
{
byte[] data = TypeConversionHelper.getByteArrayFromFloatArray(value);
((PreparedStatement) ps).setBytes(param, data);
}
else if (value instanceof int[])
{
byte[] data = TypeConversionHelper.getByteArrayFromIntArray(value);
((PreparedStatement) ps).setBytes(param, data);
}
else if (value instanceof long[])
{
byte[] data = TypeConversionHelper.getByteArrayFromLongArray(value);
((PreparedStatement) ps).setBytes(param, data);
}
else if (value instanceof short[])
{
byte[] data = TypeConversionHelper.getByteArrayFromShortArray(value);
((PreparedStatement) ps).setBytes(param, data);
}
else if (value instanceof Boolean[])
{
byte[] data = TypeConversionHelper.getByteArrayFromBooleanObjectArray(value);
((PreparedStatement) ps).setBytes(param, data);
}
else if (value instanceof Byte[])
{
byte[] data = TypeConversionHelper.getByteArrayFromByteObjectArray(value);
((PreparedStatement) ps).setBytes(param, data);
}
else if (value instanceof Character[])
{
byte[] data = TypeConversionHelper.getByteArrayFromCharObjectArray(value);
((PreparedStatement) ps).setBytes(param, data);
}
else if (value instanceof Double[])
{
byte[] data = TypeConversionHelper.getByteArrayFromDoubleObjectArray(value);
((PreparedStatement) ps).setBytes(param, data);
}
else if (value instanceof Float[])
{
byte[] data = TypeConversionHelper.getByteArrayFromFloatObjectArray(value);
((PreparedStatement) ps).setBytes(param, data);
}
else if (value instanceof Integer[])
{
byte[] data = TypeConversionHelper.getByteArrayFromIntObjectArray(value);
((PreparedStatement) ps).setBytes(param, data);
}
else if (value instanceof Long[])
{
byte[] data = TypeConversionHelper.getByteArrayFromLongObjectArray(value);
((PreparedStatement) ps).setBytes(param, data);
}
else if (value instanceof Short[])
{
byte[] data = TypeConversionHelper.getByteArrayFromShortObjectArray(value);
((PreparedStatement) ps).setBytes(param, data);
}
else if (value instanceof BigDecimal[])
{
byte[] data = TypeConversionHelper.getByteArrayFromBigDecimalArray(value);
((PreparedStatement) ps).setBytes(param, data);
}
else if (value instanceof BigInteger[])
{
byte[] data = TypeConversionHelper.getByteArrayFromBigIntegerArray(value);
((PreparedStatement) ps).setBytes(param, data);
}
else if (value instanceof byte[])
{
((PreparedStatement) ps).setBytes(param, (byte[]) value);
}
else if (value instanceof java.util.BitSet)
{
byte[] data = TypeConversionHelper.getByteArrayFromBooleanArray(TypeConversionHelper.getBooleanArrayFromBitSet((java.util.BitSet) value));
((PreparedStatement) ps).setBytes(param, data);
}
else if (value instanceof java.awt.image.BufferedImage)
{
ByteArrayOutputStream baos = new ByteArrayOutputStream(8192);
ImageIO.write((BufferedImage) value, "jpg", baos);
byte[] buffer = baos.toByteArray();
baos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
((PreparedStatement) ps).setBytes(param, buffer);
bais.close();
}
else
{
// Fall back to just perform Java serialisation for storage
if (!(value instanceof Serializable))
{
throw new NucleusDataStoreException(LOCALISER_RDBMS.msg("055005", value.getClass().getName()));
}
BlobImpl b = new BlobImpl(value);
((PreparedStatement) ps).setBytes(param, b.getBytes(0, (int) b.length()));
}
}
catch (Exception e)
{
throw new NucleusDataStoreException(LOCALISER_RDBMS.msg("055001","Object","" + value, column, e.getMessage()),e);
}
}
}