Custom repository class with Spring Data?
Hi,
I'm brand new to Spring Data and trying to get my head wrapped around it a little. I understand that everything (ie: all queries, logic, etc) is generated from interface class, which is backed by the SimpleJpaRepository class. I can foresee this being very practical for any basic queries, etc.
However, how does one manage the situation if/when I need to create some custom code in the repo class? Something that cannot be addressed with a simple query? Something that may need some business logic? For instance, if I have data that I want my repo to encrypt or decrypt prior to persisting?
In a standard DAO/repo situation, I could do something along the lines of:
Code:
public void save( T t){
t.setData( Encryptor.encrypt( t.getData() ) );
em.persist( t );
}
public T getById( Long id ){
// find object
T t = em.find( T.class, id );
t.setData( Decryptor.decrypt( t.getData() ) );
return t;
}
With the concept of only using an interface-based repo in Spring Data, how do I manage something like that? Do I just extend SimpleJpaRepository for my specific DAO needs and then inject that particular DAO bean into my code instead of a generic @Autowire on the interface name?
Thanks!
Eric