Exploring the principle of spring-data-jpa (3) - QueryMethod class

In the third article, let's talk about the QueryMethod related classes in the JPA specification. First give the class diagram and inheritance relationship:

very simple, right? There are only two related classes, QueryMethod and its subclass JpaQueryMethod.
The QueryMethod class is located in the spring-data-commons-***.jar package; and the JpaQueryMethod is located in the spring-data-jpa-***.jar package. That is to say, QueryMethod is a generic class in the spring-data package; and JpaQueryMethod is a class in the spring-data-jpa implementation that extends QueryMethod in the generic package.
QueryMethod: An abstraction of the method specified for running finder queries. It enriches the standard java.lang.reflect.Method interface and the specific RepositoryQuery information that must be constructed for this method.
JpaQueryMethod: JPA concrete/specific extension class of QueryMethod.

The QueryMethod class holds several private class variables such as RepositoryMetadata, Method, Parameters, domainClass, etc. The RepositoryMetadata stores the metadata of the repository interface. The class diagram is as follows:

Parameters is an instance of JpaParameters, which stores a set of key-value pairs of parameter names and parameter values. JpaParameters also contains an internal class, JpaParameter, which extends Parameter;

domainClass is usually assigned a value It is the Class class defined in the generic type of the Repository interface, or the Class class of the method return value;

Open the source code, we are surprised to see that the JpaQueryMethod class also holds a private Method class variable. Here, I cautiously suspect that it is a small bug in the software design by the developer. Since the parent class holds a Method class variable, It can be inherited and used by subclasses by various means.
The JpaQueryMethod class contains several class variables that parse the JPA 2.1 specification to support the configuration of stored procedures; and the QueryExtractor query extractor implementation. Through this setting, the original JPA query string can be extracted from the jpa Query according to different implementations. Here, the default Persistence Provider provider implementation of spring-data-jpa is hibernate.

In spring-data-jpa, JpaQueryMethod is all the information of the @Query annotation method in the Repository interface, including the storage class of annotations, class names, actual parameters, etc., so how many @Query annotation methods the Repository interface has, it will contain How many JpaQueryMethod instances are added to the listening sequence. When actually running, a RepositoryQuery instance holds a JpaQueryMethod instance, and JpaQueryMethod holds a Method instance.

To be continued.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326752289&siteId=291194637