本文整理汇总了Java中org.voltdb.types.ConstraintType.FOREIGN_KEY属性的典型用法代码示例。如果您正苦于以下问题:Java ConstraintType.FOREIGN_KEY属性的具体用法?Java ConstraintType.FOREIGN_KEY怎么用?Java ConstraintType.FOREIGN_KEY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.voltdb.types.ConstraintType
的用法示例。
在下文中一共展示了ConstraintType.FOREIGN_KEY属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cloneConstraints
/**
* @param src_db
* @param dest_db
*/
public static void cloneConstraints(Database src_db, Database dest_db) {
Catalog dest_catalog = dest_db.getCatalog();
for (Table src_tbl : src_db.getTables()) {
Table dest_tbl = dest_db.getTables().get(src_tbl.getName());
if (dest_tbl != null) {
for (Constraint src_cons : src_tbl.getConstraints()) {
// Only clone FKEY constraint if the other table is in the catalog
ConstraintType cons_type = ConstraintType.get(src_cons.getType());
if (cons_type != ConstraintType.FOREIGN_KEY || (cons_type == ConstraintType.FOREIGN_KEY && dest_db.getTables().get(src_cons.getForeignkeytable().getName()) != null)) {
Constraint dest_cons = clone(src_cons, dest_catalog);
assert (dest_cons != null);
}
} // FOR
}
} // FOR
}
示例2: testForeignKeys
public void testForeignKeys() {
String schemaPath = "";
try {
final URL url = new TPCCProjectBuilder().getDDLURL(true);
schemaPath = URLDecoder.decode(url.getPath(), "UTF-8");
} catch (final UnsupportedEncodingException e) {
e.printStackTrace();
System.exit(-1);
}
final String simpleProject =
"<?xml version=\"1.0\"?>\n" +
"<project>" +
"<database name='database'>" +
"<schemas><schema path='" + schemaPath + "' /></schemas>" +
"<procedures><procedure class='org.voltdb.compiler.procedures.TPCCTestProc' /></procedures>" +
"</database>" +
"</project>";
//System.out.println(simpleProject);
final File projectFile = VoltProjectBuilder.writeStringToTempFile(simpleProject);
final String projectPath = projectFile.getPath();
final VoltCompiler compiler = new VoltCompiler();
final ClusterConfig cluster_config = new ClusterConfig(1, 1, 0, "localhost");
final Catalog catalog = compiler.compileCatalog(projectPath, cluster_config);
assertNotNull(catalog);
// Now check that CUSTOMER correctly references DISTRICT
// (1) Make sure CUSTOMER has a fkey constraint
// (2) Make sure that each source column in CUSTOMER points to the constraint
// (3) Make sure that the fkey constraint points to DISTRICT
final Database catalog_db = catalog.getClusters().get("cluster").getDatabases().get("database");
assertNotNull(catalog_db);
final Table cust_table = catalog_db.getTables().get("CUSTOMER");
assertNotNull(cust_table);
final Table dist_table = catalog_db.getTables().get("DISTRICT");
assertNotNull(dist_table);
// In the code below, we will refer to the column that is pointed to by another column
// in the dependency as the parent, and the column with the fkey constraint as the child
boolean found = false;
for (final Constraint catalog_const : cust_table.getConstraints()) {
final ConstraintType const_type = ConstraintType.get(catalog_const.getType());
if (const_type == ConstraintType.FOREIGN_KEY) {
found = true;
assertEquals(dist_table, catalog_const.getForeignkeytable());
assertEquals(catalog_const.getForeignkeycols().size(), 2);
for (final ColumnRef catalog_parent_colref : catalog_const.getForeignkeycols()) {
// We store the name of the child column in the name of the ColumnRef catalog
// object to the parent
final Column catalog_child_col = cust_table.getColumns().get(catalog_parent_colref.getTypeName());
assertNotNull(catalog_child_col);
// Lame
boolean found_const_for_child = false;
for (final ConstraintRef catalog_constref : catalog_child_col.getConstraints()) {
if (catalog_constref.getConstraint().equals(catalog_const)) {
found_const_for_child = true;
break;
}
}
assertTrue(found_const_for_child);
final Column catalog_parent_col = catalog_parent_colref.getColumn();
assertEquals(dist_table, catalog_parent_col.getParent());
}
break;
}
}
assertTrue(found);
}