Skip to content

Commit fbfc3b1

Browse files
author
Aaron Klish
committed
Fixing InMemoryStore for composite IDs
1 parent 05635c3 commit fbfc3b1

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

elide-core/src/main/java/com/yahoo/elide/core/EntityDictionary.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public class EntityDictionary {
9797
@Getter
9898
protected final Injector injector;
9999

100+
@Getter
100101
protected final Function<Class, Serde> serdeLookup ;
101102

102103
public final static String REGULAR_ID_NAME = "id";

elide-core/src/main/java/com/yahoo/elide/core/datastore/inmemory/HashMapStoreTransaction.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.yahoo.elide.request.EntityProjection;
1515
import com.yahoo.elide.request.Relationship;
1616
import com.yahoo.elide.request.Sorting;
17+
import com.yahoo.elide.utils.coerce.converters.Serde;
1718

1819
import java.io.IOException;
1920
import java.io.Serializable;
@@ -149,13 +150,17 @@ public Iterable<Object> loadObjects(EntityProjection projection,
149150
@Override
150151
public Object loadObject(EntityProjection projection, Serializable id, RequestScope scope) {
151152

153+
EntityDictionary dictionary = scope.getDictionary();
154+
152155
synchronized (dataStore) {
153156
Map<String, Object> data = dataStore.get(projection.getType());
154157
if (data == null) {
155158
return null;
156159
}
157-
Object obj = data.get(id.toString());
158-
return obj;
160+
Serde serde = dictionary.getSerdeLookup().apply(id.getClass());
161+
162+
String idString = (serde == null) ? id.toString() : (String) serde.serialize(id);
163+
return data.get(idString);
159164
}
160165
}
161166

elide-integration-tests/src/test/java/com/yahoo/elide/tests/EmbeddedIdIT.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@
3030
import com.yahoo.elide.core.EntityDictionary;
3131
import com.yahoo.elide.core.HttpStatus;
3232
import com.yahoo.elide.initialization.GraphQLIntegrationTest;
33+
import com.yahoo.elide.utils.coerce.CoerceUtil;
3334

3435
import com.google.common.collect.Sets;
3536
import example.embeddedid.Address;
3637
import example.embeddedid.AddressSerde;
3738
import example.embeddedid.Building;
39+
import org.junit.jupiter.api.BeforeAll;
3840
import org.junit.jupiter.api.BeforeEach;
39-
import org.junit.jupiter.api.Tag;
4041
import org.junit.jupiter.api.Test;
4142

4243
import lombok.Data;
@@ -45,14 +46,18 @@
4546
import java.util.Arrays;
4647
import java.util.HashMap;
4748

48-
@Tag("skipInMemory")
4949
public class EmbeddedIdIT extends GraphQLIntegrationTest {
5050

5151
protected Address address1 = new Address(0, "Bullion Blvd", 40121);
5252
protected Address address2 = new Address(1409, "W Green St", 61801);
5353
protected Address address3 = new Address(1800, "South First Street", 61820);
5454
protected AddressSerde serde = new AddressSerde();
5555

56+
@BeforeAll
57+
public void beforeAll() {
58+
CoerceUtil.register(Address.class, serde);
59+
}
60+
5661
@BeforeEach
5762
public void setup() throws IOException {
5863
dataStore.populateEntityDictionary(new EntityDictionary(new HashMap<>()));

0 commit comments

Comments
 (0)