use of com.google.storage.onestore.v3.OnestoreEntity.Index.Property in project appengine-java-standard by GoogleCloudPlatform.
the class OrderedIndexComponent method preferredIndexProperties.
@Override
public List<Property> preferredIndexProperties() {
List<Property> indexProps = Lists.newArrayListWithExpectedSize(matcherProperties.size());
for (Property prop : matcherProperties) {
if (!prop.hasDirection()) {
prop = prop.clone();
prop.setDirection(Direction.ASCENDING);
}
indexProps.add(prop);
}
return indexProps;
}
use of com.google.storage.onestore.v3.OnestoreEntity.Index.Property in project nomulus by google.
the class EntityImports method fixProperty.
private static void fixProperty(OnestoreEntity.Property property, String appId) {
OnestoreEntity.PropertyValue value = property.getMutableValue();
if (value.hasReferenceValue()) {
fixKey(value.getMutableReferenceValue(), appId);
return;
}
if (property.getMeaningEnum().equals(Meaning.ENTITY_PROTO)) {
EntityProto embeddedProto = bytesToEntityProto(value.getStringValueAsBytes());
fixEntity(embeddedProto, appId);
value.setStringValueAsBytes(embeddedProto.toByteArray());
}
}
use of com.google.storage.onestore.v3.OnestoreEntity.Index.Property in project nomulus by google.
the class EntityWrapperTest method testEquals.
@Test
void testEquals() {
// Create an entity with a key and some properties.
Entity entity = new Entity(TEST_ENTITY_KIND, ARBITRARY_KEY_ID);
// Note that we need to specify these as long for property comparisons to work because that's
// how they are deserialized from protos.
entity.setProperty("eeny", 100L);
entity.setProperty("meeny", 200L);
entity.setProperty("miney", 300L);
EntityProto proto1 = EntityTranslator.convertToPb(entity);
EntityProto proto2 = EntityTranslator.convertToPb(entity);
// Reorder the property list of proto2 (the protobuf stores this as a repeated field, so
// we just have to clear and re-add them in a different order).
ImmutableList<Property> properties = ImmutableList.of(proto2.getProperty(2), proto2.getProperty(0), proto2.getProperty(1));
proto2.clearProperty();
for (Property property : properties) {
proto2.addProperty(property);
}
// Construct entity objects from the two protos.
Entity e1 = EntityTranslator.createFromPb(proto1);
Entity e2 = EntityTranslator.createFromPb(proto2);
// Ensure that we have a normalized representation.
EntityWrapper ce1 = new EntityWrapper(e1);
EntityWrapper ce2 = new EntityWrapper(e2);
assertThat(ce1).isEqualTo(ce2);
assertThat(ce1.hashCode()).isEqualTo(ce2.hashCode());
// Ensure that the original entity is equal.
assertThat(new EntityWrapper(entity)).isEqualTo(ce1);
}
use of com.google.storage.onestore.v3.OnestoreEntity.Index.Property in project nomulus by google.
the class EntityWrapperTest method testDifferentPropertiesNotEqual.
@Test
void testDifferentPropertiesNotEqual() {
Entity entity = new Entity(TEST_ENTITY_KIND, ARBITRARY_KEY_ID);
// Note that we need to specify these as long for property comparisons to work because that's
// how they are deserialized from protos.
entity.setProperty("eeny", 100L);
entity.setProperty("meeny", 200L);
entity.setProperty("miney", 300L);
EntityProto proto1 = EntityTranslator.convertToPb(entity);
entity.setProperty("tiger!", 400);
EntityProto proto2 = EntityTranslator.convertToPb(entity);
// Construct entity objects from the two protos.
Entity e1 = EntityTranslator.createFromPb(proto1);
Entity e2 = EntityTranslator.createFromPb(proto2);
EntityWrapper ce1 = new EntityWrapper(e1);
EntityWrapper ce2 = new EntityWrapper(e2);
// The keys should still be the same.
assertThat(e1).isEqualTo(e2);
assertThat(ce1).isNotEqualTo(ce2);
assertThat(ce1.hashCode()).isNotEqualTo(ce2.hashCode());
}
use of com.google.storage.onestore.v3.OnestoreEntity.Index.Property in project nomulus by google.
the class EntityImports method fixMutationEntityProtoBytes.
private static void fixMutationEntityProtoBytes(EntityProto entityProto, String appId) {
for (OnestoreEntity.Property property : entityProto.mutableRawPropertys()) {
if (Objects.equals(property.getName(), "entityProtoBytes")) {
OnestoreEntity.PropertyValue value = property.getValue();
EntityProto fixedProto = fixEntity(bytesToEntityProto(value.getStringValueAsBytes()), appId);
value.setStringValueAsBytes(fixedProto.toByteArray());
return;
}
}
}
Aggregations