Giter Site home page Giter Site logo

mars-wei / spring-data-neo4j Goto Github PK

View Code? Open in Web Editor NEW

This project forked from spring-projects/spring-data-neo4j

0.0 2.0 0.0 17.54 MB

Provides support to increase developer productivity in Java when using the neo4j graph database. Uses familiar Spring concepts such as a template classes for core API usage and provides an annotation based programming model using AspectJ

Home Page: http://www.springsource.org/spring-data/neo4j

License: Apache License 2.0

Java 99.77% Kotlin 0.23%

spring-data-neo4j's Introduction

ga snapshot

Spring Data Neo4j

The primary goal of the Spring Data project is to make it easier to build Spring-powered applications that use new data access technologies such as non-relational databases, map-reduce frameworks, and cloud based data services.

The Spring Data Neo4j project aims to provide a familiar and consistent Spring-based programming model for integrating with the Neo4j Graph Database.

Features

  • Automatic mapping of annotated domain entities for nodes and relationships;

  • Powerful CRUD based repositories with provided, derived, and annotated finder methods;

  • Integration with Spring’s comprehensive Transaction management;

  • Agnostic communication with Neo4j through a variety of transport mechanisms (embedded, http, bolt);

  • Integration into Spring Data REST;

  • Seamless integration with Spring Boot.

Documentation & Getting Help

This README is the best place to start learning about the features of Spring Data Neo4j.

To learn more refer to:

If you are new to Spring as well as to Spring Data, look for information about Spring projects.

Quick start

Add the Maven dependency:

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j</artifactId>
        <version>${version}.RELEASE</version>
    </dependency>

If you’d rather like the latest snapshots of the upcoming major version, use our Maven snapshot repository and declare the appropriate dependency version.

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j</artifactId>
        <version>${version}.BUILD-SNAPSHOT</version>
    </dependency>

    <!-- used for nightly builds -->
    <repository>
      <id>spring-libs-snapshot</id>
      <snapshots><enabled>true</enabled></snapshots>
      <name>Springframework Maven SNAPSHOT Repository</name>
      <url>http://repo.spring.io/libs-snapshot</url>
    </repository>
Tip
You can check out how to get setup with Gradle in the the Reference Manual.

Configure Spring Data Neo4j in your application using JavaConfig bean configuration

@Configuration
@ComponentScan(basePackages = "org.example.person.services",...)
@EnableNeo4jRepositories(basePackages = "com.example.person.repository",...)
@EnableTransactionManagement
public class MyConfiguration {

    @Bean
    public SessionFactory sessionFactory() {
        // with domain entity base package(s)
        return new SessionFactory(configuration(), "com.example.person.domain",...);
    }

    @Bean
    public org.neo4j.ogm.config.Configuration configuration() {
        org.neo4j.ogm.config.Configuration configuration = new org.neo4j.ogm.config.Configuration.Builder()
                .uri("bolt://localhost")
                .credentials("user", "secret")
                .build();
        return configuration;
    }

	@Bean
	public Neo4jTransactionManager transactionManager() {
		return new Neo4jTransactionManager(sessionFactory());
	}
}

Spring Data Neo4j provides support for connecting to all of Neo4j’s java drivers:

  • Bolt

  • HTTP

  • Embedded

Spring Data Neo4j will attempt to auto-configure itself using a file called ogm.properties, which it expects to find on root of the classpath. Here we will configure the HTTP Driver.

URI=http://user:password@localhost:7474

The application can be configured programmatically as well, please consult the reference guide for more information.

Annotate an entity:

@NodeEntity
public class Person {
    private Long id;
    private String name;

    @Relationship(type = "FRIEND", direction = "OUTGOING")
    private Set<Person> friends;

    public Person() {}
    public Person(String name) { this.name = name; }

    private void knows(Person friend) { friends.add(friend); }
}

To simplify the creation of data repositories Spring Data Neo4j provides a generic repository programming model. It will automatically create a repository proxy for you that adds implementations of finder methods you specify on an interface.

For example, given the Person class above, a PersonRepository interface that can query for Person by name and when the name matches a like expression is shown below:

@Repository
public interface PersonRepository extends Neo4jRepository<Person, Long> {

  List<Person> findByName(String name);

  List<Person> findByNameLike(String name);
}

The queries issued on execution will be derived from the method name.

Typically you will want to call your domain objects and repositories from services. In this Service we find the repository interface and register a proxy object in the container:

@Service
public class MyService {

    @Autowired
    private final PersonRepository repository;

    @Transactional
    public void doWork() {

        Person jon = new Person("Jon");
        Person emil = new Person("Emil");
        Person rod = new Person("Rod");

        emil.knows(jon);
        emil.knows(rod);

        // Persist entities and relationships to graph database
        personRepository.save(emil);

        for (Person friend : emil.getFriends()) {
            System.out.println("Friend: " + friend);
        }

        // Control loading depth
        Person thatSamejon = personRepository.findOne(id, 2);
        for (Person friend : jon.getFriends()) {
            System.out.println("Jon's friends to depth 2: " + friend);
        }
    }
}

Contributing to Spring Data Neo4j

There are dedicated, mandatory contribution guidelines for all Spring Data projects.

Here are some ways for you to get involved in the community:

  • Get involved with Spring Data Neo4j community on the Neo4j Google Group and by helping on StackOverflow.

  • Create JIRA tickets for bugs and new features and comment and vote on the ones that you are interested in.

  • Github is for social coding: if you want to write code, we encourage contributions through pull requests from a fork of this repository. If you want to contribute code this way, please read the contribution guidelines for details.

spring-data-neo4j's People

Contributors

luanne avatar odrotbohm avatar atg103 avatar mp911de avatar mangrish avatar meistermeier avatar nmervaillie avatar jexp avatar christophstrobl avatar frant-hartm avatar jasperblues avatar spring-builds avatar bachmanm avatar aldrinm avatar schauder avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.