added property indexing annotation

This commit is contained in:
Michael Hunger
2010-09-08 21:38:21 +02:00
parent 04b1eccab8
commit 69a9240aec
4 changed files with 34 additions and 7 deletions

View File

@@ -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;
}

View File

@@ -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> {

View File

@@ -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;

View File

@@ -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() {