package no.thc.cayenne.workbench; import java.sql.Blob; import java.sql.CallableStatement; import java.sql.PreparedStatement; import java.sql.ResultSet; import org.apache.cayenne.access.types.AbstractType; public class BlobFaultType extends AbstractType { public String getClassName() { return Blob.class.getName(); } public Object materializeObject(CallableStatement rs, int index, int type) throws Exception { return new BlobFault(); } public Object materializeObject(ResultSet rs, int index, int type) throws Exception { // TODO: make this blob usable by issuing the query with // autoCommit=true. The blob will be refetched by the BlobFault Blob blob = rs.getBlob(index); return new BlobFault(blob); } public void setJdbcObject(PreparedStatement st, Object val, int pos, int type, int precision) throws Exception { if (val instanceof BlobFault) { BlobFault b = (BlobFault) val; st.setBlob(pos, b.getUnderlyingBlob()); b.clear(); } else if (val instanceof Blob) { st.setBlob(pos, (Blob) val); } else { st.setObject(pos, val); } } }