Referring to the thread " JdbcDirectory does not work for Oracle?" in Compass Framework Users forum:
== QUOTE (with minor modification) ==
I've looked into the Oracle 9i and 10g JDBC manuals provided by Oracle. It seems that the problem with all Oracle versions before 10g requires the following steps for inserting into a BLOB:
1. use a non-autocommit connection
2. first execute an insert: "insert into index_xxx (name_, value_, ...) values (?, empty_blob(), ...)"
3. get the BLOB for update: "select value_ from index_xxx where name_ = ? for update"
4. cast the java.sql.ResultSet to oracle.jdbc.OracleResultSet and use OracleResultSet#getBLOB method to get the oracle.sql.BLOB
5. get oracle.sql.BLOB#getBinaryOutputStream to get the OutputStream that you can write the BLOB content to
If you just use setBinaryStream, you will hit the problem when the BLOB size reaches a certain threshold (which I believe is 4K). This limitation is somehow removed in Oracle 10g (but doing the same in Oracle 10g should still work). Unfortunately, upgrading the JDBC driver to 10g does not help, the database server needs to be 10g also.
For details, you can refer to Oracle JDBC Developer's Guide and Reference about "Creating and Populating a BLOB or CLOB Column" ( http://download-west.oracle.com/docs/cd/B10501_01/java.920/a96654/oralob.htm#1043351
- OTN login required).
I have modified the Compass code (based on 0.8.1) in:
org.apache.lucene.store.jdbc.index.RAMJdbcIndexOutput
org.apache.lucene.store.jdbc.index.FileJdbcIndexOutput
and it seems that the issue is gone. However, such update will make the code dependent on Oracle JDBC driver for building and running (unless I use reflection to prevent directly referring to the Oracle classes).
(Minor updates are also done to the following to make the code "look better":
org.apache.lucene.store.jdbc.lock.PhantomReadLock
org.apache.lucene.store.jdbc.lock.SelectForUpdateLock
org.apache.lucene.store.jdbc.support.JdbcTable)
== END QUOTE ==
1. It refers to oracle.jdbc.OracleResultSet and oracle.sql.BLOB directly (and thus make it dependent on the Oracle JDBC driver).
2. It checks whether the class is an instance of OracleDialect. Ideally, a method should be added to the abstract class org.apache.lucene.store.jdbc.dialect.Dialect to determine the BLOB insertion method.