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();
}
}
}
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()));
}
}
}
}
}
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);
}
}
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();
}
Aggregations