01: package com.completex.objective.components.persistency.type;
02:
03: import com.completex.objective.components.persistency.core.DatabasePolicy;
04: import com.completex.objective.components.persistency.PersistentObject;
05:
06: import java.sql.SQLException;
07: import java.sql.PreparedStatement;
08: import java.io.InputStream;
09: import java.io.ByteArrayOutputStream;
10: import java.io.ByteArrayInputStream;
11:
12: /**
13: * @author Gennady Krizhevsky
14: */
15: public class ByteArrayTypeHandler extends BinaryTypeHandler {
16:
17: public Object transformRead(Object data) throws SQLException {
18: if (data instanceof byte[]) {
19: return data;
20: }
21:
22: InputStream in = (InputStream) super .transformRead(data);
23: if (in == null) {
24: return null;
25: }
26: ByteArrayOutputStream out = new ByteArrayOutputStream();
27: BlobImpl.writeBlob(in, out);
28: return out.toByteArray();
29: }
30:
31: public void handleBind(PreparedStatement statement, int index,
32: Object value, DatabasePolicy databasePolicy,
33: LobPostProcessings postProcessings,
34: PersistentObject persistentObject, int fieldIndex)
35: throws SQLException {
36: byte[] bytes = (byte[]) value;
37: ByteArrayInputStream in = new ByteArrayInputStream(bytes);
38: super.handleBind(statement, index, in, databasePolicy,
39: postProcessings, persistentObject, fieldIndex);
40: }
41:
42: }
|