Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,10 +53,6 @@ public interface TableContract extends FilterableService<TableContract> {

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -222,32 +221,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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -311,33 +310,43 @@ public GetTableResult getTable(String table, TableServiceOptions options) throws
return result;
}

@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);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public class QueryTablesOptions extends TableServiceOptions {
private String nextTableName;
private Query query;
private String prefix;

@Override
public QueryTablesOptions setTimeout(Integer timeout) {
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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());
}
Expand Down Expand Up @@ -267,27 +267,14 @@ public void queryTablesWorks() throws Exception {
assertNotNull(result);
}

@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);
Expand Down