Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

# javadoc for CloudTableClient & CloudTableObject ()

# refactor of a method found while documenting
  • Loading branch information...
commit 2dbcea9633098798a90bd5753aee447154933933 1 parent bea9fe4
Mauro Krikorian authored
View
36 library/storage/src/com/windowsazure/samples/android/storageclient/CloudTableClient.java
@@ -6,24 +6,28 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.sql.Timestamp;
+
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
+
import com.windowsazure.samples.android.storageclient.StorageCredentials;
import com.windowsazure.samples.android.storageclient.Utility;
+/**
+Provides a client for accessing the Windows Azure Table service.
+*/
public class CloudTableClient {
private URI m_Endpoint;
private StorageCredentials m_Credentials;
/**
- Returns a new instance of the CloudTableClient that is used to handle the tables at table storage.
- @param baseUri an absolute {@link URI} giving the base location of the table storage
- @param credentials the {@link StorageCredentials} used to access the storage repository
- @return a new instance of a CloudTableClient object to manage tables
- @see StorageCredentials
+ Initializes a new instance of the CloudTableClient class using the specified Table service endpoint and account credentials.
+ @param baseUri an absolute {@link URI} giving the base location of the table storage
+ @param credentials the {@link StorageCredentials} used to access the storage repository
+ @see StorageCredentials
*/
public CloudTableClient(URI baseUri, StorageCredentials credentials) {
Utility.assertNotNull("baseUri", baseUri);
@@ -61,9 +65,9 @@ public StorageCredentials getCredentials() {
return m_Credentials;
}
- /**
+ /**
Checks whether the table exists.
- @param tableName the table name to check for
+ @param tableName the table name to check for
@return true if table exists; otherwise, false
*/
public boolean doesTableExist(String tableName) throws UnsupportedEncodingException, StorageException, IOException {
@@ -122,7 +126,7 @@ public Boolean execute() throws Exception {
/**
Creates a table with specified name.
- @param tableName the table name to create
+ @param tableName the table name to create
*/
public void createTable(String tableName)
throws UnsupportedEncodingException, StorageException, IOException {
@@ -143,7 +147,7 @@ public Void execute() throws Exception {
/**
Creates the table if it does not already exist.
- @param tableName the table name to create
+ @param tableName the table name to create
@return true if table was created; otherwise, false
*/
public boolean createTableIfNotExist(String tableName) throws UnsupportedEncodingException, StorageException, IOException {
@@ -161,7 +165,7 @@ public boolean createTableIfNotExist(String tableName) throws UnsupportedEncodin
/**
Deletes the table.
- @param tableName the table name to delete
+ @param tableName the table name to delete
*/
public void deleteTable(String tableName) throws UnsupportedEncodingException, StorageException, IOException {
final String thatTableName = tableName;
@@ -181,7 +185,7 @@ public Void execute() throws Exception {
/**
Deletes the table if it exists.
- @param tableName the table name to delete
+ @param tableName the table name to delete
@return true if table was deleted; otherwise, false
*/
public boolean deleteTableIfExist(String tableName) throws UnsupportedEncodingException, StorageException, IOException {
@@ -199,9 +203,9 @@ public boolean deleteTableIfExist(String tableName) throws UnsupportedEncodingEx
/**
Creates tables from a class model defined in code. The table created will have the same name as the type used as parameter to create it.
- @param type the type of the class that defines the table
- @param baseAddress an absolute {@link URI} giving the base location of the table storage
- @param credentials the {@link StorageCredentials} used to access the storage repository
+ @param type the type of the class that defines the table
+ @param baseAddress an absolute {@link URI} giving the base location of the table storage
+ @param credentials the {@link StorageCredentials} used to access the storage repository
*/
public static void CreateTableFromModel(Class<?> type, final String baseAddress, final StorageCredentials credentials)
throws UnsupportedEncodingException, StorageException, IOException, URISyntaxException {
@@ -238,9 +242,9 @@ public Void execute() throws Exception {
/**
Creates a new instance of a CloudTableObject to handle table entities.
- @param tableName the table name to handle
+ @param tableName the table name to handle
@return a new instance of {@link CloudTableObject} to handle table's items
- @see CloudTableObject
+ @see CloudTableObject
*/
public <E extends CloudTableEntity> CloudTableObject<E> getCloudTableObject(String tableName) {
return new CloudTableObject<E>(tableName, m_Endpoint, m_Credentials);
View
5 library/storage/src/com/windowsazure/samples/android/storageclient/CloudTableEntity.java
@@ -1,5 +1,10 @@
package com.windowsazure.samples.android.storageclient;
+/**
+Base class for entity classes to be used with CloudTableObject instances.
+@see CloudTableObject
+*/
+
public abstract class CloudTableEntity {
public String PartitionKey;
public String RowKey;
View
116 library/storage/src/com/windowsazure/samples/android/storageclient/CloudTableObject.java
@@ -15,12 +15,23 @@
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpRequestBase;
+/**
+Provides a client for accessing a Windows Azure Table entities.
+@see CloudTableEntity
+*/
public class CloudTableObject<E extends CloudTableEntity> {
private String m_TableName;
private URI m_Endpoint;
private StorageCredentials m_Credentials;
-
+
+ /**
+ Initializes a new instance of the CloudTableObject class using the specified Table service endpoint and account credentials for a specific Table.
+ @param tableName the table name to handle
+ @param baseUri an absolute {@link URI} giving the base location of the table storage
+ @param credentials the {@link StorageCredentials} used to access the storage repository
+ @see StorageCredentials
+ */
public CloudTableObject(String tableName, URI baseUri, StorageCredentials credentials) {
Utility.assertNotNull("baseUri", baseUri);
Utility.assertNotNull("credentials", credentials);
@@ -33,29 +44,65 @@ public CloudTableObject(String tableName, URI baseUri, StorageCredentials creden
m_Credentials = credentials;
m_TableName = tableName;
}
-
+
+ /**
+ Gets the table name of the handled Table.
+ @return table name for handled Table
+ */
public String getTableName() {
return m_TableName;
}
+ /**
+ Gets the base location of the table storage.
+ @return the URI value of the table storage
+ */
public URI getBaseUri() {
return m_Endpoint;
}
+ /**
+ Gets the credentials used to access the table storage.
+ @return the credentials for accesing the table storage
+ */
public StorageCredentials getCredentials() {
return m_Credentials;
}
+ /**
+ Returns an iterable collection of table entities for the storage account.
+ @param baseUri an absolute {@link URI} giving the base location of the table storage
+ @param credentials the {@link StorageCredentials} used to access the storage repository
+ @param tableName the table name to query entities from
+ @return an iterable collection of table entities
+ */
public static Iterable<Map<String, Object>> query(URI baseUri, StorageCredentials credentials, String tableName)
throws UnsupportedEncodingException, StorageException, IOException {
return query(baseUri, credentials, tableName, null);
}
+ /**
+ Returns an iterable collection of table entities for the storage account that satisfy a the specified filter.
+ @param baseUri an absolute {@link URI} giving the base location of the table storage
+ @param credentials the {@link StorageCredentials} used to access the storage repository
+ @param tableName the table name to query entities from
+ @param filter the filter that entities must satisfy
+ @return an iterable collection of table entities
+ */
public static Iterable<Map<String, Object>> query(URI baseUri, StorageCredentials credentials, String tableName, String filter)
throws UnsupportedEncodingException, StorageException, IOException {
return query(baseUri, credentials, tableName, filter, 0);
}
+ /**
+ Returns an iterable collection of the first N (specified by parameter top) table entities for the storage account that satisfy a the specified filter.
+ @param baseUri an absolute {@link URI} giving the base location of the table storage
+ @param credentials the {@link StorageCredentials} used to access the storage repository
+ @param tableName the table name to query entities from
+ @param filter the filter that entities must satisfy
+ @param top the max number of entities to retrieve
+ @return an iterable collection of table entities
+ */
public static Iterable<Map<String, Object>> query(URI baseUri, StorageCredentials credentials, String tableName, String filter, int top)
throws UnsupportedEncodingException, StorageException, IOException {
final URI thatUri = baseUri;
@@ -73,6 +120,13 @@ public StorageCredentials getCredentials() {
return storageOperation.executeTranslatingExceptions();
}
+ /**
+ Inserts a new table entity for the storage account.
+ @param baseUri an absolute {@link URI} giving the base location of the table storage
+ @param credentials the {@link StorageCredentials} used to access the storage repository
+ @param tableName the table name to query entities from
+ @param properties a map that represents the properties (key/value) of an entity
+ */
public static void insert(URI baseUri, StorageCredentials credentials, String tableName, Map<String, Object> properties)
throws UnsupportedEncodingException, StorageException, IOException {
final URI thatUri = baseUri;
@@ -89,6 +143,13 @@ public Void execute() throws Exception {
storageOperation.executeTranslatingExceptions();
}
+ /**
+ Updates a table entity for the storage account.
+ @param baseUri an absolute {@link URI} giving the base location of the table storage
+ @param credentials the {@link StorageCredentials} used to access the storage repository
+ @param tableName the table name to query entities from
+ @param properties a map that represents the properties (key/value) of an entity
+ */
public static void update(URI baseUri, StorageCredentials credentials, String tableName, Map<String, Object> properties)
throws UnsupportedEncodingException, StorageException, IOException {
final URI thatUri = baseUri;
@@ -105,14 +166,32 @@ public Void execute() throws Exception {
storageOperation.executeTranslatingExceptions();
}
+ /**
+ Returns an iterable collection of table entities for the storage account.
+ @param clazz the type of the entity object to retrieve
+ @return an iterable collection of table entities
+ */
public Iterable<E> query(Class<E> clazz) throws Exception {
return query(clazz, null);
}
+ /**
+ Returns an iterable collection of table entities for the storage account that satisfy a the specified filter.
+ @param clazz the type of the entity object to retrieve
+ @param filter the filter that entities must satisfy
+ @return an iterable collection of table entities
+ */
public Iterable<E> query(Class<E> clazz, String filter) throws Exception {
return query(clazz, filter, 0);
}
+ /**
+ Returns an iterable collection of the first N (specified by parameter top) table entities for the storage account that satisfy a the specified filter.
+ @param clazz the type of the entity object to retrieve
+ @param filter the filter that entities must satisfy
+ @param top the max number of entities to retrieve
+ @return an iterable collection of table entities
+ */
public Iterable<E> query(Class<E> clazz, String filter, int top) throws Exception {
final String thatFilter = filter;
final Class<E> thatClazz = clazz;
@@ -127,6 +206,10 @@ public Void execute() throws Exception {
return storageOperation.executeTranslatingExceptions();
}
+ /**
+ Inserts a new table entity for the storage account.
+ @param entity the entity to insert into the table
+ */
public void insert(E entity) throws UnsupportedEncodingException, StorageException, IOException {
final E thatEntity = entity;
StorageOperation<Void> storageOperation = new StorageOperation<Void>() {
@@ -139,6 +222,10 @@ public Void execute() throws Exception {
storageOperation.executeTranslatingExceptions();
}
+ /**
+ Inserts or replaces a table entity for the storage account.
+ @param entity the entity to insert or replace into the table
+ */
public void insertOrReplace(E entity) throws UnsupportedEncodingException, StorageException, IOException {
final E thatEntity = entity;
StorageOperation<Void> storageOperation = new StorageOperation<Void>() {
@@ -151,6 +238,10 @@ public Void execute() throws Exception {
storageOperation.executeTranslatingExceptions();
}
+ /**
+ Inserts or merges a table entity for the storage account.
+ @param entity the entity to insert or merge into the table
+ */
public void insertOrMerge(E entity) throws UnsupportedEncodingException, StorageException, IOException {
final E thatEntity = entity;
StorageOperation<Void> storageOperation = new StorageOperation<Void>() {
@@ -163,6 +254,10 @@ public Void execute() throws Exception {
storageOperation.executeTranslatingExceptions();
}
+ /**
+ Updates a table entity for the storage account.
+ @param entity the entity to update in the table
+ */
public void update(E entity) throws UnsupportedEncodingException, StorageException, IOException {
final E thatEntity = entity;
StorageOperation<Void> storageOperation = new StorageOperation<Void>() {
@@ -175,6 +270,10 @@ public Void execute() throws Exception {
storageOperation.executeTranslatingExceptions();
}
+ /**
+ Merges a table entity for the storage account.
+ @param entity the entity to merge in the table
+ */
public void merge(E entity) throws UnsupportedEncodingException, StorageException, IOException {
final E thatEntity = entity;
StorageOperation<Void> storageOperation = new StorageOperation<Void>() {
@@ -187,6 +286,10 @@ public Void execute() throws Exception {
storageOperation.executeTranslatingExceptions();
}
+ /**
+ Deletes a table entity for the storage account.
+ @param entity the entity to delete from the table
+ */
public void delete(E entity) throws UnsupportedEncodingException, StorageException, IOException {
final E thatEntity = entity;
StorageOperation<Void> storageOperation = new StorageOperation<Void>() {
@@ -199,6 +302,11 @@ public Void execute() throws Exception {
storageOperation.executeTranslatingExceptions();
}
+ /**
+ Deletes a table entity for the storage account.
+ @param partitionKey the partition key of the entity to delete
+ @param rowKey the row key of the entity to delete
+ */
public void delete(String partitionKey, String rowKey) throws UnsupportedEncodingException, StorageException, IOException {
final String thatPartitionKey = partitionKey;
final String thatRowKey = rowKey;
@@ -240,8 +348,4 @@ private static void signCallNValidate(HttpRequestBase request, StorageOperation<
}
- public static String encodeValueForFilter(String value) {
- return value.replace("'", "''");
- }
-
}
View
14 library/storage/src/com/windowsazure/samples/android/storageclient/TableRequest.java
@@ -118,8 +118,8 @@ public static HttpDelete deleteEntity(URI endpoint, String tableName, TablePrope
public static HttpDelete deleteEntity(URI endpoint, String tableName, String partitionKey, String rowKey) throws IOException, URISyntaxException, StorageException {
String requestUri = endpoint.toASCIIString() + String.format("/%s(PartitionKey='%s',RowKey='%s')",
tableName,
- Utility.safeEncode(CloudTableObject.encodeValueForFilter(partitionKey)),
- Utility.safeEncode(CloudTableObject.encodeValueForFilter(rowKey)));
+ Utility.safeEncode(encodeValueForFilter(partitionKey)),
+ Utility.safeEncode(encodeValueForFilter(rowKey)));
HttpDelete result = BaseRequest.setTableURIAndHeaders(new HttpDelete(), new URI(requestUri), new UriQueryBuilder());
addRequiredHeaders(result, "0", "*", false);
return result;
@@ -127,6 +127,10 @@ public static HttpDelete deleteEntity(URI endpoint, String tableName, String par
// help stuff
+ private static String encodeValueForFilter(String value) {
+ return value.replace("'", "''");
+ }
+
private static void addRequiredHeaders(HttpRequestBase request) {
addRequiredHeaders(request, null, null, false);
}
@@ -180,10 +184,10 @@ private static CloudTableEntity getEntitiyKeys(TableProperty<?>[] properties) th
CloudTableEntity result = new CloudTableEntityKey();
for (int i = 0; i < properties.length; i++) {
if (properties[i].getName().equals("PartitionKey")) {
- result.PartitionKey = Utility.safeEncode(CloudTableObject.encodeValueForFilter(properties[i].getRepresentation()));
+ result.PartitionKey = Utility.safeEncode(encodeValueForFilter(properties[i].getRepresentation()));
continue;
} else if (properties[i].getName().equals("RowKey")) {
- result.RowKey = Utility.safeEncode(CloudTableObject.encodeValueForFilter(properties[i].getRepresentation()));
+ result.RowKey = Utility.safeEncode(encodeValueForFilter(properties[i].getRepresentation()));
}
}
Utility.assertNotNull("PartitionKey property not found", result.PartitionKey);
@@ -205,7 +209,7 @@ private static String getXmlTimeWithTZ() {
sdf.setTimeZone(GMT_ZONE);
return sdf.format(new Date());
}
-
+
private static class CloudTableEntityKey extends CloudTableEntity { }
private static class HttpMerge extends HttpEntityEnclosingRequestBase {
View
9 samples/simple/src/com/windowsazure/samples/android/sampleapp/StorageEntityActivity.java
@@ -109,8 +109,8 @@ public void onStart() {
switch (operationType){
case OPERATION_TYPE_EDIT: {
String filter = String.format("PartitionKey eq '%s' and RowKey eq '%s'",
- CloudTableObject.encodeValueForFilter(partitionKey),
- CloudTableObject.encodeValueForFilter(rowKey));
+ encodeValueForFilter(partitionKey),
+ encodeValueForFilter(rowKey));
entities = CloudTableObject.query(tableClient.getEndpoint(), tableCredentials, tableName, filter);
break;
}
@@ -305,4 +305,9 @@ private void addEditView(String id, String value, LinearLayout layout, boolean e
}
return editViews;
}
+
+ private static String encodeValueForFilter(String value) {
+ return value.replace("'", "''");
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.