private void create(String rowKey, String tableName, String state, Object type) throws IOException { try { CloudTable table = tableClient.getTableReference(tableName); String serializedJob = configuration.getMapper().writeValueAsString(type); DataWrapper wrapper = new DataWrapper( configuration.getPartitionKey(), rowKey, state, serializedJob); // job id used as key TableOperation insert = TableOperation.insert(wrapper); table.execute(insert); } catch (JsonProcessingException | StorageException | URISyntaxException e) { throw new IOException("Error creating data for rowKey: " + rowKey, e); } }
@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); }
/** * A static factory method returning a {@link TableOperation} instance to insert the specified entity into * Microsoft Azure storage. To execute this {@link TableOperation} on a given table, call the * {@link CloudTable#execute(TableOperation)} method on a {@link CloudTableClient} instance with the * * @param entity * The object instance implementing {@link TableEntity} to associate with the operation. * @return * A new {@link TableOperation} instance to insert the table entity. */ public static TableOperation insert(final TableEntity entity) { return insert(entity, false); }
/** * A static factory method returning a {@link TableOperation} instance to insert the specified entity into * Microsoft Azure storage. To execute this {@link TableOperation} on a given table, call the * {@link CloudTable#execute(TableOperation)} method on a {@link CloudTableClient} instance with the * * @param entity * The object instance implementing {@link TableEntity} to associate with the operation. * @return * A new {@link TableOperation} instance to insert the table entity. */ public static TableOperation insert(final TableEntity entity) { return insert(entity, false); }
protected void create(String partitionKey, String rowKey, Map<String, EntityProperty> properties) throws StorageException { table.execute(TableOperation.insert(new DynamicTableEntity(partitionKey, rowKey, new HashMap<>(properties)))); }
public boolean insert(TableType entity) { try { return tableRefrence(entity.getAzureTableName()) .execute(TableOperation.insert(entity)) .getHttpStatusCode() == Response.Status.NO_CONTENT.getStatusCode(); } catch (StorageException e) { LOG.warn("Error performing operation on Storage service", e); } throw new IllegalStateException("Error adding data in table " + entity.getAzureTableName()); }
/** * 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 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)); }
/** * Add a row which denotes an active processor to the processor table. * @param jmVersion Job model version that the processor is operating on. * @param pid Unique processor ID. * @param isLeader Denotes whether the processor is a leader or not. * @throws AzureException If an Azure storage service error occurred. */ public void addProcessorEntity(String jmVersion, String pid, boolean isLeader) { ProcessorEntity entity = new ProcessorEntity(jmVersion, pid); entity.setIsLeader(isLeader); entity.updateLiveness(); TableOperation add = TableOperation.insert(entity); try { table.execute(add); } catch (StorageException e) { LOG.error("Azure storage exception while adding processor entity with job model version: " + jmVersion + "and pid: " + pid, e); throw new AzureException(e); } }
public void testTableQueryProjectionWithNull() throws URISyntaxException, StorageException { CloudTable table = TableTestHelper.getRandomTableReference(); try { // Create a new table so we don't pollute the main query table table.createIfNotExists(); // Insert an entity which is missing String and IntegerPrimitive DynamicTableEntity entity = new DynamicTableEntity(UUID.randomUUID().toString(), UUID.randomUUID() .toString()); table.execute(TableOperation.insert(entity)); testTableQueryProjectionWithSpecialCases(table); } finally { table.deleteIfExists(); } }
@Test public void testInsertEmptyEntity() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); EmptyClass ref = new EmptyClass(); ref.setPartitionKey("jxscl_odata"); ref.setRowKey("echo_default" + UUID.randomUUID().toString()); TableResult res = this.table.execute(TableOperation.insert(ref), options, null); assertEquals(HttpURLConnection.HTTP_NO_CONTENT, res.getHttpStatusCode()); EmptyClassDynamic refDynamic = new EmptyClassDynamic(); refDynamic.setPartitionKey("jxscl_odata"); refDynamic.setRowKey("echo_default" + UUID.randomUUID().toString()); res = this.table.execute(TableOperation.insert(refDynamic), options, null); assertEquals(HttpURLConnection.HTTP_NO_CONTENT, res.getHttpStatusCode()); }
@Before public void tableODataTestBeforeMethodSetUp() throws StorageException, URISyntaxException { this.table = TableTestHelper.getRandomTableReference(); this.table.createIfNotExists(); final CloudTableClient tClient = TableTestHelper.createCloudTableClient(); this.options = TableRequestOptions.populateAndApplyDefaults(this.options, tClient); this.options.setTablePayloadFormat(TablePayloadFormat.JsonNoMetadata); // Insert Entity this.ent = new DynamicTableEntity(); this.ent.setPartitionKey("jxscl_odata"); this.ent.setRowKey(UUID.randomUUID().toString()); this.ent.getProperties().put("foo2", new EntityProperty("bar2")); this.ent.getProperties().put("foo", new EntityProperty("bar")); this.ent.getProperties().put("fooint", new EntityProperty(1234)); this.table.execute(TableOperation.insert(this.ent), this.options, null); }
private void testDoubles(TableRequestOptions options, boolean usePropertyResolver) throws StorageException { StrangeDoubles ref = new StrangeDoubles(); ref.setPartitionKey("jxscl_odata"); ref.setRowKey(UUID.randomUUID().toString()); ref.populateEntity(); if (usePropertyResolver) { options.setPropertyResolver(ref); } // try with pojo this.table.execute(TableOperation.insert(ref), options, null); TableResult res = this.table.execute( TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), StrangeDoubles.class), options, null); StrangeDoubles retrievedComplexRef = res.getResultAsType(); ref.assertEquality(retrievedComplexRef); }
private void testComplexEntityInsert(TableRequestOptions options, boolean usePropertyResolver) throws StorageException { ComplexEntity ref = new ComplexEntity(); ref.setPartitionKey("jxscl_odata"); ref.setRowKey(UUID.randomUUID().toString()); ref.populateEntity(); if (usePropertyResolver) { options.setPropertyResolver(ref); } this.table.execute(TableOperation.insert(ref), options, null); TableResult res = this.table.execute( TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), ComplexEntity.class), options, null); ComplexEntity retrievedComplexRef = res.getResultAsType(); ref.assertEquality(retrievedComplexRef); }
@Test public void testInvalidStoreAsAnnotation() throws StorageException { InvalidStoreAsEntity ref = new InvalidStoreAsEntity(); 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(), InvalidStoreAsEntity.class)); InvalidStoreAsEntity retrievedStoreAsRef = res.getResultAsType(); assertEquals(retrievedStoreAsRef.getStoreAsString(), null); }
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 testTableQueryWithSpecialChars(char charToTest, CloudTable table) throws StorageException, URISyntaxException { String partitionKey = "partition" + charToTest + "key"; String rowKey = "row" + charToTest + "key"; EmptyClass ref = new EmptyClass(); ref.setPartitionKey(partitionKey); ref.setRowKey(rowKey); table.execute(TableOperation.insert(ref)); String condition = TableQuery.generateFilterCondition(TableConstants.PARTITION_KEY, QueryComparisons.EQUAL, partitionKey); ResultSegment<EmptyClass> seg = table.executeSegmented(TableQuery.from(EmptyClass.class).where(condition), null); assertEquals(1, seg.getLength()); assertEquals(partitionKey, seg.getResults().get(0).getPartitionKey()); }
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); }
private void testWhitespaceTest(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("jxscl_odata"); ref.setRowKey(UUID.randomUUID().toString()); 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()); }
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); } }