开发者

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

  1. 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
  2. create one EntityManager per base (even if they are sharing same connection)
  3. create a proxy which passes calls to multiple EntityManagers and collects responses
  4. 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#.

  1. 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.
  2. One facade, the knows which database you're using at the moment, and directs requests to one of two...
  3. 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.
  4. 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.
  5. Dynamic code generators are also useful, for inserts, updates, where clauses, etc.
  6. 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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜