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

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

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

DB.execWithTransaction介绍

暂无

代码示例

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

private SecretKey getKey (UUID keyId, char[] passPhrase) throws Exception {
  if (passPhrase == null && unlock == null)
    throw new SecurityException("Passphrase not available");
  passPhrase = passPhrase != null ? passPhrase : unlock.get().toCharArray();
  String v = DB.execWithTransaction(db -> {
    SysConfigManager mgr = new SysConfigManager(db, "key.");
    return mgr.get(keyId.toString(), null);
  });
  if (v == null) {
    throw new SecurityException("Invalid key");
  }
  byte[] key = PGPHelper.decrypt(
   v.getBytes(),
   privKeyRing,
   passPhrase
  );
  return new SecretKeySpec(key, 0, key.length, "AES");
}

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

private void registerKey(String k, String v) throws Exception {
  DB.execWithTransaction(db -> {
    SysConfigManager mgr = new SysConfigManager(db, "key.");
    mgr.put(k, v, "security.read", "security.write");
    return true;
  });
  LogEvent evt = getLog().createLogEvent("security");
  evt.addMessage("<id>" + k + "</id>");
  evt.addMessage(System.lineSeparator() + v);
  Logger.log(evt);
}

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

@Override
public boolean updateEntity (Binder binder) throws BLException {
  try {
    return (boolean) DB.execWithTransaction( (db) -> {
      Role oldRole = (Role) ((Role) getOriginalEntity()).clone();
      binder.writeBean(getOriginalEntity());
      Role r = (Role) getOriginalEntity();
      db.session().merge(r);
      return addRevisionUpdated(db, getEntityName(),
          String.valueOf(r.getId()),
          oldRole,
          r,
          new String[]{"name", "permissions"});
    });
  } catch (Exception e) {
    throw new BLException(e.getMessage());
  }
}

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

@Override
public boolean removeEntity() {
  //Users have a deleted flag, they are not completely removed.
  User t = (User) getOriginalEntity();
  try {
    return t != null && (boolean) DB.execWithTransaction((db) -> {
      User user = db.session().get(User.class, t.getId());
      if (user == null) return false;
      t.setDeleted(true);
      db.session().merge(t);
      addRevisionRemoved(db, getEntityName(), String.valueOf(t.getId()));
      return true;
    });
  } catch (Exception e) {
    getApp().getLog().error(e);
    return false;
  }
}

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

@Override
public boolean updateEntity(Binder binder) throws BLException {
  try {
    return DB.execWithTransaction((db) -> {
      Consumer oldConsumer = (Consumer) ((Consumer) getOriginalEntity()).clone();
      binder.writeBean(getOriginalEntity());
      Consumer newConsumer = (Consumer) getOriginalEntity();
      db.session().merge(newConsumer);
      return addRevisionUpdated(db, getEntityName(),
          String.valueOf(newConsumer.getId()),
          oldConsumer,
          newConsumer,
          new String[]{"active","roles","startDate","endDate"});
    });
  } catch (Exception e) {
    getApp().getLog().error(e);
    return false;
  }
}

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

@Override
public boolean updateEntity(Binder binder) throws BLException {
  try {
    return DB.execWithTransaction((db) -> {
      Account oldAcct = (Account) ((Account) getOriginalEntity()).clone();
      binder.writeBean(getOriginalEntity());
      Account a = (Account) getOriginalEntity();
      db.session().merge(a);
      return addRevisionUpdated(db, getEntityName(),
          String.valueOf(a.getId()),
          oldAcct,
          a,
          new String[]{"code","description","created","expired"});
    });
  } catch (Exception e) {
    getApp().getLog().error(e);
    return false;
  }
}

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

protected boolean saveEntity (Binder binder, EntryGrid entryGrid) throws BLException {
  try {
    return (boolean) DB.execWithTransaction(db -> {
      if (binder.writeBeanIfValid(getOriginalEntity())) {
        GLTransaction txn = (GLTransaction) getOriginalEntity();
        List<GLEntry> entries = entryGrid.getValue().getEntries();
        //Reset ids to 0
        for (GLEntry e : entries)
          e.setId(0);
        txn.setEntries(entries);
        txn.setTimestamp(new Date());
        GLSession glSession = new GLSession(db);
        glSession.post(txn.getJournal(), txn);
        addRevisionCreated(db, getEntityName(), getItemId(getOriginalEntity()));
        return true;
      }
      return false;
    });
  } catch (Exception e) {
    throw new BLException(e.getMessage());
  }
}

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

protected boolean updateEntity (Binder binder, EntryGrid entryGrid, boolean shouldReverse) throws BLException {
  boolean wasUpdated;
  try {
    wasUpdated = (boolean) DB.execWithTransaction( (db) -> {
      GLTransaction oldTxn = ((GLTransaction) getOriginalEntity()).clone();
      binder.writeBean(getOriginalEntity());

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

@Override
public boolean updateEntity (Binder binder) throws BLException {
  try {
    return (boolean) DB.execWithTransaction((db) -> {
      SysConfig oldSysConfig = (SysConfig) ((SysConfig) getOriginalEntity()).clone();
      binder.writeBean(getOriginalEntity());
      SysConfig s = (SysConfig) getOriginalEntity();
      //need to re-set prefix to id as it gets deleted on write
      s.setId(addPrefix(s.getId()));
      db.session().merge(s);
      return addRevisionUpdated(db, getEntityName(),
          String.valueOf(s.getId()),
          oldSysConfig,
          s,
          new String[]{"value"});
    });
  } catch (Exception e) {
    QI.getQI().getLog().error(e);
    return false;
  }
}

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

public String resetUserPassword (User user) {
  String generatedPassword = PasswordGenerator.generateRandomPassword();
  try {
    DB.execWithTransaction((db) -> {
      db.session().refresh(user);
      user.getPasswordhistory(); // hack to avoid LazyInitialization
      UserManager mgr = new UserManager(db);
      try {
        mgr.setPassword(user, generatedPassword);
      } catch (BLException e) {
        getApp().displayNotification("errorMessage.resetPassword");
        return false;
      }
      user.setForcePasswordChange(true);
      user.setLoginAttempts(0); // reset login attempts
      db.session().saveOrUpdate(user);
      return true;
    });
  } catch (Exception e) {
    getApp().getLog().error(e);
    return null;
  }
  return generatedPassword;
}

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

@Override
public boolean saveEntity (Binder binder) throws BLException {
  SysConfig entity = (SysConfig) getOriginalEntity();
  if (binder.writeBeanIfValid(getOriginalEntity())) {
    String id = entity.getId();
    id = prefix != null ? prefix + id : id;
    if (getSysConfig(id) == null) {
      final String finalId = id;
      try {
        return (boolean) DB.execWithTransaction((db) -> {
          SysConfigManager mgr = new SysConfigManager(db, prefix);
          mgr.put(entity.getId(), entity.getValue());
          addRevisionCreated(db, "SYSCONFIG", finalId);
          return true;
        });
      } catch (Exception e) {
        QI.getQI().getLog().error(e);
        return false;
      }
    } else {
      throw new BLException("SysConfig " + id + " already exists.");
    }
  } else {
    throw new BLException("Invalid SysConfig");
  }
}

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

public boolean updateUser (Binder binder, String currentPass, String newClearPass) throws BLException {
  boolean userUpdated;
  try {
    userUpdated = (boolean) DB.execWithTransaction((db) -> {
      UserManager mgr = new UserManager(db);
      User oldUser = (User) ((User)getOriginalEntity()).clone();

相关文章