added property indexing annotation
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package org.springframework.datastore.graph.api;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @author Michael Hunger
|
||||
* @since 27.08.2010
|
||||
* indexing true by default
|
||||
* implies automatic conversion
|
||||
* TODO support for custom converter class
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface GraphEntityProperty {
|
||||
boolean index() default true;
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import org.neo4j.kernel.EmbeddedGraphDatabase;
|
||||
import org.neo4j.util.GraphDatabaseUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.InvalidDataAccessResourceUsageException;
|
||||
import org.springframework.datastore.graph.api.GraphEntityProperty;
|
||||
import org.springframework.datastore.graph.api.NodeBacked;
|
||||
import org.springframework.datastore.graph.api.RelationshipBacked;
|
||||
|
||||
@@ -390,8 +391,9 @@ public aspect Neo4jNodeBacking extends AbstractTypeAnnotatingMixinFields<GraphEn
|
||||
// todo fieldlist in @graphentity
|
||||
private boolean isIndexedProperty(Field field) {
|
||||
final GraphEntity graphEntity = field.getDeclaringClass().getAnnotation(GraphEntity.class);
|
||||
if (graphEntity==null) return false;
|
||||
return graphEntity.fullIndex();
|
||||
if (graphEntity != null && graphEntity.fullIndex()) return true;
|
||||
final GraphEntityProperty graphEntityProperty = field.getAnnotation(GraphEntityProperty.class);
|
||||
return graphEntityProperty!=null && graphEntityProperty.index();
|
||||
}
|
||||
|
||||
public static class NodeBackedNodeIterableWrapper extends IterableWrapper<NodeBacked, Node> {
|
||||
|
||||
@@ -2,17 +2,15 @@ package org.springframework.datastore.graph.neo4j;
|
||||
|
||||
import org.neo4j.graphdb.DynamicRelationshipType;
|
||||
import org.neo4j.graphdb.Relationship;
|
||||
import org.springframework.datastore.graph.api.Direction;
|
||||
import org.springframework.datastore.graph.api.GraphEntity;
|
||||
import org.springframework.datastore.graph.api.GraphEntityRelationship;
|
||||
import org.springframework.datastore.graph.api.GraphEntityRelationshipEntity;
|
||||
import org.springframework.datastore.graph.api.*;
|
||||
|
||||
|
||||
@GraphEntity(useShortNames = false)
|
||||
public class Person {
|
||||
|
||||
private Long id;
|
||||
|
||||
|
||||
@GraphEntityProperty(index = true)
|
||||
private String name;
|
||||
|
||||
private int age;
|
||||
|
||||
@@ -425,6 +425,14 @@ public class Neo4jGraphPersistenceTest {
|
||||
final Collection<Group> result = IteratorUtil.addToCollection(found.iterator(), new HashSet<Group>());
|
||||
Assert.assertEquals(new HashSet<Group>(Arrays.asList(group,group2)), result);
|
||||
}
|
||||
@Test
|
||||
@Transactional
|
||||
public void testFindAllPersonByIndexOnAnnotatedField() {
|
||||
Person person = new Person("Michael",35);
|
||||
final Finder<Person> finder = finderFactory.getFinderForClass(Person.class);
|
||||
final Person found = finder.findByPropertyValue("Person.name", "Michael");
|
||||
Assert.assertEquals(person, found);
|
||||
}
|
||||
@Test
|
||||
@Transactional
|
||||
public void testTraverseFromGroupToPeople() {
|
||||
|
||||
Reference in New Issue
Block a user