Search code examples
odataolingo

Olingo: EntityContainer and EntitySets differences


I'm reading this documentation in order to figure out how to create an odata service.

I don't quite figure out what are EntityContainer and EntitySet for...

[EDIT]

I'd like to ask for a misunderstanding I don't quite figure out yet. If a EntitySet straightforwardly is a set of entities:

Why do I need to implement a EntitySet CsdlAbstractEdmProvider.getEntitySet() method on my OData provider? As you can see on here I need to implement this method that returns an EntitySet. This is the implementation on Olingo documentation:

public CsdlEntitySet getEntitySet(FullQualifiedName entityContainer, String entitySetName) {

  if(entityContainer.equals(CONTAINER)){
    if(entitySetName.equals(ES_PRODUCTS_NAME)){
      CsdlEntitySet entitySet = new CsdlEntitySet();
      entitySet.setName(ES_PRODUCTS_NAME);
      entitySet.setType(ET_PRODUCT_FQN);

      return entitySet;
    }
  }

  return null;
}

I don't quite figure out what's this implementation for.

By other hand, on EntityCollectionProcessor documentation implementation you can see they are using EntitySet as well.

I don't understand which are the differences between both EntitySet inside a Provider and inside Processor.

I don't know if I've explained so well


Solution

  • Based on the OData documentation, section 4.1:

    The central concepts in the EDM are entities and associations. Entities are instances of Entity Types (for example, Customer, Employee, and so on) which are structured records consisting of named and typed properties and with a key. Complex Types are structured types also consisting of a list of properties but with no key, and thus can only exist as a property of a containing entity or as a temporary value. An Entity Key is formed from a subset of properties of the Entity Type. The Entity Key (for example, CustomerId or OrderId) is a fundamental concept for uniquely identifying instances of Entity Types and allowing Entity Type instances to participate in relationships. Entities are grouped in Entity Sets (for example, Customers is a set of Customer Entity Type instances).

    Associations define the relationship between two or more Entity Types (for example, Employee WorksFor Department). Instances of associations are grouped in Association Sets. Navigation Properties are special properties on Entity Types which are bound to a specific association and can be used to refer to associations of an entity.

    Finally, all instance containers (Entity Sets and Association Sets) are grouped in an Entity Container.

    Summary:

    • An EntitySet is a set of Entity. Typically, an EntitySet is a business object; to use a relational database comparison, think of an EntitySet as a table and an Entity as a row in that table.
    • An EntityContainer is exactly that, a container for EntitySets and Associations. Roughly, you can think of it as a database which contains your tables, views, etc.

    Hope this helps.

    EDIT, following your question change:

    The difference between the Provider.getEntitySet() method and the Processor.getEntitySet() comes down to differences in the purpose of the Provider and the Processor classes.

    • The Provider class defines the structure and metadata of your OData service. The getEntitySet method defines the structure (name and type) of each entity set.
    • The Processor class is the servlet for your OData service, essentially. Here, HTTP requests are parsed, processed and redirected (to your service or DAO layer). The getEntitySet method, in the processor, is used to process requests of this structure: (host and port)/(service root.svc)/(MyEntitySet), for example: http://services.odata.org/V3/Northwind/Northwind.svc/Customers. In this method, determine which entity set has been asked for, then call your DAO to fetch your data accordingly.