Java Code Examples for com.microsoft.azure.storage.table.CloudTable#create()

The following examples show how to use com.microsoft.azure.storage.table.CloudTable#create() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AzureStorageTableService.java    From components with Apache License 2.0 6 votes vote down vote up
/**
 * This method create a table after it's deletion.<br/>
 * the table deletion take about 40 seconds to be effective on azure CF.
 * https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/Delete-Table#Remarks <br/>
 * So we try to wait 50 seconds if the first table creation return an
 * {@link StorageErrorCodeStrings.TABLE_BEING_DELETED } exception code
 * 
 * @param cloudTable
 * 
 * @throws StorageException
 * @throws IOException
 * 
 */
private void createTableAfterDeletion(CloudTable cloudTable) throws StorageException, IOException {
    try {
        cloudTable.create(null, AzureStorageUtils.getTalendOperationContext());
    } catch (TableServiceException e) {
        if (!e.getErrorCode().equals(StorageErrorCodeStrings.TABLE_BEING_DELETED)) {
            throw e;
        }
        LOGGER.warn("Table '{}' is currently being deleted. We'll retry in a few moments...", cloudTable.getName());
        // wait 50 seconds (min is 40s) before retrying.
        // See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/Delete-Table#Remarks
        try {
            Thread.sleep(50000);
        } catch (InterruptedException eint) {
            throw new IOException("Wait process for recreating table interrupted.");
        }
        cloudTable.create(null, AzureStorageUtils.getTalendOperationContext());
        LOGGER.debug("Table {} created.", cloudTable.getName());
    }
}
 
Example 2
Source File: AzureStorageTableService.java    From components with Apache License 2.0 5 votes vote down vote up
public void handleActionOnTable(String tableName, ActionOnTable actionTable)
        throws IOException, StorageException, InvalidKeyException, URISyntaxException {

    // FIXME How does this will behave in a distributed runtime ? See where to place correctly this
    // instruction...
    CloudTable cloudTable = connection.getCloudStorageAccount().createCloudTableClient().getTableReference(tableName);
    switch (actionTable) {
    case Create_table:
        cloudTable.create(null, AzureStorageUtils.getTalendOperationContext());
        break;
    case Create_table_if_does_not_exist:
        cloudTable.createIfNotExists(null, AzureStorageUtils.getTalendOperationContext());
        break;
    case Drop_and_create_table:
        cloudTable.delete(null, AzureStorageUtils.getTalendOperationContext());
        createTableAfterDeletion(cloudTable);
        break;
    case Drop_table_if_exist_and_create:
        cloudTable.deleteIfExists(null, AzureStorageUtils.getTalendOperationContext());
        createTableAfterDeletion(cloudTable);
        break;
    case Default:
    default:
        return;
    }

}