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


Java ForeignKeyElement类代码示例

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


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

示例1: getTablesReferencesOtherTablesWithPrimaryKeyMatch

import org.netbeans.modules.dbschema.ForeignKeyElement; //导入依赖的package包/类
/**
 *
 * @param schemaElement The schema
 * @return A set of tables that reference another tables with primary key to promary key reference
 */
public static Set<String> getTablesReferencesOtherTablesWithPrimaryKeyMatch(SchemaElement schemaElement) {
    Set<String> tableNames = new HashSet<String>();
    TableElement[] allTables = schemaElement.getTables();
    for(int i = 0; i < allTables.length; i ++ ) {
        TableElement table0 = allTables[i];
        UniqueKeyElement pk0 = table0.getPrimaryKey();
        if(pk0 != null){//it may be join table or other without pk
            ForeignKeyElement[] fkElements = table0.getForeignKeys();
            for(int fkix = 0; fkix < fkElements.length; fkix ++ ) {
                ForeignKeyElement fk = fkElements[fkix];
                TableElement table = fk.getReferencedTable();
                UniqueKeyElement pk = table.getPrimaryKey();
                //at first step support 1-1 keys (no composite yet).
                if(pk != null && 1 == pk0.getColumns().length && fk.getLocalColumns().length == 1 && pk.getColumns().length==1){
                    if(fk.getLocalColumns()[0].equals(pk0.getColumns()[0])){
                        tableNames.add(table0.getName().getName());
                        continue;
                    }
                }
            }
        }
    }

    return tableNames;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:DbSchemaEjbGenerator.java

示例2: removeDuplicateFK

import org.netbeans.modules.dbschema.ForeignKeyElement; //导入依赖的package包/类
private ForeignKeyElement[] removeDuplicateFK(ForeignKeyElement[] fkeys) {
    if(fkeys==null || fkeys.length==0) return fkeys;
    HashMap<ComparableFK, ForeignKeyElement> ret = new HashMap<ComparableFK, ForeignKeyElement>();
    for(int i=0;i<fkeys.length;i++)
    {
        ForeignKeyElement key=fkeys[i];
        ComparableFK fkc=new ComparableFK(key);
        if(ret.get(fkc)!=null){//we already have the same key
            LOGGER.log(Level.INFO,key.getName().getFullName()+" key in "+key.getDeclaringTable().getName().getFullName() + " is considered as a duplicate, you may need to verify your schema or database structure.");//NOI18N
            continue;
        } else {
            ret.put(fkc, key);
        }
    }
    return (ForeignKeyElement[]) ret.values().toArray(new ForeignKeyElement[]{});
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:DbSchemaEjbGenerator.java

示例3: getTablesReferencesOtherTablesWithPrimaryKeyMatch

import org.netbeans.modules.dbschema.ForeignKeyElement; //导入依赖的package包/类
/**
 *
 * @param schemaElement The schema
 * @return A set of tables that reference another tables with primary key to
 * promary key reference
 */
public static Set<String> getTablesReferencesOtherTablesWithPrimaryKeyMatch(SchemaElement schemaElement) {
    Set<String> tableNames = new HashSet<>();
    TableElement[] allTables = schemaElement.getTables();
    for (TableElement table0 : allTables) {
        UniqueKeyElement pk0 = table0.getPrimaryKey();
        if (pk0 != null) {
            //it may be join table or other without pk
            ForeignKeyElement[] fkElements = table0.getForeignKeys();
            for (ForeignKeyElement fk : fkElements) {
                TableElement table = fk.getReferencedTable();
                UniqueKeyElement pk = table.getPrimaryKey();
                //at first step support 1-1 keys (no composite yet).
                if (pk != null && 1 == pk0.getColumns().length && fk.getLocalColumns().length == 1 && pk.getColumns().length == 1) {
                    if (fk.getLocalColumns()[0].equals(pk0.getColumns()[0])) {
                        tableNames.add(table0.getName().getName());
                        continue;
                    }
                }
            }
        }
    }

    return tableNames;
}
 
开发者ID:jeddict,项目名称:jeddict,代码行数:31,代码来源:DbSchemaEjbGenerator.java

示例4: isFkUnique

import org.netbeans.modules.dbschema.ForeignKeyElement; //导入依赖的package包/类
private static boolean isFkUnique(ForeignKeyElement key) {
        UniqueKeyElement[] uk = key.getDeclaringTable().getUniqueKeys();
        if (uk == null) {
            return false;
        }
//        key.getColumns()[0].getName().getName()
//                uk[0].getColumns()[0].getName().getName()
        ColumnElement[] columns = key.getColumns();
        for (UniqueKeyElement uk1 : uk) {
            if (containsSameColumns(columns, uk1)) {
                return true;
            }
        }

        return false;
    }
 
开发者ID:jeddict,项目名称:jeddict,代码行数:17,代码来源:DbSchemaEjbGenerator.java

示例5: removeDuplicateFK

import org.netbeans.modules.dbschema.ForeignKeyElement; //导入依赖的package包/类
private ForeignKeyElement[] removeDuplicateFK(ForeignKeyElement[] fkeys) {
    if (fkeys == null || fkeys.length == 0) {
        return fkeys;
    }
    HashMap<ComparableFK, ForeignKeyElement> ret = new HashMap<>();
    for (ForeignKeyElement key : fkeys) {
        ComparableFK fkc = new ComparableFK(key);
        if (ret.get(fkc) != null) {//we already have the same key
            LOGGER.log(Level.INFO, key.getName().getFullName() + " key in " + key.getDeclaringTable().getName().getFullName() + " is considered as a duplicate, you may need to verify your schema or database structure.");//NOI18N
            continue;
        } else {
            ret.put(fkc, key);
        }
    }
    return (ForeignKeyElement[]) ret.values().toArray(new ForeignKeyElement[]{});
}
 
开发者ID:jeddict,项目名称:jeddict,代码行数:17,代码来源:DbSchemaEjbGenerator.java

示例6: getTablesReferencesOtherTablesWithPrimaryKeyMatch

import org.netbeans.modules.dbschema.ForeignKeyElement; //导入依赖的package包/类
/**
 *
 * @param schemaElement The schema
 * @return A set of tables that reference another tables with primary key to
 * promary key reference
 */
public static Set<String> getTablesReferencesOtherTablesWithPrimaryKeyMatch(SchemaElement schemaElement) {
    Set<String> tableNames = new HashSet<String>();
    TableElement[] allTables = schemaElement.getTables();
    for (int i = 0; i < allTables.length; i++) {
        TableElement table0 = allTables[i];
        UniqueKeyElement pk0 = table0.getPrimaryKey();
        if (pk0 != null) {//it may be join table or other without pk
            ForeignKeyElement[] fkElements = table0.getForeignKeys();
            for (int fkix = 0; fkix < fkElements.length; fkix++) {
                ForeignKeyElement fk = fkElements[fkix];
                TableElement table = fk.getReferencedTable();
                UniqueKeyElement pk = table.getPrimaryKey();
                //at first step support 1-1 keys (no composite yet).
                if (pk != null && 1 == pk0.getColumns().length && fk.getLocalColumns().length == 1 && pk.getColumns().length == 1) {
                    if (fk.getLocalColumns()[0].equals(pk0.getColumns()[0])) {
                        tableNames.add(table0.getName().getName());
                        continue;
                    }
                }
            }
        }
    }

    return tableNames;
}
 
开发者ID:foxerfly,项目名称:Netbeans-JPA-Modeler,代码行数:32,代码来源:DbSchemaEjbGenerator.java

示例7: isFkUnique

import org.netbeans.modules.dbschema.ForeignKeyElement; //导入依赖的package包/类
private static boolean isFkUnique(ForeignKeyElement key) {
        UniqueKeyElement[] uk = key.getDeclaringTable().getUniqueKeys();
        if (uk == null) {
            return false;
        }
//        key.getColumns()[0].getName().getName()
//                uk[0].getColumns()[0].getName().getName()
        ColumnElement[] columns = key.getColumns();
        for (int uin = 0; uin < uk.length; uin++) {
            if (containsSameColumns(columns, uk[uin])) {
                return true;
            }
        }

        return false;
    }
 
开发者ID:foxerfly,项目名称:Netbeans-JPA-Modeler,代码行数:17,代码来源:DbSchemaEjbGenerator.java

示例8: removeDuplicateFK

import org.netbeans.modules.dbschema.ForeignKeyElement; //导入依赖的package包/类
private ForeignKeyElement[] removeDuplicateFK(ForeignKeyElement[] fkeys) {
    if (fkeys == null || fkeys.length == 0) {
        return fkeys;
    }
    HashMap<ComparableFK, ForeignKeyElement> ret = new HashMap<ComparableFK, ForeignKeyElement>();
    for (int i = 0; i < fkeys.length; i++) {
        ForeignKeyElement key = fkeys[i];
        ComparableFK fkc = new ComparableFK(key);
        if (ret.get(fkc) != null) {//we already have the same key
            LOGGER.log(Level.INFO, key.getName().getFullName() + " key in " + key.getDeclaringTable().getName().getFullName() + " is considered as a duplicate, you may need to verify your schema or database structure.");//NOI18N
            continue;
        } else {
            ret.put(fkc, key);
        }
    }
    return (ForeignKeyElement[]) ret.values().toArray(new ForeignKeyElement[]{});
}
 
开发者ID:foxerfly,项目名称:Netbeans-JPA-Modeler,代码行数:18,代码来源:DbSchemaEjbGenerator.java

示例9: getTablesReferecedByOtherTables

import org.netbeans.modules.dbschema.ForeignKeyElement; //导入依赖的package包/类
/**
 * 
 * @param schemaElement The schema
 * @return A set of tables that are referenced by at least one another table
 */
public static Set<String> getTablesReferecedByOtherTables(SchemaElement schemaElement) {
    Set<String> tableNames = new HashSet<String>();
    TableElement[] allTables = schemaElement.getTables();
    for(int i = 0; i < allTables.length; i ++ ) {
        ForeignKeyElement[] fkElements = allTables[i].getForeignKeys();
        for(int fkix = 0; fkix < fkElements.length; fkix ++ ) {
            tableNames.add(fkElements[fkix].getReferencedTable().getName().getName());
        }
    }
    
    return tableNames;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:DbSchemaEjbGenerator.java

示例10: isJoinTable

import org.netbeans.modules.dbschema.ForeignKeyElement; //导入依赖的package包/类
/**
 * Returns true if the table is a join table. A table is considered
 * a join table regardless of whether the tables it joins are
 * included in the tables to generate.
 */
public static boolean isJoinTable(TableElement e, Set<String> tablesReferecedByOtherTables) {
    ForeignKeyElement[] foreignKeys = e.getForeignKeys();
    if (foreignKeys == null ||
            foreignKeys.length != 2) {
        return false;
    }
    
    int foreignKeySize = foreignKeys[0].getColumns().length +
            foreignKeys[1].getColumns().length;
    
    if (foreignKeySize < e.getColumns().length) {
        return false;
    }
    
    // issue 89576: a table which references itself is not a join table
    String tableName = e.getName().getName();
    for (int i = 0; i < 2; i++) {
        if (tableName.equals(foreignKeys[i].getReferencedTable().getName().getName())) {
            return false;
        }
    }
    
    // issue 90962: a table whose foreign keys are unique is not a join table
    if (isFkUnique(foreignKeys[0]) || isFkUnique(foreignKeys[1])) {
        return false;
    }
    
    // issue 111397: a table which is referenced by another table is not a join table.
    if(tablesReferecedByOtherTables.contains(e.getName().getName())) {
        return false;
    }
    
    return true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:40,代码来源:DbSchemaEjbGenerator.java

示例11: isForeignKey

import org.netbeans.modules.dbschema.ForeignKeyElement; //导入依赖的package包/类
private boolean isForeignKey(ForeignKeyElement[] fks,
        ColumnElement col) {
    if (fks == null) {
        return false;
    }
    
    for (int i = 0; i < fks.length; i++) {
        if (fks[i].getColumn(col.getName()) != null) {
            return true;
        }
    }
    
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:DbSchemaEjbGenerator.java

示例12: getLocalColumnData

import org.netbeans.modules.dbschema.ForeignKeyElement; //导入依赖的package包/类
private ColumnData[] getLocalColumnData(ForeignKeyElement key) {
    ColumnPairElement[] pkPairs = key.getColumnPairs();
    ColumnData[] localColumns = new ColumnData[pkPairs.length];
    for (int i = 0; i < pkPairs.length; i++) {
        localColumns[i] = new ColumnData(pkPairs[i].getLocalColumn().getName().getName(),
                pkPairs[i].getLocalColumn().isNullable());
    }
    return localColumns;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:DbSchemaEjbGenerator.java

示例13: getReferencedColumnData

import org.netbeans.modules.dbschema.ForeignKeyElement; //导入依赖的package包/类
private ColumnData[] getReferencedColumnData(ForeignKeyElement key) {
    ColumnPairElement[] pkPairs = key.getColumnPairs();
    ColumnData[] refColumns = new ColumnData[pkPairs.length];
    for (int i = 0; i < pkPairs.length; i++) {
        refColumns[i] = new ColumnData(pkPairs[i].getReferencedColumn().getName().getName(),
                pkPairs[i].getReferencedColumn().isNullable());
    }
    return refColumns;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:DbSchemaEjbGenerator.java

示例14: getRoleName

import org.netbeans.modules.dbschema.ForeignKeyElement; //导入依赖的package包/类
/**
 * Provide a role name based on the foreign key column.
 * @return role name based on foreign key column or default name
 */
private String getRoleName(ForeignKeyElement fk, String defaultName) {
    ColumnPairElement[] pkPairs = fk.getColumnPairs();
    if (pkPairs == null || pkPairs.length > 1) {
        return defaultName;
    }
    return EntityMember.makeClassName(
            pkPairs[0].getLocalColumn().getName().getName());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:DbSchemaEjbGenerator.java

示例15: isFkUnique

import org.netbeans.modules.dbschema.ForeignKeyElement; //导入依赖的package包/类
private static boolean isFkUnique(ForeignKeyElement key) {
    UniqueKeyElement[] uk = key.getDeclaringTable().getUniqueKeys();
    if (uk == null) {
        return false;
    }
    
    ColumnElement[] columns = key.getColumns();
    for (int uin=0; uin < uk.length; uin++) {
        if (containsSameColumns(columns, uk[uin])) {
            return true;
        }
    }
    
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:DbSchemaEjbGenerator.java


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