-
Nov 25th, 2008, 11:20 PM
#1
Spring is Right?
I have the following architecture requirements:
1. Use JPA (hibernate), Spring, AOP (compile-time weaving), and @Transactional
2. [Service Objects] <-> [Data Access Objects] <-> [Data Sources]
The problem is that the targeted data sources are dynamic and determined at run time depending on which "client" makes use of Service Objects.
I've read up on various techniques and I think I can solve it except for requirements 3.
3. Add data sources dynamically with no service down-time. That is, bring online a new datasource and change the application context to add extra data source wirings at run time.
JMX seems to be the way to go, BUT can the ApplicationContext be changed dynamically? Ie. can new beans be added, etc...?
Thanks,
-
Nov 26th, 2008, 01:40 AM
#2
You have a number of options then:
- check spring source, perform necessary downcasting and register beans within the context via the mechanisms used by spring internally (not good approach imho);
- perform necessary dependency change by hand at runtime. I.e. if you want to change datasource used by particular DAO, you can manually inject new datasource to it;
- if your 'used resource dependes on client' is consistent between all resources you can implement custom bean scope that provides necessary resource based on available client information (the best approach from my point of view);
-
Nov 26th, 2008, 09:32 AM
#3
So, the idea is that use custom scope in combination of some custom factory managing data sources. The custom factory can then be modified at runtime to manage additional or less data sources.
Sounds right?
-
Nov 26th, 2008, 11:10 AM
#4
Only the custom exists at the higher level of abstraction. Custom scope factory belongs to implementation. So, the answer is to use custom scope and scoped proxies for dependency configuration, expose necessary services for underlying mechanisms runtime configuration.
-
Nov 26th, 2008, 06:14 PM
#5
I am thinking that
1. Scoped proxy
2. AbstractRoutingDataSource
ought to do the trick. I can manipulate the AbstractRoutingDataSource at runtime to add/remove data sources.
One key issue is how to link JPA EntityManagerFactory/EntityManager (Hibernate impl.) to the whole thing. I don't mind using one EntityManager per data source.
What are your thoughts?
Thanks...
-
Nov 26th, 2008, 11:09 PM
#6
Refining
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" scope="myScope">
<aop:scoped-proxy/>
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean" scope="myScope">
<aop:scoped-proxy/>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionM anager" scope="myScope">
<aop:scoped-proxy/>
</bean>
"myScope" will handle the instantiation of transactionManager, entityManagerFactory and dataSource as per some specific values...
sounds right?
Thanks...
-
Nov 27th, 2008, 12:42 AM
#7
-
Nov 30th, 2008, 09:19 PM
#8
I am hesitating over the part where my "scope handler" instantiates the beans. Is there a way to delegate the "new" to Spring along with appropriate dependencies so Spring can wire up the objects?
I am hesitating is I wonder if a plain old "new" is sufficient for all the beans in question.
-
Dec 1st, 2008, 01:33 AM
#9
-
Dec 5th, 2008, 09:56 PM
#10
Wouldn't it be nice to be able to pass in a snippet of "<beans></beans" at runtime to Spring and have Spring add it to its application context? 
That would be cool...I think...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules