On 8/23/12 7:49 AM, "Prasanna Santhanam" <prasanna.santha...@citrix.com> wrote:
>I was looking at moving the Simulator managed entities into a >different database and found that Transaction.java is not able to >switch to the right DB based on context of its execution. > >To explain further: > >The ServerResource for simulator which is the bottommost layer manages >a set of Daos which alter entities in the database : `simulator`. When >the context goes back to the middle manager layers of CS >(ResourceManagerImpl say) after a Command is executed at the >ServerResource all the Daos in the Managers seem to access the >`simulator` db instead of the `cloud` db for their operations. > >I noticed that Transaction.java holds a threadlocal store where it >retains the _previously used database. > >1) Is this a bad design for the simulator in that it tries to alter db >entities at the ServerResource? Sounds like the DAO/Transaction stuff was not designed for this usage. >2) Or is this a bug in the way transactions are managed? It is designed this way. You could execute the transaction in a different thread I suppose. > >3) Or is this the wrong way to switch databases? > >txn = Transaction.open(Transaction.SIMULATOR_DB) >try { > txn.start(); > .... some persistence code here.... > txn.commit(); > > } catch (Exception ex) { > > txn.rollback(); > > } finally { > > txn.close(); > > } > >Thanks, > >-- >Prasanna.,