本文整理汇总了Java中com.microsoft.azure.storage.table.CloudTableClient类的典型用法代码示例。如果您正苦于以下问题:Java CloudTableClient类的具体用法?Java CloudTableClient怎么用?Java CloudTableClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CloudTableClient类属于com.microsoft.azure.storage.table包,在下文中一共展示了CloudTableClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: corsRules
import com.microsoft.azure.storage.table.CloudTableClient; //导入依赖的package包/类
/**
* Set CORS rules sample.
* @param tableClient Azure Storage Table Service
*/
private void corsRules(CloudTableClient tableClient) throws StorageException {
// Get service properties
System.out.println("Get service properties");
ServiceProperties originalProps = tableClient.downloadServiceProperties();
try {
// Setr CORS rules
System.out.println("Set CORS rules");
CorsRule ruleAllowAll = new CorsRule();
ruleAllowAll.getAllowedOrigins().add("*");
ruleAllowAll.getAllowedMethods().add(CorsHttpMethods.GET);
ruleAllowAll.getAllowedHeaders().add("*");
ruleAllowAll.getExposedHeaders().add("*");
ServiceProperties props = new ServiceProperties();
props.getCors().getCorsRules().add(ruleAllowAll);
tableClient.uploadServiceProperties(props);
}
finally {
// Revert back to original service properties
tableClient.uploadServiceProperties(originalProps);
}
}
示例3: 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;
}
示例4: callUploadServiceProps
import com.microsoft.azure.storage.table.CloudTableClient; //导入依赖的package包/类
private void callUploadServiceProps(
ServiceClient client, ServiceProperties props, FileServiceProperties fileProps)
throws StorageException, InterruptedException {
if (client.getClass().equals(CloudBlobClient.class)) {
((CloudBlobClient) client).uploadServiceProperties(props);
}
else if (client.getClass().equals(CloudTableClient.class)) {
((CloudTableClient) client).uploadServiceProperties(props);
}
else if (client.getClass().equals(CloudQueueClient.class)) {
((CloudQueueClient) client).uploadServiceProperties(props);
}
else if (client.getClass().equals(CloudFileClient.class)) {
((CloudFileClient) client).uploadServiceProperties(fileProps);
}
else {
fail();
}
Thread.sleep(30000);
}
示例5: callDownloadServiceProperties
import com.microsoft.azure.storage.table.CloudTableClient; //导入依赖的package包/类
private ServiceProperties callDownloadServiceProperties(ServiceClient client) throws StorageException {
if (client.getClass().equals(CloudBlobClient.class)) {
CloudBlobClient blobClient = (CloudBlobClient) client;
return blobClient.downloadServiceProperties();
}
else if (client.getClass().equals(CloudTableClient.class)) {
CloudTableClient tableClient = (CloudTableClient) client;
return tableClient.downloadServiceProperties();
}
else if (client.getClass().equals(CloudQueueClient.class)) {
CloudQueueClient queueClient = (CloudQueueClient) client;
return queueClient.downloadServiceProperties();
}
else {
fail();
}
return null;
}
示例6: 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();
}
}
示例7: 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());
}
示例8: createCloudTableClient
import com.microsoft.azure.storage.table.CloudTableClient; //导入依赖的package包/类
/**
* Creates a new Table service client.
*
* @return A client object that uses the Table service endpoint.
*/
public CloudTableClient createCloudTableClient() {
if (this.getTableStorageUri() == null) {
throw new IllegalArgumentException(SR.TABLE_ENDPOINT_NOT_CONFIGURED);
}
if (this.credentials == null) {
throw new IllegalArgumentException(SR.MISSING_CREDENTIALS);
}
if (!StorageCredentialsHelper.canCredentialsGenerateClient(this.credentials)) {
throw new IllegalArgumentException(SR.CREDENTIALS_CANNOT_SIGN_REQUEST);
}
return new CloudTableClient(this.getTableStorageUri(), this.getCredentials());
}
示例9: create
import com.microsoft.azure.storage.table.CloudTableClient; //导入依赖的package包/类
public TableClient create() {
try {
final CloudStorageAccount storageAccount =
new CloudStorageAccount(azureTableConfiguration.getStorageCredentialsAccountAndKey(), true);
final CloudTableClient cloudTableClient = storageAccount.createCloudTableClient();
final TableRequestOptions defaultOptions = new TableRequestOptions();
defaultOptions.setRetryPolicyFactory(new RetryLinearRetry(
Ints.checkedCast(azureTableConfiguration.getRetryInterval().toMilliseconds()),
azureTableConfiguration.getRetryAttempts()));
defaultOptions.setTimeoutIntervalInMs(Ints.checkedCast(azureTableConfiguration.getTimeout().toMilliseconds()));
cloudTableClient.setDefaultRequestOptions(defaultOptions);
return new TableClient(cloudTableClient);
} catch (URISyntaxException err) {
LOGGER.error("Failed to create a TableClient", err);
throw new IllegalArgumentException(err);
}
}
示例10: 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;
}
示例11: callUploadServiceProps
import com.microsoft.azure.storage.table.CloudTableClient; //导入依赖的package包/类
private void callUploadServiceProps(
ServiceClient client, ServiceProperties props, FileServiceProperties fileProps)
throws StorageException, InterruptedException {
if (client.getClass().equals(CloudBlobClient.class)) {
((CloudBlobClient) client).uploadServiceProperties(props);
}
else if (client.getClass().equals(CloudTableClient.class)) {
((CloudTableClient) client).uploadServiceProperties(props);
}
else if (client.getClass().equals(CloudQueueClient.class)) {
((CloudQueueClient) client).uploadServiceProperties(props);
}
else if (client.getClass().equals(CloudFileClient.class)) {
((CloudFileClient) client).uploadServiceProperties(fileProps);
}
else {
fail();
}
// It may take up to 30 seconds for the settings to take effect, but the new properties are immediately
// visible when querying service properties.
}
示例12: runSamples
import com.microsoft.azure.storage.table.CloudTableClient; //导入依赖的package包/类
/**
* Executes the samples.
*
* @throws URISyntaxException Uri has invalid syntax
* @throws InvalidKeyException Invalid key
*/
void runSamples() throws InvalidKeyException, URISyntaxException, IOException {
System.out.println();
System.out.println();
if (TableClientProvider.isAzureCosmosdbTable()) {
return;
}
PrintHelper.printSampleStartInfo("Table Advanced");
// Create a table service client
CloudTableClient tableClient = TableClientProvider.getTableClientReference();
try {
System.out.println("Service properties sample");
serviceProperties(tableClient);
System.out.println();
System.out.println("CORS rules sample");
corsRules(tableClient);
System.out.println();
System.out.println("Table Acl sample");
tableAcl(tableClient);
System.out.println();
// This will fail unless the account is RA-GRS enabled.
// System.out.println("Service stats sample");
// serviceStats(tableClient);
// System.out.println();
} catch (Throwable t) {
PrintHelper.printException(t);
}
PrintHelper.printSampleCompleteInfo("Table Advanced");
}
示例13: serviceStats
import com.microsoft.azure.storage.table.CloudTableClient; //导入依赖的package包/类
/**
* Retrieve statistics related to replication for the Table service.
* This operation is only available on the secondary location endpoint
* when read-access geo-redundant replication is enabled for the storage account.
* @param tableClient Azure Storage Table Service
*/
private void serviceStats(CloudTableClient tableClient) throws StorageException {
// Get service stats
System.out.println("Service Stats:");
ServiceStats stats = tableClient.getServiceStats();
System.out.printf("- status: %s%n", stats.getGeoReplication().getStatus());
System.out.printf("- last sync time: %s%n", stats.getGeoReplication().getLastSyncTime());
}
示例14: createCloudTableClient
import com.microsoft.azure.storage.table.CloudTableClient; //导入依赖的package包/类
/**
* Creates a new Table service client.
*
* @return A client object that uses the Table service endpoint.
*/
public CloudTableClient createCloudTableClient() {
if (this.getTableStorageUri() == null) {
throw new IllegalArgumentException(SR.TABLE_ENDPOINT_NOT_CONFIGURED);
}
if (this.credentials == null) {
throw new IllegalArgumentException(SR.MISSING_CREDENTIALS);
}
if (!StorageCredentialsHelper.canCredentialsSignRequest(this.credentials)) {
throw new IllegalArgumentException(SR.CREDENTIALS_CANNOT_SIGN_REQUEST);
}
return new CloudTableClient(this.getTableStorageUri(), this.getCredentials());
}
示例15: 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);
}