org.jpos.ee.DB类的使用及代码示例

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

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

DB介绍

暂无

代码示例

代码示例来源: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

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

public Thing create (String type) {
  Thing thing = new Thing (type);
  db.save (thing);
  return thing;
}
public Thing get (long id) {

代码示例来源: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

@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

/**
 * @return underlying Hibernate Session.
 */
public Session session () {
  return db.session();
}
/**

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

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

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

if (autoCommit && db.session() == null) {
    db.open ();
    autoClose = true;
    Transaction tx = db.beginTransaction ();
    db.session().save (evt);
    tx.commit ();
  } else {
    db.session().save (evt);
    db.close ();
} catch (Throwable t) {
  errorLog (evt, t);

代码示例来源: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

private int getChildrenCount(Account parent) throws Exception {
  return DB.exec(db -> {
    db.session().refresh(parent);
    return parent.getChildren().size();
  });
}

代码示例来源: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

@SuppressWarnings("unchecked")
public void exec(CLIContext cli, String[] args) {
  long start = System.currentTimeMillis();
  try (DB db = new DB()) {
    db.open();
    GLSession gls = new GLSession(db);
    List<BalanceCache> caches = db.session().createQuery("from org.jpos.gl.BalanceCache").list();
    int good=0;
    int total=0;

代码示例来源: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 {

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

@Before
public void setUp() throws Exception {
  db = new DB();
  db.createSchema("schema.sql", true);
  db.open();
}

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

this.db = db;
boolean autoClose = false;
if (db.session() == null) {
  db.open();
  autoClose = !autoClose;
session = db.session();
if (username != null) {
  user = getUser (username);

代码示例来源: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

/**
 * create a SysLog object with auto commit on.
 * (open/begin/commit/close is not required).
 */
public SysLogManager () {
  super (new DB(),SysLog.class);
  autoCommit = true;
}

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

public boolean hasProperty (String name) {
  try {
    if (prefix != null)
      name = prefix + name;
    return db.session().get(SysConfig.class, name) != null;
  } catch (HibernateException e) {
    db.getLog().warn (e);
  }
  return false;
}

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

public boolean saveUser (Binder binder, String clearPass) throws BLException {
  User u = (User) getOriginalEntity();
  if (binder.writeBeanIfValid(getOriginalEntity())) {
    try {
      return (boolean) DB.execWithTransaction((db) -> {
        db.save(u);
        if (clearPass != null && !clearPass.isEmpty()) {
          UserManager mgr = new UserManager(db);
          try {
            mgr.setPassword(u, clearPass);
          } catch (BLException e) {
            return false;
          }
          addRevisionCreated(db, getEntityName(), u.getId().toString());
          u.setForcePasswordChange(true);
          db.session().update(u);
          return true;
        }
        return false;
      });
    } catch (Exception e) {
      getApp().getLog().error(e);
      return false;
    }
  } else {
   throw new BLException("Invalid user");
  }
}

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

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

相关文章