当前位置: 首页>>代码示例>>Java>>正文


Java CloudTable类代码示例

本文整理汇总了Java中com.microsoft.azure.storage.table.CloudTable的典型用法代码示例。如果您正苦于以下问题:Java CloudTable类的具体用法?Java CloudTable怎么用?Java CloudTable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CloudTable类属于com.microsoft.azure.storage.table包,在下文中一共展示了CloudTable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: partitionRangeQuery

import com.microsoft.azure.storage.table.CloudTable; //导入依赖的package包/类
/**
 * Demonstrate a partition range query whereby we are searching within a partition for a set of entities that are within a specific range.
 *
 * @param table The {@link CloudTable} object
 * @param partitionKey The partition within which to search
 * @param startRowKey The lowest bound of the row key range within which to search
 * @param endRowKey The highest bound of the row key range within which to search
 *
 * @throws StorageException
 */
private static void partitionRangeQuery(CloudTable table, String partitionKey, String startRowKey, String endRowKey) throws StorageException {

    // Create the range scan query
    TableQuery<CustomerEntity> rangeQuery = TableQuery.from(CustomerEntity.class).where(
        TableQuery.combineFilters(
            TableQuery.generateFilterCondition("PartitionKey", QueryComparisons.EQUAL, partitionKey),
            TableQuery.Operators.AND,
            TableQuery.combineFilters(
                TableQuery.generateFilterCondition("RowKey", QueryComparisons.GREATER_THAN_OR_EQUAL, startRowKey),
                TableQuery.Operators.AND,
                TableQuery.generateFilterCondition("RowKey", QueryComparisons.LESS_THAN_OR_EQUAL, endRowKey))));

    // Iterate through the results
    for (CustomerEntity entity : table.execute(rangeQuery)) {
        System.out.println(String.format("\tCustomer: %s,%s\t%s\t%s\t%s", entity.getPartitionKey(), entity.getRowKey(), entity.getEmail(), entity.getHomePhoneNumber(), entity.getWorkPhoneNumber()));
    }
}
 
开发者ID:Azure-Samples,项目名称:storage-table-java-getting-started,代码行数:28,代码来源:TableBasics.java

示例2: connectToAzTable

import com.microsoft.azure.storage.table.CloudTable; //导入依赖的package包/类
/***
 *
 * @param azStorageConnStr
 * @param tableName
 * @param l
   * @return
   */
public CloudTable connectToAzTable(String azStorageConnStr, String tableName) {
	CloudTable cloudTable = null;
	try {
		// Retrieve storage account from connection-string.
		CloudStorageAccount storageAccount = CloudStorageAccount.parse(azStorageConnStr);

		// Create the table client
		CloudTableClient tableClient = storageAccount.createCloudTableClient();

		// Create a cloud table object for the table.
		cloudTable = tableClient.getTableReference(tableName);
		
	} catch (Exception e) 
	{
		logger.warn("Exception in connectToAzTable: "+tableName, e);
	}
	return cloudTable;
}
 
开发者ID:dream-lab,项目名称:echo,代码行数:26,代码来源:InsertAzure.java

示例3: createTable

import com.microsoft.azure.storage.table.CloudTable; //导入依赖的package包/类
/**
 * Creates and returns a table for the sample application to use.
 *
 * @param tableClient CloudTableClient object
 * @param tableName Name of the table to create
 * @return The newly created CloudTable object
 *
 * @throws StorageException
 * @throws RuntimeException
 * @throws IOException
 * @throws URISyntaxException
 * @throws IllegalArgumentException
 * @throws InvalidKeyException
 * @throws IllegalStateException
 */
private static CloudTable createTable(CloudTableClient tableClient, String tableName) throws StorageException, RuntimeException, IOException, InvalidKeyException, IllegalArgumentException, URISyntaxException, IllegalStateException {

    // Create a new table
    CloudTable table = tableClient.getTableReference(tableName);
    try {
        if (table.createIfNotExists() == false) {
            throw new IllegalStateException(String.format("Table with name \"%s\" already exists.", tableName));
        }
    }
    catch (StorageException s) {
        if (s.getCause() instanceof java.net.ConnectException) {
            System.out.println("Caught connection exception from the client. If running with the default configuration please make sure you have started the storage emulator.");
        }
        throw s;
    }

    return table;
}
 
开发者ID:Azure-Samples,项目名称:storage-table-java-getting-started,代码行数:34,代码来源:TableBasics.java

示例4: createTableAfterDeletion

import com.microsoft.azure.storage.table.CloudTable; //导入依赖的package包/类
/**
 * 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();
    } 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();
        LOGGER.debug("Table {} created.", cloudTable.getName());
    }
}
 
开发者ID:Talend,项目名称:components,代码行数:33,代码来源:AzureStorageTableService.java

示例5: testTableDownloadPermissions

import com.microsoft.azure.storage.table.CloudTable; //导入依赖的package包/类
private static void testTableDownloadPermissions(LocationMode optionsLocationMode, LocationMode clientLocationMode,
        StorageLocation initialLocation, List<RetryContext> retryContextList, List<RetryInfo> retryInfoList)
        throws URISyntaxException, StorageException {
    CloudTableClient client = TestHelper.createCloudTableClient();
    CloudTable table = client.getTableReference(TableTestHelper.generateRandomTableName());

    MultiLocationTestHelper helper = new MultiLocationTestHelper(table.getServiceClient().getStorageUri(),
            initialLocation, retryContextList, retryInfoList);

    table.getServiceClient().getDefaultRequestOptions().setLocationMode(clientLocationMode);
    TableRequestOptions options = new TableRequestOptions();

    options.setLocationMode(optionsLocationMode);
    options.setRetryPolicyFactory(helper.retryPolicy);

    try {
        table.downloadPermissions(options, helper.operationContext);
    }
    catch (StorageException ex) {
        assertEquals(HttpURLConnection.HTTP_NOT_FOUND, ex.getHttpStatusCode());
    }
    finally {
        helper.close();
    }
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:26,代码来源:SecondaryTests.java

示例6: testCloudStorageAccountClientUriVerify

import com.microsoft.azure.storage.table.CloudTable; //导入依赖的package包/类
@Test
public void testCloudStorageAccountClientUriVerify() throws URISyntaxException, StorageException {
    StorageCredentialsAccountAndKey cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, ACCOUNT_KEY);
    CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(cred, true);

    CloudBlobClient blobClient = cloudStorageAccount.createCloudBlobClient();
    CloudBlobContainer container = blobClient.getContainerReference("container1");
    assertEquals(cloudStorageAccount.getBlobEndpoint().toString() + "/container1", container.getUri().toString());

    CloudQueueClient queueClient = cloudStorageAccount.createCloudQueueClient();
    CloudQueue queue = queueClient.getQueueReference("queue1");
    assertEquals(cloudStorageAccount.getQueueEndpoint().toString() + "/queue1", queue.getUri().toString());

    CloudTableClient tableClient = cloudStorageAccount.createCloudTableClient();
    CloudTable table = tableClient.getTableReference("table1");
    assertEquals(cloudStorageAccount.getTableEndpoint().toString() + "/table1", table.getUri().toString());

    CloudFileClient fileClient = cloudStorageAccount.createCloudFileClient();
    CloudFileShare share = fileClient.getShareReference("share1");
    assertEquals(cloudStorageAccount.getFileEndpoint().toString() + "/share1", share.getUri().toString());
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:22,代码来源:StorageAccountTests.java

示例7: getLogDataTable

import com.microsoft.azure.storage.table.CloudTable; //导入依赖的package包/类
/**
 * For the Azure Log Store, the underlying table to use
 *
 * @param storageConnectionString
 *
 * @return
 *
 * @throws URISyntaxException
 * @throws StorageException
 * @throws InvalidKeyException
 */
@Provides
@Named("logdata")
public CloudTable getLogDataTable(@Named("azure.storage-connection-string") String storageConnectionString,
                                  @Named("azure.logging-table")
		                                  String logTableName) throws URISyntaxException, StorageException, InvalidKeyException
{
	// Retrieve storage account from connection-string.
	CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);

	// Create the table client.
	CloudTableClient tableClient = storageAccount.createCloudTableClient();

	// Create the table if it doesn't exist.
	CloudTable table = tableClient.getTableReference(logTableName);
	table.createIfNotExists();

	return table;
}
 
开发者ID:petergeneric,项目名称:stdlib,代码行数:30,代码来源:ServiceManagerGuiceModule.java

示例8: partitionScan

import com.microsoft.azure.storage.table.CloudTable; //导入依赖的package包/类
/**
 * Demonstrate a partition scan whereby we are searching for all the entities within a partition.
 * Note this is not as efficient as a range scan - but definitely more efficient than a full table scan.
 *
 * @param table The {@link CloudTable} object
 * @param partitionKey The partition within which to search
 *
 * @throws StorageException
 */
private static void partitionScan(CloudTable table, String partitionKey) throws StorageException {

    // Create the partition scan query
    TableQuery<CustomerEntity> partitionScanQuery = TableQuery.from(CustomerEntity.class).where(
        (TableQuery.generateFilterCondition("PartitionKey", QueryComparisons.EQUAL, partitionKey)));

    // Iterate through the results
    for (CustomerEntity entity : table.execute(partitionScanQuery)) {
        System.out.println(String.format("\tCustomer: %s,%s\t%s\t%s\t%s", entity.getPartitionKey(), entity.getRowKey(), entity.getEmail(), entity.getHomePhoneNumber(), entity.getWorkPhoneNumber()));
    }
}
 
开发者ID:Azure-Samples,项目名称:storage-table-java-getting-started,代码行数:21,代码来源:TableBasics.java

示例9: handleActionOnTable

import com.microsoft.azure.storage.table.CloudTable; //导入依赖的package包/类
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();
        break;
    case Create_table_if_does_not_exist:
        cloudTable.createIfNotExists();
        break;
    case Drop_and_create_table:
        cloudTable.delete();
        createTableAfterDeletion(cloudTable);
        break;
    case Drop_table_if_exist_and_create:
        cloudTable.deleteIfExists();
        createTableAfterDeletion(cloudTable);
        break;
    case Default:
    default:
        return;
    }

}
 
开发者ID:Talend,项目名称:components,代码行数:28,代码来源:AzureStorageTableService.java

示例10: getHourMetricsTable

import com.microsoft.azure.storage.table.CloudTable; //导入依赖的package包/类
/**
 * Gets the hour metrics table for a specific storage service.
 * 
 * @param service
 *            A {@link StorageService} enumeration value that indicates which storage service to use.
 * @param location
 *            A {@link StorageLocation} enumeration value that indicates which storage location to use.
 * @return
 *         The {@link CloudTable} object for the storage service.
 * @throws URISyntaxException
 * @throws StorageException
 */
public CloudTable getHourMetricsTable(StorageService service, StorageLocation location) throws URISyntaxException,
        StorageException {
    Utility.assertNotNull("service", service);
    if (location == null) {
        location = StorageLocation.PRIMARY;
    }

    switch (service) {
        case BLOB:
            if (location == StorageLocation.PRIMARY) {
                return this.tableClient
                        .getTableReference(Constants.AnalyticsConstants.METRICS_HOUR_PRIMARY_TRANSACTIONS_BLOB);
            }
            else {
                return this.tableClient
                        .getTableReference(Constants.AnalyticsConstants.METRICS_HOUR_SECONDARY_TRANSACTIONS_BLOB);
            }
        case QUEUE:
            if (location == StorageLocation.PRIMARY) {
                return this.tableClient
                        .getTableReference(Constants.AnalyticsConstants.METRICS_HOUR_PRIMARY_TRANSACTIONS_QUEUE);
            }
            else {
                return this.tableClient
                        .getTableReference(Constants.AnalyticsConstants.METRICS_HOUR_SECONDARY_TRANSACTIONS_QUEUE);
            }
        case TABLE:
            if (location == StorageLocation.PRIMARY) {
                return this.tableClient
                        .getTableReference(Constants.AnalyticsConstants.METRICS_HOUR_PRIMARY_TRANSACTIONS_TABLE);
            }
            else {
                return this.tableClient
                        .getTableReference(Constants.AnalyticsConstants.METRICS_HOUR_SECONDARY_TRANSACTIONS_TABLE);
            }
        default:
            throw new IllegalArgumentException(SR.INVALID_STORAGE_SERVICE);
    }
}
 
开发者ID:horizon-institute,项目名称:runspotrun-android-client,代码行数:52,代码来源:CloudAnalyticsClient.java

示例11: getMinuteMetricsTable

import com.microsoft.azure.storage.table.CloudTable; //导入依赖的package包/类
/**
 * Gets the minute metrics table for a specific storage service.
 * 
 * @param service
 *            A {@link StorageService} enumeration value that indicates which storage service to use.
 * @param location
 *            A {@link StorageLocation} enumeration value that indicates which storage location to use.
 * @return
 *         The <code>CloudTable</code> object for the storage service.
 * @throws URISyntaxException
 * @throws StorageException
 */
public CloudTable getMinuteMetricsTable(StorageService service, StorageLocation location)
        throws URISyntaxException, StorageException {
    Utility.assertNotNull("service", service);
    if (location == null) {
        location = StorageLocation.PRIMARY;
    }

    switch (service) {
        case BLOB:
            if (location == StorageLocation.PRIMARY) {
                return this.tableClient
                        .getTableReference(Constants.AnalyticsConstants.METRICS_MINUTE_PRIMARY_TRANSACTIONS_BLOB);
            }
            else {
                return this.tableClient
                        .getTableReference(Constants.AnalyticsConstants.METRICS_MINUTE_SECONDARY_TRANSACTIONS_BLOB);
            }
        case QUEUE:
            if (location == StorageLocation.PRIMARY) {
                return this.tableClient
                        .getTableReference(Constants.AnalyticsConstants.METRICS_MINUTE_PRIMARY_TRANSACTIONS_QUEUE);
            }
            else {
                return this.tableClient
                        .getTableReference(Constants.AnalyticsConstants.METRICS_MINUTE_SECONDARY_TRANSACTIONS_QUEUE);
            }
        case TABLE:
            if (location == StorageLocation.PRIMARY) {
                return this.tableClient
                        .getTableReference(Constants.AnalyticsConstants.METRICS_MINUTE_PRIMARY_TRANSACTIONS_TABLE);
            }
            else {
                return this.tableClient
                        .getTableReference(Constants.AnalyticsConstants.METRICS_MINUTE_SECONDARY_TRANSACTIONS_TABLE);
            }
        default:
            throw new IllegalArgumentException(SR.INVALID_STORAGE_SERVICE);
    }
}
 
开发者ID:horizon-institute,项目名称:runspotrun-android-client,代码行数:52,代码来源:CloudAnalyticsClient.java

示例12: testUserAgentString

import com.microsoft.azure.storage.table.CloudTable; //导入依赖的package包/类
@Test
public void testUserAgentString() throws URISyntaxException, StorageException {
    // Test with a blob request
    CloudBlobClient blobClient = TestHelper.createCloudBlobClient();
    CloudBlobContainer container = blobClient.getContainerReference("container1");
    OperationContext sendingRequestEventContext = new OperationContext();
    sendingRequestEventContext.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() {

        @Override
        public void eventOccurred(SendingRequestEvent eventArg) {
            assertEquals(
                    Constants.HeaderConstants.USER_AGENT_PREFIX
                            + "/"
                            + Constants.HeaderConstants.USER_AGENT_VERSION
                            + " "
                            + String.format(Utility.LOCALE_US, "(Android %s; %s; %s)",
                            android.os.Build.VERSION.RELEASE, android.os.Build.BRAND,
                            android.os.Build.MODEL), ((HttpURLConnection) eventArg.getConnectionObject())
                            .getRequestProperty(Constants.HeaderConstants.USER_AGENT));
        }
    });
    container.exists(null, null, sendingRequestEventContext);

    // Test with a queue request
    CloudQueueClient queueClient = TestHelper.createCloudQueueClient();
    CloudQueue queue = queueClient.getQueueReference("queue1");
    queue.exists(null, sendingRequestEventContext);

    // Test with a table request
    CloudTableClient tableClient = TestHelper.createCloudTableClient();
    CloudTable table = tableClient.getTableReference("table1");
    table.exists(null, sendingRequestEventContext);
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:34,代码来源:GenericTests.java

示例13: testTableMaximumExecutionTime

import com.microsoft.azure.storage.table.CloudTable; //导入依赖的package包/类
@Test
@Category({ DevFabricTests.class, DevStoreTests.class, SecondaryTests.class })
public void testTableMaximumExecutionTime() throws URISyntaxException, StorageException {
    OperationContext opContext = new OperationContext();
    setDelay(opContext, 2500);
    
    opContext.getResponseReceivedEventHandler().addListener(new StorageEvent<ResponseReceivedEvent>() {

        @Override
        public void eventOccurred(ResponseReceivedEvent eventArg) {
            // Set status code to 500 to force a retry
            eventArg.getRequestResult().setStatusCode(500);
        }
    });

    // set the maximum execution time
    TableRequestOptions options = new TableRequestOptions();
    options.setMaximumExecutionTimeInMs(2000);
    options.setTimeoutIntervalInMs(1000);

    CloudTableClient tableClient = TestHelper.createCloudTableClient();
    CloudTable table = tableClient.getTableReference(generateRandomName("share"));

    try {
        // 1. insert entity will fail as the table does not exist
        // 2. the executor will attempt to retry as we set the status code to 500
        // 3. maximum execution time should prevent the retry from being made
        DynamicTableEntity ent = new DynamicTableEntity("partition", "row");
        TableOperation insert = TableOperation.insert(ent);
        table.execute(insert, options, opContext);
        fail("Maximum execution time was reached but request did not fail.");
    }
    catch (StorageException e) {
        assertEquals(SR.MAXIMUM_EXECUTION_TIMEOUT_EXCEPTION, e.getMessage());
    }
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:37,代码来源:MaximumExecutionTimeTests.java

示例14: testUserAgentString

import com.microsoft.azure.storage.table.CloudTable; //导入依赖的package包/类
@Test
public void testUserAgentString() throws URISyntaxException, StorageException {
    // Test with a blob request
    CloudBlobClient blobClient = TestHelper.createCloudBlobClient();
    CloudBlobContainer container = blobClient.getContainerReference("container1");
    OperationContext sendingRequestEventContext = new OperationContext();
    sendingRequestEventContext.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() {

        @Override
        public void eventOccurred(SendingRequestEvent eventArg) {
            assertEquals(
                    Constants.HeaderConstants.USER_AGENT_PREFIX
                            + "/"
                            + Constants.HeaderConstants.USER_AGENT_VERSION
                            + " "
                            + String.format(Utility.LOCALE_US, "(JavaJRE %s; %s %s)",
                                    System.getProperty("java.version"),
                                    System.getProperty("os.name").replaceAll(" ", ""),
                                    System.getProperty("os.version")), ((HttpURLConnection) eventArg
                            .getConnectionObject()).getRequestProperty(Constants.HeaderConstants.USER_AGENT));
        }
    });
    container.exists(null, null, sendingRequestEventContext);

    // Test with a queue request
    CloudQueueClient queueClient = TestHelper.createCloudQueueClient();
    CloudQueue queue = queueClient.getQueueReference("queue1");
    queue.exists(null, sendingRequestEventContext);

    // Test with a table request
    CloudTableClient tableClient = TestHelper.createCloudTableClient();
    CloudTable table = tableClient.getTableReference("table1");
    table.exists(null, sendingRequestEventContext);
}
 
开发者ID:Azure,项目名称:azure-storage-java,代码行数:35,代码来源:GenericTests.java

示例15: processTable

import com.microsoft.azure.storage.table.CloudTable; //导入依赖的package包/类
@RequestMapping(value = "/table", method = RequestMethod.GET)
public String processTable(HttpServletResponse response)
{
	LOG.info("TableRestController processTable start...");
	StringBuffer result = new StringBuffer();

	try
	{
		result.append("Connecting to storage account..." + CR);
		if (account == null)
		{
			account = factory.createAccountByServiceInstanceName("mystorage");
			if (account == null)
			{
				String message = "CloudStorageAccount object not injected, lookup by name failed.";
				LOG.error(message);
				throw new RuntimeException(message);
			}
		}

		// Create the table client.
		CloudTableClient tableClient = account.createCloudTableClient();

		// Create the table if it doesn't exist.
		result.append("Creating product table..." + CR);
		String tableName = "product";
		CloudTable cloudTable = tableClient.getTableReference(tableName);
		cloudTable.createIfNotExists();

		ProductEntity product = new ProductEntity(ProductType.SOFTWARE, "pcf", "Pivotal Cloud Foundry");

		result.append("Storing new product in table..." + CR);
		TableOperation insert = TableOperation.insertOrReplace(product);
		cloudTable.execute(insert);

		result.append("Retrieving product from table..." + CR);
		TableOperation retrieve = TableOperation.retrieve(ProductType.SOFTWARE.toString(), "pcf", ProductEntity.class);

		ProductEntity specificEntity = cloudTable.execute(retrieve).getResultAsType();

		result.append("Product = " + specificEntity + CR);

	} catch (Exception e)
	{
		LOG.error("Error processing request ", e);
	}

	result.append("Processed Date = " + new Date(System.currentTimeMillis()) + CR);

	LOG.info("TableRestController processTable end");
	return result.toString();
}
 
开发者ID:pivotal-partner-solution-architecture,项目名称:azure-service-broker-client,代码行数:53,代码来源:TableRestController.java


注:本文中的com.microsoft.azure.storage.table.CloudTable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。