public static Optional<? extends Table> referencedTableIfPresent(Project project, String dbmsId, String schemaId, String tableId) { return referencedSchemaIfPresent(project, dbmsId, schemaId) .flatMap(schema -> schema.tables().filter(table -> tableId.equals(table.getId())) .findAny() ); }
public static Table referencedTable(Project project, String dbmsId, String schemaId, String tableId) { return referencedSchema(project, dbmsId, schemaId) .tables().filter(table -> tableId.equals(table.getId())) .findAny().orElseThrow(() -> new SpeedmentConfigException( "Could not find referenced " + Table.class.getSimpleName() + " with name '" + tableId + "'." )); }
/** * A helper method for accessing the foreign {@link Table} referenced by * this key. * * @return the foreign {@link Table} referenced by this */ default Optional<? extends Table> findForeignTable() { final Optional<Schema> schema = ancestors() .filter(Schema.class::isInstance) .map(Schema.class::cast) .findFirst(); return schema.flatMap(s -> s.tables() .filter(tab -> tab.getId().equals(getForeignTableName())) .findAny() ); }
/** * Set any compatible type mappers in Project <code>{@code to}</code> found in Project <code>{@code from}</code>. ** * @param to the project to mutate * @param from the project defining the type mappers */ private void setTypeMappersFrom(Project to, Project from) { from.dbmses().map(d -> (Dbms) d).forEach(dbms -> { dbms.schemas().map(s -> (Schema) s).forEach(schema -> { schema.tables().map(t -> (Table) t).forEach(table -> { table.columns().map(c -> (Column) c).filter(c -> c.getTypeMapper().isPresent()).forEach(column -> { String mapperName = column.getTypeMapper().get(); try { //noinspection unchecked @SuppressWarnings("unchecked") Class<? extends TypeMapper<?, ?>> mapperClass = (Class<? extends TypeMapper<?, ?>>)Class.forName(mapperName); setTypeMapper(to, dbms, schema, table, column, mapperClass); } catch (ClassNotFoundException | ClassCastException e) { throw new IllegalStateException("Unable to find mapper class " + mapperName); } }); }); }); }); }
.orElseThrow(() -> new IllegalArgumentException( "Could not find schema: '" + schemaId + "'.")) .tables().filter(t -> tableId.equals(t.getId())).findAny() .orElseThrow(() -> new IllegalArgumentException( "Could not find table: '" + tableId + "'."));
/** * Debug method used to track type mappers of a project. May be of future use if one perhaps would venture to * investigate why we get several copies of the dbms from the database */ private void printTypeMappers(String heading, Project p) { System.out.println(heading); p.dbmses().map(d -> (Dbms) d).forEach(dbms -> { dbms.schemas().map(s -> (Schema) s).forEach(schema -> { schema.tables().map(t -> (Table) t).forEach(table -> { table.columns().map(c -> (Column) c).filter(c -> c.getTypeMapper().isPresent()).forEach(column -> { String mapperName = column.getTypeMapper().get(); if (mapperName.endsWith("PrimitiveTypeMapper")) { mapperName = "Primitive"; } System.out.println(" - " + dbms.getName() + ":" + schema.getName() + "/" + table.getName() + "." + column.getName() + " mapped by " + mapperName); }); }); }); }); }
LOGGER.info("schema: " + schema.getName()); if (schema.getData().containsKey("tables")) { LOGGER.info("Removing " + schema.tables().count()); schema.getData().remove("tables"); } else {
final Dbms dbms = schema.getParentOrThrow(); final AtomicInteger cnt = new AtomicInteger(); final double noTables = schema.tables().count(); schema.tables().map(table -> CompletableFuture.runAsync(() -> { try (final Connection conn = connectionPool.getConnection(dbms)) { progress.setCurrentAction(describe(table));
final Dbms dbms = schema.getParentOrThrow(); final AtomicInteger cnt = new AtomicInteger(); final double noTables = schema.tables().count(); schema.tables().map(table -> CompletableFuture.runAsync(() -> { try (final Connection conn = connectionPool.getConnection(dbms)) { progress.setCurrentAction(describe(table));