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; } }
public HashMap<String, ByteIterator> resolve(String partitionkey, String rowKey, Date timeStamp, HashMap<String, EntityProperty> properties, String etag) { HashMap<String, ByteIterator> tmp = new HashMap<String, ByteIterator>(); for (Entry<String, EntityProperty> entry : properties.entrySet()) { String key = entry.getKey(); ByteIterator val = new ByteArrayByteIterator(entry.getValue().getValueAsByteArray()); tmp.put(key, val); } return tmp; } };
this.value = value; if (type.equals(byte[].class)) { this.getValueAsByteArray(); this.edmType = EdmType.BINARY; this.getValueAsByteObjectArray(); this.edmType = EdmType.BINARY; this.getValueAsBoolean(); this.edmType = EdmType.BOOLEAN; this.getValueAsBooleanObject(); this.edmType = EdmType.BOOLEAN; this.getValueAsDate(); this.edmType = EdmType.DATE_TIME; this.getValueAsDouble(); this.edmType = EdmType.DOUBLE; this.getValueAsDoubleObject(); this.edmType = EdmType.DOUBLE; this.getValueAsUUID(); this.edmType = EdmType.GUID; this.getValueAsInteger(); this.edmType = EdmType.INT32;
@Override public Class1 resolve(String partitionKey, String rowKey, Date timeStamp, HashMap<String, EntityProperty> properties, String etag) { Class1 result = new Class1(); result.setA(properties.get("A").getValueAsString()); result.setD(properties.get("D").getValueAsByteArray()); return result; } }), options, null);
switch (entry.getValue().getEdmType()) { case BOOLEAN: property = new Property(entry.getValue().getValueAsBooleanObject()); break; case DATE_TIME: Calendar value = new GregorianCalendar(); value.setTime(entry.getValue().getValueAsDate()); property = new Property(value); break; case DOUBLE: property = new Property(entry.getValue().getValueAsDoubleObject()); break; case GUID: property = new Property(entry.getValue().getValueAsUUID()); break; case INT32: property = new Property(entry.getValue().getValueAsIntegerObject()); break; case INT64: property = new Property(entry.getValue().getValueAsLongObject()); break; case STRING: property = new Property(entry.getValue().getValueAsString()); break; default: property = new Property(entry.getValue().getValueAsString()); break;
this.getValueAsByteArray(); this.type = Byte[].class; this.getValueAsBoolean(); this.type = Boolean.class; this.getValueAsDouble(); this.type = Double.class; this.getValueAsUUID(); this.type = UUID.class; this.getValueAsInteger(); this.type = Integer.class; this.getValueAsLong(); this.type = Long.class; this.getValueAsDate(); this.type = Date.class;
private static void writeJsonProperty(JsonGenerator generator, Entry<String, EntityProperty> prop) throws JsonGenerationException, IOException { EdmType edmType = prop.getValue().getEdmType(); if (prop.getValue().getIsNull()) { generator.writeNullField(prop.getKey()); } else if (edmType == EdmType.BOOLEAN) { generator.writeBooleanField(prop.getKey(), prop.getValue().getValueAsBoolean()); } else if (edmType == EdmType.DOUBLE) { generator.writeNumberField(prop.getKey(), prop.getValue().getValueAsDouble()); } else if (edmType == EdmType.INT32) { generator.writeNumberField(prop.getKey(), prop.getValue().getValueAsInteger()); } else { generator.writeStringField(prop.getKey(), prop.getValue().getValueAsString()); } }
final EntityProperty newProp = new EntityProperty(val, edmType); newProp.setDateBackwardCompatibility(options.getDateBackwardCompatibility()); properties.put(key, newProp); partitionKey = tempProp.getValueAsString(); rowKey = tempProp.getValueAsString(); tempProp.setDateBackwardCompatibility(false); timestamp = tempProp.getValueAsDate(); etag = getETagFromTimestamp(tempProp.getValueAsString()); res.setEtag(etag); if (propertyDetailsProperty != null && !propertyDetailsProperty.getIsNull() && keyProperty != null && !keyProperty.getIsNull()) { final EntityProperty newProp = new EntityProperty(property.getValue().getValueAsString(), EdmType.STRING); properties.put(property.getKey(), newProp); final EntityProperty newProp = new EntityProperty(property.getValue().getValueAsString(), EdmType.BINARY); properties.put(property.getKey(), newProp); final String value = property.getValue().getValueAsString(); EdmType edmType; final EntityProperty newProp = new EntityProperty(value, isEncrypted(encryptedPropertyDetailsSet, key) ? EdmType.BINARY : edmType);
kvp.getValue().setIsEncrypted(true); if (kvp.getValue() != null && kvp.getValue().isEncrypted()) { if (kvp.getValue().getEdmType() != EdmType.STRING) { throw new IllegalArgumentException(String.format(SR.UNSUPPORTED_PROPERTY_TYPE_FOR_ENCRYPTION, kvp.getValue().getEdmType())); byte[] src = kvp.getValue().getValueAsString().getBytes(Constants.UTF8_CHARSET); byte[] dest = myAes.doFinal(src, 0, src.length); encryptedProperties.put(kvp.getKey(), new EntityProperty(dest)); encryptionPropertyDetailsSet.add(kvp.getKey()); byte[] dest = myAes.doFinal(src, 0, src.length); encryptedProperties.put(Constants.EncryptionConstants.TABLE_ENCRYPTION_PROPERTY_DETAILS, new EntityProperty(dest)); encryptedProperties.put(Constants.EncryptionConstants.TABLE_ENCRYPTION_KEY_DETAILS, new EntityProperty( encryptionData.serialize()));
if (currProp.getEdmType().mustAnnotateType()) { final String edmTypeString = currProp.getEdmType().toString(); generator.writeStringField(ent.getKey(), ent.getValue().getValueAsString()); else if (currProp.getEdmType() == EdmType.DOUBLE && currProp.getIsNull() == false) { final String edmTypeString = currProp.getEdmType().toString(); final Double value = currProp.getValueAsDouble(); generator.writeStringField(ent.getKey(), ent.getValue().getValueAsString());
@Override public String resolve(String partitionKey, String rowKey, Date timeStamp, HashMap<String, EntityProperty> properties, String etag) { return properties.get(TableConstants.TABLE_NAME).getValueAsString(); } };
EntityProperty property = new EntityProperty(dateString, EdmType.DATE_TIME); String rowKey = TableTestHelper.generateRandomKeyName(); DynamicTableEntity dynamicEntity = new DynamicTableEntity(partitionKey, rowKey); assertEquals(expectedMilliseconds, dynamicEntity.getProperties().get(dateKey).getValueAsDate().getTime());
encryptionData.copyValues(EncryptionData.deserialize(encryptionKeyProperty.getValueAsString())); myAes.init(Cipher.DECRYPT_MODE, keySpec, ivParameterSpec); byte[] src = propertyDetailsProperty.getValueAsByteArray(); propertyDetailsProperty.setValue(myAes.doFinal(src, 0, src.length));
byte[] src = kvp.getValue().getValueAsByteArray(); byte[] dest = myAes.doFinal(src, 0, src.length); String destString = new String(dest, Constants.UTF8_CHARSET); decryptedProperties.put(kvp.getKey(), new EntityProperty(destString));
columns.put(key, new EntityProperty(value)); final DynamicTableEntity entity = new DynamicTableEntity(partition1, row1, columns); TableOperation op = TableOperation.insert(entity); assertEquals(value, result.getProperties().get(key).getValueAsString()); entity.getProperties().put(key, new EntityProperty(value2)); op = TableOperation.merge(entity); if (policy.getPermissions().contains(SharedAccessAccountPermissions.UPDATE)) { assertEquals(value2, result.getProperties().get(key).getValueAsString()); entity.getProperties().put(key, new EntityProperty(value)); op = TableOperation.insertOrMerge(entity); columns2.put(key, new EntityProperty(value2)); final DynamicTableEntity entity2 = new DynamicTableEntity(partition2, row2, columns2); TableOperation op2 = TableOperation.insertOrMerge(entity2); assertEquals(value2, result.getProperties().get(key).getValueAsString()); assertEquals(value, result.getProperties().get(key).getValueAsString());
private void testTableWithSelectOnMissingFields(TableRequestOptions options) throws StorageException { TableQuery<DynamicTableEntity> projectionQuery = TableQuery.from(DynamicTableEntity.class).where( "(PartitionKey eq 'javatables_batch_0') and (RowKey eq '000000')"); // A exists, F does not projectionQuery.select(new String[]{"A", "F"}); ResultSegment<DynamicTableEntity> seg = table.executeSegmented(projectionQuery, null, options, null); assertEquals(1, seg.getResults().size()); DynamicTableEntity ent = seg.getResults().get(0); assertEquals("foo_A", ent.getProperties().get("A").getValueAsString()); assertEquals(null, ent.getProperties().get("F").getValueAsString()); assertEquals(EdmType.STRING, ent.getProperties().get("F").getEdmType()); }
+ "\t" + entity.getProperties().get("Email") .getValueAsString() + "\t" + entity.getProperties().get("PhoneNumber") .getValueAsString() + "\t" + entity.getProperties().get("Id") .getValueAsUUID());
private static HashSet<String> parsePropertyDetails(EntityProperty propertyDetailsProperty) throws UnsupportedEncodingException { HashSet<String> encryptedPropertyDetailsSet = null; if (propertyDetailsProperty != null && !propertyDetailsProperty.getIsNull()) { byte[] binaryVal = propertyDetailsProperty.getValueAsByteArray(); // The below code will work for both potential property details formats (JavaV1 and .NET). String stringProperty = new String(binaryVal, 0, binaryVal.length, Constants.UTF8_CHARSET).replaceAll(" ", "").replaceAll("\"", ""); encryptedPropertyDetailsSet = new HashSet<String>( Arrays.asList(stringProperty.substring(1, stringProperty.length() - 1).split(","))); } return encryptedPropertyDetailsSet; } }
/** * 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; }
switch (property.getEdmType()) { field.addProp(SchemaConstants.JAVA_CLASS_FLAG, property.getType().getName());