/** * Adds a table operation to retrieve an entity of the specified class type with the specified PartitionKey and * RowKey to the batch operation. * * @param partitionKey * A <code>String</code> containing the PartitionKey of the entity to retrieve. * @param rowKey * A <code>String</code> containing the RowKey of the entity to retrieve. * @param clazzType * The class of the {@link TableEntity} type for the entity to retrieve. */ public void retrieve(final String partitionKey, final String rowKey, final Class<? extends TableEntity> clazzType) { this.lockToPartitionKey(partitionKey); this.add(TableOperation.retrieve(partitionKey, rowKey, clazzType)); }
/** * Adds a table operation to retrieve an entity of the specified class type with the specified PartitionKey and * RowKey to the batch operation. * * @param partitionKey * A <code>String</code> containing the PartitionKey of the entity to retrieve. * @param rowKey * A <code>String</code> containing the RowKey of the entity to retrieve. * @param clazzType * The class of the {@link TableEntity} type for the entity to retrieve. */ public void retrieve(final String partitionKey, final String rowKey, final Class<? extends TableEntity> clazzType) { this.lockToPartitionKey(partitionKey); this.add(TableOperation.retrieve(partitionKey, rowKey, clazzType)); }
/** * Adds a table operation to retrieve an entity of the specified class type with the specified PartitionKey and * RowKey to the batch operation. * * @param partitionKey * A <code>String</code> containing the PartitionKey of the entity to retrieve. * @param rowKey * A <code>String</code> containing the RowKey of the entity to retrieve. * @param resolver * The {@link EntityResolver} implementation to project the entity to retrieve as a particular type in * the result. */ public void retrieve(final String partitionKey, final String rowKey, final EntityResolver<?> resolver) { this.lockToPartitionKey(partitionKey); this.add(TableOperation.retrieve(partitionKey, rowKey, resolver)); }
/** * Adds a table operation to retrieve an entity of the specified class type with the specified PartitionKey and * RowKey to the batch operation. * * @param partitionKey * A <code>String</code> containing the PartitionKey of the entity to retrieve. * @param rowKey * A <code>String</code> containing the RowKey of the entity to retrieve. * @param resolver * The {@link EntityResolver} implementation to project the entity to retrieve as a particular type in * the result. */ public void retrieve(final String partitionKey, final String rowKey, final EntityResolver<?> resolver) { this.lockToPartitionKey(partitionKey); this.add(TableOperation.retrieve(partitionKey, rowKey, resolver)); }
/** * Adds a table operation to replace the specified entity to the batch operation. * * @param entity * The {@link TableEntity} to replace. */ public void replace(final TableEntity entity) { this.lockToPartitionKey(entity.getPartitionKey()); this.add(TableOperation.replace(entity)); }
/** * Adds a table operation to insert or merge the specified entity to the batch operation. * * @param entity * The {@link TableEntity} to insert if not found or to merge if it exists. */ public void insertOrMerge(final TableEntity entity) { this.lockToPartitionKey(entity.getPartitionKey()); this.add(TableOperation.insertOrMerge(entity)); }
/** * Adds a table operation to insert the specified entity to the batch operation. * * @param entity * The {@link TableEntity} to insert. * @param echoContent * The boolean representing whether the message payload should be returned in the response. */ public void insert(final TableEntity entity, boolean echoContent) { this.lockToPartitionKey(entity.getPartitionKey()); this.add(TableOperation.insert(entity, echoContent)); }
/** * Adds a table operation to insert or replace the specified entity to the batch operation. * * @param entity * The {@link TableEntity} to insert if not found or to replace if it exists. */ public void insertOrReplace(final TableEntity entity) { this.lockToPartitionKey(entity.getPartitionKey()); this.add(TableOperation.insertOrReplace(entity)); }
/** * Adds a table operation to merge the specified entity to the batch operation. * * @param entity * The {@link TableEntity} to merge. */ public void merge(final TableEntity entity) { this.lockToPartitionKey(entity.getPartitionKey()); this.add(TableOperation.merge(entity)); }
/** * Adds a table operation to insert or merge the specified entity to the batch operation. * * @param entity * The {@link TableEntity} to insert if not found or to merge if it exists. */ public void insertOrMerge(final TableEntity entity) { this.lockToPartitionKey(entity.getPartitionKey()); this.add(TableOperation.insertOrMerge(entity)); }
/** * Adds a table operation to delete the specified entity to the batch operation. * * @param entity * The {@link TableEntity} to delete. */ public void delete(final TableEntity entity) { this.lockToPartitionKey(entity.getPartitionKey()); this.add(TableOperation.delete(entity)); }
/** * Adds a table operation to insert or replace the specified entity to the batch operation. * * @param entity * The {@link TableEntity} to insert if not found or to replace if it exists. */ public void insertOrReplace(final TableEntity entity) { this.lockToPartitionKey(entity.getPartitionKey()); this.add(TableOperation.insertOrReplace(entity)); }
/** * Adds a table operation to replace the specified entity to the batch operation. * * @param entity * The {@link TableEntity} to replace. */ public void replace(final TableEntity entity) { this.lockToPartitionKey(entity.getPartitionKey()); this.add(TableOperation.replace(entity)); }
/** * Adds a table operation to delete the specified entity to the batch operation. * * @param entity * The {@link TableEntity} to delete. */ public void delete(final TableEntity entity) { this.lockToPartitionKey(entity.getPartitionKey()); this.add(TableOperation.delete(entity)); }
/** * Adds a table operation to merge the specified entity to the batch operation. * * @param entity * The {@link TableEntity} to merge. */ public void merge(final TableEntity entity) { this.lockToPartitionKey(entity.getPartitionKey()); this.add(TableOperation.merge(entity)); }
/** * Adds a table operation to insert the specified entity to the batch operation. * * @param entity * The {@link TableEntity} to insert. * @param echoContent * The boolean representing whether the message payload should be returned in the response. */ public void insert(final TableEntity entity, boolean echoContent) { this.lockToPartitionKey(entity.getPartitionKey()); this.add(TableOperation.insert(entity, echoContent)); }
@Test public void testBatchAddNullShouldThrow() { try { TableBatchOperation batch = new TableBatchOperation(); batch.add(null); fail(); } catch (IllegalArgumentException ex) { assertEquals(ex.getMessage(), String.format(SR.ARGUMENT_NULL_OR_EMPTY, "element")); } }
@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 // don't need the category secondary as the request will fail before being sent public void testBatchSecondaryWriteShouldThrow() { // create batch with an insert Class1 baseEntity = TableTestHelper.generateRandomEntity("jxscl_odata"); TableOperation op = TableOperation.insert(baseEntity); TableBatchOperation batch = new TableBatchOperation(); batch.add(op); // should not be able to make a request to secondary as there are writes try { TableRequestOptions options = new TableRequestOptions(); options.setLocationMode(LocationMode.SECONDARY_ONLY); options.setRetryPolicyFactory(new RetryNoRetry()); this.table.execute(batch, options, null); fail("Should not be able to make a request to secondary as there are writes."); } catch (StorageException e) { assertEquals(IllegalArgumentException.class, e.getCause().getClass()); assertEquals(SR.PRIMARY_ONLY_COMMAND, e.getCause().getMessage()); } }
@Test @Category(SecondaryTests.class) public void testBatchSecondaryNoWrite() throws StorageException { // create and insert an entity Class1 ref = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(ref)); // create a batch and add a query for this entity TableBatchOperation batch = new TableBatchOperation(); TableOperation queryOp = TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), ref.getClass()); batch.add(queryOp); // should be able to make a request to secondary as there are no writes TableRequestOptions options = new TableRequestOptions(); options.setLocationMode(LocationMode.SECONDARY_ONLY); options.setRetryPolicyFactory(new RetryNoRetry()); this.table.execute(batch, options, null); }