Hi everyone,
well I finally managed to write a BFile UserType that correctly maps an Oracle BFile. Entries are created using the UserType interface's method NullSafeSet and fetched by NullSafeGet.
BUT
My solution is somehow "dirty". I'll post the code from my NullSafeSet:
public void nullSafeSet(PreparedStatement st, Object value, int index)
throws HibernateException, SQLException {
if (value == null) {
st.setObject(index, null);
} else {
OracleConnection oc = (OracleConnection) st.getConnection();
OraclePreparedStatement opst = (OraclePreparedStatement) st;
String directory = readProps();
String filename = ((MyHolder) value).getName();
OracleCallableStatement ocs = (OracleCallableStatement) oc
.prepareCall("{? = call BFILENAME('" + directory + "', '"
+ filename + "')}");
ocs.registerOutParameter(1, OracleTypes.BFILE);
ocs.execute();
BFILE bfile = ocs.getBFILE(1);
opst.setBFILE(index, bfile);
}
}
As you can see, I used a OracleCallableStatement (ocs) to place an SQL Command (
BFILENAME ) to create the LOB on the Database. The BFILENAME argument directory is read via a properties file, the argument filename is saved in a class where Hibernate maps the UserType to. Afterwards I get my BFILE from the ocs in order to add it to my OraclePreparedStatement.
That can't be the optimal solution, can it?
The reason why I'm doing this is, because it seems that the BFILE implementation misses a method to set the directory and filename to. As for the C++ implementation [Oracle C++ Call Interface Programmer's Guide|http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14294/reference006.htm] there is a method which sets a directory and a filename to the BFILE object.
In Java I tried
BFILE bfile = new BFILE(oc);
bfile.setLocator((directory+"/"+filename).getBytes());
without success. The locator was inserted into the table, but was invalid and couldn't be retrieved.
That's why I used an OracleCallableStatement, and that's the reason why I am posting here. Maybe I'm missing something, but it seems to me that few people ever accomplished to do Hibernate O/R mapping with BFILEs via a UserType. Maybe you can enlighten me with some answers.
Thank you very much,
regards
Charle