Olingo:如何实现CsdlAbstractEdmProvider.getEntityType

时间:2017-11-30 09:00:44

标签: java odata olingo

我正在尝试实现和olingo提供程序类:

public class ResourcesEdmProvider extends CsdlAbstractEdmProvider {}

到目前为止,我已经能够覆盖getEntityType:

@Override
public CsdlEntityType getEntityType(final FullQualifiedName entityTypeName) throws ODataException
{
    if (ET_RESOURCE.equals(entityTypeName)) {
        return new CsdlEntityType()
            .setName(ET_RESOURCE.getName())
            .setKey(Arrays.asList(new CsdlPropertyRef().setName("Id")))
            .setProperties(
                Arrays.asList(
                    new CsdlProperty().setName("Id").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()),
                    new CsdlProperty().setName("TimeStamp").setType(EdmPrimitiveTypeKind.Date.getFullQualifiedName()),
                    new CsdlProperty().setName("ModifiedTimeStamp").setType(EdmPrimitiveTypeKind.Date.getFullQualifiedName()).setMaxLength(4),
                    new CsdlProperty().setName("Price").setType(EdmPrimitiveTypeKind.Decimal.getFullQualifiedName()).setScale(2)
                )   
            ).setNavigationProperties(
                Arrays.asList(
                    new CsdlNavigationProperty()
                        .setName("StringProperties")
                        .setType(CT_STRING_PROPERTY_VALUE)
                        .setCollection(true),
                    new CsdlNavigationProperty()
                        .setName("NumberProperties")
                        .setType(CT_NUMBER_PROPERTY_VALUE)
                        .setCollection(true),
                    new CsdlNavigationProperty()
                        .setName("DateProperties")
                        .setType(CT_DATE_PROPERTY_VALUE)
                        .setCollection(true)
                )
            );
    }

    return null;
}

但是,我不太明白我需要编码才能覆盖:

@Override
public CsdlEntitySet getEntitySet(final FullQualifiedName entityContainer, final String entitySetName) throws ODataException {
}

根据getEntityType目前的实施情况,有人能为我提供一些帮助代码吗?

1 个答案:

答案 0 :(得分:0)

查看documentation

public EntitySet getEntitySet(String entityContainer, String name) throws ODataException {
if (ENTITY_CONTAINER.equals(entityContainer)) {
  if (ENTITY_SET_NAME_CARS.equals(name)) {
    return new EntitySet().setName(name).setEntityType(ENTITY_TYPE_1_1);
  } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(name)) {
    return new EntitySet().setName(name).setEntityType(ENTITY_TYPE_1_2);
  }
}
return null;
}

Chris - 自2014年以来将人们重定向到文档