use of org.teiid.metadata.Table in project teiid by teiid.
the class TestDDLStringVisitor method testSchema.
@Test
public void testSchema() throws Exception {
Database db = new Database("foo", "2");
DataWrapper dw = new DataWrapper("orcle");
db.addDataWrapper(dw);
Server s = new Server("testing");
s.setDataWrapper(dw.getName());
s.setJndiName("java://test-server");
s.setType("orcl");
db.addServer(s);
String table = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar)";
Table t = TestDDLParser.helpParse(table, "SchemaA").getSchema().getTable("G1");
Schema schema = new Schema();
schema.setName("SchemaA");
schema.addTable(t);
schema.addServer(s);
db.addSchema(schema);
String metadataDDL = DDLStringVisitor.getDDLString(db);
String expected = "\n" + "/*\n" + "###########################################\n" + "# START DATABASE foo\n" + "###########################################\n" + "*/\n" + "CREATE DATABASE foo VERSION '2';\n" + "USE DATABASE foo VERSION '2';" + "\n" + "\n--############ Translators ############\n" + "CREATE FOREIGN DATA WRAPPER orcle;\n" + "\n" + "\n--############ Servers ############\n" + "CREATE SERVER testing TYPE 'orcl' FOREIGN DATA WRAPPER orcle OPTIONS (\"jndi-name\" 'java://test-server');\n" + "\n" + "\n--############ Schemas ############\n" + "CREATE SCHEMA SchemaA SERVER testing;\n\n" + "\n--############ Schema:SchemaA ############\n" + "SET SCHEMA SchemaA;\n" + "\n" + "CREATE FOREIGN TABLE G1 (\n" + "\te1 integer,\n" + "\te2 string\n" + ");\n" + "/*\n" + "###########################################\n" + "# END DATABASE foo\n" + "###########################################\n" + "*/\n" + "\n";
assertEquals(expected, metadataDDL);
}
use of org.teiid.metadata.Table in project teiid by teiid.
the class TestMetadataValidator method testSkipDocumentModel.
@Test
public void testSkipDocumentModel() throws Exception {
ModelMetaData model = new ModelMetaData();
model.setName("xmlstuff");
model.setModelType(Model.Type.VIRTUAL);
vdb.addModel(model);
MetadataFactory mf = new MetadataFactory("myVDB", 1, "xmlstuff", TestDDLParser.getDataTypes(), new Properties(), null);
mf.getSchema().setPhysical(false);
Table t = mf.addTable("xmldoctable");
t.setTableType(Table.Type.Document);
mf.addColumn("c1", "string", t);
t.setSelectTransformation("some dummy stuff, should not be validated");
t.setVirtual(true);
Table t2 = mf.addTable("xmldoctable2");
t2.setTableType(Table.Type.XmlMappingClass);
mf.addColumn("c1", "string", t2);
t2.setSelectTransformation("some dummy stuff, should not be validated");
t2.setVirtual(true);
mf.mergeInto(store);
buildTransformationMetadata();
ValidatorReport report = new MetadataValidator().validate(this.vdb, this.store);
assertFalse(printError(report), report.hasItems());
}
use of org.teiid.metadata.Table 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.metadata.Table in project teiid by teiid.
the class ProtobufMetadataProcessor method toTeiidSchema.
private void toTeiidSchema(String name, String contents, MetadataFactory mf, String cacheName) throws TranslatorException {
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Processing Proto file:", name, " with contents\n", contents);
ProtoFile protoFile = ProtoParser.parse(name, contents);
List<MessageElement> messageTypes = filter(protoFile.typeElements(), MessageElement.class);
List<EnumElement> enumTypes = filter(protoFile.typeElements(), EnumElement.class);
// add tables
HashSet<String> deleteTables = new HashSet<>();
for (MessageElement messageElement : messageTypes) {
Table t = addTable(mf, messageTypes, enumTypes, messageElement, null, deleteTables);
if (t != null) {
if (t.getAnnotation() != null && findFromAnnotation(AT_CACHE, t.getAnnotation(), "name") != null) {
t.setProperty(CACHE, findFromAnnotation(AT_CACHE, t.getAnnotation(), "name"));
} else {
// in metadata, as both parent child must be in single cache.
if (getParentTag(t) == -1) {
t.setProperty(CACHE, cacheName);
}
}
}
}
for (String tableName : deleteTables) {
mf.getSchema().removeTable(tableName);
}
}
use of org.teiid.metadata.Table in project teiid by teiid.
the class SchemaToProtobufProcessor method process.
public ProtobufResource process(MetadataFactory metadataFactory, InfinispanConnection connection) throws TranslatorException {
String defaultCacheName = "default";
if (connection != null) {
defaultCacheName = connection.getCache().getName();
}
this.schema = metadataFactory.getSchema();
buffer.append("package ").append(schema.getName()).append(";");
buffer.append(NL);
buffer.append(NL);
for (Table table : schema.getTables().values()) {
visit(table, defaultCacheName);
buffer.append(NL);
buffer.append(NL);
}
for (String name : this.processLater.keySet()) {
visitTable(name, this.processLater.get(name));
}
return new ProtobufResource(schema.getName() + ".proto", buffer.toString());
}
Aggregations