merge repo branch

This commit is contained in:
Michael Hunger
2011-03-29 14:12:34 +02:00
53 changed files with 669 additions and 239 deletions

View File

@@ -99,7 +99,7 @@ For more detailed questions, use the [forum](http://forum.springsource.org/forum
public class WorldRepository {
@Autowired
private FinderFactory finderFactory;
private FinderFactory graphRepositoryFactory;
@Transactional
public Collection<World> makeSomeWorlds() {
@@ -117,31 +117,31 @@ For more detailed questions, use the [forum](http://forum.springsource.org/forum
return new World(name,moons).persist();
}
private NodeFinder<World> finder() {
return finderFactory.createNodeEntityFinder(World.class);
private NodeFinder<World> graphRepository() {
return graphRepositoryFactory.createNodeEntityFinder(World.class);
}
public World findWorldIdentifiedBy( long id ) {
return finder().findById( id );
return graphRepository().findById( id );
}
public Iterable<World> findAllWorlds() {
return finder().findAll();
return graphRepository().findAll();
}
public long countWorlds() {
return finder().count();
return graphRepository().count();
}
public World findWorldNamed( String name ) {
return finder().findByPropertyValue( null, "name", name );
return graphRepository().findByPropertyValue( null, "name", name );
}
public World findWorldWithMoons( long moonCount ) {
return finder().findByPropertyValue( "moons", "moons", moonCount );
return graphRepository().findByPropertyValue( "moons", "moons", moonCount );
}
public Iterable<World> findWorldsWithMoons( int moonCount ) {
return finder().findAllByPropertyValue( "moons", "moons", moonCount );
return graphRepository().findAllByPropertyValue( "moons", "moons", moonCount );
}
}

View File

@@ -17,9 +17,9 @@
package org.springframework.data.graph.neo4j.jpa;
import org.springframework.data.graph.core.NodeBacked;
import org.springframework.data.graph.neo4j.finder.Finder;
import org.springframework.data.graph.neo4j.finder.FinderFactory;
import org.springframework.data.graph.neo4j.finder.NodeFinder;
import org.springframework.data.graph.neo4j.repository.GraphRepository;
import org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory;
import org.springframework.data.graph.neo4j.repository.NodeGraphRepository;
import org.springframework.data.graph.neo4j.support.Tuple2;
import javax.persistence.*;
@@ -39,7 +39,7 @@ import static org.springframework.util.ObjectUtils.nullSafeEquals;
public class Neo4JQuery<T> implements TypedQuery<T> {
protected final Class<T> resultClass;
protected final String qlString;
private final FinderFactory finderFactory;
private final DirectGraphRepositoryFactory graphRepositoryFactory;
private final PersistenceUnitInfo info;
private final Pattern fromPattern = Pattern.compile("^.*\\bfrom\\s+([A-Z][A-Za-z0-9]+)\\b.*");
private int startPosition = 0;
@@ -47,38 +47,38 @@ public class Neo4JQuery<T> implements TypedQuery<T> {
private QueryExecutor<?> queryExecutor;
private Map<Parameter<?>, Tuple2<?, TemporalType>> parameters = new HashMap<Parameter<?>, Tuple2<?, TemporalType>>();
public Neo4JQuery(final String qlString, final FinderFactory finderFactory, final PersistenceUnitInfo info, Class<T> resultClass) {
public Neo4JQuery(final String qlString, final DirectGraphRepositoryFactory graphRepositoryFactory, final PersistenceUnitInfo info, Class<T> resultClass) {
this.qlString = qlString;
this.finderFactory = finderFactory;
this.graphRepositoryFactory = graphRepositoryFactory;
this.info = info;
this.resultClass = resultClass;
queryExecutor = createExecutor(qlString);
}
private QueryExecutor<T> createExecutor(final String qlString) {
final Finder<?,?> finder = getFinderFromQuery(qlString);
final GraphRepository<?,?> graphRepository = getFinderFromQuery(qlString);
if (qlString.contains(" count(")) {
return new QueryExecutor<T>() {
@Override
protected T findObject() {
return (T)Long.valueOf(finder.count());
return (T)Long.valueOf(graphRepository.count());
}
};
}
return new QueryExecutor<T>() {
@Override
protected Iterable<T> findList() {
return (Iterable<T>) finder.findAll();
return (Iterable<T>) graphRepository.findAll();
}
};
}
private NodeFinder<? extends NodeBacked> getFinderFromQuery(String qlString) {
private NodeGraphRepository<? extends NodeBacked> getFinderFromQuery(String qlString) {
final Matcher matcher = fromPattern.matcher(qlString);
if (!matcher.matches()) throw new IllegalAccessError("Unable to parse query " + qlString);
final String shortName = matcher.group(1);
final Class<? extends NodeBacked> entityClass = getEntityClass(shortName);
return finderFactory.createNodeEntityFinder(entityClass);
return graphRepositoryFactory.createNodeEntityRepository(entityClass);
}
abstract static class QueryExecutor<T> {

View File

@@ -19,7 +19,7 @@ package org.springframework.data.graph.neo4j.jpa;
import org.neo4j.graphdb.*;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.data.graph.core.NodeBacked;
import org.springframework.data.graph.neo4j.finder.FinderFactory;
import org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
import org.springframework.transaction.annotation.Transactional;
@@ -46,7 +46,7 @@ public class Neo4jEntityManager implements EntityManager {
private Map params;
private volatile boolean closed;
private final FinderFactory finderFactory;
private final DirectGraphRepositoryFactory graphRepositoryFactory;
@Resource
private EntityManagerFactory entityManagerFactory;
@@ -55,11 +55,11 @@ public class Neo4jEntityManager implements EntityManager {
this.graphDatabaseContext = graphDatabaseContext;
this.info = info;
this.params = params;
finderFactory = new FinderFactory(graphDatabaseContext);
graphRepositoryFactory = new DirectGraphRepositoryFactory(graphDatabaseContext);
}
public Neo4jEntityManager() {
finderFactory = new FinderFactory(graphDatabaseContext);
graphRepositoryFactory = new DirectGraphRepositoryFactory(graphDatabaseContext);
}
private Node nodeFor(final Object entity) {
@@ -230,7 +230,7 @@ public class Neo4jEntityManager implements EntityManager {
}
public <T> TypedQuery<T> createNeo4jQuery(final String qlString, final Class<T> entityClass) {
return new Neo4JQuery<T>(qlString, finderFactory,info,entityClass);
return new Neo4JQuery<T>(qlString, graphRepositoryFactory,info,entityClass);
}
/*

View File

@@ -112,19 +112,19 @@
<property name="nodeDelegatingFieldAccessorFactory">
<bean class="org.springframework.data.graph.neo4j.fieldaccess.NodeDelegatingFieldAccessorFactory">
<constructor-arg ref="graphDatabaseContext"/>
<constructor-arg ref="finderFactory"/>
<constructor-arg ref="graphRepositoryFactory"/>
</bean>
</property>
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="finderFactory" ref="finderFactory"/>
<property name="graphRepositoryFactory" ref="graphRepositoryFactory"/>
</bean>
<bean id="relationshipEntityStateFactory" class="org.springframework.data.graph.neo4j.fieldaccess.RelationshipEntityStateFactory">
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="finderFactory" ref="finderFactory"/>
<property name="graphRepositoryFactory" ref="graphRepositoryFactory"/>
</bean>
<bean id="finderFactory" class="org.springframework.data.graph.neo4j.finder.FinderFactory">
<bean id="graphRepositoryFactory" class="org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory">
<constructor-arg ref="graphDatabaseContext" />
</bean>

View File

@@ -30,7 +30,7 @@ import org.springframework.data.graph.neo4j.fieldaccess.Neo4jConversionServiceFa
import org.springframework.data.graph.neo4j.fieldaccess.NodeDelegatingFieldAccessorFactory;
import org.springframework.data.graph.neo4j.fieldaccess.NodeEntityStateFactory;
import org.springframework.data.graph.neo4j.fieldaccess.RelationshipEntityStateFactory;
import org.springframework.data.graph.neo4j.finder.FinderFactory;
import org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
import org.springframework.data.graph.neo4j.support.NodeTypeStrategyFactoryBean;
import org.springframework.data.graph.neo4j.support.node.Neo4jConstructorGraphEntityInstantiator;
@@ -122,31 +122,31 @@ public class Neo4jConfiguration {
}
@Bean
public FinderFactory finderFactory(GraphDatabaseContext graphDatabaseContext) throws Exception {
return new FinderFactory(graphDatabaseContext);
public DirectGraphRepositoryFactory finderFactory(GraphDatabaseContext graphDatabaseContext) throws Exception {
return new DirectGraphRepositoryFactory(graphDatabaseContext);
}
@Bean
public Neo4jRelationshipBacking neo4jRelationshipBacking(GraphDatabaseContext graphDatabaseContext, FinderFactory finderFactory) {
public Neo4jRelationshipBacking neo4jRelationshipBacking(GraphDatabaseContext graphDatabaseContext, DirectGraphRepositoryFactory graphRepositoryFactory) {
Neo4jRelationshipBacking aspect = Neo4jRelationshipBacking.aspectOf();
aspect.setGraphDatabaseContext(graphDatabaseContext);
RelationshipEntityStateFactory entityStateFactory = new RelationshipEntityStateFactory();
entityStateFactory.setGraphDatabaseContext(graphDatabaseContext);
entityStateFactory.setFinderFactory(finderFactory);
entityStateFactory.setGraphRepositoryFactory(graphRepositoryFactory);
aspect.setRelationshipEntityStateFactory(entityStateFactory);
return aspect;
}
@Bean
public Neo4jNodeBacking neo4jNodeBacking(GraphDatabaseContext graphDatabaseContext, FinderFactory finderFactory) {
public Neo4jNodeBacking neo4jNodeBacking(GraphDatabaseContext graphDatabaseContext, DirectGraphRepositoryFactory graphRepositoryFactory) {
Neo4jNodeBacking aspect = Neo4jNodeBacking.aspectOf();
aspect.setGraphDatabaseContext(graphDatabaseContext);
NodeEntityStateFactory entityStateFactory = new NodeEntityStateFactory();
entityStateFactory.setGraphDatabaseContext(graphDatabaseContext);
entityStateFactory.setFinderFactory(finderFactory);
entityStateFactory.setGraphRepositoryFactory(graphRepositoryFactory);
entityStateFactory.setEntityManagerFactory(entityManagerFactory);
entityStateFactory.setNodeDelegatingFieldAccessorFactory(
new NodeDelegatingFieldAccessorFactory(graphDatabaseContext, finderFactory));
new NodeDelegatingFieldAccessorFactory(graphDatabaseContext, graphRepositoryFactory));
aspect.setNodeEntityStateFactory(entityStateFactory);
return aspect;
}

View File

@@ -20,7 +20,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.data.graph.annotation.NodeEntity;
import org.springframework.data.graph.annotation.RelationshipEntity;
import org.springframework.data.graph.neo4j.finder.FinderFactory;
import org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
import org.springframework.util.ReflectionUtils;
@@ -34,15 +34,15 @@ public abstract class DelegatingFieldAccessorFactory<T> implements FieldAccessor
protected final GraphDatabaseContext graphDatabaseContext;
protected final FinderFactory finderFactory;
protected final DirectGraphRepositoryFactory graphRepositoryFactory;
protected abstract Collection<FieldAccessorListenerFactory<?>> createListenerFactories();
protected abstract Collection<? extends FieldAccessorFactory<?>> createAccessorFactories();
public DelegatingFieldAccessorFactory(final GraphDatabaseContext graphDatabaseContext, final FinderFactory finderFactory) {
public DelegatingFieldAccessorFactory(final GraphDatabaseContext graphDatabaseContext, final DirectGraphRepositoryFactory graphRepositoryFactory) {
this.graphDatabaseContext = graphDatabaseContext;
this.finderFactory = finderFactory;
this.graphRepositoryFactory = graphRepositoryFactory;
this.fieldAccessorFactories.addAll(createAccessorFactories());
this.fieldAccessorListenerFactories.addAll(createListenerFactories());
}

View File

@@ -17,7 +17,7 @@
package org.springframework.data.graph.neo4j.fieldaccess;
import org.springframework.data.graph.core.NodeBacked;
import org.springframework.data.graph.neo4j.finder.FinderFactory;
import org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
import java.util.Arrays;
@@ -29,8 +29,8 @@ import java.util.Collection;
*/
public class NodeDelegatingFieldAccessorFactory extends DelegatingFieldAccessorFactory<NodeBacked> {
public NodeDelegatingFieldAccessorFactory(GraphDatabaseContext graphDatabaseContext, FinderFactory finderFactory) {
super(graphDatabaseContext, finderFactory);
public NodeDelegatingFieldAccessorFactory(GraphDatabaseContext graphDatabaseContext, DirectGraphRepositoryFactory graphRepositoryFactory) {
super(graphDatabaseContext, graphRepositoryFactory);
}
@Override
@@ -54,7 +54,7 @@ public class NodeDelegatingFieldAccessorFactory extends DelegatingFieldAccessorF
new SingleRelationshipFieldAccessorFactory(graphDatabaseContext),
new OneToNRelationshipFieldAccessorFactory(graphDatabaseContext),
new ReadOnlyOneToNRelationshipFieldAccessorFactory(graphDatabaseContext),
new TraversalFieldAccessorFactory(finderFactory),
new TraversalFieldAccessorFactory(graphRepositoryFactory),
new OneToNRelationshipEntityFieldAccessorFactory(graphDatabaseContext)
);
}

View File

@@ -19,7 +19,7 @@ package org.springframework.data.graph.neo4j.fieldaccess;
import org.neo4j.graphdb.Node;
import org.springframework.data.graph.annotation.NodeEntity;
import org.springframework.data.graph.core.NodeBacked;
import org.springframework.data.graph.neo4j.finder.FinderFactory;
import org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
import javax.persistence.EntityManagerFactory;
@@ -29,7 +29,7 @@ public class NodeEntityStateFactory {
private GraphDatabaseContext graphDatabaseContext;
private FinderFactory finderFactory;
private DirectGraphRepositoryFactory graphRepositoryFactory;
private EntityManagerFactory entityManagerFactory;
@@ -38,7 +38,7 @@ public class NodeEntityStateFactory {
public EntityState<NodeBacked,Node> getEntityState(final NodeBacked entity) {
final NodeEntity graphEntityAnnotation = entity.getClass().getAnnotation(NodeEntity.class); // todo cache ??
if (graphEntityAnnotation.partial()) {
final PartialNodeEntityState<NodeBacked> partialNodeEntityState = new PartialNodeEntityState<NodeBacked>(null, entity, entity.getClass(), graphDatabaseContext, finderFactory, getPersistenceUnitUtils());
final PartialNodeEntityState<NodeBacked> partialNodeEntityState = new PartialNodeEntityState<NodeBacked>(null, entity, entity.getClass(), graphDatabaseContext, graphRepositoryFactory,getPersistenceUnitUtils());
return new DetachedEntityState<NodeBacked, Node>(partialNodeEntityState, graphDatabaseContext) {
@Override
protected boolean isDetached() {
@@ -66,8 +66,8 @@ public class NodeEntityStateFactory {
this.graphDatabaseContext = graphDatabaseContext;
}
public void setFinderFactory(FinderFactory finderFactory) {
this.finderFactory = finderFactory;
public void setGraphRepositoryFactory(DirectGraphRepositoryFactory graphRepositoryFactory) {
this.graphRepositoryFactory = graphRepositoryFactory;
}
public void setEntityManagerFactory(EntityManagerFactory entityManagerFactory) {

View File

@@ -24,7 +24,7 @@ import org.springframework.dao.InvalidDataAccessResourceUsageException;
import org.springframework.data.graph.annotation.GraphProperty;
import org.springframework.data.graph.annotation.RelatedTo;
import org.springframework.data.graph.core.NodeBacked;
import org.springframework.data.graph.neo4j.finder.FinderFactory;
import org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
import org.springframework.data.persistence.StateProvider;
@@ -45,8 +45,8 @@ public class PartialNodeEntityState<ENTITY extends NodeBacked> extends DefaultEn
private final GraphDatabaseContext graphDatabaseContext;
private PersistenceUnitUtil persistenceUnitUtil;
public PartialNodeEntityState(final Node underlyingState, final ENTITY entity, final Class<? extends ENTITY> type, final GraphDatabaseContext graphDatabaseContext, final FinderFactory finderFactory, PersistenceUnitUtil persistenceUnitUtil) {
super(underlyingState, entity, type, new DelegatingFieldAccessorFactory(graphDatabaseContext, finderFactory) {
public PartialNodeEntityState(final Node underlyingState, final ENTITY entity, final Class<? extends ENTITY> type, final GraphDatabaseContext graphDatabaseContext, final DirectGraphRepositoryFactory graphRepositoryFactory, PersistenceUnitUtil persistenceUnitUtil) {
super(underlyingState, entity, type, new DelegatingFieldAccessorFactory(graphDatabaseContext, graphRepositoryFactory) {
@Override
protected Collection<FieldAccessorListenerFactory<?>> createListenerFactories() {
@@ -78,7 +78,7 @@ public class PartialNodeEntityState<ENTITY extends NodeBacked> extends DefaultEn
},
new OneToNRelationshipFieldAccessorFactory(getGraphDatabaseContext()),
new ReadOnlyOneToNRelationshipFieldAccessorFactory(getGraphDatabaseContext()),
new TraversalFieldAccessorFactory(finderFactory),
new TraversalFieldAccessorFactory(this.graphRepositoryFactory),
new OneToNRelationshipEntityFieldAccessorFactory(getGraphDatabaseContext())
);
}

View File

@@ -20,7 +20,7 @@ import org.neo4j.graphdb.NotInTransactionException;
import org.neo4j.graphdb.Relationship;
import org.springframework.dao.InvalidDataAccessResourceUsageException;
import org.springframework.data.graph.core.RelationshipBacked;
import org.springframework.data.graph.neo4j.finder.FinderFactory;
import org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
import java.util.Arrays;
@@ -34,10 +34,10 @@ public class RelationshipEntityState<ENTITY extends RelationshipBacked> extends
private final GraphDatabaseContext graphDatabaseContext;
private final FinderFactory finderFactory;
private final DirectGraphRepositoryFactory graphRepositoryFactory;
public RelationshipEntityState(final Relationship underlyingState, final ENTITY entity, final Class<? extends ENTITY> type, final GraphDatabaseContext graphDatabaseContext, final FinderFactory finderFactory) {
super(underlyingState, entity, type, new DelegatingFieldAccessorFactory(graphDatabaseContext, finderFactory) {
public RelationshipEntityState(final Relationship underlyingState, final ENTITY entity, final Class<? extends ENTITY> type, final GraphDatabaseContext graphDatabaseContext, final DirectGraphRepositoryFactory graphRepositoryFactory) {
super(underlyingState, entity, type, new DelegatingFieldAccessorFactory(graphDatabaseContext, graphRepositoryFactory) {
@Override
protected Collection<FieldAccessorListenerFactory<?>> createListenerFactories() {
return Arrays.<FieldAccessorListenerFactory<?>>asList(
@@ -59,7 +59,7 @@ public class RelationshipEntityState<ENTITY extends RelationshipBacked> extends
}
});
this.graphDatabaseContext = graphDatabaseContext;
this.finderFactory = finderFactory;
this.graphRepositoryFactory = graphRepositoryFactory;
}
@Override

View File

@@ -18,25 +18,25 @@ package org.springframework.data.graph.neo4j.fieldaccess;
import org.neo4j.graphdb.Relationship;
import org.springframework.data.graph.core.RelationshipBacked;
import org.springframework.data.graph.neo4j.finder.FinderFactory;
import org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
public class RelationshipEntityStateFactory {
private GraphDatabaseContext graphDatabaseContext;
private FinderFactory finderFactory;
private DirectGraphRepositoryFactory graphRepositoryFactory;
public EntityState<RelationshipBacked, Relationship> getEntityState(final RelationshipBacked entity) {
return new RelationshipEntityState<RelationshipBacked>(null,entity,entity.getClass(), graphDatabaseContext, finderFactory);
return new RelationshipEntityState<RelationshipBacked>(null,entity,entity.getClass(), graphDatabaseContext, graphRepositoryFactory);
}
public void setGraphDatabaseContext(GraphDatabaseContext graphDatabaseContext) {
this.graphDatabaseContext = graphDatabaseContext;
}
public void setFinderFactory(FinderFactory finderFactory) {
this.finderFactory = finderFactory;
public void setGraphRepositoryFactory(DirectGraphRepositoryFactory graphRepositoryFactory) {
this.graphRepositoryFactory = graphRepositoryFactory;
}
}

View File

@@ -21,8 +21,8 @@ import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.graph.annotation.GraphTraversal;
import org.springframework.data.graph.core.FieldTraversalDescriptionBuilder;
import org.springframework.data.graph.core.NodeBacked;
import org.springframework.data.graph.neo4j.finder.FinderFactory;
import org.springframework.data.graph.neo4j.finder.NodeFinder;
import org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory;
import org.springframework.data.graph.neo4j.repository.NodeGraphRepository;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
@@ -31,12 +31,12 @@ import static org.springframework.data.graph.neo4j.fieldaccess.DoReturn.doReturn
public class TraversalFieldAccessorFactory implements FieldAccessorFactory<NodeBacked> {
private FinderFactory finderFactory;
private DirectGraphRepositoryFactory graphRepositoryFactory;
public TraversalFieldAccessorFactory(FinderFactory finderFactory) {
public TraversalFieldAccessorFactory(DirectGraphRepositoryFactory graphRepositoryFactory) {
super();
this.finderFactory = finderFactory;
this.graphRepositoryFactory = graphRepositoryFactory;
}
@@ -51,7 +51,7 @@ public class TraversalFieldAccessorFactory implements FieldAccessorFactory<NodeB
@Override
public FieldAccessor<NodeBacked> forField(final Field field) {
return new TraversalFieldAccessor(field, finderFactory);
return new TraversalFieldAccessor(field, graphRepositoryFactory);
}
/**
@@ -60,14 +60,14 @@ public class TraversalFieldAccessorFactory implements FieldAccessorFactory<NodeB
*/
public static class TraversalFieldAccessor implements FieldAccessor<NodeBacked> {
protected final Field field;
private final FinderFactory finderFactory;
private final DirectGraphRepositoryFactory graphRepositoryFactory;
private final FieldTraversalDescriptionBuilder fieldTraversalDescriptionBuilder;
private Class<? extends NodeBacked> target;
protected String[] params;
public TraversalFieldAccessor(final Field field, FinderFactory finderFactory) {
public TraversalFieldAccessor(final Field field, DirectGraphRepositoryFactory graphRepositoryFactory) {
this.field = field;
this.finderFactory = finderFactory;
this.graphRepositoryFactory = graphRepositoryFactory;
final GraphTraversal graphEntityTraversal = field.getAnnotation(GraphTraversal.class);
this.target = graphEntityTraversal.elementClass();
this.params = graphEntityTraversal.params();
@@ -86,7 +86,7 @@ public class TraversalFieldAccessorFactory implements FieldAccessorFactory<NodeB
@Override
public Object getValue(final NodeBacked nodeBacked) {
final NodeFinder<? extends NodeBacked> finder = finderFactory.createNodeEntityFinder(target);
final NodeGraphRepository<? extends NodeBacked> finder = graphRepositoryFactory.createNodeEntityRepository(target);
final TraversalDescription traversalDescription = fieldTraversalDescriptionBuilder.build(nodeBacked,field,params);
return doReturn(finder.findAllByTraversal(nodeBacked, traversalDescription));
}

View File

@@ -1,4 +1,4 @@
package org.springframework.data.graph.neo4j.finder;
package org.springframework.data.graph.neo4j.repository;
import org.apache.lucene.search.NumericRangeQuery;
import org.neo4j.graphdb.NotFoundException;
@@ -6,10 +6,16 @@ import org.neo4j.graphdb.PropertyContainer;
import org.neo4j.graphdb.index.Index;
import org.neo4j.graphdb.index.IndexHits;
import org.neo4j.helpers.collection.IterableWrapper;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.graph.core.GraphBacked;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Repository like finder for Node and Relationship-Entities. Provides finder methods for direct access, access via {@link org.springframework.data.graph.core.TypeRepresentationStrategy}
@@ -18,14 +24,15 @@ import java.util.Collections;
* @param <T> GraphBacked target of this finder, enables the finder methods to return this concrete type
* @param <S> Type of backing state, either Node or Relationship
*/
public abstract class AbstractFinder<S extends PropertyContainer, T extends GraphBacked<S>> implements Finder<S, T> {
@org.springframework.stereotype.Repository
public abstract class AbstractGraphRepository<S extends PropertyContainer, T extends GraphBacked<S>> implements GraphRepository<S, T>, CRUDGraphRepository<S,T> {
/**
* Target graphbacked type
*/
protected final Class<T> clazz;
protected final GraphDatabaseContext graphDatabaseContext;
public AbstractFinder(final GraphDatabaseContext graphDatabaseContext, final Class<T> clazz) {
public AbstractGraphRepository(final GraphDatabaseContext graphDatabaseContext, final Class<T> clazz) {
this.graphDatabaseContext = graphDatabaseContext;
this.clazz = clazz;
}
@@ -34,7 +41,7 @@ public abstract class AbstractFinder<S extends PropertyContainer, T extends Grap
* @return Number of instances of the target type in the graph.
*/
@Override
public long count() {
public Long count() {
return graphDatabaseContext.count(clazz);
}
@@ -47,11 +54,12 @@ public abstract class AbstractFinder<S extends PropertyContainer, T extends Grap
}
/**
*
* @param id id
* @return Entity with the given id or null.
*/
@Override
public T findById(final long id) {
public T findOne(final Long id) {
try {
return createEntity(getById(id));
} catch (NotFoundException e) {
@@ -162,4 +170,44 @@ public abstract class AbstractFinder<S extends PropertyContainer, T extends Grap
}
protected abstract S getById(long id);
@Override
public boolean exists(Long id) {
return getById(id)!=null;
}
@Override
public void delete(T entity) {
entity.remove();
}
@Override
public void delete(Iterable<? extends T> entities) {
for (T entity : entities) {
entity.remove();
}
}
@Override
public void deleteAll() {
delete(findAll());
}
@Override
public Iterable<T> findAll(Sort sort) {
return findAll(); // todo
}
@Override
public Page<T> findAll(final Pageable pageable) {
int count = pageable.getOffset()+pageable.getPageSize();
Iterable<T> all = findAll(pageable.getSort());
List<T> result=new ArrayList<T>(count);
for (T t : all) {
if (count == 0) break;
result.add(t);
count--;
}
return new PageImpl<T>(result,pageable,result.size());
}
}

View File

@@ -0,0 +1,57 @@
package org.springframework.data.graph.neo4j.repository;
import org.neo4j.graphdb.PropertyContainer;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.graph.core.GraphBacked;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
import java.util.List;
/**
* @author mh
* @since 28.03.11
*/
public interface CRUDGraphRepository<S extends PropertyContainer, T extends GraphBacked<S>> extends PagingAndSortingRepository<T, Long> {
@Transactional
T save(T entity);
@Transactional
Iterable<T> save(Iterable<? extends T> entities);
T findOne(Long id);
boolean exists(Long id);
Iterable<T> findAll();
Long count();
@Transactional
void delete(T entity);
@Transactional
void delete(Iterable<? extends T> entities);
@Transactional
void deleteAll();
Iterable<T> findAll(Sort sort);
Page<T> findAll(Pageable pageable);
}

View File

@@ -14,17 +14,16 @@
* limitations under the License.
*/
package org.springframework.data.graph.neo4j.finder;
package org.springframework.data.graph.neo4j.repository;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.traversal.TraversalDescription;
import org.springframework.data.graph.core.GraphBacked;
import org.springframework.data.graph.core.NodeBacked;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
public class NodeFinder<T extends GraphBacked<Node>> extends AbstractFinder<Node, T> {
public class DefaultNodeGraphRepository<T extends NodeBacked> extends AbstractGraphRepository<Node, T> implements NodeGraphRepository<T> {
public NodeFinder(final Class<T> clazz, final GraphDatabaseContext graphDatabaseContext) {
public DefaultNodeGraphRepository(final Class<T> clazz, final GraphDatabaseContext graphDatabaseContext) {
super(graphDatabaseContext, clazz);
}
@@ -37,5 +36,18 @@ public class NodeFinder<T extends GraphBacked<Node>> extends AbstractFinder<Node
public <N extends NodeBacked> Iterable<T> findAllByTraversal(final N startNode, final TraversalDescription traversalDescription) {
return (Iterable<T>) startNode.findAllByTraversal((Class<? extends NodeBacked>) clazz, traversalDescription);
}
@Override
public T save(T entity) {
return (T) ((NodeBacked)entity).persist();
}
@Override
public Iterable<T> save(Iterable<? extends T> entities) {
for (T entity : entities) {
save(entity);
}
return (Iterable<T>) entities;
}
}

View File

@@ -14,18 +14,17 @@
* limitations under the License.
*/
package org.springframework.data.graph.neo4j.finder;
package org.springframework.data.graph.neo4j.repository;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.index.Index;
import org.neo4j.graphdb.traversal.TraversalDescription;
import org.springframework.data.graph.core.NodeBacked;
import org.springframework.data.graph.core.RelationshipBacked;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
public class RelationshipFinder<T extends RelationshipBacked> extends AbstractFinder<Relationship, T> {
public class DefaultRelationshipGraphRepository<T extends RelationshipBacked> extends AbstractGraphRepository<Relationship, T> implements RelationshipGraphRepository<T> {
public RelationshipFinder(final Class<T> clazz, final GraphDatabaseContext graphDatabaseContext) {
public DefaultRelationshipGraphRepository(final Class<T> clazz, final GraphDatabaseContext graphDatabaseContext) {
super(graphDatabaseContext, clazz);
}
@@ -38,5 +37,15 @@ public class RelationshipFinder<T extends RelationshipBacked> extends AbstractFi
public <N extends NodeBacked> Iterable<T> findAllByTraversal(final N startNode, final TraversalDescription traversalDescription) {
throw new UnsupportedOperationException("Traversal not able to start at relationship");
}
@Override
public T save(T entity) {
return entity;
}
@Override
public Iterable<T> save(Iterable<? extends T> entities) {
return (Iterable<T>) entities;
}
}

View File

@@ -14,29 +14,29 @@
* limitations under the License.
*/
package org.springframework.data.graph.neo4j.finder;
package org.springframework.data.graph.neo4j.repository;
import org.springframework.data.graph.core.NodeBacked;
import org.springframework.data.graph.core.RelationshipBacked;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
/**
* Simple Factory for {@link NodeFinder} instances.
* Simple Factory for {@link DefaultNodeGraphRepository} instances.
*/
public class FinderFactory {
public class DirectGraphRepositoryFactory {
private final GraphDatabaseContext graphDatabaseContext;
public FinderFactory(final GraphDatabaseContext graphDatabaseContext) {
public DirectGraphRepositoryFactory(final GraphDatabaseContext graphDatabaseContext) {
this.graphDatabaseContext = graphDatabaseContext;
}
public <T extends NodeBacked> NodeFinder<T> createNodeEntityFinder(Class<T> clazz) {
return new NodeFinder<T>(clazz, graphDatabaseContext);
public <T extends NodeBacked> NodeGraphRepository<T> createNodeEntityRepository(Class<T> clazz) {
return new DefaultNodeGraphRepository<T>(clazz, graphDatabaseContext);
}
public <T extends RelationshipBacked> RelationshipFinder<T> createRelationshipEntityFinder(Class<T> clazz) {
return new RelationshipFinder<T>(clazz, graphDatabaseContext);
public <T extends RelationshipBacked> RelationshipGraphRepository<T> createRelationshipEntityRepository(Class<T> clazz) {
return new DefaultRelationshipGraphRepository<T>(clazz, graphDatabaseContext);
}
}

View File

@@ -0,0 +1,17 @@
package org.springframework.data.graph.neo4j.repository;
import org.neo4j.graphdb.PropertyContainer;
import org.springframework.data.graph.core.GraphBacked;
import org.springframework.data.repository.support.EntityInformation;
import java.io.Serializable;
/**
* @author mh
* @since 28.03.11
*/
public interface GraphEntityInformation<S extends PropertyContainer, T extends GraphBacked<S>> extends EntityInformation<T, Long> {
boolean isNodeEntity();
boolean isPartialEntity();
}

View File

@@ -0,0 +1,55 @@
package org.springframework.data.graph.neo4j.repository;
/**
* @author mh
* @since 28.03.11
*/
import org.neo4j.graphdb.PropertyContainer;
import org.springframework.data.graph.annotation.NodeEntity;
import org.springframework.data.graph.core.GraphBacked;
import org.springframework.data.graph.core.NodeBacked;
import org.springframework.data.graph.core.RelationshipBacked;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
import org.springframework.data.repository.support.AbstractEntityInformation;
public class GraphMetamodelEntityInformation<S extends PropertyContainer, T extends GraphBacked<S>> extends AbstractEntityInformation<T,Long> implements GraphEntityInformation<S,T> {
private final boolean isNodeEntity;
private final boolean isPartialEntity;
private GraphDatabaseContext graphDatabaseContext;
public GraphMetamodelEntityInformation(Class domainClass, GraphDatabaseContext graphDatabaseContext) {
super(domainClass);
this.graphDatabaseContext = graphDatabaseContext;
NodeEntity nodeEntity = getJavaType().getAnnotation(NodeEntity.class);
isNodeEntity = nodeEntity!=null;
isPartialEntity = isNodeEntity && nodeEntity.partial();
}
@Override
public boolean isNodeEntity() {
return isNodeEntity;
}
@Override
public boolean isPartialEntity() {
return isPartialEntity;
}
@Override
public boolean isNew(T entity) {
return entity.hasPersistentState();
}
@Override
public Long getId(T entity) {
return isNodeEntity() ? ((NodeBacked)entity).getNodeId() : ((RelationshipBacked)entity).getRelationshipId();
}
@Override
public Class<Long> getIdType() {
return Long.class;
}
}

View File

@@ -0,0 +1,12 @@
package org.springframework.data.graph.neo4j.repository;
import org.neo4j.graphdb.PropertyContainer;
import org.springframework.data.graph.core.GraphBacked;
/**
* @author mh
* @since 12.01.11
*/
public interface GraphRepository<S extends PropertyContainer,T extends GraphBacked<S>> extends CRUDGraphRepository<S,T>, IndexQueryExecutor<S,T>, TraversalQueryExecutor<S,T> {
}

View File

@@ -0,0 +1,91 @@
package org.springframework.data.graph.neo4j.repository;
import org.springframework.data.graph.annotation.NodeEntity;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.QueryLookupStrategy;
import org.springframework.data.repository.query.RepositoryQuery;
import org.springframework.data.repository.support.EntityInformation;
import org.springframework.data.repository.support.RepositoryFactorySupport;
import org.springframework.data.repository.support.RepositoryMetadata;
import org.springframework.util.Assert;
import java.io.Serializable;
import java.lang.reflect.Method;
import static org.springframework.core.GenericTypeResolver.resolveTypeArguments;
/**
* @author mh
* @since 28.03.11
*/
public class GraphRepositoryFactory extends RepositoryFactorySupport {
private final GraphDatabaseContext graphDatabaseContext;
public GraphRepositoryFactory(GraphDatabaseContext graphDatabaseContext) {
Assert.notNull(graphDatabaseContext);
this.graphDatabaseContext = graphDatabaseContext;
}
/*
* (non-Javadoc)
*
* @see
* org.springframework.data.repository.support.RepositoryFactorySupport#
* getTargetRepository(java.lang.Class)
*/
@Override
protected Object getTargetRepository(RepositoryMetadata metadata) {
return getTargetRepository(metadata, graphDatabaseContext);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
protected Object getTargetRepository(RepositoryMetadata metadata, GraphDatabaseContext graphDatabaseContext) {
Class<?> repositoryInterface = metadata.getRepositoryInterface();
Class<?> type = metadata.getDomainClass();
GraphEntityInformation entityInformation = (GraphEntityInformation)getEntityInformation(type);
if (entityInformation.isNodeEntity()) {
return new DefaultNodeGraphRepository(type,graphDatabaseContext);
} else {
return new DefaultRelationshipGraphRepository(type,graphDatabaseContext);
}
}
private static Class<?> getDomainClass(Class repositoryInterface) {
Class<?>[] arguments = resolveTypeArguments(repositoryInterface, Repository.class);
return arguments == null ? null : arguments[0];
}
@Override
protected Class<?> getRepositoryBaseClass(Class<?> repositoryInterface) {
Class<?> domainClass = getDomainClass(repositoryInterface);
if (domainClass.isAnnotationPresent(NodeEntity.class)) {
return DefaultNodeGraphRepository.class;
} else {
return DefaultRelationshipGraphRepository.class;
}
}
@Override
@SuppressWarnings({"unchecked"})
public <T, ID extends Serializable> EntityInformation<T, ID> getEntityInformation(Class<T> type) {
return new GraphMetamodelEntityInformation(type,graphDatabaseContext);
}
@Override
protected QueryLookupStrategy getQueryLookupStrategy(QueryLookupStrategy.Key key) {
return new QueryLookupStrategy(){
@Override
public RepositoryQuery resolveQuery(Method method, Class<?> domainClass) {
return null;
}
};
}
}

View File

@@ -0,0 +1,41 @@
package org.springframework.data.graph.neo4j.repository;
import org.neo4j.graphdb.PropertyContainer;
import org.springframework.data.graph.core.GraphBacked;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
import org.springframework.data.repository.support.RepositoryFactorySupport;
import org.springframework.data.repository.support.TransactionalRepositoryFactoryBeanSupport;
import org.springframework.util.Assert;
/**
* @author mh
* @since 28.03.11
*/
public class GraphRepositoryFactoryBean<S extends PropertyContainer, R extends CRUDGraphRepository<S,T>, T extends GraphBacked<S>>
extends TransactionalRepositoryFactoryBeanSupport<R, T, Long> {
private GraphDatabaseContext graphDatabaseContext;
public void setGraphDatabaseContext(GraphDatabaseContext graphDatabaseContext) {
this.graphDatabaseContext = graphDatabaseContext;
}
@Override
protected RepositoryFactorySupport doCreateRepositoryFactory() {
return createRepositoryFactory(graphDatabaseContext);
}
protected RepositoryFactorySupport createRepositoryFactory(GraphDatabaseContext graphDatabaseContext) {
return new GraphRepositoryFactory(graphDatabaseContext);
}
@Override
public void afterPropertiesSet() {
Assert.notNull(graphDatabaseContext, "GraphDatabaseContext must not be null!");
super.afterPropertiesSet();
}
}

View File

@@ -0,0 +1,18 @@
package org.springframework.data.graph.neo4j.repository;
import org.neo4j.graphdb.PropertyContainer;
import org.springframework.data.graph.core.GraphBacked;
/**
* @author mh
* @since 29.03.11
*/
public interface IndexQueryExecutor<S extends PropertyContainer,T extends GraphBacked<S>> {
T findByPropertyValue(String indexName, String property, Object value);
Iterable<T> findAllByPropertyValue(String indexName, String property, Object value);
Iterable<T> findAllByQuery(String indexName, String key, Object query);
Iterable<T> findAllByRange(String indexName, String property, Number from, Number to);
}

View File

@@ -0,0 +1,11 @@
package org.springframework.data.graph.neo4j.repository;
import org.neo4j.graphdb.Node;
import org.springframework.data.graph.core.NodeBacked;
/**
* @author mh
* @since 29.03.11
*/
public interface NodeGraphRepository<T extends NodeBacked> extends GraphRepository<Node,T> {
}

View File

@@ -0,0 +1,11 @@
package org.springframework.data.graph.neo4j.repository;
import org.neo4j.graphdb.Relationship;
import org.springframework.data.graph.core.RelationshipBacked;
/**
* @author mh
* @since 29.03.11
*/
public interface RelationshipGraphRepository<T extends RelationshipBacked> extends GraphRepository<Relationship, T> {
}

View File

@@ -1,4 +1,4 @@
package org.springframework.data.graph.neo4j.finder;
package org.springframework.data.graph.neo4j.repository;
import org.neo4j.graphdb.PropertyContainer;
import org.neo4j.graphdb.traversal.TraversalDescription;
@@ -7,21 +7,9 @@ import org.springframework.data.graph.core.NodeBacked;
/**
* @author mh
* @since 12.01.11
* @since 29.03.11
*/
public interface Finder<S extends PropertyContainer,T extends GraphBacked<S>> {
long count();
Iterable<T> findAll();
T findById(long id);
T findByPropertyValue(String indexName, String property, Object value);
Iterable<T> findAllByPropertyValue(String indexName, String property, Object value);
Iterable<T> findAllByQuery(final String indexName, String key, final Object query);
Iterable<T> findAllByRange(final String indexName, final String property, final Number from, final Number to);
public interface TraversalQueryExecutor<S extends PropertyContainer,T extends GraphBacked<S>> {
/**
* Traversal based finder that returns a lazy Iterable over the traversal results
*

View File

@@ -18,7 +18,7 @@ import java.util.Collection;
* <pre>
* class MyInitializer extends SpringPluginInitializer {
* public MyInitializer() {
* super(new String[]{"myContext.xml"},"finderFactory","myRepository");
* super(new String[]{"myContext.xml"},"graphRepositoryFactory","myRepository");
* }
* }
* </pre>

View File

@@ -0,0 +1,10 @@
package org.springframework.data.graph.neo4j;
import org.springframework.data.graph.neo4j.repository.NodeGraphRepository;
/**
* @author mh
* @since 29.03.11
*/
public interface GroupRepository extends NodeGraphRepository<Group> {
}

View File

@@ -0,0 +1,10 @@
package org.springframework.data.graph.neo4j;
import org.springframework.data.graph.neo4j.repository.NodeGraphRepository;
/**
* @author mh
* @since 29.03.11
*/
public interface PersonRepository extends NodeGraphRepository<Person> {
}

View File

@@ -1,18 +1,13 @@
package org.springframework.data.graph.neo4j.config;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.kernel.EmbeddedGraphDatabase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.graph.neo4j.finder.FinderFactory;
import org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.PlatformTransactionManager;
/**
@@ -26,7 +21,7 @@ public class DataGraphNamespaceHandlerTest {
@Autowired
GraphDatabaseService graphDatabaseService;
@Autowired
FinderFactory finderFactory;
DirectGraphRepositoryFactory graphRepositoryFactory;
@Autowired
GraphDatabaseContext graphDatabaseContext;
@Autowired
@@ -59,7 +54,7 @@ public class DataGraphNamespaceHandlerTest {
Assert.assertNotNull("graphDatabaseContext", graphDatabaseContext);
EmbeddedGraphDatabase graphDatabaseService = (EmbeddedGraphDatabase) graphDatabaseContext.getGraphDatabaseService();
Assert.assertEquals("store-dir", "target/config-test", graphDatabaseService.getStoreDir());
Assert.assertNotNull("finderFactory",config.finderFactory);
Assert.assertNotNull("graphRepositoryFactory",config.graphRepositoryFactory);
Assert.assertNotNull("graphDatabaseService",config.graphDatabaseService);
Assert.assertNotNull("transactionManager",config.transactionManager);
config.graphDatabaseService.shutdown();

View File

@@ -8,7 +8,7 @@ import org.neo4j.graphdb.Node;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.graph.core.NodeBacked;
import org.springframework.data.graph.neo4j.Developer;
import org.springframework.data.graph.neo4j.finder.FinderFactory;
import org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -25,17 +25,17 @@ public class AttachEntityTest {
protected final Log log = LogFactory.getLog(getClass());
@Autowired
private FinderFactory finderFactory;
private DirectGraphRepositoryFactory graphRepositoryFactory;
@Test
@Transactional
public void entityShouldHaveNoNode() {
Developer dev = new Developer("Michael");
assertFalse(hasUnderlyingNode(dev));
assertFalse(hasPersistentState(dev));
assertNull(nodeFor(dev));
}
private boolean hasUnderlyingNode(NodeBacked nodeBacked) {
private boolean hasPersistentState(NodeBacked nodeBacked) {
return nodeBacked.hasPersistentState();
}

View File

@@ -2,19 +2,19 @@ package org.springframework.data.graph.neo4j.support;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hamcrest.Matcher;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.internal.matchers.IsCollectionContaining;
import org.junit.runner.RunWith;
import org.neo4j.helpers.collection.IteratorUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.graph.neo4j.Group;
import org.springframework.data.graph.neo4j.GroupRepository;
import org.springframework.data.graph.neo4j.Person;
import static org.springframework.data.graph.neo4j.Person.persistedPerson;
import org.springframework.data.graph.neo4j.finder.FinderFactory;
import org.springframework.data.graph.neo4j.finder.NodeFinder;
import org.springframework.data.graph.neo4j.PersonRepository;
import org.springframework.data.graph.neo4j.support.node.Neo4jHelper;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.BeforeTransaction;
@@ -24,7 +24,13 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import static java.util.Arrays.asList;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.internal.matchers.IsCollectionContaining.hasItems;
import static org.neo4j.helpers.collection.IteratorUtil.asCollection;
import static org.springframework.data.graph.neo4j.Person.persistedPerson;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:org/springframework/data/graph/neo4j/support/Neo4jGraphPersistenceTest-context.xml"})
@@ -36,8 +42,10 @@ public class FinderTest {
@Autowired
private GraphDatabaseContext graphDatabaseContext;
@Autowired
private FinderFactory finderFactory;
@Autowired
private PersonRepository personRepository;
@Autowired
private GroupRepository groupRepository;
@BeforeTransaction
public void cleanDb() {
@@ -49,17 +57,48 @@ public class FinderTest {
public void testFinderFindAll() {
Person p1 = persistedPerson("Michael", 35);
Person p2 = persistedPerson("David", 25);
NodeFinder<Person> finder = finderFactory.createNodeEntityFinder(Person.class);
Iterable<Person> allPersons = finder.findAll();
assertEquals(new HashSet<Person>(Arrays.asList(p1, p2)), IteratorUtil.addToCollection(allPersons.iterator(), new HashSet<Person>()));
Iterable<Person> allPersons = personRepository.findAll();
assertThat(asCollection(allPersons), hasItems(p1, p2));
}
@Test
@Transactional
public void testSaveManyPeople() {
Person p1 = new Person("Michael", 35);
Person p2 = new Person("David", 25);
personRepository.save(asList(p1,p2));
assertEquals("persisted person 1",true,p1.hasPersistentState());
assertEquals("persisted person 2",true,p2.hasPersistentState());
assertThat(asCollection(personRepository.findAll()), hasItems(p2, p1));
}
@Test
@Transactional
public void testSavePerson() {
Person p1 = new Person("Michael", 35);
personRepository.save(p1);
assertEquals("persisted person",true,p1.hasPersistentState());
assertThat(personRepository.findOne(p1.getId()),is(p1));
}
@Test
public void testDeletePerson() {
Person p1 = persistedPerson("Michael", 35);
personRepository.delete(p1);
assertEquals("people deleted", false, personRepository.findAll().iterator().hasNext());
}
@Test
public void testDeletePeople() {
Person p1 = persistedPerson("Michael", 35);
Person p2 = persistedPerson("David", 26);
personRepository.delete(asList(p1,p2));
assertEquals("people deleted", false, personRepository.findAll().iterator().hasNext());
}
@Test
@Transactional
public void testFinderFindById() {
Person p = persistedPerson("Michael", 35);
NodeFinder<Person> finder = finderFactory.createNodeEntityFinder(Person.class);
Person pById = finder.findById(p.getNodeId());
Person pById = personRepository.findOne(p.getNodeId());
assertEquals(p, pById);
}
@@ -67,19 +106,18 @@ public class FinderTest {
@Transactional
public void testFinderFindByIdNonexistent() {
Person p = persistedPerson("Michael", 35);
NodeFinder<Person> finder = finderFactory.createNodeEntityFinder(Person.class);
Person p2 = finder.findById(589736218);
Person p2 = personRepository.findOne(589736218L);
Assert.assertNull(p2);
}
@Test
@Transactional
public void testFinderCount() {
NodeFinder<Person> finder = finderFactory.createNodeEntityFinder(Person.class);
assertEquals(0, finder.count());
assertEquals((Long)0L, personRepository.count());
Person p = persistedPerson("Michael", 35);
assertEquals(1, finder.count());
assertEquals((Long)1L, personRepository.count());
}
@Test
@Transactional
public void testFindAllOnGroup() {
@@ -88,8 +126,7 @@ public class FinderTest {
g.setName("test");
Group g2 = new Group().persist();
g.setName("test");
final NodeFinder<Group> finder = finderFactory.createNodeEntityFinder(Group.class);
Collection<Group> groups = IteratorUtil.addToCollection(finder.findAll().iterator(), new HashSet<Group>());
Collection<Group> groups = IteratorUtil.addToCollection(groupRepository.findAll().iterator(), new HashSet<Group>());
Assert.assertEquals(2, groups.size());
log.debug("FindAllOnGroup done");
}

View File

@@ -4,7 +4,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.neo4j.graphdb.DynamicRelationshipType;
@@ -19,9 +18,9 @@ import org.springframework.data.graph.annotation.NodeEntity;
import org.springframework.data.graph.neo4j.Friendship;
import org.springframework.data.graph.neo4j.Group;
import org.springframework.data.graph.neo4j.Person;
import org.springframework.data.graph.neo4j.finder.FinderFactory;
import org.springframework.data.graph.neo4j.finder.NodeFinder;
import org.springframework.data.graph.neo4j.finder.RelationshipFinder;
import org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory;
import org.springframework.data.graph.neo4j.repository.NodeGraphRepository;
import org.springframework.data.graph.neo4j.repository.RelationshipGraphRepository;
import org.springframework.data.graph.neo4j.support.node.Neo4jHelper;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -49,14 +48,14 @@ public class IndexTest {
private GraphDatabaseContext graphDatabaseContext;
@Autowired
private FinderFactory finderFactory;
protected NodeFinder<Group> groupFinder;
protected NodeFinder<Person> personFinder;
private DirectGraphRepositoryFactory graphRepositoryFactory;
protected NodeGraphRepository<Group> groupFinder;
protected NodeGraphRepository<Person> personFinder;
@Before
public void setUp() throws Exception {
groupFinder = finderFactory.createNodeEntityFinder(Group.class);
personFinder = finderFactory.createNodeEntityFinder(Person.class);
groupFinder = graphRepositoryFactory.createNodeEntityRepository(Group.class);
personFinder = graphRepositoryFactory.createNodeEntityRepository(Person.class);
}
@BeforeTransaction
@@ -71,7 +70,7 @@ public class IndexTest {
Person p2 = persistedPerson(NAME_VALUE2, 25);
Friendship friendship = p.knows(p2);
friendship.setYears(1);
RelationshipFinder<Friendship> friendshipFinder = finderFactory.createRelationshipEntityFinder(Friendship.class);
RelationshipGraphRepository<Friendship> friendshipFinder = graphRepositoryFactory.createRelationshipEntityRepository(Friendship.class);
assertEquals(friendship, friendshipFinder.findByPropertyValue(null, "Friendship.years", 1));
}

View File

@@ -10,8 +10,8 @@ import org.neo4j.graphdb.Node;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.graph.neo4j.Group;
import org.springframework.data.graph.neo4j.Person;
import org.springframework.data.graph.neo4j.finder.FinderFactory;
import org.springframework.data.graph.neo4j.finder.NodeFinder;
import org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory;
import org.springframework.data.graph.neo4j.repository.NodeGraphRepository;
import org.springframework.data.graph.neo4j.support.node.Neo4jHelper;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -37,7 +37,7 @@ public class ModificationOutsideOfTransactionTest
private GraphDatabaseContext graphDatabaseContext;
@Autowired
private FinderFactory finderFactory;
private DirectGraphRepositoryFactory graphRepositoryFactory;
@Before
public void cleanDb() {
@@ -49,7 +49,7 @@ public class ModificationOutsideOfTransactionTest
assertEquals(35, p.getAge());
p.setAge(36);
assertEquals(36, p.getAge());
assertFalse(hasUnderlyingNode(p));
assertFalse(hasPersistentState(p));
p.persist();
assertEquals(36, nodeFor(p).getProperty("Person.age"));
}
@@ -63,8 +63,8 @@ public class ModificationOutsideOfTransactionTest
michael.setBoss(emil);
assertEquals(emil, michael.getBoss());
assertFalse(hasUnderlyingNode(michael));
assertFalse(hasUnderlyingNode(emil));
assertFalse(hasPersistentState(michael));
assertFalse(hasPersistentState(emil));
michael.persist();
assertThat(nodeFor(michael), hasRelationship("boss", nodeFor(emil)));
assertThat(nodeFor(emil), hasRelationship("boss", nodeFor(michael)));
@@ -80,8 +80,8 @@ public class ModificationOutsideOfTransactionTest
michael.setBoss(emil);
assertEquals(emil, michael.getBoss());
assertFalse(hasUnderlyingNode(michael));
assertFalse(hasUnderlyingNode(emil));
assertFalse(hasPersistentState(michael));
assertFalse(hasPersistentState(emil));
emil.persist();
assertThat(nodeFor(michael), hasRelationship("boss", nodeFor(emil)));
assertThat(nodeFor(emil), hasRelationship("boss", nodeFor(michael)));
@@ -159,7 +159,7 @@ public class ModificationOutsideOfTransactionTest
assertEquals( spouse2, p.getSpouse() );
}
private boolean hasUnderlyingNode( Person person )
private boolean hasPersistentState( Person person )
{
return person.hasPersistentState();
}
@@ -179,7 +179,7 @@ public class ModificationOutsideOfTransactionTest
@Test
public void testFindOutsideTransaction()
{
final NodeFinder<Person> finder = finderFactory.createNodeEntityFinder( Person.class );
final NodeGraphRepository<Person> finder = graphRepositoryFactory.createNodeEntityRepository(Person.class);
assertEquals( false, finder.findAll().iterator().hasNext() );
}

View File

@@ -2,18 +2,13 @@ package org.springframework.data.graph.neo4j.support;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.NotFoundException;
import org.neo4j.graphdb.Transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.graph.core.NodeBacked;
import org.springframework.data.graph.neo4j.Group;
import org.springframework.data.graph.neo4j.Person;
import org.springframework.data.graph.neo4j.finder.FinderFactory;
import org.springframework.data.graph.neo4j.finder.NodeFinder;
import org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory;
import org.springframework.data.graph.neo4j.repository.NodeGraphRepository;
import org.springframework.data.graph.neo4j.support.node.Neo4jHelper;
import org.springframework.test.context.CleanContextCacheTestExecutionListener;
import org.springframework.test.context.ContextConfiguration;
@@ -41,7 +36,7 @@ import static org.springframework.data.graph.neo4j.Person.persistedPerson;
private GraphDatabaseContext graphDatabaseContext;
@Autowired
private FinderFactory finderFactory;
private DirectGraphRepositoryFactory graphRepositoryFactory;
@BeforeTransaction
public void cleanDb() {
@@ -60,8 +55,8 @@ import static org.springframework.data.graph.neo4j.Person.persistedPerson;
Person person2 = graphDatabaseContext.createEntityFromState(node,Person.class);
assertEquals("Rod", person2.getName());
NodeFinder<Person> finder = finderFactory.createNodeEntityFinder(Person.class);
Person found = finder.findById(nodeId);
NodeGraphRepository<Person> finder = graphRepositoryFactory.createNodeEntityRepository(Person.class);
Person found = finder.findOne(nodeId);
assertEquals("Rod", found.getName());
}
}

View File

@@ -3,7 +3,6 @@ package org.springframework.data.graph.neo4j.support;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.neo4j.graphdb.*;
@@ -14,7 +13,7 @@ import org.springframework.data.graph.neo4j.Friendship;
import org.springframework.data.graph.neo4j.Group;
import org.springframework.data.graph.neo4j.Person;
import static org.springframework.data.graph.neo4j.Person.persistedPerson;
import org.springframework.data.graph.neo4j.finder.FinderFactory;
import org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory;
import org.springframework.data.graph.neo4j.support.node.Neo4jHelper;
import org.springframework.test.context.ContextConfiguration;
@@ -37,7 +36,7 @@ public class NodeEntityRelationshipTest {
private GraphDatabaseContext graphDatabaseContext;
@Autowired
private FinderFactory finderFactory;
private DirectGraphRepositoryFactory graphRepositoryFactory;
@BeforeTransaction
public void cleanDb() {

View File

@@ -10,8 +10,8 @@ import org.neo4j.graphdb.Transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.graph.neo4j.Group;
import org.springframework.data.graph.neo4j.Person;
import org.springframework.data.graph.neo4j.finder.FinderFactory;
import org.springframework.data.graph.neo4j.finder.NodeFinder;
import org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory;
import org.springframework.data.graph.neo4j.repository.NodeGraphRepository;
import org.springframework.data.graph.neo4j.support.node.Neo4jHelper;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -32,7 +32,7 @@ import static org.springframework.data.graph.neo4j.Person.persistedPerson;
private GraphDatabaseContext graphDatabaseContext;
@Autowired
private FinderFactory finderFactory;
private DirectGraphRepositoryFactory graphRepositoryFactory;
@BeforeTransaction
public void cleanDb() {
@@ -93,7 +93,7 @@ import static org.springframework.data.graph.neo4j.Person.persistedPerson;
tx.success();
tx.finish();
Assert.assertNull("spouse removed " + p.getSpouse(), p.getSpouse());
NodeFinder<Person> finder = finderFactory.createNodeEntityFinder(Person.class);
NodeGraphRepository<Person> finder = graphRepositoryFactory.createNodeEntityRepository(Person.class);
Person spouseFromIndex = finder.findByPropertyValue(Person.NAME_INDEX, "name", "Tina");
Assert.assertNull("spouse not found in index",spouseFromIndex);
Assert.assertNull("node deleted " + id, graphDatabaseContext.getNodeById(id));
@@ -110,7 +110,7 @@ import static org.springframework.data.graph.neo4j.Person.persistedPerson;
tx.success();
tx.finish();
Assert.assertNull("spouse removed " + p.getSpouse(), p.getSpouse());
NodeFinder<Person> finder = finderFactory.createNodeEntityFinder(Person.class);
NodeGraphRepository<Person> finder = graphRepositoryFactory.createNodeEntityRepository(Person.class);
Person spouseFromIndex = finder.findByPropertyValue(Person.NAME_INDEX, "name", "Tina");
Assert.assertNull("spouse not found in index", spouseFromIndex);
Assert.assertNull("node deleted " + id, graphDatabaseContext.getNodeById(id));

View File

@@ -2,16 +2,14 @@ package org.springframework.data.graph.neo4j.support;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.graph.neo4j.Group;
import org.springframework.data.graph.neo4j.Named;
import org.springframework.data.graph.neo4j.finder.FinderFactory;
import org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory;
import org.springframework.data.graph.neo4j.support.node.Neo4jHelper;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.BeforeTransaction;
@@ -30,7 +28,7 @@ public class ProjectionTest {
private GraphDatabaseContext graphDatabaseContext;
@Autowired
private FinderFactory finderFactory;
private DirectGraphRepositoryFactory graphRepositoryFactory;
@BeforeTransaction
public void cleanDb() {

View File

@@ -8,7 +8,7 @@ import org.neo4j.graphdb.NotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.graph.neo4j.*;
import org.springframework.data.graph.neo4j.finder.FinderFactory;
import org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory;
import org.springframework.data.graph.neo4j.support.node.Neo4jHelper;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
@@ -32,7 +32,7 @@ public class PropertyTest {
private GraphDatabaseContext graphDatabaseContext;
@Autowired
private FinderFactory finderFactory;
private DirectGraphRepositoryFactory graphRepositoryFactory;
@BeforeTransaction
public void cleanDb() {

View File

@@ -2,7 +2,6 @@ package org.springframework.data.graph.neo4j.support;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.neo4j.graphdb.*;
@@ -11,7 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.graph.neo4j.Friendship;
import org.springframework.data.graph.neo4j.Person;
import static org.springframework.data.graph.neo4j.Person.persistedPerson;
import org.springframework.data.graph.neo4j.finder.FinderFactory;
import org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory;
import org.springframework.data.graph.neo4j.support.node.Neo4jHelper;
import org.springframework.test.context.ContextConfiguration;
@@ -32,7 +32,7 @@ public class RelationshipEntityTest {
private GraphDatabaseContext graphDatabaseContext;
@Autowired
private FinderFactory finderFactory;
private DirectGraphRepositoryFactory graphRepositoryFactory;
@BeforeTransaction
public void cleanDb() {

View File

@@ -19,8 +19,8 @@ import org.springframework.data.graph.neo4j.Person;
import static org.springframework.data.graph.neo4j.Person.persistedPerson;
import org.springframework.data.graph.neo4j.Toyota;
import org.springframework.data.graph.neo4j.Volvo;
import org.springframework.data.graph.neo4j.finder.FinderFactory;
import org.springframework.data.graph.neo4j.finder.NodeFinder;
import org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory;
import org.springframework.data.graph.neo4j.repository.NodeGraphRepository;
import org.springframework.data.graph.neo4j.support.node.Neo4jHelper;
import org.springframework.test.context.CleanContextCacheTestExecutionListener;
@@ -51,7 +51,7 @@ public class SubReferenceNodeTypeStrategyTest {
@Autowired
GraphDatabaseContext graphDatabaseContext;
@Autowired
private FinderFactory finderFactory;
private DirectGraphRepositoryFactory graphRepositoryFactory;
@Autowired
private SubReferenceTypeRepresentationStrategy nodeTypeStrategy;
private Node thingNode;
@@ -166,7 +166,7 @@ public class SubReferenceNodeTypeStrategyTest {
public void testInstantiateConcreteClassWithFinder() {
log.debug("testInstantiateConcreteClassWithFinder");
Volvo v=new Volvo().persist();
NodeFinder<Car> finder = finderFactory.createNodeEntityFinder(Car.class);
NodeGraphRepository<Car> finder = graphRepositoryFactory.createNodeEntityRepository(Car.class);
assertEquals("Wrong concrete class.", Volvo.class, finder.findAll().iterator().next().getClass());
}
@@ -178,16 +178,16 @@ public class SubReferenceNodeTypeStrategyTest {
log.warn("Created volvo");
new Toyota().persist();
log.warn("Created volvo");
assertEquals("Wrong count for Volvo.", 1, finderFactory.createNodeEntityFinder(Volvo.class).count());
assertEquals("Wrong count for Toyota.", 1, finderFactory.createNodeEntityFinder(Toyota.class).count());
assertEquals("Wrong count for Car.", 2, finderFactory.createNodeEntityFinder(Car.class).count());
assertEquals("Wrong count for Volvo.", (Long)1L, graphRepositoryFactory.createNodeEntityRepository(Volvo.class).count());
assertEquals("Wrong count for Toyota.", (Long)1L, graphRepositoryFactory.createNodeEntityRepository(Toyota.class).count());
assertEquals("Wrong count for Car.", (Long)2L, graphRepositoryFactory.createNodeEntityRepository(Car.class).count());
}
@Test
@Transactional
public void testCountClasses() {
persistedPerson("Michael", 36);
persistedPerson("David", 25);
assertEquals("Wrong Person instance count.", 2, finderFactory.createNodeEntityFinder(Person.class).count());
assertEquals("Wrong Person instance count.", (Long)2L, graphRepositoryFactory.createNodeEntityRepository(Person.class).count());
}
@NodeEntity

View File

@@ -2,7 +2,6 @@ package org.springframework.data.graph.neo4j.support;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.neo4j.graphdb.DynamicRelationshipType;
@@ -13,8 +12,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.graph.neo4j.Group;
import org.springframework.data.graph.neo4j.Person;
import static org.springframework.data.graph.neo4j.Person.persistedPerson;
import org.springframework.data.graph.neo4j.finder.FinderFactory;
import org.springframework.data.graph.neo4j.finder.NodeFinder;
import org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory;
import org.springframework.data.graph.neo4j.repository.NodeGraphRepository;
import org.springframework.data.graph.neo4j.support.node.Neo4jHelper;
import org.springframework.test.annotation.Rollback;
@@ -39,7 +39,7 @@ public class TraversalTest {
private GraphDatabaseContext graphDatabaseContext;
@Autowired
private FinderFactory finderFactory;
private DirectGraphRepositoryFactory graphRepositoryFactory;
@BeforeTransaction
public void cleanDb() {
@@ -81,7 +81,7 @@ public class TraversalTest {
@Test
@Transactional
public void testTraverseFromGroupToPeopleWithFinder() {
final NodeFinder<Person> finder = finderFactory.createNodeEntityFinder(Person.class);
final NodeGraphRepository<Person> finder = graphRepositoryFactory.createNodeEntityRepository(Person.class);
Person p = persistedPerson("Michael", 35);
Group group = new Group().persist();
group.setName("dev");

View File

@@ -115,21 +115,21 @@
<property name="nodeDelegatingFieldAccessorFactory">
<bean class="org.springframework.data.graph.neo4j.fieldaccess.NodeDelegatingFieldAccessorFactory">
<constructor-arg ref="graphDatabaseContext"/>
<constructor-arg ref="finderFactory"/>
<constructor-arg ref="graphRepositoryFactory"/>
</bean>
</property>
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="finderFactory" ref="finderFactory"/>
<property name="graphRepositoryFactory" ref="graphRepositoryFactory"/>
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<bean id="relationshipEntityStateFactory" class="org.springframework.data.graph.neo4j.fieldaccess.RelationshipEntityStateFactory">
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="finderFactory" ref="finderFactory"/>
<property name="graphRepositoryFactory" ref="graphRepositoryFactory"/>
</bean>
<bean id="finderFactory" class="org.springframework.data.graph.neo4j.finder.FinderFactory">
<bean id="graphRepositoryFactory" class="org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory">
<constructor-arg ref="graphDatabaseContext" />
</bean>

View File

@@ -109,19 +109,19 @@
<property name="nodeDelegatingFieldAccessorFactory">
<bean class="org.springframework.data.graph.neo4j.fieldaccess.NodeDelegatingFieldAccessorFactory">
<constructor-arg ref="graphDatabaseContext"/>
<constructor-arg ref="finderFactory"/>
<constructor-arg ref="graphRepositoryFactory"/>
</bean>
</property>
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="finderFactory" ref="finderFactory"/>
<property name="graphRepositoryFactory" ref="graphRepositoryFactory"/>
</bean>
<bean id="relationshipEntityStateFactory" class="org.springframework.data.graph.neo4j.fieldaccess.RelationshipEntityStateFactory">
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="finderFactory" ref="finderFactory"/>
<property name="graphRepositoryFactory" ref="graphRepositoryFactory"/>
</bean>
<bean id="finderFactory" class="org.springframework.data.graph.neo4j.finder.FinderFactory">
<bean id="graphRepositoryFactory" class="org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory">
<constructor-arg ref="graphDatabaseContext" />
</bean>
@@ -139,4 +139,21 @@
</bean>
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
<bean id="personRepository" class="org.springframework.data.graph.neo4j.repository.GraphRepositoryFactoryBean">
<property name="repositoryInterface" value="org.springframework.data.graph.neo4j.PersonRepository" />
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
</bean>
<bean id="groupRepository" class="org.springframework.data.graph.neo4j.repository.GraphRepositoryFactoryBean">
<property name="repositoryInterface" value="org.springframework.data.graph.neo4j.GroupRepository" />
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
</bean>
<!-- Adds transaparent exception translation to the DAOs -->
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<!-- Adds dependency checks for setters annotated with @Required -->
<bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor" />
<bean class="org.springframework.data.graph.neo4j.template.Neo4jExceptionTranslator"/>
</beans>

View File

@@ -42,7 +42,7 @@ org.neo4j.server.thirdparty_jaxrs_classes=com.example.mypackage=/my-context
by the spring context but already provided by the Neo4j-server. But a correctly set up and loaded
spring context ist the requirement for spring data graph to work. By using the lifecycle support of
Neo4j server extendsions it is possible to register the provided graph database with the
spring configuration and also to expose certain spring beans (e.g. finderFactory, graphDatabaseContext) to be
spring configuration and also to expose certain spring beans (e.g. graphRepositoryFactory, graphDatabaseContext) to be
injected via jersey into subsequent resources.
</para>
<para>
@@ -52,7 +52,7 @@ org.neo4j.server.thirdparty_jaxrs_classes=com.example.mypackage=/my-context
<programlisting language="java"><![CDATA[
public class HelloWorldInitializer extends SpringPluginInitializer {
public HelloWorldInitializer() {
super(new String[]{"spring/helloWorldServer-Context.xml"}, "worldRepository","finderFactory");
super(new String[]{"spring/helloWorldServer-Context.xml"}, "worldRepository","graphRepositoryFactory");
}
}
]]></programlisting>

View File

@@ -16,7 +16,7 @@
The aspect introduces some internal fields and some public methods (<xref linkend="reference:programming-model:introduced-methods"/>)
to the entities for accessing the backing
state via <code>getPersistentState()</code> and creating relationships with <code>relateTo</code>
and retrieving relationship entities via <code>getRelationshipTo</code>. It also introduces finder methods like
and retrieving relationship entities via <code>getRelationshipTo</code>. It also introduces graphRepository methods like
<code>find(Class&lt;? extends NodeEntity&gt;, TraversalDescription)</code>
and equals and hashCode delegation.
</para>

View File

@@ -43,21 +43,21 @@
The <code>Finder</code> instances are created via a FinderFactory to be bound to a concrete node or relationship entity class.
The <code>FinderFactory</code> is configured in the Spring context and can be injected.
<programlisting language="java"><![CDATA[
NodeFinder<Person> finder = finderFactory.createNodeEntityFinder(Person.class);
NodeFinder<Person> graphRepository = graphRepositoryFactory.createNodeEntityFinder(Person.class);
Person dave=finder.findById(123);
Person dave=graphRepository.findById(123);
long numberOfPeople = finder.count();
long numberOfPeople = graphRepository.count();
Person mark = finder.findByPropertyValue(null,"name", "mark");
Person mark = graphRepository.findByPropertyValue(null,"name", "mark");
Iterable<Person> devs = finder.findAllByProperyValue(null, "occupation","developer");
Iterable<Person> devs = graphRepository.findAllByProperyValue(null, "occupation","developer");
Iterable<Person> middleAgedPeople = finder.findAllByRange(null, "age",20,40);
Iterable<Person> middleAgedPeople = graphRepository.findAllByRange(null, "age",20,40);
Iterable<Person> aTeam = finder.findAllByQuery(null, "name","A*");
Iterable<Person> aTeam = graphRepository.findAllByQuery(null, "name","A*");
Iterable<Person> davesFriends = finder.findAllByTraversal(dave,
Iterable<Person> davesFriends = graphRepository.findAllByTraversal(dave,
Traversal.description().pruneAfterDepth(1)
.relationships(KNOWS).filter(returnAllButStartNode()));
]]></programlisting>

View File

@@ -27,7 +27,7 @@
</para>
<para>
Query access to the index happens with the Node- and RelationshipFinders that are created via an instance of
<code>org.springframework.data.graph.neo4j.finder.FinderFactory</code>. The methods
<code>org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory</code>. The methods
<code>findByPropertyValue</code> and <code>findAllByPropertyValue</code> work on the exact indexes and
return the first or all matches. To do range queries, use <code>findAllByRange</code> (please note that
currently both values are inclusive).
@@ -44,13 +44,13 @@ class Person {
}
NodeFinder<Person> finder = finderFactory.createNodeEntityFinder(Person.class);
NodeFinder<Person> graphRepository = graphRepositoryFactory.createNodeEntityFinder(Person.class);
// exact finder
Person mark = finder.findByProperyValue("people","name","mark");
// exact graphRepository
Person mark = graphRepository.findByProperyValue("people","name","mark");
// numeric range queries
for (Person middleAgedDeveloper : finder.findAllByRange(null, "age", 20, 40)) {
for (Person middleAgedDeveloper : graphRepository.findAllByRange(null, "age", 20, 40)) {
Developer developer=middleAgedDeveloper.projectTo(Developer.class);
}
]]></programlisting>
@@ -76,10 +76,10 @@ class Person {
String name;
}
NodeFinder<Person> finder = finderFactory.createNodeEntityFinder(Person.class);
NodeFinder<Person> graphRepository = graphRepositoryFactory.createNodeEntityFinder(Person.class);
// exact finder
Person mark = finder.findAllByQuery("people-search","name","ma*");
// exact graphRepository
Person mark = graphRepository.findAllByQuery("people-search","name","ma*");
]]></programlisting>
</para>
<note>

View File

@@ -33,7 +33,7 @@ class Trainee {
Set<Training> trainings;
}
for (Person person : finder.findAllByProperyValue("occupation","developer")) {
for (Person person : graphRepository.findAllByProperyValue("occupation","developer")) {
Developer developer = person.projectTo(Developer.class);
if (developer.isJavaDeveloper()) {
trainInSpringData(developer.projectTo(Trainee.class));

View File

@@ -18,12 +18,12 @@ class Movie {
int year;
}
@Autowired FinderFactory finderFactory;
@Autowired FinderFactory graphRepositoryFactory;
@Test [@Transactional] public void persistedMovieShouldBeRetrievableFromGraphDb() {
int id=1;
Movie forrestGump = new Movie(id, "Forrest Gump", 1994).persist();
NodeFinder<Movie> movieFinder = finderFactory.createNodeEntityFinder(Movie.class);
NodeFinder<Movie> movieFinder = graphRepositoryFactory.createNodeEntityFinder(Movie.class);
// REMINDER, the "null" stands for an optional index name
Movie retrievedMovie = movieFinder.findByPropertyValue(null, "id",id);
assertEqual("retrieved movie matches persisted one",forrestGump,retrievedMovie);

View File

@@ -10,12 +10,12 @@
<programlisting language="java"><![CDATA[
@Repository @Transactional
public class CineastsRepostory {
FinderFactory finderFactory;
FinderFactory graphRepositoryFactory;
Finder<Movie> movieFinder;
@Autowired
public CineastsRepostory(FinderFactory finderFactory) {
this.finderFactory = finderFactory;
this.movieFinder = finderFactory.createNodeEntityFinder(Movie.class);
public CineastsRepostory(FinderFactory graphRepositoryFactory) {
this.graphRepositoryFactory = graphRepositoryFactory;
this.movieFinder = graphRepositoryFactory.createNodeEntityFinder(Movie.class);
}
public Movie getMovie(int id) {
return movieFinder.findByPropertyValue(null,"id", id);

View File

@@ -90,12 +90,12 @@ in a separate applicationContext-security.xml. But first, as always, Maven and w
@Service
public class CineastsUserDetailsService implements UserDetailsService, InitializingBean {
@Autowired private FinderFactory finderFactory;
@Autowired private FinderFactory graphRepositoryFactory;
private NodeFinder<User> userFinder;
@Override
public void afterPropertiesSet() throws Exception {
userFinder = finderFactory.createNodeEntityFinder(User.class);
userFinder = graphRepositoryFactory.createNodeEntityFinder(User.class);
}
@Override

View File

@@ -35,7 +35,7 @@ lucene we were delighted to see that fulltext indexes are supported out of the b
</para>
<para>
We happily annotated the title field of my Movie class with @Index(fulltext=true) and was told with an exception that we have to specify a separate index name for that.
So it became @Indexed(fulltext = true, indexName = "search"). The corresponding finder method is called findAllByQuery. So there was our second repository method for
So it became @Indexed(fulltext = true, indexName = "search"). The corresponding graphRepository method is called findAllByQuery. So there was our second repository method for
searching movies. To restrict the size of the returned set we just added a limit for now that truncates the result after so many entries.
</para>
<para>