From: brian z. <bz...@us...> - 2002-03-26 02:46:39
|
Update of /cvsroot/jython/jython/com/ziclix/python/sql In directory usw-pr-cvs1:/tmp/cvs-serv29788/com/ziclix/python/sql Modified Files: PyConnection.java PyCursor.java Log Message: close open cursors when the connection closes Index: PyConnection.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/PyConnection.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PyConnection.java 11 Jan 2002 21:46:01 -0000 1.5 --- PyConnection.java 26 Mar 2002 02:46:36 -0000 1.6 *************** *** 11,14 **** --- 11,15 ---- import java.sql.*; + import java.util.*; import org.python.core.*; *************** *** 28,31 **** --- 29,35 ---- protected boolean supportsTransactions; + /** Field cursors */ + protected List cursors; + /** Field __class__ */ public static PyClass __class__; *************** *** 56,60 **** m[4] = new PyString("nativesql"); __methods__ = new PyList(m); ! m = new PyObject[6]; m[0] = new PyString("autocommit"); m[1] = new PyString("dbname"); --- 60,64 ---- m[4] = new PyString("nativesql"); __methods__ = new PyList(m); ! m = new PyObject[7]; m[0] = new PyString("autocommit"); m[1] = new PyString("dbname"); *************** *** 63,66 **** --- 67,71 ---- m[4] = new PyString("url"); m[5] = new PyString("__connection__"); + m[6] = new PyString("__cursors__"); __members__ = new PyList(m); } *************** *** 72,75 **** --- 77,81 ---- this.connection = connection; + this.cursors = new LinkedList(); this.supportsTransactions = this.connection.getMetaData().supportsTransactions(); *************** *** 116,119 **** --- 122,126 ---- dict.__setitem__("connection", null); dict.__setitem__("classDictInit", null); + dict.__setitem__("cursors", null); } *************** *** 181,184 **** --- 188,193 ---- } else if ("__connection__".equals(name)) { return Py.java2py(this.connection); + } else if ("__cursors__".equals(name)) { + return Py.java2py(Collections.unmodifiableList(this.cursors)); } else if ("__methods__".equals(name)) { return __methods__; *************** *** 200,206 **** public void close() { ! try { ! // close the cursors too? this.connection.close(); } catch (SQLException e) { --- 209,223 ---- public void close() { ! synchronized (this.cursors) { ! // close the cursors ! for (int i = this.cursors.size() - 1; i >= 0; i--) { ! ((PyCursor)this.cursors.get(i)).close(); ! } ! ! this.cursors.clear(); ! } ! ! try { this.connection.close(); } catch (SQLException e) { *************** *** 286,290 **** */ public PyCursor cursor() { ! return new PyExtendedCursor(this); } --- 303,307 ---- */ public PyCursor cursor() { ! return cursor(false); } *************** *** 298,302 **** */ public PyCursor cursor(boolean dynamicFetch) { ! return new PyExtendedCursor(this, dynamicFetch); } } --- 315,334 ---- */ public PyCursor cursor(boolean dynamicFetch) { ! ! PyCursor cursor = new PyExtendedCursor(this, dynamicFetch); ! ! cursors.add(cursor); ! ! return cursor; ! } ! ! /** ! * Unregister an open PyCursor. ! * ! * @param PyCursor cursor ! * ! */ ! void unregister(PyCursor cursor) { ! this.cursors.remove(cursor); } } Index: PyCursor.java =================================================================== RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/PyCursor.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** PyCursor.java 14 Jan 2002 04:28:41 -0000 1.17 --- PyCursor.java 26 Mar 2002 02:46:36 -0000 1.18 *************** *** 266,269 **** --- 266,270 ---- this.clear(); + this.connection.unregister(this); this.closed = true; |