We are trying to implement a solution that requires us to,
Poll a control table in frequent intervals to query for unprocessed transactions
Once we pull the transaction identifiers from Step 1 we have to query for details. This step is existing functionality, only that we do a full scan by joining the with the control table in step one.
The existing solution is starting to slow down the processing when there is a volume. So we decided to pull transactions that are not processed, from the status table and do a PK look up for querying the details.
I understand that this is not an ideal solution like Adapters,CDC or having the full details expressed in a view. We are restricted due to product contract that forbids us from creating any kind of objects on the source schema or anywhere in the source Oracle instance that leaves us polling the tables and this solution is required to be scallable and near real time(5 seconds delay).
DDL:
CREATE TABLE "CONTROL_TABLE"
(
"REF_NO" VARCHAR2(16 CHAR),
"BRANCH" VARCHAR2(3 CHAR),
"INIT_DATE" DATE,
"STATUS" VARCHAR2(1 CHAR),
CONSTRAINT "CONST_CONTROL_TABLE" PRIMARY KEY ("REF_NO")
)
Following is what I have tried as a POC, executing the below block,
1. Created a block to run a SELECT for UPDATE as follows. In the below block I am selecting for update with "SKIP LOCKED" and update the records in the cursor scope.
DECLARE
CURSOR tCURSOR IS
SELECT REF_NO FROM CONTROL_TABLE
WHERE STATUS = 'U' FOR UPDATE OF STATUS SKIP LOCKED;
BEGIN
FOR tCURSORREC IN tCURSOR LOOP
UPDATE CONTROL_TABLE SET STATUS='W' WHERE STATUS='U';
END LOOP;
COMMIT;
END;
The above block works just fine and I have tested by randomly inserting new records and updating status from different client sessions. My issue is I would like to get the cursor returned to the Java client for downstream processing. Referred to an earlier post where just a SELECT query returns a cursor bind var to Java. Any helpful pointer is greatly appreciated. Execute anonymous pl/sql block and get resultset in java
Java snippet that runs the block,
public static void main(String args[]) throws Exception
{
final Connection c = DriverManager.getConnection("jdbc:oracle:thin:<<service_name>>:8888:<<schema>>", "user", "passwd");
String plsql = "declare\r\n" +
" cursor tCursor is\r\n" +
" select ref_no from CONTROL_TABLE \r\n" +
" where status = 'U' for update of REF_NO,STATUS skip locked;\r\n" +
"begin\r\n" +
" for tCursorRec in tCursor loop\r\n" +
" update CONTROL_TABLE set status='W' where status ='U'; \r\n" +
" end loop;\r\n" +
" commit; \r\n" +
"? := tCursor" +
"end;";
CallableStatement cs = c.prepareCall(plsql);
cs.registerOutParameter(1, OracleTypes.CURSOR);
cs.execute();
ResultSet cursorResultSet = (ResultSet) cs.getObject(1);
while (cursorResultSet.next ())
{
System.out.println (cursorResultSet.getString(1));
}
cs.close();
c.close();
Exception:Exception in thread "main" java.sql.SQLException: ORA-06550:
line 10, column 8:
PLS-00382: expression is of wrong type
ORA-06550: line 10, column 1: