Skip to content

Commit

Permalink
Fixing InMemoryStore for composite IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Klish committed Jul 10, 2020
1 parent 05635c3 commit fbfc3b1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public class EntityDictionary {
@Getter
protected final Injector injector;

@Getter
protected final Function<Class, Serde> serdeLookup ;

public final static String REGULAR_ID_NAME = "id";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.yahoo.elide.request.EntityProjection;
import com.yahoo.elide.request.Relationship;
import com.yahoo.elide.request.Sorting;
import com.yahoo.elide.utils.coerce.converters.Serde;

import java.io.IOException;
import java.io.Serializable;
Expand Down Expand Up @@ -149,13 +150,17 @@ public Iterable<Object> loadObjects(EntityProjection projection,
@Override
public Object loadObject(EntityProjection projection, Serializable id, RequestScope scope) {

EntityDictionary dictionary = scope.getDictionary();

synchronized (dataStore) {
Map<String, Object> data = dataStore.get(projection.getType());
if (data == null) {
return null;
}
Object obj = data.get(id.toString());
return obj;
Serde serde = dictionary.getSerdeLookup().apply(id.getClass());

String idString = (serde == null) ? id.toString() : (String) serde.serialize(id);
return data.get(idString);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@
import com.yahoo.elide.core.EntityDictionary;
import com.yahoo.elide.core.HttpStatus;
import com.yahoo.elide.initialization.GraphQLIntegrationTest;
import com.yahoo.elide.utils.coerce.CoerceUtil;

import com.google.common.collect.Sets;
import example.embeddedid.Address;
import example.embeddedid.AddressSerde;
import example.embeddedid.Building;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import lombok.Data;
Expand All @@ -45,14 +46,18 @@
import java.util.Arrays;
import java.util.HashMap;

@Tag("skipInMemory")
public class EmbeddedIdIT extends GraphQLIntegrationTest {

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

@BeforeAll
public void beforeAll() {
CoerceUtil.register(Address.class, serde);
}

@BeforeEach
public void setup() throws IOException {
dataStore.populateEntityDictionary(new EntityDictionary(new HashMap<>()));
Expand Down

0 comments on commit fbfc3b1

Please sign in to comment.