private void deleteEntities(Iterator<TaskCheckpointEntity> entitiesToDelete) { TableBatchOperation batchOperation = new TableBatchOperation(); while (entitiesToDelete.hasNext()) { TaskCheckpointEntity entity = entitiesToDelete.next(); // Add to batch operation batchOperation.delete(entity); // Execute when batch reaches capacity or when this is the last item if (batchOperation.size() >= MAX_WRITE_BATCH_SIZE || !entitiesToDelete.hasNext()) { try { cloudTable.execute(batchOperation); } catch (StorageException e) { LOG.error("Executing batch failed for deleting checkpoints"); throw new AzureException(e); } batchOperation.clear(); } } } }
@Override public void deleteVreAuthorizations(String vreId) throws AuthorizationUnavailableException { String condition = TableQuery.generateFilterCondition( "PartitionKey", TableQuery.QueryComparisons.EQUAL, vreId ); TableBatchOperation deletes = new TableBatchOperation(); for (DynamicTableEntity entity : table.execute(TableQuery.from(DynamicTableEntity.class).where(condition))) { deletes.delete(entity); } try { table.execute(deletes); } catch (StorageException e) { LOG.error("deleteVreAuthorizations failed", e); throw new AuthorizationUnavailableException("Could not delete authorizations"); } }
private void testBatchInsert(TableRequestOptions options) throws StorageException { TableBatchOperation batch = new TableBatchOperation(); // Add 3 inserts addInsertBatch(batch); // default echo content (true) addInsertBatch(batch, true); // set echo content to true addInsertBatch(batch, false); // set echo content to false // insert entity Class1 ref = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(ref), options, null); batch.delete(ref); ArrayList<TableResult> results = this.table.execute(batch, options, null); assertEquals(results.size(), 4); Iterator<TableResult> iter = results.iterator(); TableResult res = iter.next(); assertEquals(res.getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); res = iter.next(); assertEquals(res.getHttpStatusCode(), HttpURLConnection.HTTP_CREATED); res = iter.next(); assertEquals(res.getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); // delete assertEquals(iter.next().getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); }
private void testBatchMerge(TableRequestOptions options) throws StorageException { TableBatchOperation batch = new TableBatchOperation(); addInsertBatch(batch); // insert entity to delete Class1 delRef = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(delRef)); batch.delete(delRef); // Insert entity to merge Class1 baseEntity = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(baseEntity), options, null); addMergeToBatch(baseEntity, batch); ArrayList<TableResult> results = this.table.execute(batch); assertEquals(results.size(), 3); Iterator<TableResult> iter = results.iterator(); // insert assertEquals(iter.next().getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); // delete assertEquals(iter.next().getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); // merge assertEquals(iter.next().getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); }
private void testBatchInsertOrMerge(TableRequestOptions options) throws StorageException { TableBatchOperation batch = new TableBatchOperation(); addInsertBatch(batch); // insert entity to delete Class1 delRef = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(delRef), options, null); batch.delete(delRef); // Insert entity to merge Class1 baseEntity = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(baseEntity), options, null); addInsertOrMergeToBatch(baseEntity, batch); ArrayList<TableResult> results = this.table.execute(batch); assertEquals(results.size(), 3); Iterator<TableResult> iter = results.iterator(); // insert assertEquals(iter.next().getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); // delete assertEquals(iter.next().getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); // merge assertEquals(iter.next().getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); }
private void testBatchReplace(TableRequestOptions options) throws StorageException { TableBatchOperation batch = new TableBatchOperation(); addInsertBatch(batch); // insert entity to delete Class1 delRef = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(delRef), options, null); batch.delete(delRef); // Insert entity to replace Class1 baseEntity = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(baseEntity), options, null); addReplaceToBatch(baseEntity, batch); ArrayList<TableResult> results = this.table.execute(batch); assertEquals(results.size(), 3); Iterator<TableResult> iter = results.iterator(); // insert assertEquals(iter.next().getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); // delete assertEquals(iter.next().getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); // replace assertEquals(iter.next().getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); }
private void testBatchInsertOrReplace(TableRequestOptions options) throws StorageException { TableBatchOperation batch = new TableBatchOperation(); addInsertBatch(batch); // insert entity to delete Class1 delRef = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(delRef), options, null); batch.delete(delRef); // Insert entity to replace Class1 baseEntity = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(baseEntity), options, null); addInsertOrReplaceToBatch(baseEntity, batch); ArrayList<TableResult> results = this.table.execute(batch, options, null); assertEquals(results.size(), 3); Iterator<TableResult> iter = results.iterator(); // insert assertEquals(iter.next().getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); // delete assertEquals(iter.next().getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); // replace assertEquals(iter.next().getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); }
private void insertAndDeleteBatchWithX(int x, TableRequestOptions options) throws StorageException { TableBatchOperation batch = new TableBatchOperation(); for (int m = 0; m < x; m++) { addInsertBatch(batch); } TableBatchOperation delBatch = new TableBatchOperation(); ArrayList<TableResult> results = this.table.execute(batch, options, null); for (TableResult r : results) { assertEquals(r.getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); delBatch.delete((Class1) r.getResult()); } ArrayList<TableResult> delResults = this.table.execute(delBatch, options, null); for (TableResult r : delResults) { assertEquals(r.getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); } }
private void testBatchDelete(TableRequestOptions options) throws StorageException { Class1 ref = TableTestHelper.generateRandomEntity("jxscl_odata"); // insert entity this.table.execute(TableOperation.insert(ref), options, null); TableBatchOperation batch = new TableBatchOperation(); batch.delete(ref); ArrayList<TableResult> delResults = this.table.execute(batch, options, null); for (TableResult r : delResults) { assertEquals(r.getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); } try { this.table.execute(batch, options, null); fail(); } catch (StorageException ex) { assertEquals(ex.getHttpStatusCode(), HttpURLConnection.HTTP_NOT_FOUND); } }
private void upsertAndDeleteBatchWithX(int x, TableRequestOptions options) throws StorageException { TableBatchOperation batch = new TableBatchOperation(); for (int m = 0; m < x; m++) { addInsertOrMergeToBatch(TableTestHelper.generateRandomEntity("jxscl_odata"), batch); } TableBatchOperation delBatch = new TableBatchOperation(); ArrayList<TableResult> results = this.table.execute(batch, options, null); for (TableResult r : results) { assertEquals(r.getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); delBatch.delete((Class2) r.getResult()); } ArrayList<TableResult> delResults = this.table.execute(delBatch, options, null); for (TableResult r : delResults) { assertEquals(r.getHttpStatusCode(), HttpURLConnection.HTTP_NO_CONTENT); } }
batch.delete(delRef);
@Test public void testBatchDeleteFail() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); TableBatchOperation batch = new TableBatchOperation(); // Insert entity to delete Class1 baseEntity = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(baseEntity), options, null); Class1 updatedEntity = TableTestHelper.generateRandomEntity("jxscl_odata"); updatedEntity.setPartitionKey(baseEntity.getPartitionKey()); updatedEntity.setRowKey(baseEntity.getRowKey()); updatedEntity.setEtag(baseEntity.getEtag()); this.table.execute(TableOperation.replace(updatedEntity), options, null); // add delete to fail batch.delete(baseEntity); try { this.table.execute(batch, options, null); fail(); } catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Precondition Failed"); assertTrue(ex.getExtendedErrorInformation().getErrorMessage() .startsWith("The update condition specified in the request was not satisfied.")); assertEquals(ex.getErrorCode(), StorageErrorCodeStrings.UPDATE_CONDITION_NOT_SATISFIED); } }
delBatch.delete(e);
batch.delete(retObj); res = this.table.execute(batch, options, null).get(0);