List of usage examples for org.springframework.jdbc.core.simple SimpleJdbcInsert executeAndReturnKey
@Override
public Number executeAndReturnKey(SqlParameterSource parameterSource)
From source file:org.sakuli.services.receiver.database.dao.impl.DaoTestSuiteImpl.java
@Override public int saveTestSuiteToSahiJobs() { logger.info("save the guid to the table 'sahi_jobs'"); //build up the statement MapSqlParameterSource tcParameters = getGuidParameter(); logger.info("write the following values to 'sahi_jobs': " + tcParameters.getValues() + " ==> now execute ...."); SimpleJdbcInsert insertTS = new SimpleJdbcInsert(getDataSource()).withTableName("sahi_jobs") .usingGeneratedKeyColumns("id"); testSuite.setDbJobPrimaryKey(insertTS.executeAndReturnKey(tcParameters).intValue()); logger.info("the test suite \"" + testSuite.getId() + "\"" + "with the guid \"" + testSuite.getGuid() + "\" has been written to 'sahi_jobs' with primaryKey=" + testSuite.getDbJobPrimaryKey()); return testSuite.getDbJobPrimaryKey(); }
From source file:org.sakuli.services.forwarder.database.dao.impl.DaoTestSuiteImpl.java
@Override public int saveTestSuiteToSahiJobs() { LOGGER.debug("save the guid to the table 'sakuli_jobs'"); //build up the statement MapSqlParameterSource tcParameters = getGuidParameter(); LOGGER.debug("write the following values to 'sakuli_jobs': " + tcParameters.getValues() + " ==> now execute ...."); SimpleJdbcInsert insertTS = new SimpleJdbcInsert(getDataSource()).withTableName("sakuli_jobs") .usingGeneratedKeyColumns("id"); testSuite.setDbJobPrimaryKey(insertTS.executeAndReturnKey(tcParameters).intValue()); LOGGER.info("the test suite \"" + testSuite.getId() + "\"" + "with the guid \"" + testSuite.getGuid() + "\" has been written to 'sakuli_jobs' with primaryKey=" + testSuite.getDbJobPrimaryKey()); return testSuite.getDbJobPrimaryKey(); }
From source file:org.sakuli.services.receiver.database.dao.impl.DaoTestSuiteImpl.java
/** * {@inheritDoc}//from w w w. j a v a 2 s.co m */ @Override public int insertInitialTestSuiteData() { logger.info("Build SQL query for new primary key in table 'sahi_suites'"); testSuite.refreshState(); MapSqlParameterSource tcParameters = getInitialDataParameters(); logger.info("write the following values to 'sahi_suites': " + tcParameters.getValues() + " ==> now execute ...."); SimpleJdbcInsert insertInitialSuiteData = new SimpleJdbcInsert(getDataSource()).withTableName("sahi_suites") .usingGeneratedKeyColumns("id"); int dbPrimaryKey = insertInitialSuiteData.executeAndReturnKey(tcParameters).intValue(); logger.info("test suite \"" + testSuite.getId() + "\" has been written to 'sahi_suites' with primaryKey=" + dbPrimaryKey); return dbPrimaryKey; }
From source file:org.sakuli.services.forwarder.database.dao.impl.DaoTestSuiteImpl.java
/** * {@inheritDoc}// w w w . j a va 2s . co m */ @Override public int insertInitialTestSuiteData() { LOGGER.debug("Build SQL query for new primary key in table 'sakuli_suites'"); testSuite.refreshState(); MapSqlParameterSource tcParameters = getInitialDataParameters(); LOGGER.debug("write the following values to 'sakuli_suites': " + tcParameters.getValues() + " ==> now execute ...."); SimpleJdbcInsert insertInitialSuiteData = new SimpleJdbcInsert(getDataSource()) .withTableName("sakuli_suites").usingGeneratedKeyColumns("id"); int dbPrimaryKey = insertInitialSuiteData.executeAndReturnKey(tcParameters).intValue(); LOGGER.info("test suite \"" + testSuite.getId() + "\" has been written to 'sakuli_suites' with primaryKey=" + dbPrimaryKey); return dbPrimaryKey; }
From source file:org.sakuli.services.forwarder.database.dao.impl.DaoTestCaseStepImpl.java
@Override public void saveTestCaseSteps(SortedSet<TestCaseStep> steps, int primaryKeyOfTestCase) { for (TestCaseStep step : steps) { LOGGER.info("============== save STEP \"" + step.getName() + "\" =============="); MapSqlParameterSource stepParameters = new MapSqlParameterSource(); stepParameters.addValue("sakuli_cases_id", primaryKeyOfTestCase); stepParameters.addValue("result", step.getState().getErrorCode()); stepParameters.addValue("result_desc", step.getState()); stepParameters.addValue("name", step.getName()); stepParameters.addValue("start", step.getStartDateAsUnixTimestamp()); stepParameters.addValue("stop", step.getStopDateAsUnixTimestamp()); int warningTime = step.getWarningTime(); stepParameters.addValue("warning", (warningTime != 0) ? warningTime : null); stepParameters.addValue("duration", step.getDuration()); LOGGER.debug("write the following values to 'sakuli_steps': " + stepParameters.getValues() + "\n now execute ...."); //generate the sql-statement SimpleJdbcInsert insertStepResults = new SimpleJdbcInsert(getDataSource()).withTableName("sakuli_steps") .usingGeneratedKeyColumns("id"); //execute the sql-statement and save the primary key int dbPrimaryKey = insertStepResults.executeAndReturnKey(stepParameters).intValue(); LOGGER.info("test case step '" + step.getName() + "' has been written to 'sakuli_steps' with primaryKey=" + dbPrimaryKey); step.setDbPrimaryKey(dbPrimaryKey); }//from w w w . j a va2 s . com }
From source file:org.sakuli.services.receiver.database.dao.impl.DaoTestCaseStepImpl.java
@Override public void saveTestCaseSteps(List<TestCaseStep> steps, int primaryKeyOfTestCase) { for (TestCaseStep step : steps) { logger.info("============== save STEP \"" + step.getName() + "\" =============="); MapSqlParameterSource stepParameters = new MapSqlParameterSource(); stepParameters.addValue("sahi_cases_id", primaryKeyOfTestCase); stepParameters.addValue("result", step.getState().getErrorCode()); stepParameters.addValue("result_desc", step.getState()); stepParameters.addValue("name", step.getName()); stepParameters.addValue("start", step.getStartDateAsUnixTimestamp()); stepParameters.addValue("stop", step.getStopDateAsUnixTimestamp()); stepParameters.addValue("warning", step.getWarningTime()); stepParameters.addValue("duration", step.getDuration()); logger.info("write the following values to 'sahi_steps': " + stepParameters.getValues() + "\n now execute ...."); //generate the sql-statement SimpleJdbcInsert insertStepResults = new SimpleJdbcInsert(getDataSource()).withTableName("sahi_steps") .usingGeneratedKeyColumns("id"); //execute the sql-statement and save the primary key int dbPrimaryKey = insertStepResults.executeAndReturnKey(stepParameters).intValue(); logger.info("test case step '" + step.getName() + "' has been written to 'sahi_steps' with primaryKey=" + dbPrimaryKey);//from w w w . j a va2s . c o m step.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.ja v a2s . com*/ 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); }
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 ww w . j a v a 2 s. co m testCase.setDbPrimaryKey(dbPrimaryKey); }
From source file:main.java.net.bornil.db.service.jdbc.JdbcEventDao.java
@Override public int createEvent(Event event) { SimpleJdbcInsert insertEvent = new SimpleJdbcInsert(this.jdbcTemplate).withTableName("EVENT") .usingColumns("EVT_STATUS", "EVT_CLASS", "EVT_CREATED_BY", "EVT_CREATED_ON") .usingGeneratedKeyColumns("EVT_ID"); Map<String, Object> args = new HashMap<String, Object>(4); args.put("EVT_STATUS", 1100); args.put("EVT_CLASS", event.getEvtClass()); args.put("EVT_CREATED_BY", "MaMuN"); args.put("EVT_CREATED_ON", new Date()); Number newId = insertEvent.executeAndReturnKey(args); event.setEvtId(newId.intValue());/*from w w w .j a v a 2 s .c om*/ return event.getEvtId(); }
From source file:de.siemens.quantarch.bugs.dao.IssueTrackerDaoImpl.java
/** * Populate the issue_history table with the history data of the issue * //from w ww. j a va2 s.c o m * @param history * @param issueId * @param projectId */ private void addBugHistory(BugHistory history, long issueId, long projectId) { SimpleJdbcInsert insertPerson = new SimpleJdbcInsert(getDataSource()).withTableName("issue_history") .usingGeneratedKeyColumns("id"); Map<String, Object> parameters = new HashMap<String, Object>(2); parameters.put("field", history.getField()); parameters.put("changeDate", history.getWhen()); parameters.put("oldValue", history.getOldValue()); parameters.put("newValue", history.getNewValue()); parameters.put("issueId", issueId); // get the person who changed the history long commentUser = PersonServiceClient.getPerson(null, history.getWho(), projectId, projectConfig.getPersonServiceURL()); parameters.put("who", commentUser); insertPerson.executeAndReturnKey(parameters); }