use of org.odata4j.edm.EdmEntitySet in project teiid by teiid.
the class TestODataMetadataProcessor method testManytoManyAssosiation.
@Test
public void testManytoManyAssosiation() 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.MANY);
EdmAssociationEnd.Builder aend2 = EdmAssociationEnd.newBuilder().setRole("target").setType(g2Entity).setMultiplicity(EdmMultiplicity.MANY);
EdmAssociation.Builder assocition = EdmAssociation.newBuilder().setNamespace("namspace").setName("m_2_m").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();
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(1, linkTable.getColumns().size());
assertEquals("e1", linkTable.getColumns().get(0).getName());
assertNotNull(linkTable);
assertEquals("G2,G1", linkTable.getProperty(ODataMetadataProcessor.LINK_TABLES, false));
ForeignKey fk1 = linkTable.getForeignKeys().get(0);
assertEquals("G2_FK", fk1.getName());
assertNotNull(fk1.getColumnByName("e1"));
ForeignKey fk2 = linkTable.getForeignKeys().get(1);
assertEquals("G1_FK", fk2.getName());
assertNotNull(fk2.getColumnByName("e1"));
}
use of org.odata4j.edm.EdmEntitySet 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.odata4j.edm.EdmEntitySet 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.odata4j.edm.EdmEntitySet 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.odata4j.edm.EdmEntitySet in project teiid by teiid.
the class TestODataMetadataProcessor method testMultipleEnititySetWithSameComplexType.
@Test
public void testMultipleEnititySetWithSameComplexType() 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);
es = EdmEntitySet.newBuilder().setName("Business").setEntityType(buildBusinessEntity(buildAddressEntity().build())).build();
processor.addEntitySetAsTable(mf, es);
assertEquals(2, mf.getSchema().getTables().size());
assertNotNull(mf.getSchema().getTable("Person"));
assertNotNull(mf.getSchema().getTable("Business"));
Table personTable = mf.getSchema().getTable("Person");
assertEquals(5, personTable.getColumns().size());
Table businessTable = mf.getSchema().getTable("Business");
assertEquals(4, businessTable.getColumns().size());
assertNotNull(personTable.getColumnByName("address_street"));
assertNotNull(businessTable.getColumnByName("address_street"));
}
Aggregations