Search in sources :

Example 6 with EdmEntitySet

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());
}
Also used : Table(org.teiid.metadata.Table) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Column(org.teiid.metadata.Column) ArrayList(java.util.ArrayList) EdmEntityType(org.odata4j.edm.EdmEntityType) EdmEntitySet(org.odata4j.edm.EdmEntitySet) Properties(java.util.Properties) EdmProperty(org.odata4j.edm.EdmProperty) Test(org.junit.Test)

Example 7 with EdmEntitySet

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));
}
Also used : EdmAssociationEnd(org.odata4j.edm.EdmAssociationEnd) Table(org.teiid.metadata.Table) EdmReferentialConstraint(org.odata4j.edm.EdmReferentialConstraint) EdmEntityType(org.odata4j.edm.EdmEntityType) EdmNavigationProperty(org.odata4j.edm.EdmNavigationProperty) Properties(java.util.Properties) ForeignKey(org.teiid.metadata.ForeignKey) KeyRecord(org.teiid.metadata.KeyRecord) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) EdmAssociation(org.odata4j.edm.EdmAssociation) EdmEntitySet(org.odata4j.edm.EdmEntitySet) Test(org.junit.Test)

Example 8 with EdmEntitySet

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();
}
Also used : Entry(org.odata4j.format.Entry) StringWriter(java.io.StringWriter) EdmEntitySet(org.odata4j.edm.EdmEntitySet)

Aggregations

EdmEntitySet (org.odata4j.edm.EdmEntitySet)8 Properties (java.util.Properties)7 Test (org.junit.Test)7 MetadataFactory (org.teiid.metadata.MetadataFactory)7 Table (org.teiid.metadata.Table)7 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)7 EdmEntityType (org.odata4j.edm.EdmEntityType)5 EdmAssociation (org.odata4j.edm.EdmAssociation)4 EdmAssociationEnd (org.odata4j.edm.EdmAssociationEnd)4 EdmNavigationProperty (org.odata4j.edm.EdmNavigationProperty)4 ForeignKey (org.teiid.metadata.ForeignKey)4 EdmReferentialConstraint (org.odata4j.edm.EdmReferentialConstraint)2 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 EdmProperty (org.odata4j.edm.EdmProperty)1 Entry (org.odata4j.format.Entry)1 Column (org.teiid.metadata.Column)1 KeyRecord (org.teiid.metadata.KeyRecord)1