org.odata4j.consumer
Class ODataConsumer

java.lang.Object
  extended by org.odata4j.consumer.ODataConsumer

public class ODataConsumer
extends Object

ODataConsumer is the client-side interface to an OData service.

Use create(String) or one of the other static factory methods to connect to an existing OData service.


Nested Class Summary
static class ODataConsumer.Dump
          Sends http request and/or response information to standard out.
 
Field Summary
static ODataConsumer.Dump dump
          Sends http request and/or response information to standard out.
 
Method Summary
static ODataConsumer create(FormatType preferredType, String serviceRootUri)
           
static ODataConsumer create(FormatType preferredType, String serviceRootUri, OClientBehavior... behaviors)
           
static ODataConsumer create(String serviceRootUri)
          Creates a new consumer for the given OData service uri.
static ODataConsumer create(String serviceRootUri, OClientBehavior... behaviors)
          Creates a new consumer for the given OData service uri, adding one or more client behaviors.
 OCreateRequest<OEntity> createEntity(String entitySetName)
          Creates a new entity in the given entity-set.
 OEntityRequest<Void> deleteEntity(OEntity entity)
          Deletes an existing entity.
 OEntityRequest<Void> deleteEntity(String entitySetName, Object keyValue)
          Deletes an existing entity.
 OEntityRequest<Void> deleteEntity(String entitySetName, OEntityKey key)
          Deletes an existing entity.
<T> OQueryRequest<T>
getEntities(Class<T> entityType, String entitySetName)
          Gets entities from the given entity-set.
 OQueryRequest<OEntity> getEntities(ORelatedEntitiesLink link)
          Gets entities referred to by the given related-entities link.
 OQueryRequest<OEntity> getEntities(String entitySetName)
          Gets entities from the given entity-set.
<T> OEntityRequest<T>
getEntity(Class<T> entityType, String entitySetName, Object keyValue)
          Gets the entity by entity-set name and entity-key value.
<T> OEntityRequest<T>
getEntity(Class<T> entityType, String entitySetName, OEntityKey key)
          Gets the entity by entity-set name and entity-key.
 OEntityRequest<OEntity> getEntity(OEntity entity)
          Gets the latest version of an entity using the given entity as a template.
 OEntityRequest<OEntity> getEntity(ORelatedEntityLink link)
          Gets the entity referred to by the given related entity link.
 OEntityRequest<OEntity> getEntity(String entitySetName, Object keyValue)
          Gets the entity by entity-set name and entity-key value.
 OEntityRequest<OEntity> getEntity(String entitySetName, OEntityKey key)
          Gets the entity by entity-set name and entity-key.
 Enumerable<String> getEntitySets()
          Lists the names of all top-level entity-sets for the OData service.
 EdmDataServices getMetadata()
          Gets the OData service metadata.
 String getServiceRootUri()
          Gets the OData service uri.
 OModifyRequest<OEntity> mergeEntity(OEntity entity)
          Modifies an existing entity using merge semantics.
 OModifyRequest<OEntity> mergeEntity(String entitySetName, Object keyValue)
          Modifies an existing entity using merge semantics.
 OModifyRequest<OEntity> mergeEntity(String entitySetName, OEntityKey key)
          Modifies an existing entity using merge semantics.
 OModifyRequest<OEntity> updateEntity(OEntity entity)
          Modifies an existing entity using update semantics.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dump

public static final ODataConsumer.Dump dump
Sends http request and/or response information to standard out. Useful for debugging.

Method Detail

create

public static ODataConsumer create(FormatType preferredType,
                                   String serviceRootUri)

create

public static ODataConsumer create(FormatType preferredType,
                                   String serviceRootUri,
                                   OClientBehavior... behaviors)

create

public static ODataConsumer create(String serviceRootUri)
Creates a new consumer for the given OData service uri.

Parameters:
serviceRootUri - the service uri

e.g. http://services.odata.org/Northwind/Northwind.svc/

Returns:
a new OData consumer

create

public static ODataConsumer create(String serviceRootUri,
                                   OClientBehavior... behaviors)
Creates a new consumer for the given OData service uri, adding one or more client behaviors. Client behaviors transform http requests to interact with services that require custom extensions.

Parameters:
serviceRootUri - the service uri

e.g. http://services.odata.org/Northwind/Northwind.svc/

behaviors - one or more client behaviors
Returns:
a new OData consumer

createEntity

public OCreateRequest<OEntity> createEntity(String entitySetName)
Creates a new entity in the given entity-set.

The create-request builder returned can be used to construct the new entity. Call OCreateRequest.execute() to issue request.

Parameters:
entitySetName - the name of the entity-set
Returns:
a new create-request builder

deleteEntity

public OEntityRequest<Void> deleteEntity(OEntity entity)
Deletes an existing entity.

The entity-request builder returned can be used for further navigation. Call OEntityRequest.execute() to issue request.

Parameters:
entity - the entity identity
Returns:
a new entity-request builder

deleteEntity

public OEntityRequest<Void> deleteEntity(String entitySetName,
                                         Object keyValue)
Deletes an existing entity.

The entity-request builder returned can be used for further navigation. Call OEntityRequest.execute() to issue request.

Parameters:
entitySetName - the entity identity entity-set name
keyValue - the entity identity key value
Returns:
a new entity-request builder

deleteEntity

public OEntityRequest<Void> deleteEntity(String entitySetName,
                                         OEntityKey key)
Deletes an existing entity.

The entity-request builder returned can be used for further navigation. Call OEntityRequest.execute() to issue request.

Parameters:
entitySetName - the entity identity entity-set name
key - the entity identity key
Returns:
a new entity-request builder

getEntities

public <T> OQueryRequest<T> getEntities(Class<T> entityType,
                                        String entitySetName)
Gets entities from the given entity-set. The entities will be represented as the given java-type.

The query-request builder returned can be used for further server-side filtering. Call OQueryRequest.execute() or simply iterate to issue request.

Type Parameters:
T - the entity representation as a java type
Parameters:
entityType - the entity representation as a java type
entitySetName - the entity-set name
Returns:
a new query-request builder

getEntities

public OQueryRequest<OEntity> getEntities(ORelatedEntitiesLink link)
Gets entities referred to by the given related-entities link.

The query-request builder returned can be used for further server-side filtering. Call OQueryRequest.execute() or simply iterate to issue request.

Parameters:
link - the link
Returns:
a new query-request builder

getEntities

public OQueryRequest<OEntity> getEntities(String entitySetName)
Gets entities from the given entity-set.

The query-request builder returned can be used for further server-side filtering. Call OQueryRequest.execute() or simply iterate to issue request.

Parameters:
entitySetName - the entity-set name
Returns:
a new query-request builder

getEntity

public <T> OEntityRequest<T> getEntity(Class<T> entityType,
                                       String entitySetName,
                                       Object keyValue)
Gets the entity by entity-set name and entity-key value. The entity will be represented as the given java-type.

The entity-request builder returned can be used for further navigation. Call OEntityRequest.execute() to issue request.

Type Parameters:
T - the entity representation as a java type
Parameters:
entityType - the entity representation as a java type
entitySetName - the name of the entity-set
keyValue - the entity-key value
Returns:
a new entity-request builder

getEntity

public <T> OEntityRequest<T> getEntity(Class<T> entityType,
                                       String entitySetName,
                                       OEntityKey key)
Gets the entity by entity-set name and entity-key. The entity will be represented as the given java-type.

The entity-request builder returned can be used for further navigation. Call OEntityRequest.execute() to issue request.

Type Parameters:
T - the entity representation as a java type
Parameters:
entityType - the entity representation as a java type
entitySetName - the name of the entity-set
key - the entity-key
Returns:
a new entity-request builder

getEntity

public OEntityRequest<OEntity> getEntity(OEntity entity)
Gets the latest version of an entity using the given entity as a template.

The entity-request builder returned can be used for further navigation. Call OEntityRequest.execute() to issue request.

Parameters:
entity - an existing entity to use as a template, using its entity-set and entity-key
Returns:
a new entity-request builder

getEntity

public OEntityRequest<OEntity> getEntity(ORelatedEntityLink link)
Gets the entity referred to by the given related entity link.

The entity-request builder returned can be used for further navigation. Call OEntityRequest.execute() to issue request.

Parameters:
link - the link
Returns:
a new entity-request builder

getEntity

public OEntityRequest<OEntity> getEntity(String entitySetName,
                                         Object keyValue)
Gets the entity by entity-set name and entity-key value.

The entity-request builder returned can be used for further navigation. Call OEntityRequest.execute() to issue request.

Parameters:
entitySetName - the name of the entity-set
keyValue - the entity-key value
Returns:
a new entity-request builder

getEntity

public OEntityRequest<OEntity> getEntity(String entitySetName,
                                         OEntityKey key)
Gets the entity by entity-set name and entity-key.

The entity-request builder returned can be used for further navigation. Call OEntityRequest.execute() to issue request.

Parameters:
entitySetName - the name of the entity-set
key - the entity-key
Returns:
a new entity-request builder

getEntitySets

public Enumerable<String> getEntitySets()
Lists the names of all top-level entity-sets for the OData service.

Returns:
the entity-set names

getMetadata

public EdmDataServices getMetadata()
Gets the OData service metadata.

Returns:
the service metadata
See Also:
[msdn] 2.2 <edmx:DataServices>

getServiceRootUri

public String getServiceRootUri()
Gets the OData service uri.

e.g. http://services.odata.org/Northwind/Northwind.svc/

Returns:
the service uri

mergeEntity

public OModifyRequest<OEntity> mergeEntity(OEntity entity)
Modifies an existing entity using merge semantics.

The modification-request builder returned can be used to modify the new entity. Call OModifyRequest.execute() to issue request.

Parameters:
entity - the entity identity
Returns:
a new modification-request builder

mergeEntity

public OModifyRequest<OEntity> mergeEntity(String entitySetName,
                                           Object keyValue)
Modifies an existing entity using merge semantics.

The modification-request builder returned can be used to modify the new entity. Call OModifyRequest.execute() to issue request.

Parameters:
entitySetName - the entity identity entity-set name
keyValue - the entity identity key value
Returns:
a new modification-request builder

mergeEntity

public OModifyRequest<OEntity> mergeEntity(String entitySetName,
                                           OEntityKey key)
Modifies an existing entity using merge semantics.

The modification-request builder returned can be used to modify the new entity. Call OModifyRequest.execute() to issue request.

Parameters:
entitySetName - the entity identity entity-set name
key - the entity identity key
Returns:
a new modification-request builder

updateEntity

public OModifyRequest<OEntity> updateEntity(OEntity entity)
Modifies an existing entity using update semantics.

The modification-request builder returned can be used to redefine the new entity. Call OModifyRequest.execute() to issue request.

Parameters:
entity - the entity identity
Returns:
a new modification-request builder


http://odata4j.org