Skip to content

Commit

Permalink
#148 added support for untyped relations
Browse files Browse the repository at this point in the history
  • Loading branch information
DirkMahler committed Apr 21, 2015
1 parent bc93805 commit 22f8985
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package com.buschmais.xo.impl.metadata;

import static com.buschmais.xo.spi.metadata.type.RelationTypeMetadata.Direction;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import com.buschmais.xo.api.XOException;
import com.buschmais.xo.spi.datastore.DatastoreEntityMetadata;
import com.buschmais.xo.spi.datastore.DatastoreRelationMetadata;
Expand All @@ -18,6 +11,13 @@
import com.buschmais.xo.spi.metadata.type.TypeMetadata;
import com.buschmais.xo.spi.reflection.AnnotatedType;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import static com.buschmais.xo.spi.metadata.type.RelationTypeMetadata.Direction;

/**
* Allows resolving types from relation discriminators as provided by the
* datastores.
Expand Down Expand Up @@ -92,14 +92,13 @@ public TypeMetadataSet<RelationTypeMetadata<RelationMetadata>> getRelationTypes(
RelationDiscriminator discriminator, Set<EntityDiscriminator> targetDiscriminators) {
TypeMetadataSet<RelationTypeMetadata<RelationMetadata>> types = new TypeMetadataSet<>();
Set<RelationMapping<EntityDiscriminator, RelationMetadata, RelationDiscriminator>> relations = relationMappings.get(discriminator);
if (relations == null) {
throw new XOException("Cannot resolve relation from discriminator '" + discriminator + "'");
}
for (RelationMapping<EntityDiscriminator, RelationMetadata, RelationDiscriminator> relation : relations) {
Set<EntityDiscriminator> source = relation.getSource();
Set<EntityDiscriminator> target = relation.getTarget();
if (sourceDiscriminators.containsAll(source) && targetDiscriminators.containsAll(target)) {
types.add(relation.getRelationType());
if (relations != null) {
for (RelationMapping<EntityDiscriminator, RelationMetadata, RelationDiscriminator> relation : relations) {
Set<EntityDiscriminator> source = relation.getSource();
Set<EntityDiscriminator> target = relation.getTarget();
if (sourceDiscriminators.containsAll(source) && targetDiscriminators.containsAll(target)) {
types.add(relation.getRelationType());
}
}
}
return types;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.buschmais.xo.neo4j.test.mapping;

import com.buschmais.xo.api.CompositeObject;
import com.buschmais.xo.api.XOManager;
import com.buschmais.xo.api.bootstrap.XOUnit;
import com.buschmais.xo.neo4j.test.AbstractNeo4jXOManagerTest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.neo4j.graphdb.Node;

import java.net.URISyntaxException;
import java.util.Collection;

import static com.buschmais.xo.api.Query.Result;
import static com.buschmais.xo.api.Query.Result.CompositeRowObject;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertThat;

@RunWith(Parameterized.class)
public class UnmappedTypesTest extends AbstractNeo4jXOManagerTest {

public UnmappedTypesTest(XOUnit xoUnit) {
super(xoUnit);
}

@Parameterized.Parameters
public static Collection<Object[]> getXOUnits() throws URISyntaxException {
return xoUnits();
}

@Test
public void query() {
XOManager xoManager = getXoManager();
xoManager.currentTransaction().begin();
Result<CompositeRowObject> result = xoManager.createQuery("CREATE (x:X)-[y:Y]->(z:Z) RETURN x, y, z").execute();
CompositeRowObject compositeRowObject = result.getSingleResult();
CompositeObject x = compositeRowObject.get("x", CompositeObject.class);
assertThat(x.getDelegate(), instanceOf(Node.class));
CompositeObject y = compositeRowObject.get("y", CompositeObject.class);
assertThat(y.getDelegate(), instanceOf(Node.class));
CompositeObject z = compositeRowObject.get("z", CompositeObject.class);
assertThat(z.getDelegate(), instanceOf(Node.class));
xoManager.currentTransaction().commit();
}

}

This file was deleted.

This file was deleted.

0 comments on commit 22f8985

Please sign in to comment.