Welcome to Spring Data Hazelcast project!
The primary goal of the Spring Data project is to make it easier to build Spring-powered applications that use data access technologies.
Spring Data Hazelcast project will enable the Spring Data paradigm to gain the power of a distributed data repository.
Submit your question with hazelcast
and spring-data-hazelcast
tags.
Please, join the mail group if you are interested in using or developing Hazelcast.
The Spring platform is a commonly used environment and Hazelcast is the most widely used IMDG. Therefore it is natural to provide a way to use Hazelcast via Spring in a standard, platform neutral manner and to provide a baseline implementation of Spring Data Hazelcast that can be enhanced with Hazelcast specific features.
The implementation is built on the new Spring Data KeyValue module and is one of the first projects to do this.
This module provides infrastructure components for creating repository abstractions for stores dealing with Key/Value pairs like java.util.Map
or Hazelcast IMap
.
Through the means of the repository interface, CRUD operations, and expression-based query methods can interrogate an in-memory data store in a manner consistent with the other Spring Data projects allowing developers to be productive quickly and easily.
-
Familiar "Spring Data" approach, developers do not need to learn a new technology to be able to use it
-
Utilizes the new Spring-Data-Key value abstraction, we did not reinvent the wheel
-
FURTHER eases the integration of Hazelcast into Spring and clouds
-
Reduces vendor lock-in. One can swap Hazelcast in place of more expensive or slower options
-
@Query Support
@Configuration
@EnableHazelcastRepositories(basePackages={"example.springdata.keyvalue.chemistry"}) // (1)
public class ApplicationConfiguration {
@Bean
HazelcastInstance hazelcastInstance() { // (2)
return Hazelcast.newHazelcastInstance();
// return HazelcastClient.newHazelcastClient();
}
@Bean
public KeyValueOperations keyValueTemplate() { // (3)
return new KeyValueTemplate(new HazelcastKeyValueAdapter(hazelcastInstance()));
}
@Bean
public HazelcastKeyValueAdapter hazelcastKeyValueAdapter(HazelcastInstance hazelcastInstance) {
return new HazelcastKeyValueAdapter(hazelcastInstance);
}
}
-
Enables Spring Data magic for Hazelcast. You can specify
basePackages
for component scan. -
Instantiates Hazelcast instance (a member or a client)
-
Instantiates KV template
public interface SpeakerRepository extends HazelcastRepository<Speaker, Long> {}
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = AppConfiguration.class)
public class AppTest {
@Autowired
SpeakerRepository speakerRepository;
@Test
public void testStart(){
speakerRepository.findAll();
}
}
Query with hardcoded value
@Query("firstname=James")
public List<Person> peoplewiththeirFirstNameIsJames();
Query with one variable
@Query("firstname=%s")
public List<Person> peoplewiththeirFirstName(String firstName);
Query with multiple variable values
@Query("firstname=%s and lastname=%s")
public List<Person> peoplewithFirstAndLastName(String firstName,String lastName);
Hazelcast is available under the Apache 2 License. Please see the Licensing appendix for more information.
Copyright (c) 2008-2016, Hazelcast, Inc. All Rights Reserved.
Visit http://www.hazelcast.com for more information.