use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class BaseQueryExecution method executeSkipToken.
protected InputStream executeSkipToken(URI nextURL, String baseURL, HttpStatusCode[] accepeted) throws TranslatorException {
String next = nextURL.toString();
// $NON-NLS-1$
int idx = next.indexOf("$skiptoken=");
if (next.toLowerCase().startsWith("http")) {
// $NON-NLS-1$
return executeQuery("GET", nextURL.toString(), null, null, accepeted);
} else if (idx != -1) {
String skip = null;
try {
skip = next.substring(idx + 11);
skip = URLDecoder.decode(skip, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new TranslatorException(e);
}
String nextUri = baseURL;
if (baseURL.indexOf('?') == -1) {
// $NON-NLS-1$
nextUri = baseURL + "?$skiptoken=" + skip;
} else {
// $NON-NLS-1$
nextUri = baseURL + "&$skiptoken=" + skip;
}
// $NON-NLS-1$
return executeQuery("GET", nextUri, null, null, accepeted);
} else {
throw new TranslatorException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID17001, next));
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class BaseQueryExecution method executeQuery.
protected InputStream executeQuery(String method, String uri, String payload, String eTag, HttpStatusCode[] expectedStatus) throws TranslatorException {
Map<String, List<String>> headers = getDefaultHeaders();
if (eTag != null) {
// $NON-NLS-1$
headers.put("If-Match", Arrays.asList(eTag));
}
if (payload != null) {
headers.put("Content-Type", // $NON-NLS-1$
Arrays.asList(ContentType.APPLICATION_JSON.toContentTypeString()));
}
BinaryWSProcedureExecution execution;
try {
execution = invokeHTTP(method, uri, payload, headers);
for (HttpStatusCode status : expectedStatus) {
if (status.getStatusCode() == execution.getResponseCode()) {
if (execution.getResponseCode() != HttpStatusCode.NO_CONTENT.getStatusCode() && execution.getResponseCode() != HttpStatusCode.NOT_FOUND.getStatusCode()) {
Blob blob = (Blob) execution.getOutputParameterValues().get(0);
return blob.getBinaryStream();
}
// this is success with no-data
return null;
}
}
} catch (SQLException e) {
throw new TranslatorException(e);
}
// throw an error
throw buildError(execution);
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class BaseQueryExecution method buildRow.
@SuppressWarnings("unchecked")
<T extends AbstractMetadataRecord> List<?> buildRow(T record, List<Column> columns, Class<?>[] expectedType, Map<String, Object> values) throws TranslatorException {
List<Object> results = new ArrayList<Object>();
for (int i = 0; i < columns.size(); i++) {
Column column = columns.get(i);
T columnParent = (T) column.getParent();
String colName = column.getName();
if (!columnParent.equals(record)) {
// $NON-NLS-1$
colName = getName(columnParent) + "/" + column.getName();
}
Object value;
try {
value = ODataTypeManager.convertToTeiidRuntimeType(expectedType[i], values.get(colName), ODataMetadataProcessor.getNativeType(column));
} catch (TeiidException e) {
throw new TranslatorException(e);
}
results.add(value);
}
return results;
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class ODataUpdateVisitor method visit.
@Override
public void visit(Insert obj) {
this.operationType = OperationType.INSERT;
visitNode(obj.getTable());
try {
// read the properties
int elementCount = obj.getColumns().size();
for (int i = 0; i < elementCount; i++) {
Column column = obj.getColumns().get(i).getMetadataObject();
List<Expression> values = ((ExpressionValueSource) obj.getValueSource()).getValues();
Expression expr = values.get(i);
Object value = resolveExpressionValue(expr);
this.odataQuery.addInsertProperty(column, ODataMetadataProcessor.getNativeType(column), value);
}
} catch (TranslatorException e) {
this.exceptions.add(e);
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class DirectQueryExecution method doUpsert.
private void doUpsert(String upsert) throws TranslatorException {
DataPayload payload = buildDataPlayload(upsert);
try {
// $NON-NLS-1$
this.updateCount = this.connection.upsert(payload);
this.updateQuery = true;
} catch (ResourceException e) {
throw new TranslatorException(e);
}
}
Aggregations