Search in sources :

Example 56 with Table

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

the class SchemaToProtobufProcessor method processFKTable.

// Find FK to this table, and add the column
private void processFKTable(Table table) {
    int increment = 1;
    for (Table t : schema.getTables().values()) {
        if (table == t) {
            continue;
        }
        if (!t.getForeignKeys().isEmpty()) {
            List<ForeignKey> fks = t.getForeignKeys();
            for (ForeignKey fk : fks) {
                if (fk.getReferenceTableName().equals(table.getName())) {
                    addTab();
                    String messageName = ProtobufMetadataProcessor.getMessageName(t);
                    if (messageName == null) {
                        messageName = table.getName();
                    } else {
                        messageName = messageName.substring(messageName.lastIndexOf('.') + 1);
                    }
                    String columnName = ProtobufMetadataProcessor.getParentColumnName(t);
                    if (columnName == null) {
                        columnName = t.getName().toLowerCase();
                    }
                    int tag = ProtobufMetadataProcessor.getParentTag(t);
                    if (tag == -1) {
                        tag = table.getColumns().size() + increment;
                        increment++;
                    }
                    buffer.append("repeated ");
                    buffer.append(messageName).append(SPACE).append(columnName);
                    buffer.append(" = ").append(tag).append(SEMICOLON).append(NL);
                }
            }
        }
    }
}
Also used : Table(org.teiid.metadata.Table) ForeignKey(org.teiid.metadata.ForeignKey)

Example 57 with Table

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

the class IckleConversionVisitor method visit.

@Override
public void visit(NamedTable obj) {
    this.queriedTable = obj;
    if (obj.getCorrelationName() == null) {
        obj.setCorrelationName(obj.getMetadataObject().getName().toLowerCase() + "_" + aliasCounter.getAndIncrement());
    }
    if (this.rootNode == null) {
        String messageName = null;
        String aliasName = null;
        String mergedTableName = ProtobufMetadataProcessor.getMerge(obj.getMetadataObject());
        if (mergedTableName == null) {
            aliasName = obj.getCorrelationName();
            messageName = getMessageName(obj.getMetadataObject());
            this.parentTable = obj;
            this.rootNode = new DocumentNode(obj.getMetadataObject(), true);
            this.joinedNode = this.rootNode;
            // check to see if there is one-2-one rows
            Set<String> tags = new HashSet<>();
            for (Column column : obj.getMetadataObject().getColumns()) {
                if (ProtobufMetadataProcessor.getParentTag(column) != -1) {
                    String childMessageName = ProtobufMetadataProcessor.getMessageName(column);
                    if (!tags.contains(childMessageName)) {
                        tags.add(childMessageName);
                        // TODO: DocumentNode needs to be refactored to just take name, not table
                        Table t = new Table();
                        t.setName(childMessageName);
                        this.joinedNode = this.rootNode.joinWith(JoinType.INNER_JOIN, new DocumentNode(t, false));
                    }
                }
            }
        } else {
            try {
                Table mergedTable = this.metadata.getTable(mergedTableName);
                messageName = getMessageName(mergedTable);
                aliasName = mergedTable.getName().toLowerCase() + "_" + aliasCounter.getAndIncrement();
                this.parentTable = new NamedTable(mergedTable.getName(), aliasName, mergedTable);
                this.rootNode = new DocumentNode(mergedTable, true);
                this.joinedNode = this.rootNode.joinWith(JoinType.INNER_JOIN, new DocumentNode(obj.getMetadataObject(), true));
                this.nested = true;
            } catch (TranslatorException e) {
                this.exceptions.add(e);
            }
        }
        buffer.append(messageName);
        if (aliasName != null) {
            buffer.append(Tokens.SPACE);
            buffer.append(aliasName);
        }
        if (this.includePK) {
            KeyRecord pk = this.parentTable.getMetadataObject().getPrimaryKey();
            if (pk != null) {
                for (Column column : pk.getColumns()) {
                    projectedExpressions.add(new ColumnReference(obj, column.getName(), column, column.getJavaType()));
                }
            }
        }
    }
}
Also used : KeyRecord(org.teiid.metadata.KeyRecord) Table(org.teiid.metadata.Table) DocumentNode(org.teiid.translator.document.DocumentNode) Column(org.teiid.metadata.Column) TranslatorException(org.teiid.translator.TranslatorException) HashSet(java.util.HashSet)

Example 58 with Table

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

the class IckleConversionVisitor method visit.

@Override
public void visit(Join obj) {
    Condition cond = null;
    if (obj.getLeftItem() instanceof Join) {
        cond = obj.getCondition();
        append(obj.getLeftItem());
        Table right = ((NamedTable) obj.getRightItem()).getMetadataObject();
        this.joinedNode.joinWith(obj.getJoinType(), new DocumentNode(right, true));
    } else if (obj.getRightItem() instanceof Join) {
        cond = obj.getCondition();
        append(obj.getRightItem());
        Table left = ((NamedTable) obj.getLeftItem()).getMetadataObject();
        this.joinedNode.joinWith(obj.getJoinType(), new DocumentNode(left, true));
    } else {
        cond = obj.getCondition();
        append(obj.getLeftItem());
        this.queriedTable = (NamedTable) obj.getRightItem();
        Table right = ((NamedTable) obj.getRightItem()).getMetadataObject();
        this.joinedNode.joinWith(obj.getJoinType(), new DocumentNode(right, true));
    }
    if (cond != null) {
        append(cond);
    }
}
Also used : Table(org.teiid.metadata.Table) DocumentNode(org.teiid.translator.document.DocumentNode)

Example 59 with Table

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

the class InfinispanDirectQueryExecution method clearContents.

private void clearContents(BasicCache<String, String> aliasCache, String tableName) throws TranslatorException {
    tableName = getAliasName(context, aliasCache, tableName);
    Table table = metadata.getTable(tableName);
    String cacheName = ProtobufMetadataProcessor.getCacheName(table);
    BasicCache<Object, Object> cache = connection.getCacheFactory().getCache(cacheName);
    if (cache == null) {
        throw new TranslatorException(InfinispanPlugin.Event.TEIID25014, InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25014, tableName));
    }
    cache.clear();
}
Also used : Table(org.teiid.metadata.Table) TranslatorException(org.teiid.translator.TranslatorException)

Example 60 with Table

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

the class InfinispanExecutionFactory method getMetadata.

@Override
public void getMetadata(MetadataFactory metadataFactory, InfinispanConnection conn) throws TranslatorException {
    ProtobufMetadataProcessor metadataProcessor = (ProtobufMetadataProcessor) getMetadataProcessor();
    // $NON-NLS-1$
    PropertiesUtils.setBeanProperties(metadataProcessor, metadataFactory.getModelProperties(), "importer");
    // This block is only invoked when NATIVE metadata is defined, by the time code got here if we have
    // tables already in schema, then user defined through other metadata repositories. In this case,
    // a .proto file need to be generated based on schema, then use that to generate final metadata and
    // register the .proto with the Infinispan
    Schema schema = metadataFactory.getSchema();
    ProtobufResource resource = null;
    ArrayList<Table> removedTables = new ArrayList<>();
    if (schema.getTables() != null && !schema.getTables().isEmpty()) {
        SchemaToProtobufProcessor stpp = new SchemaToProtobufProcessor();
        stpp.setIndexMessages(true);
        resource = stpp.process(metadataFactory, conn);
        metadataProcessor.setProtobufResource(resource);
        ArrayList<Table> tables = new ArrayList<>(schema.getTables().values());
        for (Table t : tables) {
            // remove the previous tables, as we want to introduce them with necessary
            // extension metadata generated with generated .proto file. As some of the default
            // extension metadata can be added.
            removedTables.add(schema.removeTable(t.getName()));
        }
    }
    metadataProcessor.process(metadataFactory, conn);
    // may be not carried forward, we need to make sure we copy those back.
    for (Table oldT : removedTables) {
        Table newT = schema.getTable(oldT.getName());
        Map<String, String> properties = oldT.getProperties();
        for (Map.Entry<String, String> entry : properties.entrySet()) {
            newT.setProperty(entry.getKey(), entry.getValue());
        }
        newT.setSupportsUpdate(oldT.supportsUpdate());
        if (oldT.getAnnotation() != null) {
            newT.setAnnotation(oldT.getAnnotation());
        }
        List<Column> columns = oldT.getColumns();
        for (Column c : columns) {
            Column newCol = newT.getColumnByName(c.getName());
            if (newCol != null) {
                Map<String, String> colProperties = c.getProperties();
                for (Map.Entry<String, String> entry : colProperties.entrySet()) {
                    newCol.setProperty(entry.getKey(), entry.getValue());
                }
                newCol.setUpdatable(c.isUpdatable());
                if (c.getAnnotation() != null) {
                    newCol.setAnnotation(c.getAnnotation());
                }
            }
        }
    }
    resource = metadataProcessor.getProtobufResource();
    if (resource == null) {
        SchemaToProtobufProcessor stpp = new SchemaToProtobufProcessor();
        resource = stpp.process(metadataFactory, conn);
    }
    // register protobuf
    if (resource != null) {
        conn.registerProtobufFile(resource);
    }
}
Also used : Table(org.teiid.metadata.Table) Schema(org.teiid.metadata.Schema) ArrayList(java.util.ArrayList) Column(org.teiid.metadata.Column) ProtobufResource(org.teiid.infinispan.api.ProtobufResource) Map(java.util.Map)

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