org.jpos.ee.DB.beginTransaction()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(176)

本文整理了Java中org.jpos.ee.DB.beginTransaction()方法的一些代码示例,展示了DB.beginTransaction()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DB.beginTransaction()方法的具体详情如下:
包路径:org.jpos.ee.DB
类名称:DB
方法名:beginTransaction

DB.beginTransaction介绍

暂无

代码示例

代码示例来源:origin: jpos/jPOS-EE

public void setNextCommand (String id, String command) 
  throws HibernateException, SQLException
{
  Transaction tx = db.beginTransaction();
  Status status = getStatus (id, false);
  if (status != null)
    status.setCommand (command);
  tx.commit();
}
/**

代码示例来源:origin: jpos/jPOS-EE

/**
 * @param id status id
 * @param state Status.OK, Status.WARN, Status.ERROR or user defined
 * @param detail optional detail information
 */
public void touch (String id, String state, String detail) 
  throws HibernateException, SQLException
{
  Transaction tx = db.beginTransaction();
  Status status = touch (id, state, detail, tx);
  tx.commit();
  db.session().evict (status);
}

代码示例来源:origin: jpos/jPOS-EE

@Override
  public void exec(CLIContext cli, String[] args) throws Exception {
    String filename = "-";  // defaults to stdout     '
    String configModifier = null;
    boolean create = false;
    if (args.length > 1)
      filename = args[1];
    if (args.length > 2)
      create = "yes".equalsIgnoreCase(args[2]) || "true".equalsIgnoreCase(args[2]);
    if (args.length > 3)
      configModifier = args[3];

    try (DB db = new DB(configModifier)) {
      db.open();
      db.beginTransaction();
      db.createSchema(filename, create);
    }
  }
}

代码示例来源:origin: jpos/jPOS-EE

private void create (String id) {
    try (DB db = new DB()) {
      db.open();
      db.beginTransaction();
      SeqNo seq = new SeqNo(id);
      db.session().save(seq);
      db.commit();
    } catch (Exception ignored) { }
  }
}

代码示例来源:origin: jpos/jPOS-EE

public static <T> T execWithTransaction(DBAction<T> action) throws Exception {
  try (DB db = new DB()) {
    db.open();
    db.beginTransaction();
    T obj = action.exec(db);
    db.commit();
    return obj;
  }
}

代码示例来源:origin: jpos/jPOS-EE

public static <T> T execWithTransaction(String configModifier, DBAction<T> action) throws Exception {
  try (DB db = new DB(configModifier)) {
    db.open();
    db.beginTransaction();
    T obj = action.exec(db);
    db.commit();
    return obj;
  }
}

代码示例来源:origin: jpos/jPOS-EE

private void createSchema () throws HibernateException, DocumentException {
  DB db = new DB();
  db.open();
  db.beginTransaction();
  db.createSchema(null, true);
  db.commit();
  db.close();
}

代码示例来源:origin: jpos/jPOS-EE

/**
 * Release an async lock
 * @param id lock ID
 * @param lockedBy  unique client identifier
 */
public boolean release (String id, long lockedBy) {
  if (db.session != null && db.session.isOpen())
    throw new IllegalStateException("DB should not be open");
  try (DB db1 = db) {
    db1.open();
    db1.beginTransaction();
    SeqNo seq = getOrCreate(id);
    if (seq.getLockedBy() == lockedBy && seq.getLockUntil() > System.currentTimeMillis()) {
      seq.setLockedBy(0L);
      db1.commit();
      return true;
    }
  }
  return false;
}

代码示例来源:origin: jpos/jPOS-EE

private void createTransactions (DB db, Iterator iter)
 throws SQLException, HibernateException, ParseException, GLException {
  GLSession gls = new GLSession(db);
  while (iter.hasNext()) {
    Transaction txn = db.beginTransaction();
    Element elem = (Element) iter.next ();
    GLTransaction glt = new GLTransaction (elem);
    Journal journal = getJournal (
      db.session(), elem.getAttributeValue ("journal")
    );
    glt.setJournal (journal);
    addEntries (
      db.session(), glt,
      elem.getChildren("entry").iterator()
    );
    gls.post(journal, glt);
    txn.commit ();
    System.out.println (glt.getId() + " " + glt.getDetail());
  }
}
private void addEntries (

代码示例来源:origin: jpos/jPOS-EE

@Override
  public void exec(CLIContext cli, String[] args) throws Exception {
    if (args.length < 2) {
      cli.println("Usage: rm <id> ");
      return;
    }
    try (DB db = new DB()) {
      db.open();
      db.beginTransaction();
      SysConfigManager mgr = new SysConfigManager(db);
      if (cli.getUserData().containsKey(SYSCONFIG.PREFIX))
        mgr.setPrefix((String) cli.getUserData().get(SYSCONFIG.PREFIX));
      boolean deleted = mgr.delete(args[1]);
      db.commit();
      cli.println ("sysconfig " + (deleted ? "deleted" : "not found"));
    } catch (Exception e) {
      cli.println (e.getMessage());
    }
  }
}

代码示例来源:origin: jpos/jPOS-EE

@Override
  public void exec(CLIContext cli, String[] args) throws Exception {
    if (args.length != 2) {
      cli.println("Usage: rmrole <role>");
      return;
    }
    try (DB db = new DB()) {
      db.open();
      db.beginTransaction();
      RoleManager rm = new RoleManager(db);
      Role r = rm.getRoleByName(args[1]);
      if (r != null)
        db.session().delete(r);
      db.commit();
      cli.println (r != null ? "Role " + r + " has been deleted" : "Role not found");
    } catch (Exception e) {
      cli.println (e.getMessage());
    }
  }
}

代码示例来源:origin: jpos/jPOS-EE

@Override
  public void exec(CLIContext cli, String[] args) throws Exception {
    if (args.length != 2) {
      cli.println("Usage: rmrole <role>");
      return;
    }
    try (DB db = new DB()) {
      db.open();
      db.beginTransaction();
      RoleManager rm = new RoleManager(db);
      Role r = rm.getRoleByName(args[1]);
      if (r != null)
        db.session().delete(r);
      db.commit();
      cli.println (r != null ? "Role " + r + " has been deleted" : "Role not found");
    } catch (Exception e) {
      cli.println (e.getMessage());
    }
  }
}

代码示例来源:origin: jpos/jPOS-EE

public int prepare (long id, Serializable o) {
  int rc = ABORTED;
  Context ctx = (Context) o;
  try {
    DB db = getDB (ctx);
    db.open ();
    ctx.put (TX, db.beginTransaction(timeout));
    checkPoint (ctx);
    rc = PREPARED;
  } catch (Throwable t) {
    error (t);
    ctx.remove (DB); // "Close" participant checks 
             // for DB in Context
  }
  return rc | NO_JOIN | READONLY;
}
public void commit (long id, Serializable o) { }

代码示例来源:origin: jpos/jPOS-EE

@Override
  public void exec(CLIContext cli, String[] args) throws Exception {
    if (args.length != 2) {
      cli.println("Usage: rmuser <user>");
      return;
    }
    try (DB db = new DB()) {
      db.open();
      db.beginTransaction();
      UserManager mgr = new UserManager(db);
      User u = mgr.getUserByNick(args[1]);
      if (u != null) {
        u.setDeleted(true);
      }
      db.commit();
      cli.println(u != null ? "User " + u.getNickAndId() + " has been deleted" : "User does not exist");
    } catch (Exception e) {
      cli.println(e.getMessage());
    }
  }
}

代码示例来源:origin: jpos/jPOS-EE

@Override
  public void exec(CLIContext cli, String[] args) throws Exception {
    if (args.length != 2) {
      cli.println("Usage: rmconsumer <id>");
      return;
    }
    try (DB db = new DB()) {
      db.open();
      db.beginTransaction();
      ConsumerManager mgr = new ConsumerManager(db);
      Consumer c = mgr.getById(args[1]);
      if (c != null) {
        c.setDeleted(true);
      }
      db.commit();
      cli.println(c != null ? "Consumer " + c.getId() + " has been deleted" : "Consumer does not exist");
    } catch (Exception e) {
      cli.println(e.getMessage());
    }
  }
}

代码示例来源:origin: jpos/jPOS-EE

private void createRealms() throws Exception {
  db.beginTransaction();
  db.save(new Realm("TEST"));
  db.save(new Realm("PROD"));
  db.commit();
}

代码示例来源:origin: jpos/jPOS-EE

private void initStatus() 
    throws HibernateException, SQLException
  {
    try {
      db.open ();
      statusId = cfg.get ("status-id", getName());
      Status s = mgr.getStatus (statusId, false);
      if (s == null) {
        Transaction tx = db.beginTransaction();
        s = mgr.getStatus (statusId, true);
        s.setName (cfg.get ("status-name", statusId));
        s.setGroupName (cfg.get ("status-group", ""));
        s.setTimeoutState (cfg.get ("on-timeout", Status.OFF));
        s.setTimeout (cfg.getLong ("status-timeout", 360000L));
        s.setLastTick (new Date());
        tx.commit();
      }
    } finally {
      close();
    }
  }
}

代码示例来源:origin: jpos/jPOS-EE

private void reset() {
    try (DB db = new DB()) {
      SeqNoManager mgr = new SeqNoManager(db);
      db.open();
      db.beginTransaction();
      mgr.reset("sync", 0L);
      db.commit();
    }
  }
}

代码示例来源:origin: jpos/jPOS-EE

private long next(long delay) {
  try (DB db = new DB()) {
    SeqNoManager mgr = new SeqNoManager(db);
    db.open();
    db.beginTransaction();
    long l = mgr.next("sync", 999999L);
    ISOUtil.sleep(delay);
    db.commit();
    return l;
  }
}

代码示例来源:origin: jpos/jPOS-EE

private void createUser() throws Exception {
  db.beginTransaction();
  User user = new User();
  user.setNick("admin");
  user.setName("User Administrator");
  user.setActive(true);
  db.session().save(user);
  UserManager mgr = new UserManager(db, HashVersion.ZERO);
  mgr.setPassword(user, "test", null);
  RealmManager rmgr = new RealmManager(db);
  Realm testRealm = rmgr.getRealmByName("TEST");
  Realm prodRealm = rmgr.getRealmByName("PROD");
  Role r = createRole(db, null, "admin", "login", "admin");
  user.getRoles().add(r);
  // user permissions: `login`, `admin`, `role.admin`
  Role r1 = createRole (db, testRealm, "tester", "testread", "testwrite");
  r1.setParent(r);
  user.getRoles().add(r1);
  // adds permissions: `TEST.testread`, `TEST.testwrite`
  db.commit();
}
public void checkUser() throws Exception {

相关文章