[
https://issues.apache.org/jira/browse/IGNITE-1192?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15398164#comment-15398164
]
Semen Boikov commented on IGNITE-1192:
--------------------------------------
Here are some thoughts how spring data integration can look like. Main feature
Spring Data provides - Repository concept, user just defines some interface for
entity access and spring data framework automatically generates CRUD/query
methods.
Basically, it can look like this:
There is cache enity type:
{code}
class Person {
@QuerySqlField(index = true)
private String firstName;
@QuerySqlField(index = true)
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
{code}
User creates PersonRepository interface:
{code}
// PersonRepository, spring data automatically generates CRUD/query methods.
interface PersonRepository extends CrudRepository<Person, Long> {
// Inherited from CrudRepository, call cache.get(key)
Person findOne(Long key);
// Inherited from CrudRepository, call cache.containsKey(key)
boolean exists(Long key);
// Inherited from CrudRepository, call cache.remove(key)
void delete(Long key);
// SQL query 'where firstName=?'
List<Person> findByLastname(String lastname);
// SQL query 'where firstName=? or lastName=?'
List<Person> findByFirstnameOrLastname(String firstname, String
lastname);
// Query with pagination.
Page<Person> findPersonByLastname(String lastname, Pageable page);
}
{code}
Then spring-data framework should atomatically generate repository methods
implementation so that PersonRepository.findOne will call cache.get(), and
PersonRepository.findByLastname will execute Ignite SqlQuery 'select from
Person where firstName=?'.
(there also should be some ignite-specific configuration which can be used by
repository to connect to Ignite).
Some notes:
- there is separate module 'Spring Data Key Value' which provides some
infrastructure for key/value storage integration
(https://github.com/spring-projects/spring-data-keyvalue). Need check if it
makes sense to use it for Ignite integration
- standard repository assumes that each entity has some 'id' field - unique
entity identifier, (e.g. database primary key), but for values stored in Ignite
cache often this is not the case. Maybe it makes sense to add special
IgniteRepository interface with save methods which will accept 'key' parameter?
But it still makes sense support 'id': if enity has propery with @Id annotation
it can be use as cache key, thus standard CrudRepository.save API can be used.
- there should be some way to specify what cache to use for entity access.
Looks like 'Spring Data Key Value' has KeySpace annotation for such purpose (or
it can be Ignite-specific annotation/repositiry configuration parameter/derived
from class name?)
> Provide integration with Spring Data
> ------------------------------------
>
> Key: IGNITE-1192
> URL: https://issues.apache.org/jira/browse/IGNITE-1192
> Project: Ignite
> Issue Type: Bug
> Components: general
> Affects Versions: 1.1.4
> Reporter: Valentin Kulichenko
> Assignee: Juan C Fiorenzano
> Priority: Minor
> Labels: Newbie
> Fix For: 1.7
>
>
> Spring Data docs:
> * http://docs.spring.io/spring-data/data-commons/docs/current/reference/html/
> * http://docs.spring.io/spring-data/data-commons/docs/current/api/
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)