Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. OObjectDatabaseTx db = new OObjectDatabaseTx ("remote:localhost/demo").open("admin", "admin");
  2. db.getEntityManager().registerEntityClass(A.class);
  3. db.getEntityManager().registerEntityClass(B.class);
  4. db.begin();
  5. try {
  6. int amt = 10;
  7. OCommandSQL cmd = new OCommandSQL("update A set id = eval('id - $id') where eval('id - $id') > 0");
  8. cmd.getContext().setVariable( "id", 100 );
  9. int recordsUpdated = db.command(cmd).execute();
  10. //int recordsUpdated = db.command(new OCommandSQL("update A set id = eval('id - "+ amt +"') where eval('id - "+ amt +"') > 0")).execute();
  11. B b = new B();
  12. b.setName("B class");
  13. db.save(b);
  14. System.out.println(recordsUpdated);
  15. throw new Exception();
  16. } catch (Exception e) {
  17. System.out.println("rollbacked...");
  18. db.rollback();
  19. }
  20.  
  21. /*OCommandSQL cmd = new OCommandSQL("update A set id = eval('id - $id') where eval('id - $id') > 0");
  22. cmd.getContext().setVariable( "id", 100 );
  23. int recordsUpdated = db.command(cmd).execute();*/
  24. int recordsUpdated = db.command(new OCommandSQL("update A set id = eval('id - "+ amt +"') where eval('id - "+ amt +"') > 0")).execute();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement