Search in sources :

Example 1 with DocumentNode

use of org.teiid.translator.document.DocumentNode in project teiid by teiid.

the class ODataProcedureExecution method handleResponse.

private void handleResponse(final Procedure procedure, final String baseUri, final InputStream payload) throws TranslatorException, ODataDeserializerException {
    if (procedure.getResultSet() != null) {
        ODataType type = ODataType.valueOf(procedure.getResultSet().getProperty(ODataMetadataProcessor.ODATA_TYPE, false));
        this.response = new ODataResponse(payload, type, new DocumentNode()) {

            @Override
            public InputStream nextBatch(java.net.URI uri) throws TranslatorException {
                return executeSkipToken(uri, baseUri, new HttpStatusCode[] { HttpStatusCode.OK });
            }
        };
    } else if (getReturnParameter() != null) {
        // this is scalar result
        JsonDeserializer parser = new JsonDeserializer(false);
        Property property = parser.toProperty(payload).getPayload();
        if (property.isCollection()) {
            this.returnValue = property.asCollection();
        } else {
            this.returnValue = property.asPrimitive();
        }
    }
}
Also used : DocumentNode(org.teiid.translator.document.DocumentNode) InputStream(java.io.InputStream) ODataType(org.teiid.translator.odata4.ODataMetadataProcessor.ODataType) HttpStatusCode(org.apache.olingo.commons.api.http.HttpStatusCode) TranslatorException(org.teiid.translator.TranslatorException) JsonDeserializer(org.apache.olingo.client.core.serialization.JsonDeserializer) Property(org.apache.olingo.commons.api.data.Property)

Example 2 with DocumentNode

use of org.teiid.translator.document.DocumentNode 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 3 with DocumentNode

use of org.teiid.translator.document.DocumentNode 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 4 with DocumentNode

use of org.teiid.translator.document.DocumentNode in project teiid by teiid.

the class ODataUpdateQuery method buildUpdateURL.

public String buildUpdateURL(String serviceRoot, List<?> row) {
    URIBuilderImpl uriBuilder = new URIBuilderImpl(new ConfigurationImpl(), serviceRoot);
    uriBuilder.appendEntitySetSegment(this.rootDocument.getName());
    List<String> selection = this.rootDocument.getIdentityColumns();
    if (selection.size() == 1) {
        uriBuilder.appendKeySegment(row.get(0));
    } else if (!selection.isEmpty()) {
        LinkedHashMap<String, Object> keys = new LinkedHashMap<String, Object>();
        for (int i = 0; i < selection.size(); i++) {
            keys.put(selection.get(i), row.get(i));
        }
        uriBuilder.appendKeySegment(keys);
    }
    if (!this.complexTables.isEmpty()) {
        uriBuilder.appendPropertySegment(this.complexTables.get(0).getName());
    }
    if (!this.expandTables.isEmpty()) {
        uriBuilder.appendPropertySegment(this.expandTables.get(0).getName());
        // add keys if present
        DocumentNode use = this.expandTables.get(0);
        List<String> expandSelection = use.getIdentityColumns();
        LinkedHashMap<String, Object> keys = new LinkedHashMap<String, Object>();
        for (int i = 0; i < expandSelection.size(); i++) {
            keys.put(expandSelection.get(i), row.get(selection.size() + i));
        }
        if (!keys.isEmpty()) {
            uriBuilder.appendKeySegment(keys);
        }
    }
    URI uri = uriBuilder.build();
    return uri.toString();
}
Also used : URIBuilderImpl(org.apache.olingo.client.core.uri.URIBuilderImpl) DocumentNode(org.teiid.translator.document.DocumentNode) ConfigurationImpl(org.apache.olingo.client.core.ConfigurationImpl) URI(java.net.URI) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

DocumentNode (org.teiid.translator.document.DocumentNode)4 Table (org.teiid.metadata.Table)2 TranslatorException (org.teiid.translator.TranslatorException)2 InputStream (java.io.InputStream)1 URI (java.net.URI)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 ConfigurationImpl (org.apache.olingo.client.core.ConfigurationImpl)1 JsonDeserializer (org.apache.olingo.client.core.serialization.JsonDeserializer)1 URIBuilderImpl (org.apache.olingo.client.core.uri.URIBuilderImpl)1 Property (org.apache.olingo.commons.api.data.Property)1 HttpStatusCode (org.apache.olingo.commons.api.http.HttpStatusCode)1 Column (org.teiid.metadata.Column)1 KeyRecord (org.teiid.metadata.KeyRecord)1 ODataType (org.teiid.translator.odata4.ODataMetadataProcessor.ODataType)1