Skip to content

Commit 0e72198

Browse files
committed
fix update in transaction
1 parent ee70c59 commit 0e72198

3 files changed

Lines changed: 1 addition & 62 deletions

File tree

src/main/java/in/kuros/jfirebase/provider/firebase/AttributeValueHelper.java

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import in.kuros.jfirebase.metadata.AttributeValue;
88
import in.kuros.jfirebase.metadata.MapAttributeValue;
99
import in.kuros.jfirebase.metadata.ValuePath;
10-
import in.kuros.jfirebase.util.CustomCollectors;
1110

1211
import java.lang.reflect.Constructor;
1312
import java.lang.reflect.Field;
@@ -39,31 +38,6 @@ public <T> T createEntity(final List<AttributeValue<T, ?>> attributeValues) {
3938
}
4039
}
4140

42-
public <T> Map<String, Object> toFieldValueMap(final List<AttributeValue<T, ?>> attributeValues) {
43-
return attributeValues
44-
.stream()
45-
.collect(CustomCollectors.toMap(
46-
attributeValue -> {
47-
if (MapAttributeValue.class.isAssignableFrom(attributeValue.getClass())) {
48-
final MapAttributeValue mapAttributeValue = (MapAttributeValue) attributeValue;
49-
if (mapAttributeValue.isKeyUpdate()) {
50-
return mapAttributeValue.getAttribute().getName() + "." + mapAttributeValue.getKey();
51-
}
52-
}
53-
return attributeValue.getAttribute().getName();
54-
},
55-
56-
attributeValue -> {
57-
if (MapAttributeValue.class.isAssignableFrom(attributeValue.getClass())) {
58-
final MapAttributeValue mapAttributeValue = (MapAttributeValue) attributeValue;
59-
if (mapAttributeValue.isKeyUpdate()) {
60-
return mapAttributeValue.getMapValue().getValue();
61-
}
62-
}
63-
return attributeValue.getAttributeValue().getValue();
64-
}));
65-
}
66-
6741
public <T> List<FieldPath> getFieldPaths(final List<AttributeValue<T, ?>> attributeValues) {
6842
return attributeValues
6943
.stream()

src/main/java/in/kuros/jfirebase/provider/firebase/WriteBatchImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public <T> void remove(final RemoveAttribute<T> removeAttribute) {
9292
@Override
9393
public <T> void update(final UpdateAttribute<T> updateAttribute) {
9494
final List<AttributeValue<T, ?>> attributeValues = UpdateAttribute.Helper.getAttributeValues(updateAttribute);
95-
final Map<String, Object> valueMap = attributeValueHelper.toFieldValueMap(attributeValues);
95+
final Map<String, Object> valueMap = attributeValueHelper.convertToObjectMap(attributeValues);
9696
attributeValueHelper.addValuePaths(valueMap, UpdateAttribute.Helper.getValuePaths(updateAttribute));
9797

9898
final String documentPath = entityHelper.getDocumentPath(UpdateAttribute.Helper.getKeys(updateAttribute));

src/test/java/in/kuros/jfirebase/provider/firebase/AttributeValueHelperTest.java

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -60,41 +60,6 @@ void shouldThrowExceptionWhenCreateEntityForGivenAttributeValuesWithoutId() {
6060
.build()));
6161
}
6262

63-
@Test
64-
void shouldConvertToFieldValueMap() {
65-
final String id = RandomStringUtils.randomAlphanumeric(3);
66-
final String value = RandomStringUtils.randomAlphanumeric(5);
67-
final String mapKey = RandomStringUtils.randomAlphanumeric(4);
68-
final String mapValue = RandomStringUtils.randomAlphanumeric(4);
69-
final List<AttributeValue<TestClass, ?>> attributeValues = AttributeValue
70-
.with(TestClass_.testId, id)
71-
.with(TestClass_.testValue, value)
72-
.with(TestClass_.testMap, mapKey, mapValue)
73-
.build();
74-
75-
final Map<String, Object> resultMap = attributeValueHelper.toFieldValueMap(attributeValues);
76-
77-
assertEquals(3, resultMap.size());
78-
assertEquals(id, resultMap.get("testId"));
79-
assertEquals(value, resultMap.get("testValue"));
80-
assertEquals(mapValue, resultMap.get("testMap." + mapKey));
81-
}
82-
83-
@Test
84-
void shouldConvertToFieldValueMapWithCompleteMapPath() {
85-
final Map<String, String> map = new HashMap<>();
86-
map.put(RandomStringUtils.randomAlphanumeric(4), RandomStringUtils.randomAlphanumeric(4));
87-
88-
final List<AttributeValue<TestClass, ?>> attributeValues = AttributeValue
89-
.with(TestClass_.testMap, map)
90-
.build();
91-
92-
final Map<String, Object> resultMap = attributeValueHelper.toFieldValueMap(attributeValues);
93-
94-
assertEquals(1, resultMap.size());
95-
assertEquals(map, resultMap.get("testMap"));
96-
}
97-
9863
@Test
9964
void shouldCreateFieldPathForAttributeValues() {
10065
final String id = RandomStringUtils.randomAlphanumeric(3);

0 commit comments

Comments
 (0)