private String sqlColumnList(Predicate<Column> preFilter, Function<String, String> postMapper) { return table.columns() .sorted(comparing(Column::getOrdinalPosition)) .filter(Column::isEnabled) .filter(preFilter) .map(Column::getName) .map(naming::encloseField) .map(postMapper) .collect(joining(",")); }
private String sqlColumnList(Predicate<Column> preFilter, Function<String, String> postMapper) { return table.columns() .sorted(comparing(Column::getOrdinalPosition)) .filter(Column::isEnabled) .filter(preFilter) .map(Column::getName) .map(naming::encloseField) .map(postMapper) .collect(joining(",")); }
/** * Locate the {@link Column} child with the specified id if it exists, else * return an empty {@code Optional}. * * @param id the {@link HasId#getId()} of the column * @return the child found or an empty {@code Optional} */ default Optional<? extends Column> findColumn(String id) { return columns().filter(child -> child.getId().equals(id)).findAny(); }
public static Optional<? extends Column> referencedColumnIfPresent(Project project, String dbmsId, String schemaId, String tableId, String columnId) { return referencedTableIfPresent(project, dbmsId, schemaId, tableId) .flatMap(table -> table.columns().filter(column -> columnId.equals(column.getId())) .findAny() ); }
public static Stream<? extends Document> typedChildrenOf(Table table) { return Stream.of( table.columns().map(Document.class::cast), table.primaryKeyColumns().map(Document.class::cast), table.indexes().map(Document.class::cast), table.foreignKeys().map(Document.class::cast) ).flatMap(Function.identity()); }
/** * Returns a {@code AND} separated list of {@link PrimaryKeyColumn} database * names, formatted in accordance to the current {@link DbmsType}. * * @param naming the current naming convention * @param table the table to get columns from * @param postMapper mapper to be applied to each column name * @return list of fully quoted primary key column names */ public static String sqlColumnList(DatabaseNamingConvention naming, Table table, Function<String, String> postMapper) { requireNonNulls(naming, table, postMapper); return table.columns() .filter(Column::isEnabled) .map(Column::getName) .map(naming::encloseField) .map(postMapper) .collect(joining(",")); }
/** * Locates and returns the column referenced by the {@link #getId()} * method. * * @return the referenced column */ default Optional<? extends Column> findColumn() { return ancestors() .filter(Table.class::isInstance) .map(Table.class::cast) .findFirst() .flatMap(table -> table .columns() .filter(col -> col.getId().equals(getId())) .findAny() ); }
public static Stream<? extends Document> traverseOver(Table table) { return Stream.of( table.columns(), table.columns().flatMap(DocumentDbUtil::traverseOver), table.primaryKeyColumns(), table.primaryKeyColumns().flatMap(DocumentDbUtil::traverseOver), table.indexes(), table.indexes().flatMap(DocumentDbUtil::traverseOver), table.foreignKeys(), table.foreignKeys().flatMap(DocumentDbUtil::traverseOver) ).flatMap(Function.identity()); }
/** * A helper method for accessing the foreign {@link Column} referenced by * this key. * * @return the foreign {@link Column} referenced by this */ default Optional<? extends Column> findForeignColumn() { return findForeignTable() .flatMap(table -> table.columns() .filter(col -> col.getId().equals(getForeignColumnName())) .findAny() ); }
private static int findNullOffset( final Table table, final Stage<?> stage, final HasComparableOperators<?, ?> field ) { int result = -1; final String onColumnId = field .identifier() .getColumnId(); final List<Column> columns = table.columns() .filter(Column::isEnabled) .collect(toList()); for (int j = 0; j < columns.size(); j++) { final String columnId = columns.get(j).getId(); if (columnId.equals(onColumnId)) { // Compose a null detecting entity mapper result = j; break; } } if (result == -1) { throw new IllegalStateException( "Unable to locate column " + onColumnId + " in table " + table.getId() + " for stage " + stage.toString() + " Columns: " + columns.stream().map(Column::getId).collect(joining(", ")) ); } return result; }
/** * 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); } }); }); }); }); }
public static <T> Stream<T> traverseOver(Table table, Class<T> clazz) { if (Column.class.isAssignableFrom(clazz)) { return table.columns().map(clazz::cast); } else if (PrimaryKeyColumn.class.isAssignableFrom(clazz)) { return table.primaryKeyColumns().map(clazz::cast); } else if (Index.class.isAssignableFrom(clazz)) { return table.indexes().map(clazz::cast); } else if (ForeignKey.class.isAssignableFrom(clazz)) { return table.foreignKeys().map(clazz::cast); } else { final Stream.Builder<T> sb = Stream.builder(); table.columns().flatMap(c -> traverseOver(c, clazz)).forEachOrdered(sb::accept); table.primaryKeyColumns().flatMap(c -> traverseOver(c, clazz)).forEachOrdered(sb::accept); table.indexes().flatMap(c -> traverseOver(c, clazz)).forEachOrdered(sb::accept); table.foreignKeys().flatMap(c -> traverseOver(c, clazz)).forEachOrdered(sb::accept); return sb.build(); } }
/** * 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); }); }); }); }); }
SqlStage( final SqlInfo info, final Stage<?> stage, final int stageIndex ) { requireNonNull(info); this.stage = requireNonNull(stage); this.stageIndex = requireNonNegative(stageIndex); this.table = DocumentDbUtil.referencedTable(info.project(), stage.identifier()); final String tableAlias = JoinSqlUtil.tableAlias(stageIndex); this.sqlColumnList = table.columns() .filter(Column::isEnabled) .map(Column::getName) .map(n -> tableAlias + "." + info.namingConvention().encloseField(n)) .collect(joining(",")); this.sqlTableReference = info.namingConvention().fullNameOf(table) + (DbmsType.SubSelectAlias.PROHIBITED.equals(info.dbmsType().getSubSelectAlias()) ? " " : " AS ") + tableAlias; }
final String sqlColumnList = table.columns() .filter(Column::isEnabled) .map(Column::getName)
final Stage<?> otherStage = stages.get(i); final Table table = DocumentDbUtil.referencedTable(project, otherStage.identifier()); offset += table.columns() .filter(Column::isEnabled) .count();
if (table.columns() .filter(col -> col.getAsString(ORIGINAL_TYPE).filter("INTEGER"::equalsIgnoreCase).isPresent()) .noneMatch(col -> table.primaryKeyColumns().anyMatch(pkc -> DocumentDbUtil.isSame(pkc.findColumn().get(), col))) && table.columns().map(Column::getId).noneMatch("rowid"::equalsIgnoreCase)) { final Column column = table.mutator().addNewColumn(); pkc.mutator().setOrdinalPosition(1); } else { table.columns() .filter(col -> col.getAsString(ORIGINAL_TYPE).filter("INTEGER"::equalsIgnoreCase).isPresent()) .filter(col -> table.primaryKeyColumns().anyMatch(pkc -> DocumentDbUtil.isSame(pkc.findColumn().get(), col))) table.columns().forEach(col -> { col.getData().remove(ORIGINAL_TYPE); });
getSupport().entityType()) )).set(Value.ofReference("unmodifiableList(asList(" + nl() + indent( table.columns() .sorted(comparing(Column::getOrdinalPosition)) .filter(HasEnabled::isEnabled)
table.columns() .filter(HasEnabled::test) .filter(c -> c.getTypeMapper()
file.getImports().removeIf(i -> i.getType().equals(IntegerToEnumTypeMapper.class)); table.columns() .filter(HasEnabled::test) .filter(col -> col.getTypeMapper()