use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class IckleConversionVisitor method visit.
@Override
public void visit(Select obj) {
buffer.append(SQLConstants.Reserved.FROM).append(Tokens.SPACE);
visitNodes(obj.getFrom());
if (obj.getWhere() != null) {
buffer.append(Tokens.SPACE);
buffer.append(SQLConstants.Reserved.WHERE).append(Tokens.SPACE);
visitNode(obj.getWhere());
}
if (obj.getGroupBy() != null) {
buffer.append(Tokens.SPACE);
append(obj.getGroupBy());
}
if (obj.getHaving() != null) {
buffer.append(Tokens.SPACE).append(HAVING).append(Tokens.SPACE);
append(obj.getHaving());
}
if (obj.getOrderBy() != null) {
buffer.append(Tokens.SPACE);
visitNode(obj.getOrderBy());
if (this.nested) {
this.exceptions.add(new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25010)));
}
}
if (obj.getLimit() != null) {
buffer.append(Tokens.SPACE);
visitNode(obj.getLimit());
}
visitNodes(obj.getDerivedColumns());
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class InfinispanDirectQueryExecution method execute.
@Override
public void execute() throws TranslatorException {
String command = (String) this.arguments.get(0).getArgumentValue().getValue();
BasicCache<String, String> aliasCache = getAliasCache(this.connection);
Matcher m = truncatePattern.matcher(command);
if (m.matches()) {
String tableName = m.group(1);
clearContents(aliasCache, tableName);
return;
}
m = renamePattern.matcher(command);
if (m.matches()) {
String tableOne = m.group(1);
String tableTwo = m.group(2);
String aliasName = getAliasName(context, aliasCache, tableOne);
if (aliasName.equals(tableOne)) {
aliasCache.put(fqn(context, tableTwo), tableOne);
aliasCache.put(fqn(context, tableOne), tableTwo);
} else if (aliasName.equals(tableTwo)) {
aliasCache.put(fqn(context, tableOne), tableOne);
aliasCache.put(fqn(context, tableTwo), tableTwo);
} else {
throw new TranslatorException(InfinispanPlugin.Event.TEIID25015, InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25015, tableOne, aliasName));
}
clearContents(aliasCache, tableOne);
return;
}
throw new TranslatorException(InfinispanPlugin.Event.TEIID25016, InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25016, command));
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class InfinispanDirectQueryExecution method clearContents.
private void clearContents(BasicCache<String, String> aliasCache, String tableName) throws TranslatorException {
tableName = getAliasName(context, aliasCache, tableName);
Table table = metadata.getTable(tableName);
String cacheName = ProtobufMetadataProcessor.getCacheName(table);
BasicCache<Object, Object> cache = connection.getCacheFactory().getCache(cacheName);
if (cache == null) {
throw new TranslatorException(InfinispanPlugin.Event.TEIID25014, InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25014, tableName));
}
cache.clear();
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class InfinispanQueryExecution method useModifiedGroups.
static void useModifiedGroups(InfinispanConnection connection, ExecutionContext context, RuntimeMetadata metadata, Command command) throws TranslatorException {
BasicCache<String, String> aliasCache = InfinispanDirectQueryExecution.getAliasCache(connection);
CollectorVisitor.collectGroups(command).forEach(namedTable -> {
try {
Table table = InfinispanDirectQueryExecution.getAliasTable(context, metadata, aliasCache, namedTable.getMetadataObject());
Collection<ColumnReference> columns = CollectorVisitor.collectElements(command);
columns.forEach(reference -> {
if (reference.getTable().getMetadataObject().equals(namedTable.getMetadataObject())) {
Column column = table.getColumnByName(reference.getMetadataObject().getName());
reference.getTable().setMetadataObject(table);
reference.setMetadataObject(column);
}
});
namedTable.setMetadataObject(table);
} catch (TranslatorException e) {
LogManager.logError(LogConstants.CTX_CONNECTOR, e, e.getMessage());
}
});
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class InfinispanUpdateExecution method execute.
@Override
public void execute() throws TranslatorException {
if (useAliasCache) {
if (useAliasCache) {
InfinispanQueryExecution.useModifiedGroups(this.connection, this.executionContext, this.metadata, this.command);
}
}
final InfinispanUpdateVisitor visitor = new InfinispanUpdateVisitor(this.metadata);
visitor.append(this.command);
if (!visitor.exceptions.isEmpty()) {
throw visitor.exceptions.get(0);
}
TeiidTableMarsheller marshaller = null;
try {
Table table = visitor.getParentTable();
Column pkColumn = visitor.getPrimaryKey();
if (pkColumn == null) {
throw new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25013, table.getName()));
}
final String PK = MarshallerBuilder.getDocumentAttributeName(pkColumn, false, this.metadata);
DocumentFilter docFilter = null;
if (visitor.isNestedOperation() && visitor.getWhereClause() != null) {
Action action = Action.ALWAYSADD;
if (command instanceof Delete) {
action = Action.REMOVE;
}
SQLStringVisitor ssv = new SQLStringVisitor() {
@Override
public void visit(ColumnReference obj) {
String groupName = null;
NamedTable group = obj.getTable();
if (group.getCorrelationName() != null) {
groupName = group.getCorrelationName();
} else {
Table groupID = group.getMetadataObject();
if (groupID.getFullName().equals(visitor.getParentTable().getFullName())) {
groupName = visitor.getParentNamedTable().getCorrelationName();
} else {
groupName = visitor.getQueryNamedTable().getCorrelationName();
}
}
buffer.append(groupName).append(Tokens.DOT).append(getName(obj.getMetadataObject()));
}
@Override
public String getName(AbstractMetadataRecord object) {
return object.getName();
}
};
ssv.append(visitor.getWhereClause());
docFilter = new ComplexDocumentFilter(visitor.getParentNamedTable(), visitor.getQueryNamedTable(), this.metadata, ssv.toString(), action);
}
marshaller = MarshallerBuilder.getMarshaller(table, this.metadata, docFilter);
this.connection.registerMarshaller(marshaller);
// if the message in defined in different cache than the default, switch it out now.
final RemoteCache<Object, Object> cache = InfinispanQueryExecution.getCache(table, connection);
if (visitor.getOperationType() == OperationType.DELETE) {
paginateDeleteResults(cache, visitor.getDeleteQuery(), new Task() {
@Override
public void run(Object row) throws TranslatorException {
if (visitor.isNestedOperation()) {
String childName = ProtobufMetadataProcessor.getMessageName(visitor.getQueryTable());
InfinispanDocument document = (InfinispanDocument) row;
cache.replace(document.getProperties().get(PK), document);
// false below means count that not matched, i.e. deleted count
updateCount = updateCount + document.getUpdateCount(childName, false);
} else {
Object key = ((Object[]) row)[0];
cache.remove(key);
updateCount++;
}
}
}, this.executionContext.getBatchSize());
} else if (visitor.getOperationType() == OperationType.UPDATE) {
paginateUpdateResults(cache, visitor.getUpdateQuery(), new Task() {
@Override
public void run(Object row) throws TranslatorException {
InfinispanDocument previous = (InfinispanDocument) row;
Object key = previous.getProperties().get(PK);
int count = previous.merge(visitor.getInsertPayload());
cache.replace(key, previous);
updateCount = updateCount + count;
}
}, this.executionContext.getBatchSize());
} else if (visitor.getOperationType() == OperationType.INSERT) {
performInsert(visitor, table, cache, false, marshaller);
} else if (visitor.getOperationType() == OperationType.UPSERT) {
performInsert(visitor, table, cache, true, marshaller);
}
} finally {
if (marshaller != null) {
this.connection.unRegisterMarshaller(marshaller);
}
}
}
Aggregations