use of org.apache.olingo.client.api.edm.xml.XMLMetadata in project teiid by teiid.
the class TestODataMetadataProcessor method testAssosiationWithReferentialContriant.
@Test
public void testAssosiationWithReferentialContriant() throws Exception {
ODataMetadataProcessor processor = new ODataMetadataProcessor();
MetadataFactory mf = new MetadataFactory("vdb", 1, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
CsdlEntityType g1Entity = entityType("g1");
g1Entity.getProperties().add(createProperty("g2e2", EdmPrimitiveTypeKind.String));
g1Entity.setKey(Arrays.asList(new CsdlPropertyRef().setName("g2e2")));
CsdlEntityType g2Entity = entityType("g2");
CsdlNavigationProperty navProperty = new CsdlNavigationProperty();
navProperty.setName("one_2_one");
navProperty.setType("namespace.g2");
navProperty.setNullable(false);
navProperty.setPartner("PartnerPath");
navProperty.setReferentialConstraints(Arrays.asList(new CsdlReferentialConstraint().setProperty("g2e2").setReferencedProperty("e2")));
g1Entity.setNavigationProperties(Arrays.asList(navProperty));
CsdlEntitySet g1Set = createES("G1", "namespace.g1");
CsdlEntitySet g2Set = createES("G2", "namespace.g2");
CsdlNavigationPropertyBinding navBinding = new CsdlNavigationPropertyBinding();
navBinding.setPath("one_2_one");
navBinding.setTarget("G2");
g1Set.setNavigationPropertyBindings(Arrays.asList(navBinding));
XMLMetadata metadata = buildXmlMetadata(g1Entity, g1Set, g2Entity, g2Set);
processor.getMetadata(mf, metadata);
Table g1 = mf.getSchema().getTable("G1");
Table g2 = mf.getSchema().getTable("G2");
assertNotNull(g1);
assertNotNull(g2);
ForeignKey fk = g1.getForeignKeys().get(0);
assertEquals("G1_one_2_one", fk.getName());
assertNotNull(fk.getColumnByName("g2e2"));
assertEquals("e2", fk.getReferenceColumns().get(0));
}
use of org.apache.olingo.client.api.edm.xml.XMLMetadata in project teiid by teiid.
the class TestODataMetadataProcessor method multipleNavigationProperties.
static MetadataFactory multipleNavigationProperties() throws TranslatorException {
ODataMetadataProcessor processor = new ODataMetadataProcessor();
MetadataFactory mf = new MetadataFactory("vdb", 1, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
CsdlEntityType g1Entity = entityType("g1");
CsdlEntityType g2Entity = entityType("g2");
CsdlEntityType g3Entity = entityType("g3");
CsdlNavigationProperty navProperty = new CsdlNavigationProperty();
navProperty.setName("one_2_many");
navProperty.setType("Collection(namespace.g2)");
navProperty.setNullable(false);
navProperty.setPartner("PartnerPath");
navProperty.setCollection(true);
CsdlNavigationProperty navProperty2 = new CsdlNavigationProperty();
navProperty2.setName("one_2_g3");
navProperty2.setType("namespace.g3");
navProperty2.setNullable(true);
g1Entity.setNavigationProperties(Arrays.asList(navProperty, navProperty2));
CsdlEntitySet g1Set = createES("G1", "namespace.g1");
CsdlEntitySet g2Set = createES("G2", "namespace.g2");
CsdlEntitySet g3Set = createES("G3", "namespace.g3");
CsdlNavigationPropertyBinding navBinding = new CsdlNavigationPropertyBinding();
navBinding.setPath("one_2_many");
navBinding.setTarget("G2");
CsdlNavigationPropertyBinding navBinding2 = new CsdlNavigationPropertyBinding();
navBinding2.setPath("one_2_g3");
navBinding2.setTarget("G3");
g1Set.setNavigationPropertyBindings(Arrays.asList(navBinding, navBinding2));
XMLMetadata metadata = buildXmlMetadata(g1Entity, g1Set, g2Entity, g2Set, g3Entity, g3Set);
processor.getMetadata(mf, metadata);
return mf;
}
use of org.apache.olingo.client.api.edm.xml.XMLMetadata in project teiid by teiid.
the class TestODataMetadataProcessor method createMetadata.
private static MetadataFactory createMetadata(final String file, final String schema, final String schemaNamespace) throws TranslatorException {
ODataMetadataProcessor processor = new ODataMetadataProcessor() {
protected XMLMetadata getSchema(WSConnection conn) throws TranslatorException {
try {
ClientODataDeserializerImpl deserializer = new ClientODataDeserializerImpl(false, ContentType.APPLICATION_XML);
XMLMetadata metadata = deserializer.toMetadata(new FileInputStream(UnitTestUtil.getTestDataFile(file)));
return metadata;
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}
};
Properties props = new Properties();
props.setProperty("schemaNamespace", schemaNamespace);
processor.setSchemaNamespace(schemaNamespace);
MetadataFactory mf = new MetadataFactory("vdb", 1, schema, SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
processor.process(mf, null);
return mf;
}
use of org.apache.olingo.client.api.edm.xml.XMLMetadata in project teiid by teiid.
the class TestODataMetadataProcessor method testSelfJoin.
@Test
public void testSelfJoin() throws Exception {
ODataMetadataProcessor processor = new ODataMetadataProcessor();
MetadataFactory mf = new MetadataFactory("vdb", 1, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
CsdlEntityType g1Entity = entityType("g1");
CsdlNavigationProperty navProperty = new CsdlNavigationProperty();
navProperty.setName("self");
navProperty.setType("Collection(namespace.g1)");
navProperty.setNullable(false);
navProperty.setPartner("PartnerPath");
navProperty.setCollection(true);
g1Entity.setNavigationProperties(Arrays.asList(navProperty));
CsdlEntitySet g1Set = createES("G1", "namespace.g1");
CsdlNavigationPropertyBinding navBinding = new CsdlNavigationPropertyBinding();
navBinding.setPath("self");
navBinding.setTarget("G1");
g1Set.setNavigationPropertyBindings(Arrays.asList(navBinding));
XMLMetadata metadata = buildXmlMetadata(g1Entity, g1Set);
processor.getMetadata(mf, metadata);
Table g1 = mf.getSchema().getTable("G1_self");
assertNotNull(g1);
assertEquals("FK0", g1.getForeignKeys().get(0).getName());
assertNotNull(g1.getForeignKeys().get(0).getColumnByName("G1_e1"));
assertEquals("self", g1.getNameInSource());
}
use of org.apache.olingo.client.api.edm.xml.XMLMetadata in project teiid by teiid.
the class TestODataMetadataProcessor method oneToManyRelationMetadata.
static MetadataFactory oneToManyRelationMetadata() throws TranslatorException {
ODataMetadataProcessor processor = new ODataMetadataProcessor();
MetadataFactory mf = new MetadataFactory("vdb", 1, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
CsdlEntityType g1Entity = entityType("g1");
CsdlEntityType g2Entity = multipleKeyEntityType("g2");
CsdlNavigationProperty navProperty = new CsdlNavigationProperty();
navProperty.setName("one_2_many");
navProperty.setType("Collection(namespace.g2)");
navProperty.setNullable(false);
navProperty.setPartner("PartnerPath");
navProperty.setCollection(true);
g1Entity.setNavigationProperties(Arrays.asList(navProperty));
CsdlEntitySet g1Set = createES("G1", "namespace.g1");
CsdlEntitySet g2Set = createES("G2", "namespace.g2");
CsdlNavigationPropertyBinding navBinding = new CsdlNavigationPropertyBinding();
navBinding.setPath("one_2_many");
navBinding.setTarget("G2");
g1Set.setNavigationPropertyBindings(Arrays.asList(navBinding));
XMLMetadata metadata = buildXmlMetadata(g1Entity, g1Set, g2Entity, g2Set);
processor.getMetadata(mf, metadata);
return mf;
}
Aggregations