Dynamic ORM datasource by session

I have an architectural challenge in my current system and I am hoping someone out there has some done something simliar and can provide some help. I have an application that currently uses a single code base but separate client databases and separate CF application names for security purposes. We are porting the entire app to Coldbox and would like to use ORM. We would also like to consolidate down to a single application name so we are not caching the entire framework once per client. It seems like this is impossible considering you have to explicitly declare your ORM datasource in application.cfc and CF caches the entity objects by datasource. One option we explored was using the VirtualEntityService methods that support the “datasource” argument so we could change it with each call. This works fine when you use the same datasource as you declared in application.cfc but when you try a new one, CF throws an error saying that there is no active hibernate session for the given datasource. We also tried using a variable for the “datasource” attribute of our entity object and CF throws an unknown error. One last option we are pursuing is trying to use a hibernate configuration file so we can explicitly declare all of our datasources up front and hope that this opens a hibernate session for each allowing dynamic assignment of the datasource in our ORM calls. Any thoughts or ideas on a solution would be greatly appreciated.

This is just a teaser but shows how.

http://www.andyscott.id.au/blog/writing-a-coldbox-application-to-handle-more-than-one-site-with-orm-support

Hi Andrew,

Thanks for the example code, it is great. Are you using the same application name for each client in this example or do you set it dynamically similar to the ORM data source?

Thanks,
Micah

Yeah the application is set dependent on the client, so that the entire site operates as if it was a single site for each client.

Right. I was hoping to avoid that because we have 50+ clients at present and it does not seem very scalable to have the ColdBox framework and all the ORM entities cached in memory for each individual client. How has it performed for you?

It has been awhile since I worked on the site, but there is no reason you have to change the Application name. It was easier for that site as each client had their own administration section, as well as separate ORM to be specific to certain clients as well.

When I ran jMeter against the site, it could handle the maximum IIS settings for concurrent connections and there was very little increase in the JVM. But these sites where only getting around 30k hits a month so they were very lite or small as far as traffic goes.

But if you think about hosting providers, they have more than 100 clients on some servers.