use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class ODataQueryExecution method execute.
@Override
public void execute() throws TranslatorException {
String URI = this.visitor.buildURL();
if (this.visitor.isCount()) {
Map<String, List<String>> headers = new TreeMap<String, List<String>>();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
headers.put("Accept", Arrays.asList("text/xml", "text/plain"));
// $NON-NLS-1$
BinaryWSProcedureExecution execution = executeDirect("GET", URI, null, headers);
if (execution.getResponseCode() != Status.OK.getStatusCode()) {
throw buildError(execution);
}
Blob blob = (Blob) execution.getOutputParameterValues().get(0);
try {
this.countResponse = Integer.parseInt(ObjectConverterUtil.convertToString(blob.getBinaryStream()));
} catch (IOException e) {
throw new TranslatorException(e);
} catch (SQLException e) {
throw new TranslatorException(e);
}
} else {
Schema schema = visitor.getEnityTable().getParent();
EdmDataServices edm = new TeiidEdmMetadata(schema.getName(), ODataEntitySchemaBuilder.buildMetadata(schema));
// $NON-NLS-1$
this.response = executeWithReturnEntity("GET", URI, null, visitor.getEnityTable().getName(), edm, null, Status.OK, Status.NO_CONTENT, Status.NOT_FOUND);
if (this.response != null && this.response.hasError()) {
throw this.response.getError();
}
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class ODataUpdateVisitor method visit.
@Override
public void visit(Delete obj) {
// $NON-NLS-1$
this.method = "DELETE";
this.entity = obj.getTable().getMetadataObject();
visitNode(obj.getTable());
// only pk are allowed, no other criteria not allowed
obj.setWhere(buildEntityKey(obj.getWhere()));
// this will build with entity keys
this.uri = getEnitityURL();
if (this.uri.indexOf('(') == -1) {
this.exceptions.add(new TranslatorException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID17011, this.filter.toString())));
}
if (this.filter.length() > 0) {
this.exceptions.add(new TranslatorException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID17009, this.filter.toString())));
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class ODataFilterVisitor method visit.
@Override
public void visit(ColumnReference obj) {
Column column = obj.getMetadataObject();
ODataDocumentNode schemaElement = this.query.getSchemaElement((Table) column.getParent());
// check if the column on pseudo column, then move it to the parent.
if (ODataMetadataProcessor.isPseudo(column)) {
try {
Column realColumn = ODataMetadataProcessor.normalizePseudoColumn(this.metadata, column);
schemaElement = this.query.getSchemaElement((Table) realColumn.getParent());
} catch (TranslatorException e) {
this.exceptions.add(e);
}
}
if (this.filterOnElement == null) {
this.filterOnElement = schemaElement;
} else if (schemaElement.isExpandType() && (!this.filterOnElement.isExpandType())) {
this.exceptions.add(new TranslatorException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID17026)));
}
try {
if (this.filterOnElement.isComplexType()) {
if (ODataMetadataProcessor.isPseudo(column)) {
Column realColumn = ODataMetadataProcessor.normalizePseudoColumn(this.metadata, column);
this.filter.append(realColumn.getName());
} else {
this.filter.append(this.filterOnElement.getName()).append("/").append(column.getName());
}
} else {
if (ODataMetadataProcessor.isPseudo(column)) {
Column realColumn = ODataMetadataProcessor.normalizePseudoColumn(this.metadata, column);
this.filter.append(realColumn.getName());
} else {
this.filter.append(column.getName());
}
}
} catch (TranslatorException e) {
this.exceptions.add(e);
}
}
use of org.teiid.translator.TranslatorException 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.TranslatorException in project teiid by teiid.
the class ODataProcedureExecution method execute.
@Override
public void execute() throws TranslatorException {
try {
String parameters = getQueryParameters(this.command);
InputStream response = null;
Procedure procedure = this.command.getMetadataObject();
if (isFunction(procedure)) {
String URI = buildFunctionURL(this.command, parameters);
response = executeQuery("GET", URI, null, null, new HttpStatusCode[] { HttpStatusCode.OK });
handleResponse(procedure, URI, response);
} else {
String URI = this.command.getProcedureName();
response = executeQuery("POST", URI, parameters, null, new HttpStatusCode[] { HttpStatusCode.OK });
handleResponse(procedure, URI, response);
}
} catch (ODataDeserializerException e) {
throw new TranslatorException(e);
} catch (EdmPrimitiveTypeException e) {
throw new TranslatorException(e);
}
}
Aggregations