List of usage examples for org.springframework.jdbc.core.namedparam MapSqlParameterSource getValues
public Map<String, Object> getValues()
From source file:org.sakuli.services.forwarder.database.dao.impl.DaoTestCaseImpl.java
@Override public void saveTestCaseResult(final TestCase testCase) { LOGGER.info("Save results for test case \"" + testCase.getId() + "\""); //create a map for the sql parameters MapSqlParameterSource tcParameters = new MapSqlParameterSource(); tcParameters.addValue("sakuli_suites_id", testSuite.getDbPrimaryKey()); tcParameters.addValue("caseID", testCase.getId()); tcParameters.addValue("result", testCase.getState().getErrorCode()); tcParameters.addValue("result_desc", testCase.getState()); tcParameters.addValue("name", testCase.getName()); tcParameters.addValue("guid", testSuite.getGuid()); tcParameters.addValue("start", testCase.getStartDateAsUnixTimestamp()); tcParameters.addValue("stop", testCase.getStopDateAsUnixTimestamp()); int warningTime = testCase.getWarningTime(); tcParameters.addValue("warning", (warningTime != 0) ? warningTime : null); int criticalTime = testCase.getCriticalTime(); tcParameters.addValue("critical", (criticalTime != 0) ? criticalTime : null); tcParameters.addValue("browser", testSuite.getBrowserInfo()); tcParameters.addValue("lastpage", testCase.getLastURL()); //try to save the screenshot tcParameters.addValue("screenshot", getScreenshotAsSqlLobValue(testCase), Types.BLOB); tcParameters.addValue("duration", testCase.getDuration()); tcParameters.addValue("msg", testCase.getExceptionMessages(true)); //generate the sql-statement SimpleJdbcInsert insertTCResults = new SimpleJdbcInsert(getDataSource()).withTableName("sakuli_cases") .usingGeneratedKeyColumns("id"); LOGGER.debug("write the following values to 'sakuli_cases': " + tcParameters.getValues() + " => now execute ...."); int dbPrimaryKey = insertTCResults.executeAndReturnKey(tcParameters).intValue(); LOGGER.info("test case '" + testCase.getId() + "' has been written to 'sahi_cases' with primaryKey=" + dbPrimaryKey);/*from w ww.j ava 2 s . c o m*/ testCase.setDbPrimaryKey(dbPrimaryKey); }
From source file:org.sakuli.services.receiver.database.dao.impl.DaoTestCaseImpl.java
@Override public void saveTestCaseResult(final TestCase testCase) { logger.info("Save results for test case \"" + testCase.getId() + "\""); //create a map for the sql parameters MapSqlParameterSource tcParameters = new MapSqlParameterSource(); tcParameters.addValue("sahi_suites_id", testSuite.getDbPrimaryKey()); tcParameters.addValue("caseID", testCase.getId()); tcParameters.addValue("result", testCase.getState().getErrorCode()); tcParameters.addValue("result_desc", testCase.getState()); tcParameters.addValue("name", testCase.getName()); tcParameters.addValue("guid", testSuite.getGuid()); tcParameters.addValue("start", testCase.getStartDateAsUnixTimestamp()); tcParameters.addValue("stop", testCase.getStopDateAsUnixTimestamp()); tcParameters.addValue("warning", testCase.getWarningTime()); tcParameters.addValue("critical", testCase.getCriticalTime()); tcParameters.addValue("browser", testSuite.getBrowserInfo()); tcParameters.addValue("lastpage", testCase.getLastURL()); //try to save the screenshot try {/*w w w. jav a 2 s. co m*/ if (testCase.getScreenShotPath() != null) { final InputStream blobIs = Files.newInputStream(testCase.getScreenShotPath()); final int length = (int) testCase.getScreenShotPath().toFile().length(); tcParameters.addValue("screenshot", new SqlLobValue(blobIs, length, lobHandler), Types.BLOB); } } catch (IOException e) { throw new RuntimeException(e); } tcParameters.addValue("duration", testCase.getDuration()); tcParameters.addValue("msg", testCase.getExceptionMessages()); //generate the sql-statement SimpleJdbcInsert insertTCResults = new SimpleJdbcInsert(getDataSource()).withTableName("sahi_cases") .usingGeneratedKeyColumns("id"); logger.info( "write the following values to 'sahi_cases': " + tcParameters.getValues() + " => now execute ...."); int dbPrimaryKey = insertTCResults.executeAndReturnKey(tcParameters).intValue(); logger.info("test case '" + testCase.getId() + "' has been written to 'sahi_cases' with primaryKey=" + dbPrimaryKey); testCase.setDbPrimaryKey(dbPrimaryKey); }