public FkHolder(Injector injector, ForeignKey fk) { requireNonNull(fk); this.codeGenerationComponent = injector.getOrThrow(CodeGenerationComponent.class); this.fk = fk; this.fkc = fk.foreignKeyColumns().findFirst().orElseThrow(this::noEnabledForeignKeyException); this.column = fkc.findColumn().orElseThrow(this::couldNotFindLocalColumnException); this.table = ancestor(column, Table.class).orElseThrow(NoSuchElementException::new); this.foreignColumn = fkc.findForeignColumn().orElseThrow(this::foreignKeyWasNullException); this.foreignTable = fkc.findForeignTable().orElseThrow(this::foreignKeyWasNullException); }
/** * 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(ForeignKeyColumn first, ForeignKeyColumn second) { if (first.getId().equals(second.getId())) { final ForeignKey firstParent = first.getParentOrThrow(); final ForeignKey secondParent = second.getParentOrThrow(); return isSame(firstParent, secondParent); } else { return false; } }
ImmutableForeignKeyColumn(ImmutableForeignKey parent, Map<String, Object> fkc) { super(parent, requireKeys(fkc, ForeignKeyColumn.FOREIGN_COLUMN_NAME, ForeignKeyColumn.FOREIGN_TABLE_NAME)); final ForeignKeyColumn prototype = new ForeignKeyColumnImpl(parent, fkc); this.id = prototype.getId(); this.name = prototype.getName(); this.ordinalPosition = prototype.getOrdinalPosition(); this.foreignTableName = prototype.getForeignTableName(); this.foreignColumnName = prototype.getForeignColumnName(); this.foreignTable = LazyReference.create(); this.foreignColumn = LazyReference.create(); this.column = LazyReference.create(); }
private SpeedmentException foreignKeyWasNullException() { return new SpeedmentException( "Could not find referenced foreign column '" + fkc.getForeignColumnName() + "' in table '" + fkc.getForeignTableName() + "'." ); } }
final Type fkType = new TranslatorSupport<>(injector, fkc.findForeignTable().orElseThrow( () -> new SpeedmentException( "Could not find referenced foreign table '" + fkc.getForeignTableName() + "'." ))).entityType();
EntityTranslatorSupport.getForeignKey( translator.getSupport().tableOrThrow(), col ).map(fkc -> new FkHolder(injector, fkc.getParentOrThrow()));
/** * 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() ); }
@Override public Optional<ImmutableTable> findForeignTable() { return foreignTable.getOrCompute(() -> ForeignKeyColumn.super.findForeignTable() .map(ImmutableTable.class::cast) ); }
@Override public Optional<ImmutableColumn> findForeignColumn() { return foreignColumn.getOrCompute(() -> ForeignKeyColumn.super.findForeignColumn() .map(ImmutableColumn.class::cast) ); }
final ForeignKeyColumnMutator<?> fkcMutator = foreignKeyColumn.mutator(); final String fkColumnName = rs.getString("FKCOLUMN_NAME"); fkcMutator.setId(fkColumnName);
/** * 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() ); }
@Override public Optional<ImmutableColumn> findColumn() { return column.getOrCompute(() -> ForeignKeyColumn.super.findColumn() .map(ImmutableColumn.class::cast) ); }
final Type fkType = new TranslatorSupport<>(injector, fkc.findForeignTable().orElseThrow( () -> new SpeedmentException( "Could not find referenced foreign table '" + fkc.getForeignTableName() + "'." ))).entityType();
getSupport().tableOrThrow(), col ).ifPresent(fkc -> { final FkHolder fu = new FkHolder(injector, fkc.getParentOrThrow()); final TranslatorSupport<Table> fuSupport = fu.getForeignEmt().getSupport(); final FkHolder fu = new FkHolder(injector, fkc.getParentOrThrow()); final TranslatorSupport<Table> fuSupport = fu.getForeignEmt().getSupport();
private SpeedmentException foreignKeyWasNullException() { return new SpeedmentException( "Could not find referenced foreign column '" + fkc.getForeignColumnName() + "' in table '" + fkc.getForeignTableName() + "'." ); } }
public final ObjectBinding<TableProperty> foreignTableProperty() { return createObjectBinding( () -> ForeignKeyColumn.super.findForeignTable() .map(TableProperty.class::cast) .orElse(null), foreignTableNameProperty() ); }
public final ObjectBinding<ColumnProperty> foreignColumnProperty() { return createObjectBinding( () -> ForeignKeyColumn.super.findForeignColumn() .map(ColumnProperty.class::cast) .orElse(null), foreignTableNameProperty(), foreignColumnNameProperty() ); }
final ForeignKeyColumnMutator<?> fkcMutator = foreignKeyColumn.mutator(); final String fkColumnName = rs.getString("FKCOLUMN_NAME"); fkcMutator.setId(fkColumnName);