There's nothing in Neo yet that allows for accessing multple database from a single context but the context/datastore boundary was designed with this in mind.
The idea is to have multiple datastores, one for each database, and a new "DataStoreCoordinator" that implements IDataStore and can forward queries to "real" datastores. (It could have a table that lists which datastore to use for which entity.) The context only knows the DataStoreCoordinator. Somehow like this:
. ObjectContext
|
DataStoreCoordinator
/ \
SqlDataStore OracleDataStore
This poses a fewimportant questions:
- How does the coordinator know which store to use?
- How do you do queries that span multiple tables?
- How do you guarantee atomicity on saves?
I think the answer to question 1 is quite simple and one could add a database name to the table in the xml file and make this information available through the EntityMaps. At runtime you could do something like:
IDataStore store1 = new SqlDataStore("...");
IDataStore store2 = new OracleDataStore("...");
DataStoreCoordinator coordinator = new DataStoreCoordinator();
coordinator.AddStore("sqlstore", store1);
coordinator.AddStore("oracledb", store2);
ObjectContext context = new ObjectContext(coordinator);
Question 2 is harder but it should be possible for the coordinator to analyse and modify the fetchspec, maybe split it, and then forward the sub queries to the individual stores.
The answer to question 3 is, of course, two-phase commit. (Unless you never update more that one database at a time; which is actually not a completely unlikely scenario.) The coordinator would probably have to stipulate that data stores implement an interface that allows the coordinator to access two-phase commit functionality provided by the underlying data store. Somethow like this:
interface ICooperatingDataStore : IDataStore
{
void Prepare();
void Commit();
void Rollback();
}
Save changes in the StoreCoordinator can then identify all stores required for the save, call prepare and if everybody's ready call commit.
