private boolean hasTypeMapper(Column col, Class<?> typeMapperClass) { return col.getTypeMapper() .filter(typeMapperClass.getName()::equals) .isPresent(); }
/** * 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); } }); }); }); }); }
/** * 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); }); }); }); }); }
final boolean isCustomTypeMapper = c.getTypeMapper().isPresent() && !TypeMapper.identity().getClass().isAssignableFrom(typeMapperClass) && !TypeMapper.primitive().getClass().isAssignableFrom(typeMapperClass);
ImmutableColumn(ImmutableTable parent, Map<String, Object> data) { super(parent, data); final Column prototype = new ColumnImpl(parent, data); this.enabled = prototype.isEnabled(); this.id = prototype.getId(); this.name = prototype.getName(); this.alias = prototype.getAlias(); this.nullable = prototype.isNullable(); this.nullableImplementation = prototype.getNullableImplementation(); this.autoincrement = prototype.isAutoIncrement(); this.typeMapper = prototype.getTypeMapper(); this.databaseType = prototype.getDatabaseType(); this.databaseTypeObject = prototype.findDatabaseType(); this.enumConstants = prototype.getEnumConstants(); this.decimalDigits = prototype.getDecimalDigits(); this.columnSize = prototype.getColumnSize(); this.ordinalPosition = prototype.getOrdinalPosition(); }
.filter(c -> c.getTypeMapper() .filter(tm -> !"".equals(tm)) .filter(tm -> !tm.equals(TypeMapper.identity().getClass().getName()))
.filter(col -> col.getTypeMapper() .filter(ENUM_TYPE_MAPPERS::contains) .isPresent() throw new UnsupportedOperationException(format( "Unknown enum type mapper '%s' in column '%s'.", col.getTypeMapper().orElse(null), col ));
if (col.getTypeMapper().isPresent()) { final String typeMapper = col.getTypeMapper().get();
final boolean isCustomTypeMapper = c.getTypeMapper().isPresent() && !TypeMapper.identity().getClass().isAssignableFrom(typeMapperClass) && !TypeMapper.primitive().getClass().isAssignableFrom(typeMapperClass);
.filter(c -> c.getTypeMapper() .filter(tm -> !"".equals(tm)) .filter(tm -> !tm.equals(TypeMapper.identity().getClass().getName()))
if (col.getTypeMapper().isPresent()) { final String typeMapper = col.getTypeMapper().get();