org.soyatec.windows.azure.table
Class AzureTable

java.lang.Object
  extended by org.soyatec.windows.azure.table.AzureTable
All Implemented Interfaces:
BatchStorage
Direct Known Subclasses:
AzureTableRest

public abstract class AzureTable
extends java.lang.Object
implements BatchStorage

API entry point for using structured storage.

The underlying usage pattern is designed to be similar to the one used in blob and queue services in this library.

Batch operations
The AzureTable implements the BatchStorage. Some TRANSCATION supported operations can be enlist a single batch operation. Example:
      SampleEntity sampleEntity1 = createSampleEntity();
                SampleEntity sampleEntity2 = createSampleEntity();
                try {
                        table.startBatch();
                        table.insertEntity(sampleEntity1);
                        table.insertEntity(sampleEntity2);
                        table.executeBatch();
            catch(Exception e){
                //
            }
 
For more detail about Batch operation, see BatchStorage.


Field Summary
 
Fields inherited from interface org.soyatec.windows.azure.table.BatchStorage
BATCH_BOUNDARY_PREFIX, BATCH_PATH, CHANGESET_BOUNDARY_PREFIX
 
Method Summary
abstract  void createTable()
          Creates a new table in the service
abstract  void deleteEntity(TableStorageEntity obj)
          Deletes an entity within a table
abstract  void deleteEntityIfNotModified(TableStorageEntity obj)
          Deletes a table entity if the entity is not modified after it is loaded from azure table storage.
abstract  void deleteTable()
          Deletes a table from the service.
abstract  boolean doesTableExist()
          Checks whether a table with the same name already exists.
 java.lang.String getAccountName()
          Get the name of the storage account
 java.net.URI getBaseUri()
          Get the base uri of the table service
 java.lang.Class<? extends TableStorageEntity> getModelClass()
          Get the model class for this table.
 RetryPolicy getRetryPolicy()
          Get the retry policy used for retrying requests
 java.lang.String getTableName()
          Get the name of specified table.
 TimeSpan getTimeout()
          Get the timeout per requeet
abstract  void insertEntity(TableStorageEntity obj)
          Inserts a new entity into a table.
 boolean isUsePathStyleUris()
          Whether use/generate path-style or host-style URIs
abstract
<T extends TableStorageEntity>
T
loadEntity(T entity)
          Load the entity within table by the entity identifier(PartitionKey and RowKey).
abstract  void mergeEntity(TableStorageEntity obj)
          Merges table entity
abstract  java.util.List<TableStorageEntity> retrieveEntities()
          This operation queries entities in a table.
abstract  java.util.List<TableStorageEntity> retrieveEntities(java.lang.String queryExpression)
          This operation queries entities in a table.
abstract  java.util.List<TableStorageEntity> retrieveEntitiesByKey(java.lang.String partitionKey, java.lang.String rowKey)
           
 void setModelClass(java.lang.Class<? extends TableStorageEntity> modelClass)
          Set model class for this table.
 void setRetryPolicy(RetryPolicy retryPolicy)
          Set the RetryPolicy userd for retrying requests
 void setTimeout(TimeSpan timeout)
          Set timeout per request
abstract  void updateEntity(TableStorageEntity obj)
          Updates an existing entity within a table by replacing it.
abstract  void updateEntityIfNotModified(TableStorageEntity obj)
          Updates table entity if the entity is not modified after it is loaded from azure table storage.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.soyatec.windows.azure.table.BatchStorage
clearBatch, executeBatch, isInBatch, startBatch
 

Method Detail

createTable

public abstract void createTable()
Creates a new table in the service


doesTableExist

public abstract boolean doesTableExist()
Checks whether a table with the same name already exists.

Returns:
True if the table already exists.

deleteTable

public abstract void deleteTable()
Deletes a table from the service.

When a table is successfully deleted, it is immediately marked for deletion and is no longer accessible to clients. The table is later removed from the Table service during garbage collection.

Note that deleting a table is likely to take at least 40 seconds to complete. If an operation is attempted against the table while it was being deleted, the service returns status code 409 (Conflict), with additional error information indicating that the table is being deleted.

Parameters:
tableName - The name of the table to be deleted

insertEntity

public abstract void insertEntity(TableStorageEntity obj)
                           throws StorageException
Inserts a new entity into a table.

When inserting an entity into a table, you must specify values for the PartitionKey and RowKey system properties. Together, these properties form the primary key and must be unique within the table.

Both the PartitionKey and RowKey values must be string values; each key value may be up to 64 KB in size. If you are using an integer value for the key value, you should convert the integer to a fixed-width string, because they are canonically sorted. For example, you should convert the value 1 to 0000001 to ensure proper sorting.

Reference Insert entity

Parameters:
obj - The object to be inserted. The entity shoule be instance of TableStorageEntity or subclass of TableStorageEntity
Throws:
StorageException

updateEntity

public abstract void updateEntity(TableStorageEntity obj)
                           throws StorageException
Updates an existing entity within a table by replacing it. When updating an entity, you must specify the PartitionKey and RowKey system properties as part of the update operation.

An entity's ETag provides default optimistic concurrency for update operations. The ETag value is opaque and should not be read or relied upon. Before an update operation occurs, the Table service verifies that the entity's current ETag value is identical to the ETag value included with the update request. If the values are identical, the Table service determines that the entity has not been modified since it was retrieved, and the update operation proceeds.

If the entity's ETag differs from that specified with the update request, the update operation fails with status code 412 (Precondition Failed). This error indicates that the entity has been changed on the server since it was retrieved. To resolve this error, retrieve the entity again and reissue the request.

To force an unconditional update operation, set the value of the If-Match header to the wildcard character (*) on the request. Passing this value to the operation will override the default optimistic concurrency and ignore any mismatch in ETag values.

If the If-Match header is missing from the request, the service returns status code 400 (Bad Request). A request malformed in other ways may also return 400; see Table Service Error Codes for more information.

If the request specifies a property with a null value, that property is ignored, the update proceeds, and the existing entity is replaced.

Reference Update entity

Parameters:
obj - the object to be updated
Throws:
StorageException

updateEntityIfNotModified

public abstract void updateEntityIfNotModified(TableStorageEntity obj)
                                        throws StorageException
Updates table entity if the entity is not modified after it is loaded from azure table storage. TableStorageEntity should have etag value which is retrieved from table storage.

Parameters:
obj - the object to be updated
Throws:
StorageException
See Also:
#updateEntity(TableStorageEntity)}

mergeEntity

public abstract void mergeEntity(TableStorageEntity obj)
                          throws StorageException
Merges table entity

Updates an existing entity within a table by merging new property values into the entity.

Remark

Any properties with null values are ignored by the Merge Entity operation. All other properties will be updated.

A property cannot be removed with a Merge Entity operation. To remove a property from an entity, replace the entity by calling the Update Entity operation.

When merging an entity, you must specify the PartitionKey and RowKey system properties as part of the merge operation.

An entity's ETag provides default optimistic concurrency for merge operations. The ETag value is opaque and should not be read or relied upon. Before a merge operation occurs, the Table service verifies that the entity's current ETag value is identical to the ETag value included with the request. If the values are identical, the Table service determines that the entity has not been modified since it was retrieved, and the merge operation proceeds.

If the entity's ETag differs from that specified with the merge request, the merge operation fails with status code 412 (Precondition Failed). This error indicates that the entity has been changed on the server since it was retrieved. To resolve this error, retrieve the entity again and reissue the request.

To force an unconditional merge operation, set the value of the If-Match header to the wildcard character (*) on the request. Passing this value to the operation will override the default optimistic concurrency and ignore any mismatch in ETag values.

Reference Merge entity

Parameters:
obj - the object to be merged
Throws:
StorageException

deleteEntity

public abstract void deleteEntity(TableStorageEntity obj)
                           throws StorageException
Deletes an entity within a table

When an entity is successfully deleted, the entity is immediately marked for deletion and is no longer accessible to clients. The entity is later removed from the Table service during garbage collection.

Parameters:
obj - the object to be deleted
Throws:
StorageException - If entity is not exists, an exception is also thrown.

deleteEntityIfNotModified

public abstract void deleteEntityIfNotModified(TableStorageEntity obj)
                                        throws StorageException
Deletes a table entity if the entity is not modified after it is loaded from azure table storage. TableStorageEntity should have etag value which is retrieved from table storage.

Parameters:
obj - the object to be deleted
Throws:
StorageException
See Also:
#deleteEntity(TableStorageEntity)}

loadEntity

public abstract <T extends TableStorageEntity> T loadEntity(T entity)
                                                 throws StorageException
Load the entity within table by the entity identifier(PartitionKey and RowKey).

Type Parameters:
T - TableStorageEntity instance of subclass of TableStorageEntity instance
Parameters:
entity - Specified Entity
Returns:
Entity within table
Throws:
StorageException

retrieveEntities

public abstract java.util.List<TableStorageEntity> retrieveEntities(java.lang.String queryExpression)
                                                             throws StorageException
This operation queries entities in a table. A query against a table returns a list of entities conforming to the criteria specified in the query.

Parameters:
queryExpression - If queryExpression is not given, all rows are return.
Returns:
A list of TableStorageEntity
Throws:
StorageException

retrieveEntities

public abstract java.util.List<TableStorageEntity> retrieveEntities()
                                                             throws StorageException
This operation queries entities in a table. A query against a table returns a list of entities conforming to the criteria specified in the query.

Returns:
A list of TableStorageEntity
Throws:
StorageException

retrieveEntitiesByKey

public abstract java.util.List<TableStorageEntity> retrieveEntitiesByKey(java.lang.String partitionKey,
                                                                         java.lang.String rowKey)
                                                                  throws StorageException
Parameters:
partitionKey -
rowKey -
Returns:
A list of entities who's partition key and row key are all euqals with the given.
Throws:
StorageException

getBaseUri

public java.net.URI getBaseUri()
Get the base uri of the table service

Returns:

getAccountName

public java.lang.String getAccountName()
Get the name of the storage account

Returns:

getTableName

public java.lang.String getTableName()
Get the name of specified table.

Returns:

isUsePathStyleUris

public boolean isUsePathStyleUris()
Whether use/generate path-style or host-style URIs

Returns:

getTimeout

public TimeSpan getTimeout()
Get the timeout per requeet

Returns:

getRetryPolicy

public RetryPolicy getRetryPolicy()
Get the retry policy used for retrying requests

Returns:

setTimeout

public void setTimeout(TimeSpan timeout)
Set timeout per request

Parameters:
timeout -

setRetryPolicy

public void setRetryPolicy(RetryPolicy retryPolicy)
Set the RetryPolicy userd for retrying requests

Parameters:
retryPolicy -

getModelClass

public java.lang.Class<? extends TableStorageEntity> getModelClass()
Get the model class for this table.

Returns:
modelClass

setModelClass

public void setModelClass(java.lang.Class<? extends TableStorageEntity> modelClass)
Set model class for this table.

Parameters:
modelClass -
See Also:
#modelClass}