static MetadataFactory oneToOneRelationMetadata() 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"); CsdlNavigationProperty navProperty = new CsdlNavigationProperty(); navProperty.setName("one_2_one"); navProperty.setType("namespace.g2"); navProperty.setNullable(false); navProperty.setPartner("PartnerPath"); 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); return mf; }
@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()); }
private CsdlEntityType buildBusinessEntity(CsdlComplexType address) { ArrayList<CsdlProperty> properties = new ArrayList<CsdlProperty>(); properties.add(createProperty("name", EdmPrimitiveTypeKind.String).setMaxLength(25)); properties.add(new CsdlProperty().setName("address").setType(address.getName())); CsdlEntityType entityType = new CsdlEntityType(); entityType.setName("Business"); entityType.setProperties(properties); entityType.setKey(Arrays.asList(new CsdlPropertyRef().setName("name"))); return entityType; }
static CsdlEntityType entityType(String name) { ArrayList<CsdlProperty> properties = new ArrayList<CsdlProperty>(); properties.add(createProperty("e1", EdmPrimitiveTypeKind.Int32)); properties.add(createProperty("e2", EdmPrimitiveTypeKind.String).setNullable(false)); CsdlEntityType entityType = new CsdlEntityType(); entityType.setName(name); entityType.setProperties(properties); entityType.setKey(Arrays.asList(new CsdlPropertyRef().setName("e1"))); return entityType; }
static CsdlEntityType buildPersonEntity(CsdlComplexType address) { ArrayList<CsdlProperty> properties = new ArrayList<CsdlProperty>(); properties.add(createProperty("name", EdmPrimitiveTypeKind.String).setMaxLength(25)); properties.add(createProperty("ssn", EdmPrimitiveTypeKind.Int64).setNullable(false)); properties.add(new CsdlProperty().setName("address").setType(address.getName())); properties.add(new CsdlProperty().setName("secondaddress").setType(address.getName())); CsdlEntityType entityType = new CsdlEntityType(); entityType.setName("Person"); entityType.setProperties(properties); entityType.setKey(Arrays.asList(new CsdlPropertyRef().setName("ssn"))); return entityType; }
@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 = g2.getForeignKeys().get(0); assertEquals("one_2_one", fk.getName()); assertNotNull(fk.getColumnByName("e2")); assertEquals("g2e2", fk.getReferenceColumns().get(0)); }
@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("self", g1.getForeignKeys().get(0).getName()); assertNotNull(g1.getForeignKeys().get(0).getColumnByName("G1_e1")); assertEquals("self", g1.getNameInSource()); }