Skip to content

Commit

Permalink
Switching to IndexType to allow for more advanced IndexProvider
Browse files Browse the repository at this point in the history
creation.
  • Loading branch information
Peter Neubauer authored and jexp committed Oct 21, 2011
1 parent 31a6ce8 commit f0e81ee
Show file tree
Hide file tree
Showing 22 changed files with 96 additions and 41 deletions.
Expand Up @@ -16,7 +16,18 @@

package org.springframework.data.neo4j.aspects.support;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.springframework.data.neo4j.aspects.Person.NAME_INDEX;
import static org.springframework.data.neo4j.aspects.Person.persistedPerson;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;

import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.neo4j.graphdb.DynamicRelationshipType;
Expand All @@ -37,14 +48,6 @@
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;

import static org.junit.Assert.*;
import static org.springframework.data.neo4j.aspects.Person.NAME_INDEX;
import static org.springframework.data.neo4j.aspects.Person.persistedPerson;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:org/springframework/data/neo4j/aspects/support/Neo4jGraphPersistenceTest-context.xml"})
public class IndexTest extends EntityTestBase {
Expand Down Expand Up @@ -151,6 +154,12 @@ static class InvalidIndexed {
@Indexed(indexType=IndexType.FULLTEXT, indexName = "InvalidIndexed")
String fullTextDefaultIndexName;

@Indexed(indexType=IndexType.POINT, indexName = "InvalidIndexed")
double[] latlon;

@Indexed(indexType=IndexType.POINT)
double[] latlonNoIndexName;

public void setFulltextNoIndexName(String fulltextNoIndexName) {
this.fulltextNoIndexName = fulltextNoIndexName;
}
Expand All @@ -159,8 +168,56 @@ public void setFullTextDefaultIndexName(String fullTextDefaultIndexName) {
this.fullTextDefaultIndexName = fullTextDefaultIndexName;
}
}

@NodeEntity
static class InvalidSpatialIndexed {

@Indexed(indexType=IndexType.POINT, indexName = "InvalidSpatialIndexed")
double[] latlon;

@Indexed(indexType=IndexType.POINT)
double[] latlonNoIndexName;

@Indexed(indexType=IndexType.POINT, indexName = "pointLayer")
double[] latlonValid;

public void setLatlonNoIndexName(double[] latlonNoIndexName) {
this.latlonNoIndexName = latlonNoIndexName;
}

public void setLatlon(double[] latlon) {
this.latlon = latlon;
}
public void setLatlonValid(double[] latlonValid) {
this.latlonValid = latlonValid;
}
}

@Test(expected = IllegalStateException.class)
@Transactional
public void indexAccessWithFullAndNoSpatialIndexNameShouldFail() {
InvalidSpatialIndexed invalidIndexed = persist(new InvalidSpatialIndexed());
double[] latlon = {15.0,65};
invalidIndexed.setLatlonNoIndexName(latlon);
}

@Test(expected = IllegalStateException.class)
@Transactional
public void indexAccessWithDefaultSpatialIndexNameShouldFail() {
InvalidSpatialIndexed invalidIndexed = persist(new InvalidSpatialIndexed());
double[] latlon = {15.0,65};
invalidIndexed.setLatlon( latlon);
}

@Test
@Ignore
@Transactional
public void indexAccessWithValidSpatialIndexName() {
InvalidSpatialIndexed invalidIndexed = persist(new InvalidSpatialIndexed());
double[] latlon = {15.0,65};
invalidIndexed.setLatlonValid( latlon);
}

@Test(expected = IllegalStateException.class)
@Transactional
public void indexAccessWithFullAndNoIndexNameShouldFail() {
Expand Down
Expand Up @@ -29,6 +29,7 @@
import org.springframework.data.neo4j.mapping.Neo4jPersistentEntity;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.index.IndexType;

import javax.persistence.PersistenceUnitUtil;
import java.lang.reflect.Field;
Expand Down Expand Up @@ -104,7 +105,7 @@ private void persistForeignId(Node node, Object id) {
}

private Index<Node> getForeignIdIndex() {
return template.getIndex(type,null,false);
return template.getIndex(type,null,IndexType.SIMPLE);
}

private String createForeignId(Object id) {
Expand Down
Expand Up @@ -6,6 +6,7 @@
import org.springframework.data.neo4j.annotation.RelatedTo;
import org.springframework.data.neo4j.annotation.RelatedToVia;
import org.springframework.data.neo4j.annotation.Indexed;
import org.springframework.data.neo4j.support.index.IndexType;

import java.util.*;

Expand All @@ -22,7 +23,7 @@ public class Movie {
@Indexed
String id;

@Indexed(fulltext = true, indexName = "search")
@Indexed(indexType=IndexType.FULLTEXT, indexName = "search")
String title;

String description;
Expand Down
@@ -1,6 +1,7 @@
package org.neo4j.cineasts.domain;

import org.springframework.data.neo4j.annotation.*;
import org.springframework.data.neo4j.support.index.IndexType;

import java.util.Date;
import java.util.Set;
Expand All @@ -9,7 +10,7 @@
public class Person {
@Indexed
String id;
@Indexed(fulltext = true, indexName = "people")
@Indexed(indexType=IndexType.FULLTEXT, indexName = "people")
String name;
private Date birthday;
private String birthplace;
Expand Down
Expand Up @@ -6,6 +6,7 @@
import org.springframework.data.neo4j.annotation.RelatedTo;
import org.springframework.data.neo4j.annotation.RelatedToVia;
import org.springframework.data.neo4j.annotation.Indexed;
import org.springframework.data.neo4j.support.index.IndexType;

import java.util.*;

Expand All @@ -22,7 +23,7 @@ public class Movie {
@Indexed
String id;

@Indexed(fulltext = true, indexName = "search")
@Indexed(indexType=IndexType.FULLTEXT, indexName = "search")
String title;

String description;
Expand Down
Expand Up @@ -4,6 +4,7 @@
import org.springframework.data.neo4j.annotation.NodeEntity;
import org.springframework.data.neo4j.annotation.RelatedTo;
import org.springframework.data.neo4j.annotation.RelatedToVia;
import org.springframework.data.neo4j.support.index.IndexType;

import java.util.Date;
import java.util.Set;
Expand All @@ -16,7 +17,7 @@
public class Person {
@Indexed
String id;
@Indexed(fulltext = true, indexName = "people")
@Indexed(indexType=IndexType.FULLTEXT, indexName = "people")
String name;
private Date birthday;
private String birthplace;
Expand Down
2 changes: 1 addition & 1 deletion spring-data-neo4j-rest/pom.xml
Expand Up @@ -76,7 +76,7 @@
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-rest-graphdb</artifactId>
<version>1.5.M02</version>
<version>1.5-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.neo4j</groupId>
Expand Down
Expand Up @@ -15,13 +15,16 @@
*/
package org.springframework.data.neo4j.rest;

import java.util.Map;

import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.PropertyContainer;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.index.Index;
import org.neo4j.graphdb.traversal.TraversalDescription;
import org.neo4j.rest.graphdb.*;
import org.neo4j.rest.graphdb.ExecutingRestRequest;
import org.neo4j.rest.graphdb.RestAPI;
import org.neo4j.rest.graphdb.RestRequest;
import org.neo4j.rest.graphdb.index.RestIndexManager;
import org.neo4j.rest.graphdb.query.RestCypherQueryEngine;
Expand All @@ -34,8 +37,6 @@
import org.springframework.data.neo4j.support.query.ConversionServiceQueryResultConverter;
import org.springframework.data.neo4j.support.query.QueryEngine;

import java.util.Map;

public class SpringRestGraphDatabase extends org.neo4j.rest.graphdb.RestGraphDatabase implements GraphDatabase{
private ConversionService conversionService;
private ResultConverter resultConverter;
Expand Down Expand Up @@ -72,8 +73,8 @@ public <T extends PropertyContainer> Index<T> getIndex(String indexName) {
}

@Override
public <T extends PropertyContainer> Index<T> createIndex(Class<T> type, String indexName, boolean fullText) {
return super.getRestAPI().createIndex(type, indexName, fullText);
public <T extends PropertyContainer> Index<T> createIndex(Class<T> type, String indexName, org.springframework.data.neo4j.support.index.IndexType indexType) {
return super.getRestAPI().createIndex(type, indexName, indexType.getConfig());
}

@Override
Expand Down
Expand Up @@ -22,7 +22,6 @@
import org.junit.runner.RunWith;
import org.springframework.data.neo4j.aspects.support.IndexTest;
import org.springframework.data.neo4j.rest.support.RestTestBase;
import org.springframework.data.neo4j.rest.support.RestTestBase;
import org.springframework.test.context.CleanContextCacheTestExecutionListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
Expand Down
Expand Up @@ -16,22 +16,21 @@

package org.springframework.data.neo4j.rest.integration;

import java.io.IOException;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.neo4j.graphdb.GraphDatabaseService;
import org.springframework.dao.DataAccessException;
import org.springframework.data.neo4j.core.GraphDatabase;
import org.springframework.data.neo4j.config.NullTransactionManager;
import org.springframework.data.neo4j.rest.support.RestTestHelper;
import org.springframework.data.neo4j.core.GraphDatabase;
import org.springframework.data.neo4j.rest.support.RestTestHelper;
import org.springframework.data.neo4j.template.Neo4jTemplateApiTest;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.jta.JtaTransactionManager;

import java.io.IOException;

public class RestNeo4jTemplateApiTest extends Neo4jTemplateApiTest
{
private static RestTestHelper testHelper;
Expand Down
Expand Up @@ -18,9 +18,8 @@

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.springframework.data.neo4j.rest.support.RestTestHelper;
import org.springframework.data.neo4j.rest.support.RestTestHelper;
import org.springframework.data.neo4j.core.GraphDatabase;
import org.springframework.data.neo4j.rest.support.RestTestHelper;
import org.springframework.data.neo4j.template.Neo4jTemplateTest;
import org.springframework.transaction.PlatformTransactionManager;

Expand Down
Expand Up @@ -18,9 +18,8 @@

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.springframework.data.neo4j.core.GraphDatabase;
import org.springframework.data.neo4j.config.NullTransactionManager;
import org.springframework.data.neo4j.rest.support.RestTestHelper;
import org.springframework.data.neo4j.core.GraphDatabase;
import org.springframework.data.neo4j.rest.support.RestTestHelper;
import org.springframework.data.neo4j.template.NeoTraversalTest;
import org.springframework.transaction.PlatformTransactionManager;
Expand Down
Expand Up @@ -22,7 +22,6 @@
import org.junit.runner.RunWith;
import org.springframework.data.neo4j.aspects.support.NodeEntityRelationshipTest;
import org.springframework.data.neo4j.rest.support.RestTestBase;
import org.springframework.data.neo4j.rest.support.RestTestBase;
import org.springframework.test.context.CleanContextCacheTestExecutionListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
Expand Down
Expand Up @@ -23,7 +23,6 @@
import org.junit.runner.RunWith;
import org.springframework.data.neo4j.aspects.support.NodeEntityTest;
import org.springframework.data.neo4j.rest.support.RestTestBase;
import org.springframework.data.neo4j.rest.support.RestTestBase;
import org.springframework.test.context.CleanContextCacheTestExecutionListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
Expand Down
Expand Up @@ -22,7 +22,6 @@
import org.junit.runner.RunWith;
import org.springframework.data.neo4j.aspects.support.ProjectionTest;
import org.springframework.data.neo4j.rest.support.RestTestBase;
import org.springframework.data.neo4j.rest.support.RestTestBase;
import org.springframework.test.context.CleanContextCacheTestExecutionListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
Expand Down
Expand Up @@ -22,7 +22,6 @@
import org.junit.runner.RunWith;
import org.springframework.data.neo4j.aspects.support.PropertyTest;
import org.springframework.data.neo4j.rest.support.RestTestBase;
import org.springframework.data.neo4j.rest.support.RestTestBase;
import org.springframework.test.context.CleanContextCacheTestExecutionListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
Expand Down
Expand Up @@ -22,7 +22,6 @@
import org.junit.runner.RunWith;
import org.springframework.data.neo4j.aspects.support.RelationshipEntityTest;
import org.springframework.data.neo4j.rest.support.RestTestBase;
import org.springframework.data.neo4j.rest.support.RestTestBase;
import org.springframework.test.context.CleanContextCacheTestExecutionListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
Expand Down
Expand Up @@ -22,7 +22,6 @@
import org.junit.runner.RunWith;
import org.springframework.data.neo4j.aspects.support.TraversalTest;
import org.springframework.data.neo4j.rest.support.RestTestBase;
import org.springframework.data.neo4j.rest.support.RestTestBase;
import org.springframework.test.context.CleanContextCacheTestExecutionListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
Expand Down
Expand Up @@ -21,7 +21,6 @@
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.aspects.support.query.GremlinQueryEngineTest;
import org.springframework.data.neo4j.aspects.support.query.QueryEngineTest;
import org.springframework.data.neo4j.core.GraphDatabase;
import org.springframework.data.neo4j.rest.SpringRestGraphDatabase;
import org.springframework.test.context.CleanContextCacheTestExecutionListener;
Expand Down
Expand Up @@ -17,6 +17,8 @@
package org.springframework.data.neo4j.rest.support;


import java.util.Iterator;

import org.apache.log4j.BasicConfigurator;
import org.junit.AfterClass;
import org.junit.Before;
Expand All @@ -27,9 +29,6 @@
import org.neo4j.graphdb.Relationship;
import org.springframework.data.neo4j.rest.SpringRestGraphDatabase;

import java.net.URI;
import java.util.Iterator;

public class RestTestBase {

protected SpringRestGraphDatabase restGraphDatabase;
Expand Down
Expand Up @@ -17,13 +17,12 @@
package org.springframework.data.neo4j.rest.support;


import java.net.URISyntaxException;

import org.apache.log4j.BasicConfigurator;
import org.springframework.data.neo4j.core.GraphDatabase;
import org.springframework.data.neo4j.rest.SpringRestGraphDatabase;

import java.net.URI;
import java.net.URISyntaxException;

public class RestTestHelper
{

Expand Down
Expand Up @@ -99,6 +99,11 @@ public <S extends PropertyContainer> Index<S> getIndex(Neo4jPersistentProperty p
final Class<?> declaringType = property.getOwner().getType();
final String providedIndexName = indexedAnnotation.indexName().isEmpty() ? null : indexedAnnotation.indexName();
String indexName = Indexed.Name.get(indexedAnnotation.level(), declaringType, providedIndexName, instanceType);
if (property.getIndexInfo().getIndexType() == IndexType.SIMPLE) {
return getIndex(declaringType, indexName, IndexType.SIMPLE);
}
String defaultIndexName = Indexed.Name.get(indexedAnnotation.level(), declaringType, null, instanceType.getClass());
if (providedIndexName==null || providedIndexName.equals(defaultIndexName)) throw new IllegalStateException("Index name for "+property+" must differ from the default name: "+defaultIndexName);
return getIndex(declaringType, indexName, property.getIndexInfo().getIndexType());
}
}

0 comments on commit f0e81ee

Please sign in to comment.