I would like to make a request or offer to contribute something with
regards error handling? Specifically, with regards to data extraction
using the org.apache.ddlutils.platform.ModelBasedResultSetIterator
class. As is, If this Iterators encounters an error when setting a
Dynabean property it throws a generic
DatabaseOperationException("Exception while reading the row from the
resultset"). It occurs, in my case, when encountering an allowable
(under mysql) but perhaps a bit unusual date value of "0000-00-00". The
existing source code in question looks like this:
45 /**
46 * This is an iterator that is specifically targeted at traversing result
sets.
47 * If the query is against a known table, then [EMAIL PROTECTED]
org.apache.ddlutils.dynabean.SqlDynaBean} instances
48 * are created from the rows, otherwise normal [EMAIL PROTECTED]
org.apache.commons.beanutils.DynaBean} instances
49 * are created.
50 *
51 * @version $Revision: 289996 $
52 */
...
218 /**
219 * [EMAIL PROTECTED]
220 */
221 public Object next() throws DatabaseOperationException
222 {
223 advanceIfNecessary();
224 if (_isAtEnd)
225 {
226 throw new NoSuchElementException("No more elements in the
resultset");
227 }
228 else
229 {
230 try
231 {
232 DynaBean bean = _dynaClass.newInstance();
233 Table table = null;
234
235 if (bean instanceof SqlDynaBean)
236 {
237 SqlDynaClass dynaClass =
(SqlDynaClass)((SqlDynaBean)bean).getDynaClass();
238
239 table = dynaClass.getTable();
240 }
241
242 for (Iterator it = _columnsToProperties.entrySet().iterator(); it.hasNext();)
243 {
244 Map.Entry entry = (Map.Entry)it.next();
245 String columnName = (String)entry.getKey();
246 String propName = (String)entry.getValue();
247 Table curTable = table;
248
249 if (curTable == null)
250 {
251 curTable =
(Table)_preparedQueryHints.get(_caseSensitive ? columnName :
columnName.toLowerCase());
252 }
253 Object value =
_platform.getObjectFromResultSet(_resultSet, columnName, curTable);
254
255 bean.set(propName, value);
256 }
257 _needsAdvancing = true;
258 return bean;
259 }
260 catch (Exception ex)
261 {
262 cleanUp();
263 throw new DatabaseOperationException("Exception while reading
the row from the resultset", ex);
264 }
265 }
266 }
I am suggesting at least more lax error handling around the value
setting code (lines 253 - 255) as I use below (using some logging api
wrapped with commons-logging) to just log the actual error message
encountered ("[ERROR] ModelBasedResultSetIterator - Value '0000-00-00'
can not be represented as java.sql.Date") and proceed with the
extraction rather than just fail. An even better solution might be to
declare a level for error handling (fail | warn | ignore perhaps) that
could be specified as ant task attribute so the could would know how to
handle the errors encountered more precisely.
258 Object value=null;
259
260 try {
261 value =
_platform.getObjectFromResultSet(_resultSet, columnName, curTable);
262 bean.set(propName, value);
263 } catch (SQLException ex) {
264 log.error(ex.getMessage());
265 }