Search in sources :

Example 26 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class DirectQueryExecution method getRow.

private List<?> getRow(QueryResult result) throws TranslatorException {
    // for insert/update/delete clauses
    if (this.updateQuery) {
        if (this.updateCount != -1) {
            List<?> updateResult = Arrays.asList(this.updateCount);
            this.updateCount = -1;
            return updateResult;
        }
        return null;
    }
    // select clauses
    List<Object> row = null;
    if (this.currentBatch == null) {
        this.currentBatch = loadBatch(this.results);
    }
    if (!this.currentBatch.isEmpty()) {
        row = this.currentBatch.remove(0);
    } else {
        if (!result.isDone()) {
            // fetch more results
            try {
                this.results = this.connection.queryMore(results.getQueryLocator(), context.getBatchSize());
            } catch (ResourceException e) {
                throw new TranslatorException(e);
            }
            this.currentBatch = loadBatch(this.results);
            // read next row
            row = this.currentBatch.remove(0);
        }
    }
    return row;
}
Also used : XmlObject(com.sforce.ws.bind.XmlObject) SObject(com.sforce.soap.partner.sobject.SObject) ResourceException(javax.resource.ResourceException) TranslatorException(org.teiid.translator.TranslatorException)

Example 27 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class DirectQueryExecution method doDelete.

private void doDelete() throws TranslatorException {
    List<String> ids = new ArrayList<String>();
    for (Argument arg : arguments) {
        Object val = arg.getArgumentValue().getValue();
        if (val != null) {
            ids.add(Util.stripQutes(val.toString()));
        }
    }
    try {
        this.updateCount = this.connection.delete(ids.toArray(new String[ids.size()]));
        this.updateQuery = true;
    } catch (ResourceException e) {
        throw new TranslatorException(e);
    }
}
Also used : Argument(org.teiid.language.Argument) ArrayList(java.util.ArrayList) XmlObject(com.sforce.ws.bind.XmlObject) SObject(com.sforce.soap.partner.sobject.SObject) ResourceException(javax.resource.ResourceException) TranslatorException(org.teiid.translator.TranslatorException)

Example 28 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class InsertExecutionImpl method buildBulkRowPayload.

protected List<com.sforce.async.SObject> buildBulkRowPayload(Insert insert, Iterator<? extends List<?>> it, int rowCount) throws TranslatorException {
    List<com.sforce.async.SObject> rows = new ArrayList<com.sforce.async.SObject>();
    List<ColumnReference> columns = insert.getColumns();
    int boundCount = 0;
    List<Expression> literalValues = ((ExpressionValueSource) insert.getValueSource()).getValues();
    while (it.hasNext()) {
        if (boundCount >= rowCount) {
            break;
        }
        boundCount++;
        List<?> values = it.next();
        com.sforce.async.SObject sobj = new com.sforce.async.SObject();
        for (int i = 0; i < columns.size(); i++) {
            Expression ex = literalValues.get(i);
            ColumnReference element = columns.get(i);
            Column column = element.getMetadataObject();
            Class<?> type = ex.getType();
            Object value = null;
            if (ex instanceof Parameter) {
                value = values.get(((Parameter) ex).getValueIndex());
            } else if (!(ex instanceof Literal)) {
                throw new TranslatorException(SalesForcePlugin.Util.gs(SalesForcePlugin.Event.TEIID13007));
            } else {
                value = ((Literal) ex).getValue();
            }
            sobj.setField(column.getSourceName(), getStringValue(value, type));
        }
        rows.add(sobj);
    }
    return rows;
}
Also used : ArrayList(java.util.ArrayList) Expression(org.teiid.language.Expression) Column(org.teiid.metadata.Column) Literal(org.teiid.language.Literal) SObject(com.sforce.async.SObject) Parameter(org.teiid.language.Parameter) SObject(com.sforce.async.SObject) TranslatorException(org.teiid.translator.TranslatorException) SObject(com.sforce.async.SObject) ColumnReference(org.teiid.language.ColumnReference) ExpressionValueSource(org.teiid.language.ExpressionValueSource)

Example 29 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class InsertExecutionImpl method buildSingleRowInsertPayload.

private void buildSingleRowInsertPayload(Insert insert, DataPayload data) throws TranslatorException {
    List<ColumnReference> columns = insert.getColumns();
    List<Expression> values = ((ExpressionValueSource) insert.getValueSource()).getValues();
    if (columns.size() != values.size()) {
        throw new TranslatorException(SalesForcePlugin.Util.gs(SalesForcePlugin.Event.TEIID13006));
    }
    for (int i = 0; i < columns.size(); i++) {
        Column column = columns.get(i).getMetadataObject();
        Object value = values.get(i);
        if (!(value instanceof Literal)) {
            throw new TranslatorException(SalesForcePlugin.Util.gs(SalesForcePlugin.Event.TEIID13007));
        }
        Literal literalValue = (Literal) values.get(i);
        Object val = literalValue.getValue();
        if (val instanceof Timestamp) {
            Calendar cal = Calendar.getInstance();
            cal.setTime((Timestamp) val);
            val = cal;
        }
        data.addField(column.getSourceName(), val);
    }
}
Also used : Expression(org.teiid.language.Expression) Column(org.teiid.metadata.Column) Literal(org.teiid.language.Literal) Calendar(java.util.Calendar) TranslatorException(org.teiid.translator.TranslatorException) SObject(com.sforce.async.SObject) Timestamp(java.sql.Timestamp) ColumnReference(org.teiid.language.ColumnReference) ExpressionValueSource(org.teiid.language.ExpressionValueSource)

Example 30 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class ODataProcedureExecution method execute.

@Override
public void execute() throws TranslatorException {
    String URI = this.visitor.buildURL();
    Schema schema = visitor.getProcedure().getParent();
    EdmDataServices edm = new TeiidEdmMetadata(schema.getName(), ODataEntitySchemaBuilder.buildMetadata(schema));
    if (this.visitor.hasCollectionReturn()) {
        if (this.visitor.isReturnComplexType()) {
            // complex return
            this.response = executeWithComplexReturn(this.visitor.getMethod(), URI, null, this.visitor.getReturnEntityTypeName(), edm, null, Status.OK, Status.NO_CONTENT);
        } else {
            // entity type return
            this.response = executeWithReturnEntity(this.visitor.getMethod(), URI, null, this.visitor.getTable().getName(), edm, null, Status.OK, Status.NO_CONTENT);
        }
        if (this.response != null && this.response.hasError()) {
            throw this.response.getError();
        }
    } else {
        try {
            BinaryWSProcedureExecution execution = executeDirect(this.visitor.getMethod(), URI, null, getDefaultHeaders());
            if (execution.getResponseCode() != Status.OK.getStatusCode()) {
                throw buildError(execution);
            }
            Blob blob = (Blob) execution.getOutputParameterValues().get(0);
            ODataVersion version = getODataVersion(execution);
            // if the procedure is not void
            if (this.visitor.getReturnType() != null) {
                FormatParser<? extends OObject> parser = FormatParserFactory.getParser(OSimpleObject.class, FormatType.ATOM, new Settings(version, edm, this.visitor.getProcedure().getName(), // entitykey
                null, // isResponse
                true, ODataTypeManager.odataType(this.visitor.getReturnType())));
                OSimpleObject object = (OSimpleObject) parser.parse(new InputStreamReader(blob.getBinaryStream()));
                this.returnValue = this.translator.retrieveValue(object.getValue(), this.visitor.getReturnTypeClass());
            }
        } catch (SQLException e) {
            throw new TranslatorException(e);
        }
    }
}
Also used : Blob(java.sql.Blob) OSimpleObject(org.odata4j.core.OSimpleObject) InputStreamReader(java.io.InputStreamReader) SQLException(java.sql.SQLException) Schema(org.teiid.metadata.Schema) BinaryWSProcedureExecution(org.teiid.translator.ws.BinaryWSProcedureExecution) ODataVersion(org.odata4j.core.ODataVersion) EdmDataServices(org.odata4j.edm.EdmDataServices) TranslatorException(org.teiid.translator.TranslatorException) Settings(org.odata4j.format.Settings)

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