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.RowHandler implementation needs to be able to end current resultSet processing ------------------------------------------------------------------------------- Key: IBATIS-368 URL: http://issues.apache.org/jira/browse/IBATIS-368 Project: iBatis for Java Issue Type: Improvement Affects Versions: 2.1.7 Reporter: Kai Grabfelder The current RowHandler interface lacks the possibility to end current resultSet processing. Example: If a join query which joins categories and products Per category multiple products are allowed. The query is sorted by category ID. The query returns 100 000 rows but I only want to return the first 100 categories. I can not use the current limit functionalities of ibatis as I don't know how many products are present per category. So the number of rows to get the first 200 categories could be anything between 200 and infinity. I've written my own RowHandler implementation that throws and exception after the first 200 categoires - but that is not very nice. So why not change the interface of RowHandler#handleRow() to return boolean instead of void - this way the result set processing could be interupted if desired. cheers Kai -- 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)