Here is the sample UserType clas i am using to get BFILE from database. But when i am trying to get BILE from database... i am not getting data, Any one knows how to get BFILE data from database.
package com.ameripath.shared.apptier.hibernate;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import oracle.jdbc.OracleConnection;
import oracle.jdbc.driver.OracleTypes;
import oracle.sql.BFILE;
import oracle.sql.BLOB;
import org.hibernate.HibernateException;
import org.hibernate.usertype.UserType;
public final class BFileType implements UserType {
private static final int BFILE_TYPE = OracleTypes.BFILE;
private static final Class RETURNED_CLASS = BFILE.class;
public int[] sqlTypes() {
return new int[]{BFILE_TYPE};
}
public Class returnedClass() {
return byte[].class;
}
public boolean equals(Object x, Object y) throws HibernateException {
return (x == y)
|| (x != null && y != null && java.util.Arrays.equals(
(byte[]) x, (byte[]) y));
}
public boolean isMutable() {
return false;
}
public int hashCode(Object arg0) throws HibernateException {
// TODO Auto-generated method stub
return 0;
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner)throws HibernateException, SQLException {
BFILE file = (BFILE) rs.getObject(names[0]);
if (file != null && file.getBytes()!= null){
return file.getBytes();
}else{
return null;
}
}
public void nullSafeSet(PreparedStatement st, Object value, int index)throws HibernateException, SQLException {
if (value == null)
st.setObject(index, null);
else{
BFILE file = new BFILE((OracleConnection)((org.jboss.resource.adapter.jdbc.WrappedConnection) st.getConnection()).getUnderlyingConnection(),(byte[]) value);
st.setBytes(index,file.getBytes());
}
}
public Object deepCopy(Object value)
{
if (value == null) return null;
byte[] bytes = (byte[]) value;
byte[] result = new byte[bytes.length];
System.arraycopy(bytes, 0, result, 0, bytes.length);
return result;
}
public Serializable disassemble(Object arg0) throws HibernateException {
// TODO Auto-generated method stub
return null;
}
public Object assemble(Serializable arg0, Object arg1) throws HibernateException {
// TODO Auto-generated method stub
return null;
}
public Object replace(Object arg0, Object arg1, Object arg2) throws HibernateException {
// TODO Auto-generated method stub
return null;
}
}
|