Permalink
Browse files

Merge pull request #14 from loudej/issue-216

Issue 216
  • Loading branch information...
2 parents 3e29e5c + c4206d7 commit a55279780ddb26345866cf709d452ec227e80286 @jcookems jcookems committed Feb 24, 2012
@@ -24,7 +24,6 @@
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;
@@ -54,10 +53,6 @@
GetTableResult getTable(String table, TableServiceOptions options) throws ServiceException;
- QueryTablesResult listTables() throws ServiceException;
-
- QueryTablesResult listTables(ListTablesOptions options) throws ServiceException;
-
QueryTablesResult queryTables() throws ServiceException;
QueryTablesResult queryTables(QueryTablesOptions options) throws ServiceException;
@@ -31,7 +31,6 @@
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;
@@ -223,32 +222,6 @@ public QueryTablesResult queryTables(QueryTablesOptions options) throws ServiceE
}
@Override
- public QueryTablesResult listTables() throws ServiceException {
- try {
- return service.listTables();
- }
- catch (UniformInterfaceException e) {
- throw processCatch(new ServiceException(e));
- }
- catch (ClientHandlerException e) {
- throw processCatch(new ServiceException(e));
- }
- }
-
- @Override
- public QueryTablesResult listTables(ListTablesOptions options) throws ServiceException {
- try {
- return service.listTables(options);
- }
- catch (UniformInterfaceException e) {
- throw processCatch(new ServiceException(e));
- }
- catch (ClientHandlerException e) {
- throw processCatch(new ServiceException(e));
- }
- }
-
- @Override
public InsertEntityResult insertEntity(String table, Entity entity) throws ServiceException {
try {
return service.insertEntity(table, entity);
@@ -67,7 +67,6 @@
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.LitteralFilter;
import com.microsoft.windowsazure.services.table.models.Query;
import com.microsoft.windowsazure.services.table.models.QueryEntitiesOptions;
@@ -312,32 +311,42 @@ public GetTableResult getTable(String table, TableServiceOptions options) throws
}
@Override
- public QueryTablesResult listTables() throws ServiceException {
- return listTables(new ListTablesOptions());
- }
-
- @Override
- public QueryTablesResult listTables(ListTablesOptions options) throws ServiceException {
- // Append Max char to end '{' is 1 + 'z' in AsciiTable ==> uppperBound is prefix + '{'
- Filter filter = Filter.and(Filter.ge(Filter.litteral("TableName"), Filter.constant(options.getPrefix())),
- Filter.le(Filter.litteral("TableName"), Filter.constant(options.getPrefix() + "{")));
-
- QueryTablesOptions queryTableOptions = new QueryTablesOptions();
- queryTableOptions.setTimeout(options.getTimeout());
- queryTableOptions.setQuery(new Query().setFilter(filter));
- return queryTables(queryTableOptions);
- }
-
- @Override
public QueryTablesResult queryTables() throws ServiceException {
return queryTables(new QueryTablesOptions());
}
@Override
public QueryTablesResult queryTables(QueryTablesOptions options) throws ServiceException {
+
+ Query query = options.getQuery();
+ String nextTableName = options.getNextTableName();
+ String prefix = options.getPrefix();
+
+ if (prefix != null) {
+ // Append Max char to end '{' is 1 + 'z' in AsciiTable ==> upperBound is prefix + '{'
+ Filter prefixFilter = Filter.and(Filter.ge(Filter.litteral("TableName"), Filter.constant(prefix)),
+ Filter.le(Filter.litteral("TableName"), Filter.constant(prefix + "{")));
+
+ // a new query is needed if prefix alone is passed in
+ if (query == null) {
+ query = new Query();
+ }
+
+ // examine the existing filter on the query
+ if (query.getFilter() == null) {
+ // use the prefix filter if the query filter is null
+ query.setFilter(prefixFilter);
+ }
+ else {
+ // combine and use the prefix filter if the query filter exists
+ Filter combinedFilter = Filter.and(query.getFilter(), prefixFilter);
+ query.setFilter(combinedFilter);
+ }
+ }
+
WebResource webResource = getResource(options).path("Tables");
- webResource = addOptionalQuery(webResource, options.getQuery());
- webResource = addOptionalQueryParam(webResource, "NextTableName", options.getNextTableName());
+ webResource = addOptionalQuery(webResource, query);
+ webResource = addOptionalQueryParam(webResource, "NextTableName", nextTableName);
WebResource.Builder builder = webResource.getRequestBuilder();
builder = addTableRequestHeaders(builder);
@@ -1,20 +0,0 @@
-package com.microsoft.windowsazure.services.table.models;
-
-public class ListTablesOptions extends TableServiceOptions {
- private String prefix;
-
- @Override
- public ListTablesOptions setTimeout(Integer timeout) {
- super.setTimeout(timeout);
- return this;
- }
-
- public String getPrefix() {
- return prefix;
- }
-
- public ListTablesOptions setPrefix(String prefix) {
- this.prefix = prefix;
- return this;
- }
-}
@@ -3,6 +3,7 @@
public class QueryTablesOptions extends TableServiceOptions {
private String nextTableName;
private Query query;
+ private String prefix;
@Override
public QueryTablesOptions setTimeout(Integer timeout) {
@@ -27,4 +28,13 @@ public QueryTablesOptions setNextTableName(String nextTableName) {
this.nextTableName = nextTableName;
return this;
}
+
+ public String getPrefix() {
+ return prefix;
+ }
+
+ public QueryTablesOptions setPrefix(String prefix) {
+ this.prefix = prefix;
+ return this;
+ }
}
@@ -40,10 +40,10 @@
import com.microsoft.windowsazure.services.table.models.GetEntityResult;
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.Query;
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;
import com.microsoft.windowsazure.services.table.models.TableEntry;
@@ -117,7 +117,7 @@ private static void createTables(TableContract service, String prefix, String[]
// Retry creating every table as long as we get "409 - Table being deleted" error
service = service.withFilter(new RetryPolicyFilter(new ExponentialRetryPolicy(new int[] { 409 })));
- Set<String> containers = listTables(service, prefix);
+ Set<String> containers = queryTables(service, prefix);
for (String item : list) {
if (!containers.contains(item)) {
service.createTable(item);
@@ -126,7 +126,7 @@ private static void createTables(TableContract service, String prefix, String[]
}
private static void deleteTables(TableContract service, String prefix, String[] list) throws Exception {
- Set<String> containers = listTables(service, prefix);
+ Set<String> containers = queryTables(service, prefix);
for (String item : list) {
if (containers.contains(item)) {
service.deleteTable(item);
@@ -145,9 +145,9 @@ private static void deleteAllTables(TableContract service, String[] list) throws
}
}
- private static Set<String> listTables(TableContract service, String prefix) throws Exception {
+ private static Set<String> queryTables(TableContract service, String prefix) throws Exception {
HashSet<String> result = new HashSet<String>();
- QueryTablesResult list = service.listTables(new ListTablesOptions().setPrefix(prefix));
+ QueryTablesResult list = service.queryTables(new QueryTablesOptions().setPrefix(prefix));
for (TableEntry item : list.getTables()) {
result.add(item.getName());
}
@@ -268,26 +268,13 @@ public void queryTablesWorks() throws Exception {
}
@Test
- public void listTablesWorks() throws Exception {
- // Arrange
- Configuration config = createConfiguration();
- TableContract service = TableService.create(config);
-
- // Act
- QueryTablesResult result = service.listTables();
-
- // Assert
- assertNotNull(result);
- }
-
- @Test
public void queryTablesWithPrefixWorks() throws Exception {
// Arrange
Configuration config = createConfiguration();
TableContract service = TableService.create(config);
// Act
- QueryTablesResult result = service.listTables(new ListTablesOptions().setPrefix(testTablesPrefix));
+ QueryTablesResult result = service.queryTables(new QueryTablesOptions().setPrefix(testTablesPrefix));
// Assert
assertNotNull(result);

0 comments on commit a552797

Please sign in to comment.