Java源码示例:com.microsoft.azure.storage.table.EntityProperty
示例1
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();
}
示例2
protected Schema inferSchemaDynamicTableEntity(DynamicTableEntity entity) {
List<Field> fields = new ArrayList<>();
fields.add(new Field("PartitionKey", AvroUtils._string(), null, (Object) null));
fields.add(new Field("RowKey", AvroUtils._string(), null, (Object) null));
fields.add(new Field("Timestamp", AvroUtils._date(), null, (Object) null));
// FIXME set tableName properly and manage nameMappings
String tableName = "schemaInfered";
for (Entry<String, EntityProperty> f : entity.getProperties().entrySet()) {
String fieldName = f.getKey();
Field field = getAvroMapping(fieldName, f.getValue());
fields.add(field);
}
return Schema.createRecord(tableName, null, null, false, fields);
}
示例3
@Test
public void testDynamicTableEntityConversion() {
DynamicTableEntity entity = new DynamicTableEntity();
entity.setPartitionKey(pk_test1);
entity.setRowKey(rk_test1);
entity.getProperties().put("a_bool", new EntityProperty(true));
entity.getProperties().put("a_int", new EntityProperty(1000));
entity.getProperties().put("a_string", new EntityProperty(RandomStringUtils.random(10)));
Schema s = registry.inferSchemaDynamicTableEntity(entity);
assertEquals(6, s.getFields().size());
recordConv.setSchema(s);
IndexedRecord record = recordConv.convertToAvro(entity);
assertEquals(pk_test1, record.get(0));
assertEquals(rk_test1, record.get(1));
assertTrue(record.get(2) instanceof Date);
//
assertEquals(true, record.get(s.getField("a_bool").pos()));
assertEquals(1000, record.get(s.getField("a_int").pos()));
assertTrue(record.get(s.getField("a_string").pos()) instanceof String);
Map<String, String> nameMappings = new HashMap<>();
nameMappings.put("a_bool", "booly");
AzureStorageTableAdaptorFactory adaptor = new AzureStorageTableAdaptorFactory(nameMappings);
adaptor.setSchema(s);
//
registry.inferSchemaDynamicTableEntity(entity);
assertEquals(DynamicTableEntity.class, recordConv.getDatumClass());
assertNull(recordConv.convertToDatum(record));
}
示例4
/**
*
* @see org.talend.components.azurestorage.table.avro.AzureStorageAvroRegistry#getAvroMapping(String,EntityProperty)
*/
@Test
public void testGetAvroMapping() {
String name = "field";
assertEquals(new Field(name, AvroUtils._bytes(), null, (Object) null).toString(),
registry.getAvroMapping(name, new EntityProperty(new byte[] {})).toString());
assertEquals(new Field(name, AvroUtils._string(), null, (Object) null).toString(),
registry.getAvroMapping(name, new EntityProperty("test")).toString());
assertEquals(new Field(name, AvroUtils._boolean(), null, (Object) null).toString(),
registry.getAvroMapping(name, new EntityProperty(true)).toString());
assertEquals(new Field(name, AvroUtils._byte(), null, (Object) null).toString(),
registry.getAvroMapping(name, new EntityProperty((byte) 11)).toString());
assertEquals(new Field(name, AvroUtils._date(), null, (Object) null).toString(),
registry.getAvroMapping(name, new EntityProperty(new Date())).toString());
assertEquals(new Field(name, AvroUtils._date(), null, (Object) null).toString(),
registry.getAvroMapping(name, new EntityProperty(new Date())).toString());
assertEquals(new Field(name, AvroUtils._short(), null, (Object) null).toString(),
registry.getAvroMapping(name, new EntityProperty((short) 12)).toString());
assertEquals(new Field(name, AvroUtils._int(), null, (Object) null).toString(),
registry.getAvroMapping(name, new EntityProperty((int) 12)).toString());
assertEquals(new Field(name, AvroUtils._long(), null, (Object) null).toString(),
registry.getAvroMapping(name, new EntityProperty((long) 12)).toString());
assertEquals(new Field(name, AvroUtils._double(), null, (Object) null).toString(),
registry.getAvroMapping(name, new EntityProperty((double) 12.0)).toString());
}
示例5
protected static byte[] getByteArrayOrEmpty(DynamicTableEntity entity, String key) {
EntityProperty property = entity.getProperties().get(key);
byte[] result = new byte[0];
if (property != null) {
result = property.getValueAsByteArray();
}
return result;
}
示例6
protected static String getStringOrNull(DynamicTableEntity entity, String key) {
EntityProperty property = entity.getProperties().get(key);
String result = null;
if (property != null) {
result = property.getValueAsString();
}
return result;
}
示例7
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;
}
示例8
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()))
);
}
示例9
protected void create(String partitionKey, String rowKey, Map<String, EntityProperty> properties)
throws StorageException {
table.execute(TableOperation.insert(new DynamicTableEntity(partitionKey, rowKey, new HashMap<>(properties))));
}