package com.completex.objective.components.persistency.type;
import com.completex.objective.components.persistency.core.DatabasePolicy;
import com.completex.objective.components.persistency.PersistentObject;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.io.InputStream;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
/**
* @author Gennady Krizhevsky
*/
public class ByteArrayTypeHandler extends BinaryTypeHandler {
public Object transformRead(Object data) throws SQLException {
if (data instanceof byte[]) {
return data;
}
InputStream in = (InputStream) super.transformRead(data);
if (in == null) {
return null;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
BlobImpl.writeBlob(in, out);
return out.toByteArray();
}
public void handleBind(PreparedStatement statement, int index,
Object value,
DatabasePolicy databasePolicy,
LobPostProcessings postProcessings,
PersistentObject persistentObject,
int fieldIndex) throws SQLException {
byte [] bytes = (byte[]) value;
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
super.handleBind(statement, index, in, databasePolicy, postProcessings, persistentObject, fieldIndex);
}
}
|