use of org.teiid.metadata.MetadataFactory in project teiid by teiid.
the class TestODataMetadataProcessor method testManytoManyAssosiationWithReferntialConstraint.
@Test
public void testManytoManyAssosiationWithReferntialConstraint() throws Exception {
ODataMetadataProcessor processor = new ODataMetadataProcessor();
MetadataFactory mf = new MetadataFactory("vdb", 1, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
EdmEntityType.Builder g1Entity = entityType("g1");
g1Entity.addProperties(EdmProperty.newBuilder("g2e2").setType(EdmSimpleType.STRING).setNullable(false));
EdmEntityType.Builder g2Entity = entityType("g2");
EdmAssociationEnd.Builder aend1 = EdmAssociationEnd.newBuilder().setRole("source").setType(g1Entity).setMultiplicity(EdmMultiplicity.MANY);
EdmAssociationEnd.Builder aend2 = EdmAssociationEnd.newBuilder().setRole("target").setType(g2Entity).setMultiplicity(EdmMultiplicity.MANY);
EdmReferentialConstraint.Builder refContraint = EdmReferentialConstraint.newBuilder().addPrincipalReferences("e1").addDependentReferences("g2e2");
EdmAssociation.Builder assocition = EdmAssociation.newBuilder().setNamespace("namspace").setName("m_2_m").setEnds(aend2, aend1).setRefConstraint(refContraint);
EdmNavigationProperty.Builder navigation = EdmNavigationProperty.newBuilder("g1").setFromTo(aend2, aend1).setFromToName("source", "target").setRelationship(assocition);
g2Entity.addNavigationProperties(navigation);
EdmEntitySet g1Set = EdmEntitySet.newBuilder().setName("G1").setEntityType(g1Entity).build();
EdmEntitySet g2Set = EdmEntitySet.newBuilder().setName("G2").setEntityType(g2Entity).build();
processor.addEntitySetAsTable(mf, g1Set);
processor.addEntitySetAsTable(mf, g2Set);
processor.addNavigationRelations(mf, "G2", g2Entity.build());
Table g1 = mf.getSchema().getTable("G1");
Table g2 = mf.getSchema().getTable("G2");
Table linkTable = mf.getSchema().getTable("m_2_m");
assertEquals(2, linkTable.getColumns().size());
assertEquals("e1", linkTable.getColumns().get(0).getName());
assertEquals("g2e2", linkTable.getColumns().get(1).getName());
assertNotNull(linkTable);
assertEquals("G2,G1", linkTable.getProperty(ODataMetadataProcessor.LINK_TABLES, false));
ForeignKey fk = linkTable.getForeignKeys().get(0);
assertEquals("G2_FK", fk.getName());
assertNotNull(fk.getColumnByName("e1"));
ForeignKey fk2 = linkTable.getForeignKeys().get(1);
assertEquals("G1_FK", fk2.getName());
assertNotNull(fk2.getColumnByName("g2e2"));
}
use of org.teiid.metadata.MetadataFactory in project teiid by teiid.
the class TestODataMetadataProcessor method testEnititySetWithComplexType.
@Test
public void testEnititySetWithComplexType() throws Exception {
ODataMetadataProcessor processor = new ODataMetadataProcessor();
MetadataFactory mf = new MetadataFactory("vdb", 1, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
EdmEntitySet es = EdmEntitySet.newBuilder().setName("Person").setEntityType(buildPersonEntity(buildAddressEntity().build())).build();
processor.addEntitySetAsTable(mf, es);
assertEquals(1, mf.getSchema().getTables().size());
assertNotNull(mf.getSchema().getTable("Person"));
Table personTable = mf.getSchema().getTable("Person");
assertEquals(5, personTable.getColumns().size());
assertNotNull(personTable.getColumnByName("address_street"));
}
use of org.teiid.metadata.MetadataFactory in project teiid by teiid.
the class TestODataMetadataProcessor method testOneToOneAssosiation.
@Test
public void testOneToOneAssosiation() throws Exception {
ODataMetadataProcessor processor = new ODataMetadataProcessor();
MetadataFactory mf = new MetadataFactory("vdb", 1, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
EdmEntityType.Builder g1Entity = entityType("g1");
EdmEntityType.Builder g2Entity = entityType("g2");
EdmAssociationEnd.Builder aend1 = EdmAssociationEnd.newBuilder().setRole("source").setType(g1Entity).setMultiplicity(EdmMultiplicity.ONE);
EdmAssociationEnd.Builder aend2 = EdmAssociationEnd.newBuilder().setRole("target").setType(g2Entity).setMultiplicity(EdmMultiplicity.ONE);
EdmAssociation.Builder assocition = EdmAssociation.newBuilder().setNamespace("namspace").setName("one_2_one").setEnds(aend2, aend1);
EdmNavigationProperty.Builder navigation = EdmNavigationProperty.newBuilder("g1").setFromTo(aend2, aend1).setFromToName("source", "target").setRelationship(assocition);
g2Entity.addNavigationProperties(navigation);
EdmEntitySet g1Set = EdmEntitySet.newBuilder().setName("G1").setEntityType(g1Entity).build();
processor.addEntitySetAsTable(mf, g1Set);
EdmEntitySet g2Set = EdmEntitySet.newBuilder().setName("G2").setEntityType(g2Entity).build();
processor.addEntitySetAsTable(mf, g2Set);
processor.addNavigationRelations(mf, "G2", g2Entity.build());
Table g1 = mf.getSchema().getTable("G1");
Table g2 = mf.getSchema().getTable("G2");
ForeignKey fk = g1.getForeignKeys().get(0);
assertEquals("one_2_one", fk.getName());
assertNotNull(fk.getColumnByName("e1"));
}
use of org.teiid.metadata.MetadataFactory in project teiid by teiid.
the class TestODataMetadataProcessor method testSchema.
@Test
public void testSchema() throws Exception {
translator = new ODataExecutionFactory();
translator.start();
String csdl = ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("northwind.xml"));
ODataMetadataProcessor processor = new ODataMetadataProcessor();
Properties props = new Properties();
props.setProperty("schemaNamespace", "ODataWeb.Northwind.Model");
props.setProperty("entityContainer", "NorthwindEntities");
MetadataFactory mf = new MetadataFactory("vdb", 1, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
processor.getMetadata(mf, new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new InputStreamReader(new ByteArrayInputStream(csdl.getBytes())))));
TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "northwind", new FunctionTree("foo", new UDFSource(translator.getPushDownFunctions())));
ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
if (report.hasItems()) {
throw new RuntimeException(report.getFailureMessage());
}
String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
// System.out.println(ddl);
MetadataFactory mf2 = new MetadataFactory("vdb", 1, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
QueryParser.getQueryParser().parseDDL(mf2, ddl);
Procedure p = mf.getSchema().getProcedure("executeVoid");
assertNotNull(p);
assertEquals(1, p.getParameters().size());
}
use of org.teiid.metadata.MetadataFactory in project teiid by teiid.
the class TestODataQueryExecution method testArrayType.
@Test
public void testArrayType() throws Exception {
ModelMetaData model = new ModelMetaData();
model.setName("nw");
model.setModelType(Type.PHYSICAL);
MetadataFactory mf = new MetadataFactory("northwind", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), model);
EdmDataServices edm = new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new FileReader(UnitTestUtil.getTestDataFile("arraytest.xml"))));
ODataMetadataProcessor metadataProcessor = new ODataMetadataProcessor();
// $NON-NLS-1$
PropertiesUtils.setBeanProperties(metadataProcessor, mf.getModelProperties(), "importer");
metadataProcessor.getMetadata(mf, edm);
Column c = mf.getSchema().getTable("G2").getColumnByName("e3");
assertEquals("integer[]", c.getRuntimeType());
Procedure p = mf.getSchema().getProcedure("ARRAYITERATE");
assertEquals("varbinary[]", p.getParameters().get(0).getRuntimeType());
assertEquals("varbinary", p.getResultSet().getColumns().get(0).getRuntimeType());
String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
TransformationMetadata metadata = RealMetadataFactory.fromDDL(ddl, "northwind", "nw");
String query = "SELECT * FROM G2";
String expectedURL = "G2?$select=e1,e3";
String result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<feed xmlns=\"http://www.w3.org/2005/Atom\" xmlns:d=\"http://schemas.microsoft.com/ado/2007/08/dataservices\" xmlns:m=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\" xml:base=\"http://localhost:8080/odata/loopy/\">\n" + " <title type=\"text\">VM1.x</title>\n" + " <id>http://localhost:8080/odata/loopy/VM1.x</id>\n" + " <updated>2015-10-14T19:36:58Z</updated>\n" + " <link rel=\"self\" title=\"VM1.x\" href=\"VM1.x\" />\n" + " <entry>\n" + " <id>http://localhost:8080/odata/loopy/VM1.x('x')</id>\n" + " <title type=\"text\" />\n" + " <updated>2015-10-14T19:36:58Z</updated>\n" + " <author>\n" + " <name />\n" + " </author>\n" + " <link rel=\"edit\" title=\"x\" href=\"VM1.x('x')\" />\n" + " <category term=\"PM1.G2\" scheme=\"http://schemas.microsoft.com/ado/2007/08/dataservices/scheme\" />\n" + " <content type=\"application/xml\">\n" + " <m:properties>\n" + " <d:e1>32</d:e1>\n" + " <d:e3 m:type=\"Collection(Edm.Int32)\">\n" + " <d:element>1</d:element>\n" + " <d:element>2</d:element>\n" + " <d:element>3</d:element>\n" + " </d:e3>\n" + " </m:properties>\n" + " </content>\n" + " </entry>\n" + "</feed>";
ResultSetExecution excution = helpExecute(query, result, expectedURL, 200, metadata);
assertArrayEquals(new Object[] { 32, new Integer[] { 1, 2, 3 } }, excution.next().toArray(new Object[2]));
}
Aggregations