use of org.springframework.jdbc.core.RowMapper in project iaf by ibissource.
the class Storage method getReport.
@Override
public Report getReport(Integer storageId) throws StorageException {
final Report report = new Report();
report.setTestTool(testTool);
report.setStorage(this);
report.setStorageId(storageId);
report.setName("Table " + table);
report.setStubStrategy("Never");
final List<Checkpoint> checkpoints = new ArrayList<Checkpoint>();
report.setCheckpoints(checkpoints);
StringBuilder query = new StringBuilder("select " + reportColumnNames.get(0));
for (int i = 1; i < reportColumnNames.size(); i++) {
query.append(", " + reportColumnNames.get(i));
}
query.append(" from " + table + " where LOGID = ?");
try {
jdbcTemplate.query(query.toString(), new Object[] { storageId }, new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
for (int i = 0; i < reportColumnNames.size(); i++) {
String value = getValue(rs, i + 1);
Checkpoint checkpoint = new Checkpoint(report, Thread.currentThread().getName(), Storage.class.getName(), "Column " + reportColumnNames.get(i), Checkpoint.TYPE_INPUTPOINT, 0);
checkpoint.setMessage(value);
checkpoints.add(checkpoint);
}
return null;
}
});
} catch (DataAccessException e) {
throw new StorageException("Could not read report", e);
}
return report;
}
use of org.springframework.jdbc.core.RowMapper in project spring-integration by spring-projects.
the class StoredProcExecutorTests method testSetReturningResultSetRowMappersWithMapContainingNullValues.
@Test
public void testSetReturningResultSetRowMappersWithMapContainingNullValues() {
DataSource datasource = mock(DataSource.class);
StoredProcExecutor storedProcExecutor = new StoredProcExecutor(datasource);
Map<String, RowMapper<?>> rowmappers = new HashMap<String, RowMapper<?>>();
rowmappers.put("results", null);
try {
storedProcExecutor.setReturningResultSetRowMappers(rowmappers);
} catch (IllegalArgumentException e) {
assertEquals("The provided map cannot contain null values.", e.getMessage());
return;
}
fail("Exception expected.");
}
use of org.springframework.jdbc.core.RowMapper in project ma-core-public by infiniteautomation.
the class Upgrade14 method upgrade.
/* (non-Javadoc)
* @see com.serotonin.m2m2.db.upgrade.DBUpgrade#upgrade()
*/
@Override
protected void upgrade() throws Exception {
OutputStream os = createUpdateLogOutputStream();
// Run the scripts to add the ID Column
Map<String, String[]> scripts = new HashMap<>();
scripts.put(DatabaseProxy.DatabaseType.DERBY.name(), derbyIdColumnScript);
scripts.put(DatabaseProxy.DatabaseType.MYSQL.name(), mysqlIdColumnScript);
scripts.put(DatabaseProxy.DatabaseType.MSSQL.name(), mssqlIdColumnScript);
scripts.put(DatabaseProxy.DatabaseType.H2.name(), h2IdColumnScript);
runScript(scripts, os);
// Run the scripts to create the XID column but not restrict it to NOT NULL
scripts = new HashMap<>();
scripts.put(DatabaseProxy.DatabaseType.DERBY.name(), derbyXidColumnScript);
scripts.put(DatabaseProxy.DatabaseType.MYSQL.name(), mysqlXidColumnScript);
scripts.put(DatabaseProxy.DatabaseType.MSSQL.name(), mssqlXidColumnScript);
scripts.put(DatabaseProxy.DatabaseType.H2.name(), h2XidColumnScript);
runScript(scripts, os);
// Set XIDs on all the user comments, ugh
AtomicInteger count = new AtomicInteger();
final String prefix = "UC_";
final RowMapper<Integer> mapper = new RowMapper<Integer>() {
@Override
public Integer mapRow(ResultSet rs, int rowNum) throws SQLException {
return rs.getInt(1);
}
};
final MappedRowCallback<Integer> callback = new MappedRowCallback<Integer>() {
@Override
public void row(Integer item, int index) {
ejt.update("UPDATE userComments SET xid=? WHERE id=?", new Object[] { prefix + UUID.randomUUID(), item });
count.incrementAndGet();
}
};
this.ejt.query("SELECT id FROM userComments", new Object[] {}, new RowCallbackHandler() {
private int rowNum = 0;
public void processRow(ResultSet rs) throws SQLException {
callback.row(mapper.mapRow(rs, rowNum), rowNum);
rowNum++;
}
});
String upgradedString = new String("Updated " + count.get() + " user comments with XIDs.\n");
os.write(upgradedString.getBytes(Common.UTF8_CS));
// Run the scripts to restrict the XID to NOT NULL
scripts.put(DatabaseProxy.DatabaseType.DERBY.name(), derbyXidNotNullColumnScript);
scripts.put(DatabaseProxy.DatabaseType.MYSQL.name(), mysqlXidNotNullColumnScript);
scripts.put(DatabaseProxy.DatabaseType.MSSQL.name(), mssqlXidNotNullColumnScript);
scripts.put(DatabaseProxy.DatabaseType.H2.name(), h2XidNotNullColumnScript);
runScript(scripts, os);
}
use of org.springframework.jdbc.core.RowMapper in project ovirt-engine by oVirt.
the class SystemStatisticsDaoImpl method getSystemStatisticsValue.
@Override
public Integer getSystemStatisticsValue(String entity, String status) {
MapSqlParameterSource parameterSource = new CustomMapSqlParameterSource(dbEngineDialect).addValue("entity", entity).addValue("status", status);
RowMapper<Integer> mapper = (rs, rowNum) -> rs.getInt("val");
Map<String, Object> dbResults = dbEngineDialect.createJdbcCallForQuery(jdbcTemplate).withProcedureName("Getsystem_statistics").returningResultSet("RETURN_VALUE", mapper).execute(parameterSource);
return (Integer) DbFacadeUtils.asSingleResult((List<?>) dbResults.get("RETURN_VALUE"));
}
use of org.springframework.jdbc.core.RowMapper in project ovirt-engine by oVirt.
the class TagDaoImpl method getTagTemplateByTagIdAndByTemplateId.
/**
* In the database both Template and Vm Tags share the same tables and functions
*/
@Override
public TagsTemplateMap getTagTemplateByTagIdAndByTemplateId(Guid tagId, Guid vmId) {
MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource().addValue("tag_id", tagId).addValue("vm_id", vmId);
RowMapper<TagsTemplateMap> mapper = (rs, rowNum) -> {
TagsTemplateMap entity = new TagsTemplateMap();
entity.setTagId(getGuidDefaultEmpty(rs, "tag_id"));
entity.setTemplateId(getGuidDefaultEmpty(rs, "vm_id"));
entity.setDefaultDisplayType((Integer) rs.getObject("DefaultDisplayType"));
return entity;
};
return getCallsHandler().executeRead("GetTagVmByTagIdAndByvmId", mapper, parameterSource);
}
Aggregations