请问有人了解ResourceHolderSupport是做什么用的吗?
类全路径 为:org.springframework.transaction.support.ResourceHolderSupport
或者说Holder这个关键字在Spring中的命名表示什么意思,比如在Spring中
JDBC有ConnectionHodler
Hiberate有SessionHolder等
从结构上说ResourceHolderSupport是“资源句柄支持类”,作用在于方便ResourceHolder接口的实现。
可以把类名分解来理解:
Resource:资源,将会被其它类使用的某类资源。
Holder:句柄,即拥有某种资源,同时可以对资源实施一定的操作。
Support:支持,如果使用过ActionSupport,就会比较容易理解这里support的含义。在spring的类定义中,support是一种实现某接口部分函数的抽象类,它为其子类提供了部分函数的实现,在需要创建子类时,子类只需实现或重写个性化的方法即可。
例如:
JmsResourceHolder继承了ResourceHolderSupport,作为Jms资源句柄,封装了JMS的connection、session等资源。
[code="java"]
/**
Note: This is an SPI class, not intended to be used by applications. *
@see org.springframework.jms.core.JmsTemplate
*/
public class JmsResourceHolder extends ResourceHolderSupport {
private static final Log logger = LogFactory.getLog(JmsResourceHolder.class);
private ConnectionFactory connectionFactory;
private boolean frozen = false;
private final List connections = new LinkedList();
private final List sessions = new LinkedList();
private final Map> sessionsPerConnection =
new HashMap>();
/**
[/code]
Holder 是句柄/持有人的意思 ResourceHolderSupport 应该是资源句柄支持的意思。
API:
Convenient base class for resource holders.
Features rollback-only support for nested transactions. Can expire after a certain number of seconds or milliseconds, to determine transactional timeouts.
回滚功能只支持嵌套事务。可以几秒钟后失效或毫秒一定数量,以确定事务超时。
应该是对Resource的处理把。
先说下Spring中的support类的功能,作为抽象类,提高代码复用。
Holder应该算是适配器模式的实现。Session,connection and entitymanager都算是第三方的东西,所以spring针对每个第三方component提供自己的holder作为适配器,集成到spring的platform中。