Migrate repository methods changed in Spring Data 2.0
ProprietarySpring Data 2.0 renamed the CrudRepository methods that took an id or an Iterable: findOne(id) to findById(id), which returns an Optional, exists(id) to existsById(id), delete(id) to deleteById(id), delete(Iterable) to deleteAll(Iterable), save(Iterable) to saveAll(Iterable) and findAll(Iterable) to findAllById(Iterable). findOne of a Predicate, Specification or Example keeps its name and returns an Optional too. A call to findOne(id) becomes findById(id).orElse(null), and the others get the same orElse(null), so that they still give null for a missing entity. Mockito stubbings and verifications of these methods stay on the method itself, and the values given to thenReturn, willReturn and doReturn become Optionals. Repositories that redeclare these methods are changed along with their callers, since Spring Data 2.0 would otherwise read a leftover findOne(id) as a query method. A repository's own T findById(ID), which no longer compiles on Spring Data 2.0, becomes Optional<T> findById(ID) with its callers. Calls to delete(entity) and save(entity) keep their names. Overrides of findOne(id) that have a body, repositories with another findById that gives no Optional, and method references to findOne are left for the compiler to point out. Only code compiled against Spring Data 1.x is changed.
io. moderne. java. spring. data. MigrateCrudRepositoryMethodsmod run . --recipe= io. moderne. java. spring. data. MigrateCrudRepositoryMethodsInstall it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.