use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class AccumuloUpdateExecution method createBatchWriter.
private BatchWriter createBatchWriter(Table table, Connector connector) throws TranslatorException, TableNotFoundException {
String tableName = SQLStringVisitor.getRecordName(table);
BatchWriter writer;
try {
writer = connector.createBatchWriter(tableName, new BatchWriterConfig());
} catch (TableNotFoundException e) {
try {
connector.tableOperations().create(tableName, true, TimeType.LOGICAL);
} catch (AccumuloException e1) {
throw new TranslatorException(e1);
} catch (AccumuloSecurityException e1) {
throw new TranslatorException(e1);
} catch (TableExistsException e1) {
throw new TranslatorException(e1);
}
writer = connector.createBatchWriter(tableName, new BatchWriterConfig());
}
return writer;
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class AccumuloUpdateExecution method getRowId.
private byte[] getRowId(List<ColumnReference> columns, List<Expression> values) throws TranslatorException {
for (int i = 0; i < columns.size(); i++) {
Column column = columns.get(i).getMetadataObject();
String rowId = SQLStringVisitor.getRecordName(column);
if (rowId.equalsIgnoreCase(AccumuloMetadataProcessor.ROWID) || AccumuloQueryVisitor.isPartOfPrimaryKey(column)) {
Object value = values.get(i);
if (value instanceof Literal) {
return AccumuloDataTypeManager.serialize(((Literal) value).getValue());
}
throw new TranslatorException(AccumuloPlugin.Event.TEIID19006, AccumuloPlugin.Util.gs(AccumuloPlugin.Event.TEIID19006));
}
}
return null;
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class AccumuloUpdateExecution method performDelete.
private void performDelete(Delete delete) throws TableNotFoundException, MutationsRejectedException, TranslatorException {
if (delete.getParameterValues() != null) {
throw new TranslatorException(AccumuloPlugin.Event.TEIID19005, AccumuloPlugin.Util.gs(AccumuloPlugin.Event.TEIID19005));
}
Table table = delete.getTable().getMetadataObject();
AccumuloQueryVisitor visitor = new AccumuloQueryVisitor(this.aef);
visitor.visitNode(delete.getWhere());
if (!visitor.exceptions.isEmpty()) {
throw visitor.exceptions.get(0);
}
/*
// To get the update count I am taking longer route..
Connector connector = this.connection.getInstance();
BatchDeleter deleter = connector.createBatchDeleter(SQLStringVisitor.getRecordName(table), auths, this.aef.getQueryThreadsCount(), new BatchWriterConfig());
deleter.setRanges(visitor.getRanges());
deleter.delete();
deleter.close();
*/
Text prevRow = null;
Connector connector = this.connection.getInstance();
BatchWriter writer = createBatchWriter(table, connector);
Iterator<Entry<Key, Value>> results = AccumuloQueryExecution.runQuery(this.aef, this.connection.getInstance(), this.connection.getAuthorizations(), visitor.getRanges(), table, null);
while (results.hasNext()) {
Key key = results.next().getKey();
Text rowId = key.getRow();
if (prevRow == null || !prevRow.equals(rowId)) {
this.updateCount++;
}
prevRow = rowId;
Mutation mutation = new Mutation(rowId);
mutation.putDelete(key.getColumnFamily(), key.getColumnQualifier());
writer.addMutation(mutation);
}
writer.close();
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class SimpleDBConnectionImpl method performSelect.
/**
* Performs select expression. This expression must be in format which is understandable to SimpleDB database
* @param selectExpression
* @param columns
* @return Iterator of List<String> results
*/
@Override
public SelectResult performSelect(String selectExpression, String nextToken) throws TranslatorException {
try {
SelectRequest selectRequest = new SelectRequest(selectExpression);
if (nextToken != null) {
selectRequest.setNextToken(nextToken);
}
selectRequest.setConsistentRead(true);
return client.select(selectRequest);
} catch (AmazonServiceException e) {
throw new TranslatorException(e);
} catch (AmazonClientException e) {
throw new TranslatorException(e);
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class SimpleDBConnectionImpl method performUpdate.
/**
* Performs update on given domain and items
* @param domainName
* @param items
*/
@Override
public int performUpdate(String domainName, Map<String, Object> updateAttributes, String selectExpression) throws TranslatorException {
try {
List<ReplaceableAttribute> attributes = new ArrayList<ReplaceableAttribute>();
for (Map.Entry<String, Object> column : updateAttributes.entrySet()) {
addAttribute(column.getKey(), column.getValue(), attributes);
}
List<ReplaceableItem> updateItems = new ArrayList<ReplaceableItem>();
int count = 0;
String nextToken = null;
do {
SelectResult result = performSelect(selectExpression, nextToken);
nextToken = result.getNextToken();
Iterator<Item> iter = result.getItems().iterator();
while (iter.hasNext()) {
Item item = iter.next();
updateItems.add(new ReplaceableItem(item.getName(), attributes));
count++;
if (count % 25 == 0) {
executeBatch(domainName, updateItems);
updateItems.clear();
}
}
executeBatch(domainName, updateItems);
} while (nextToken != null);
return count;
} catch (AmazonServiceException e) {
throw new TranslatorException(e);
} catch (AmazonClientException e) {
throw new TranslatorException(e);
}
}
Aggregations