Permalink
Browse files

Add support for "getEntity" and "queryEntities"

  • Loading branch information...
1 parent a4f49b0 commit bf53b9c4e03e2ccac31dda10e13bcae846e9300f Renaud Paquay committed with lodejard Jan 11, 2012
@@ -18,10 +18,13 @@
import com.microsoft.windowsazure.services.core.ServiceException;
import com.microsoft.windowsazure.services.table.models.DeleteEntityOptions;
import com.microsoft.windowsazure.services.table.models.Entity;
+import com.microsoft.windowsazure.services.table.models.GetEntityResult;
import com.microsoft.windowsazure.services.table.models.GetServicePropertiesResult;
import com.microsoft.windowsazure.services.table.models.GetTableResult;
import com.microsoft.windowsazure.services.table.models.InsertEntityResult;
import com.microsoft.windowsazure.services.table.models.ListTablesOptions;
+import com.microsoft.windowsazure.services.table.models.QueryEntitiesOptions;
+import com.microsoft.windowsazure.services.table.models.QueryEntitiesResult;
import com.microsoft.windowsazure.services.table.models.QueryTablesOptions;
import com.microsoft.windowsazure.services.table.models.QueryTablesResult;
import com.microsoft.windowsazure.services.table.models.ServiceProperties;
@@ -83,4 +86,13 @@ UpdateEntityResult insertOrMergeEntity(String table, Entity entity, TableService
void deleteEntity(String table, String partitionKey, String rowKey, DeleteEntityOptions options)
throws ServiceException;
+
+ GetEntityResult getEntity(String table, String partitionKey, String rowKey) throws ServiceException;
+
+ GetEntityResult getEntity(String table, String partitionKey, String rowKey, TableServiceOptions options)
+ throws ServiceException;
+
+ QueryEntitiesResult queryEntities(String table) throws ServiceException;
+
+ QueryEntitiesResult queryEntities(String table, QueryEntitiesOptions options) throws ServiceException;
}
@@ -117,26 +117,40 @@ public TableEntry parseTableEntry(InputStream stream) {
}
}
- public Entity parseEntityEntry(InputStream stream) {
+ public List<Entity> parseEntityEntries(InputStream stream) {
try {
XMLStreamReader xmlr = xmlStreamFactory.getReader(stream);
- Entity result = new Entity();
expect(xmlr, XMLStreamConstants.START_DOCUMENT);
+ expect(xmlr, XMLStreamConstants.START_ELEMENT, "feed");
- result.setEtag(xmlr.getAttributeValue(null, "etag"));
- expect(xmlr, XMLStreamConstants.START_ELEMENT, "entry");
-
- while (!isEndElement(xmlr, "entry")) {
- if (isStartElement(xmlr, "properties")) {
- result.setProperties(parseEntryProperties(xmlr));
+ List<Entity> result = new ArrayList<Entity>();
+ while (!isEndElement(xmlr, "feed")) {
+ // Process "entry" elements only
+ if (isStartElement(xmlr, "entry")) {
+ result.add(parseEntityEntry(xmlr));
}
else {
nextSignificant(xmlr);
}
}
- expect(xmlr, XMLStreamConstants.END_ELEMENT, "entry");
+ expect(xmlr, XMLStreamConstants.END_ELEMENT, "feed");
+ expect(xmlr, XMLStreamConstants.END_DOCUMENT);
+
+ return result;
+ }
+ catch (XMLStreamException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public Entity parseEntityEntry(InputStream stream) {
+ try {
+ XMLStreamReader xmlr = xmlStreamFactory.getReader(stream);
+
+ expect(xmlr, XMLStreamConstants.START_DOCUMENT);
+ Entity result = parseEntityEntry(xmlr);
expect(xmlr, XMLStreamConstants.END_DOCUMENT);
return result;
@@ -218,6 +232,26 @@ private TableEntry parseTableEntry(XMLStreamReader xmlr) throws XMLStreamExcepti
return result;
}
+ private Entity parseEntityEntry(XMLStreamReader xmlr) throws XMLStreamException {
+ Entity result = new Entity();
+
+ result.setEtag(xmlr.getAttributeValue(null, "etag"));
+ expect(xmlr, XMLStreamConstants.START_ELEMENT, "entry");
+
+ while (!isEndElement(xmlr, "entry")) {
+ if (isStartElement(xmlr, "properties")) {
+ result.setProperties(parseEntryProperties(xmlr));
+ }
+ else {
+ nextSignificant(xmlr);
+ }
+ }
+
+ expect(xmlr, XMLStreamConstants.END_ELEMENT, "entry");
+
+ return result;
+ }
+
private Map<String, Property> parseEntryProperties(XMLStreamReader xmlr) throws XMLStreamException {
Map<String, Property> result = new HashMap<String, Property>();
@@ -25,10 +25,13 @@
import com.microsoft.windowsazure.services.table.TableContract;
import com.microsoft.windowsazure.services.table.models.DeleteEntityOptions;
import com.microsoft.windowsazure.services.table.models.Entity;
+import com.microsoft.windowsazure.services.table.models.GetEntityResult;
import com.microsoft.windowsazure.services.table.models.GetServicePropertiesResult;
import com.microsoft.windowsazure.services.table.models.GetTableResult;
import com.microsoft.windowsazure.services.table.models.InsertEntityResult;
import com.microsoft.windowsazure.services.table.models.ListTablesOptions;
+import com.microsoft.windowsazure.services.table.models.QueryEntitiesOptions;
+import com.microsoft.windowsazure.services.table.models.QueryEntitiesResult;
import com.microsoft.windowsazure.services.table.models.QueryTablesOptions;
import com.microsoft.windowsazure.services.table.models.QueryTablesResult;
import com.microsoft.windowsazure.services.table.models.ServiceProperties;
@@ -404,4 +407,57 @@ public void deleteEntity(String table, String partitionKey, String rowKey, Delet
throw processCatch(new ServiceException(e));
}
}
+
+ @Override
+ public GetEntityResult getEntity(String table, String partitionKey, String rowKey) throws ServiceException {
+ try {
+ return service.getEntity(table, partitionKey, rowKey);
+ }
+ catch (UniformInterfaceException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ catch (ClientHandlerException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ }
+
+ @Override
+ public GetEntityResult getEntity(String table, String partitionKey, String rowKey, TableServiceOptions options)
+ throws ServiceException {
+ try {
+ return service.getEntity(table, partitionKey, rowKey, options);
+ }
+ catch (UniformInterfaceException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ catch (ClientHandlerException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ }
+
+ @Override
+ public QueryEntitiesResult queryEntities(String table) throws ServiceException {
+ try {
+ return service.queryEntities(table);
+ }
+ catch (UniformInterfaceException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ catch (ClientHandlerException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ }
+
+ @Override
+ public QueryEntitiesResult queryEntities(String table, QueryEntitiesOptions options) throws ServiceException {
+ try {
+ return service.queryEntities(table, options);
+ }
+ catch (UniformInterfaceException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ catch (ClientHandlerException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ }
}
@@ -37,12 +37,15 @@
import com.microsoft.windowsazure.services.table.models.DeleteEntityOptions;
import com.microsoft.windowsazure.services.table.models.Entity;
import com.microsoft.windowsazure.services.table.models.FilterExpression;
+import com.microsoft.windowsazure.services.table.models.GetEntityResult;
import com.microsoft.windowsazure.services.table.models.GetServicePropertiesResult;
import com.microsoft.windowsazure.services.table.models.GetTableResult;
import com.microsoft.windowsazure.services.table.models.InsertEntityResult;
import com.microsoft.windowsazure.services.table.models.ListTablesOptions;
import com.microsoft.windowsazure.services.table.models.LitteralFilterExpression;
import com.microsoft.windowsazure.services.table.models.QueryBuilder;
+import com.microsoft.windowsazure.services.table.models.QueryEntitiesOptions;
+import com.microsoft.windowsazure.services.table.models.QueryEntitiesResult;
import com.microsoft.windowsazure.services.table.models.QueryTablesOptions;
import com.microsoft.windowsazure.services.table.models.QueryTablesResult;
import com.microsoft.windowsazure.services.table.models.ServiceProperties;
@@ -463,4 +466,50 @@ public void deleteEntity(String table, String partitionKey, String rowKey, Delet
ClientResponse response = builder.delete(ClientResponse.class);
ThrowIfError(response);
}
+
+ @Override
+ public GetEntityResult getEntity(String table, String partitionKey, String rowKey) throws ServiceException {
+ return getEntity(table, partitionKey, rowKey, new TableServiceOptions());
+ }
+
+ @Override
+ public GetEntityResult getEntity(String table, String partitionKey, String rowKey, TableServiceOptions options)
+ throws ServiceException {
+ WebResource webResource = getResource(options).path(getEntityPath(table, partitionKey, rowKey));
+
+ WebResource.Builder builder = webResource.getRequestBuilder();
+ builder = addTableRequestHeaders(builder);
+
+ ClientResponse response = builder.get(ClientResponse.class);
+ ThrowIfError(response);
+
+ GetEntityResult result = new GetEntityResult();
+ result.setEntity(atomReaderWriter.parseEntityEntry(response.getEntityInputStream()));
+
+ return result;
+ }
+
+ @Override
+ public QueryEntitiesResult queryEntities(String table) throws ServiceException {
+ return queryEntities(table, new QueryEntitiesOptions());
+ }
+
+ @Override
+ public QueryEntitiesResult queryEntities(String table, QueryEntitiesOptions options) throws ServiceException {
+ WebResource webResource = getResource(options).path(table);
+ webResource = addOptionalQuery(webResource, options.getQuery());
+
+ WebResource.Builder builder = webResource.getRequestBuilder();
+ builder = addTableRequestHeaders(builder);
+
+ ClientResponse response = builder.get(ClientResponse.class);
+ ThrowIfError(response);
+
+ QueryEntitiesResult result = new QueryEntitiesResult();
+ result.setNextPartitionKey(response.getHeaders().getFirst("x-ms-continuation-NextPartitionKey"));
+ result.setNextRowKey(response.getHeaders().getFirst("x-ms-continuation-NextRowKey"));
+ result.setEntities(atomReaderWriter.parseEntityEntries(response.getEntityInputStream()));
+
+ return result;
+ }
}
@@ -0,0 +1,13 @@
+package com.microsoft.windowsazure.services.table.models;
+
+public class GetEntityResult {
+ private Entity entity;
+
+ public Entity getEntity() {
+ return entity;
+ }
+
+ public void setEntity(Entity entity) {
+ this.entity = entity;
+ }
+}
@@ -0,0 +1,20 @@
+package com.microsoft.windowsazure.services.table.models;
+
+public class QueryEntitiesOptions extends TableServiceOptions {
+ private QueryBuilder query;
+
+ @Override
+ public QueryEntitiesOptions setTimeout(Integer timeout) {
+ super.setTimeout(timeout);
+ return this;
+ }
+
+ public QueryBuilder getQuery() {
+ return query;
+ }
+
+ public QueryEntitiesOptions setQuery(QueryBuilder query) {
+ this.query = query;
+ return this;
+ }
+}
@@ -0,0 +1,34 @@
+package com.microsoft.windowsazure.services.table.models;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class QueryEntitiesResult {
+ private String nextPartitionKey;
+ private String nextRowKey;
+ private List<Entity> entities = new ArrayList<Entity>();
+
+ public List<Entity> getEntities() {
+ return entities;
+ }
+
+ public void setEntities(List<Entity> entities) {
+ this.entities = entities;
+ }
+
+ public String getNextPartitionKey() {
+ return nextPartitionKey;
+ }
+
+ public void setNextPartitionKey(String nextPartitionKey) {
+ this.nextPartitionKey = nextPartitionKey;
+ }
+
+ public String getNextRowKey() {
+ return nextRowKey;
+ }
+
+ public void setNextRowKey(String nextRowKey) {
+ this.nextRowKey = nextRowKey;
+ }
+}
Oops, something went wrong.

0 comments on commit bf53b9c

Please sign in to comment.