multiple databases with same structure
What is the best way in doctrine2 to开发者_如何学JAVA deal with different bases but with the same schema. Currently I
- generate entities separately for every database, adding namespace and name of database to every metadata object, putting them in the different namespaces (XXX\Base\EntityClass), but with the same alias
- create one EntityManager per base (even if they are sharing same connection)
- create a proxy which passes calls to multiple EntityManagers and collects responses
- merge responses in one output
Is there simpler way of dealing with multiple bases in doctrine2 ?
I can't answer for doctrine2, but I'm doing this in C#.
- One set of entities, with strong names and strong types, defined in terms of what the rest of the application needs. This maps the schema, but isn't tied to either database.
- One facade, the knows which database you're using at the moment, and directs requests to one of two...
- Separate data access namespaces, that handle a common set of operations, and populate results into the single set of entities, which are returned to the requestor through the facade.
- Static code generators, based on reading the scema from the database catalog, are useful. You may want to pick one as a model, if you can infer everything you need to know about the other database.
- Dynamic code generators are also useful, for inserts, updates, where clauses, etc.
- Invest some time in a framework to support all of this. Decide whether you need to keep metadata at run time, and whether it's primarily to support queries or change operations. Provide a common method for extracting data from results sets for either database, so that you can get strongly named and typed result sets back to your application without regard to the underlying database.
精彩评论