Search in sources :

Example 1 with DbResourceBodyWrapper

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");
    });
}
Also used : JdbcSqlQuery(com.github.mgramin.sqlboot.sql.impl.JdbcSqlQuery) DbResourceBodyWrapper(com.github.mgramin.sqlboot.model.resource.wrappers.DbResourceBodyWrapper)

Example 2 with DbResourceBodyWrapper

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;
    }
}
Also used : Entry(java.util.Map.Entry) DbResourceImpl(com.github.mgramin.sqlboot.model.resource.impl.DbResourceImpl) DbResource(com.github.mgramin.sqlboot.model.resource.DbResource) DbResourceBodyWrapper(com.github.mgramin.sqlboot.model.resource.wrappers.DbResourceBodyWrapper)

Aggregations

DbResourceBodyWrapper (com.github.mgramin.sqlboot.model.resource.wrappers.DbResourceBodyWrapper)2 DbResource (com.github.mgramin.sqlboot.model.resource.DbResource)1 DbResourceImpl (com.github.mgramin.sqlboot.model.resource.impl.DbResourceImpl)1 JdbcSqlQuery (com.github.mgramin.sqlboot.sql.impl.JdbcSqlQuery)1 Entry (java.util.Map.Entry)1