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; }
public Map<String, EntityProperty> objectToProps(VreAuthorization source) { return ImmutableMap.of( "vreId", new EntityProperty(source.getVreId()), "userId", new EntityProperty(source.getUserId()), "roles", new EntityProperty(String.join(",", source.getRoles())) ); }
/** * Reserved for internal use. Generates an {@link EntityProperty} from the result of invoking the getter method for * this property on the specified instance parameter. * * @param instance * An instance of a class supporting this property with getter and setter methods of the * appropriate name and parameter or return type. * * @return * An {@link EntityProperty} with the data type and value returned by the invoked getter on the instance. * * @throws IllegalArgumentException * if the specified instance parameter is not an instance of the class * or interface declaring the getter method (or of a subclass or implementor thereof). * @throws IllegalAccessException * if the getter method is inaccessible. * @throws InvocationTargetException * if the getter method throws an exception. */ protected EntityProperty generateEntityProperty(final Object instance) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { final Class<?> getType = this.getter.getReturnType(); Object val = this.getter.invoke(instance, (Object[]) null); return new EntityProperty(val, getType); }
public Map<String, EntityProperty> objectToProps(User source) { Map<String, EntityProperty> result = new HashMap<>(); if (source.getPersistentId() != null) { result.put("persistentId", new EntityProperty(source.getPersistentId())); } if (source.getDisplayName() != null) { result.put("displayName", new EntityProperty(source.getDisplayName())); } result.put("id", new EntityProperty(source.getId())); return result; }
/** * Reserved for internal use. Generates an {@link EntityProperty} from the result of invoking the getter method for * this property on the specified instance parameter. * * @param instance * An instance of a class supporting this property with getter and setter methods of the * appropriate name and parameter or return type. * * @return * An {@link EntityProperty} with the data type and value returned by the invoked getter on the instance. * * @throws IllegalArgumentException * if the specified instance parameter is not an instance of the class * or interface declaring the getter method (or of a subclass or implementor thereof). * @throws IllegalAccessException * if the getter method is inaccessible. * @throws InvocationTargetException * if the getter method throws an exception. */ protected EntityProperty generateEntityProperty(final Object instance) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { final Class<?> getType = this.getter.getReturnType(); Object val = this.getter.invoke(instance, (Object[]) null); EntityProperty property = new EntityProperty(val, getType); property.setIsEncrypted(this.isEncrypted); return property; }
private Map<String, EntityProperty> objectToProps(Login source) { ImmutableMap.Builder<String, EntityProperty> builder = ImmutableMap.<String, EntityProperty>builder() .put("username", new EntityProperty(source.getUsername())) .put("userPid", new EntityProperty(source.getUserPid())) .put("password", new EntityProperty(source.getPassword())) .put("salt", new EntityProperty(source.getSalt())); if (source.getGivenName() != null) { builder.put("givenName", new EntityProperty(source.getGivenName())); } if (source.getSurName() != null) { builder.put("surName", new EntityProperty(source.getSurName())); } if (source.getEmailAddress() != null) { builder.put("emailAddress", new EntityProperty(source.getEmailAddress())); } if (source.getOrganization() != null) { builder.put("organization", new EntityProperty(source.getOrganization())); } return builder.build(); }
entityProperty = new EntityProperty(property.getValueAsBoolean()); break; case DateTime: entityProperty = new EntityProperty(property.getValueAsCalendar().getTime()); break; case Double: entityProperty = new EntityProperty(property.getValueAsDouble()); break; case Uuid: entityProperty = new EntityProperty(property.getValueAsUuid()); break; case Integer: entityProperty = new EntityProperty(property.getValueAsInteger()); break; case Long: entityProperty = new EntityProperty(property.getValueAsLong()); break; case String: entityProperty = new EntityProperty(property.getValueAsString()); break; default: entityProperty = new EntityProperty(property.getValueAsString()); break;
byte[] dest = myAes.doFinal(src, 0, src.length); String destString = new String(dest, Constants.UTF8_CHARSET); decryptedProperties.put(kvp.getKey(), new EntityProperty(destString));
@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(); } }
@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); }
/** * 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); }
tableEntry.getProperties().put(TableConstants.TABLE_NAME, new EntityProperty(this.name));
tableEntry.getProperties().put(TableConstants.TABLE_NAME, new EntityProperty(this.name));
@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"); } }
bigEnt.getProperties().put(propName, new EntityProperty("test")); bigEnt.setPartitionKey("jxscl_odata"); bigEnt.setRowKey(UUID.randomUUID().toString());
EntityProperty property = new EntityProperty(dateString, EdmType.DATE_TIME); String rowKey = TableTestHelper.generateRandomKeyName(); DynamicTableEntity dynamicEntity = new DynamicTableEntity(partitionKey, rowKey);
final EntityProperty property = new EntityProperty(date); rowKey = TableTestHelper.generateRandomKeyName(); DynamicTableEntity dynamicEntity = new DynamicTableEntity(partitionKey, rowKey);