more fun with indexing
This commit is contained in:
committed by
Michael Hunger
parent
e2422b42d4
commit
0d043c6096
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,3 +3,5 @@ target
|
||||
.ant-targets-build.xml
|
||||
src/ant/.ant-targets-upload-dist.xml
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
|
||||
@@ -303,7 +303,7 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<useFile>false</useFile>
|
||||
<useFile>true</useFile>
|
||||
<includes>
|
||||
<include>**/*Tests.java</include>
|
||||
<include>**/*Test.java</include>
|
||||
|
||||
@@ -12,151 +12,181 @@ import java.util.Date;
|
||||
|
||||
|
||||
@NodeEntity(useShortNames = false)
|
||||
public class Person {
|
||||
public class Person
|
||||
{
|
||||
|
||||
@GraphId
|
||||
private Long graphId;
|
||||
public static final String NAME_INDEX = "name_index";
|
||||
@GraphId
|
||||
private Long graphId;
|
||||
|
||||
@GraphProperty(index = true)
|
||||
private String name;
|
||||
@Indexed(name = NAME_INDEX)
|
||||
private String name;
|
||||
|
||||
@Indexed
|
||||
private String nickname;
|
||||
@Indexed
|
||||
private String nickname;
|
||||
|
||||
private int age;
|
||||
private int age;
|
||||
|
||||
private Short height;
|
||||
private Short height;
|
||||
|
||||
private transient String thought;
|
||||
private transient String thought;
|
||||
|
||||
private Personality personality;
|
||||
private Personality personality;
|
||||
|
||||
private Date birthdate;
|
||||
private Date birthdate;
|
||||
|
||||
private Person spouse;
|
||||
private Person spouse;
|
||||
|
||||
private Car car;
|
||||
private Car car;
|
||||
|
||||
@RelatedTo(type = "mother", direction = Direction.OUTGOING)
|
||||
private Person mother;
|
||||
@RelatedTo(type = "mother", direction = Direction.OUTGOING)
|
||||
private Person mother;
|
||||
|
||||
@RelatedTo(type = "boss", direction = Direction.INCOMING)
|
||||
private Person boss;
|
||||
@RelatedTo(type = "boss", direction = Direction.INCOMING)
|
||||
private Person boss;
|
||||
|
||||
@RelatedToVia(type = "knows", elementClass = Friendship.class)
|
||||
private Iterable<Friendship> friendships;
|
||||
@RelatedToVia(type = "knows", elementClass = Friendship.class)
|
||||
private Iterable<Friendship> friendships;
|
||||
|
||||
public Person() {
|
||||
public Person()
|
||||
{
|
||||
}
|
||||
|
||||
public Person(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
public Person( String name, int age )
|
||||
{
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void setName( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
public int getAge()
|
||||
{
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
public void setAge( int age )
|
||||
{
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public Short getHeight() {
|
||||
return height;
|
||||
}
|
||||
public Short getHeight()
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
public void setHeight(Short height) {
|
||||
this.height = height;
|
||||
}
|
||||
public void setHeight( Short height )
|
||||
{
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
|
||||
public Person getSpouse() {
|
||||
return spouse;
|
||||
}
|
||||
public Person getSpouse()
|
||||
{
|
||||
return spouse;
|
||||
}
|
||||
|
||||
public void setSpouse(Person spouse) {
|
||||
this.spouse = spouse;
|
||||
}
|
||||
public void setSpouse( Person spouse )
|
||||
{
|
||||
this.spouse = spouse;
|
||||
}
|
||||
|
||||
public Person getMother() {
|
||||
return mother;
|
||||
}
|
||||
public Person getMother()
|
||||
{
|
||||
return mother;
|
||||
}
|
||||
|
||||
public void setMother(Person mother) {
|
||||
this.mother = mother;
|
||||
}
|
||||
public void setMother( Person mother )
|
||||
{
|
||||
this.mother = mother;
|
||||
}
|
||||
|
||||
public Person getBoss() {
|
||||
return boss;
|
||||
}
|
||||
public Person getBoss()
|
||||
{
|
||||
return boss;
|
||||
}
|
||||
|
||||
public void setBoss(Person boss) {
|
||||
this.boss = boss;
|
||||
}
|
||||
public void setBoss( Person boss )
|
||||
{
|
||||
this.boss = boss;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public Iterable<Friendship> getFriendships() {
|
||||
return friendships;
|
||||
}
|
||||
public Iterable<Friendship> getFriendships()
|
||||
{
|
||||
return friendships;
|
||||
}
|
||||
|
||||
public void setFriendships(Iterable<Friendship> f) {
|
||||
friendships = f;
|
||||
}
|
||||
public void setFriendships( Iterable<Friendship> f )
|
||||
{
|
||||
friendships = f;
|
||||
}
|
||||
|
||||
public Friendship knows(Person p) {
|
||||
return (Friendship)relateTo(p, Friendship.class,"knows");
|
||||
}
|
||||
public Friendship knows( Person p )
|
||||
{
|
||||
return (Friendship) relateTo( p, Friendship.class, "knows" );
|
||||
}
|
||||
|
||||
public void setPersonality(Personality personality) {
|
||||
this.personality = personality;
|
||||
}
|
||||
public void setPersonality( Personality personality )
|
||||
{
|
||||
this.personality = personality;
|
||||
}
|
||||
|
||||
public Personality getPersonality() {
|
||||
return personality;
|
||||
}
|
||||
public Personality getPersonality()
|
||||
{
|
||||
return personality;
|
||||
}
|
||||
|
||||
public void setThought(String thought) {
|
||||
this.thought = thought;
|
||||
}
|
||||
public void setThought( String thought )
|
||||
{
|
||||
this.thought = thought;
|
||||
}
|
||||
|
||||
public String getThought() {
|
||||
return thought;
|
||||
}
|
||||
public String getThought()
|
||||
{
|
||||
return thought;
|
||||
}
|
||||
|
||||
public Date getBirthdate() {
|
||||
return birthdate;
|
||||
}
|
||||
public Date getBirthdate()
|
||||
{
|
||||
return birthdate;
|
||||
}
|
||||
|
||||
public void setBirthdate(Date birthdate) {
|
||||
this.birthdate = birthdate;
|
||||
}
|
||||
public void setBirthdate( Date birthdate )
|
||||
{
|
||||
this.birthdate = birthdate;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return graphId;
|
||||
}
|
||||
public long getId()
|
||||
{
|
||||
return graphId;
|
||||
}
|
||||
|
||||
public void setCar(Car car) {
|
||||
this.car = car;
|
||||
}
|
||||
public void setCar( Car car )
|
||||
{
|
||||
this.car = car;
|
||||
}
|
||||
|
||||
public Car getCar() {
|
||||
return car;
|
||||
}
|
||||
public Car getCar()
|
||||
{
|
||||
return car;
|
||||
}
|
||||
|
||||
public void setNickname(String nickname) {
|
||||
this.nickname = nickname;
|
||||
}
|
||||
public void setNickname( String nickname )
|
||||
{
|
||||
this.nickname = nickname;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,8 +32,4 @@ import java.lang.annotation.Target;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface GraphProperty {
|
||||
/**
|
||||
* @return true if the property should be indexed, false if not
|
||||
*/
|
||||
boolean index() default true;
|
||||
}
|
||||
|
||||
@@ -48,9 +48,7 @@ class IndexingNodePropertyFieldAccessorListenerFactory implements FieldAccessorL
|
||||
final NodeEntity entityAnnotation = f.getDeclaringClass().getAnnotation(NodeEntity.class);
|
||||
if (entityAnnotation!=null && entityAnnotation.fullIndex()) return true;
|
||||
final Indexed indexedAnnotation = f.getAnnotation(Indexed.class);
|
||||
if (indexedAnnotation != null) return true;
|
||||
final GraphProperty propertyAnnotation = f.getAnnotation(GraphProperty.class);
|
||||
return propertyAnnotation!=null && propertyAnnotation.index();
|
||||
return indexedAnnotation != null;
|
||||
}
|
||||
|
||||
private boolean isPropertyField(final Field f) {
|
||||
@@ -64,7 +62,10 @@ class IndexingNodePropertyFieldAccessorListenerFactory implements FieldAccessorL
|
||||
|
||||
private String getIndexName(Field field) {
|
||||
Indexed indexed = field.getAnnotation(Indexed.class);
|
||||
return hasIndexName(indexed) ? indexed.name() : null;
|
||||
if (hasIndexName(indexed)) return indexed.name();
|
||||
|
||||
final Indexed indexedEntity = field.getDeclaringClass().getAnnotation(Indexed.class);
|
||||
return hasIndexName( indexedEntity ) ? indexedEntity.name() : null;
|
||||
}
|
||||
|
||||
private boolean hasIndexName(Indexed indexed) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.neo4j.graphdb.DynamicRelationshipType;
|
||||
import org.neo4j.graphdb.traversal.TraversalDescription;
|
||||
import org.neo4j.kernel.Traversal;
|
||||
import org.neo4j.kernel.impl.traversal.TraversalDescriptionImpl;
|
||||
import org.springframework.data.annotation.Indexed;
|
||||
import org.springframework.data.graph.*;
|
||||
import org.springframework.data.graph.annotation.GraphProperty;
|
||||
import org.springframework.data.graph.annotation.GraphTraversal;
|
||||
@@ -30,9 +31,10 @@ public class Group {
|
||||
private Iterable<Person> people;
|
||||
|
||||
@GraphProperty
|
||||
@Indexed
|
||||
private String name;
|
||||
|
||||
@GraphProperty(index = false)
|
||||
@GraphProperty
|
||||
private String unindexedName;
|
||||
|
||||
private String unindexedName2;
|
||||
|
||||
@@ -14,10 +14,11 @@ import java.util.Date;
|
||||
@NodeEntity(useShortNames = false)
|
||||
public class Person {
|
||||
|
||||
@GraphId
|
||||
public static final String NAME_INDEX = "name_index";
|
||||
@GraphId
|
||||
private Long graphId;
|
||||
|
||||
@GraphProperty(index = true)
|
||||
@Indexed(name = NAME_INDEX)
|
||||
private String name;
|
||||
|
||||
@Indexed
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.springframework.data.graph.neo4j.partial;
|
||||
|
||||
import org.springframework.data.annotation.Indexed;
|
||||
import org.springframework.data.graph.annotation.GraphProperty;
|
||||
import org.springframework.data.graph.annotation.NodeEntity;
|
||||
|
||||
@@ -20,6 +21,7 @@ public class Restaurant {
|
||||
String zipCode;
|
||||
|
||||
@GraphProperty
|
||||
@Indexed
|
||||
@Transient
|
||||
Cuisine cuisine;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.springframework.data.graph.neo4j.partial;
|
||||
|
||||
import org.neo4j.graphdb.DynamicRelationshipType;
|
||||
import org.springframework.data.annotation.Indexed;
|
||||
import org.springframework.data.graph.*;
|
||||
import org.springframework.data.graph.annotation.GraphProperty;
|
||||
import org.springframework.data.graph.annotation.NodeEntity;
|
||||
@@ -26,6 +27,7 @@ public class User {
|
||||
int age;
|
||||
|
||||
@GraphProperty
|
||||
@Indexed
|
||||
@Transient
|
||||
String nickname;
|
||||
|
||||
|
||||
@@ -369,7 +369,7 @@ public class Neo4jGraphPersistenceTest {
|
||||
Person spouse = new Person("Tina", 36);
|
||||
me.setSpouse(spouse);
|
||||
final Finder<Person> personFinder = finderFactory.getFinderForClass(Person.class);
|
||||
final Person foundMe = personFinder.findByPropertyValue(null, "Person.name", "Michael");
|
||||
final Person foundMe = personFinder.findByPropertyValue( Person.NAME_INDEX, "Person.name", "Michael");
|
||||
assertEquals(spouse,foundMe.getSpouse());
|
||||
}
|
||||
|
||||
@@ -481,7 +481,7 @@ public class Neo4jGraphPersistenceTest {
|
||||
public void testFindAllPersonByIndexOnAnnotatedField() {
|
||||
Person person = new Person("Michael",35);
|
||||
final Finder<Person> finder = finderFactory.getFinderForClass(Person.class);
|
||||
final Person found = finder.findByPropertyValue(null, "Person.name", "Michael");
|
||||
final Person found = finder.findByPropertyValue( Person.NAME_INDEX, "Person.name", "Michael");
|
||||
assertEquals(person, found);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user