Skip to content

Instantly share code, notes, and snippets.

@jeanpierregomez
Created March 14, 2024 22:33
Show Gist options
  • Save jeanpierregomez/1bfe049da2ba2d2d2b8035352c2245bc to your computer and use it in GitHub Desktop.
Save jeanpierregomez/1bfe049da2ba2d2d2b8035352c2245bc to your computer and use it in GitHub Desktop.
@Repository
public class JPARepositoryAdapter extends AdapterOperations<User, UserEntity, String, JPARepository>
implements UserRepository
{
public JPARepositoryAdapter(JPARepository repository, ObjectMapper mapper) {
/**
* Could be use mapper.mapBuilder if your domain model implement builder pattern
* super(repository, mapper, d -> mapper.mapBuilder(d,ObjectModel.ObjectModelBuilder.class).build());
* Or using mapper.map with the class of the object model
*/
super(repository, mapper, d -> mapper.map(d, User.class));
}
@Override
public User getUser(String id) {
return this.findById(id);
}
@Override
public User saveUser(User user) {
return this.save(user);
}
@Override
public User updateUser(User user) {
return this.save(user);
}
@Override
public void deleteUser(String id) {
this.repository.deleteById(id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment