Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- OObjectDatabaseTx db = new OObjectDatabaseTx ("remote:localhost/demo").open("admin", "admin");
- db.getEntityManager().registerEntityClass(A.class);
- db.getEntityManager().registerEntityClass(B.class);
- db.begin();
- try {
- int amt = 10;
- OCommandSQL cmd = new OCommandSQL("update A set id = eval('id - $id') where eval('id - $id') > 0");
- cmd.getContext().setVariable( "id", 100 );
- int recordsUpdated = db.command(cmd).execute();
- //int recordsUpdated = db.command(new OCommandSQL("update A set id = eval('id - "+ amt +"') where eval('id - "+ amt +"') > 0")).execute();
- B b = new B();
- b.setName("B class");
- db.save(b);
- System.out.println(recordsUpdated);
- throw new Exception();
- } catch (Exception e) {
- System.out.println("rollbacked...");
- db.rollback();
- }
- /*OCommandSQL cmd = new OCommandSQL("update A set id = eval('id - $id') where eval('id - $id') > 0");
- cmd.getContext().setVariable( "id", 100 );
- int recordsUpdated = db.command(cmd).execute();*/
- 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