From: <fg...@us...> - 2007-02-19 23:28:56
|
Revision: 278 http://svn.sourceforge.net/openutils/?rev=278&view=rev Author: fgiust Date: 2007-02-19 15:28:57 -0800 (Mon, 19 Feb 2007) Log Message: ----------- better handing of types, trim column names Modified Paths: -------------- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java Modified: trunk/openutils-dbmigration/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java =================================================================== --- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java 2007-02-19 23:08:13 UTC (rev 277) +++ trunk/openutils-dbmigration/src/main/java/it/openutils/migration/task/setup/ExcelConfigurationTask.java 2007-02-19 23:28:57 UTC (rev 278) @@ -126,7 +126,7 @@ String columnName = row.getCell(k).getStringCellValue(); if (StringUtils.isNotBlank(columnName)) { - columns.add(columnName); + columns.add(StringUtils.trim(columnName)); } else { @@ -138,7 +138,7 @@ final List<Integer> types = new ArrayList<Integer>(); - new JdbcTemplate(dataSource).execute(new ConnectionCallback() + boolean result = (Boolean) new JdbcTemplate(dataSource).execute(new ConnectionCallback() { public Object doInConnection(Connection con) throws SQLException, DataAccessException @@ -150,12 +150,22 @@ { types.add(res.getInt("DATA_TYPE")); } + else + { + log.warn("Unable to determine type for column '{}' in table '{}'", column, tableName); + return false; + } res.close(); } - return null; + return true; } }); + if (!result) + { + log.warn("Skipping sheet {} ", tableName); + } + String checkStatement = StringUtils.remove(StringUtils.trim(con.getCheckQuery()), "\n"); String insertStatement = StringUtils.remove(StringUtils.trim(con.getInsertQuery()), "\n"); @@ -258,15 +268,24 @@ if (existing == 0) { Object[] insertParams = ArrayUtils.subarray(values.toArray(), 0, insertNum); + int[] insertTypes = ArrayUtils.subarray(types, 0, insertNum); if (log.isDebugEnabled()) { log.debug("Missing record with key {}; inserting {}", ArrayUtils.toString(checkParams), ArrayUtils .toString(insertParams)); } + if (insertParams.length != insertTypes.length) + { + log.warn("Invalid number of param/type for table {}. Params: {}, types: {}", new Object[]{ + tableName, + insertParams.length, + insertTypes.length }); + } + try { - jdbcTemplate.update(insertStatement, insertParams, types); + jdbcTemplate.update(insertStatement, insertParams, insertTypes); } catch (DataIntegrityViolationException bsge) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |