use of org.odata4j.edm.EdmEntitySet 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, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
ArrayList<EdmProperty.Builder> props = new ArrayList<EdmProperty.Builder>();
props.add(EdmProperty.newBuilder("name").setType(EdmSimpleType.STRING).setMaxLength(25));
props.add(EdmProperty.newBuilder("dob").setType(EdmSimpleType.DATETIME).setNullable(true));
props.add(EdmProperty.newBuilder("ssn").setType(EdmSimpleType.INT64).setNullable(false));
EdmEntityType.Builder entity = EdmEntityType.newBuilder().addProperties(props).addKeys("ssn");
EdmEntitySet es = EdmEntitySet.newBuilder().setName("Person").setEntityType(entity).build();
processor.addEntitySetAsTable(mf, es);
assertNotNull(mf.getSchema().getTable("Person"));
Table person = mf.getSchema().getTable("Person");
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.odata4j.edm.EdmEntitySet 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);
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.ONE);
EdmAssociationEnd.Builder aend2 = EdmAssociationEnd.newBuilder().setRole("target").setType(g2Entity).setMultiplicity(EdmMultiplicity.ONE);
EdmReferentialConstraint.Builder refContraint = EdmReferentialConstraint.newBuilder().addPrincipalReferences("g2e2").setPrincipalRole("source").addDependentReferences("e1").setDependentRole("target");
EdmAssociation.Builder assocition = EdmAssociation.newBuilder().setNamespace("namspace").setName("one_2_one").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();
Table t1 = processor.addEntitySetAsTable(mf, g1Set);
Table t2 = processor.addEntitySetAsTable(mf, g2Set);
KeyRecord record = new KeyRecord(Type.Unique);
record.addColumn(t1.getColumnByName("g2e2"));
t1.setUniqueKeys(Arrays.asList(record));
processor.addNavigationRelations(mf, "G2", g2Entity.build());
Table g1 = mf.getSchema().getTable("G1");
Table g2 = mf.getSchema().getTable("G2");
assertNotNull(g1);
assertNotNull(g2);
ForeignKey fk = g1.getForeignKeys().get(0);
assertEquals("one_2_one", fk.getName());
assertNotNull(fk.getColumnByName("g2e2"));
assertEquals("e1", fk.getReferenceColumns().get(0));
}
use of org.odata4j.edm.EdmEntitySet in project teiid by teiid.
the class ODataUpdateExecution method buildPayload.
private String buildPayload(String entitySet, final List<OProperty<?>> props, EdmDataServices edm) {
// this is remove the teiid specific model name from the entity type name.
final EdmEntitySet ees = ODataEntitySchemaBuilder.removeModelName(edm.getEdmEntitySet(entitySet));
Entry entry = new Entry() {
public String getUri() {
return null;
}
public OEntity getEntity() {
return OEntities.createRequest(ees, props, null);
}
};
StringWriter sw = new StringWriter();
// $NON-NLS-1$
FormatWriter<Entry> fw = FormatWriterFactory.getFormatWriter(Entry.class, null, "ATOM", null);
fw.write(null, sw, entry);
return sw.toString();
}
Aggregations