当前位置: 首页>>代码示例>>Java>>正文


Java ForeignKeyColumnReference类代码示例

本文整理汇总了Java中schemacrawler.schema.ForeignKeyColumnReference的典型用法代码示例。如果您正苦于以下问题:Java ForeignKeyColumnReference类的具体用法?Java ForeignKeyColumnReference怎么用?Java ForeignKeyColumnReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

ForeignKeyColumnReference类属于schemacrawler.schema包,在下文中一共展示了ForeignKeyColumnReference类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: findMismatchedForeignKeys

import schemacrawler.schema.ForeignKeyColumnReference; //导入依赖的package包/类
private void findMismatchedForeignKeys(final Table table){
    
    if (table != null && !(table instanceof View))
    {
        for (final ForeignKey foreignKey: table.getImportedForeignKeys())
        {
            for (final ForeignKeyColumnReference columnReference: foreignKey)
            {
                final Column pkColumn = columnReference.getPrimaryKeyColumn();
                final Column fkColumn = columnReference.getForeignKeyColumn();
                if (!pkColumn.getColumnDataType().getJavaSqlType().getJavaSqlTypeName().equals(fkColumn.getColumnDataType().getJavaSqlType().getJavaSqlTypeName())
                        || pkColumn.getSize() != fkColumn.getSize())
                {
                    addTableLint(table, "Foreign key data type ("+fkColumn.getColumnDataType().getJavaSqlType().getJavaSqlTypeName()+") "
                            + "does not match Primary key ("+pkColumn.getColumnDataType().getJavaSqlType().getJavaSqlTypeName()+").", foreignKey);
                    break;
                }
            }
        }
    }
}
 
开发者ID:mbarre,项目名称:schemacrawler-additional-lints,代码行数:22,代码来源:LinterForeignKeyMismatchLazy.java


示例2: matchesColumns

import schemacrawler.schema.ForeignKeyColumnReference; //导入依赖的package包/类
private static boolean matchesColumns(final String[] regexes, final ForeignKey foreignKey) {
    /*return foreignKey.getColumnReferences().stream()
            .map(ForeignKeyColumnReference::getForeignKeyColumn)
            .map(Column::getName)
            .anyMatch(name -> name.matches(regex));*/
    List<String> columnNames = foreignKey.getColumnReferences().stream()
            .map(ForeignKeyColumnReference::getForeignKeyColumn)
            .map(Column::getName)
            .collect(Collectors.toList());
    if (columnNames.size() != regexes.length) {
        return false;
    }
    final Stack<Integer> usedFields = new Stack<>();
    for (final String colName : columnNames) {
        boolean foundMatch = false;
        for (int i = 0; i < regexes.length; i++) {
            if (!usedFields.contains(i)) {
                foundMatch = colName.matches(regexes[i]);
                if (foundMatch) {
                    usedFields.push(i);
                    break;
                }
            }
        }
        if (!foundMatch) {
            return false;
        }
    }
    return true;

}
 
开发者ID:btc-ag,项目名称:redg,代码行数:32,代码来源:JsonFileExplicitAttributeDecider.java


示例3: getMethodNameForReference

import schemacrawler.schema.ForeignKeyColumnReference; //导入依赖的package包/类
@Override
public String getMethodNameForReference(final ForeignKey foreignKey) {
    ForeignKeyColumnReference firstForeignKeyColumnReferences = foreignKey.getColumnReferences().get(0);
    final String tableName = firstForeignKeyColumnReferences.getForeignKeyColumn().getParent().getName();
    if (mappings.containsKey(tableName)) {
        if (mappings.get(tableName).getColumns() != null &&
                mappings.get(tableName).getColumns().containsKey(foreignKey.getName())) {
            return mappings.get(tableName).getColumns().get(foreignKey.getName());
        }
    }
    return null;
}
 
开发者ID:btc-ag,项目名称:redg,代码行数:13,代码来源:JsonFileNameProvider.java


示例4: getCanonicalDataTypeName

import schemacrawler.schema.ForeignKeyColumnReference; //导入依赖的package包/类
@Override
public String getCanonicalDataTypeName(schemacrawler.schema.Column column) {
	SingularAttribute singularAttribute;
	if (column.isPartOfForeignKey()) {
		Optional<ForeignKeyColumnReference> foreignKeyColumnReferenceOptional = column.getParent().getForeignKeys().stream()
				.flatMap(foreignKeyColumnReferences -> foreignKeyColumnReferences.getColumnReferences().stream())
				.filter(foreignKeyColumnReference -> foreignKeyColumnReference.getForeignKeyColumn().getName().equals(column.getName()))
				.findFirst();

		if (foreignKeyColumnReferenceOptional.isPresent()) {
			ForeignKeyColumnReference ref = foreignKeyColumnReferenceOptional.get();
			SingularAttribute targetSingularAttribute =
					singularAttributesByColumnName.get(new QualifiedColumnName(ref.getPrimaryKeyColumn().getParent().getName(), ref.getPrimaryKeyColumn().getName()));
			if (targetSingularAttribute != null) {
				return targetSingularAttribute.getJavaType().getCanonicalName();
			} else {
				LOG.warn("Could not find target singular attribute for column " + column.getParent().getName() + "." + column.getName());
				return fallbackDataTypeProvider.getCanonicalDataTypeName(column);
			}
		} else {
			return fallbackDataTypeProvider.getCanonicalDataTypeName(column);
		}
	} else {
		singularAttribute =
				singularAttributesByColumnName.get(new QualifiedColumnName(column.getParent().getName(), column.getName()));
		if (singularAttribute != null) {
			return singularAttribute.getJavaType().getCanonicalName();
		} else {
			return fallbackDataTypeProvider.getCanonicalDataTypeName(column);
		}
	}
}
 
开发者ID:btc-ag,项目名称:redg,代码行数:33,代码来源:JpaMetamodelRedGProvider.java


示例5: attachColumnsToFk

import schemacrawler.schema.ForeignKeyColumnReference; //导入依赖的package包/类
public void attachColumnsToFk(final Catalog catalog) {
    try (Transaction tx = getDbService().beginTx()) {
        // get all columns
        for (final Schema schema : catalog.getSchemas()) {
            for (final Table table : catalog.getTables(schema)) {
                for (final ForeignKey fk : table.getImportedForeignKeys()) {
                    //fk.
                    //get the node of the fk
                    dbService.findNode(DatabaseNodeType.FOREIGN_KEY, "fullName", fk.getFullName());
                    // get the node of the table
                    dbService.findNode(DatabaseNodeType.TABLE, "fullName", table.getFullName());
                    // attach FK to table
                    Relationship fkBelongsToTable = dbService.findNode(DatabaseNodeType.FOREIGN_KEY, "fullName", fk.getFullName()).createRelationshipTo(dbService.findNode(DatabaseNodeType.TABLE, "fullName", table.getFullName()), SchemaRelationShips.BELONGS_TO_TABLE);
                    // fetch the columns of the fk
                    for (final ForeignKeyColumnReference fkColRef : fk.getColumnReferences()) {
                        // get the node of the column
                        dbService.findNode(DatabaseNodeType.TABLE_COLUMN, "fullName", fkColRef.getForeignKeyColumn().getFullName());
                        // attach column to fk
                        Relationship rel = dbService.findNode(DatabaseNodeType.TABLE_COLUMN, "fullName", fkColRef.getForeignKeyColumn().getFullName()).createRelationshipTo(dbService.findNode(DatabaseNodeType.FOREIGN_KEY, "fullName", fk.getFullName()), SchemaRelationShips.IS_COLUMN_OF_FK);
                    }

                    //dbService.findNodes(DatabaseNodeType.TABLE_COLUMN, "fullName", fk.)
                }
            }
        }
        tx.success();
    }
}
 
开发者ID:adriens,项目名称:schemacrawler-plugin-neo4j,代码行数:29,代码来源:AdditionalExecutable.java


示例6: DaColumnReferenceImpl

import schemacrawler.schema.ForeignKeyColumnReference; //导入依赖的package包/类
public DaColumnReferenceImpl(ForeignKeyColumnReference fkColumnReference, SchemaStrategy schemaStrategy) {
    this.fkColumnReference = Validate.notNull(fkColumnReference);
    this.schemaStrategy = Validate.notNull(schemaStrategy);
}
 
开发者ID:goldmansachs,项目名称:obevo,代码行数:5,代码来源:DaColumnReferenceImpl.java


示例7: secondPass

import schemacrawler.schema.ForeignKeyColumnReference; //导入依赖的package包/类
/**
 * process the foreign key relations and constraints.
 */
private void secondPass(Catalog catalog) {
    for (Schema schema: catalog.getSchemas()) {
        System.out.println(schema);
        for (Table table: catalog.getTables(schema)) {
            for (ForeignKey fk: table.getForeignKeys()) {
                for (ForeignKeyColumnReference fkRef: fk.getColumnReferences()) {
                    Column fkCol = fkRef.getForeignKeyColumn();
                    Column pkCol = fkRef.getPrimaryKeyColumn();
                    Table pkTable = pkCol.getParent();

                    EntitySpec pkEspec = entitySpecs.get(pkTable);
                    EntitySpec fkEspec = entitySpecs.get(fkCol.getParent());
                    NodeSpec fkNSpec = nodeSpecs.get(fkCol);

                    if (!processedFks.add(new ProcessedFk(fkNSpec, pkEspec))) {
                        continue;
                    }

                    /*
                     *  Do the N:1 natual foreign key relation *
                     */
                    fkNSpec.setName( genRealtionNodeName(pkEspec) );
                    RelationSpec rspec = new RelationSpec();
                    rspec.setEntitySpec(pkEspec);
                    rspec.setJoinType(JoinTypeSpec.LEFT_OUTER_JOIN);
                    rspec.setType(RelationType.REFERS);
                    fkNSpec.setRelation(rspec);

                    LOG.debug("Added FK relation from {}.{} to {}", fkEspec.getClassName(), fkNSpec.getName(), pkEspec.getClassName());

                    createForeignKeyConstraint(fkEspec, fkNSpec, rspec);

                    /*
                     * do the opposite 1:N relation
                     */
                    //create the nodespec as there is no dbcolumn whch created a node for us
                    LOG.debug("Creating tomany node for N relation from {} to {}", pkEspec.getClassName(), fkEspec.getClassName());
                    NodeSpec toManyNodeSpec = new NodeSpec();
                    String nodeName = genRealtionNodeName(fkEspec);
                    while (pkEspec.getNodeSpec(nodeName) != null) {
                        nodeName = incrementNodeName(nodeName);
                    }
                    toManyNodeSpec.setName( nodeName );
                    toManyNodeSpec.setEntity(pkEspec);

                    rspec = new RelationSpec();
                    rspec.setBackReference(fkNSpec);
                    rspec.setEntitySpec(fkEspec);
                    rspec.setJoinType(JoinTypeSpec.LEFT_OUTER_JOIN);
                    rspec.setType(RelationType.REFERS);
                    toManyNodeSpec.setRelation(rspec);
                    pkEspec.add(toManyNodeSpec);
                }
            }
        }
    }
}
 
开发者ID:scottysinclair,项目名称:barleydb,代码行数:61,代码来源:FromDatabaseSchemaToSpecification.java


示例8: isExplicitForeignKey

import schemacrawler.schema.ForeignKeyColumnReference; //导入依赖的package包/类
@Test
public void isExplicitForeignKey() throws Exception {
    JsonFileExplicitAttributeDecider decider =
            new JsonFileExplicitAttributeDecider(new InputStreamReader(getClass().getResourceAsStream("JsonFileExplicitAttributeDeciderTest.json")));
    Table tableMock = Mockito.mock(Table.class);
    Mockito.when(tableMock.getName()).thenReturn("TABLENAME");

    ForeignKey fk1Mock = Mockito.mock(ForeignKey.class);

    ForeignKeyColumnReference fkcr1Mock = Mockito.mock(ForeignKeyColumnReference.class);

    Column c1Mock = Mockito.mock(Column.class);
    Mockito.when(c1Mock.getName()).thenReturn("NOPE");
    Mockito.when(c1Mock.getParent()).thenReturn(tableMock);

    Mockito.when(fkcr1Mock.getForeignKeyColumn()).thenReturn(c1Mock);

    Mockito.when(fk1Mock.getColumnReferences()).thenReturn(Collections.singletonList(fkcr1Mock));

    assertFalse(decider.isExplicitForeignKey(fk1Mock));

    ForeignKey fk2Mock = Mockito.mock(ForeignKey.class);

    ForeignKeyColumnReference fkcr2Mock = Mockito.mock(ForeignKeyColumnReference.class);

    Column c2Mock = Mockito.mock(Column.class);
    Mockito.when(c2Mock.getName()).thenReturn("FOREIGNKEY1");
    Mockito.when(c2Mock.getParent()).thenReturn(tableMock);

    Mockito.when(fkcr2Mock.getForeignKeyColumn()).thenReturn(c2Mock);

    ForeignKeyColumnReference fkcr3Mock = Mockito.mock(ForeignKeyColumnReference.class);

    Column c3Mock = Mockito.mock(Column.class);
    Mockito.when(c3Mock.getName()).thenReturn("PART2");
    Mockito.when(c3Mock.getParent()).thenReturn(tableMock);

    Mockito.when(fkcr3Mock.getForeignKeyColumn()).thenReturn(c3Mock);

    Mockito.when(fk2Mock.getColumnReferences()).thenReturn(Arrays.asList(fkcr2Mock, fkcr3Mock));

    assertTrue(decider.isExplicitForeignKey(fk2Mock));
}
 
开发者ID:btc-ag,项目名称:redg,代码行数:44,代码来源:JsonFileExplicitAttributeDeciderTest.java



注:本文中的schemacrawler.schema.ForeignKeyColumnReference类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。