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

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

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

DB.save介绍

[英]handy method used to avoid having to call db.session().save (xxx)
[中]用于避免调用数据库的简便方法。会话()。保存(xxx)

代码示例

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

/**
 * @param id status id and optional name (used when create=true)
 * @param create if true and status doesn't exist, a new status with an optional name would be created.
 */
public Status getStatus (String id, boolean create) 
  throws HibernateException, SQLException
{
  String name = "";
  int sp = id.indexOf (" ");
  if (sp > 0 && id.length() > sp) {
    name = id.substring (sp + 1);
    id = id.substring (0, sp);
  }
  Status s = (Status) db.session().get(Status.class, id);
  if (s == null && create) {
    s = new Status ();
    s.setId (id);
    s.setName (name.length() > 0 ? name : id);
    s.setTimeoutState (Status.OFF);
    s.setGroupName ("Unfiled");
    db.save (s);
  }
  return s;
}

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

/**
   * factory method used to create a Revision associated with this user.
   *
   * @param author the revision author
   * @param ref associated with this revision
   * @param info information
   * @return a revision entry
   */
  public Revision createRevision (User author, String ref, String info) {
    Revision re = new Revision();
    re.setDate (new Date());
    re.setInfo (info);
    re.setRef (ref);
    re.setAuthor (author);
    db.save (re);
    return re;
  }
}

代码示例来源: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 Role createRole (DB db, Realm realm, String name, String... permissions) {
    Role role = new Role(realm, name);
    Set<Permission> perms = role.getPermissions();
    for (String p : permissions)
      perms.add(Permission.valueOf(p));
    db.save(role);
    return role;
  }
}

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

@Override
  public void exec(CLIContext cli, String[] args) throws Exception {
    if (args.length < 2) {
      cli.println("Usage: addpermission <role> <permission 1> <permission 2> ... <permission n>");
      return;
    }
    try (DB db = new DB()) {
      db.open();
      db.beginTransaction();
      RoleManager rm = new RoleManager(db);
      Role role = null;
      if (rm.getRoleByName(args[1]) == null) {
        role = new Role(args[1]);
        Set<Permission> perms = role.getPermissions();
        for (int i = 2; i < args.length; i++)
          perms.add(Permission.valueOf(args[i]));
        db.save(role);
      }
      db.commit();
      cli.println (role != null ? "Role created " + role.getName() : " Role already exists");
    } 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: addrole <role> <permission 1> <permission 2> ... <permission n>");
      return;
    }
    try (DB db = new DB()) {
      db.open();
      db.beginTransaction();
      RoleManager rm = new RoleManager(db);
      Role role = null;
      if (rm.getRoleByName(args[1]) == null) {

        role = new Role(args[1]);
        Set<Permission> perms = role.getPermissions();
        for (int i = 2; i < args.length; i++)
          perms.add(Permission.valueOf(args[i]));
        db.save(role);
      }
      db.commit();
      cli.println (role != null ? "Role created " + role.getName() : " Role already exists");
    } catch (Exception e) {
      cli.println (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");
  }
}

相关文章