use of org.teiid.language.visitor.SQLStringVisitor in project teiid by teiid.
the class AccumuloQueryVisitor method visit.
@Override
public void visit(Select obj) {
visitNodes(obj.getFrom());
visitNodes(obj.getDerivedColumns());
visitNode(obj.getWhere());
visitNode(obj.getGroupBy());
visitNode(obj.getHaving());
visitNode(obj.getOrderBy());
visitNode(obj.getLimit());
if (this.doScanEvaluation) {
HashMap<String, String> options = buildEvaluatorOptions(this.scanTable);
SQLStringVisitor visitor = new SQLStringVisitor() {
@Override
public String getName(AbstractMetadataRecord object) {
return object.getName();
}
};
visitor.append(obj.getWhere());
options.put(EvaluatorIterator.QUERYSTRING, visitor.toString());
IteratorSetting it = new IteratorSetting(1, EvaluatorIterator.class, options);
this.scanIterators.add(it);
}
}
use of org.teiid.language.visitor.SQLStringVisitor 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);
}
}
}
use of org.teiid.language.visitor.SQLStringVisitor in project teiid by teiid.
the class InfinispanQueryExecution method execute.
@Override
public void execute() throws TranslatorException {
try {
if (useAliasCache) {
useModifiedGroups(this.connection, this.executionContext, this.metadata, this.command);
}
final IckleConversionVisitor visitor = new IckleConversionVisitor(metadata, false);
visitor.append(this.command);
Table table = visitor.getParentTable();
String queryStr = visitor.getQuery();
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "SourceQuery:", queryStr);
DocumentFilter docFilter = null;
if (queryStr.startsWith("FROM ") && ((Select) command).getWhere() != null) {
SQLStringVisitor ssv = new SQLStringVisitor() {
@Override
public String getName(AbstractMetadataRecord object) {
return object.getName();
}
};
ssv.append(((Select) command).getWhere());
docFilter = new ComplexDocumentFilter(visitor.getParentNamedTable(), visitor.getQueryNamedTable(), this.metadata, ssv.toString(), Action.ADD);
}
this.marshaller = MarshallerBuilder.getMarshaller(table, this.metadata, docFilter);
this.connection.registerMarshaller(this.marshaller);
// if the message in defined in different cache than the default, switch it out now.
RemoteCache<Object, Object> cache = getCache(table, connection);
results = new InfinispanResponse(cache, queryStr, this.executionContext.getBatchSize(), visitor.getRowLimit(), visitor.getRowOffset(), visitor.getProjectedDocumentAttributes(), visitor.getDocumentNode());
} finally {
this.connection.unRegisterMarshaller(this.marshaller);
}
}
Aggregations