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


Java CloudTableClient.getTableReference方法代码示例

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


在下文中一共展示了CloudTableClient.getTableReference方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: connectToAzTable

import com.microsoft.azure.storage.table.CloudTableClient; //导入方法依赖的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

示例2: createTable

import com.microsoft.azure.storage.table.CloudTableClient; //导入方法依赖的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

示例3: testTableDownloadPermissions

import com.microsoft.azure.storage.table.CloudTableClient; //导入方法依赖的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

示例4: testCloudStorageAccountClientUriVerify

import com.microsoft.azure.storage.table.CloudTableClient; //导入方法依赖的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

示例5: getLogDataTable

import com.microsoft.azure.storage.table.CloudTableClient; //导入方法依赖的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

示例6: testUserAgentString

import com.microsoft.azure.storage.table.CloudTableClient; //导入方法依赖的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

示例7: testTableMaximumExecutionTime

import com.microsoft.azure.storage.table.CloudTableClient; //导入方法依赖的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

示例8: testUserAgentString

import com.microsoft.azure.storage.table.CloudTableClient; //导入方法依赖的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

示例9: AzureAccess

import com.microsoft.azure.storage.table.CloudTableClient; //导入方法依赖的package包/类
public AzureAccess(CloudTableClient client, String tableName) throws AzureAccessNotPossibleException {
  try {
    table = client.getTableReference(tableName);
    table.createIfNotExists();
  } catch (URISyntaxException | StorageException e) {
    LOG.error("Azure communication failed", e);
    throw new AzureAccessNotPossibleException("Azure communication failed");
  }
}
 
开发者ID:HuygensING,项目名称:timbuctoo,代码行数:10,代码来源:AzureAccess.java

示例10: processTable

import com.microsoft.azure.storage.table.CloudTableClient; //导入方法依赖的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

示例11: tableAcl

import com.microsoft.azure.storage.table.CloudTableClient; //导入方法依赖的package包/类
/**
 * Manage table access properties
 * @param tableClient Azure Storage Table Service
 */
private void tableAcl(CloudTableClient tableClient) throws StorageException, URISyntaxException, InterruptedException {
    // Get a reference to a table
    // The table name must be lower case
    CloudTable table = tableClient.getTableReference("table"
            + UUID.randomUUID().toString().replace("-", ""));

    try {
        // Create the table
        System.out.println("Create table");
        table.createIfNotExists();

        // Get permissions
        TablePermissions permissions = table.downloadPermissions();

        System.out.println("Set table permissions");
        final Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
        cal.add(Calendar.MINUTE, -30);
        final Date start = cal.getTime();
        cal.add(Calendar.MINUTE, 30);
        final Date expiry = cal.getTime();

        SharedAccessTablePolicy policy = new SharedAccessTablePolicy();
        policy.setPermissions(EnumSet.of(SharedAccessTablePermissions.ADD, SharedAccessTablePermissions.DELETE, SharedAccessTablePermissions.UPDATE));
        policy.setSharedAccessStartTime(start);
        policy.setSharedAccessExpiryTime(expiry);
        permissions.getSharedAccessPolicies().put("key1", policy);

        // Set table permissions
        table.uploadPermissions(permissions);
        Thread.sleep(30000);

        System.out.println("Get table permissions");
        // Get table permissions
        permissions = table.downloadPermissions();

        HashMap<String, SharedAccessTablePolicy> accessPolicies = permissions.getSharedAccessPolicies();
        Iterator it = accessPolicies.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry pair = (Map.Entry) it.next();
            SharedAccessTablePolicy value = (SharedAccessTablePolicy) pair.getValue();
            System.out.printf(" %s: %n", pair.getKey());
            System.out.printf("  Permissions: %s%n", value.permissionsToString());
            System.out.printf("  Start: %s%n", value.getSharedAccessStartTime());
            System.out.printf("  Expiry: %s%n", value.getSharedAccessStartTime());
            it.remove();
        }

        System.out.println("Clear table permissions");
        // Clear permissions
        permissions.getSharedAccessPolicies().clear();
        table.uploadPermissions(permissions);
    }
    finally {
        // Delete the table
        System.out.println("Delete table");
        table.deleteIfExists();
    }
}
 
开发者ID:Azure-Samples,项目名称:storage-table-java-getting-started,代码行数:63,代码来源:TableAdvanced.java

示例12: main

import com.microsoft.azure.storage.table.CloudTableClient; //导入方法依赖的package包/类
public static void main(String[] args) throws URISyntaxException,
        StorageException, InvalidKeyException, NoSuchAlgorithmException {
    Utility.printSampleStartInfo("TableResolverAttributes");

    // Retrieve storage account information from connection string
    // How to create a storage connection string -
    // https://azure.microsoft.com/en-us/documentation/articles/storage-configure-connection-string/
    CloudStorageAccount storageAccount = CloudStorageAccount
            .parse(Utility.storageConnectionString);
    CloudTableClient client = storageAccount.createCloudTableClient();
    CloudTable table = client.getTableReference("encryptiontableattributes"
            + UUID.randomUUID().toString().replace("-", ""));

    try {
        table.createIfNotExists();

        // Create the IKey used for encryption.
        RsaKey key = new RsaKey("private:key1");

        EncryptedEntity ent = new EncryptedEntity(UUID.randomUUID()
                .toString(), String.valueOf(new Date().getTime()));
        ent.Populate();

        TableRequestOptions insertOptions = new TableRequestOptions();
        insertOptions.setEncryptionPolicy(new TableEncryptionPolicy(key,
                null));

        // Insert Entity
        System.out.println("Inserting the encrypted entity.");
        table.execute(TableOperation.insert(ent), insertOptions, null);

        // For retrieves, a resolver can be set up that will help pick the
        // key based on the key id.
        LocalResolver resolver = new LocalResolver();
        resolver.add(key);

        TableRequestOptions retrieveOptions = new TableRequestOptions();
        retrieveOptions.setEncryptionPolicy(new TableEncryptionPolicy(null,
                resolver));

        // Retrieve Entity
        System.out.println("Retrieving the encrypted entity.");
        TableOperation operation = TableOperation.retrieve(
                ent.getPartitionKey(), ent.getRowKey(),
                EncryptedEntity.class);
        TableResult result = table
                .execute(operation, retrieveOptions, null);
        EncryptedEntity resultEntity = result.getResultAsType();
        System.out.println("EncryptedProperty2 = "
                + resultEntity.getEncryptedProperty2());
    } finally {
        table.deleteIfExists();
        Utility.printSampleCompleteInfo("TableResolverAttributes");
    }
}
 
开发者ID:Azure,项目名称:azure-storage-java,代码行数:56,代码来源:TableGettingStartedAttributes.java


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