|
I am interested in a slightly different RowHandler -- one that can
respond to the thread being interrupted. My not pretty attempt, appended below, looks for isInterrupted() on the thread and if it is it calls endTransaction which seems pretty drastic but the only other option that I thought of (without modifying iBATIS) was to close the underlying SqlConnection but that seems even more drastic (and endTransaction closes the underlying connection anyways, I believe). What do people think? private class InterruptableRowHandler implements RowHandler { private List<Object> list = new ArrayList<Object>(); private String id; private Object parameterObject; public InterruptableRowHandler(String id, Object parameterObject) { this.id = id; this.parameterObject = parameterObject; } public void handleRow(Object object) { Thread currentThread = Thread.currentThread(); Main.log.info("&&&&&& handleRow " +id + " passed: " + ((parameterObject == null) ? "null" : parameterObject.toString()) + " called with thread: " + currentThread.getName() + " isInterrupted: " + currentThread.isInterrupted()); if (currentThread.isInterrupted()) { try { sqlMapClient.endTransaction(); } catch (SQLException ex) { if (ex.getMessage().indexOf("Operation not allowed after Result Closed") == -1) { ex.printStackTrace(); } else { Main.log.info("got Result closed exception: handleRow " +id + " passed: " + ((parameterObject == null) ? "null" : parameterObject.toString()) + " called with thread: " + currentThread.getName() + " isInterrupted: " + currentThread.isInterrupted()); } } } else { if (!list.add(object)) { Main.log.warn("InterruptableRowHandler: adding object to list failed. Call to " + id + " passed: " + ((parameterObject == null) ? "null" : parameterObject.toString()) + ". Rejected object: " + ((object == null) ? "null" : object.toString()) ); } } } public List getList() { Thread currentThread = Thread.currentThread(); if (currentThread.isInterrupted()) { return null; } else { return list; } } Larry Meadors (JIRA) wrote: [ http://issues.apache.org/jira/browse/IBATIS-368?page=comments#action_12450735 ] Larry Meadors commented on IBATIS-368: --------------------------------------Changing this signature would break every existing rowhandler written, so that won't do. :-) If you add a method to the interface, that will do the same thing. You could create an AbortableRowHandler interface that extends the existing interface, and add a 'boolean stopProcessing()' method to it. It would take some tinkering with the internals, but I think it would work. -- Peter Andrews Software Engineer Dartmouth Medical School Computational Genetics Rubin 707 (603) 653-3598 [EMAIL PROTECTED] |
- [jira] Created: (IBATIS-368) RowHandler implementati... Kai Grabfelder (JIRA)
- [jira] Commented: (IBATIS-368) RowHandler imple... Larry Meadors (JIRA)
- Re: [jira] Commented: (IBATIS-368) RowHandl... Peter Andrews
- [jira] Commented: (IBATIS-368) RowHandler imple... Kai Grabfelder (JIRA)
