Not so long ago on Habré there was a good
post dedicated to the project
Spring Data-JPA .
The project impressed me a lot, because He offered a well thought out solution for working with
repositories .
We had our own work on this topic, however, Spring Data-JPA was a much more elegant and functional solution.
There was one snag - the projects with which I work are built using Google Guice.
At one time it was my conscious choice and, in general, he still suits both project teams and customers.
... but the concept of Spring Data JPA repositories was too tasty ...
As a result of some reflections, it was decided to create an integration module between Spring Data-JPA and the
guice-persist subsystem from the set of standard Google Guice integration modules.
The Spring Data-JPA architecture is intelligently designed, making such integration possible.
')
What came of it
The list of main features of the integration module:
- Full support for parts 1.1-1.4 and 2.2-2.4 of the Spring Data-JPA specification
- Support for batch inserts (see here )
- Direct Access to EntityManager from Repository
- The possibility of autobinding for all repositories in the specified packages (see here )
- Configuration - separation of common ORM-mapping moments and specific DBMS parameters (see here )
How to work with it?
Here are three main steps:
1. Creating your version of the
repository :
public interface AccountRepository extends JpaRepository<Account, Long>,
EntityManagerProvider {
Account findAccountByUuid( String uuid);
@Query( "select a from Account a where a.name = :name" )
Account findAccountByName(@Param( "name" ) String name);
}
2. Installing an integration Guice module:
install( new JpaRepositoryModule( "my-persistence-unit" ) {
protected void configureRepositories() {
bind(AccountRepository. class ).toProvider( new JpaRepositoryProvider<AccountRepository>());
}
});
3. Injection and use:
public class AccountService {
@Inject
private AccountRepository accountRepository;
public void registerUser( String login, String password) throws RegistrationException{
// ... some checks & etc
accountRepository.save( new Account(login, password));
// ... something else
}
public Account findAccount( String login) throws FinderException{
return accountRepository.findAccountByLogin(login);
}
}
Live examples of use can be found in the project JUnit tests:
http://code.google.com/p/guice-repository/source/browse/tags/1.0.0/src/test/java/com/google/code/guice/repository/More detailed aspects of the use are described in the project documentation:
http://code.google.com/p/guice-repository/wiki/DevGuideThe project is available to everyone under the Apache License 2.0 license:
http://code.google.com/p/guice-repository/Artifact in the central Maven repository:
< dependency >
< groupId > com.google.code.guice-repository </ groupId >
< artifactId > guice-repository </ artifactId >
< version > 1.0.0 </ version >
</ dependency >
I would be glad if the project will be useful to you :)
Thanks for attention!