Skip to content

Move to better naming scheme of methods in repository interfaces [DATACMNS-944] #1399

@spring-projects-issues

Description

@spring-projects-issues

Oliver Drotbohm opened DATACMNS-944 and commented

The current naming scheme for methods in CrudRepository cause quite a few problems. Especially the methods taking parameters that are generic type variables. Under bad circumstances they could effectively resolve to the same methods and cause ambiguities.

With the 2.0 release we have the chance to correct those mistakes and the following scheme is suggested (pseudo code):

// Previously ID extends Serializable
interface CrudRepository<T, ID> {

	<S extends T> … save(S entity);
	// Previously save(Iterable)
	<S extends T> … saveAll(Iterable<S> entities);

	// Previously findOne(ID)findById(ID id);

	// Previously exists(…)existsById(ID id);

	… findAll();
	… findAllByIds(Iterable<ID> ids);

	… count();

	// Previously delete(ID)deleteById(ID id);
	… delete(T entity);

	// Previously delete(Iterable)deleteAll(Iterable<? extends T> entities);
	… deleteAll();
}

The methods that are effected by a change are marked with a comment here. The new scheme is driven by the following requirements:

  1. We're able to uniquely find methods by name and raw parameter type (ideally by the number of parameters in the first place). Previously, the generics of esp. the delete(…) methods could effectively resolve to the same type.
  2. Methods named …All(…) affect a collection of items and/or return one.
  3. Methods taking an identifier are named …ById(…).
  4. With that in place, we can reliably drop the ID extends Serializable requirement, which is not possible without that change as then the delete(…) methods would be ambiguous

Issue Links:

  • DATACASS-441 Adapt to API changes in repository interfaces
    ("is depended on by")
  • DATAKV-177 Adapt to API changes in repository interfaces
    ("is depended on by")
  • SGF-623 Adapt to API changes in Repository interfaces
    ("is depended on by")
  • DATAMONGO-1679 Adapt to API changes in CrudRepository
    ("is depended on by")
  • DATACOUCH-305 Adapt to API changes in repository interfaces
    ("is depended on by")
  • DATAGRAPH-991 Adapt to API changes in repository interfaces
    ("is depended on by")
  • DATAJPA-1104 Adapt to API changes in repository interfaces
    ("is depended on by")
  • DATAKV-176 Adapt to API changes in repository interfaces
    ("is depended on by")
  • DATALDAP-35 Adapt to API changes in repository interfaces
    ("is depended on by")
  • DATAREDIS-640 Adapt to API changes in repository interfaces
    ("is depended on by")
  • DATAREST-1064 Adapt to API changes in repository interfaces
    ("is depended on by")
  • DATASOLR-385 Adapt to API changes in repository interfaces
    ("is depended on by")
  • DATAES-352 Adapt to API changes in CrudRepository
    ("is depended on by")
  • DATAREDIS-641 Adapt to API changes in CrudRepository
    ("is depended on by")
  • DATAREST-1065 Adapt to API changes in CrudRepository
    ("is depended on by")
  • SGF-622 Adapt to API changes in CrudRepository
    ("is depended on by")
  • DATACMNS-574 Change CrudRepository to return Optional<T> as return values instead of null reference or provide alternative base interface

1 votes, 18 watchers

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions