如何查看 Spring Data MongoDB 生成的存储库实现? [英] How to see the repository implementation generated by Spring Data MongoDB?

查看:28
本文介绍了如何查看 Spring Data MongoDB 生成的存储库实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么时候实现 Spring Data 生成的存储库?在编译时还是运行时?可以看到 Spring Data 生成的实现仓库实现吗?

When is the implementation for repositories generated by Spring Data? At compile time or runtime? Can I see the implementation repository implementation generated by Spring Data?

推荐答案

tl;dr

不,原因很简单:没有进行代码生成.该实现基于代理和将调用执行委托到正确位置的方法拦截器.

tl;dr

No, for a very simple reason: there's no code generation going on. The implementation is based on proxies and a method interceptor delegating the call executions to the right places.

实际上,方法执行可以由 3 种类型的代码支持:

Effectively, a method execution can be backed by 3 types of code:

  1. CrudRepository 的 store 特定实现.查看名为 Simple(Jpa|Mongo|Neo4|…)Repository 的类型(参见 JPA 特定的 这里).他们有真实的"CrudRepositoryPagingAndSortingRepository 中所有方法的实现.

  1. The store specific implementation of CrudRepository. Have a look for types named Simple(Jpa|Mongo|Neo4|…)Repository (see the JPA specific one here). They have "real" implementations for all of the methods in CrudRepository and PagingAndSortingRepository.

查询方法由 QueryExecutorMethodInterceptor.doInvoke(…) 有效执行(参见 这里).找到委托目标并调用它基本上是一个 3 步过程.实际的执行是在名为 (Jpa|Mongo|Neo4j…)QueryExecution 的类中完成的(例如,参见这个).

Query methods are effectively executed by QueryExecutorMethodInterceptor.doInvoke(…) (see here). It's basically a 3-step-process to find the delegation target and invoke it. The actual execution is done in classes named (Jpa|Mongo|Neo4j…)QueryExecution (see this one for example).

直接调用自定义实现代码,同样来自QueryExecutorMethodInterceptor.

Custom implementation code is called directly, also from QueryExecutorMethodInterceptor.

唯一剩下的就是查询派生,它由两个主要部分组成:方法名解析和查询创建.对于前者,请查看 PartTree.它接受一个方法名和一个基类型,如果它无法解析属性等,它将返回一个已解析的类似 AST 的结构或抛出异常.

The only thing left is the query derivation, which consists of two major parts: method name parsing and query creation. For the former, have a look at PartTree. It takes a method name and a base type and will return you a parsed AST-like structure or throw an exception if it fails to resolve properties or the like.

后者在名为 PartTree(Jpa|Mongo|Neo4j|…)Query 的类中实现,并委托给其他组件以实际创建特定于商店的查询.例如.对于 JPA,有趣的部分可能在 JpaQueryCreator.PredicateBuilder.build() 中(参见 这里).

The latter is implemented in classes named PartTree(Jpa|Mongo|Neo4j|…)Query and delegates to additional components for actually creating the store specific query. E.g. for JPA the interesting bits are probably in JpaQueryCreator.PredicateBuilder.build() (see here).

这篇关于如何查看 Spring Data MongoDB 生成的存储库实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆