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