Search in sources :

Example 51 with Table

use of org.teiid.metadata.Table in project teiid by teiid.

the class TestDDLStringVisitor method testSchema.

@Test
public void testSchema() throws Exception {
    Database db = new Database("foo", "2");
    DataWrapper dw = new DataWrapper("orcle");
    db.addDataWrapper(dw);
    Server s = new Server("testing");
    s.setDataWrapper(dw.getName());
    s.setJndiName("java://test-server");
    s.setType("orcl");
    db.addServer(s);
    String table = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar)";
    Table t = TestDDLParser.helpParse(table, "SchemaA").getSchema().getTable("G1");
    Schema schema = new Schema();
    schema.setName("SchemaA");
    schema.addTable(t);
    schema.addServer(s);
    db.addSchema(schema);
    String metadataDDL = DDLStringVisitor.getDDLString(db);
    String expected = "\n" + "/*\n" + "###########################################\n" + "# START DATABASE foo\n" + "###########################################\n" + "*/\n" + "CREATE DATABASE foo VERSION '2';\n" + "USE DATABASE foo VERSION '2';" + "\n" + "\n--############ Translators ############\n" + "CREATE FOREIGN DATA WRAPPER orcle;\n" + "\n" + "\n--############ Servers ############\n" + "CREATE SERVER testing TYPE 'orcl' FOREIGN DATA WRAPPER orcle OPTIONS (\"jndi-name\" 'java://test-server');\n" + "\n" + "\n--############ Schemas ############\n" + "CREATE SCHEMA SchemaA SERVER testing;\n\n" + "\n--############ Schema:SchemaA ############\n" + "SET SCHEMA SchemaA;\n" + "\n" + "CREATE FOREIGN TABLE G1 (\n" + "\te1 integer,\n" + "\te2 string\n" + ");\n" + "/*\n" + "###########################################\n" + "# END DATABASE foo\n" + "###########################################\n" + "*/\n" + "\n";
    assertEquals(expected, metadataDDL);
}
Also used : DataWrapper(org.teiid.metadata.DataWrapper) Table(org.teiid.metadata.Table) Server(org.teiid.metadata.Server) Schema(org.teiid.metadata.Schema) Database(org.teiid.metadata.Database) Test(org.junit.Test)

Example 52 with Table

use of org.teiid.metadata.Table in project teiid by teiid.

the class TestMetadataValidator method testSkipDocumentModel.

@Test
public void testSkipDocumentModel() throws Exception {
    ModelMetaData model = new ModelMetaData();
    model.setName("xmlstuff");
    model.setModelType(Model.Type.VIRTUAL);
    vdb.addModel(model);
    MetadataFactory mf = new MetadataFactory("myVDB", 1, "xmlstuff", TestDDLParser.getDataTypes(), new Properties(), null);
    mf.getSchema().setPhysical(false);
    Table t = mf.addTable("xmldoctable");
    t.setTableType(Table.Type.Document);
    mf.addColumn("c1", "string", t);
    t.setSelectTransformation("some dummy stuff, should not be validated");
    t.setVirtual(true);
    Table t2 = mf.addTable("xmldoctable2");
    t2.setTableType(Table.Type.XmlMappingClass);
    mf.addColumn("c1", "string", t2);
    t2.setSelectTransformation("some dummy stuff, should not be validated");
    t2.setVirtual(true);
    mf.mergeInto(store);
    buildTransformationMetadata();
    ValidatorReport report = new MetadataValidator().validate(this.vdb, this.store);
    assertFalse(printError(report), report.hasItems());
}
Also used : Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) Properties(java.util.Properties) ValidatorReport(org.teiid.query.validator.ValidatorReport) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 53 with Table

use of org.teiid.metadata.Table in project teiid by teiid.

the class InfinispanUpdateVisitor method updateDocument.

@SuppressWarnings("unchecked")
private void updateDocument(InfinispanDocument parentDocument, Column column, Object value) throws TranslatorException {
    boolean complexObject = this.nested;
    InfinispanDocument targetDocument = parentDocument;
    int parentTag = ProtobufMetadataProcessor.getParentTag(column);
    if (parentTag != -1) {
        // this is in one-2-one case. Dummy child will be there due to buildTargetDocument logic.
        String messageName = ProtobufMetadataProcessor.getMessageName(column);
        InfinispanDocument child = (InfinispanDocument) parentDocument.getChildDocuments(messageName).get(0);
        targetDocument = child;
        complexObject = true;
    } else if (this.nested) {
        Table table = (Table) column.getParent();
        String messageName = ProtobufMetadataProcessor.getMessageName(table);
        InfinispanDocument child = (InfinispanDocument) parentDocument.getChildDocuments(messageName).get(0);
        targetDocument = child;
        complexObject = true;
    }
    if (!ProtobufMetadataProcessor.isPseudo(column)) {
        if (value instanceof List) {
            List<Object> l = (List<Object>) value;
            for (Object o : l) {
                targetDocument.addArrayProperty(getName(column), o);
            }
        } else {
            targetDocument.addProperty(getName(column), value);
        }
        String attrName = MarshallerBuilder.getDocumentAttributeName(column, complexObject, this.metadata);
        this.updatePayload.put(attrName, value);
    }
}
Also used : Table(org.teiid.metadata.Table) InfinispanDocument(org.teiid.infinispan.api.InfinispanDocument) ArrayList(java.util.ArrayList) List(java.util.List)

Example 54 with Table

use of org.teiid.metadata.Table in project teiid by teiid.

the class ProtobufMetadataProcessor method toTeiidSchema.

private void toTeiidSchema(String name, String contents, MetadataFactory mf, String cacheName) throws TranslatorException {
    LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Processing Proto file:", name, "  with contents\n", contents);
    ProtoFile protoFile = ProtoParser.parse(name, contents);
    List<MessageElement> messageTypes = filter(protoFile.typeElements(), MessageElement.class);
    List<EnumElement> enumTypes = filter(protoFile.typeElements(), EnumElement.class);
    // add tables
    HashSet<String> deleteTables = new HashSet<>();
    for (MessageElement messageElement : messageTypes) {
        Table t = addTable(mf, messageTypes, enumTypes, messageElement, null, deleteTables);
        if (t != null) {
            if (t.getAnnotation() != null && findFromAnnotation(AT_CACHE, t.getAnnotation(), "name") != null) {
                t.setProperty(CACHE, findFromAnnotation(AT_CACHE, t.getAnnotation(), "name"));
            } else {
                // in metadata, as both parent child must be in single cache.
                if (getParentTag(t) == -1) {
                    t.setProperty(CACHE, cacheName);
                }
            }
        }
    }
    for (String tableName : deleteTables) {
        mf.getSchema().removeTable(tableName);
    }
}
Also used : Table(org.teiid.metadata.Table) ProtoFile(com.squareup.protoparser.ProtoFile) MessageElement(com.squareup.protoparser.MessageElement) EnumElement(com.squareup.protoparser.EnumElement) HashSet(java.util.HashSet)

Example 55 with Table

use of org.teiid.metadata.Table in project teiid by teiid.

the class SchemaToProtobufProcessor method process.

public ProtobufResource process(MetadataFactory metadataFactory, InfinispanConnection connection) throws TranslatorException {
    String defaultCacheName = "default";
    if (connection != null) {
        defaultCacheName = connection.getCache().getName();
    }
    this.schema = metadataFactory.getSchema();
    buffer.append("package ").append(schema.getName()).append(";");
    buffer.append(NL);
    buffer.append(NL);
    for (Table table : schema.getTables().values()) {
        visit(table, defaultCacheName);
        buffer.append(NL);
        buffer.append(NL);
    }
    for (String name : this.processLater.keySet()) {
        visitTable(name, this.processLater.get(name));
    }
    return new ProtobufResource(schema.getName() + ".proto", buffer.toString());
}
Also used : Table(org.teiid.metadata.Table) ProtobufResource(org.teiid.infinispan.api.ProtobufResource)

Aggregations

Table (org.teiid.metadata.Table)239 Test (org.junit.Test)82 Column (org.teiid.metadata.Column)72 MetadataFactory (org.teiid.metadata.MetadataFactory)59 Properties (java.util.Properties)45 MetadataStore (org.teiid.metadata.MetadataStore)37 Schema (org.teiid.metadata.Schema)35 TranslatorException (org.teiid.translator.TranslatorException)30 ArrayList (java.util.ArrayList)27 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)27 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)23 List (java.util.List)22 ForeignKey (org.teiid.metadata.ForeignKey)22 Connection (java.sql.Connection)15 QueryNode (org.teiid.query.mapping.relational.QueryNode)15 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)15 KeyRecord (org.teiid.metadata.KeyRecord)14 Dimension (org.teiid.translator.couchbase.CouchbaseMetadataProcessor.Dimension)14 CouchbaseMetadataProcessor (org.teiid.translator.couchbase.CouchbaseMetadataProcessor)13 CouchbaseProperties (org.teiid.translator.couchbase.CouchbaseProperties)13