/** * Reserved for internal use. Clears internal fields when the batch operation is empty. */ private void checkResetEntityLocks() { if (this.size() == 0) { this.partitionKey = null; this.hasQuery = false; this.containsWrites = false; } }
/** * Reserved for internal use. Clears internal fields when the batch operation is empty. */ private void checkResetEntityLocks() { if (this.size() == 0) { this.partitionKey = null; this.hasQuery = false; this.containsWrites = false; } }
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(); } } } }
if (batchOperation.size() >= MAX_WRITE_BATCH_SIZE || !iterator.hasNext()) { try { cloudTable.execute(batchOperation);
if (this.size() == 0) { throw new IllegalArgumentException(SR.EMPTY_BATCH_NOT_ALLOWED);
if (this.size() == 0) { throw new IllegalArgumentException(SR.EMPTY_BATCH_NOT_ALLOWED);
for (int m = 0; m < batch.size(); m++) { final TableOperation currOp = batch.get(m); final MimePart currMimePart = responseParts.get(m);
for (int m = 0; m < batch.size(); m++) { final TableOperation currOp = batch.get(m); final MimePart currMimePart = responseParts.get(m);
/** * Adds the table operation to the batch operation <code>ArrayList</code>. * * @param element * The {@link TableOperation} to add to the batch operation. * @return * <code>true</code> if the operation was added successfully. */ @Override public boolean add(final TableOperation element) { Utility.assertNotNull("element", element); this.checkSingleQueryPerBatch(element, this.size()); if (element.getOperationType() == TableOperationType.RETRIEVE) { // Query operation this.lockToPartitionKey(((QueryTableOperation) element).getPartitionKey()); } else { this.lockToPartitionKey(element.getEntity().getPartitionKey()); } return super.add(element); }
/** * Adds the table operation at the specified index in the batch operation <code>ArrayList</code>. * * @param index * An <code>int</code> which represents the index in the batch operation <code>ArrayList</code> to add * the table operation at. * @param element * The {@link TableOperation} to add to the batch operation. */ @Override public void add(final int index, final TableOperation element) { Utility.assertNotNull("element", element); this.checkSingleQueryPerBatch(element, this.size()); if (element.getOperationType() == TableOperationType.RETRIEVE) { this.lockToPartitionKey(((QueryTableOperation) element).getPartitionKey()); } else { this.lockToPartitionKey(element.getEntity().getPartitionKey()); } super.add(index, element); }
/** * Adds the table operation to the batch operation <code>ArrayList</code>. * * @param element * The {@link TableOperation} to add to the batch operation. * @return * <code>true</code> if the operation was added successfully. */ @Override public boolean add(final TableOperation element) { Utility.assertNotNull("element", element); this.checkSingleQueryPerBatch(element, this.size()); if (element.getOperationType() == TableOperationType.RETRIEVE) { // Query operation this.lockToPartitionKey(((QueryTableOperation) element).getPartitionKey()); } else { this.lockToPartitionKey(element.getEntity().getPartitionKey()); } return super.add(element); }
/** * Adds the table operation at the specified index in the batch operation <code>ArrayList</code>. * * @param index * An <code>int</code> which represents the index in the batch operation <code>ArrayList</code> to add * the table operation at. * @param element * The {@link TableOperation} to add to the batch operation. */ @Override public void add(final int index, final TableOperation element) { Utility.assertNotNull("element", element); this.checkSingleQueryPerBatch(element, this.size()); if (element.getOperationType() == TableOperationType.RETRIEVE) { this.lockToPartitionKey(((QueryTableOperation) element).getPartitionKey()); } else { this.lockToPartitionKey(element.getEntity().getPartitionKey()); } super.add(index, element); }
/** * Adds the collection of table operations to the batch operation <code>ArrayList</code>. * * @param c * A <code>java.util.Collection</code> of {@link TableOperation} objects to add to the batch operation. * @return * <code>true</code> if the operations were added successfully. */ @Override public boolean addAll(final java.util.Collection<? extends TableOperation> c) { int size = this.size(); for (final TableOperation operation : c) { Utility.assertNotNull("operation", operation); this.checkSingleQueryPerBatch(operation, size); if (operation.getEntity() == null) { // Query operation this.lockToPartitionKey(((QueryTableOperation) operation).getPartitionKey()); } else { this.lockToPartitionKey(operation.getEntity().getPartitionKey()); } size++; } return super.addAll(c); }
/** * Adds the collection of table operations to the batch operation <code>ArrayList</code>. * * @param c * A <code>java.util.Collection</code> of {@link TableOperation} objects to add to the batch operation. * @return * <code>true</code> if the operations were added successfully. */ @Override public boolean addAll(final java.util.Collection<? extends TableOperation> c) { int size = this.size(); for (final TableOperation operation : c) { Utility.assertNotNull("operation", operation); this.checkSingleQueryPerBatch(operation, size); if (operation.getEntity() == null) { // Query operation this.lockToPartitionKey(((QueryTableOperation) operation).getPartitionKey()); } else { this.lockToPartitionKey(operation.getEntity().getPartitionKey()); } size++; } return super.addAll(c); }
/** * Adds the collection of table operations to the batch operation <code>ArrayList</code> starting at the specified * index. * * @param index * An <code>int</code> which represents the index in the batch operation <code>ArrayList</code> to add * the table operation at. * @param c * A <code>java.util.Collection</code> of {@link TableOperation} objects to add to the batch operation. * @return * <code>true</code> if the operations were added successfully. */ @Override public boolean addAll(final int index, final java.util.Collection<? extends TableOperation> c) { int size = this.size(); for (final TableOperation operation : c) { Utility.assertNotNull("operation", operation); this.checkSingleQueryPerBatch(operation, size); if (operation.getEntity() == null) { // Query operation this.lockToPartitionKey(((QueryTableOperation) operation).getPartitionKey()); } else { this.lockToPartitionKey(operation.getEntity().getPartitionKey()); } size++; } return super.addAll(index, c); }
/** * Adds the collection of table operations to the batch operation <code>ArrayList</code> starting at the specified * index. * * @param index * An <code>int</code> which represents the index in the batch operation <code>ArrayList</code> to add * the table operation at. * @param c * A <code>java.util.Collection</code> of {@link TableOperation} objects to add to the batch operation. * @return * <code>true</code> if the operations were added successfully. */ @Override public boolean addAll(final int index, final java.util.Collection<? extends TableOperation> c) { int size = this.size(); for (final TableOperation operation : c) { Utility.assertNotNull("operation", operation); this.checkSingleQueryPerBatch(operation, size); if (operation.getEntity() == null) { // Query operation this.lockToPartitionKey(((QueryTableOperation) operation).getPartitionKey()); } else { this.lockToPartitionKey(operation.getEntity().getPartitionKey()); } size++; } return super.addAll(index, c); }
@Test public void testBatchRemoveAll() throws StorageException { ArrayList<TableOperation> ops = allOpsList(); TableBatchOperation batch = new TableBatchOperation(); batch.addAll(ops); assertTrue(batch.removeAll(ops)); assertEquals(0, batch.size()); // should be able to add an entity with a different partition key Class1 baseEntity = TableTestHelper.generateRandomEntity("jxscl_odata_2"); batch.insert(baseEntity); }
@Test @Category(SecondaryTests.class) public void testBatchRemove() { TableBatchOperation batch = new TableBatchOperation(); // add a retrieve Class1 ref = TableTestHelper.generateRandomEntity("jxscl_odata"); TableOperation queryOp = TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), ref.getClass()); batch.add(queryOp); // remove the retrieve batch.remove(queryOp); assertEquals(0, batch.size()); // should be able to add an entity with a different partition key Class1 baseEntity = TableTestHelper.generateRandomEntity("jxscl_odata_2"); TableOperation op = TableOperation.insert(baseEntity); batch.add(op); // remove the insert batch.remove(op); assertEquals(0, batch.size()); // should be able to add a retrieve to the batch ref = TableTestHelper.generateRandomEntity("jxscl_odata"); queryOp = TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), ref.getClass()); batch.add(queryOp); }
@Test @Category(SecondaryTests.class) public void testBatchAddIndex() { TableBatchOperation batch = new TableBatchOperation(); // add a retrieve Class1 ref = TableTestHelper.generateRandomEntity("jxscl_odata"); TableOperation queryOp = TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), ref.getClass()); batch.add(0, queryOp); // remove the retrieve batch.remove(0); assertEquals(0, batch.size()); // should be able to add an entity with a different partition key Class1 baseEntity = TableTestHelper.generateRandomEntity("jxscl_odata_2"); TableOperation op = TableOperation.insert(baseEntity); batch.add(0, op); // remove the insert batch.remove(0); assertEquals(0, batch.size()); // add a retrieve to the batch ref = TableTestHelper.generateRandomEntity("jxscl_odata"); queryOp = TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), ref.getClass()); batch.add(0, queryOp); }
@Test @Category(SecondaryTests.class) public void testBatchRemoveRange() throws StorageException { ArrayList<TableOperation> ops = allOpsList(); TableBatchOperation batch = new TableBatchOperation(); batch.addAll(ops); batch.removeRange(0, ops.size()); assertEquals(0, batch.size()); // should be able to add an entity with a different partition key Class1 baseEntity = TableTestHelper.generateRandomEntity("jxscl_odata_2"); batch.insert(baseEntity); batch.removeRange(0, 1); batch.addAll(ops); batch.removeRange(0, ops.size() - 1); // should be not be able to add an entity with a different partition key baseEntity = TableTestHelper.generateRandomEntity("jxscl_odata_2"); try { batch.insert(baseEntity); fail(SR.OPS_IN_BATCH_MUST_HAVE_SAME_PARTITION_KEY); } catch (IllegalArgumentException e) { assertEquals(SR.OPS_IN_BATCH_MUST_HAVE_SAME_PARTITION_KEY, e.getMessage()); } batch.removeRange(0, 1); // should be able to add a retrieve to the batch Class1 ref = TableTestHelper.generateRandomEntity("jxscl_odata"); TableOperation queryOp = TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), ref.getClass()); batch.add(queryOp); }