Good afternoon!
After some trial and error we managed to find a solution. The answer was
in using Spring's AbstractRoutingDatasource. We point the
SqlSessionFactory's datasource to a class we created which returns a
different datasource based on parameters on the code. Follows are the
relevant snippets in case anyone needs to perform the same action.
(CustomerType is a simple enum with values C3 and C7)
public class SharedDataSource extends AbstractRoutingDataSource {
protected Object determineCurrentLookupKey() {
BigDecimal customerId = UserContext.getUserContext().getCustomerId();
switch( customerId.intValue() ) {
case 3:
return CustomerType.C3;
case 7:
return CustomerType.C7;
default:
throw new RuntimeException( "Datasource not defined for customer " +
customerId );
}
}
}
spring configuration for the datasource
<bean id="T24.JDBC.SharedDataSource"
class="com.armada.t24.core.db.SharedDataSource">
<property name="targetDataSources">
<map key-type="com.armada.t24.core.db.CustomerType">
<entry key="C3" value-ref="T24.JDBC.ARCDataSource"/>
<entry key="C7" value-ref="T24.JDBC.CFADataSource"/>
</map>
</property>
</bean>
Thanks!
Steve.