|
From: brian z. <bz...@us...> - 2002-04-19 19:47:49
|
Update of /cvsroot/jython/jython/com/ziclix/python/sql
In directory usw-pr-cvs1:/tmp/cvs-serv11379/com/ziclix/python/sql
Modified Files:
PyCursor.java zxJDBC.java
Log Message:
cleanup dynamic statements
Index: PyCursor.java
===================================================================
RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/PyCursor.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** PyCursor.java 19 Apr 2002 19:01:06 -0000 1.22
--- PyCursor.java 19 Apr 2002 19:47:45 -0000 1.23
***************
*** 66,69 ****
--- 66,72 ----
protected PyStatement statement;
+ /** A set of statements which this cursor prepared and distributed. */
+ protected Set preparedStatements;
+
// they are stateless instances, so we only need to instantiate it once
private static DataHandler DATAHANDLER = null;
***************
*** 104,107 ****
--- 107,111 ----
this.datahandler = DATAHANDLER;
this.dynamicFetch = dynamicFetch;
+ this.preparedStatements = new HashSet(3);
// constructs the appropriate Fetch among other things
***************
*** 277,280 ****
--- 281,285 ----
dict.__setitem__("rsConcur", null);
dict.__setitem__("rsType", null);
+ dict.__setitem__("preparedStatements", null);
}
***************
*** 296,303 ****
public void close() {
! this.clear();
! this.connection.unregister(this);
! this.closed = true;
}
--- 301,318 ----
public void close() {
! try {
! this.clear();
! for (Iterator i = this.preparedStatements.iterator(); i.hasNext(); ) {
! try {
! ((PyStatement)i.next()).close();
! } catch (Throwable t) {}
! }
!
! this.preparedStatements.clear();
! this.connection.unregister(this);
! } finally {
! this.closed = true;
! }
}
***************
*** 378,382 ****
* @return PyStatement
*/
! protected PyStatement prepareStatement(PyObject sql, PyObject maxRows, boolean prepared) {
PyStatement stmt = null;
--- 393,397 ----
* @return PyStatement
*/
! private PyStatement prepareStatement(PyObject sql, PyObject maxRows, boolean prepared) {
PyStatement stmt = null;
***************
*** 754,757 ****
--- 769,789 ----
/**
+ * Prepare a sql statement for later execution.
+ *
+ * @param sql The sql string to be prepared.
+ *
+ * @return A prepared statement usable with .executeXXX()
+ */
+ public PyStatement prepare(PyObject sql) {
+
+ PyStatement s = this.prepareStatement(sql, Py.None, true);
+
+ // add to the set of statements which are leaving our control
+ this.preparedStatements.add(s);
+
+ return s;
+ }
+
+ /**
* Scroll the cursor in the result set to a new position according
* to mode.
***************
*** 825,829 ****
}
- this.statement = null;
this.warnings = Py.None;
this.lastrowid = Py.None;
--- 857,860 ----
***************
*** 836,839 ****
--- 867,885 ----
this.fetch = Fetch.newFetch(this);
}
+
+ if (this.statement != null) {
+
+ // we can't close a dynamic fetch statement until everything has been
+ // consumed so the only time we can clean up is now
+ // but if this is a previously prepared statement we don't want to close
+ // it underneath someone; we can check this by looking in the set
+ try {
+ if (this.dynamicFetch && (!this.preparedStatements.contains(this.statement))) {
+ this.statement.close();
+ }
+ } finally {
+ this.statement = null;
+ }
+ }
}
***************
*** 1034,1038 ****
case 12 :
! return cursor.prepareStatement(arg, Py.None, true);
default :
--- 1080,1084 ----
case 12 :
! return cursor.prepare(arg);
default :
Index: zxJDBC.java
===================================================================
RCS file: /cvsroot/jython/jython/com/ziclix/python/sql/zxJDBC.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** zxJDBC.java 12 Apr 2002 04:12:27 -0000 1.8
--- zxJDBC.java 19 Apr 2002 19:47:45 -0000 1.9
***************
*** 125,129 ****
* Add the types from java.sql.Types
*
! * @param PyObject dict
*
* @throws PyException
--- 125,130 ----
* Add the types from java.sql.Types
*
! *
! * @param dict
*
* @throws PyException
***************
*** 169,173 ****
* Add all the possible connectors
*
! * @param PyObject dict
*
* @throws PyException
--- 170,175 ----
* Add all the possible connectors
*
! *
! * @param dict
*
* @throws PyException
***************
*** 204,207 ****
--- 206,211 ----
/**
* Create the exception classes and get their descriptions from the resource bundle.
+ *
+ * @param dict
*/
protected static void _buildExceptions(PyObject dict) {
***************
*** 222,227 ****
* Method _empty__init__
*
! * @param PyObject[] arg
! * @param String[] kws
*
* @return PyObject
--- 226,232 ----
* Method _empty__init__
*
! *
! * @param arg
! * @param kws
*
* @return PyObject
***************
*** 243,246 ****
--- 248,255 ----
* separator. If no indexed key is found, it defaults to checking the bundle by the
* key value alone.
+ *
+ * @param key
+ *
+ * @return String
*/
public static String getString(String key) {
***************
*** 265,269 ****
if ((lines == null) || (lines.size() == 0)) {
! resource = resourceBundle.getString(key);
} else {
String sep = System.getProperty("line.separator");
--- 274,282 ----
if ((lines == null) || (lines.size() == 0)) {
! try {
! resource = resourceBundle.getString(key);
! } catch (MissingResourceException e) {
! return key;
! }
} else {
String sep = System.getProperty("line.separator");
***************
*** 285,288 ****
--- 298,306 ----
* Return a formatted string. The key is used to get the format and the values
* are passed, along with the format, to a MessageFormat who formats it appropriately.
+ *
+ * @param key
+ * @param values
+ *
+ * @return String
*/
public static String getString(String key, Object[] values) {
***************
*** 295,298 ****
--- 313,320 ----
/**
* Return a newly instantiated PyException of the type Error.
+ *
+ * @param msg
+ *
+ * @return PyException
*/
public static PyException makeException(String msg) {
***************
*** 302,305 ****
--- 324,332 ----
/**
* Return a newly instantiated PyException of the given type.
+ *
+ * @param type
+ * @param msg
+ *
+ * @return PyException
*/
public static PyException makeException(PyObject type, String msg) {
***************
*** 309,312 ****
--- 336,343 ----
/**
* Return a newly instantiated PyException of the type Error.
+ *
+ * @param throwable
+ *
+ * @return PyException
*/
public static PyException makeException(Throwable throwable) {
***************
*** 316,319 ****
--- 347,355 ----
/**
* Return a newly instantiated PyException of the given type.
+ *
+ * @param type
+ * @param t
+ *
+ * @return PyException
*/
public static PyException makeException(PyObject type, Throwable t) {
***************
*** 363,366 ****
--- 399,408 ----
/**
* This function constructs an object holding a date value.
+ *
+ * @param year
+ * @param month
+ * @param day
+ *
+ * @return PyObject
*/
protected static PyObject Date(int year, int month, int day) {
***************
*** 377,380 ****
--- 419,428 ----
/**
* This function constructs an object holding a time value.
+ *
+ * @param hour
+ * @param minute
+ * @param second
+ *
+ * @return PyObject
*/
protected static PyObject Time(int hour, int minute, int second) {
***************
*** 391,394 ****
--- 439,451 ----
/**
* This function constructs an object holding a time stamp value.
+ *
+ * @param year
+ * @param month
+ * @param day
+ * @param hour
+ * @param minute
+ * @param second
+ *
+ * @return PyObject
*/
protected static PyObject Timestamp(int year, int month, int day, int hour, int minute, int second) {
***************
*** 418,421 ****
--- 475,480 ----
*
* @param ticks number of seconds since the epoch
+ *
+ * @return PyObject
*/
protected static PyObject DateFromTicks(long ticks) {
***************
*** 443,446 ****
--- 502,507 ----
*
* @param ticks number of seconds since the epoch
+ *
+ * @return PyObject
*/
protected static PyObject TimeFromTicks(long ticks) {
***************
*** 459,462 ****
--- 520,525 ----
*
* @param ticks number of seconds since the epoch
+ *
+ * @return PyObject
*/
protected static PyObject TimestampFromTicks(long ticks) {
***************
*** 467,473 ****
* Method buildClass
*
! * @param String classname
! * @param PyObject superclass
! * @param String classCodeName
*
* @return PyObject
--- 530,537 ----
* Method buildClass
*
! *
! * @param classname
! * @param superclass
! * @param classCodeName
*
* @return PyObject
***************
*** 498,507 ****
* Constructor zxJDBCFunc
*
! * @param String name
! * @param int index
! * @param int minargs
! * @param int maxargs
! * @param boolean func
! * @param String doc
*
*/
--- 562,572 ----
* Constructor zxJDBCFunc
*
! *
! * @param name
! * @param index
! * @param minargs
! * @param maxargs
! * @param func
! * @param doc
*
*/
***************
*** 513,517 ****
* Method __call__
*
! * @param PyObject arg
*
* @return PyObject
--- 578,583 ----
* Method __call__
*
! *
! * @param arg
*
* @return PyObject
***************
*** 541,547 ****
* Method __call__
*
! * @param PyObject arga
! * @param PyObject argb
! * @param PyObject argc
*
* @return PyObject
--- 607,614 ----
* Method __call__
*
! *
! * @param arga
! * @param argb
! * @param argc
*
* @return PyObject
***************
*** 574,578 ****
* Method fancyCall
*
! * @param PyObject[] args
*
* @return PyObject
--- 641,646 ----
* Method fancyCall
*
! *
! * @param args
*
* @return PyObject
|