Standard Naming Convention for DAO Methods

假如想象 提交于 2019-11-30 09:15:15

Usually I name the methods in such way that the name hints the type of the CRUD operation that will be applied by the method, like add*, save* or find*.

  • add* can be applied on INSERT operations, like addPhoneNumber(Long userId).

  • get* can be applied for SELECT operations, like getEmailAddress(Long userId).

  • set* can be applied on method that performs an UPDATE operation.

  • delete* can be applied on DELETE operations, like deleteUser(Long userId). Althought I'm not pretty sure how useful is the physical delete. Personally, I would set a flag that denotes that the row is not gonna be used, rather than performing a physical delete.

  • is* can be applied on a method that check something, for example isUsernameAvailable(String username).

Angular University

I am aware of conventions like the following:

  • methods starting with find perform select operations, and method names containing the search criteria, like findById, findByUsername, findByFirstNameAndLastName, etc.

  • modification methods start with create, update, delete.

Check out the conventions used by Spring Data JPA. This is part of the Spring framework that writes the DAOs automatically based on among other things inspection of the method name based on naming conventions.

get() for single entities does not seem to be a good option, as get is associated by Java developers to a Java-bean getter.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!