public static Optional<? extends Schema> referencedSchemaIfPresent(Project project, String dbmsId, String schemaId) { return referencedDbmsIfPresent(project, dbmsId) .flatMap(dbms -> dbms.schemas().filter(schema -> schemaId.equals(schema.getId())) .findAny() ); }
public static Schema referencedSchema(Project project, String dbmsId, String schemaId) { return referencedDbms(project, dbmsId) .schemas().filter(schema -> schemaId.equals(schema.getId())) .findAny().orElseThrow(() -> new SpeedmentConfigException( "Could not find referenced " + Schema.class.getSimpleName() + " with name '" + schemaId + "'." )); }
/** * 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 dbms: '" + dbmsId + "'.")) .schemas().filter(s -> schemaId.equals(s.getId())).findAny() .orElseThrow(() -> new IllegalArgumentException( "Could not find schema: '" + schemaId + "'."))
/** * 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); }); }); }); }); }
project.dbmses().forEach(dbms -> { LOGGER.info("dbms: " + dbms.getName()); dbms.schemas().forEach(schema -> { LOGGER.info("schema: " + schema.getName()); if (schema.getData().containsKey("tables")) {
@SuppressWarnings({"unchecked", "rawtypes"}) final CompletableFuture<Schema>[] tablesTask = dbms.schemas() .map(schema -> tables(sqlTypeMappingTask, dbms, schema, progress)) .toArray(s -> (CompletableFuture<Schema>[]) new CompletableFuture[s]);
@SuppressWarnings({"unchecked", "rawtypes"}) final CompletableFuture<Schema>[] tablesTask = dbms.schemas() .map(schema -> tables(sqlTypeMappingTask, dbms, schema, progress)) .toArray(s -> (CompletableFuture<Schema>[]) new CompletableFuture[s]);