We use the Spring TransactionInterceptor
to set the database partition information using ThreadLocal
whenever the DAO method marked with the @Transactional
annotation is @Transactional
. We need this in order to be able to direct our requests to different sections of the database.
This works great for most DAO methods:
// this causes the invoke method to set a thread-local with the host name of // the database server the partition is on @Transactional public int deleteAll() throws LocalDataException {
The problem is when we need to reference the DAO proxy object itself inside the DAO. As a rule, we should have the pass of the caller in the proxy dao:
public Pager<Foo, Long> getPager(FooDao proxyDao) {
This is as follows in the code, which is clearly important.
fooDao.getPager(fooDao);
The problem is that when we are inside FooDao, this
not the DAO proxy that we need.
Is there a better mechanism for a bean to discover that it has a proxy around it? I looked at Spring AOPUtils , but I see no way to find proxies for an object. I do not want, for example, isAopProxy(...)
. I also read Spring AOP docs , but I don't see a solution there unless I implement my own native AOP code, which I was hoping to avoid.
I suspect that I could inject the DAO into myself using the ApplicationContextAware
bean and setProxyDao(...)
utilities, but this seems like a hack. Any other ideas how I can define a proxy so that I can use it from the bean itself? Thanks for any help.
source share