use of com.github.mgramin.sqlboot.model.uri.impl.DbUri in project sql-boot by sql-boot.
the class ViewJdbcResourceType method read.
@Override
public Stream<DbResource> read(final Uri uri) throws BootException {
try {
final List<DbResource> result = new ArrayList<>();
final ResultSet tables = dataSource.getConnection().getMetaData().getTables(null, uri.path(0), uri.path(1), new String[] { "VIEW" });
final ResultSetMetaData tableMetaData = tables.getMetaData();
final int columnsCount = tableMetaData.getColumnCount();
while (tables.next()) {
final String tableSchem = columnsCount >= 2 ? tables.getString(2) : null;
final String tableName = columnsCount >= 3 ? tables.getString(3) : null;
final Map<String, Object> props = new LinkedHashMap<>();
props.put("TABLE_CAT", columnsCount >= 1 ? tables.getString(1) : null);
props.put("TABLE_SCHEM", columnsCount >= 2 ? tables.getString(2) : null);
props.put("TABLE_NAME", columnsCount >= 3 ? tables.getString(3) : null);
props.put("TABLE_TYPE", columnsCount >= 4 ? tables.getString(4) : null);
props.put("REMARKS", columnsCount >= 5 ? tables.getString(5) : null);
props.put("TYPE_CAT", columnsCount >= 6 ? tables.getString(6) : null);
props.put("TYPE_SCHEM", columnsCount >= 7 ? tables.getString(7) : null);
props.put("TYPE_NAME", columnsCount >= 8 ? tables.getString(8) : null);
props.put("SELF_REFERENCING_COL_NAME", columnsCount >= 9 ? tables.getString(9) : null);
props.put("REF_GENERATION", columnsCount >= 10 ? tables.getString(10) : null);
result.add(new DbResourceImpl(tableName, this, new DbUri(name(), asList(tableSchem, tableName)), props));
}
return result.stream();
} catch (SQLException e) {
throw new BootException(e);
}
}
use of com.github.mgramin.sqlboot.model.uri.impl.DbUri in project sql-boot by sql-boot.
the class SqlResourceType method read.
@Override
public Stream<DbResource> read(final Uri uri) throws BootException {
final Map<String, Object> variables = new HashMap<>();
variables.put("uri", uri);
return sqlQuery.select(variables).map(o -> {
final List<Object> path = o.entrySet().stream().filter(v -> (v.getKey().startsWith("@") || v.getKey().startsWith("_"))).map(Entry::getValue).collect(toList());
final String name = path.get(path.size() - 1).toString();
final Map<String, Object> headers = o.entrySet().stream().collect(toMap(k -> strip(strip(k.getKey(), "@"), "_"), v -> ofNullable(v.getValue()).orElse(""), (a, b) -> a, LinkedHashMap::new));
return new DbResourceImpl(name, this, new DbUri(this.name(), path.stream().map(Object::toString).collect(toList())), headers);
});
}
use of com.github.mgramin.sqlboot.model.uri.impl.DbUri in project sql-boot by sql-boot.
the class FunctionJdbcResourceTypeTest method read.
@Test
@Ignore
public void read() {
final ResourceType function = new FunctionJdbcResourceType(dataSource);
final Stream<DbResource> functions = function.read(new SqlPlaceholdersWrapper(new DbUri("function", asList("*"))));
assertEquals(1, functions.count());
}
use of com.github.mgramin.sqlboot.model.uri.impl.DbUri in project sql-boot by sql-boot.
the class ProcedureJdbcResourceTypeTest method read.
@Test
public void read() {
final ResourceType procedure = new ProcedureJdbcResourceType(dataSource);
final Stream<DbResource> procedures = procedure.read(new SqlPlaceholdersWrapper(new DbUri("procedure", asList("*"))));
assertEquals(1, procedures.count());
}
use of com.github.mgramin.sqlboot.model.uri.impl.DbUri in project sql-boot by sql-boot.
the class TableJdbcResourceTypeTest method read.
@Test
public void read() {
final ResourceType table = new TableJdbcResourceType(dataSource);
final Stream<DbResource> tables = table.read(new SqlPlaceholdersWrapper(new DbUri("table", asList("*"))));
assertEquals(2, tables.count());
}
Aggregations