Code Monkey home page Code Monkey logo

spring-data-keyvalue's Introduction

Spring Data KeyValue icon?job=spring data keyvalue%2Fmain&subject=Build Gitter Revved up by Gradle Enterprise

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.

This module provides infrastructure components to build repository abstractions for stores dealing with Key/Value pairs and ships with a default java.util.Map based implementation.

Features

  • Infrastructure for building repositories on top of key/value implementations.

  • Dynamic SpEL query generation from query method names.

  • Possibility to integrate custom repository code.

Code of Conduct

This project is governed by the Spring Code of Conduct. By participating, you are expected to uphold this code of conduct. Please report unacceptable behavior to [email protected].

Getting Started

Here is a quick teaser of an application using Spring Data Repositories in Java:

public interface PersonRepository extends CrudRepository<Person, Long> {

    List<Person> findByLastname(String lastname);

    List<Person> findByFirstnameLike(String firstname);
}

@Service
public class MyService {

    private final PersonRepository repository;

    public MyService(PersonRepository repository) {
        this.repository = repository;
    }

    public void doWork() {

        repository.deleteAll();

        Person person = new Person();
        person.setFirstname("Oliver");
        person.setLastname("Gierke");
        repository.save(person);

        List<Person> lastNameResults = repository.findByLastname("Gierke");
        List<Person> firstNameResults = repository.findByFirstnameLike("Oli*");
    }
}

@KeySpace("person")
class Person {

    @Id String uuid;
    String firstname;
    String lastname;

    // getters and setters omitted for brevity
}

@Configuration
@EnableMapRepositories("com.acme.repositories")
class AppConfig { … }

Maven configuration

Add the Maven dependency:

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-keyvalue</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-keyvalue</artifactId>
    <version>${version}-SNAPSHOT</version>
</dependency>

<repository>
    <id>spring-snapshot</id>
    <name>Spring Snapshot Repository</name>
    <url>https://repo.spring.io/snapshot</url>
</repository>

Getting Help

Having trouble with Spring Data? We’d love to help!

Reporting Issues

Spring Data uses Github as issue tracking system to record bugs and feature requests. If you want to raise an issue, please follow the recommendations below:

  • Before you log a bug, please search the issue tracker to see if someone has already reported the problem.

  • If the issue does not already exist, create a new issue.

  • Please provide as much information as possible with the issue report, we like to know the version of Spring Data that you are using, the JVM version, Stacktrace, etc.

  • If you need to paste code, or include a stack trace use Markdown code fences ```.

  • If possible try to create a test-case or project that replicates the issue. Attach a link to your code or a compressed file containing your code.

Building from Source

You don’t need to build from source to use Spring Data (binaries in repo.spring.io), but if you want to try out the latest and greatest, Spring Data can be easily built with the maven wrapper. You also need JDK 17.

 $ ./mvnw clean install

If you want to build with the regular mvn command, you will need Maven v3.5.0 or above.

Also see CONTRIBUTING.adoc if you wish to submit pull requests, and in particular please sign the Contributor’s Agreement before your first change, is trivial.

Building reference documentation

Building the documentation builds also the project without running tests.

 $ ./mvnw clean install -Pantora

The generated documentation is available from target/antora/site/index.html.

Examples

License

Spring Data KeyValue is Open Source software released under the Apache 2.0 license.

spring-data-keyvalue's People

Contributors

abassadeyemi avatar ajbrown avatar cbmeeks avatar christophstrobl avatar erichaagdev avatar eugenenik avatar gregturn avatar jxblum avatar linkedlist avatar marceloverdijk avatar mert-z avatar mp911de avatar odrotbohm avatar runbing avatar schauder avatar sdavids avatar skylark95 avatar spring-builds avatar sxhinzvc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spring-data-keyvalue's Issues

@EnableMapRepositories should allow the definition of the Map-type to be used [DATAKV-87]

Oliver Drotbohm opened DATAKV-87 and commented

Would be cool to be able to configure the Map-type used for the repository in the @EnableMapRepositories annotation like this:

@Configuration
@EnableMapRepositories(mapType = MyMap.class)
class Config { }

Issue Links:

  • DATAKV-93 Add readme and reference documentation
    ("is depended on by")

Referenced from: pull request #2, and commits bc88cb4, 7b79e1f, b16a454, 5994025

Executing query methods on repositories is not thread-safe [DATAKV-115]

Shu Yu opened DATAKV-115 and commented

I am using Spring data key value for a web application. Calls to a repository's findByXXX fail randomly, causing an exception.

I have attached the test case that can reproduce the problem.

I think that KeyValuePartTreeQuery is reusing a SpelExpression object, causing failing in SpelQueryEngine.filterMatchingRange() because the expression evaluation context in one thread can be changed by another thread


Affects: 1.0 GA (Gosling)

Attachments:

Referenced from: pull request #16

Query using a repository's findByXXX fails when a property XXX of any entry is null [DATAKV-114]

Shu Yu opened DATAKV-114 and commented

I am using spring data key value for a web application. Queries via the repository interface can fail at random time.

It seems that this failing occurs when a property of an entry is null, which happens often in a multi-thread environment as a property may not have been set yet while another thread is making a query to a repository. This is preventing me from using Spring Data Keyvalue.

The attached test can reproduce this issue. The stack trace of the exception is:

org.springframework.data.keyvalue.core.UncategorizedKeyValueException: nested exception is java.lang.NullPointerException
	at org.springframework.data.keyvalue.core.KeyValuePersistenceExceptionTranslator.translateExceptionIfPossible(KeyValuePersistenceExceptionTranslator.java:49)
	at org.springframework.data.keyvalue.core.KeyValueTemplate.resolveExceptionIfPossible(KeyValueTemplate.java:485)
	at org.springframework.data.keyvalue.core.KeyValueTemplate.execute(KeyValueTemplate.java:380)
	at org.springframework.data.keyvalue.core.KeyValueTemplate.find(KeyValueTemplate.java:391)
	at org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery.execute(KeyValuePartTreeQuery.java:88)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:454)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:432)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
	at com.sun.proxy.$Proxy20.findByLastname(Unknown Source)
	at my.keyvalue.MyTest.queryFailingWithEntryOfNullLastname(MyTest.java:26)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:73)
	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:73)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:224)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:68)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
Caused by: java.lang.NullPointerException
	at org.springframework.data.keyvalue.core.SpelQueryEngine.filterMatchingRange(SpelQueryEngine.java:96)
	at org.springframework.data.keyvalue.core.SpelQueryEngine.sortAndFilterMatchingRange(SpelQueryEngine.java:76)
	at org.springframework.data.keyvalue.core.SpelQueryEngine.execute(SpelQueryEngine.java:55)
	at org.springframework.data.keyvalue.core.SpelQueryEngine.execute(SpelQueryEngine.java:38)
	at org.springframework.data.keyvalue.core.QueryEngine.execute(QueryEngine.java:56)
	at org.springframework.data.keyvalue.core.AbstractKeyValueAdapter.find(AbstractKeyValueAdapter.java:66)
	at org.springframework.data.keyvalue.core.AbstractKeyValueAdapter.find(AbstractKeyValueAdapter.java:29)
	at org.springframework.data.keyvalue.core.KeyValueTemplate$7.doInKeyValue(KeyValueTemplate.java:397)
	at org.springframework.data.keyvalue.core.KeyValueTemplate$7.doInKeyValue(KeyValueTemplate.java:391)
	at org.springframework.data.keyvalue.core.KeyValueTemplate.execute(KeyValueTemplate.java:378)
	... 40 more

Affects: 1.0 GA (Gosling)

Attachments:

Referenced from: pull request #15

Backported to: 1.0.1 (Gosling SR1)

Let the configuration infrastructure for maps default a KeyValueTemplate [DATAKV-88]

Oliver Drotbohm opened DATAKV-88 and commented

Currently a bean name keyValueTemplate is required in the ApplicationContext to bootstrap Map based repositories. We could default a bean definition using the MapKeyValueAdapterFactory using the Map type configured on the @EnableMapRepositories annotation.

MapKeyValueAdapterFactory should get the setter for the Map-type removed to become immutable


No further details from DATAKV-88

ApplicationEvents with generic type argument do not get published to listener using Spring 4.2 [DATAKV-116]

Christoph Strobl opened DATAKV-116 and commented

Type reolution fails for ApplicationEvents using generic types. Using Spring 4.2 it is required to either implement ResolvableTypeProvider or extend PayloadApplicationEvent. In order to support 4.2 from a 4.1 based source we need to provide means to deal with this by providing base handling the generics.

class KeyValueEventListener <E> implements ApplicationListener<KeyValueEvent<?>> {

	private final Class<?> domainClass;

	public KeyValueEventListener() {
		Class<?> typeArgument = GenericTypeResolver.resolveTypeArgument(this.getClass(), NeoEventListener.class);
		this.domainClass = typeArgument == null ? Object.class : typeArgument;
	}

	@SuppressWarnings({ "unchecked" })
	public void onApplicationEvent(KeyValueEvent<?> event) {

		if (event instanceof BeforeDeleteEvent<?>) {
			BeforeDeleteEvent<?> beforeDeleteEvent = (BeforeDeleteEvent<?>) event;

			// inspect for matching types and ignore others
			if (domainClass.isAssignableFrom(beforeDeleteEvent.getType())) {
				onBeforeDelete((BeforeDeleteEvent <E>) event);
			}
			// other event types...

		}
	}

	protected void onBeforeDelete(BeforeDeleteEvent<E> event) {

	}
}

Affects: 1.0 GA (Gosling)

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.