本文整理汇总了Java中org.netbeans.modules.dbschema.ForeignKeyElement.getLocalColumns方法的典型用法代码示例。如果您正苦于以下问题:Java ForeignKeyElement.getLocalColumns方法的具体用法?Java ForeignKeyElement.getLocalColumns怎么用?Java ForeignKeyElement.getLocalColumns使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.modules.dbschema.ForeignKeyElement
的用法示例。
在下文中一共展示了ForeignKeyElement.getLocalColumns方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: 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;
}
示例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<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;
}
示例4: generateRelationship
import org.netbeans.modules.dbschema.ForeignKeyElement; //导入方法依赖的package包/类
private void generateRelationship(ForeignKeyElement key) {
String keyTableName = key.getDeclaringTable().getName().getName();
String keyRefName = key.getReferencedTable().getName().getName();
boolean oneToOne = isFkUnique(key);
EntityClass roleAHelper = getBean(keyTableName);
if (roleAHelper == null) {
return;
}
EntityClass roleBHelper = getBean(keyRefName);
if (roleBHelper == null) {
if(generateUnresolvedRelationships){
//we may want to generate field instead of skip
for(ColumnElement col:key.getLocalColumns()){
generatePkField(col, false, false);
}
}
return;
}
// create role B (it's the table which contains the foreign key)
String roleBCmr = EntityMember.makeRelationshipFieldName(
roleAHelper.getClassName(), colectionType, !oneToOne);
roleBCmr = uniqueAlgorithm(getFieldNames(roleBHelper), roleBCmr, null);
RelationshipRole roleB = new RelationshipRole(
//TODO ask generator for default role name, do not assume it is EJB name
getRoleName(key, roleBHelper.getClassName()),
roleBHelper.getClassName(),
roleBCmr,
false,
!oneToOne,
!isNullable(key),
isNullable(key));
roleB.setEntityPkgName(roleBHelper.getPackage());
roleBHelper.addRole(roleB);
// role A
String roleACmr = EntityMember.makeRelationshipFieldName(
roleBHelper.getClassName(), colectionType, false);
/* only use database column name if a column is not required by the
primary key. If a column is already required by the primary key
then executing this code would cause the cmr-field name to be
named cmp-fieldname1. Therefore, we do not change the cmr-field
name and instead use the name of the other ejb (default).
*/
// #185253 I don't see a good reason to have one case when it's possible to use column name and anothe case when it's not possible
// comment code below for now, may need review or deletion in next release if there will be any negative feedback
// #188550 add backward compartible option to have column names instead of tables names
if (useColumNamesInRelations && !containsColumns(key.getColumns(), getPrimaryOrCandidateKey(key.getDeclaringTable()))) {
roleACmr = EntityMember.makeRelationshipFieldName(roleB.getRoleName(), colectionType, false);
}
roleACmr = uniqueAlgorithm(getFieldNames(roleAHelper), roleACmr, null);
RelationshipRole roleA = new RelationshipRole(
//TODO ask generator for default role name, do not assume it is EJB name
getRoleName(key, roleAHelper.getClassName()),
roleAHelper.getClassName(),
roleACmr,
!oneToOne,
false,
false,
isNullable(key));
roleA.setEntityPkgName(roleAHelper.getPackage());
roleAHelper.addRole(roleA);
EntityRelation relation = new EntityRelation(roleA, roleB);
relation.setRelationName(roleA.getEntityName() + '-' + roleB.getEntityName()); // NOI18N
relations.add(relation);
roleAHelper.getCMPMapping().getCmrFieldMapping().put(roleACmr, getLocalColumnData(key));
roleBHelper.getCMPMapping().getCmrFieldMapping().put(roleBCmr, getReferencedColumnData(key));
}
示例5: generateRelationship
import org.netbeans.modules.dbschema.ForeignKeyElement; //导入方法依赖的package包/类
private void generateRelationship(ForeignKeyElement key) {
String keyTableName = key.getDeclaringTable().getName().getName();
String keyRefName = key.getReferencedTable().getName().getName();
boolean oneToOne = isFkUnique(key);
EntityClass roleAHelper = getBean(keyTableName);
if (roleAHelper == null) {
return;
}
EntityClass roleBHelper = getBean(keyRefName);
if (roleBHelper == null) {
if (generateUnresolvedRelationships) {
//we may want to generate field instead of skip
for (ColumnElement col : key.getLocalColumns()) {
generatePkField(col, false, false);
}
}
return;
}
// create role B (it's the table which contains the foreign key)
String roleBCmr = EntityMember.makeRelationshipFieldName(
roleAHelper.getClassName(), colectionType, !oneToOne);
roleBCmr = uniqueAlgorithm(getFieldNames(roleBHelper), roleBCmr, null);
RelationshipRole roleB = new RelationshipRole(
//TODO ask generator for default role name, do not assume it is EJB name
getRoleName(key, roleBHelper.getClassName()),
roleBHelper.getClassName(),
roleBCmr,
false,
!oneToOne,
!isNullable(key),
isNullable(key));
roleB.setEntityPkgName(roleBHelper.getPackage());
roleBHelper.addRole(roleB);
// role A
String roleACmr = EntityMember.makeRelationshipFieldName(
roleBHelper.getClassName(), colectionType, false);
/* only use database column name if a column is not required by the
primary key. If a column is already required by the primary key
then executing this code would cause the cmr-field name to be
named cmp-fieldname1. Therefore, we do not change the cmr-field
name and instead use the name of the other ejb (default).
*/
// #185253 I don't see a good reason to have one case when it's possible to use column name and anothe case when it's not possible
// comment code below for now, may need review or deletion in next release if there will be any negative feedback
// #188550 add backward compartible option to have column names instead of tables names
if (useColumNamesInRelations && !containsColumns(key.getColumns(), getPrimaryOrCandidateKey(key.getDeclaringTable()))) {
roleACmr = EntityMember.makeRelationshipFieldName(roleB.getRoleName(), colectionType, false);
}
roleACmr = uniqueAlgorithm(getFieldNames(roleAHelper), roleACmr, null);
RelationshipRole roleA = new RelationshipRole(
//TODO ask generator for default role name, do not assume it is EJB name
getRoleName(key, roleAHelper.getClassName()),
roleAHelper.getClassName(),
roleACmr,
!oneToOne,
false,
false,
isNullable(key));
roleA.setEntityPkgName(roleAHelper.getPackage());
roleAHelper.addRole(roleA);
EntityRelation relation = new EntityRelation(roleA, roleB);
relation.setRelationName(roleA.getEntityName() + '-' + roleB.getEntityName()); // NOI18N
relations.add(relation);
roleAHelper.getCMPMapping().getCmrFieldMapping().put(roleACmr, getLocalColumnData(key));
roleBHelper.getCMPMapping().getCmrFieldMapping().put(roleBCmr, getReferencedColumnData(key));
}