builder.addJoinToGroup(group, joinName, 0);
}
}
private void createTables() throws Exception {
TestAISBuilder builder = new TestAISBuilder(ais, nameGenerator,
schemaManager.getTypesRegistry(), schemaManager.getStorageFormatRegistry());
{
String schema = "test";
String table = "foo";
builder.table(schema, table);
builder.column(schema, table, "c1", 0, "MCOMPAT", "INT", false);
builder.column(schema, table, "c2", 1, "MCOMPAT", "DOUBLE", true);
builder.createGroup(table, schema);
builder.addTableToGroup(table, schema, table);
// no defined pk or indexes
}
{
String schema = "test";
String table = "bar";
builder.table(schema, table);
builder.column(schema, table, "col", 0, "MCOMPAT", "BIGINT", false);
builder.column(schema, table, "name", 1, "MCOMPAT", "INT", false);
builder.pk(schema, table);
builder.indexColumn(schema, table, Index.PRIMARY, "col", 0, true, null);
builder.createGroup(table, schema);
schema = "test";
String childTable = table + "2";
String indexName = "foo_name";
builder.table(schema, childTable);
builder.column(schema, childTable, "foo", 0, "MCOMPAT", "INT", true);
builder.column(schema, childTable, "pid", 1, "MCOMPAT", "INT", true);
String joinName = childTable + "/" + table;
builder.joinTables(joinName, schema, table, schema, childTable);
builder.joinColumns(joinName, schema, table, "col", schema, childTable, "pid");
builder.addJoinToGroup(table, joinName, 0);
builder.groupIndex(table, indexName, false, Index.JoinType.RIGHT);
builder.groupIndexColumn(table, indexName, schema, childTable, "foo", 0);
builder.groupIndexColumn(table, indexName, schema, table, "name", 1);
}
{
String schema = "zap";
String table = "pow";
String indexName = "name_value";
builder.table(schema, table);
builder.column(schema, table, "name", 0, "MCOMPAT", "VARCHAR", 32L, null, true);
builder.column(schema, table, "value", 1, "MCOMPAT", "DECIMAL", 10L, 2L, true);
builder.unique(schema, table, indexName);
builder.indexColumn(schema, table, indexName, "name", 0, true, null);
builder.indexColumn(schema, table, indexName, "value", 1, true, null);
builder.createGroup(table, schema);
builder.addTableToGroup(table, schema, table);
// no defined pk
}
{
// Added for bug1019905: Last table only had GFK show up in constraints/key_column_usage if it had a GFK
String schema = "zzz";
String table = schema + "1";
builder.table(schema, table);
builder.column(schema, table, "id", 0, "MCOMPAT", "INT", false);
builder.pk(schema, table);
builder.indexColumn(schema, table, Index.PRIMARY, "id", 0, true, null);
builder.createGroup(table, schema);
String childTable = schema + "2";
builder.table(schema, childTable);
builder.column(schema, childTable, "id", 0, "MCOMPAT", "INT", false);
builder.column(schema, childTable, "one_id", 1, "MCOMPAT", "INT", true);
builder.pk(schema, childTable);
builder.indexColumn(schema, childTable, Index.PRIMARY, "id", 0, true, null);
String joinName = childTable + "/" + table;
builder.joinTables(joinName, schema, table, schema, childTable);
builder.joinColumns(joinName, schema, table, "id", schema, childTable, "one_id");
builder.addJoinToGroup(table, joinName, 0);
}
{
// bug1024965: Grouping constraints not in depth order
/*
* r
* |-m
* | |-b
* | |-x
* |-a
* |-w
*/
String schema = "gco";
String group = "r";
simpleTable(builder, group, schema, "r", null, true);
simpleTable(builder, group, schema, "m", "r", true);
simpleTable(builder, group, schema, "b", "m", true);
simpleTable(builder, group, schema, "x", "b", false);
simpleTable(builder, group, schema, "a", "r", true);
simpleTable(builder, group, schema, "w", "a", false);
}
{
/* Sequence testing */
String schema = "test";
String sequence = "sequence";
builder.sequence(schema, sequence, 1, 1, 0, 1000, false);
sequence = sequence + "1";
builder.sequence(schema, sequence, 1000, -1, 0, 1000, false);
String table = "seq-table";
sequence = "_col_sequence";
builder.table(schema, table);
builder.column(schema, table, "col", 0, "MCOMPAT", "BIGINT", false);
builder.pk(schema, table);
builder.indexColumn(schema, table, Index.PRIMARY, "col", 0, true, null);
builder.sequence(schema, sequence, 1, 1, 0, 1000, false);
builder.columnAsIdentity(schema, table, "col", sequence, true);
builder.createGroup(table, schema);
builder.addTableToGroup(table, schema, table);
}
{
String schema = "test";
String table = "defaults";
builder.table(schema, table);
builder.column(schema, table, "col1", 0, "MCOMPAT", "VARCHAR", 10L, null, false, "fred", null);
builder.column(schema, table, "col2", 1, "MCOMPAT", "VARCHAR", 10L, null, false, "", null);
builder.column(schema, table, "col3", 2, "MCOMPAT", "BIGINT", null, null, false, "0", null);
builder.column(schema, table, "col4", 3, "MCOMPAT", "DATE", null, null, false, null, "current_date");
builder.column(schema, table, "col5", 4, "MCOMPAT", "DECIMAL", 11L, 2L, false, "5.5", null);
builder.column(schema, table, "col6", 5, "MCOMPAT", "VARBINARY", 15L, null, false, null, null);
builder.createGroup(table, schema);
builder.addTableToGroup(table, schema, table);
}
{
String schema = "test";
String table = "parent";
builder.table(schema, table);
builder.column(schema, table, "col1", 0, "MCOMPAT", "BIGINT", null, false, null, null);
builder.pk(schema, table);
builder.indexColumn(schema, table, Index.PRIMARY, "col1", 0, true, null);
builder.createGroup(table, schema);
builder.addTableToGroup(table, schema, table);
table = "child";
builder.table(schema, table);
builder.column(schema, table, "col1", 0, "MCOMPAT", "BIGINT", null, false, null, null);
builder.column(schema, table, "col2", 1, "MCOMPAT", "BIGINT", null, true, null, null);
builder.pk(schema, table);
builder.indexColumn(schema, table, Index.PRIMARY, "col1", 0, true, null);
builder.foreignKey(schema, "child", Arrays.asList("col2"), schema, "parent", Arrays.asList("col1"), ForeignKey.Action.RESTRICT, ForeignKey.Action.RESTRICT, true, true, "fkey_parent");
builder.createGroup(table, schema);
builder.addTableToGroup(table, schema, table);
}
builder.basicSchemaIsComplete();
builder.groupingIsComplete();
Map<Table, Integer> ordinalMap = new HashMap<>();
List<Table> remainingTables = new ArrayList<>();
// Add all roots
for(Table table : ais.getTables().values()) {
if(table.isRoot()) {
remainingTables.add(table);
}
}
while(!remainingTables.isEmpty()) {
Table table = remainingTables.remove(remainingTables.size()-1);
ordinalMap.put(table, 0);
for(Index index : table.getIndexesIncludingInternal()) {
index.computeFieldAssociations(ordinalMap);
}
// Add all immediate children
for(Join join : table.getChildJoins()) {
remainingTables.add(join.getChild());
}
}
for(Group group : ais.getGroups().values()) {
for(Index index : group.getIndexes()) {
index.computeFieldAssociations(ordinalMap);
}
}
{
String schema = "test";
String view = "voo";
Map<TableName,Collection<String>> refs = new HashMap<>();
refs.put(TableName.create(schema, "foo"), Arrays.asList("c1", "c2"));
builder.view(schema, view,
"CREATE VIEW voo(c1,c2) AS SELECT c2,c1 FROM foo", new Properties(),
refs);
builder.column(schema, view, "c1", 0, "MCOMPAT", "DOUBLE", true);
builder.column(schema, view, "c2", 1, "MCOMPAT", "INT", false);
}
builder.sqljJar("test", "ajar",
new URL("https://example.com/procs/ajar.jar"));
builder.routine("test", "proc1", "java", Routine.CallingConvention.JAVA);
builder.parameter("test", "proc1", "n1", Parameter.Direction.IN,
"MCOMPAT", "bigint", null, null);
builder.parameter("test", "proc1", "s1", Parameter.Direction.IN,
"MCOMPAT", "varchar", 16L, null);
builder.parameter("test", "proc1", "n2", Parameter.Direction.IN,
"MCOMPAT", "decimal", 10L, 5L);
builder.parameter("test", "proc1", null, Parameter.Direction.OUT,
"MCOMPAT", "varchar", 100L, null);
builder.routineExternalName("test", "proc1", "test", "ajar",
"com.foundationdb.procs.Proc1", "call");
}