public class MethodSourceContainer extends BaseNamespaceContainer<Object,Object> implements Container
表示以实例方法作为数据源的数据源容器。内部维护有方法实例与命名空间的映射表。
当spring启动时,将扫描容器中类上带有MethodSourceBean注解的实例,
并通过register(Object)将其注册到方法数据源容器中。
方法数据源会进一步解析该示例中被MethodSourceBean.Method注解的方法,
按照各自MethodSourceBean.Method#namespace()
缓存到不同的命名空间中。
容器中作为数据源的方法应当有且仅有一个Collection及其子类型的入参,
当调用时,会将一批对象中Assemble指定的key集合作为参数,传入命名空间对的方法。
方法的返回也应当为Collection集合或其子类。
容器根据MethodSourceBean.Method#mappingType()属性指定的MappingType枚举,
支持按照MethodSourceBean.Method#sourceKey()指定的key对数据源一对多或多对一。
当指定为MappingType.ONE_TO_ONE时,容器根据key批量获取的数据源默认将会按一对一分组,
当出现复数数据源对一个key值时将会抛出异常。此时装配器根据key获得到的值为数据源对象本身。
当指定为MappingType.ONE_TO_MORE时,容器将按key分组,此时装配器根据key获得到的值为数据源对象集合。
MethodSourceBean| 限定符和类型 | 类和说明 |
|---|---|
static class |
MethodSourceContainer.MethodSource |
| 限定符和类型 | 字段和说明 |
|---|---|
Map<String,MethodSourceContainer.MethodSource> |
methodCache |
ORDERLY_COMPARATOR| 构造器和说明 |
|---|
MethodSourceContainer() |
| 限定符和类型 | 方法和说明 |
|---|---|
protected Map<String,Map<Object,Object>> |
getSources(com.google.common.collect.Multimap<String,Object> namespaceAndKeys)
根据装配的key字段值与namespace获取对应的数据源对象集合
|
void |
register(Object methodSourceBean)
注册方法数据源
|
void |
unregister(String namespace)
注销已注册方法数据源
|
getNamespaceAndKeyFromTargets, parseKey, process, writeToTargetsclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcomparator, compareTo, getActualOrder, getOrderpublic final Map<String,MethodSourceContainer.MethodSource> methodCache
public void unregister(String namespace)
namespace - 命名空间public void register(Object methodSourceBean)
methodSourceBean - 方法数据源@Nonnull protected Map<String,Map<Object,Object>> getSources(@Nonnull com.google.common.collect.Multimap<String,Object> namespaceAndKeys)
BaseNamespaceContainergetSources 在类中 BaseNamespaceContainer<Object,Object>namespaceAndKeys - namespace与key字段值集合Copyright © 2022. All rights reserved.