private Status insertOrUpdate(String key, Map<String, ByteIterator> values) { HashMap<String, EntityProperty> properties = new HashMap<String, EntityProperty>(); for (Entry<String, ByteIterator> entry : values.entrySet()) { String fieldName = entry.getKey(); byte[] fieldVal = entry.getValue().toArray(); properties.put(fieldName, new EntityProperty(fieldVal)); } DynamicTableEntity entity = new DynamicTableEntity(partitionKey, key, properties); TableOperation insertOrReplace = TableOperation.insertOrReplace(entity); try { cloudTable.execute(insertOrReplace); return Status.OK; } catch (Exception e) { return Status.ERROR; } }
private Status insertBatch(String key, Map<String, ByteIterator> values) { HashMap<String, EntityProperty> properties = new HashMap<String, EntityProperty>(); for (Entry<String, ByteIterator> entry : values.entrySet()) { String fieldName = entry.getKey(); byte[] fieldVal = entry.getValue().toArray(); properties.put(fieldName, new EntityProperty(fieldVal)); } DynamicTableEntity entity = new DynamicTableEntity(partitionKey, key, properties); BATCH_OPERATION.insertOrReplace(entity); if (++curIdx == batchSize) { try { cloudTable.execute(BATCH_OPERATION); BATCH_OPERATION.clear(); curIdx = 0; } catch (Exception e) { return Status.ERROR; } } return Status.OK; }
protected void create(String partitionKey, String rowKey, Map<String, EntityProperty> properties) throws StorageException { table.execute(TableOperation.insert(new DynamicTableEntity(partitionKey, rowKey, new HashMap<>(properties)))); }
protected void delete(String partitionKey, String rowKey) throws StorageException { table.execute(TableOperation.delete(new DynamicTableEntity(partitionKey, rowKey))); }
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(); } }
private DynamicTableEntity createDynamicEntityFromInputRecord(IndexedRecord indexedRecord, Schema schema) { DynamicTableEntity entity = new DynamicTableEntity(); HashMap<String, EntityProperty> entityProps = new HashMap<>(); for (Field f : schema.getFields()) {
private DynamicTableEntity createDynamicEntityFromInputRecord(IndexedRecord indexedRecord, Schema schema) { DynamicTableEntity entity = new DynamicTableEntity(); HashMap<String, EntityProperty> entityProps = new HashMap<>(); for (Field f : schema.getFields()) {
@NotNull private static DynamicTableEntity getDynamicTableEntity(@NotNull String partitionKey, @NotNull String rowKey, @Nullable Calendar timestamp, @Nullable String eTag, @NotNull Map<String, Property> properties) throws AzureCmdException { Date ts = null; if (timestamp != null) { ts = timestamp.getTime(); } HashMap<String, EntityProperty> entityProperties = getEntityProperties(properties); return new DynamicTableEntity(partitionKey, rowKey, eTag, entityProperties); }
/** * Deletes the table from the storage service, using the specified request options and operation context. * * @param options * A {@link TableRequestOptions} object that specifies any additional options for the request. Specifying * <code>null</code> will use the default request options from the associated service client ( * {@link CloudTableClient}). * @param opContext * An {@link OperationContext} object that represents the context for the current operation. This object * is used to track requests to the storage service, and to provide additional runtime information about * the operation. * * @throws StorageException * If a storage service error occurred during the operation. */ @DoesServiceRequest public void delete(TableRequestOptions options, OperationContext opContext) throws StorageException { if (opContext == null) { opContext = new OperationContext(); } opContext.initialize(); options = TableRequestOptions.populateAndApplyDefaults(options, this.tableServiceClient); Utility.assertNotNullOrEmpty("tableName", this.name); final DynamicTableEntity tableEntry = new DynamicTableEntity(); tableEntry.getProperties().put(TableConstants.TABLE_NAME, new EntityProperty(this.name)); TableOperation deleteOp = new TableOperation(tableEntry, TableOperationType.DELETE); deleteOp.execute(this.tableServiceClient, TableConstants.TABLES_SERVICE_TABLES_NAME, options, opContext); }
/** * Deletes the table from the storage service, using the specified request options and operation context. * * @param options * A {@link TableRequestOptions} object that specifies any additional options for the request. Specifying * <code>null</code> will use the default request options from the associated service client ( * {@link CloudTableClient}). * @param opContext * An {@link OperationContext} object that represents the context for the current operation. This object * is used to track requests to the storage service, and to provide additional runtime information about * the operation. * * @throws StorageException * If a storage service error occurred during the operation. */ @DoesServiceRequest public void delete(TableRequestOptions options, OperationContext opContext) throws StorageException { if (opContext == null) { opContext = new OperationContext(); } opContext.initialize(); options = TableRequestOptions.populateAndApplyDefaults(options, this.tableServiceClient); Utility.assertNotNullOrEmpty("tableName", this.name); final DynamicTableEntity tableEntry = new DynamicTableEntity(); tableEntry.getProperties().put(TableConstants.TABLE_NAME, new EntityProperty(this.name)); TableOperation deleteOp = new TableOperation(tableEntry, TableOperationType.DELETE); deleteOp.execute(this.tableServiceClient, TableConstants.TABLES_SERVICE_TABLES_NAME, options, opContext); }
final DynamicTableEntity tableEntry = new DynamicTableEntity(); tableEntry.getProperties().put(TableConstants.TABLE_NAME, new EntityProperty(this.name));
@Test public void testTableQueryProjectionWithIncorrectTypes() 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 with String as an int, and IntegerPrimitive as a bool DynamicTableEntity entity = new DynamicTableEntity(UUID.randomUUID().toString(), UUID.randomUUID() .toString()); entity.getProperties().put("String", new EntityProperty(1234)); entity.getProperties().put("IntegerPrimitive", new EntityProperty(true)); table.execute(TableOperation.insert(entity)); testTableQueryProjectionWithSpecialCases(table); } finally { table.deleteIfExists(); } }
final DynamicTableEntity tableEntry = new DynamicTableEntity(); tableEntry.getProperties().put(TableConstants.TABLE_NAME, new EntityProperty(this.name));
@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); }
@Test public void testInsertEntityWithNumericProperty() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); DynamicTableEntity ref = new DynamicTableEntity(); String propName = ""; for (int m = 0; m < 255; m++) { propName = propName.concat(Integer.toString(m % 9)); } ref.getProperties().put(propName, new EntityProperty("test")); ref.setPartitionKey("jxscl_odata"); ref.setRowKey(UUID.randomUUID().toString()); try { this.table.execute(TableOperation.insert(ref), options, null); fail(); } catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Bad Request"); assertTrue(ex.getExtendedErrorInformation().getErrorMessage().startsWith("The property name is invalid.")); assertEquals(ex.getExtendedErrorInformation().getErrorCode(), "PropertyNameInvalid"); } }
@Test public void testInsertEntityWithPropertyMoreThan255chars() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.Json); DynamicTableEntity ref = new DynamicTableEntity(); String propName = ""; for (int m = 0; m < 256; m++) { propName = propName.concat("a"); } ref.getProperties().put(propName, new EntityProperty("test")); ref.setPartitionKey("jxscl_odata"); ref.setRowKey(UUID.randomUUID().toString()); try { this.table.execute(TableOperation.insert(ref), options, null); fail(); } catch (TableServiceException ex) { assertEquals(ex.getMessage(), "Bad Request"); assertTrue(ex.getExtendedErrorInformation().getErrorMessage() .startsWith("The property name exceeds the maximum allowed length (255).")); assertEquals(ex.getExtendedErrorInformation().getErrorCode(), "PropertyNameTooLong"); } }
DynamicTableEntity bigEnt = new DynamicTableEntity();
DynamicTableEntity dynamicEntity = new DynamicTableEntity(partitionKey, rowKey); dynamicEntity.getProperties().put(dateKey, property);
final EntityProperty property = new EntityProperty(date); rowKey = TableTestHelper.generateRandomKeyName(); DynamicTableEntity dynamicEntity = new DynamicTableEntity(partitionKey, rowKey); dynamicEntity.getProperties().put(dateKey, property); dynamicEntity = new DynamicTableEntity(partitionKey, rowKey); dynamicEntity.getProperties().put(dateKey, property);
DynamicTableEntity ent = new DynamicTableEntity("partition", "row"); TableOperation insert = TableOperation.insert(ent); table.execute(insert, options, opContext);