DATAGRAPH-340 - Polished CDI integration.
Changed configuration model to be based on a GraphDatabase CDI bean only. The Neo4jMappingContext and Neo4jTemplate are created internally on the fly now. Upgraded to Javassist 3.18.1 for tests now to make previously failing tests work. Applied some general code, JavaDoc and formatting polish. Original pull request: #133.
This commit is contained in:
@@ -120,8 +120,21 @@
|
||||
<groupId>org.apache.openwebbeans.test</groupId>
|
||||
<artifactId>cditest-owb</artifactId>
|
||||
<version>${webbeans}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>javassist</groupId>
|
||||
<artifactId>javassist</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.javassist</groupId>
|
||||
<artifactId>javassist</artifactId>
|
||||
<version>3.18.1-GA</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.neo4j.repository.cdi;
|
||||
|
||||
|
||||
|
||||
import org.springframework.data.neo4j.core.GraphDatabase;
|
||||
import org.springframework.data.neo4j.repository.GraphRepositoryFactory;
|
||||
import org.springframework.data.neo4j.support.Neo4jTemplate;
|
||||
import org.springframework.data.neo4j.support.mapping.Neo4jMappingContext;
|
||||
@@ -30,37 +29,28 @@ import java.lang.annotation.Annotation;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* {@link org.springframework.data.repository.cdi.CdiRepositoryBean} to create
|
||||
* Neo4j repository instances via CDI.
|
||||
*
|
||||
* {@link org.springframework.data.repository.cdi.CdiRepositoryBean} to create Neo4j repository instances via CDI.
|
||||
*
|
||||
* @author Nicki Watt
|
||||
*/
|
||||
public class Neo4jCdiRepositoryBean<T> extends CdiRepositoryBean<T> {
|
||||
|
||||
private final Bean<Neo4jMappingContext> neo4jMappingContext;
|
||||
private final Bean<Neo4jTemplate> template;
|
||||
private final Bean<GraphDatabase> graphDatabase;
|
||||
|
||||
/**
|
||||
* Creates a new {@link Neo4jCdiRepositoryBean}.
|
||||
*
|
||||
* @param neo4jMappingContext must not be {@literal null}.
|
||||
* @param template must not be {@literal null}.
|
||||
* @param graphDatabase must not be {@literal null}.
|
||||
* @param qualifiers must not be {@literal null}.
|
||||
* @param repositoryType must not be {@literal null}.
|
||||
* @param beanManager must not be {@literal null}.
|
||||
*/
|
||||
public Neo4jCdiRepositoryBean(Bean<Neo4jMappingContext> neo4jMappingContext,
|
||||
Bean<Neo4jTemplate> template,
|
||||
Set<Annotation> qualifiers,
|
||||
Class<T> repositoryType,
|
||||
BeanManager beanManager) {
|
||||
public Neo4jCdiRepositoryBean(Bean<GraphDatabase> graphDatabase,
|
||||
Set<Annotation> qualifiers, Class<T> repositoryType, BeanManager beanManager) {
|
||||
|
||||
super(qualifiers, repositoryType, beanManager);
|
||||
|
||||
Assert.notNull(neo4jMappingContext);
|
||||
Assert.notNull(template);
|
||||
this.neo4jMappingContext = neo4jMappingContext;
|
||||
this.template = template;
|
||||
this.graphDatabase = graphDatabase;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -70,10 +60,10 @@ public class Neo4jCdiRepositoryBean<T> extends CdiRepositoryBean<T> {
|
||||
@Override
|
||||
protected T create(CreationalContext<T> creationalContext, Class<T> repositoryType) {
|
||||
|
||||
Neo4jMappingContext neo4jMapCtx = getDependencyInstance(neo4jMappingContext, Neo4jMappingContext.class);
|
||||
Neo4jTemplate neo4jTemplate = getDependencyInstance(template, Neo4jTemplate.class);
|
||||
Neo4jMappingContext neo4jMapCtx = new Neo4jMappingContext();
|
||||
Neo4jTemplate neo4jTemplate = new Neo4jTemplate(getDependencyInstance(graphDatabase, GraphDatabase.class));
|
||||
|
||||
GraphRepositoryFactory factory = new GraphRepositoryFactory(neo4jTemplate,neo4jMapCtx);
|
||||
GraphRepositoryFactory factory = new GraphRepositoryFactory(neo4jTemplate, neo4jMapCtx);
|
||||
return factory.getRepository(repositoryType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,19 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.neo4j.repository.cdi;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.data.neo4j.support.Neo4jTemplate;
|
||||
import org.springframework.data.neo4j.support.mapping.Neo4jMappingContext;
|
||||
import org.springframework.data.repository.cdi.CdiRepositoryExtensionSupport;
|
||||
|
||||
import javax.enterprise.event.Observes;
|
||||
import javax.enterprise.inject.UnsatisfiedResolutionException;
|
||||
import javax.enterprise.inject.spi.AfterBeanDiscovery;
|
||||
import javax.enterprise.inject.spi.Bean;
|
||||
import javax.enterprise.inject.spi.BeanManager;
|
||||
import javax.enterprise.inject.spi.ProcessBean;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
@@ -36,6 +23,19 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.event.Observes;
|
||||
import javax.enterprise.inject.UnsatisfiedResolutionException;
|
||||
import javax.enterprise.inject.spi.AfterBeanDiscovery;
|
||||
import javax.enterprise.inject.spi.Bean;
|
||||
import javax.enterprise.inject.spi.BeanManager;
|
||||
import javax.enterprise.inject.spi.ProcessBean;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.neo4j.core.GraphDatabase;
|
||||
import org.springframework.data.neo4j.support.mapping.Neo4jMappingContext;
|
||||
import org.springframework.data.repository.cdi.CdiRepositoryExtensionSupport;
|
||||
|
||||
/**
|
||||
* CDI extension to export Neo4j repositories.
|
||||
*
|
||||
@@ -45,10 +45,9 @@ public class Neo4jCdiRepositoryExtension extends CdiRepositoryExtensionSupport {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Neo4jCdiRepositoryExtension.class);
|
||||
|
||||
private final Map<Set<Annotation>, Bean<Neo4jMappingContext>> neo4jMappingContexts = new HashMap<Set<Annotation>, Bean<Neo4jMappingContext>>();
|
||||
private final Map<Set<Annotation>, Bean<Neo4jTemplate>> neo4jTemplates = new HashMap<Set<Annotation>, Bean<Neo4jTemplate>>();
|
||||
private final Map<Set<Annotation>, Bean<GraphDatabase>> graphDatabases = new HashMap<Set<Annotation>, Bean<GraphDatabase>>();
|
||||
|
||||
public Neo4jCdiRepositoryExtension() {
|
||||
public Neo4jCdiRepositoryExtension() {
|
||||
LOG.info("Activating CDI extension for Spring Data Neo4j repositories.");
|
||||
}
|
||||
|
||||
@@ -58,23 +57,15 @@ public class Neo4jCdiRepositoryExtension extends CdiRepositoryExtensionSupport {
|
||||
Bean<X> bean = processBean.getBean();
|
||||
|
||||
for (Type type : bean.getTypes()) {
|
||||
if (type instanceof Class<?> && Neo4jMappingContext.class.isAssignableFrom((Class<?>) type)) {
|
||||
if (type instanceof Class<?> && GraphDatabase.class.isAssignableFrom((Class<?>) type)) {
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug(String.format("Discovered %s with qualifiers %s.", Neo4jMappingContext.class.getName(),
|
||||
LOG.debug(String.format("Discovered %s with qualifiers %s.", GraphDatabase.class.getName(),
|
||||
bean.getQualifiers()));
|
||||
}
|
||||
// Store the EntityManager bean using its qualifiers.
|
||||
neo4jMappingContexts.put(new HashSet<Annotation>(bean.getQualifiers()), (Bean<Neo4jMappingContext>) bean);
|
||||
|
||||
graphDatabases.put(new HashSet<Annotation>(bean.getQualifiers()), (Bean<GraphDatabase>) bean);
|
||||
}
|
||||
|
||||
if (type instanceof Class<?> && Neo4jTemplate.class.isAssignableFrom((Class<?>) type)) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug(String.format("Discovered %s with qualifiers %s.", Neo4jTemplate.class.getName(),
|
||||
bean.getQualifiers()));
|
||||
}
|
||||
// Store the EntityManager bean using its qualifiers.
|
||||
neo4jTemplates.put(new HashSet<Annotation>(bean.getQualifiers()), (Bean<Neo4jTemplate>) bean);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,20 +98,14 @@ public class Neo4jCdiRepositoryExtension extends CdiRepositoryExtensionSupport {
|
||||
*/
|
||||
private <T> Bean<T> createRepositoryBean(Class<T> repositoryType, Set<Annotation> qualifiers, BeanManager beanManager) {
|
||||
|
||||
// Determine the Neo4jOperations bean which matches the qualifiers of the repository.
|
||||
Bean<Neo4jMappingContext> neo4jMappingContextBean = this.neo4jMappingContexts.get(qualifiers);
|
||||
Bean<Neo4jTemplate> neo4jTemplateBean = this.neo4jTemplates.get(qualifiers);
|
||||
Bean<GraphDatabase> graphDatabase = this.graphDatabases.get(qualifiers);
|
||||
|
||||
if (neo4jMappingContextBean == null) {
|
||||
if (graphDatabase == null) {
|
||||
throw new UnsatisfiedResolutionException(String.format("Unable to resolve a bean for '%s' with qualifiers %s.",
|
||||
Neo4jMappingContext.class.getName(), qualifiers));
|
||||
Neo4jMappingContext.class.getName(), qualifiers));
|
||||
}
|
||||
if (neo4jTemplateBean == null) {
|
||||
throw new UnsatisfiedResolutionException(String.format("Unable to resolve a bean for '%s' with qualifiers %s.",
|
||||
Neo4jTemplate.class.getName(), qualifiers));
|
||||
}
|
||||
|
||||
// Construct and return the repository bean.
|
||||
return new Neo4jCdiRepositoryBean<T>(neo4jMappingContextBean, neo4jTemplateBean, qualifiers, repositoryType, beanManager);
|
||||
return new Neo4jCdiRepositoryBean<T>(graphDatabase, qualifiers, repositoryType,
|
||||
beanManager);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,24 +15,24 @@
|
||||
*/
|
||||
package org.springframework.data.neo4j.repository.cdi;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.apache.webbeans.cditest.CdiTestContainer;
|
||||
import org.apache.webbeans.cditest.CdiTestContainerLoader;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.neo4j.graphdb.Transaction;
|
||||
import org.springframework.data.neo4j.core.GraphDatabase;
|
||||
import org.springframework.data.neo4j.model.Person;
|
||||
import org.springframework.data.neo4j.support.Neo4jTemplate;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link Neo4jCdiRepositoryExtension}.
|
||||
*
|
||||
* @see DATAGRAPH-340
|
||||
* @author Nicki Watt
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class CdiExtensionIntegrationTests {
|
||||
|
||||
@@ -50,98 +50,99 @@ public class CdiExtensionIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("null")
|
||||
public void testRepositoryStyle1IsCreatedCorrectly() {
|
||||
|
||||
Neo4jTemplate template = container.getInstance(Neo4jTemplate.class);
|
||||
GraphDatabase database = container.getInstance(GraphDatabase.class);
|
||||
RepositoryClient client = container.getInstance(RepositoryClient.class);
|
||||
CdiPersonRepository repository = client.getRepository();
|
||||
CdiPersonRepository repository = client.repository;
|
||||
|
||||
assertThat(repository, is(notNullValue()));
|
||||
|
||||
Person person = null;
|
||||
Person result = null;
|
||||
Person person = null;
|
||||
Person result = null;
|
||||
|
||||
Transaction tx = template.getGraphDatabaseService().beginTx();
|
||||
try {
|
||||
repository.deleteAll();
|
||||
Transaction tx = database.beginTx();
|
||||
try {
|
||||
repository.deleteAll();
|
||||
|
||||
person = new Person("Simon", 28);
|
||||
result = repository.save(person);
|
||||
tx.success();
|
||||
} catch (Exception e) {
|
||||
tx.failure();
|
||||
} finally {
|
||||
tx.finish();
|
||||
}
|
||||
person = new Person("Simon", 28);
|
||||
result = repository.save(person);
|
||||
tx.success();
|
||||
} catch (Exception e) {
|
||||
tx.failure();
|
||||
} finally {
|
||||
tx.finish();
|
||||
}
|
||||
|
||||
assertThat(result, is(notNullValue()));
|
||||
assertThat(result, is(notNullValue()));
|
||||
Long resultId = result.getId();
|
||||
Person lookedUpPerson = repository.findOne(person.getId());
|
||||
assertThat(lookedUpPerson.getId(), is(resultId));
|
||||
Person lookedUpPerson = repository.findOne(person.getId());
|
||||
assertThat(lookedUpPerson.getId(), is(resultId));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepositoryStyle2IsCreatedCorrectly() {
|
||||
@Test
|
||||
@SuppressWarnings("null")
|
||||
public void testRepositoryStyle2IsCreatedCorrectly() {
|
||||
|
||||
Neo4jTemplate template = container.getInstance(Neo4jTemplate.class);
|
||||
RepositoryClient client = container.getInstance(RepositoryClient.class);
|
||||
CdiPersonRepository2 repository = client.getRepository2();
|
||||
GraphDatabase database = container.getInstance(GraphDatabase.class);
|
||||
RepositoryClient client = container.getInstance(RepositoryClient.class);
|
||||
CdiPersonRepository2 repository = client.repository2;
|
||||
|
||||
assertThat(repository, is(notNullValue()));
|
||||
assertThat(repository, is(notNullValue()));
|
||||
|
||||
Person person = null;
|
||||
Person result = null;
|
||||
Person person = null;
|
||||
Person result = null;
|
||||
|
||||
Transaction tx = template.getGraphDatabaseService().beginTx();
|
||||
try {
|
||||
repository.deleteAll();
|
||||
Transaction tx = database.beginTx();
|
||||
try {
|
||||
repository.deleteAll();
|
||||
|
||||
person = new Person("Simon", 28);
|
||||
result = repository.save(person);
|
||||
tx.success();
|
||||
} catch (Exception e) {
|
||||
tx.failure();
|
||||
} finally {
|
||||
tx.finish();
|
||||
}
|
||||
person = new Person("Simon", 28);
|
||||
result = repository.save(person);
|
||||
tx.success();
|
||||
} catch (Exception e) {
|
||||
tx.failure();
|
||||
} finally {
|
||||
tx.finish();
|
||||
}
|
||||
|
||||
assertThat(result, is(notNullValue()));
|
||||
Long resultId = result.getId();
|
||||
Person lookedUpPerson = repository.findOne(person.getId());
|
||||
assertThat(lookedUpPerson.getId(), is(resultId));
|
||||
}
|
||||
assertThat(result, is(notNullValue()));
|
||||
Long resultId = result.getId();
|
||||
Person lookedUpPerson = repository.findOne(person.getId());
|
||||
assertThat(lookedUpPerson.getId(), is(resultId));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // uncomment me to see issue (Note also need to uncomment
|
||||
// @Inject in RepositoryClient
|
||||
public void demoNonWorkingRepository() {
|
||||
@Test
|
||||
@SuppressWarnings("null")
|
||||
public void neo4jCrudRepositorySubTypeWorks() {
|
||||
|
||||
Neo4jTemplate template = container.getInstance(Neo4jTemplate.class);
|
||||
RepositoryClient client = container.getInstance(RepositoryClient.class);
|
||||
NonWorkingCdiPersonRepository repository = client.getNonWorkingRepository();
|
||||
GraphDatabase database = container.getInstance(GraphDatabase.class);
|
||||
RepositoryClient client = container.getInstance(RepositoryClient.class);
|
||||
CdiPersonRepository3 repository = client.repository3;
|
||||
|
||||
assertThat(repository, is(notNullValue()));
|
||||
assertThat(repository, is(notNullValue()));
|
||||
|
||||
Person person = null;
|
||||
Person result = null;
|
||||
Person person = null;
|
||||
Person result = null;
|
||||
|
||||
Transaction tx = template.getGraphDatabaseService().beginTx();
|
||||
try {
|
||||
repository.deleteAll();
|
||||
Transaction tx = database.beginTx();
|
||||
try {
|
||||
repository.deleteAll();
|
||||
|
||||
person = new Person("Simon", 28);
|
||||
result = repository.save(person);
|
||||
tx.success();
|
||||
} catch (Exception e) {
|
||||
tx.failure();
|
||||
} finally {
|
||||
tx.finish();
|
||||
}
|
||||
person = new Person("Simon", 28);
|
||||
result = repository.save(person);
|
||||
tx.success();
|
||||
} catch (Exception e) {
|
||||
tx.failure();
|
||||
} finally {
|
||||
tx.finish();
|
||||
}
|
||||
|
||||
assertThat(result, is(notNullValue()));
|
||||
Long resultId = result.getId();
|
||||
Person lookedUpPerson = repository.findOne(person.getId());
|
||||
assertThat(lookedUpPerson.getId(), is(resultId));
|
||||
assertThat(result, is(notNullValue()));
|
||||
Long resultId = result.getId();
|
||||
Person lookedUpPerson = repository.findOne(person.getId());
|
||||
assertThat(lookedUpPerson.getId(), is(resultId));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import org.springframework.data.neo4j.model.Person;
|
||||
import org.springframework.data.neo4j.repository.CRUDRepository;
|
||||
|
||||
|
||||
public interface NonWorkingCdiPersonRepository extends CRUDRepository<Person> {
|
||||
public interface CdiPersonRepository3 extends CRUDRepository<Person> {
|
||||
|
||||
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 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.repository.cdi;
|
||||
|
||||
|
||||
import org.springframework.data.neo4j.core.GraphDatabase;
|
||||
import org.springframework.data.neo4j.support.DelegatingGraphDatabase;
|
||||
import org.springframework.data.neo4j.support.GraphDatabaseFactory;
|
||||
import org.springframework.data.neo4j.support.Neo4jTemplate;
|
||||
import org.springframework.data.neo4j.support.mapping.Neo4jMappingContext;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.enterprise.inject.Produces;
|
||||
|
||||
/**
|
||||
* Simple component exposing {@link Neo4jTemplate} and {@link Neo4jMappingContext}
|
||||
* instances as CDI bean.
|
||||
*
|
||||
* @author Nicki Watt
|
||||
*/
|
||||
class Neo4jCDIProducer {
|
||||
|
||||
@Produces
|
||||
@ApplicationScoped
|
||||
public Neo4jTemplate createNeo4jTemplate() {
|
||||
return new Neo4jTemplate(createGraphDatabase());
|
||||
}
|
||||
|
||||
//@Produces
|
||||
//@ApplicationScoped
|
||||
private GraphDatabase createGraphDatabase() {
|
||||
|
||||
GraphDatabaseFactory factory = new GraphDatabaseFactory();
|
||||
GraphDatabase graphDatabase = null;
|
||||
try {
|
||||
factory.setStoreLocation("target/cdi-test-db");
|
||||
graphDatabase = factory.getObject();
|
||||
registerShutdownHook(graphDatabase);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Unable to start up factory");
|
||||
}
|
||||
|
||||
return graphDatabase;
|
||||
|
||||
}
|
||||
|
||||
private static void registerShutdownHook( final GraphDatabase graphDb )
|
||||
{
|
||||
// Registers a shutdown hook for the Neo4j instance so that it
|
||||
// shuts down nicely when the VM exits (even if you "Ctrl-C" the
|
||||
// running application).
|
||||
Runtime.getRuntime().addShutdownHook( new Thread()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
((DelegatingGraphDatabase)graphDb).getGraphDatabaseService().shutdown();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
@Produces
|
||||
@ApplicationScoped
|
||||
public Neo4jMappingContext createNeo4jMappingContext() {
|
||||
return new Neo4jMappingContext();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2013 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.repository.cdi;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.enterprise.inject.Disposes;
|
||||
import javax.enterprise.inject.Produces;
|
||||
|
||||
import org.springframework.data.neo4j.core.GraphDatabase;
|
||||
import org.springframework.data.neo4j.support.GraphDatabaseFactory;
|
||||
|
||||
/**
|
||||
* Simple component exposing a {@link GraphDatabase} as CDI bean.
|
||||
*
|
||||
* @author Nicki Watt
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
class Neo4jCdiProducer {
|
||||
|
||||
@Produces
|
||||
@ApplicationScoped
|
||||
GraphDatabase createGraphDatabase() throws Exception {
|
||||
|
||||
GraphDatabaseFactory factory = new GraphDatabaseFactory();
|
||||
factory.setStoreLocation("target/cdi-test-db");
|
||||
|
||||
return factory.getObject();
|
||||
}
|
||||
|
||||
void shutdown(@Disposes GraphDatabase database) {
|
||||
database.shutdown();
|
||||
}
|
||||
}
|
||||
@@ -19,35 +19,11 @@ import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* @author Nicki Watt
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
class RepositoryClient {
|
||||
|
||||
@Inject
|
||||
CdiPersonRepository repository;
|
||||
|
||||
@Inject
|
||||
CdiPersonRepository2 repository2;
|
||||
|
||||
// @Inject
|
||||
//- Uncomment me, but I have problems
|
||||
// (javassist.bytecode.DuplicateMemberException: duplicate method)
|
||||
NonWorkingCdiPersonRepository nonWorkingCdiPersonRepository;
|
||||
|
||||
/**
|
||||
* @return the repository
|
||||
*/
|
||||
public CdiPersonRepository getRepository() {
|
||||
return repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the repository
|
||||
*/
|
||||
public CdiPersonRepository2 getRepository2() {
|
||||
return repository2;
|
||||
}
|
||||
|
||||
public NonWorkingCdiPersonRepository getNonWorkingRepository() {
|
||||
return nonWorkingCdiPersonRepository;
|
||||
}
|
||||
@Inject CdiPersonRepository repository;
|
||||
@Inject CdiPersonRepository2 repository2;
|
||||
@Inject CdiPersonRepository3 repository3;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user