DATAGRAPH-388 Support for Labels

* make base-package mandatory
* fix tests
This commit is contained in:
Michael Hunger
2014-02-24 10:15:27 +01:00
parent 97ea4c236b
commit 264e7825da
80 changed files with 339 additions and 217 deletions

View File

@@ -32,7 +32,7 @@
<properties>
<project.type>multi</project.type>
<dist.id>spring-data-neo4j</dist.id>
<springdata.commons>1.7.0.RC1</springdata.commons>
<springdata.commons>1.7.0.BUILD-SNAPSHOT</springdata.commons>
<!-- Neo4j 2.0 now requires JDK 7 as a min -->
<source.level>1.7</source.level>

View File

@@ -24,6 +24,8 @@ public class BasePackageScanner {
public static Set<String> scanBasePackages(String...basePackages) {
ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider(false);
componentProvider.addIncludeFilter(new AnnotationTypeFilter(Persistent.class));
componentProvider.addIncludeFilter(new AnnotationTypeFilter(NodeEntity.class));
componentProvider.addIncludeFilter(new AnnotationTypeFilter(RelationshipEntity.class));
Set<String> classes = new ManagedSet<String>();
for (String basePackage : basePackages) {
@@ -35,7 +37,7 @@ public class BasePackageScanner {
return classes;
}
static Set<? extends Class<?>> scanBasePackageForClasses(String...basePackages) throws ClassNotFoundException {
public static Set<? extends Class<?>> scanBasePackageForClasses(String...basePackages) throws ClassNotFoundException {
Set<Class<?>> classes = new HashSet<>();
for (String basePackage : basePackages) {
for (String className : scanBasePackage(basePackage)){

View File

@@ -80,7 +80,7 @@ public class Neo4jAuditingBeanDefinitionParser extends AbstractSingleBeanDefinit
return ctxRef;
}
return "neo4jMappingContext";
return MAPPING_CONTEXT;
}
private String createIsNewStrategyFactoryBeanDefinition(String mappingContextRef, ParserContext context,

View File

@@ -36,6 +36,7 @@ public class DefaultConverter<T,R> implements ResultConverter<T,R> {
return convert(value,type, null);
}
public R convert(Object value, Class type, MappingPolicy mappingPolicy) {
if (type == null) return (R) value;
if (value == null || type.isInstance(value)) return (R) value;
Object singleValue = extractValue(value);
if (singleValue == null || type.isInstance(singleValue)) return (R) singleValue;

View File

@@ -79,7 +79,9 @@ public class RelationshipInfo {
annotation.elementClass() != Object.class ? ClassTypeInformation.from(annotation.elementClass()) : null,
ctx
);
if (relationshipInfo.isRelatedToVia()) throw new MappingException("Relationship field with NodeEntity "+relationshipInfo.getTargetEntity().getType()+" annotated with @RelatedTo");
if (relationshipInfo.isRelatedToVia()) {
throw new MappingException("Relationship field with NodeEntity "+relationshipInfo.getTargetEntity().getType()+" annotated with @RelatedTo");
}
return relationshipInfo;
}
@@ -100,7 +102,9 @@ public class RelationshipInfo {
if (!annotation.type().isEmpty()) return annotation.type();
final TypeInformation<?> relationshipEntityType = elementClass(annotation, typeInformation);
final RelationshipEntity relationshipEntity = relationshipEntityType.getType().getAnnotation(RelationshipEntity.class);
if (relationshipEntity==null) throw new MappingException(typeInformation.getType()+" is no RelationshipEntity");
if (relationshipEntity==null) {
throw new MappingException(typeInformation.getType()+" is no RelationshipEntity");
}
if (relationshipEntity.type()==null || relationshipEntity.type().isEmpty()) {
throw new MappingException("Relationship entity must have a default type");
}

View File

@@ -269,7 +269,7 @@ public class Neo4jTemplate implements Neo4jOperations, ApplicationContextAware {
final Node node = createNode(properties);
if (isNodeEntity(target)) {
final StoredEntityType entityType = getEntityType(target);
infrastructure.getTypeRepresentationStrategies().writeTypeTo(node, entityType);
if (entityType!=null) infrastructure.getTypeRepresentationStrategies().writeTypeTo(node, entityType);
}
return convert(node, target);
}

View File

@@ -16,7 +16,10 @@
package org.springframework.data.neo4j.support.mapping;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.PropertyContainer;
import org.neo4j.graphdb.Relationship;
import org.neo4j.index.lucene.ValueContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.annotation.Reference;
@@ -29,6 +32,7 @@ import org.springframework.data.neo4j.annotation.RelationshipEntity;
import org.springframework.data.neo4j.mapping.InvalidEntityTypeException;
import org.springframework.data.neo4j.mapping.Neo4jPersistentEntity;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import java.beans.PropertyDescriptor;
@@ -70,7 +74,7 @@ public class Neo4jMappingContext extends AbstractMappingContext<Neo4jPersistentE
private void updateStoredEntityType(Neo4jPersistentEntityImpl<?> entity, Collection<Neo4jPersistentEntity<?>> superTypeEntities) {
entity.updateStoredType(new StoredEntityType(entity, superTypeEntities, entityAlias));
entityIndexCreator.ensureEntityIndexes(entity);
if (entityIndexCreator!=null) entityIndexCreator.ensureEntityIndexes(entity);
}
private List<Neo4jPersistentEntity<?>> addSuperTypes(Neo4jPersistentEntity<?> entity) {
@@ -134,7 +138,9 @@ public class Neo4jMappingContext extends AbstractMappingContext<Neo4jPersistentE
}
public StoredEntityType getStoredEntityType(Class type) {
return getPersistentEntity(type).getEntityType();
if (type==null) return null;
Neo4jPersistentEntityImpl<?> persistentEntity = getPersistentEntity(type);
return persistentEntity==null ? null : persistentEntity.getEntityType();
}
@Override
@@ -146,6 +152,7 @@ public class Neo4jMappingContext extends AbstractMappingContext<Neo4jPersistentE
private final Map<Class<?>,Class<?>> annotationCheckCache = new IdentityHashMap<Class<?>, Class<?>>();
public boolean isNodeEntity(Class<?> type) {
if (Node.class.isAssignableFrom(type)) return true;
if (!annotationCheckCache.containsKey(type)) cacheType(type);
return checkAnnotationType(type,NodeEntity.class);
}
@@ -162,6 +169,22 @@ public class Neo4jMappingContext extends AbstractMappingContext<Neo4jPersistentE
}
}
@Override
protected boolean shouldCreatePersistentEntityFor(TypeInformation<?> typeInformation) {
boolean result = super.shouldCreatePersistentEntityFor(typeInformation);
if (!result) return result;
if (typeInformation.isCollectionLike()) return false;
Class<?> type = typeInformation.getType();
if (type.isEnum() || type.isArray() || type.equals(Node.class) || type.equals(Relationship.class) || type.equals(ValueContext.class)) {
return false;
}
String packageName = type.getPackage().getName();
if (packageName.startsWith("java")) {
return false;
}
return true;
}
private boolean checkAnnotationType(Class<?> type, Class<?> annotation) {
final Class<?> marker = annotationCheckCache.get(type);
return marker==annotation;

View File

@@ -3,22 +3,14 @@ package org.springframework.data.neo4j.support.schema;
import org.neo4j.graphdb.Transaction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.neo4j.graphdb.event.TransactionData;
import org.neo4j.graphdb.event.TransactionEventHandler;
import org.springframework.data.mapping.model.MappingException;
import org.springframework.data.neo4j.annotation.QueryType;
import org.springframework.data.neo4j.conversion.EndResult;
import org.springframework.data.neo4j.core.GraphDatabase;
import org.springframework.data.neo4j.mapping.IndexInfo;
import org.springframework.data.neo4j.mapping.Neo4jPersistentEntity;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.support.DelegatingGraphDatabase;
import org.springframework.data.neo4j.support.query.QueryEngine;
import java.util.Queue;
import java.util.concurrent.*;
import static java.lang.String.format;
import static org.neo4j.helpers.collection.MapUtil.map;
/**
@@ -30,33 +22,17 @@ public class SchemaIndexProvider {
private final QueryEngine<Object> cypher;
private static final Logger logger = LoggerFactory.getLogger(SchemaIndexProvider.class);
private final IndexCreator indexCreator;
public SchemaIndexProvider(GraphDatabase gd) {
this.gd = gd;
indexCreator = setupIndexCreator();
cypher = gd.queryEngineFor(QueryType.Cypher);
}
private IndexCreator setupIndexCreator() {
// if (this.gd instanceof DelegatingGraphDatabase) {
// TransactionalHandler handler = new TransactionalHandler();
// ((DelegatingGraphDatabase)this.gd).getGraphDatabaseService().registerTransactionEventHandler(handler);
// return handler;
// } else {
// return new SeparateThreadIndexCreator();
// }
return new InlineCreator();
}
public void createIndex(Neo4jPersistentProperty property) {
indexCreator.deferCreateIndex(property);
}
public void doCreateIndex(Neo4jPersistentProperty property) {
String label = getLabel(property);
String prop = getName(property);
String query = indexQuery(label, prop, property.getIndexInfo().isUnique());
System.err.println(query);
if (logger.isInfoEnabled()) logger.info(query);
cypher.query(query, null);
}
@@ -100,90 +76,4 @@ public class SchemaIndexProvider {
interface IndexCreator {
void deferCreateIndex(Neo4jPersistentProperty property);
}
private class TransactionalHandler extends TransactionEventHandler.Adapter<Object> implements IndexCreator {
Queue<Neo4jPersistentProperty> indexesToBeCreated=new ArrayBlockingQueue<>(10);
@Override
public void afterCommit(TransactionData data, Object state) {
runAfterTransaction();
}
private void runAfterTransaction() {
while (gd.transactionIsRunning()) {
try {
Thread.sleep(1);
} catch (InterruptedException e) { }
}
if (gd.transactionIsRunning()) return;
if (indexesToBeCreated.isEmpty()) return;
try (Transaction tx = gd.beginTx()) {
while (!indexesToBeCreated.isEmpty()) {
Neo4jPersistentProperty property = indexesToBeCreated.poll();
doCreateIndex(property);
}
tx.success();
}
}
@Override
public void afterRollback(TransactionData data, Object state) {
runAfterTransaction();
}
@Override
public void deferCreateIndex(Neo4jPersistentProperty property) {
indexesToBeCreated.add(property);
}
}
private class InlineCreator implements IndexCreator {
@Override
public void deferCreateIndex(Neo4jPersistentProperty property) {
doCreateIndex(property);
}
}
private class SeparateThreadIndexCreator implements IndexCreator {
private final ExecutorService pool = Executors.newFixedThreadPool(1);
@Override
public void deferCreateIndex(final Neo4jPersistentProperty property) {
/* 1) NW-ISSUE01
If we don't do this in a separate tx we get the following
error depending on certain circumstances .... :
"org.neo4j.cypher.CypherExecutionException: Cannot perform
schema updates in a transaction that has performed data updates."
HOWEVER, even doing this does not necessarily work in all cases as
often it appears that there have been some previous updates in the
original calling thread, which itself took out some locks and then
essentially blocks this code from ever completing ... As a temp
measure introducing a timeout to catch this case rather than letting
it just hang forever (see LabelBasedIndexedPropertyHangingEntityTests)
TODO: Look at an alternative approach / way to ensure these schema
updates are the first things done - this is not very efficient
as it stands anyway
*/
try {
pool.submit(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
doCreateIndex(property);
return true;
}
}).get(2, TimeUnit.SECONDS);
} catch (TimeoutException e) {
throw new MappingException(format(
"Timeour occured trying to create schema index %s on against label %s: " +
"This may well be an indicator that another thread (the one which just " +
"initiated this update), has probably got a lock of " +
"this node and this timeout is because its in a deadlock situation and" +
" cant acquire it - investigation required", getName(property), getLabel(property)),e);
} catch (Exception e) {
throw new MappingException(format("Unable to create schema index %s on against label %s", getName(property), getLabel(property)),e);
}
}
}
}

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.annotation.relatedto.bidirectional;
package org.springframework.data.neo4j.annotation.relatedto;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.annotation.relatedto.bidirectional;
package org.springframework.data.neo4j.annotation.relatedto;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.annotation.relatedto.bidirectional;
package org.springframework.data.neo4j.annotation.relatedto;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.annotation.relatedto.bidirectional;
package org.springframework.data.neo4j.annotation.relatedto;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@@ -28,13 +28,13 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.GenericConverter;
import org.springframework.data.neo4j.config.model.TestEntity;
import org.springframework.data.neo4j.model.PersonRepository;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.mapping.Neo4jMappingContext;
import org.springframework.data.neo4j.support.mapping.Neo4jPersistentEntityImpl;
import org.springframework.transaction.PlatformTransactionManager;
import java.io.File;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;

View File

@@ -22,7 +22,7 @@ import org.neo4j.test.TestGraphDatabaseFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.repository.PersonRepository;
import org.springframework.data.neo4j.repositories.PersonRepository;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -36,10 +36,13 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
public class Neo4jRepositoriesRegistrarIntegrationTests {
@Configuration
@EnableNeo4jRepositories(basePackages = "org.springframework.data.neo4j.repository")
@EnableNeo4jRepositories(basePackages = "org.springframework.data.neo4j.repositories")
static class Config extends Neo4jConfiguration {
Config() throws ClassNotFoundException {
setBasePackage("org.springframework.data.neo4j.model");
}
@Bean
@Bean
public GraphDatabaseService graphDatabaseService() {
return new TestGraphDatabaseFactory().newImpermanentDatabase();
}

View File

@@ -25,8 +25,9 @@ import org.neo4j.test.TestGraphDatabaseFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.repository.ClassWithNestedRepository.NestedUserRepository;
import org.springframework.data.neo4j.repository.PersonRepository;
import org.springframework.data.neo4j.model.Person;
import org.springframework.data.neo4j.repositories.ClassWithNestedRepository.NestedUserRepository;
import org.springframework.data.neo4j.repositories.PersonRepository;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -42,8 +43,11 @@ public class NestedNeo4jRepositoriesJavaConfigTests {
@Configuration
@EnableNeo4jRepositories(basePackageClasses = PersonRepository.class, considerNestedRepositories = true)
static class Config extends Neo4jConfiguration {
Config() throws ClassNotFoundException {
setBasePackage(Person.class.getPackage().getName());
}
@Bean
@Bean
public GraphDatabaseService graphDatabaseService() {
return new TestGraphDatabaseFactory().newImpermanentDatabase();
}

View File

@@ -21,7 +21,7 @@ import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.repository.ClassWithNestedRepository.NestedUserRepository;
import org.springframework.data.neo4j.repositories.ClassWithNestedRepository.NestedUserRepository;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.neo4j.config;
package org.springframework.data.neo4j.config.model;
import org.springframework.data.neo4j.annotation.GraphId;
import org.springframework.data.neo4j.annotation.NodeEntity;

View File

@@ -22,6 +22,7 @@ import org.springframework.data.neo4j.mapping.Neo4jPersistentTestBase;
import org.springframework.data.neo4j.model.Friendship;
import org.springframework.data.neo4j.model.Person;
import org.springframework.data.neo4j.support.conversion.NoSuchColumnFoundException;
import org.springframework.data.neo4j.support.mapping.Neo4jMappingContext;
import java.util.HashMap;
import java.util.HashSet;
@@ -63,6 +64,11 @@ public class QueryMapResultConverterTests extends Neo4jPersistentTestBase {
Iterable<String> getFriendNames();
}
@Override
protected void setBasePackage(Neo4jMappingContext mappingContext) throws ClassNotFoundException {
super.setBasePackage(mappingContext,Person.class.getPackage().getName());
}
@Before
public void init() throws Exception {
storeInGraph( michael );
@@ -151,4 +157,4 @@ public class QueryMapResultConverterTests extends Neo4jPersistentTestBase {
private QueryMapResultConverter<SimplestQuery> getConverter() {
return new QueryMapResultConverter<SimplestQuery>( template );
}
}
}

View File

@@ -114,6 +114,10 @@ public class EqualityTests {
@Configuration
@EnableNeo4jRepositories
static class TestConfig extends Neo4jConfiguration {
TestConfig() throws ClassNotFoundException {
setBasePackage("org.springframework.data.neo4j.equality");
}
@Bean
GraphDatabaseService graphDatabaseService() {
return new TestGraphDatabaseFactory().newImpermanentDatabase();

View File

@@ -79,6 +79,11 @@ public class PropertyTypeConversionTests {
@Configuration
@EnableNeo4jRepositories
static class TestConfig extends Neo4jConfiguration {
TestConfig() throws ClassNotFoundException {
setBasePackage(EntityWithCustomTypeProperty.class.getPackage().getName());
}
@Bean
GraphDatabaseService graphDatabaseService() {
return new TestGraphDatabaseFactory().newImpermanentDatabase();

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.mapping.invalid;
package org.springframework.data.neo4j.invalid.model;
import org.junit.Test;
import org.springframework.data.mapping.context.MappingContext;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.unique.domain;
package org.springframework.data.neo4j.invalid.unique;
import org.springframework.data.neo4j.annotation.GraphId;
import org.springframework.data.neo4j.annotation.Indexed;

View File

@@ -13,11 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.unique.repository;
package org.springframework.data.neo4j.invalid.unique;
import org.springframework.data.neo4j.repository.GraphRepository;
import org.springframework.data.neo4j.repository.NamedIndexRepository;
import org.springframework.data.neo4j.unique.domain.InvalidClub;
public interface InvalidClubRepository extends GraphRepository<InvalidClub>, NamedIndexRepository<InvalidClub> {

View File

@@ -0,0 +1,48 @@
/**
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.invalid.unique;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.neo4j.graphdb.GraphDatabaseService;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.mapping.model.MappingException;
import org.springframework.data.neo4j.unique.domain.Club;
import org.springframework.data.neo4j.unique.domain.UniqueClub;
import org.springframework.data.neo4j.unique.domain.UniqueNumericIdClub;
import org.springframework.data.neo4j.unique.repository.ClubRepository;
import org.springframework.data.neo4j.unique.repository.UniqueClubRepository;
import org.springframework.data.neo4j.unique.repository.UniqueNumericIdClubRepository;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import static org.junit.Assert.assertEquals;
public class InvalidUniqueEntityTests {
@Test(expected = BeanCreationException.class)
public void shouldThrowExceptionWhenMultipleUniqueSpecified() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:invalid-unique-test-context.xml");
InvalidClubRepository invalidClubRepository = ctx.getBean(InvalidClubRepository.class);
InvalidClub club = new InvalidClub();
invalidClubRepository.save(club);
}
}

View File

@@ -48,6 +48,10 @@ public class AfterDeleteEventTests {
@Configuration
@EnableNeo4jRepositories
static class TestConfig extends Neo4jConfiguration {
TestConfig() throws ClassNotFoundException {
setBasePackage(Program.class.getPackage().getName());
}
@Bean
GraphDatabaseService graphDatabaseService() {
return new TestGraphDatabaseFactory().newImpermanentDatabase();

View File

@@ -51,6 +51,9 @@ public class AfterSaveEventTests {
@Configuration
@EnableNeo4jRepositories
static class TestConfig extends Neo4jConfiguration {
TestConfig() throws ClassNotFoundException {
setBasePackage(Bar.class.getPackage().getName());
}
@Bean
GraphDatabaseService graphDatabaseService() {
return new TestGraphDatabaseFactory().newImpermanentDatabase();

View File

@@ -50,6 +50,9 @@ public class BeforeDeleteEventTests {
@Configuration
@EnableNeo4jRepositories
static class TestConfig extends Neo4jConfiguration {
TestConfig() throws ClassNotFoundException {
setBasePackage(Program.class.getPackage().getName());
}
@Bean
GraphDatabaseService graphDatabaseService() {
return new TestGraphDatabaseFactory().newImpermanentDatabase();

View File

@@ -51,6 +51,9 @@ public class BeforeSaveEventTests {
@Configuration
@EnableNeo4jRepositories
static class TestConfig extends Neo4jConfiguration {
TestConfig() throws ClassNotFoundException {
setBasePackage(Foo.class.getPackage().getName());
}
@Bean
GraphDatabaseService graphDatabaseService() {
return new TestGraphDatabaseFactory().newImpermanentDatabase();

View File

@@ -68,6 +68,9 @@ public class DeleteEventTests {
@Configuration
@EnableNeo4jRepositories
static class TestConfig extends Neo4jConfiguration {
TestConfig() throws ClassNotFoundException {
setBasePackage(DeprecatedProgram.class.getPackage().getName());
}
@Bean
GraphDatabaseService graphDatabaseService() {
return new TestGraphDatabaseFactory().newImpermanentDatabase();
@@ -110,4 +113,4 @@ public class DeleteEventTests {
assertThat(deletions, hasItem(sark));
}
}
}

View File

@@ -176,6 +176,11 @@ public class SaveEventTests {
@Configuration
@EnableNeo4jRepositories
static class TestConfig extends Neo4jConfiguration {
public TestConfig() throws ClassNotFoundException {
setBasePackage(SaveEventTests.class.getPackage().getName());
}
@Bean
GraphDatabaseService graphDatabaseService() {
return new TestGraphDatabaseFactory().newImpermanentDatabase();

View File

@@ -25,6 +25,7 @@ import org.springframework.data.convert.DefaultTypeMapper;
import org.springframework.data.convert.TypeMapper;
import org.springframework.data.neo4j.annotation.GraphId;
import org.springframework.data.neo4j.annotation.NodeEntity;
import org.springframework.data.neo4j.config.BasePackageScanner;
import org.springframework.data.neo4j.fieldaccess.DelegatingFieldAccessorFactory;
import org.springframework.data.neo4j.fieldaccess.FieldAccessorFactoryFactory;
import org.springframework.data.neo4j.fieldaccess.Neo4jConversionServiceFactoryBean;
@@ -36,12 +37,14 @@ import org.springframework.data.neo4j.support.DelegatingGraphDatabase;
import org.springframework.data.neo4j.support.Infrastructure;
import org.springframework.data.neo4j.support.MappingInfrastructureFactoryBean;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.index.IndexProviderImpl;
import org.springframework.data.neo4j.support.mapping.*;
import org.springframework.data.neo4j.support.node.EntityStateFactory;
import org.springframework.data.neo4j.support.node.NodeEntityInstantiator;
import org.springframework.data.neo4j.support.node.NodeEntityStateFactory;
import org.springframework.data.neo4j.support.relationship.RelationshipEntityInstantiator;
import org.springframework.data.neo4j.support.relationship.RelationshipEntityStateFactory;
import org.springframework.data.neo4j.support.schema.SchemaIndexProvider;
import org.springframework.data.neo4j.support.typerepresentation.ClassValueTypeInformationMapper;
import org.springframework.data.neo4j.support.typerepresentation.NoopNodeTypeRepresentationStrategy;
import org.springframework.data.neo4j.support.typerepresentation.NoopRelationshipTypeRepresentationStrategy;
@@ -82,8 +85,8 @@ public class Neo4jPersistentTestBase {
@NodeEntity
public static class Developer {
@GraphId
Long id;
String name;
public Long id;
public String name;
}
@Before
@@ -131,6 +134,9 @@ public class Neo4jPersistentTestBase {
factoryBean.setNodeEntityStateFactory(nodeEntityStateFactory);
factoryBean.setRelationshipEntityStateFactory(relationshipEntityStateFactory);
mappingContext.setEntityIndexCreator(new EntityIndexCreator(new IndexProviderImpl(graphDatabase), new SchemaIndexProvider(graphDatabase)));
mappingContext.setSimpleTypeHolder(null);
setBasePackage(mappingContext);
nodeEntityInstantiator = new NodeEntityInstantiator(entityStateHandler);
relationshipEntityInstantiator = new RelationshipEntityInstantiator(entityStateHandler);
@@ -143,11 +149,19 @@ public class Neo4jPersistentTestBase {
final EntityTools<Relationship> relationshipEntityTools = new EntityTools<Relationship>(relationshipTypeRepresentationStrategy, relationshipEntityStateFactory, relationshipEntityInstantiator, mappingContext);
entityPersister = new Neo4jEntityPersister(conversionService, nodeEntityTools, relationshipEntityTools, mappingContext, entityStateHandler);
mappingContext.afterPropertiesSet();
factoryBean.afterPropertiesSet();
return factoryBean.getObject();
}
protected void setBasePackage(Neo4jMappingContext mappingContext) throws ClassNotFoundException {
setBasePackage(mappingContext, getClass().getPackage().getName());
}
protected void setBasePackage(Neo4jMappingContext mappingContext, String...basePackages) throws ClassNotFoundException {
mappingContext.setInitialEntitySet(BasePackageScanner.scanBasePackageForClasses(basePackages));
}
protected List<Node> groupMemberNodes() {
return groupMemberNodes(groupNode());
}
@@ -158,8 +172,10 @@ public class Neo4jPersistentTestBase {
@After
public void tearDown() throws Exception {
tx.failure();
tx.close();
if (tx!=null) {
tx.failure();
tx.close();
}
template.getGraphDatabaseService().shutdown();
}

View File

@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.mapping;
package org.springframework.data.neo4j.mapping.context;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.mapping.model.MappingException;
import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty;
import org.springframework.data.neo4j.model.Person;
import org.springframework.data.neo4j.invalid.model.PrimitiveIdEntity;
import org.springframework.data.neo4j.support.index.IndexType;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.mapping;
package org.springframework.data.neo4j.mapping.converter;
import org.junit.Test;
import org.neo4j.graphdb.Direction;
@@ -22,10 +22,12 @@ import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.index.Index;
import org.neo4j.helpers.collection.IteratorUtil;
import org.springframework.data.neo4j.mapping.Neo4jPersistentTestBase;
import org.springframework.data.neo4j.model.Friendship;
import org.springframework.data.neo4j.model.Group;
import org.springframework.data.neo4j.model.Person;
import org.springframework.data.neo4j.model.Personality;
import org.springframework.data.neo4j.support.mapping.Neo4jMappingContext;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collection;
@@ -70,6 +72,10 @@ public class Neo4jEntityConverterTests extends Neo4jPersistentTestBase {
*/
@Override
protected void setBasePackage(Neo4jMappingContext mappingContext) throws ClassNotFoundException {
super.setBasePackage(mappingContext,Person.class.getPackage().getName());
}
@Test
public void testWriteEntityToNewNode() {

View File

@@ -13,13 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.mapping;
package org.springframework.data.neo4j.mapping.persist;
import org.junit.Test;
import org.mockito.Mockito;
import org.neo4j.graphdb.Node;
import org.springframework.data.neo4j.mapping.ManagedEntity;
import org.springframework.data.neo4j.mapping.Neo4jPersistentTestBase;
import org.springframework.data.neo4j.model.Friendship;
import org.springframework.data.neo4j.model.Person;
import org.springframework.data.neo4j.support.mapping.Neo4jMappingContext;
import org.springframework.transaction.annotation.Transactional;
import static java.util.Arrays.asList;
@@ -33,6 +36,11 @@ import static org.junit.Assert.assertNotSame;
*/
public class Neo4jEntityPersisterTests extends Neo4jPersistentTestBase {
@Override
protected void setBasePackage(Neo4jMappingContext mappingContext) throws ClassNotFoundException {
super.setBasePackage(mappingContext,Person.class.getPackage().getName(),Developer.class.getPackage().getName());
}
@Test
public void testCreateEntityFromStoredType() throws Exception {
final Node personNode = template.createNode();

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.mapping;
package org.springframework.data.neo4j.mapping.persist;
import org.junit.Before;
import org.junit.Test;
@@ -24,6 +24,8 @@ import org.springframework.data.neo4j.support.mapping.Neo4jMappingContext;
import org.springframework.data.neo4j.support.mapping.Neo4jPersistentEntityImpl;
import org.springframework.data.neo4j.support.mapping.StoredEntityType;
import java.util.Collections;
import static org.junit.Assert.assertEquals;
/**
@@ -38,6 +40,7 @@ public class Neo4jPersistentEntityTests {
@Before
public void setUp() throws Exception {
mappingContext = new Neo4jMappingContext();
mappingContext.setInitialEntitySet(Collections.singleton(Person.class));
personType = mappingContext.getPersistentEntity(Person.class);
}

View File

@@ -1,4 +1,4 @@
package org.springframework.data.neo4j.repository;
package org.springframework.data.neo4j.repositories;
import org.springframework.data.neo4j.model.AbstractNodeEntity;
import org.springframework.data.neo4j.repository.GraphRepository;

View File

@@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.repository;
package org.springframework.data.neo4j.repositories;
import org.springframework.data.neo4j.model.Being;
import org.springframework.data.neo4j.repository.GraphRepository;
/**
* @author mh

View File

@@ -1,4 +1,4 @@
package org.springframework.data.neo4j.repository;
package org.springframework.data.neo4j.repositories;
import org.springframework.data.neo4j.model.Person;
import org.springframework.data.repository.Repository;

View File

@@ -14,9 +14,10 @@
* limitations under the License.
*/
package org.springframework.data.neo4j.repository;
package org.springframework.data.neo4j.repositories;
import org.springframework.data.neo4j.model.Friendship;
import org.springframework.data.neo4j.repository.GraphRepository;
public interface FriendshipRepository extends GraphRepository<Friendship> {
}

View File

@@ -14,11 +14,13 @@
* limitations under the License.
*/
package org.springframework.data.neo4j.repository;
package org.springframework.data.neo4j.repositories;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.neo4j.model.Group;
import org.springframework.data.neo4j.repository.GraphRepository;
import org.springframework.data.neo4j.repository.NamedIndexRepository;
/**

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.neo4j.repository;
package org.springframework.data.neo4j.repositories;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
@@ -26,6 +26,7 @@ import org.springframework.data.neo4j.annotation.ResultColumn;
import org.springframework.data.neo4j.conversion.EndResult;
import org.springframework.data.neo4j.model.Group;
import org.springframework.data.neo4j.model.Person;
import org.springframework.data.neo4j.repository.*;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.repository;
package org.springframework.data.neo4j.repositories;
import org.springframework.data.neo4j.model.Friendship;
import org.springframework.data.neo4j.model.Person;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.repository;
package org.springframework.data.neo4j.repositories;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.model.Friendship;

View File

@@ -14,13 +14,14 @@
* limitations under the License.
*/
package org.springframework.data.neo4j.repository;
package org.springframework.data.neo4j.repositories;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.conversion.EndResult;
import org.springframework.data.neo4j.model.Person;
import org.springframework.data.neo4j.repository.GraphRepository;
/**
* @author Thomas Darimont

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.repository;
package org.springframework.data.neo4j.repositories;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.model.Car;
@@ -21,7 +21,7 @@ import org.springframework.data.neo4j.model.User;
import org.springframework.data.neo4j.repository.GraphRepository;
import org.springframework.data.repository.query.Param;
interface UserRepository extends GraphRepository<User> {
public interface UserRepository extends GraphRepository<User> {
@Query("start user=node:User(name={name}) match user-[:Loves]->car return car limit 1")
public Car getSingleCar(@Param("name") String name);
}

View File

@@ -26,6 +26,8 @@ import org.springframework.data.neo4j.model.AbstractNodeEntity;
import org.springframework.data.neo4j.model.Concrete1NodeEntity;
import org.springframework.data.neo4j.model.Concrete2NodeEntity;
import org.springframework.data.neo4j.model.Person;
import org.springframework.data.neo4j.repositories.AbstractNodeEntityRepository;
import org.springframework.data.neo4j.repositories.PersonRepository;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.node.Neo4jHelper;
import org.springframework.test.context.CleanContextCacheTestExecutionListener;

View File

@@ -30,6 +30,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.neo4j.model.Person;
import org.springframework.data.neo4j.model.QPerson;
import org.springframework.data.neo4j.repositories.PersonRepository;
import org.springframework.data.neo4j.template.Neo4jOperations;
import org.springframework.test.context.CleanContextCacheTestExecutionListener;
import org.springframework.test.context.ContextConfiguration;
@@ -58,7 +59,8 @@ import static org.neo4j.helpers.collection.MapUtil.map;
@Ignore
public class CypherDslRepositoryTests {
@Autowired PersonRepository personRepository;
@Autowired
PersonRepository personRepository;
@Autowired Neo4jOperations template;
private TestTeam team;
private Map<String,Object> peopleParams;

View File

@@ -175,6 +175,10 @@ public class DerivedFinderTests {
@EnableNeo4jRepositories
static class TestConfig extends Neo4jConfiguration {
TestConfig() throws ClassNotFoundException {
setBasePackage("org.springframework.data.neo4j.repository","org.springframework.data.neo4j.model");
}
@Bean
GraphDatabaseService graphDatabaseService() {
return new TestGraphDatabaseFactory().newImpermanentDatabase();

View File

@@ -30,6 +30,8 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.neo4j.model.*;
import org.springframework.data.neo4j.repositories.*;
import org.springframework.data.neo4j.repositories.FriendshipRepository;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.ReferenceNodes;
import org.springframework.data.neo4j.support.conversion.NoSuchColumnFoundException;
@@ -79,11 +81,11 @@ public class GraphRepositoryTests {
private PlatformTransactionManager transactionManager;
@Autowired
private PersonRepository personRepository;
private org.springframework.data.neo4j.repositories.PersonRepository personRepository;
@Autowired
private BeingRepository beingRepository;
@Autowired
GroupRepository groupRepository;
org.springframework.data.neo4j.repositories.GroupRepository groupRepository;
@Autowired
FriendshipRepository friendshipRepository;
@@ -213,7 +215,7 @@ public class GraphRepositoryTests {
@Test @Transactional
public void testFindQueryResultWithCollection() {
PersonRepository.TeamResult teamMembers = personRepository.findAllTeamMembersAsGroup(testTeam.sdg);
org.springframework.data.neo4j.repositories.PersonRepository.TeamResult teamMembers = personRepository.findAllTeamMembersAsGroup(testTeam.sdg);
assertThat( teamMembers.getName(), is( testTeam.sdg.getName() ) );
assertThat( asCollection( teamMembers.getMembers() ), hasItems( testTeam.michael, testTeam.david, testTeam.emil ) );
}
@@ -471,8 +473,8 @@ public class GraphRepositoryTests {
@Transactional
public void findWithMapResult() throws InterruptedException
{
Iterable<PersonRepository.NameAndPersonResult> result = personRepository.getAllNamesAndPeople();
PersonRepository.NameAndPersonResult nameAndPerson = IteratorUtil.first( result );
Iterable<org.springframework.data.neo4j.repositories.PersonRepository.NameAndPersonResult> result = personRepository.getAllNamesAndPeople();
org.springframework.data.neo4j.repositories.PersonRepository.NameAndPersonResult nameAndPerson = IteratorUtil.first( result );
assertEquals( testTeam.david.getName(), nameAndPerson.getName() );
assertEquals( testTeam.david, nameAndPerson.getPerson() );
}

View File

@@ -33,6 +33,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.conversion.EndResult;
import org.springframework.data.neo4j.model.Group;
import org.springframework.data.neo4j.model.Person;
import org.springframework.data.neo4j.repositories.GroupRepository;
import org.springframework.data.neo4j.repositories.PersonRepository;
import org.springframework.test.context.CleanContextCacheTestExecutionListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

View File

@@ -25,6 +25,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.neo4j.conversion.EndResult;
import org.springframework.data.neo4j.model.Person;
import org.springframework.data.neo4j.repositories.RedeclaringRepositoryMethodsRepository;
import org.springframework.transaction.annotation.Transactional;
/**
@@ -33,7 +34,8 @@ import org.springframework.transaction.annotation.Transactional;
@Transactional
public class RedeclaringRepositoryMethodsTests extends AbstractEntityBasedGraphRepositoryTests {
@Autowired RedeclaringRepositoryMethodsRepository repository;
@Autowired
RedeclaringRepositoryMethodsRepository repository;
/**
* @see DATAGRAPH-392

View File

@@ -27,6 +27,9 @@ import org.springframework.data.neo4j.fieldaccess.ManagedFieldAccessorSet;
import org.springframework.data.neo4j.fieldaccess.ManagedPrefixedDynamicProperties;
import org.springframework.data.neo4j.fieldaccess.PrefixedDynamicProperties;
import org.springframework.data.neo4j.model.Person;
import org.springframework.data.neo4j.repositories.FriendshipRepository;
import org.springframework.data.neo4j.repositories.GroupRepository;
import org.springframework.data.neo4j.repositories.PersonRepository;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.node.Neo4jHelper;
import org.springframework.data.neo4j.template.GraphCallback;

View File

@@ -22,6 +22,9 @@ import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.repositories.FriendshipRepository;
import org.springframework.data.neo4j.repositories.GroupRepository;
import org.springframework.data.neo4j.repositories.PersonRepository;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.node.Neo4jHelper;
import org.springframework.test.context.CleanContextCacheTestExecutionListener;

View File

@@ -24,6 +24,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.neo4j.model.Person;
import org.springframework.data.neo4j.repositories.FriendshipRepository;
import org.springframework.data.neo4j.repositories.GroupRepository;
import org.springframework.data.neo4j.repositories.PersonRepository;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.node.Neo4jHelper;
import org.springframework.test.context.CleanContextCacheTestExecutionListener;
@@ -59,7 +62,8 @@ public class SpatialGraphRepositoryTests {
@Autowired
GroupRepository groupRepository;
@Autowired FriendshipRepository friendshipRepository;
@Autowired
FriendshipRepository friendshipRepository;
@Autowired

View File

@@ -114,6 +114,11 @@ public class InParameterisedByArrayOfSimpleTypeTests {
@Configuration
@EnableNeo4jRepositories
static class TestConfig extends Neo4jConfiguration {
TestConfig() throws ClassNotFoundException {
setBasePackage(SimpleTypeArrayEntity.class.getPackage().getName());
}
@Bean
GraphDatabaseService graphDatabaseService() {
return new TestGraphDatabaseFactory().newImpermanentDatabase();
@@ -186,4 +191,4 @@ public class InParameterisedByArrayOfSimpleTypeTests {
public void shouldSupportCharArrayAsParameterForIn() throws Exception {
assertThat(simpleTypeArrayEntityRepository.findUsingChar(asList(CHARS)).chars, is(CHARS));
}
}
}

View File

@@ -84,6 +84,10 @@ public class InParameterisedByDateTests {
@Configuration
@EnableNeo4jRepositories
static class TestConfig extends Neo4jConfiguration {
TestConfig() throws ClassNotFoundException {
setBasePackage(DateEntity.class.getPackage().getName());
}
@Bean
GraphDatabaseService graphDatabaseService() {
return new TestGraphDatabaseFactory().newImpermanentDatabase();
@@ -127,4 +131,4 @@ public class InParameterisedByDateTests {
Iterable<Date[]> dates = asList(new Date[]{TODAY, TOMORROW}, new Date[]{YESTERDAY});
assertThat(dateEntityRepository.findUsingArrayOfArrayOfDate(dates).date, is(TODAY));
}
}
}

View File

@@ -85,6 +85,11 @@ public class InParameterisedByEnumTests {
@Configuration
@EnableNeo4jRepositories
static class TestConfig extends Neo4jConfiguration {
TestConfig() throws ClassNotFoundException {
setBasePackage(EnumEntity.class.getPackage().getName());
}
@Bean
GraphDatabaseService graphDatabaseService() {
return new TestGraphDatabaseFactory().newImpermanentDatabase();
@@ -128,4 +133,4 @@ public class InParameterisedByEnumTests {
assertThat(enumEntityRepository.findUsingArrayOfArrayOfString(asList(new String[]{"CLUB", "DIAMOND", "HEART"}, new String[]{"SPADE", "DIAMOND"})).suit, is(SPADE));
assertThat(enumEntityRepository.findUsingArrayOfArrayOfEnum(asList(new Suit[]{CLUB, DIAMOND, HEART}, new Suit[]{SPADE, DIAMOND})).suit, is(SPADE));
}
}
}

View File

@@ -106,6 +106,10 @@ public class InParameterisedBySimpleTypeTests {
@Configuration
@EnableNeo4jRepositories
static class TestConfig extends Neo4jConfiguration {
TestConfig() throws ClassNotFoundException {
setBasePackage(SimpleTypeEntity.class.getPackage().getName());
}
@Bean
GraphDatabaseService graphDatabaseService() {
return new TestGraphDatabaseFactory().newImpermanentDatabase();
@@ -157,4 +161,4 @@ public class InParameterisedBySimpleTypeTests {
assertThat(simpleTypeEntityRepository.findUsingChar(CHAR).aChar, is(CHAR));
assertThat(simpleTypeEntityRepository.findUsingString(STRING).aString, is(STRING));
}
}
}

View File

@@ -70,6 +70,10 @@ public class ParameterisedInTests {
@Configuration
@EnableNeo4jRepositories
static class TestConfig extends Neo4jConfiguration {
TestConfig() throws ClassNotFoundException {
setBasePackage(RandomEntity.class.getPackage().getName());
}
@Bean
GraphDatabaseService graphDatabaseService() {
return new TestGraphDatabaseFactory().newImpermanentDatabase();
@@ -113,4 +117,4 @@ public class ParameterisedInTests {
public void shouldSupportParametersAsVarargs() throws Exception {
assertThat(randomEntityRepository.findUsingVarargs("Louie").name, is("Louie"));
}
}
}

View File

@@ -23,11 +23,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.mapping.model.MappingException;
import org.springframework.data.neo4j.unique.domain.Club;
import org.springframework.data.neo4j.unique.domain.InvalidClub;
import org.springframework.data.neo4j.invalid.unique.InvalidClub;
import org.springframework.data.neo4j.unique.domain.UniqueClub;
import org.springframework.data.neo4j.unique.domain.UniqueNumericIdClub;
import org.springframework.data.neo4j.unique.repository.ClubRepository;
import org.springframework.data.neo4j.unique.repository.InvalidClubRepository;
import org.springframework.data.neo4j.invalid.unique.InvalidClubRepository;
import org.springframework.data.neo4j.unique.repository.UniqueClubRepository;
import org.springframework.data.neo4j.unique.repository.UniqueNumericIdClubRepository;
import org.springframework.test.context.ContextConfiguration;
@@ -47,9 +47,6 @@ public class UniqueEntityTests {
@Autowired
private UniqueClubRepository uniqueClubRepository;
@Autowired
private InvalidClubRepository invalidClubRepository;
@Autowired
protected GraphDatabaseService graphDatabaseService;
@@ -153,9 +150,4 @@ public class UniqueEntityTests {
uniqueClubRepository.save(club);
assertEquals(club.getId(),uniqueClubRepository.findByPropertyValue("name","bar").getId());
}
@Test(expected = MappingException.class)
public void shouldThrowExceptionWhenMultipleUniqueSpecified() {
InvalidClub club = new InvalidClub();
invalidClubRepository.save(club);
}
}

View File

@@ -23,6 +23,7 @@ import org.neo4j.graphdb.Relationship;
import org.springframework.data.neo4j.mapping.Neo4jPersistentTestBase;
import org.springframework.data.neo4j.model.BestFriend;
import org.springframework.data.neo4j.model.Person;
import org.springframework.data.neo4j.support.mapping.Neo4jMappingContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -34,6 +35,11 @@ import static org.junit.Assert.assertNotSame;
*/
public class UniqueRelationshipTests extends Neo4jPersistentTestBase {
@Override
protected void setBasePackage(Neo4jMappingContext mappingContext) throws ClassNotFoundException {
super.setBasePackage(mappingContext,Person.class.getPackage().getName());
}
@Test
public void testCreateUniqueRelationship() {
final Person p1 = storeInGraph(michael);

View File

@@ -9,8 +9,8 @@
http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:annotation-config/>
<neo4j:config graphDatabaseService="graphDatabaseService"/>
<neo4j:config graphDatabaseService="graphDatabaseService" base-package="org.springframework.data.test.snippets"/>
<neo4j:repositories base-package="org.springframework.data.test.snippets"/>
<bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase" destroy-method="shutdown"/>
<tx:annotation-driven/>
</beans>
</beans>

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:spring-configured/>
<context:annotation-config/>
<bean class="org.springframework.data.neo4j.config.Neo4jConfiguration">
<property name="basePackage" value="org.springframework.data.neo4j.invalid.unique"/>
</bean>
<bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase" destroy-method="shutdown"/>
<neo4j:repositories base-package="org.springframework.data.neo4j.invalid.unique"/>
</beans>

View File

@@ -11,5 +11,5 @@
<neo4j:config storeDirectory="target/config-test" base-package="org.springframework.data.neo4j.config"/>
<bean id="config" class="org.springframework.data.neo4j.config.DataGraphNamespaceHandlerTests$Config"/>
<neo4j:repositories base-package="org.springframework.data.neo4j"/>
</beans>
<neo4j:repositories base-package="org.springframework.data.neo4j.config"/>
</beans>

View File

@@ -9,8 +9,8 @@
http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:annotation-config/>
<neo4j:config storeDirectory="target/config-test"/>
<neo4j:config storeDirectory="target/config-test" base-package="org.springframework.data.neo4j.model"/>
<bean id="config" class="org.springframework.data.neo4j.config.DataGraphNamespaceHandlerTests$Config"/>
<neo4j:repositories base-package="org.springframework.data.neo4j.repository" consider-nested-repositories="true"/>
</beans>
<neo4j:repositories base-package="org.springframework.data.neo4j.repositories" consider-nested-repositories="true"/>
</beans>

View File

@@ -5,7 +5,7 @@
xsi:schemaLocation="http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<neo4j:config graphDatabaseService="graphDatabaseService" />
<neo4j:config graphDatabaseService="graphDatabaseService" base-package="org.springframework.data.neo4j.config"/>
<bean class="org.springframework.data.neo4j.lifecycle.AuditingEventListener">
<constructor-arg>

View File

@@ -5,7 +5,7 @@
xsi:schemaLocation="http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<neo4j:config graphDatabaseService="graphDatabaseService" />
<neo4j:config graphDatabaseService="graphDatabaseService" base-package="org.springframework.data.neo4j.config.model" />
<neo4j:auditing />

View File

@@ -9,8 +9,8 @@
http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:annotation-config/>
<neo4j:config graphDatabaseService="graphDatabaseService"/>
<neo4j:config graphDatabaseService="graphDatabaseService" base-package="org.springframework.data.neo4j.inheritance.model"/>
<neo4j:repositories base-package="org.springframework.data.neo4j.inheritance.repository"/>
<bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase" destroy-method="shutdown"/>
<tx:annotation-driven/>
</beans>
</beans>

View File

@@ -7,7 +7,7 @@
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd">
<context:annotation-config/>
<neo4j:config graphDatabaseService="graphDatabaseService"/>
<neo4j:repositories base-package="org.springframework.data.neo4j.repository"/>
<neo4j:config graphDatabaseService="graphDatabaseService" base-package="org.springframework.data.neo4j.model"/>
<neo4j:repositories base-package="org.springframework.data.neo4j.repositories"/>
<bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase" destroy-method="shutdown"/>
</beans>
</beans>

View File

@@ -7,7 +7,7 @@
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd">
<context:annotation-config/>
<neo4j:config graphDatabaseService="graphDatabaseService"/>
<neo4j:repositories base-package="org.springframework.data.neo4j.repository"/>
<neo4j:config graphDatabaseService="graphDatabaseService" base-package="org.springframework.data.neo4j.model"/>
<neo4j:repositories base-package="org.springframework.data.neo4j.repositories"/>
<bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase" destroy-method="shutdown"/>
</beans>
</beans>

View File

@@ -7,7 +7,7 @@
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd">
<context:annotation-config/>
<neo4j:config graphDatabaseService="graphDatabaseService"/>
<neo4j:repositories base-package="org.springframework.data.neo4j.repository"/>
<neo4j:config graphDatabaseService="graphDatabaseService" base-package="org.springframework.data.neo4j.model"/>
<neo4j:repositories base-package="org.springframework.data.neo4j.repositories"/>
<bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase" destroy-method="shutdown"/>
</beans>
</beans>

View File

@@ -7,7 +7,7 @@
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd">
<context:annotation-config/>
<neo4j:config graphDatabaseService="graphDatabaseService"/>
<neo4j:repositories base-package="org.springframework.data.neo4j.repository"/>
<neo4j:config graphDatabaseService="graphDatabaseService" base-package="org.springframework.data.neo4j.model"/>
<neo4j:repositories base-package="org.springframework.data.neo4j.repositories"/>
<bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase" destroy-method="shutdown"/>
</beans>
</beans>

View File

@@ -13,7 +13,7 @@
<constructor-arg index="1" value="Indexed"/>
</bean>
<neo4j:config graphDatabaseService="graphDatabaseService" base-package="org.springframework.data.neo4j.model"/>
<neo4j:config graphDatabaseService="graphDatabaseService" base-package="org.springframework.data.neo4j.model,org.springframework.data.neo4j.repository.query"/>
<neo4j:repositories base-package="org.springframework.data.neo4j.repository.query"/>
<bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase" destroy-method="shutdown"/>
</beans>
</beans>

View File

@@ -13,7 +13,7 @@
<constructor-arg index="1" value="Labeled"/>
</bean>
<neo4j:config graphDatabaseService="graphDatabaseService" base-package="org.springframework.data.neo4j.model" />
<neo4j:config graphDatabaseService="graphDatabaseService" base-package="org.springframework.data.neo4j.model,org.springframework.data.neo4j.repository.query" />
<neo4j:repositories base-package="org.springframework.data.neo4j.repository.query"/>
<bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase" destroy-method="shutdown"/>
</beans>
</beans>

View File

@@ -12,7 +12,7 @@
<context:annotation-config/>
<bean class="org.springframework.data.neo4j.config.Neo4jConfiguration">
<property name="basePackage" value="org.springframework.data.neo4j.annotation.relatedto.bidirectional"/>
<property name="basePackage" value="org.springframework.data.neo4j.annotation.relatedto"/>
</bean>
<bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase" destroy-method="shutdown"/>

View File

@@ -11,7 +11,9 @@
<context:spring-configured/>
<context:annotation-config/>
<bean class="org.springframework.data.neo4j.config.Neo4jConfiguration"/>
<bean class="org.springframework.data.neo4j.config.Neo4jConfiguration">
<property name="basePackage" value="org.springframework.data.neo4j.annotation.relatedtovia"/>
</bean>
<bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase" destroy-method="shutdown"/>

View File

@@ -9,11 +9,11 @@
http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:annotation-config/>
<neo4j:config graphDatabaseService="graphDatabaseService"/>
<neo4j:config graphDatabaseService="graphDatabaseService" base-package="org.springframework.data.neo4j.model"/>
<neo4j:repositories base-package="org.springframework.data.neo4j.model"/>
<bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase" destroy-method="shutdown"/>
<bean id="typeSafetyPolicy" class="org.springframework.data.neo4j.support.typesafety.TypeSafetyPolicy">
<constructor-arg type="org.springframework.data.neo4j.support.typesafety.TypeSafetyOption"><value>RETURNS_NULL</value></constructor-arg>
</bean>
<tx:annotation-driven mode="aspectj"/>
</beans>
</beans>

View File

@@ -9,11 +9,11 @@
http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:annotation-config/>
<neo4j:config graphDatabaseService="graphDatabaseService"/>
<neo4j:config graphDatabaseService="graphDatabaseService" base-package="org.springframework.data.neo4j.model"/>
<neo4j:repositories base-package="org.springframework.data.neo4j.model"/>
<bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase" destroy-method="shutdown"/>
<bean id="typeSafetyPolicy" class="org.springframework.data.neo4j.support.typesafety.TypeSafetyPolicy">
<constructor-arg type="org.springframework.data.neo4j.support.typesafety.TypeSafetyOption"><value>THROWS_EXCEPTION</value></constructor-arg>
</bean>
<tx:annotation-driven mode="aspectj"/>
</beans>
</beans>

View File

@@ -9,8 +9,8 @@
http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:annotation-config/>
<neo4j:config graphDatabaseService="graphDatabaseService"/>
<neo4j:config graphDatabaseService="graphDatabaseService" base-package="org.springframework.data.neo4j.model"/>
<neo4j:repositories base-package="org.springframework.data.neo4j.model"/>
<bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase" destroy-method="shutdown"/>
<tx:annotation-driven mode="aspectj"/>
</beans>
</beans>

View File

@@ -12,7 +12,9 @@
<context:spring-configured/>
<context:annotation-config/>
<bean class="org.springframework.data.neo4j.config.Neo4jConfiguration"/>
<bean class="org.springframework.data.neo4j.config.Neo4jConfiguration">
<property name="basePackage" value="org.springframework.data.neo4j.unique"/>
</bean>
<bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase" destroy-method="shutdown"/>