use of org.teiid.language.Insert in project teiid by teiid.
the class InfinispanUpdateExecution method performInsert.
@SuppressWarnings("unchecked")
private void performInsert(final InfinispanUpdateVisitor visitor, Table table, final RemoteCache<Object, Object> cache, boolean upsert, TeiidTableMarsheller marshaller) throws TranslatorException {
Insert insert = (Insert) this.command;
if (visitor.isNestedOperation()) {
InfinispanDocument previous = null;
if (visitor.getIdentity() != null) {
previous = (InfinispanDocument) cache.get(visitor.getIdentity());
}
if (insert.getParameterValues() != null) {
throw new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25017, table.getName(), visitor.getParentTable().getName()));
}
if (previous == null) {
throw new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25009, table.getName(), visitor.getIdentity()));
}
String childName = ProtobufMetadataProcessor.getMessageName(visitor.getQueryTable());
previous.addChildDocument(childName, visitor.getInsertPayload().getChildDocuments(childName).get(0));
if (upsert) {
previous = (InfinispanDocument) cache.replace(visitor.getIdentity(), previous);
} else {
previous = (InfinispanDocument) cache.put(visitor.getIdentity(), previous);
}
this.updateCount++;
} else {
if (insert.getParameterValues() == null) {
insertRow(cache, visitor.getIdentity(), visitor.getInsertPayload(), upsert);
this.updateCount++;
} else {
boolean putAll = false;
if (this.executionContext.getSourceHint() != null) {
putAll = this.executionContext.getSourceHint().indexOf("use-putall") != -1;
}
// bulk insert
int batchSize = this.executionContext.getBatchSize();
Iterator<? extends List<Expression>> args = (Iterator<? extends List<Expression>>) insert.getParameterValues();
while (true) {
Map<Object, InfinispanDocument> rows = visitor.getBulkInsertPayload(insert, batchSize, args);
if (rows.isEmpty()) {
break;
}
if (putAll) {
BulkInsert bi = new UsePutAll(cache);
bi.run(rows, false);
} else {
BulkInsert bi = new OneAtATime(cache);
bi.run(rows, upsert);
}
this.updateCount += rows.size();
}
}
}
}
Aggregations