Package com.foundationdb.ais.model

Examples of com.foundationdb.ais.model.TestAISBuilder


    /* CREATE TABLE t1 (c1 int not null primary key) */
    /* CREATE TABLE t2 (c1 int not null primary key, c2 int not null, grouping foreign key (c2) references t1) */
    private void createTableFKSimpleGenerateAIS() {
        dropTable = TableName.create(DEFAULT_SCHEMA, JOIN_TABLE);

        TestAISBuilder builders[] = { builder, new TestAISBuilder(ddlFunctions.externalAIS, typesRegistry) };

        // Re-gen the DDLFunctions to have the AIS for internal references.
        ddlFunctions = new DDLFunctionsMock(builder.akibanInformationSchema(), ddlFunctions.externalAIS);
        // Need t1 in both internal and external
        for(TestAISBuilder b : builders) {
View Full Code Here


    private int ordinal (String tableName) {
        return schema.ais().getTable("schema", tableName).getOrdinal().intValue();
    }
   
    private Schema caoiSchema() {
        TestAISBuilder builder = new TestAISBuilder(registry.getTypesRegistry());
        builder.table("schema", "customer");
        builder.column("schema", "customer", "customer_id", 0, "MCOMPAT", "int", false);
        builder.column("schema", "customer", "customer_name", 1, "MCOMPAT", "varchar", 64L, null, false);
        builder.pk("schema", "customer");
        builder.indexColumn("schema", "customer", Index.PRIMARY, "customer_id", 0, true, null);
        builder.table("schema", "order");
        builder.column("schema", "order", "order_id", 0, "MCOMPAT", "int", false);
        builder.column("schema", "order", "customer_id", 1, "MCOMPAT", "int", false);
        builder.column("schema", "order", "order_date", 2, "MCOMPAT", "int", false);
        builder.pk("schema", "order");
        builder.indexColumn("schema", "order", Index.PRIMARY, "order_id", 0, true, null);
        builder.table("schema", "item");
        builder.column("schema", "item", "item_id", 0, "MCOMPAT", "int", false);
        builder.column("schema", "item", "order_id", 1, "MCOMPAT", "int", false);
        builder.column("schema", "item", "quantity", 2, "MCOMPAT", "int", false);
        builder.pk("schema", "item");
        builder.indexColumn("schema", "item", Index.PRIMARY, "item_id", 0, true, null);
        builder.joinTables("co", "schema", "customer", "schema", "order");
        builder.joinColumns("co", "schema", "customer", "customer_id", "schema", "order", "customer_id");
        builder.joinTables("oi", "schema", "order", "schema", "item");
        builder.joinColumns("oi", "schema", "order", "order_id", "schema", "item", "order_id");
        builder.table("schema", "state");
        builder.column("schema", "state", "code", 0, "MCOMPAT", "varchar", 2L, null, false);
        builder.column("schema", "state", "name", 1, "MCOMPAT", "varchar", 50L, null, false);
        builder.table("schema", "customer2");
        builder.column("schema", "customer2", "customer_id", 0, "MCOMPAT", "int unsigned", false);
        builder.column("schema", "customer2", "customer_name", 1, "MCOMPAT", "VARCHAR", 64L, null,  false);
        builder.pk("schema", "customer2");
        builder.indexColumn("schema", "customer2", Index.PRIMARY, "customer_id", 0, true, null);
        builder.basicSchemaIsComplete();
        builder.createGroup("group", "schema");
        builder.addJoinToGroup("group", "co", 0);
        builder.addJoinToGroup("group", "oi", 0);
        builder.createGroup("state", "schema");
        builder.addTableToGroup("state", "schema", "state");
        builder.createGroup("customer", "schema");
        builder.addTableToGroup("customer", "schema", "customer2");
        builder.groupingIsComplete();
       
        SchemaFactory factory = new SchemaFactory ("schema");
        factory.buildRowDefs(builder.akibanInformationSchema());
        return new Schema(builder.akibanInformationSchema());
    }
View Full Code Here

        assertEquals(ApiTestBase.getLong(productRow, 2), Long.valueOf(45));
       
    }

    private Schema caoiSchema() {
        TestAISBuilder builder = new TestAISBuilder(TestTypesRegistry.MCOMPAT);
        builder.table("schema", "customer");
        builder.column("schema", "customer", "customer_id", 0, "MCOMPAT", "int", false);
        builder.column("schema", "customer", "customer_name", 1, "MCOMPAT", "varchar", 64L, null, false);
        builder.pk("schema", "customer");
        builder.indexColumn("schema", "customer", Index.PRIMARY, "customer_id", 0, true, null);
        builder.table("schema", "order");
        builder.column("schema", "order", "order_id", 0, "MCOMPAT", "int", false);
        builder.column("schema", "order", "customer_id", 1, "MCOMPAT", "int", false);
        builder.column("schema", "order", "order_date", 2, "MCOMPAT", "int", false);
        builder.pk("schema", "order");
        builder.indexColumn("schema", "order", Index.PRIMARY, "order_id", 0, true, null);
        builder.table("schema", "item");
        builder.column("schema", "item", "item_id", 0, "MCOMPAT", "int", false);
        builder.column("schema", "item", "order_id", 1, "MCOMPAT", "int", false);
        builder.column("schema", "item", "quantity", 2, "MCOMPAT", "int", false);
        builder.pk("schema", "item");
        builder.indexColumn("schema", "item", Index.PRIMARY, "item_id", 0, true, null);
        builder.joinTables("co", "schema", "customer", "schema", "order");
        builder.joinColumns("co", "schema", "customer", "customer_id", "schema", "order", "customer_id");
        builder.joinTables("oi", "schema", "order", "schema", "item");
        builder.joinColumns("oi", "schema", "order", "order_id", "schema", "item", "item_id");
        builder.table("schema", "state");
        builder.column("schema", "state", "code", 0, "MCOMPAT", "varchar", 2L, null, false);
        builder.column("schema", "state", "name", 1, "MCOMPAT", "varchar", 50L, null, false);
        builder.basicSchemaIsComplete();
        builder.createGroup("group", "groupschema");
        builder.addJoinToGroup("group", "co", 0);
        builder.addJoinToGroup("group", "oi", 0);
        builder.createGroup("state", "schema");
        builder.addTableToGroup("state", "schema", "state");
        builder.groupingIsComplete();
       
        SchemaFactory factory = new SchemaFactory ("schema");
        factory.buildRowDefs(builder.akibanInformationSchema());
        return new Schema(builder.akibanInformationSchema());
    }
View Full Code Here

    private final TypesRegistry typesRegistry = TestTypesRegistry.MCOMPAT;

    @Test
    public void testSupportedCollation() {
        final TestAISBuilder builder = new TestAISBuilder(typesRegistry);
        builder.table("test", "t1");
        builder.column("test", "t1", "c1", 0, "MCOMPAT", "VARCHAR", 16L, true, null, "en_us");
        builder.basicSchemaIsComplete();
        Assert.assertEquals("Expect no validation failure for supported collation", 0, builder
                .akibanInformationSchema().validate(validations).failures().size());
    }
View Full Code Here

    @Test
    public void testUnsupportedCollationStrictMode() {
        Mode save = AkCollatorFactory.getCollationMode();
        try {
            AkCollatorFactory.setCollationMode(Mode.STRICT);
            final TestAISBuilder builder = new TestAISBuilder(typesRegistry);
            builder.table("test", "t1");
            builder.column("test", "t1", "c1", 0, "MCOMPAT", "VARCHAR", 16L, true, null, "fricostatic_sengalese_ci");
            builder.basicSchemaIsComplete();
            Assert.assertEquals("Expect validation failure on invalid collation", 1, builder.akibanInformationSchema()
                    .validate(validations).failures().size());
        } catch (UnsupportedCollationException ex) {
            // Okay if thrown earlier.
        } finally {
            AkCollatorFactory.setCollationMode(save);
View Full Code Here

    @Test
    public void testUnsupportedCollationLooseMode() {
        Mode save = AkCollatorFactory.getCollationMode();
        try {
            AkCollatorFactory.setCollationMode(Mode.LOOSE);
            final TestAISBuilder builder = new TestAISBuilder(typesRegistry);
            builder.table("test", "t1");
            builder.column("test", "t1", "c1", 0, "MCOMPAT", "VARCHAR", 16L, true, null, "fricostatic_sengalese_ci");
            builder.basicSchemaIsComplete();
            Assert.assertEquals("Expect no validation failure in loose mode", 0, builder.akibanInformationSchema()
                    .validate(validations).failures().size());
        } finally {
            AkCollatorFactory.setCollationMode(save);
        }
    }
View Full Code Here

    @Before
    public void createValidations() {
        validations = new LinkedList<>();
        validations.add(AISValidations.JOIN_TO_ONE_PARENT);
       
        builder = new TestAISBuilder(TestTypesRegistry.MCOMPAT);
        builder.table("schema", "customer");
        builder.column("schema", "customer", "customer_id", 0, "MCOMPAT", "int", false);
        builder.column("schema", "customer", "customer_name", 1, "MCOMPAT", "varchar", 64L, null, false);
        builder.pk("schema", "customer");
        builder.indexColumn("schema", "customer", Index.PRIMARY, "customer_id", 0, true, null);
View Full Code Here

    protected SQLParser parser;

    private AkibanInformationSchema factory () throws Exception
    {
        TypesRegistry typesRegistry = TestTypesRegistry.MCOMPAT;
        TestAISBuilder builder = new TestAISBuilder(typesRegistry);
        builder.table("s", "t");
        builder.column ("s", "t", "c1", 0, "MCOMPAT", "int", false);
        builder.pk("s", "t");
        builder.indexColumn("s", "t", "PRIMARY", "c1", 0, true, 0);
        builder.basicSchemaIsComplete();
        return builder.akibanInformationSchema();
    }
View Full Code Here

            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");
    }
View Full Code Here

TOP

Related Classes of com.foundationdb.ais.model.TestAISBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.