use of org.teiid.infinispan.api.TableWireFormat 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.TableWireFormat 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.TableWireFormat in project teiid by teiid.
the class MarshallerBuilder method buildWireMap.
private static TreeMap<Integer, TableWireFormat> buildWireMap(Table table, boolean nested, RuntimeMetadata metadata) throws TranslatorException {
TreeMap<Integer, TableWireFormat> wireMap = new TreeMap<>();
for (Column column : table.getColumns()) {
if (ProtobufMetadataProcessor.getPseudo(column) != null) {
continue;
}
int parentTag = ProtobufMetadataProcessor.getParentTag(column);
if (parentTag == -1) {
// normal columns
int tag = ProtobufMetadataProcessor.getTag(column);
String name = getDocumentAttributeName(column, nested, metadata);
TableWireFormat twf = new TableWireFormat(name, tag, column);
wireMap.put(twf.getReadTag(), twf);
} else {
// columns from one 2 one relation
int tag = ProtobufMetadataProcessor.getTag(column);
String name = getDocumentAttributeName(column, true, metadata);
TableWireFormat child = new TableWireFormat(name, tag, column);
String parentName = ProtobufMetadataProcessor.getMessageName(column);
TableWireFormat parent = null;
TableWireFormat existing = wireMap.get(TableWireFormat.buildNestedTag(parentTag));
if (existing == null) {
parent = new TableWireFormat(parentName, parentTag);
wireMap.put(parent.getReadTag(), parent);
} else {
parent = existing;
}
parent.addNested(child);
}
}
return wireMap;
}
use of org.teiid.infinispan.api.TableWireFormat in project teiid by teiid.
the class TestProtobufMetadataProcessor method testTableWireFormat.
@Test
public void testTableWireFormat() throws Exception {
MetadataFactory mf = protoMatadata("tables.proto");
InfinispanExecutionFactory ef = new InfinispanExecutionFactory();
TransformationMetadata metadata = getTransformationMetadata(mf, ef);
TreeMap<Integer, TableWireFormat> map = MarshallerBuilder.getWireMap(mf.getSchema().getTable("G2"), new RuntimeMetadataImpl(metadata));
String expected = "{8=TableWireFormat [expectedTag=8, attributeName=e1, nested=null], " + "18=TableWireFormat [expectedTag=18, attributeName=e2, nested=null], " + "42=TableWireFormat [expectedTag=42, attributeName=pm1.G3, nested={" + "8=TableWireFormat [expectedTag=8, attributeName=pm1.G2/pm1.G3/e1, nested=null], " + "18=TableWireFormat [expectedTag=18, attributeName=pm1.G2/pm1.G3/e2, nested=null]}], " + "50=TableWireFormat [expectedTag=50, attributeName=pm1.G4, nested={" + "8=TableWireFormat [expectedTag=8, attributeName=pm1.G2/pm1.G4/e1, nested=null], " + "18=TableWireFormat [expectedTag=18, attributeName=pm1.G2/pm1.G4/e2, nested=null]}], " + "58=TableWireFormat [expectedTag=58, attributeName=e5, nested=null], " + "65=TableWireFormat [expectedTag=65, attributeName=e6, nested=null]}";
assertEquals(expected, map.toString());
}
use of org.teiid.infinispan.api.TableWireFormat in project teiid by teiid.
the class TestTeiidTableMarsheller method buildG2.
private InfinispanDocument buildG2(IckleConversionVisitor visitor) throws TranslatorException {
TreeMap<Integer, TableWireFormat> wireMap = MarshallerBuilder.getWireMap(visitor.getParentTable(), visitor.getMetadata());
InfinispanDocument g2 = new InfinispanDocument("pm1.G2", wireMap, null);
g2.addProperty("e1", 1);
g2.addProperty("e2", "foo");
InfinispanDocument g3 = new InfinispanDocument("pm1.G3", getWireMap(wireMap, "pm1.G3"), g2);
g3.addProperty("e1", 1);
g3.addProperty("e2", "bar");
g2.addChildDocument("pm1.G3", g3);
InfinispanDocument g41 = new InfinispanDocument("pm1.G4", getWireMap(wireMap, "pm1.G4"), g2);
g41.addProperty("e1", 1);
g41.addProperty("e2", "hello");
g2.addChildDocument("pm1.G4", g41);
InfinispanDocument g42 = new InfinispanDocument("pm1.G4", getWireMap(wireMap, "pm1.G4"), g2);
g42.addProperty("e1", 2);
g42.addProperty("e2", "world");
g2.addChildDocument("pm1.G4", g42);
g2.addProperty("e5", "Hello Infinispan");
g2.addProperty("e6", new Timestamp(1489835322801L));
return g2;
}
Aggregations