1 24 package org.ofbiz.entity.jdbc; 25 26 import java.lang.reflect.Method ; 27 import java.sql.ResultSet ; 28 import java.sql.SQLException ; 29 import java.sql.Statement ; 30 31 36 public class CursorResultSet extends AbstractCursorHandler { 37 38 protected ResultSet rs; 39 protected Statement stmt; 40 protected String query; 41 42 protected CursorResultSet(Statement stmt, String cursorName, int fetchSize) throws SQLException { 43 super(cursorName, fetchSize); 44 this.stmt = stmt; 45 query = "FETCH FORWARD " + fetchSize + " IN " + cursorName; 46 System.err.println("executing page fetch(1)"); 47 rs = stmt.executeQuery(query); 48 } 49 50 public Object invoke(Object proxy, Method method, Object [] args) throws Throwable { 51 if ("close".equals(method.getName())) { 52 close(); 53 return null; 54 } else if ("next".equals(method.getName())) { 55 return next() ? Boolean.TRUE : Boolean.FALSE; 56 } 57 return super.invoke(rs, proxy, method, args); 58 } 59 60 protected boolean next() throws SQLException { 61 if (rs.next()) return true; 62 System.err.println("executing page fetch(2)"); 63 rs = stmt.executeQuery(query); 64 return rs.next(); 65 } 66 67 protected void close() throws SQLException { 68 stmt.executeUpdate("CLOSE " + cursorName); 69 rs.close(); 70 } 71 72 public static ResultSet newCursorResultSet(Statement stmt, String cursorName, int fetchSize) throws SQLException , Exception { 73 return (ResultSet ) newHandler(new CursorResultSet(stmt, cursorName, fetchSize), ResultSet .class); 74 } 75 } 76 | Popular Tags |