/** * 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 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)); }
public boolean update(TableType entity) { try { return tableRefrence(entity.getAzureTableName()) .execute(TableOperation.replace(entity)) .getHttpStatusCode() == Response.Status.NO_CONTENT.getStatusCode(); } catch (StorageException e) { LOG.warn("Error updating row in table: {}", entity.getAzureTableName(), e); } throw new IllegalStateException("Error updating data in table: " + entity.getAzureTableName()); }
/** * Updates the liveness value of a particular processor with a randomly generated integer, which in turn updates the last modified since timestamp of the row. * @param jmVersion Job model version of the processor row to be updated. * @param pid Unique processor ID of the processor row to be updated. */ public void updateHeartbeat(String jmVersion, String pid) { try { TableOperation retrieveEntity = TableOperation.retrieve(jmVersion, pid, ProcessorEntity.class); ProcessorEntity entity = table.execute(retrieveEntity).getResultAsType(); entity.updateLiveness(); TableOperation update = TableOperation.replace(entity); table.execute(update); } catch (StorageException e) { LOG.error("Azure storage exception while updating heartbeat for job model version: " + jmVersion + "and pid: " + pid, e); } }
/** * Updates the isLeader value when the processor starts or stops being a leader. * @param jmVersion Job model version of the processor row to be updated. * @param pid Unique processor ID of the processor row to be updated. * @param isLeader Denotes whether the processor is a leader or not. * @throws AzureException If an Azure storage service error occurred. */ public void updateIsLeader(String jmVersion, String pid, boolean isLeader) { try { TableOperation retrieveEntity = TableOperation.retrieve(jmVersion, pid, ProcessorEntity.class); ProcessorEntity entity = table.execute(retrieveEntity).getResultAsType(); entity.setIsLeader(isLeader); TableOperation update = TableOperation.replace(entity); table.execute(update); } catch (StorageException e) { LOG.error("Azure storage exception while updating isLeader value for job model version: " + jmVersion + "and pid: " + pid, e); throw new AzureException(e); } }
private TableOperation getTableOperation(DynamicTableEntity entity) { TableOperation tableOpe = null; switch (actionData) { case Insert: tableOpe = TableOperation.insert(entity); break; case Insert_Or_Merge: tableOpe = TableOperation.insertOrMerge(entity); break; case Insert_Or_Replace: tableOpe = TableOperation.insertOrReplace(entity); break; case Merge: tableOpe = TableOperation.merge(entity); break; case Replace: tableOpe = TableOperation.replace(entity); break; case Delete: tableOpe = TableOperation.delete(entity); break; default: LOGGER.error("No specified operation for table"); } return tableOpe; }
private TableOperation getTableOperation(DynamicTableEntity entity) { TableOperation tableOpe = null; switch (actionData) { case Insert: tableOpe = TableOperation.insert(entity); break; case Insert_Or_Merge: tableOpe = TableOperation.insertOrMerge(entity); break; case Insert_Or_Replace: tableOpe = TableOperation.insertOrReplace(entity); break; case Merge: tableOpe = TableOperation.merge(entity); break; case Replace: tableOpe = TableOperation.replace(entity); break; case Delete: tableOpe = TableOperation.delete(entity); break; default: LOGGER.error("No specified operation for table"); } return tableOpe; }
@NotNull public TableEntity updateTableEntity(@NotNull StorageAccount storageAccount, @NotNull TableEntity tableEntity) throws AzureCmdException { try { CloudTableClient client = getCloudTableClient(storageAccount); CloudTable cloudTable = client.getTableReference(tableEntity.getTableName()); DynamicTableEntity entity = getDynamicTableEntity(tableEntity); TableRequestOptions tro = new TableRequestOptions(); tro.setTablePayloadFormat(TablePayloadFormat.JsonFullMetadata); TableResult result = cloudTable.execute(TableOperation.replace(entity), tro, null); DynamicTableEntity resultEntity = result.getResultAsType(); return getTableEntity(tableEntity.getTableName(), resultEntity); } catch (Throwable t) { throw new AzureCmdException("Error updating the Table Entity", t); } }
ops.add(TableOperation.replace(createEntityToReplaceOrMerge(baseEntity)));
TableResult replaceResult = this.table.execute(TableOperation.replace(retrievedEntity), options, null);
this.table.execute(TableOperation.replace(retrievedEntity), options, null); this.table.execute(TableOperation.replace(retrievedEntity), options, null); fail(); } catch (TableServiceException ex) { this.table.execute(TableOperation.replace(retrievedEntity), options, null); fail(); } catch (TableServiceException ex) {
@Test public void testBatchMergeFail() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); TableBatchOperation batch = new TableBatchOperation(); addInsertBatch(batch); // Insert entity to merge 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 merge to fail addMergeToBatch(baseEntity, batch); try { this.table.execute(batch, options, null); fail(); } catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Precondition Failed"); String errorAfterSemiColon = ex.getExtendedErrorInformation().getErrorMessage(); errorAfterSemiColon = errorAfterSemiColon.substring(errorAfterSemiColon.indexOf(":") + 1); assertTrue(errorAfterSemiColon .startsWith("The update condition specified in the request was not satisfied.")); assertEquals(ex.getErrorCode(), StorageErrorCodeStrings.UPDATE_CONDITION_NOT_SATISFIED); } }
this.table.execute(TableOperation.replace(ref), options, null); this.table.execute(TableOperation.replace(ref), options, null); this.table.execute(TableOperation.replace(ref), options, null); this.table.execute(TableOperation.replace(ref), options, null); this.table.execute(TableOperation.replace(ref), options, null); this.table.execute(TableOperation.replace(ref), options, null); this.table.execute(TableOperation.replace(ref), options, null);
@Test public void testEntityWithSingleQuote() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); EmptyClass ref = new EmptyClass(); ref.setPartitionKey("partition'key"); ref.setRowKey("row'key"); this.table.execute(TableOperation.insert(ref), options, null); this.table.execute(TableOperation.merge(ref), options, null); this.table.execute(TableOperation.insertOrReplace(ref), options, null); this.table.execute(TableOperation.insertOrMerge(ref), options, null); this.table.execute(TableOperation.replace(ref), options, null); this.table.execute(TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), EmptyClass.class), options, null); this.table.execute(TableOperation.delete(ref), options, null); }
@Test public void testBatchReplaceFail() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); TableBatchOperation batch = new TableBatchOperation(); // Insert entity to merge 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 merge to fail addReplaceToBatch(baseEntity, batch); try { this.table.execute(batch); 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); } }
@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); } }
this.table.execute(TableOperation.replace(ref), options, null);
this.table.execute(TableOperation.replace(ref), options, null);