use of org.teiid.infinispan.api.InfinispanDocument in project teiid by teiid.
the class InfinispanUpdateVisitor method buildTargetDocument.
private InfinispanDocument buildTargetDocument(Table table, boolean addDefaults) throws TranslatorException {
TreeMap<Integer, TableWireFormat> wireMap = MarshallerBuilder.getWireMap(getParentTable(), metadata);
String messageName = ProtobufMetadataProcessor.getMessageName(getParentTable());
InfinispanDocument parentDocument = new InfinispanDocument(messageName, wireMap, null);
// if there are any one-2-one relation build them and add defaults
addDefaults(parentDocument, getParentTable(), addDefaults);
// now create the document at child node, this is one-2-many case
if (!table.equals(getParentTable())) {
messageName = ProtobufMetadataProcessor.getMessageName(table);
int parentTag = ProtobufMetadataProcessor.getParentTag(table);
TableWireFormat twf = wireMap.get(TableWireFormat.buildNestedTag(parentTag));
this.nested = true;
InfinispanDocument child = new InfinispanDocument(messageName, twf.getNestedWireMap(), parentDocument);
addDefaults(child, table, addDefaults);
parentDocument.addChildDocument(messageName, child);
}
return parentDocument;
}
use of org.teiid.infinispan.api.InfinispanDocument in project teiid by teiid.
the class InfinispanUpdateVisitor method getBulkInsertPayload.
Map<Object, InfinispanDocument> getBulkInsertPayload(Insert obj, int batchSize, Iterator<? extends List<Expression>> iter) {
Map<Object, InfinispanDocument> updates = new TreeMap<>();
int count = 0;
while (iter.hasNext()) {
InfinispanDocument doc = buildInsertPayload(obj, iter.next());
updates.put(doc.getIdentifier(), doc);
if (count++ == batchSize) {
break;
}
}
return updates;
}
use of org.teiid.infinispan.api.InfinispanDocument in project teiid by teiid.
the class InfinispanUpdateVisitor method updateDocument.
@SuppressWarnings("unchecked")
private void updateDocument(InfinispanDocument parentDocument, Column column, Object value) throws TranslatorException {
boolean complexObject = this.nested;
InfinispanDocument targetDocument = parentDocument;
int parentTag = ProtobufMetadataProcessor.getParentTag(column);
if (parentTag != -1) {
// this is in one-2-one case. Dummy child will be there due to buildTargetDocument logic.
String messageName = ProtobufMetadataProcessor.getMessageName(column);
InfinispanDocument child = (InfinispanDocument) parentDocument.getChildDocuments(messageName).get(0);
targetDocument = child;
complexObject = true;
} else if (this.nested) {
Table table = (Table) column.getParent();
String messageName = ProtobufMetadataProcessor.getMessageName(table);
InfinispanDocument child = (InfinispanDocument) parentDocument.getChildDocuments(messageName).get(0);
targetDocument = child;
complexObject = true;
}
if (!ProtobufMetadataProcessor.isPseudo(column)) {
if (value instanceof List) {
List<Object> l = (List<Object>) value;
for (Object o : l) {
targetDocument.addArrayProperty(getName(column), o);
}
} else {
targetDocument.addProperty(getName(column), value);
}
String attrName = MarshallerBuilder.getDocumentAttributeName(column, complexObject, this.metadata);
this.updatePayload.put(attrName, value);
}
}
use of org.teiid.infinispan.api.InfinispanDocument in project teiid by teiid.
the class InfinispanUpdateVisitor method addDefaults.
private void addDefaults(InfinispanDocument parentDocument, Table table, boolean addDefaults) throws TranslatorException {
for (Column column : table.getColumns()) {
int parentTag = ProtobufMetadataProcessor.getParentTag(column);
if (parentTag != -1) {
String messageName = ProtobufMetadataProcessor.getMessageName(column);
List<?> children = parentDocument.getChildDocuments(messageName);
InfinispanDocument child = null;
if (children == null || children.isEmpty()) {
TableWireFormat twf = parentDocument.getWireMap().get(TableWireFormat.buildNestedTag(parentTag));
child = new InfinispanDocument(messageName, twf.getNestedWireMap(), parentDocument);
parentDocument.addChildDocument(messageName, child);
} else {
child = (InfinispanDocument) children.get(0);
}
if (addDefaults && column.getDefaultValue() != null) {
child.addProperty(getName(column), column.getDefaultValue());
}
} else {
if (addDefaults && column.getDefaultValue() != null) {
parentDocument.addProperty(getName(column), column.getDefaultValue());
}
}
}
}
use of org.teiid.infinispan.api.InfinispanDocument in project teiid by teiid.
the class TestTeiidTableMarsheller method testWriteSimple.
@Test
public void testWriteSimple() throws Exception {
IckleConversionVisitor visitor = helpExecute("select * from G1");
TeiidTableMarsheller g1WriteMarshaller = new TeiidTableMarsheller(ProtobufMetadataProcessor.getMessageName(visitor.getParentTable()), MarshallerBuilder.getWireMap(visitor.getParentTable(), visitor.getMetadata()));
G1Marshaller g1ReadMarshaller = new G1Marshaller() {
@Override
public void writeTo(ProtoStreamWriter writer, G1 g1) throws IOException {
throw new RuntimeException("Use Teiid marshaller for writing for this test..");
}
};
SerializationContext ctx = ProtobufUtil.newSerializationContext(Configuration.builder().build());
ctx.registerProtoFiles(FileDescriptorSource.fromString("tables.proto", ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("tables.proto"))));
InfinispanDocument g1 = new InfinispanDocument("pm1.G1", MarshallerBuilder.getWireMap(visitor.getParentTable(), visitor.getMetadata()), null);
g1.addProperty("e1", 1);
g1.addProperty("e2", "foo");
g1.addProperty("e3", 1.234f);
g1.addProperty("e4", null);
g1.addArrayProperty("e5", "hello");
g1.addArrayProperty("e5", "world");
// write to buffer
ctx.registerMarshaller(g1WriteMarshaller);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
RawProtoStreamWriter out = RawProtoStreamWriterImpl.newInstance(baos);
WrappedMessage.writeMessage(ctx, out, g1);
out.flush();
baos.flush();
ctx.unregisterMarshaller(g1WriteMarshaller);
// read from buffer
ctx.registerMarshaller(g1ReadMarshaller);
RawProtoStreamReader in = RawProtoStreamReaderImpl.newInstance(baos.toByteArray());
G1 result = WrappedMessage.readMessage(ctx, in);
ctx.unregisterMarshaller(g1ReadMarshaller);
assertEquals(buildG1(), result);
}
Aggregations