https://github.com/hazelcast/spring-data-hazelcast
Hazelcast Spring Data integration Project http://projects.spring.io/spring-data/
https://github.com/hazelcast/spring-data-hazelcast
Last synced: 3 months ago
JSON representation
Hazelcast Spring Data integration Project http://projects.spring.io/spring-data/
- Host: GitHub
- URL: https://github.com/hazelcast/spring-data-hazelcast
- Owner: hazelcast
- License: apache-2.0
- Created: 2014-09-24T08:21:03.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2024-04-30T17:21:38.000Z (over 1 year ago)
- Last Synced: 2024-08-02T13:34:14.151Z (over 1 year ago)
- Language: Java
- Size: 9.89 MB
- Stars: 83
- Watchers: 57
- Forks: 56
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Spring Data Hazelcast
[](https://maven-badges.herokuapp.com/maven-central/com.hazelcast/spring-data-hazelcast)
The primary goal of the [Spring Data](http://projects.spring.io/spring-data/) is to make it easier to build Spring-powered applications that use new data access technologies. This module provides integration with [Hazelcast](http://hazelcast.com).
# Examples
For examples on using Spring Data Hazelcast, see dedicated Code Samples: [spring-data-hazelcast-chemistry-sample](https://github.com/hazelcast/hazelcast-code-samples/tree/master/hazelcast-integration/spring-data-hazelcast-chemistry-sample) and [spring-data-jpa-hazelcast-migration](https://github.com/hazelcast/hazelcast-code-samples/tree/master/hazelcast-integration/spring-data-jpa-hazelcast-migration).
# Artifacts
## Maven
```xml
com.hazelcast
spring-data-hazelcast
${version}
```
## Gradle
```groovy
dependencies {
compile 'com.hazelcast:spring-data-hazelcast:${version}'
}
```
# Usage
## Spring Configuration
```java
@Configuration
@EnableHazelcastRepositories(basePackages={"example.springdata.keyvalue.chemistry"}) // <1>
public class ApplicationConfiguration {
@Bean
HazelcastInstance hazelcastInstance() { // <2>
return Hazelcast.newHazelcastInstance();
// return HazelcastClient.newHazelcastClient();
}
}
```
1. Enables Spring Data magic for Hazelcast. You can specify `basePackages` for component scan.
2. Instantiates Hazelcast instance (a member or a client)
## Repository Definition
```java
public interface SpeakerRepository extends HazelcastRepository {}
```
## Test of Repository
```java
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = AppConfiguration.class)
public class AppTest {
@Autowired
SpeakerRepository speakerRepository;
@Test
public void testStart(){
speakerRepository.findAll();
}
}
```
# @Query Support
## Sample @Query Usages
### Query with hardcoded value
```java
@Query("firstname=James")
public List peopleWithTheirFirstNameIsJames();
```
### Query with one variable
```java
@Query("firstname=%s")
public List peopleWithTheirFirstName(String firstName);
```
### Query with multiple variable values
```java
@Query("firstname=%s and lastname=%s")
public List peopleWithFirstAndLastName(String firstName,String lastName);
```
## Supported Query Keywords
```
True
False
Equal
NotEqual
Before
LessThan
LessThanEqual
After
GreaterThan
GreaterThanEqual
Between
IsNull
IsNotNull
In
NotIn
Containing
NotContaining
StartingWith
EndingWith
Like
NotLike
Regex
Distinct
IsEmpty
ExistsBy
IsWithin
IsNear
```