public class

InMemoryProducer

extends Object
implements ODataProducer
java.lang.Object
   ↳ org.odata4j.producer.inmemory.InMemoryProducer

Class Overview

An in-memory implementation of an ODATA Producer. Uses the standard Java bean and property model to access information within entities.

Summary

Constants
int DEFAULT_MAX_RESULTS
String ID_PROPNAME
Fields
private final String containerName
private final EdmDecorator decorator
private final Map<String, InMemoryEntityInfo<?>> eis
private final int maxResults
private EdmDataServices metadata
private final MetadataProducer metadataProducer
private final String namespace
private final InMemoryTypeMapping typeMapping
Public Constructors
InMemoryProducer(String namespace)
Creates a new instance of an in-memory POJO producer.
InMemoryProducer(String namespace, int maxResults)
Creates a new instance of an in-memory POJO producer.
InMemoryProducer(String namespace, String containerName, int maxResults, EdmDecorator decorator, InMemoryTypeMapping typeMapping)
Creates a new instance of an in-memory POJO producer.
Public Methods
BaseResponse callFunction(EdmFunctionImport name, Map<String, OFunctionParameter> params, QueryInfo queryInfo)
Call a function (aka Service Operation)
void close()
Releases any resources managed by this producer.
EntityResponse createEntity(String entitySetName, OEntity entity)
Creates a new OData entity.
EntityResponse createEntity(String entitySetName, OEntityKey entityKey, String navProp, OEntity entity)
Creates a new OData entity as a reference of an existing entity, implicitly linked to the existing entity by a navigation property.
void createLink(OEntityId sourceEntity, String targetNavProp, OEntityId targetEntity)
Creates a link between two entities.
void deleteEntity(String entitySetName, OEntityKey entityKey)
Deletes an existing entity.
void deleteLink(OEntityId sourceEntity, String targetNavProp, OEntityKey targetEntityKey)
Deletes an existing link between two entities.
EntitiesResponse getEntities(String entitySetName, QueryInfo queryInfo)
Gets all the entities for a given set matching the query information.
CountResponse getEntitiesCount(String entitySetName, QueryInfo queryInfo)
Gets the count of all the entities for a given set matching the query information.
EntityResponse getEntity(String entitySetName, OEntityKey entityKey, EntityQueryInfo queryInfo)
Obtains a single entity based on its type and key.
EntityIdResponse getLinks(OEntityId sourceEntity, String targetNavProp)
Returns the value of an entity's navigation property as a collection of entity links (or a single link if the association cardinality is 1).
EdmDataServices getMetadata()
Obtains the service metadata for this producer.
MetadataProducer getMetadataProducer()
Obtains the ODataProducer implementation that serves the metadata as OData EDM constructs.
BaseResponse getNavProperty(String entitySetName, OEntityKey entityKey, String navProp, QueryInfo queryInfo)
Given a specific entity, follow one of its navigation properties, applying constraints as appropriate.
CountResponse getNavPropertyCount(String entitySetName, OEntityKey entityKey, String navProp, QueryInfo queryInfo)
Given a specific entity, follow one of its navigation properties, applying constraints as appropriate.
void mergeEntity(String entitySetName, OEntity entity)
Modifies an existing entity using merge semantics.
<TEntity> void register(Class<TEntity> entityClass, String entitySetName, String entityTypeName, Func<Iterable<TEntity>> get, String... keys)
Registers a new entity based on a POJO, with support for composite keys.
<TEntity> void register(Class<TEntity> entityClass, PropertyModel propertyModel, String entitySetName, String entityTypeName, Func<Iterable<TEntity>> get, String... keys)
<TEntity> void register(Class<TEntity> entityClass, String entitySetName, Func<Iterable<TEntity>> get, String... keys)
Registers a new entity based on a POJO, with support for composite keys.
<TEntity, TKey> void register(Class<TEntity> entityClass, Class<TKey> keyClass, String entitySetName, Func<Iterable<TEntity>> get, Func1<TEntity, TKey> id)
Registers a new entity set based on a POJO type using the default property model.
<TEntity, TKey> void register(Class<TEntity> entityClass, PropertyModel propertyModel, String entitySetName, Func<Iterable<TEntity>> get, String... keys)
Registers a new entity set based on a POJO type and a property model.
void updateEntity(String entitySetName, OEntity entity)
Modifies an existing entity using update semantics.
void updateLink(OEntityId sourceEntity, String targetNavProp, OEntityKey oldTargetEntityKey, OEntityId newTargetEntity)
Replaces an existing link between two entities.
Protected Methods
InMemoryEdmGenerator newEdmGenerator(String namespace, InMemoryTypeMapping typeMapping, String idPropName, Map<String, InMemoryEntityInfo<?>> eis)
OEntity toOEntity(EdmEntitySet ees, Object obj, List<EntitySimpleProperty> expand)
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.odata4j.producer.ODataProducer

Constants

private static final int DEFAULT_MAX_RESULTS

Constant Value: 100 (0x00000064)

private static final String ID_PROPNAME

Constant Value: "EntityId"

Fields

private final String containerName

private final EdmDecorator decorator

private final Map<String, InMemoryEntityInfo<?>> eis

private final int maxResults

private EdmDataServices metadata

private final MetadataProducer metadataProducer

private final String namespace

private final InMemoryTypeMapping typeMapping

Public Constructors

public InMemoryProducer (String namespace)

Creates a new instance of an in-memory POJO producer.

Parameters
namespace The namespace of the schema registrations

public InMemoryProducer (String namespace, int maxResults)

Creates a new instance of an in-memory POJO producer.

Parameters
namespace The namespace of the schema registrations
maxResults The maximum number of entities to return in a single call

public InMemoryProducer (String namespace, String containerName, int maxResults, EdmDecorator decorator, InMemoryTypeMapping typeMapping)

Creates a new instance of an in-memory POJO producer.

Parameters
namespace The namespace of the schema registrations
containerName The container name for generated metadata
maxResults The maximum number of entities to return in a single call
decorator A decorator to use for edm customizations
typeMapping Optional mapping between java types and edm types, null for default

Public Methods

public BaseResponse callFunction (EdmFunctionImport name, Map<String, OFunctionParameter> params, QueryInfo queryInfo)

Call a function (aka Service Operation)

Parameters
name The name of the function
params The parameters to the function
queryInfo Additional query parameters to apply to collection-valued results
Returns
  • a BaseResponse appropriately typed to hold the function results From the spec:
        The return type of <Function> MUST be one of the following:
            An EDMSimpleType or collection of EDMSimpleTypes.
            An entity type or collection of entity types.
            A complex type or collection of complex types.
            A row type or collection of row types.
            <ReturnType> can contain a maximum of one <CollectionType> element.
            <ReturnType> can contain a maximum of one <ReferenceType> element.
            <ReturnType> can contain a maximum of one <RowType> element.
            A ref type or collection of ref types.

public void close ()

Releases any resources managed by this producer.

public EntityResponse createEntity (String entitySetName, OEntity entity)

Creates a new OData entity.

Parameters
entitySetName The entity-set name
entity The request entity sent from the client
Returns
  • the newly-created entity, fully populated with the key and default properties

public EntityResponse createEntity (String entitySetName, OEntityKey entityKey, String navProp, OEntity entity)

Creates a new OData entity as a reference of an existing entity, implicitly linked to the existing entity by a navigation property.

Parameters
entitySetName The entity-set name of the existing entity
entityKey The entity-key of the existing entity
navProp The navigation property off of the existing entity
entity The request entity sent from the client
Returns
  • the newly-created entity, fully populated with the key and default properties, and linked to the existing entity

public void createLink (OEntityId sourceEntity, String targetNavProp, OEntityId targetEntity)

Creates a link between two entities.

Parameters
sourceEntity An entity with at least one navigation property
targetNavProp The navigation property
targetEntity The link target entity

public void deleteEntity (String entitySetName, OEntityKey entityKey)

Deletes an existing entity.

Parameters
entitySetName The entity-set name of the entity
entityKey The entity-key of the entity

public void deleteLink (OEntityId sourceEntity, String targetNavProp, OEntityKey targetEntityKey)

Deletes an existing link between two entities.

Parameters
sourceEntity An entity with at least one navigation property
targetNavProp The navigation property
targetEntityKey If the navigation property represents a set, the key identifying the target entity within the set, else n/a

public EntitiesResponse getEntities (String entitySetName, QueryInfo queryInfo)

Gets all the entities for a given set matching the query information.

Parameters
entitySetName The entity-set name for entities to return
queryInfo The additional constraints to apply to the entities
Returns
  • a packaged collection of entities to pass back to the client

public CountResponse getEntitiesCount (String entitySetName, QueryInfo queryInfo)

Gets the count of all the entities for a given set matching the query information.

Parameters
entitySetName The entity-set name for entities whose count is returned
queryInfo The additional constraints to apply to the entities
Returns
  • count of the entities

public EntityResponse getEntity (String entitySetName, OEntityKey entityKey, EntityQueryInfo queryInfo)

Obtains a single entity based on its type and key.

Parameters
entitySetName The entity-set name for entities to return
entityKey The unique entity-key of the entity to start with
queryInfo The additional constraints applicable to single-entity queries
Returns
  • the resulting entity

public EntityIdResponse getLinks (OEntityId sourceEntity, String targetNavProp)

Returns the value of an entity's navigation property as a collection of entity links (or a single link if the association cardinality is 1).

Parameters
sourceEntity An entity with at least one navigation property
targetNavProp The navigation property
Returns
  • a collection of entity links (or a single link if the association cardinality is 1)

public EdmDataServices getMetadata ()

Obtains the service metadata for this producer.

Returns
  • a fully-constructed metadata object

public MetadataProducer getMetadataProducer ()

Obtains the ODataProducer implementation that serves the metadata as OData EDM constructs.

Returns
  • the MetadataProducer object

public BaseResponse getNavProperty (String entitySetName, OEntityKey entityKey, String navProp, QueryInfo queryInfo)

Given a specific entity, follow one of its navigation properties, applying constraints as appropriate. Return the resulting entity, entities, or property value.

Parameters
entitySetName The entity-set of the entity to start with
entityKey The unique entity-key of the entity to start with
navProp The navigation property to follow
queryInfo Additional constraints to apply to the result
Returns
  • the resulting entity, entities, or property value

public CountResponse getNavPropertyCount (String entitySetName, OEntityKey entityKey, String navProp, QueryInfo queryInfo)

Given a specific entity, follow one of its navigation properties, applying constraints as appropriate. Return the count of the resulting entities.

Parameters
entitySetName The entity-set of the entity to start with
entityKey The unique entity-key of the entity to start with
navProp The navigation property to follow
queryInfo Additional constraints to apply to the result
Returns
  • the count of the resulting entities

public void mergeEntity (String entitySetName, OEntity entity)

Modifies an existing entity using merge semantics.

Parameters
entitySetName The entity-set name
entity The entity modifications sent from the client

public void register (Class<TEntity> entityClass, String entitySetName, String entityTypeName, Func<Iterable<TEntity>> get, String... keys)

Registers a new entity based on a POJO, with support for composite keys.

Parameters
entityClass The class of the entities that are to be stored in the set
entitySetName The alias the set will be known by; this is what is used in the OData url
entityTypeName Type name of the entity
get A function to iterate over the elements in the set
keys One or more keys for the entity

public void register (Class<TEntity> entityClass, PropertyModel propertyModel, String entitySetName, String entityTypeName, Func<Iterable<TEntity>> get, String... keys)

Parameters
entityClass
propertyModel
entitySetName
entityTypeName
get
keys

public void register (Class<TEntity> entityClass, String entitySetName, Func<Iterable<TEntity>> get, String... keys)

Registers a new entity based on a POJO, with support for composite keys.

Parameters
entityClass The class of the entities that are to be stored in the set
entitySetName The alias the set will be known by; this is what is used in the OData url
get A function to iterate over the elements in the set
keys One or more keys for the entity

public void register (Class<TEntity> entityClass, Class<TKey> keyClass, String entitySetName, Func<Iterable<TEntity>> get, Func1<TEntity, TKey> id)

Registers a new entity set based on a POJO type using the default property model.

Parameters
entityClass
keyClass
entitySetName
get
id

public void register (Class<TEntity> entityClass, PropertyModel propertyModel, String entitySetName, Func<Iterable<TEntity>> get, String... keys)

Registers a new entity set based on a POJO type and a property model.

Parameters
entityClass The class of the entities that are to be stored in the set
propertyModel A way to get/set properties on the POJO
entitySetName The alias the set will be known by; this is what is used in the ODATA URL
get A function to iterate over the elements in the set
keys One or more keys for the entity

public void updateEntity (String entitySetName, OEntity entity)

Modifies an existing entity using update semantics.

Parameters
entitySetName The entity-set name
entity The entity modifications sent from the client

public void updateLink (OEntityId sourceEntity, String targetNavProp, OEntityKey oldTargetEntityKey, OEntityId newTargetEntity)

Replaces an existing link between two entities.

Parameters
sourceEntity An entity with at least one navigation property
targetNavProp The navigation property
oldTargetEntityKey If the navigation property represents a set, the key identifying the old target entity within the set, else n/a
newTargetEntity The new link target entity

Protected Methods

protected InMemoryEdmGenerator newEdmGenerator (String namespace, InMemoryTypeMapping typeMapping, String idPropName, Map<String, InMemoryEntityInfo<?>> eis)

Parameters
namespace
typeMapping
idPropName
eis

protected OEntity toOEntity (EdmEntitySet ees, Object obj, List<EntitySimpleProperty> expand)

Parameters
ees
obj
expand