use of org.springframework.jdbc.core.RowMapper in project spring-data-jdbc by spring-projects.
the class JdbcQueryLookupStrategyUnitTests method typeBasedRowMapperGetsUsedForQuery.
// DATAJDBC-166
@Test
@SuppressWarnings("unchecked")
void typeBasedRowMapperGetsUsedForQuery() {
RowMapper<? extends NumberFormat> numberFormatMapper = mock(RowMapper.class);
QueryMappingConfiguration mappingConfiguration = new DefaultQueryMappingConfiguration().registerRowMapper(NumberFormat.class, numberFormatMapper);
RepositoryQuery repositoryQuery = getRepositoryQuery("returningNumberFormat", mappingConfiguration);
repositoryQuery.execute(new Object[] {});
verify(operations).queryForObject(anyString(), any(SqlParameterSource.class), any(RowMapper.class));
}
use of org.springframework.jdbc.core.RowMapper in project spring-data-jdbc by spring-projects.
the class ConfigurableRowMapperMapUnitTests method prefersLatestRegistrationForSuperTypeMatch.
// DATAJDBC-166
@Test
public void prefersLatestRegistrationForSuperTypeMatch() {
RowMapper rowMapper = mock(RowMapper.class);
QueryMappingConfiguration map = //
new DefaultQueryMappingConfiguration().registerRowMapper(Integer.class, //
mock(RowMapper.class)).registerRowMapper(Number.class, rowMapper);
assertThat(map.getRowMapper(Object.class)).isEqualTo(rowMapper);
}
use of org.springframework.jdbc.core.RowMapper in project spring-data-jdbc by spring-projects.
the class ConfigurableRowMapperMapUnitTests method returnsConfiguredInstanceForClass.
// DATAJDBC-166
@Test
public void returnsConfiguredInstanceForClass() {
RowMapper rowMapper = mock(RowMapper.class);
QueryMappingConfiguration map = new DefaultQueryMappingConfiguration().registerRowMapper(Object.class, rowMapper);
assertThat(map.getRowMapper(Object.class)).isEqualTo(rowMapper);
}
use of org.springframework.jdbc.core.RowMapper in project iaf by ibissource.
the class Storage method getMetadata.
@Override
public List<List<Object>> getMetadata(int maxNumberOfRecords, final List<String> metadataNames, List<String> searchValues, int metadataValueType) throws StorageException {
// According to SimpleDateFormat javadoc it needs to be synchronised
// when accessed by multiple threads, hence instantiate it here instead
// of instantiating it at class level and synchronising it.
final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(TIMESTAMP_PATTERN);
List<String> rangeSearchValues = new ArrayList<String>();
List<String> regexSearchValues = new ArrayList<String>();
for (int i = 0; i < searchValues.size(); i++) {
String searchValue = searchValues.get(i);
if (searchValue != null && searchValue.startsWith("<") && searchValue.endsWith(">")) {
rangeSearchValues.add(searchValue);
regexSearchValues.add(null);
searchValues.remove(i);
searchValues.add(i, null);
} else if (searchValue != null && searchValue.startsWith("(") && searchValue.endsWith(")")) {
rangeSearchValues.add(null);
regexSearchValues.add(searchValue);
searchValues.remove(i);
searchValues.add(i, null);
} else {
rangeSearchValues.add(null);
regexSearchValues.add(null);
}
}
IDbmsSupport dbmsSupport = getDbmsSupport();
StringBuilder query = new StringBuilder("select " + dbmsSupport.provideFirstRowsHintAfterFirstKeyword(maxNumberOfRecords) + " * from (select ");
List<Object> args = new ArrayList<Object>();
boolean first = true;
for (String metadataName : metadataNames) {
if (first) {
first = false;
} else {
query.append(", ");
}
if (bigValueColumns.contains(metadataName)) {
query.append("substr(" + metadataName + ", 1, 100)");
} else {
query.append(metadataName);
}
}
String rowNumber = dbmsSupport.getRowNumber(metadataNames.get(0), "desc");
if (StringUtils.isNotEmpty(rowNumber)) {
if (first) {
first = false;
} else {
query.append(", ");
}
query.append(rowNumber);
}
query.append(" from " + table);
for (int i = 0; i < rangeSearchValues.size(); i++) {
String searchValue = rangeSearchValues.get(i);
if (searchValue != null) {
int j = searchValue.indexOf('|');
if (j != -1) {
String column = metadataNames.get(i);
String searchValueLeft = searchValue.substring(1, j);
String searchValueRight = searchValue.substring(j + 1, searchValue.length() - 1);
if (StringUtils.isNotEmpty(searchValueLeft)) {
if (integerColumns.contains(column)) {
addNumberExpression(query, args, column, ">=", searchValueLeft);
} else if (timestampColumns.contains(column)) {
addTimestampExpression(query, args, column, ">=", searchValueLeft, simpleDateFormat);
}
}
if (StringUtils.isNotEmpty(searchValueRight)) {
if (integerColumns.contains(column)) {
addNumberExpression(query, args, column, "<=", searchValueRight);
} else if (timestampColumns.contains(column)) {
addTimestampExpression(query, args, column, "<=", searchValueRight, simpleDateFormat);
}
}
} else {
throw new StorageException("Separator | not found");
}
}
}
for (int i = 0; i < searchValues.size(); i++) {
String searchValue = searchValues.get(i);
if (StringUtils.isNotEmpty(searchValue)) {
String column = metadataNames.get(i);
if (integerColumns.contains(column)) {
addNumberExpression(query, args, column, "<=", searchValue);
} else if (timestampColumns.contains(column)) {
addTimestampExpression(query, args, column, "<=", searchValue, simpleDateFormat);
} else if (fixedStringColumns != null && fixedStringColumns.contains(column)) {
addFixedStringExpression(query, args, column, searchValue);
} else {
addLikeExpression(query, args, column, searchValue);
}
}
}
query.append(")");
if (StringUtils.isNotEmpty(rowNumber)) {
query.append(" where " + dbmsSupport.getRowNumberShortName() + " < ?");
args.add(maxNumberOfRecords + 1);
}
query.append(" order by ");
query.append(metadataNames.get(0) + " desc");
log.debug("Metadata query: " + query.toString());
List metadata;
try {
metadata = jdbcTemplate.query(query.toString(), args.toArray(), new RowMapper() {
public List mapRow(ResultSet rs, int rowNum) throws SQLException {
List row = new ArrayList();
for (int i = 0; i < metadataNames.size(); i++) {
if (integerColumns.contains(metadataNames.get(i))) {
row.add(rs.getInt(i + 1));
} else if (timestampColumns.contains(metadataNames.get(i))) {
row.add(simpleDateFormat.format(rs.getTimestamp(i + 1)));
} else {
row.add(getValue(rs, i + 1));
}
}
return row;
}
});
} catch (DataAccessException e) {
throw new StorageException("Could not read metadata", e);
}
for (int i = 0; i < metadata.size(); i++) {
if (!SearchUtil.matches((List) metadata.get(i), regexSearchValues)) {
metadata.remove(i);
i--;
}
}
return metadata;
}
use of org.springframework.jdbc.core.RowMapper in project topcom-cloud by 545314690.
the class RowMappers method companyVORowMapper.
/**
* 企业RowMapper
* @return
*/
public static RowMapper<CompanyVO> companyVORowMapper() {
return new RowMapper<CompanyVO>() {
@Override
public CompanyVO mapRow(ResultSet resultSet, int i) throws SQLException {
CompanyVO company = new CompanyVO();
company.setId(resultSet.getLong("id"));
company.setCompanyName(resultSet.getString("companyName"));
company.setLng(resultSet.getDouble("lng"));
company.setLat(resultSet.getDouble("lat"));
return company;
}
};
}
Aggregations