ImmutableSchema(ImmutableDbms parent, Map<String, Object> schema) { super(parent, schema); final Schema prototype = new SchemaImpl(parent, schema); this.enabled = prototype.isEnabled(); this.id = prototype.getId(); this.name = prototype.getName(); this.alias = prototype.getAlias(); this.defaultSchema = prototype.isDefaultSchema(); this.tables = unmodifiableList(super.children(TABLES, ImmutableTable::new).collect(toList())); }
/** * Returns {@code true} if the two specified documents represents the same * element in the database. Two documents are considered same if they have * the same name and type and their parents are considered same. * * @param first the first document * @param second the second document * @return {@code true} if same, else {@code false} */ public static boolean isSame(Schema first, Schema second) { if (first.getId().equals(second.getId())) { final Dbms firstParent = first.getParentOrThrow(); final Dbms secondParent = second.getParentOrThrow(); return isSame(firstParent, secondParent); } else { return false; } }
.orElseThrow(() -> new IllegalArgumentException( "Could not find dbms: '" + dbmsId + "'.")) .schemas().filter(s -> schemaId.equals(s.getId())).findAny() .orElseThrow(() -> new IllegalArgumentException( "Could not find schema: '" + schemaId + "'.")) .tables().filter(t -> tableId.equals(t.getId())).findAny() .orElseThrow(() -> new IllegalArgumentException( "Could not find table: '" + tableId + "'."));
@Override public BUILDER withSchema(String schemaName) { requireNonNull(schemaName); with(Schema.class, s -> { // This makes sure that old json files with no id // first sets it id before the name is changed // Todo: Remove in next major API bumnp s.mutator().setId(s.getId()); s.mutator().setName(schemaName); }); return self(); }
/** * Returns the catalog lookup name used when calling * connection.getMetaData().getXxxx(catalogLookupName, ...) methods. * * @param schema to use * @return the catalog lookup name used when calling * connection.getMetaData().getXxxx(catalogLookupName, ...) methods */ protected String jdbcCatalogLookupName(Schema schema) { return schema.getId(); }
final Dbms dbms = schema.getParentOrThrow(); final Table table = schema.mutator().addNewTable(); final String tableName = rsTable.getString("TABLE_NAME"); final String tableType = rsTable.getString("TABLE_TYPE"); 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));
private String readFromResultSet(File file, Column c, AtomicInteger position) { final Dbms dbms = c.getParentOrThrow().getParentOrThrow().getParentOrThrow(); dbmsTypeOf(dbmsHandlerComponent, c.getParentOrThrow().getParentOrThrow().getParentOrThrow()), c.findDatabaseType() );
final Table table = schema.mutator().addNewTable(); final String tableName = rsTable.getString("TABLE_NAME"); final String tableType = rsTable.getString("TABLE_TYPE"); final double noTables = schema.tables().count(); schema.tables().map(table -> sqlTypeMapping.thenAcceptAsync(mapping -> { try (final Connection connection = getConnection(dbms)) { progressListener.setCurrentAction(actionName(table));
/** * 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); }); }); }); }); }
/** * Returns the full name used in the database for the specified * {@link Table}. This is typically constructed by combining the schema and * the table name with a separator, but that might be different in different * implementations. * * @param table the table to retrieve the name of * @return the full name */ default String fullNameOf(Table table) { final Schema schema = table.getParentOrThrow(); return fullNameOf(schema.getName(), table.getName()); }
private CompletableFuture<Project> readSchemaMetadata( Project project, Dbms dbms, ProgressMeasure progress) { //final DbmsType dbmsType = dbmsTypeOf(dbmsHandlerComponent, dbms); progress.setCurrentAction(describe(dbms)); LOGGER.info(describe(dbms)); final CompletableFuture<Map<String, Class<?>>> typeMappingTask = typeMappingHelper.loadFor(dbms); final Schema schema = dbms.mutator().addNewSchema(); schema.mutator().setId("schema"); schema.mutator().setName("schema"); return readTableMetadata(schema, typeMappingTask, progress) .thenApplyAsync($ -> project); }
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() ); }
@Override public BUILDER withSchema(String oldSchemaName, String schemaName) { requireNonNulls(oldSchemaName, schemaName); with(Schema.class, oldSchemaName, s -> { // This makes sure that old json files with no id // first sets it id before the name is changed // Todo: Remove in next major API bumnp s.mutator().setId(s.getId()); s.mutator().setName(schemaName); }); return self(); }
final Dbms dbms = schema.getParentOrThrow(); final Table table = schema.mutator().addNewTable(); final String tableName = rsTable.getString("TABLE_NAME"); final String tableType = rsTable.getString("TABLE_TYPE"); 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));
fkcMutator.setForeignDatabaseName(schema.getParentOrThrow().getId()); fkcMutator.setForeignSchemaName("schema"); };
final Table table = schema.mutator().addNewTable(); final String tableName = rsTable.getString("TABLE_NAME"); final String tableType = rsTable.getString("TABLE_TYPE"); final double noTables = schema.tables().count(); schema.tables().map(table -> sqlTypeMapping.thenAcceptAsync(mapping -> { try (final Connection connection = getConnection(dbms)) { progressListener.setCurrentAction(actionName(table));
/** * Returns the full name used in the database for the specified * {@link Column}. This is typically constructed by combining the table and * the column name with a separator, but that might be different in * different implementations. * * @param column the column to retrieve the name of * @return the full name */ default String fullNameOf(Column column) { final Table table = column.getParentOrThrow(); final Schema schema = table.getParentOrThrow(); return fullNameOf(schema.getName(), table.getName(), column.getName()); }