try
{
stmt2.setString(1, configuredObject.getType());
if (configuredObject.getAttributes() != null)
{
byte[] attributesAsBytes = (new ObjectMapper()).writeValueAsBytes(
configuredObject.getAttributes());
ByteArrayInputStream bis = new ByteArrayInputStream(attributesAsBytes);
stmt2.setBinaryStream(2, bis, attributesAsBytes.length);
}
else
{
stmt2.setNull(2, Types.BLOB);
}
stmt2.setString(3, configuredObject.getId().toString());
stmt2.execute();
}
finally
{
stmt2.close();
}
}
else if(createIfNecessary)
{
PreparedStatement insertStmt = conn.prepareStatement(INSERT_INTO_CONFIGURED_OBJECTS);
try
{
insertStmt.setString(1, configuredObject.getId().toString());
insertStmt.setString(2, configuredObject.getType());
if(configuredObject.getAttributes() == null)
{
insertStmt.setNull(3, Types.BLOB);
}
else
{
final Map<String, Object> attributes = configuredObject.getAttributes();
byte[] attributesAsBytes = new ObjectMapper().writeValueAsBytes(attributes);
ByteArrayInputStream bis = new ByteArrayInputStream(attributesAsBytes);
insertStmt.setBinaryStream(3, bis, attributesAsBytes.length);
}
insertStmt.execute();
}