use of com.github.mgramin.sqlboot.model.resource.wrappers.DbResourceBodyWrapper in project sql-boot by sql-boot.
the class SqlBodyWrapper method read.
@Override
public Stream<DbResource> read(final Uri uri) throws BootException {
return origin.read(uri).map(origin -> {
if (origin.body() != null && !origin.body().isEmpty()) {
final JdbcSqlQuery jdbcSqlQuery = new JdbcSqlQuery(dataSource, origin.body());
final Map<String, Object> stringObjectMap = jdbcSqlQuery.select().findFirst().get();
final Object body = stringObjectMap.values().iterator().next();
return new DbResourceBodyWrapper(origin, body.toString());
}
return new DbResourceBodyWrapper(origin, "NOT SET SQL");
});
}
use of com.github.mgramin.sqlboot.model.resource.wrappers.DbResourceBodyWrapper in project sql-boot by sql-boot.
the class SelectWrapper method read.
@Override
public Stream<DbResource> read(final Uri uri) throws BootException {
final String select = uri.params().get(SELECT);
final Stream<DbResource> resources = origin.read(uri);
if (select != null) {
return resources.map(v -> new DbResourceBodyWrapper(new DbResourceImpl(v.name(), v.type(), v.dbUri(), v.headers().entrySet().stream().filter(h -> asList(select.split(",")).contains(h.getKey())).collect(toMap(Entry::getKey, Entry::getValue))), v.body()));
} else {
return resources;
}
}
Aggregations