use of org.teiid.metadata.MetadataFactory in project teiid by teiid.
the class TestSQLConversionVisitor method queryMetadataInterface.
private static TransformationMetadata queryMetadataInterface() {
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("prestodbModel");
MetadataFactory mf = new MetadataFactory("prestodb", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), mmd);
mf.setParser(new QueryParser());
mf.parse(new FileReader(UnitTestUtil.getTestDataFile("sample.ddl")));
TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "x");
ValidatorReport report = new MetadataValidator().validate(tm.getVdbMetaData(), tm.getMetadataStore());
if (report.hasItems()) {
throw new RuntimeException(report.getFailureMessage());
}
return tm;
} catch (MetadataException | FileNotFoundException e) {
throw new RuntimeException(e);
}
}
use of org.teiid.metadata.MetadataFactory in project teiid by teiid.
the class TestODataMetadataProcessor method multiplePKMetadata.
static MetadataFactory multiplePKMetadata() throws TranslatorException {
ODataMetadataProcessor processor = new ODataMetadataProcessor();
MetadataFactory mf = new MetadataFactory("vdb", 1, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
CsdlEntityType entityType = multipleKeyEntityType("g1");
CsdlEntitySet entitySet = createES("G1", "namespace.g1");
XMLMetadata metadata = buildXmlMetadata(entityType, entitySet);
processor.getMetadata(mf, metadata);
return mf;
}
use of org.teiid.metadata.MetadataFactory in project teiid by teiid.
the class TestODataMetadataProcessor method testEnititySet.
@Test
public void testEnititySet() throws Exception {
ODataMetadataProcessor processor = new ODataMetadataProcessor();
MetadataFactory mf = new MetadataFactory("vdb", 1, "trippin", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
ArrayList<CsdlProperty> properties = new ArrayList<CsdlProperty>();
properties.add(createProperty("name", EdmPrimitiveTypeKind.String).setMaxLength(25).setNullable(false));
properties.add(createProperty("dob", EdmPrimitiveTypeKind.DateTimeOffset).setNullable(true));
properties.add(createProperty("ssn", EdmPrimitiveTypeKind.Int64).setNullable(false));
CsdlEntityType entityType = new CsdlEntityType();
entityType.setName("Person");
entityType.setProperties(properties);
entityType.setKey(Arrays.asList(new CsdlPropertyRef().setName("ssn")));
CsdlEntitySet es = createES("Persons", "namespace.Person");
XMLMetadata metadata = buildXmlMetadata(es, entityType);
processor.getMetadata(mf, metadata);
assertNotNull(mf.getSchema().getTable("Persons"));
Table person = mf.getSchema().getTable("Persons");
assertEquals(3, person.getColumns().size());
assertNotNull(person.getColumnByName("name"));
assertNotNull(person.getColumnByName("dob"));
assertNotNull(person.getColumnByName("ssn"));
Column name = person.getColumnByName("name");
Column dob = person.getColumnByName("dob");
Column ssn = person.getColumnByName("ssn");
assertEquals("string", name.getDatatype().getRuntimeTypeName());
assertEquals("timestamp", dob.getDatatype().getRuntimeTypeName());
assertEquals("long", ssn.getDatatype().getRuntimeTypeName());
assertTrue(name.getNullType() == NullType.No_Nulls);
assertTrue(dob.getNullType() == NullType.Nullable);
assertTrue(ssn.getNullType() == NullType.No_Nulls);
assertEquals(25, name.getLength());
assertNotNull(person.getPrimaryKey());
assertEquals(1, person.getPrimaryKey().getColumns().size());
assertEquals("ssn", person.getPrimaryKey().getColumns().get(0).getName());
assertTrue(person.getForeignKeys().isEmpty());
}
use of org.teiid.metadata.MetadataFactory in project teiid by teiid.
the class TestODataMetadataProcessor method actionMetadata.
static MetadataFactory actionMetadata(String name, CsdlReturnType returnType, Object other) throws TranslatorException {
ODataMetadataProcessor processor = new ODataMetadataProcessor();
MetadataFactory mf = new MetadataFactory("vdb", 1, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
CsdlAction func = action(name, returnType);
CsdlActionImport funcImport = new CsdlActionImport();
funcImport.setAction(new FullQualifiedName("namespace." + name));
funcImport.setName(name);
XMLMetadata metadata = buildXmlMetadata(funcImport, func, other);
processor.getMetadata(mf, metadata);
return mf;
}
use of org.teiid.metadata.MetadataFactory in project teiid by teiid.
the class TestODataMetadataProcessor method testOneToOneAssosiation.
@Test
public void testOneToOneAssosiation() throws Exception {
MetadataFactory mf = oneToOneRelationMetadata(true);
Table g1 = mf.getSchema().getTable("G1");
Table g2 = mf.getSchema().getTable("G2");
ForeignKey fk = g1.getForeignKeys().get(0);
assertEquals("G2_one_2_one", fk.getName());
assertNotNull(fk.getColumnByName("e1"));
fk = g2.getForeignKeys().get(0);
assertEquals("G1_one_2_one", fk.getName());
assertNotNull(fk.getColumnByName("e1"));
mf = oneToOneRelationMetadata(false);
g1 = mf.getSchema().getTable("G1");
g2 = mf.getSchema().getTable("G2");
fk = g1.getForeignKeys().get(0);
assertEquals("G2_one_2_one", fk.getName());
assertNotNull(fk.getColumnByName("e1"));
// TODO: could infer this, but for now it's not in the metadata
assertTrue(g2.getForeignKeys().isEmpty());
}
Aggregations