Search in sources :

Example 21 with TranslatorException

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));
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) TranslatorException(org.teiid.translator.TranslatorException)

Example 22 with TranslatorException

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);
}
Also used : Blob(java.sql.Blob) SQLException(java.sql.SQLException) BinaryWSProcedureExecution(org.teiid.translator.ws.BinaryWSProcedureExecution) HttpStatusCode(org.apache.olingo.commons.api.http.HttpStatusCode) ArrayList(java.util.ArrayList) List(java.util.List) TranslatorException(org.teiid.translator.TranslatorException)

Example 23 with TranslatorException

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;
}
Also used : Column(org.teiid.metadata.Column) ArrayList(java.util.ArrayList) TranslatorException(org.teiid.translator.TranslatorException) TeiidException(org.teiid.core.TeiidException)

Example 24 with TranslatorException

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);
    }
}
Also used : Column(org.teiid.metadata.Column) Expression(org.teiid.language.Expression) TranslatorException(org.teiid.translator.TranslatorException) ExpressionValueSource(org.teiid.language.ExpressionValueSource)

Example 25 with TranslatorException

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);
    }
}
Also used : ResourceException(javax.resource.ResourceException) TranslatorException(org.teiid.translator.TranslatorException)

Aggregations

TranslatorException (org.teiid.translator.TranslatorException)227 ArrayList (java.util.ArrayList)51 Column (org.teiid.metadata.Column)47 List (java.util.List)32 Table (org.teiid.metadata.Table)30 IOException (java.io.IOException)26 SQLException (java.sql.SQLException)26 ResourceException (javax.resource.ResourceException)26 Test (org.junit.Test)16 Expression (org.teiid.language.Expression)16 Literal (org.teiid.language.Literal)16 DataNotAvailableException (org.teiid.translator.DataNotAvailableException)16 Blob (java.sql.Blob)15 Argument (org.teiid.language.Argument)13 DBObject (com.mongodb.DBObject)11 HashMap (java.util.HashMap)11 ColumnReference (org.teiid.language.ColumnReference)11 ExecutionContext (org.teiid.translator.ExecutionContext)11 BasicDBObject (com.mongodb.BasicDBObject)10 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)10