Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CloudTableClient should use Iterator instead of Iterable. #55

Closed
wants to merge 1 commit into from
Closed
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 @@ -25,6 +25,7 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;

import javax.xml.stream.XMLStreamException;

Expand Down Expand Up @@ -657,7 +658,7 @@ public TableResult execute(final String tableName, final TableOperation operatio
* <code>R</code> of the results of executing the query.
*/
@DoesServiceRequest
public <R> Iterable<R> execute(final TableQuery<?> query, final EntityResolver<R> resolver) {
public <R> Iterator<R> execute(final TableQuery<?> query, final EntityResolver<R> resolver) {
return this.execute(query, resolver, null, null);
}

Expand Down Expand Up @@ -692,11 +693,11 @@ public <R> Iterable<R> execute(final TableQuery<?> query, final EntityResolver<R
*/
@DoesServiceRequest
@SuppressWarnings("unchecked")
public <R> Iterable<R> execute(final TableQuery<?> query, final EntityResolver<R> resolver,
public <R> Iterator<R> execute(final TableQuery<?> query, final EntityResolver<R> resolver,
final TableRequestOptions options, final OperationContext opContext) {
Utility.assertNotNull("query", query);
Utility.assertNotNull("Query requires a valid class type or resolver.", resolver);
return (Iterable<R>) this.generateIteratorForQuery(query, resolver, options, opContext);
return (Iterator<R>) this.generateIteratorForQuery(query, resolver, options, opContext);
}

/**
Expand All @@ -716,7 +717,7 @@ public <R> Iterable<R> execute(final TableQuery<?> query, final EntityResolver<R
* executing the query.
*/
@DoesServiceRequest
public <T extends TableEntity> Iterable<T> execute(final TableQuery<T> query) {
public <T extends TableEntity> Iterator<T> execute(final TableQuery<T> query) {
return this.execute(query, null, null);
}

Expand Down Expand Up @@ -748,10 +749,10 @@ public <T extends TableEntity> Iterable<T> execute(final TableQuery<T> query) {
*/
@SuppressWarnings("unchecked")
@DoesServiceRequest
public <T extends TableEntity> Iterable<T> execute(final TableQuery<T> query, final TableRequestOptions options,
public <T extends TableEntity> Iterator<T> execute(final TableQuery<T> query, final TableRequestOptions options,
final OperationContext opContext) {
Utility.assertNotNull("query", query);
return (Iterable<T>) this.generateIteratorForQuery(query, null, options, opContext);
return (Iterator<T>) this.generateIteratorForQuery(query, null, options, opContext);
}

/**
Expand Down Expand Up @@ -942,7 +943,7 @@ public <T extends TableEntity> ResultSegment<T> executeSegmented(final TableQuer
* An <code>Iterable</code> collection of the table names in the storage account.
*/
@DoesServiceRequest
public Iterable<String> listTables() {
public Iterator<String> listTables() {
return this.listTables(null);
}

Expand All @@ -961,7 +962,7 @@ public Iterable<String> listTables() {
* prefix.
*/
@DoesServiceRequest
public Iterable<String> listTables(final String prefix) {
public Iterator<String> listTables(final String prefix) {
return this.listTables(prefix, null, null);
}

Expand Down Expand Up @@ -991,7 +992,7 @@ public Iterable<String> listTables(final String prefix) {
* prefix.
*/
@DoesServiceRequest
public Iterable<String> listTables(final String prefix, final TableRequestOptions options,
public Iterator<String> listTables(final String prefix, final TableRequestOptions options,
final OperationContext opContext) {
return this.execute(this.generateListTablesQuery(prefix), this.tableNameResolver, options, opContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.net.URISyntaxException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Iterator;

import junit.framework.Assert;

Expand Down Expand Up @@ -142,8 +143,8 @@ public void listTablesWithIterator() throws IOException, URISyntaxException, Sto
try {
// With prefix
int currTable = 0;
for (String s : tClient.listTables(tableBaseName, null, null)) {
Assert.assertEquals(s,
for (Iterator<String> iterator = tClient.listTables(tableBaseName, null, null); iterator.hasNext();) {
Assert.assertEquals(iterator.next(),
String.format("%s%s", tableBaseName, new DecimalFormat("#0000").format(currTable)));
currTable++;
}
Expand All @@ -152,8 +153,8 @@ public void listTablesWithIterator() throws IOException, URISyntaxException, Sto

// Without prefix
currTable = 0;
for (String s : tClient.listTables()) {
if (s.startsWith(tableBaseName)) {
for (Iterator<String> iterator = tClient.listTables(tableBaseName, null, null); iterator.hasNext();) {
if (iterator.next().startsWith(tableBaseName)) {
currTable++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package com.microsoft.windowsazure.services.table.client;

import java.util.Iterator;
import java.util.UUID;

import junit.framework.Assert;
Expand Down Expand Up @@ -217,7 +218,8 @@ private void doQueryEscapeTest(String data) throws StorageException {

int count = 0;

for (class1 ent : tClient.execute(query)) {
for (Iterator<class1> iterator = tClient.execute(query); iterator.hasNext();) {
class1 ent = iterator.next();
count++;
Assert.assertEquals(ent.getA(), ref.getA());
Assert.assertEquals(ent.getB(), ref.getB());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
import java.net.HttpURLConnection;
import java.net.URISyntaxException;
import java.security.InvalidKeyException;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.UUID;
import java.util.*;

import junit.framework.Assert;

Expand Down Expand Up @@ -64,11 +61,12 @@ public void tableQueryWithDynamicEntity() {
// Create entity to check against
class1 randEnt = TableTestBase.generateRandomEnitity(null);

final Iterable<DynamicTableEntity> result = tClient.execute(TableQuery.from(testSuiteTableName,
final Iterator<DynamicTableEntity> result = tClient.execute(TableQuery.from(testSuiteTableName,
DynamicTableEntity.class));

// Validate results
for (DynamicTableEntity ent : result) {
while (result.hasNext()) {
DynamicTableEntity ent = result.next();
Assert.assertEquals(ent.getProperties().size(), 4);
Assert.assertEquals(ent.getProperties().get("A").getValueAsString(), randEnt.getA());
Assert.assertEquals(ent.getProperties().get("B").getValueAsString(), randEnt.getB());
Expand All @@ -81,11 +79,12 @@ public void tableQueryWithDynamicEntity() {
public void tableQueryWithProjection() {
// Create entity to check against
class1 randEnt = TableTestBase.generateRandomEnitity(null);
final Iterable<class1> result = tClient.execute(TableQuery.from(testSuiteTableName, class1.class).select(
final Iterator<class1> result = tClient.execute(TableQuery.from(testSuiteTableName, class1.class).select(
new String[] { "A", "C" }));

// Validate results
for (class1 ent : result) {
while (result.hasNext()) {
class1 ent = result.next();
// Validate core properties were sent.
Assert.assertNotNull(ent.getPartitionKey());
Assert.assertNotNull(ent.getRowKey());
Expand Down Expand Up @@ -116,12 +115,13 @@ public void eventOccurred(ResponseReceivedEvent eventArg) {
}
});

final Iterable<class1> result = tClient.execute(
final Iterator<class1> result = tClient.execute(
TableQuery.from(testSuiteTableName, class1.class).select(
new String[] { "PartitionKey", "RowKey", "Timestamp" }), null, opContext);

// Validate results
for (class1 ent : result) {
while (result.hasNext()) {
class1 ent = result.next();
Assert.assertEquals(ent.getA(), null);
Assert.assertEquals(ent.getB(), null);
Assert.assertEquals(ent.getC(), null);
Expand All @@ -134,10 +134,11 @@ public void tableQueryWithReflection() {
// Create entity to check against
class1 randEnt = TableTestBase.generateRandomEnitity(null);

final Iterable<class1> result = tClient.execute(TableQuery.from(testSuiteTableName, class1.class));
final Iterator<class1> result = tClient.execute(TableQuery.from(testSuiteTableName, class1.class));

// Validate results
for (class1 ent : result) {
while (result.hasNext()) {
class1 ent = result.next();
Assert.assertEquals(ent.getA(), randEnt.getA());
Assert.assertEquals(ent.getB(), randEnt.getB());
Assert.assertEquals(ent.getC(), randEnt.getC());
Expand All @@ -150,7 +151,7 @@ public void tableQueryWithResolver() {
// Create entity to check against
class1 randEnt = TableTestBase.generateRandomEnitity(null);

final Iterable<class1> result = tClient.execute(TableQuery.from(testSuiteTableName, TableServiceEntity.class),
final Iterator<class1> result = tClient.execute(TableQuery.from(testSuiteTableName, TableServiceEntity.class),
new EntityResolver<class1>() {
@Override
public class1 resolve(String partitionKey, String rowKey, Date timeStamp,
Expand All @@ -166,7 +167,8 @@ public class1 resolve(String partitionKey, String rowKey, Date timeStamp,
});

// Validate results
for (class1 ent : result) {
while (result.hasNext()) {
class1 ent = result.next();
Assert.assertEquals(ent.getA(), randEnt.getA());
Assert.assertEquals(ent.getB(), randEnt.getB());
Assert.assertEquals(ent.getC(), randEnt.getC());
Expand Down Expand Up @@ -202,7 +204,8 @@ public void tableQueryWithFilter() throws StorageException {

int count = 0;

for (class1 ent : tClient.execute(query)) {
for (Iterator<class1> iterator = tClient.execute(query); iterator.hasNext();) {
class1 ent = iterator.next();
Assert.assertEquals(ent.getA(), randEnt.getA());
Assert.assertEquals(ent.getB(), randEnt.getB());
Assert.assertEquals(ent.getC(), randEnt.getC());
Expand All @@ -225,7 +228,8 @@ public void tableQueryWithContinuation() throws StorageException {

int count = 0;
int pk = 1;
for (class1 ent : tClient.execute(query)) {
for (Iterator<class1> iterator = tClient.execute(query); iterator.hasNext();) {
class1 ent = iterator.next();
Assert.assertEquals(ent.getA(), randEnt.getA());
Assert.assertEquals(ent.getB(), randEnt.getB());
Assert.assertEquals(ent.getC(), randEnt.getC());
Expand Down Expand Up @@ -406,8 +410,8 @@ public void testQueryOnSupportedTypes() throws StorageException {
TableQuery<ComplexEntity> query = TableQuery.from(testSuiteTableName, ComplexEntity.class).where(
String.format("PartitionKey eq '%s'", pk));

for (ComplexEntity e : tClient.execute(query)) {
delBatch.delete(e);
for (Iterator<ComplexEntity> iterator = tClient.execute(query); iterator.hasNext();) {
delBatch.delete(iterator.next());
}

tClient.execute(testSuiteTableName, delBatch);
Expand All @@ -417,8 +421,7 @@ public void testQueryOnSupportedTypes() throws StorageException {
private void executeQueryAndAssertResults(String filter, int expectedResults) {
int count = 0;
TableQuery<ComplexEntity> query = TableQuery.from(testSuiteTableName, ComplexEntity.class).where(filter);
for (@SuppressWarnings("unused")
ComplexEntity e : tClient.execute(query)) {
for (Iterator<ComplexEntity> iterator = tClient.execute(query); iterator.hasNext();) {
count++;
}

Expand Down