use of com.revolsys.jdbc.LocalBlob in project com.revolsys.open by revolsys.
the class JdbcBlobFieldDefinition method setPreparedStatementValue.
@Override
public int setPreparedStatementValue(final PreparedStatement statement, final int parameterIndex, final Object value) throws SQLException {
if (value == null) {
final int sqlType = getSqlType();
statement.setNull(parameterIndex, sqlType);
} else {
Blob blob;
if (value instanceof Blob) {
blob = (Blob) value;
} else if (value instanceof byte[]) {
final byte[] bytes = (byte[]) value;
blob = new LocalBlob(bytes);
} else if (value instanceof CharSequence) {
final String string = ((CharSequence) value).toString();
final byte[] bytes = string.getBytes(StandardCharsets.UTF_8);
blob = new LocalBlob(bytes);
} else {
try {
final Resource resource = Resource.getResource(value);
blob = new LocalBlob(resource);
} catch (final IllegalArgumentException e) {
throw new IllegalArgumentException(value.getClass() + " not valid for a blob column");
}
}
statement.setBlob(parameterIndex, blob);
}
return parameterIndex + 1;
}