| 1 package com.quadcap.sql; 2 3 40 41 import java.sql.SQLException ; 42 43 import java.util.ArrayList ; 44 45 import com.quadcap.util.Debug; 46 47 53 public class MultiCursor extends FilterCursor { 54 ArrayList cursors = new ArrayList (); 55 int cursorNum = 0; 56 57 public MultiCursor(Session session) throws SQLException { 58 super(session); 59 } 60 61 public MultiCursor(Session session, Cursor cursor) throws SQLException { 62 super(session, cursor); 63 appendCursor(session, cursor); 64 } 65 66 public void appendCursor(Session session, Cursor cursor) throws SQLException { 67 cursors.add(cursor); 68 if (this.cursor == null) { 69 this.cursor = cursor; 70 addColumns(session, cursor); 71 } 72 } 73 74 public void beforeFirst() throws SQLException { 75 for (int i = 0; i < cursors.size(); i++) { 76 Cursor c = ((Cursor)cursors.get(i)); 77 c.beforeFirst(); 78 if (i == 0) cursor = c; 79 } 80 cursorNum = 0; 81 } 82 83 public boolean next() throws SQLException { 84 boolean ret = cursor.next(); 85 while (!ret && ++cursorNum < cursors.size()) { 86 cursor = (Cursor)cursors.get(cursorNum); 87 cursor.beforeFirst(); 88 ret = cursor.next(); 89 } 90 return ret; 91 } 92 93 public boolean prev() throws SQLException { 94 throw new SQLException ("MultiCursor.prev() not implemented"); 95 } 96 97 public void close() throws SQLException { 98 for (int i = 0; i < cursors.size(); i++) { 99 try { 100 ((Cursor)cursors.get(i)).close(); 101 } catch (Throwable t) {} 102 } 103 } 104 } 105 | Popular Tags |