Merge pull request #5070 from eugenp/update-neo4j

update neo4j
This commit is contained in:
Loredana Crusoveanu 2018-08-25 23:27:01 +03:00 committed by GitHub
commit 9033ec89d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 59 additions and 62 deletions

View File

@ -37,18 +37,6 @@
<groupId>org.springframework.data</groupId> <groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId> <artifactId>spring-data-neo4j</artifactId>
<version>${spring-data-neo4j.version}</version> <version>${spring-data-neo4j.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>${spring-data-neo4j.version}</version>
<type>test-jar</type>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.voodoodyne.jackson.jsog</groupId> <groupId>com.voodoodyne.jackson.jsog</groupId>
@ -86,6 +74,11 @@
<version>${neo4j-ogm.version}</version> <version>${neo4j-ogm.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-embedded-driver</artifactId>
<version>${neo4j-ogm.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.neo4j.test</groupId> <groupId>org.neo4j.test</groupId>
<artifactId>neo4j-harness</artifactId> <artifactId>neo4j-harness</artifactId>
@ -96,23 +89,17 @@
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId> <artifactId>spring-test</artifactId>
<version>${spring-test.version}</version> <version>${spring-test.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
</dependencies> </dependencies>
<properties> <properties>
<neo4j-java-driver.version>1.1.1</neo4j-java-driver.version> <neo4j-java-driver.version>1.6.2</neo4j-java-driver.version>
<neo4j.version>3.1.0</neo4j.version> <neo4j.version>3.4.6</neo4j.version>
<spring-data-neo4j.version>4.1.6.RELEASE</spring-data-neo4j.version> <spring-data-neo4j.version>5.0.1.RELEASE</spring-data-neo4j.version>
<jackson-jsog.version>1.1</jackson-jsog.version> <jackson-jsog.version>1.1</jackson-jsog.version>
<spring-boot.version>1.5.13.RELEASE</spring-boot.version> <spring-boot.version>2.0.1.RELEASE</spring-boot.version>
<spring-test.version>4.3.17.RELEASE</spring-test.version> <spring-test.version>5.0.1.RELEASE</spring-test.version>
<neo4j-ogm.version>2.1.1</neo4j-ogm.version> <neo4j-ogm.version>3.1.2</neo4j-ogm.version>
</properties> </properties>
</project> </project>

View File

@ -1,5 +1,6 @@
package com.baeldung.spring.data.neo4j.config; package com.baeldung.spring.data.neo4j.config;
import org.neo4j.ogm.config.Configuration.Builder;
import org.neo4j.ogm.session.SessionFactory; import org.neo4j.ogm.session.SessionFactory;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
@ -8,15 +9,14 @@ import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
@ComponentScan(basePackages = { "com.baeldung.spring.data.neo4j.services" }) @ComponentScan(basePackages = { "com.baeldung.spring.data.neo4j.services" })
@Configuration @Configuration
@EnableNeo4jRepositories(basePackages = "com.baeldung.spring.data.neo4j.repostory") @EnableNeo4jRepositories(basePackages = "com.baeldung.spring.data.neo4j.repository")
public class MovieDatabaseNeo4jConfiguration { public class MovieDatabaseNeo4jConfiguration {
public static final String URL = System.getenv("NEO4J_URL") != null ? System.getenv("NEO4J_URL") : "http://neo4j:movies@localhost:7474"; public static final String URL = System.getenv("NEO4J_URL") != null ? System.getenv("NEO4J_URL") : "http://neo4j:movies@localhost:7474";
@Bean @Bean
public org.neo4j.ogm.config.Configuration getConfiguration() { public org.neo4j.ogm.config.Configuration getConfiguration() {
org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration(); org.neo4j.ogm.config.Configuration config = new Builder().uri(URL).build();
config.driverConfiguration().setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver").setURI(URL);
return config; return config;
} }

View File

@ -1,26 +1,25 @@
package com.baeldung.spring.data.neo4j.config; package com.baeldung.spring.data.neo4j.config;
import org.neo4j.ogm.config.Configuration.Builder;
import org.neo4j.ogm.session.SessionFactory; import org.neo4j.ogm.session.SessionFactory;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Profile;
import org.springframework.data.neo4j.config.Neo4jConfiguration;
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories; import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
import org.springframework.data.neo4j.transaction.Neo4jTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration @Configuration
@EnableTransactionManagement @EnableTransactionManagement
@ComponentScan(basePackages = { "com.baeldung.spring.data.neo4j.services" }) @ComponentScan(basePackages = { "com.baeldung.spring.data.neo4j.services" })
@EnableNeo4jRepositories(basePackages = "com.baeldung.spring.data.neo4j.repostory") @EnableNeo4jRepositories(basePackages = "com.baeldung.spring.data.neo4j.repository")
@Profile({ "embedded", "test" }) @Profile({ "embedded", "test" })
public class MovieDatabaseNeo4jTestConfiguration extends Neo4jConfiguration { public class MovieDatabaseNeo4jTestConfiguration {
@Bean @Bean
public org.neo4j.ogm.config.Configuration getConfiguration() { public org.neo4j.ogm.config.Configuration getConfiguration() {
final org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration(); org.neo4j.ogm.config.Configuration config = new Builder().build();
config.driverConfiguration()
.setDriverClassName("org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver");
return config; return config;
} }
@ -29,4 +28,9 @@ public class MovieDatabaseNeo4jTestConfiguration extends Neo4jConfiguration {
return new SessionFactory(getConfiguration(), "com.baeldung.spring.data.neo4j.domain"); return new SessionFactory(getConfiguration(), "com.baeldung.spring.data.neo4j.domain");
} }
@Bean
public Neo4jTransactionManager transactionManager() {
return new Neo4jTransactionManager(getSessionFactory());
}
} }

View File

@ -1,12 +1,13 @@
package com.baeldung.spring.data.neo4j.domain; package com.baeldung.spring.data.neo4j.domain;
import org.neo4j.ogm.annotation.GraphId; import org.neo4j.ogm.annotation.GeneratedValue;
import org.neo4j.ogm.annotation.Id;
import org.neo4j.ogm.annotation.NodeEntity; import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Relationship; import org.neo4j.ogm.annotation.Relationship;
@NodeEntity @NodeEntity
public class Car { public class Car {
@GraphId @Id @GeneratedValue
private Long id; private Long id;
private String make; private String make;

View File

@ -2,7 +2,9 @@ package com.baeldung.spring.data.neo4j.domain;
import com.fasterxml.jackson.annotation.JsonIdentityInfo; import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.voodoodyne.jackson.jsog.JSOGGenerator; import com.voodoodyne.jackson.jsog.JSOGGenerator;
import org.neo4j.ogm.annotation.GraphId;
import org.neo4j.ogm.annotation.GeneratedValue;
import org.neo4j.ogm.annotation.Id;
import org.neo4j.ogm.annotation.NodeEntity; import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Relationship; import org.neo4j.ogm.annotation.Relationship;
@ -13,7 +15,7 @@ import java.util.List;
@NodeEntity @NodeEntity
public class Movie { public class Movie {
@GraphId @Id @GeneratedValue
Long id; Long id;
private String title; private String title;

View File

@ -2,7 +2,9 @@ package com.baeldung.spring.data.neo4j.domain;
import com.fasterxml.jackson.annotation.JsonIdentityInfo; import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.voodoodyne.jackson.jsog.JSOGGenerator; import com.voodoodyne.jackson.jsog.JSOGGenerator;
import org.neo4j.ogm.annotation.GraphId;
import org.neo4j.ogm.annotation.GeneratedValue;
import org.neo4j.ogm.annotation.Id;
import org.neo4j.ogm.annotation.NodeEntity; import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Relationship; import org.neo4j.ogm.annotation.Relationship;
@ -11,7 +13,7 @@ import java.util.List;
@JsonIdentityInfo(generator = JSOGGenerator.class) @JsonIdentityInfo(generator = JSOGGenerator.class)
@NodeEntity @NodeEntity
public class Person { public class Person {
@GraphId @Id @GeneratedValue
Long id; Long id;
private String name; private String name;

View File

@ -3,7 +3,8 @@ package com.baeldung.spring.data.neo4j.domain;
import com.fasterxml.jackson.annotation.JsonIdentityInfo; import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.voodoodyne.jackson.jsog.JSOGGenerator; import com.voodoodyne.jackson.jsog.JSOGGenerator;
import org.neo4j.ogm.annotation.EndNode; import org.neo4j.ogm.annotation.EndNode;
import org.neo4j.ogm.annotation.GraphId; import org.neo4j.ogm.annotation.GeneratedValue;
import org.neo4j.ogm.annotation.Id;
import org.neo4j.ogm.annotation.RelationshipEntity; import org.neo4j.ogm.annotation.RelationshipEntity;
import org.neo4j.ogm.annotation.StartNode; import org.neo4j.ogm.annotation.StartNode;
@ -12,7 +13,7 @@ import java.util.Collection;
@JsonIdentityInfo(generator = JSOGGenerator.class) @JsonIdentityInfo(generator = JSOGGenerator.class)
@RelationshipEntity(type = "ACTED_IN") @RelationshipEntity(type = "ACTED_IN")
public class Role { public class Role {
@GraphId @Id @GeneratedValue
Long id; Long id;
private Collection<String> roles; private Collection<String> roles;
@StartNode @StartNode

View File

@ -1,8 +1,8 @@
package com.baeldung.spring.data.neo4j.repostory; package com.baeldung.spring.data.neo4j.repository;
import com.baeldung.spring.data.neo4j.domain.Movie; import com.baeldung.spring.data.neo4j.domain.Movie;
import org.springframework.data.neo4j.annotation.Query; import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.GraphRepository; import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@ -11,7 +11,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
@Repository @Repository
public interface MovieRepository extends GraphRepository<Movie> { public interface MovieRepository extends Neo4jRepository<Movie, Long> {
Movie findByTitle(@Param("title") String title); Movie findByTitle(@Param("title") String title);

View File

@ -0,0 +1,9 @@
package com.baeldung.spring.data.neo4j.repository;
import com.baeldung.spring.data.neo4j.domain.Person;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface PersonRepository extends Neo4jRepository<Person, Long> {
}

View File

@ -1,9 +0,0 @@
package com.baeldung.spring.data.neo4j.repostory;
import com.baeldung.spring.data.neo4j.domain.Person;
import org.springframework.data.neo4j.repository.GraphRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface PersonRepository extends GraphRepository<Person> {
}

View File

@ -1,10 +1,11 @@
package com.baeldung.spring.data.neo4j.services; package com.baeldung.spring.data.neo4j.services;
import com.baeldung.spring.data.neo4j.repostory.MovieRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import com.baeldung.spring.data.neo4j.repository.MovieRepository;
import java.util.*; import java.util.*;
@Service @Service

View File

@ -12,14 +12,12 @@ import org.neo4j.ogm.session.SessionFactory;
import com.baeldung.spring.data.neo4j.domain.Car; import com.baeldung.spring.data.neo4j.domain.Car;
import com.baeldung.spring.data.neo4j.domain.Company; import com.baeldung.spring.data.neo4j.domain.Company;
import org.neo4j.ogm.transaction.Transaction;
public class Neo4jOgmLiveTest { public class Neo4jOgmLiveTest {
@Test @Test
public void testOgm() { public void testOgm() {
Configuration conf = new Configuration(); Configuration conf = new Configuration.Builder().build();
conf.driverConfiguration().setDriverClassName("org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver");
SessionFactory factory = new SessionFactory(conf, "com.baeldung.spring.data.neo4j.domain"); SessionFactory factory = new SessionFactory(conf, "com.baeldung.spring.data.neo4j.domain");
Session session = factory.openSession(); Session session = factory.openSession();

View File

@ -4,8 +4,9 @@ import com.baeldung.spring.data.neo4j.config.MovieDatabaseNeo4jTestConfiguration
import com.baeldung.spring.data.neo4j.domain.Movie; import com.baeldung.spring.data.neo4j.domain.Movie;
import com.baeldung.spring.data.neo4j.domain.Person; import com.baeldung.spring.data.neo4j.domain.Person;
import com.baeldung.spring.data.neo4j.domain.Role; import com.baeldung.spring.data.neo4j.domain.Role;
import com.baeldung.spring.data.neo4j.repostory.MovieRepository; import com.baeldung.spring.data.neo4j.repository.MovieRepository;
import com.baeldung.spring.data.neo4j.repostory.PersonRepository; import com.baeldung.spring.data.neo4j.repository.PersonRepository;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -50,10 +51,10 @@ public class MovieRepositoryIntegrationTest {
Role charlie = new Role(); Role charlie = new Role();
charlie.setMovie(italianJob); charlie.setMovie(italianJob);
charlie.setPerson(mark); charlie.setPerson(mark);
Collection<String> roleNames = new HashSet(); Collection<String> roleNames = new HashSet<>();
roleNames.add("Charlie Croker"); roleNames.add("Charlie Croker");
charlie.setRoles(roleNames); charlie.setRoles(roleNames);
List<Role> roles = new ArrayList(); List<Role> roles = new ArrayList<>();
roles.add(charlie); roles.add(charlie);
italianJob.setRoles(roles); italianJob.setRoles(roles);
movieRepository.save(italianJob); movieRepository.save(italianJob);