@Override public Status delete(String table, String key) { try { // firstly, retrieve the entity to be deleted TableOperation retrieveOp = TableOperation.retrieve(partitionKey, key, TableServiceEntity.class); TableServiceEntity entity = cloudTable.execute(retrieveOp).getResultAsType(); // secondly, delete the entity TableOperation deleteOp = TableOperation.delete(entity); cloudTable.execute(deleteOp); return Status.OK; } catch (Exception e) { return Status.ERROR; } }
try { cloudTable = tableClient.getTableReference(table); cloudTable.createIfNotExists(); } catch (Exception e) { throw new DBException("Could not connect to the table.\n", e);
CloudTable table = TableTestHelper.getRandomTableReference(); try { table.create(); SharedAccessTablePermissions.UPDATE, SharedAccessTablePermissions.DELETE)); String sasString = table.generateSharedAccessSignature(policy1, null, "javatables_batch_0", "00", "javatables_batch_1", "04"); StorageCredentialsSharedAccessSignature sasCreds = new StorageCredentialsSharedAccessSignature(sasString); CloudTable directTable = new CloudTable(PathUtility.addToQuery(table.getUri(), sasString)); CloudTable transformedTable = new CloudTable(sasCreds.transformUri(table.getUri())); directTable.execute(TableOperation.insert(ent)); transformedTable.execute(TableOperation.insert(ent)); directTable.execute(TableOperation.insert(ent)); transformedTable.execute(TableOperation.insert(ent)); directTable.execute(TableOperation.insert(ent)); transformedTable.execute(TableOperation.insert(ent)); 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(); } }
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; } }
table.create(); table.uploadPermissions(expectedPermissions); Thread.sleep(30000); table.execute(batch); String sasString = table.generateSharedAccessSignature(policy1, null, "javatables_batch_0", "0", "javatables_batch_9", "9"); CloudTableClient tableClientFromPermission = new CloudTableClient(tClient.getEndpoint(), CloudTable tableFromUri = new CloudTable(PathUtility.addToQuery(table.getStorageUri(), table .generateSharedAccessSignature((SharedAccessTablePolicy) null, identifier, "javatables_batch_0", "0", "javatables_batch_9", "9"))); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), tableFromUri.getServiceClient() .getCredentials().getClass().toString()); table.generateSharedAccessSignature((SharedAccessTablePolicy) null, identifier, "javatables_batch_0", "0", "javatables_batch_9", "9")); CloudTableClient tableClient = new CloudTableClient(policySasTable.getServiceClient().getStorageUri(), creds); tableFromUri = tableClient.getTableReference(table.getName()); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), tableFromUri.getServiceClient() .getCredentials().getClass().toString()); assertEquals(tableClient.getDefaultRequestOptions().getLocationMode(), tableFromUri.getServiceClient() .getDefaultRequestOptions().getLocationMode()); assertEquals(tableClient.getDefaultRequestOptions().getTimeoutIntervalInMs(), tableFromUri.getServiceClient() .getDefaultRequestOptions().getTimeoutIntervalInMs());
public void testTableQueryProjectionWithNull() throws URISyntaxException, StorageException { CloudTable table = TableTestHelper.getRandomTableReference(); try { // Create a new table so we don't pollute the main query table table.createIfNotExists(); // Insert an entity which is missing String and IntegerPrimitive DynamicTableEntity entity = new DynamicTableEntity(UUID.randomUUID().toString(), UUID.randomUUID() .toString()); table.execute(TableOperation.insert(entity)); testTableQueryProjectionWithSpecialCases(table); } finally { table.deleteIfExists(); } }
assertFalse(table.exists()); URI sasUri = sasClient.getTableReference(table.getName()).getUri(); sasUri = sasClient.getCredentials().transformUri(sasUri); final CloudTable sasTable = new CloudTable(sasUri); sasTable.create(); sasTable.create(); fail(); table.create(); assertTrue(table.exists()); assertEquals(sasTable.getName(), sasClient.listTables(sasTable.getName()).iterator().next()); sasClient.listTables(sasTable.getName()).iterator().next(); fail(); assertEquals(sasTable.getName(), this.tableClient.listTables(sasTable.getName()).iterator().next()); sasTable.execute(op); sasTable.execute(op); fail(); table.execute(op);
public boolean destroy(AzureTableName azureTableName) { try { return tableRefrence(azureTableName).deleteIfExists(); } catch (StorageException e) { LOG.warn("Error deleting table from Azure", e); } throw new IllegalStateException("Unable to destroy table " + azureTableName); }
/** * Returns the canonical name for shared access. * * @return A <code>String</code> containing the canonical name for shared access. */ private String getSharedAccessCanonicalName() { String accountName = this.getServiceClient().getCredentials().getAccountName(); String tableNameLowerCase = this.getName().toLowerCase(Locale.ENGLISH); return String.format("/%s/%s/%s", SR.TABLE, accountName, tableNameLowerCase); }
@After public void tableODataTestBeforeMethodTearDown() throws StorageException { this.table.execute(TableOperation.delete(this.ent), this.options, null); this.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 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(); } }
table.create(); testPermissions = table.downloadPermissions(); assertTablePermissionsEqual(expectedPermissions, testPermissions); table.uploadPermissions(expectedPermissions); Thread.sleep(30000); testPermissions = table.downloadPermissions(); assertTablePermissionsEqual(expectedPermissions, testPermissions); expectedPermissions.getSharedAccessPolicies().put(UUID.randomUUID().toString(), policy1); table.uploadPermissions(expectedPermissions); Thread.sleep(30000); testPermissions = table.downloadPermissions(); assertTablePermissionsEqual(expectedPermissions, testPermissions); } finally { table.deleteIfExists();
@Test public void testCloudTableDeleteIfExistsErrorCode() throws StorageException, URISyntaxException { final CloudTable table = TableTestHelper.getRandomTableReference(); try { assertFalse(table.deleteIfExists()); OperationContext ctx = new OperationContext(); ctx.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() { @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."); } } } }); table.create(); // The second delete of a table will return a 404 assertFalse(table.deleteIfExists(null, ctx)); } finally { table.deleteIfExists(); } }
@Test public void testTableTypesWithStorageUri() throws URISyntaxException, StorageException { CloudTableClient tableClient = TestHelper.createCloudTableClient(); StorageUri endpoint = new StorageUri(new URI("http://" + ACCOUNT_NAME + TABLE_SERVICE + ENDPOINT_SUFFIX), new URI("http://" + ACCOUNT_NAME + SECONDARY_SUFFIX + TABLE_SERVICE + ENDPOINT_SUFFIX)); CloudTableClient client = new CloudTableClient(endpoint, tableClient.getCredentials()); assertEquals(endpoint, client.getStorageUri()); assertEquals(endpoint.getPrimaryUri(), client.getEndpoint()); StorageUri tableUri = new StorageUri(new URI(endpoint.getPrimaryUri() + "/table"), new URI( endpoint.getSecondaryUri() + "/table")); CloudTable table = client.getTableReference("table"); assertEquals(tableUri, table.getStorageUri()); assertEquals(tableUri.getPrimaryUri(), table.getUri()); assertEquals(endpoint, table.getServiceClient().getStorageUri()); table = new CloudTable(tableUri, client.getCredentials()); assertEquals(tableUri, table.getStorageUri()); assertEquals(tableUri.getPrimaryUri(), table.getUri()); assertEquals(endpoint, table.getServiceClient().getStorageUri()); } }
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()); throw new IOException("Wait process for recreating table interrupted."); cloudTable.create(null, AzureStorageUtils.getTalendOperationContext()); LOGGER.debug("Table {} created.", cloudTable.getName());