private void remove(UUID jobId, String tableName) throws IOException { try { CloudTable table = tableClient.getTableReference(tableName); TableOperation retrieve = TableOperation.retrieve( configuration.getPartitionKey(), jobId.toString(), DataWrapper.class); TableResult result = table.execute(retrieve); DataWrapper wrapper = result.getResultAsType(); TableOperation delete = TableOperation.delete(wrapper); table.execute(delete); } catch (StorageException | URISyntaxException e) { throw new IOException("Error removing data for job: " + jobId, e); } }
@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; } }
protected void delete(String partitionKey, String rowKey) throws StorageException { table.execute(TableOperation.delete(new DynamicTableEntity(partitionKey, rowKey))); }
/** * 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 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)); }
public void removeBlobDataTracker(long id,String volid) throws StorageException { TableOperation to = TableOperation.retrieve(volid, Long.toString(id), BlobDataTracker.class); BlobDataTracker btr = cloudTable.execute(to).getResultAsType(); if(btr != null) { TableOperation deleteBtr = TableOperation.delete(btr); // Submit the delete operation to the table service. cloudTable.execute(deleteBtr); } }
public boolean remove(TableType entity) { try { return tableRefrence(entity.getAzureTableName()) .execute(TableOperation.delete(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()); } }
/** * Deletes a specified row in the processor table. * * Note: Table service uses optimistic locking by default. In order to disable it, set the ETag on the ProcessorEntity * to "*" before invoking this method. * * @param entity ProcessorEntity that has to be deleted * @throws AzureException If an Azure storage service error occurred. */ public void deleteProcessorEntity(ProcessorEntity entity) { try { TableOperation remove = TableOperation.delete(entity); table.execute(remove); } catch (StorageException e) { LOG.error("Azure storage exception while deleting processor entity with job model version: " + entity.getJobModelVersion() + "and pid: " + entity.getProcessorId(), e); throw new AzureException(e); } } /**
/** * Illustrates how to form and execute an entity delete operation. * * @throws StorageException */ public void BasicDeleteEntity() throws StorageException { // Create an operation to retrieve the entity with partition key of // "Smith" and row key of "Jeff". TableOperation retrieveSmithJeff = TableOperation.retrieve("Smith", "Jeff", CustomerEntity.class); // Retrieve the entity with partition key of "Smith" and row key of // "Jeff". CustomerEntity entitySmithJeff = table.execute(retrieveSmithJeff) .getResultAsType(); // Create an operation to delete the entity. TableOperation deleteSmithJeff = TableOperation.delete(entitySmithJeff); // Submit the delete operation to the table service. table.execute(deleteSmithJeff); }
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; }
/** * Deletes a specified row in the processor table. * * Note: Table service uses optimistic locking by default. Hence, if there is an update after retrieving the entity, * then the delete operation will fail. * * @param jmVersion Job model version of the processor row to be deleted. * @param pid Unique processor ID of the processor row to be deleted. * @param force True, to disable optimistic locking on the table. False, otherwise. Setting to false may result in * AzureException when there is concurrent access to the table. * * @throws AzureException If an Azure storage service error occurred. */ public void deleteProcessorEntity(String jmVersion, String pid, boolean force) { try { TableOperation retrieveEntity = TableOperation.retrieve(jmVersion, pid, ProcessorEntity.class); ProcessorEntity entity = table.execute(retrieveEntity).getResultAsType(); if (force) { entity.setEtag("*"); } TableOperation remove = TableOperation.delete(entity); table.execute(remove); } catch (StorageException e) { LOG.error("Azure storage exception while deleting processor entity with job model version: " + jmVersion + "and pid: " + pid, e); throw new AzureException(e); } }
@After public void tableODataTestBeforeMethodTearDown() throws StorageException { this.table.execute(TableOperation.delete(this.ent), this.options, null); this.table.deleteIfExists(); }
public void deleteTableEntity(@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); cloudTable.execute(TableOperation.delete(entity), tro, null); } catch (Throwable t) { throw new AzureCmdException("Error deleting the Table Entity", t); } }
private void testBatchRetrieve(TableRequestOptions options) throws StorageException { // insert entity Class1 ref = TableTestHelper.generateRandomEntity("jxscl_odata"); this.table.execute(TableOperation.insert(ref), options, null); TableBatchOperation batch = new TableBatchOperation(); batch.retrieve(ref.getPartitionKey(), ref.getRowKey(), ref.getClass()); ArrayList<TableResult> results = this.table.execute(batch, options, null); assertEquals(results.size(), 1); assertEquals(results.get(0).getHttpStatusCode(), HttpURLConnection.HTTP_OK); Class1 retrievedRef = results.get(0).getResultAsType(); assertEquals(ref.getA(), retrievedRef.getA()); assertEquals(ref.getB(), retrievedRef.getB()); assertEquals(ref.getC(), retrievedRef.getC()); assertTrue(Arrays.equals(ref.getD(), retrievedRef.getD())); this.table.execute(TableOperation.delete(ref), options, null); }
private void testDelete(TableRequestOptions options) throws StorageException { Class1 ref = new Class1(); ref.setA("foo_A"); ref.setB("foo_B"); ref.setC("foo_C"); ref.setD(new byte[]{0, 1, 2}); ref.setPartitionKey("jxscl_odata"); ref.setRowKey(UUID.randomUUID().toString()); TableOperation op = TableOperation.insert(ref); this.table.execute(op, options, null); this.table.execute(TableOperation.delete(ref), options, null); TableResult res2 = this.table.execute( TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), Class1.class), options, null); assertTrue(res2.getResult() == null); }
@Test public void testStoreAsAnnotation() throws StorageException { StoreAsEntity ref = new StoreAsEntity(); ref.setPartitionKey("jxscl_odata"); ref.setRowKey(UUID.randomUUID().toString()); ref.setStoreAsString("StoreAsOverride Data"); ref.populateEntity(); this.table.execute(TableOperation.insert(ref)); TableResult res = this.table.execute(TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), StoreAsEntity.class)); StoreAsEntity retrievedStoreAsRef = res.getResultAsType(); assertEquals(retrievedStoreAsRef.getStoreAsString(), ref.getStoreAsString()); // Same query with a class without the storeAs annotation res = this.table.execute(TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), ComplexEntity.class)); ComplexEntity retrievedComplexRef = res.getResultAsType(); assertEquals(retrievedComplexRef.getString(), ref.getStoreAsString()); this.table.execute(TableOperation.delete(retrievedComplexRef)); }
private void testWhitespaceOnEmptyKeysTest(TableRequestOptions options, boolean usePropertyResolver) throws StorageException { Class1 ref = new Class1(); ref.setA("B "); ref.setB(" A "); ref.setC(" "); ref.setD(new byte[] { 0, 1, 2 }); ref.setPartitionKey(""); ref.setRowKey(""); if (usePropertyResolver) { options.setPropertyResolver(ref); } this.table.execute(TableOperation.insert(ref), options, null); TableResult res = this.table.execute( TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), Class1.class), options, null); assertEquals(((Class1) res.getResult()).getA(), ref.getA()); this.table.execute(TableOperation.delete(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); }