/** * Returns a value that indicates whether the table exists in the storage service. * * @return <code>true</code> if the table exists in the storage service; otherwise <code>false</code>. * * @throws StorageException * If a storage service error occurred during the operation. */ @DoesServiceRequest public boolean exists() throws StorageException { return this.exists(null /* options */, null /* opContext */); }
/** * Returns a value that indicates whether the table exists in the storage service. * * @return <code>true</code> if the table exists in the storage service; otherwise <code>false</code>. * * @throws StorageException * If a storage service error occurred during the operation. */ @DoesServiceRequest public boolean exists() throws StorageException { return this.exists(null /* options */, null /* opContext */); }
public boolean exists(AzureTableName azureTableName) { try { return tableRefrence(azureTableName).exists(); } catch (StorageException e) { LOG.warn("Error accessing azure table", e); } throw new IllegalStateException("Error verifying if table " + azureTableName + " exists"); }
/** * Returns a value that indicates whether the table exists in the storage service, using the specified request * options and operation context. * * @param options * A {@link TableRequestOptions} object that specifies any additional options for the request. Specifying * <code>null</code> will use the default request options from the associated service client ( * {@link CloudTableClient}). * @param opContext * An {@link OperationContext} object that represents the context for the current operation. This object * is used to track requests to the storage service, and to provide additional runtime information about * the operation. * * @return <code>true</code> if the table exists in the storage service, otherwise <code>false</code>. * * @throws StorageException * If a storage service error occurred during the operation. */ @DoesServiceRequest public boolean exists(TableRequestOptions options, OperationContext opContext) throws StorageException { return this.exists(false, options, opContext); }
/** * Returns a value that indicates whether the table exists in the storage service, using the specified request * options and operation context. * * @param options * A {@link TableRequestOptions} object that specifies any additional options for the request. Specifying * <code>null</code> will use the default request options from the associated service client ( * {@link CloudTableClient}). * @param opContext * An {@link OperationContext} object that represents the context for the current operation. This object * is used to track requests to the storage service, and to provide additional runtime information about * the operation. * * @return <code>true</code> if the table exists in the storage service, otherwise <code>false</code>. * * @throws StorageException * If a storage service error occurred during the operation. */ @DoesServiceRequest public boolean exists(TableRequestOptions options, OperationContext opContext) throws StorageException { return this.exists(false, options, opContext); }
options = TableRequestOptions.populateAndApplyDefaults(options, this.tableServiceClient); boolean exists = this.exists(true, options, opContext); if (exists) { return false;
options = TableRequestOptions.populateAndApplyDefaults(options, this.tableServiceClient); if (this.exists(true, options, opContext)) { try { this.delete(options, opContext);
options = TableRequestOptions.populateAndApplyDefaults(options, this.tableServiceClient); boolean exists = this.exists(true, options, opContext); if (exists) { return false;
options = TableRequestOptions.populateAndApplyDefaults(options, this.tableServiceClient); if (this.exists(true, options, opContext)) { try { this.delete(options, opContext);
@Override public void eventOccurred(SendingRequestEvent eventArg) { if (((HttpURLConnection) eventArg.getConnectionObject()).getRequestMethod().equals("DELETE")) { try { table.delete(); assertFalse(table.exists()); } catch (StorageException e) { fail("Delete should succeed."); } } } });
@Test public void testTableDoesTableExist() throws StorageException, URISyntaxException { CloudTableClient tClient = TableTestHelper.createCloudTableClient(); String tableName = TableTestHelper.generateRandomTableName(); CloudTable table = tClient.getTableReference(tableName); try { assertFalse(table.exists()); assertTrue(table.createIfNotExists()); assertTrue(table.exists()); } finally { // cleanup table.deleteIfExists(); } }
@Test public void testTableDeleteWhenExistAndNotExists() throws StorageException, URISyntaxException { CloudTableClient tClient = TableTestHelper.createCloudTableClient(); String tableName = TableTestHelper.generateRandomTableName(); CloudTable table = tClient.getTableReference(tableName); try { // Should fail as it doesnt already exists try { table.delete(); fail(); } catch (StorageException ex) { assertEquals(ex.getMessage(), "Not Found"); } table.create(); assertTrue(table.exists()); table.delete(); assertFalse(table.exists()); } finally { table.deleteIfExists(); } }
@Test public void testTableCreateExistsAndDelete() throws StorageException, URISyntaxException { CloudTableClient tClient = TableTestHelper.createCloudTableClient(); String tableName = TableTestHelper.generateRandomTableName(); CloudTable table = tClient.getTableReference(tableName); try { assertTrue(table.createIfNotExists()); assertTrue(table.exists()); assertTrue(table.deleteIfExists()); } finally { // cleanup table.deleteIfExists(); } }
@Test public void testTableCreateIfNotExists() throws StorageException, URISyntaxException { CloudTableClient tClient = TableTestHelper.createCloudTableClient(); String tableName = TableTestHelper.generateRandomTableName(); CloudTable table = tClient.getTableReference(tableName); try { assertTrue(table.createIfNotExists()); assertTrue(table.exists()); assertFalse(table.createIfNotExists()); } finally { // cleanup table.deleteIfExists(); } }
@Test public void testTableDeleteIfExists() throws StorageException, URISyntaxException { CloudTableClient tClient = TableTestHelper.createCloudTableClient(); String tableName = TableTestHelper.generateRandomTableName(); CloudTable table = tClient.getTableReference(tableName); assertFalse(table.deleteIfExists()); table.create(); assertTrue(table.exists()); assertTrue(table.deleteIfExists()); assertFalse(table.deleteIfExists()); }
@Test public void testTableCreateAndAttemptCreateOnceExists() throws StorageException, URISyntaxException { CloudTableClient tClient = TableTestHelper.createCloudTableClient(); String tableName = TableTestHelper.generateRandomTableName(); CloudTable table = tClient.getTableReference(tableName); tClient.getDefaultRequestOptions().setTablePayloadFormat(TablePayloadFormat.Json); try { table.create(); assertTrue(table.exists()); // Should fail as it already exists try { table.create(); fail(); } catch (StorageException ex) { assertEquals(ex.getErrorCode(), "TableAlreadyExists"); } } finally { // cleanup table.deleteIfExists(); } }
@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); }