How do I request less-strict error handling? Specifically I had to
modify org.apache.ddlutils.platform.ModelBasedResultSetIterator class to
skip setting bean values for allowable(in mysql 5.x) but unusual
timestamp values of "0000-00-00 00:00:00" (set by default). If this is
not the right forum for this request, please redirect me. 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 }
The data extraction fails with the existing code with a "Exception while
reading the row from the resultset" error when it encounters the
"0000-00-00 00:00:00" timestamp values in the database. I am suggesting
a more lax error handling around the value setting code (lines 253 -
255) as such (using some logging api wrapped with commons-logging) to
display the actual error message encountered and proceed with the
extraction rather than just fail. Perhaps this could be regulated with
an appropriate configuration directive "errorHandling" in the ant task
that could be checked at execution time for a more elegant solution:
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 }