Example #1
0
  public String loadSchema() {
    save();

    loadSchemaResult = false;
    Connection conn = null;
    String url =
        "jdbc:mysql://"
            + dbconfig.getHost()
            + ":"
            + dbconfig.getPort()
            + "/"
            + dbconfig.getDatabase_name();
    String sql_tables =
        String.format(
            "select TABLE_SCHEMA, TABLE_NAME, TABLE_COMMENT from information_schema.tables where TABLE_SCHEMA=\"%s\";",
            dbconfig.getDatabase_name());
    String sql_columns =
        String.format(
            "select TABLE_NAME, COLUMN_NAME, DATA_TYPE, COLUMN_TYPE, COLUMN_KEY, COLUMN_COMMENT from information_schema.columns where TABLE_SCHEMA=\"%s\";",
            dbconfig.getDatabase_name());
    String sql_keys =
        String.format(
            "select CONSTRAINT_NAME, TABLE_NAME, COLUMN_NAME, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME from information_schema.KEY_COLUMN_USAGE where TABLE_SCHEMA=\"%s\";",
            dbconfig.getDatabase_name());

    try {
      DbUtils.loadDriver(driver);
      conn = DriverManager.getConnection(url, dbconfig.getUsername(), dbconfig.getPassword());
      QueryRunner qr = new QueryRunner();
      List<Map<String, Object>> tables = qr.query(conn, sql_tables, new MapListHandler());
      List<Map<String, Object>> columns = qr.query(conn, sql_columns, new MapListHandler());
      List<Map<String, Object>> keys = qr.query(conn, sql_keys, new MapListHandler());
      dbconfig.setTables_json(JSONUtil.serialize(tables, false));
      dbconfig.setColumns_json(JSONUtil.serialize(columns, false));
      dbconfig.setKeys_json(JSONUtil.serialize(keys, false));
      DbUtils.closeQuietly(conn);
    } catch (Exception ex) {
      return ERROR;
    }
    loadSchemaResult = true;
    SaveLog.saveLog(
        new Users((long) 1),
        "11",
        "数据库映射",
        new Date(),
        "数据库-企业数据库-模板映射—导入数据库配置方案",
        Constant.DATABASE_OPERATION,
        this.getClass().getName());
    return SUCCESS;
  }
Example #2
0
  public String save() {
    // update session process
    org.sega.ProcessDesigner.models.Process sp =
        (org.sega.ProcessDesigner.models.Process) getSession().get("process");

    Session hb_session = HibernateUtil.getSessionFactory().getCurrentSession();
    hb_session.beginTransaction();
    if (sp.getDbconfig() == null) {
      hb_session.save(dbconfig);
      hb_session.flush();
      sp.setDbconfig(dbconfig);
    } else {
      sp.getDbconfig().setType(dbconfig.getType());
      sp.getDbconfig().setHost(dbconfig.getHost());
      sp.getDbconfig().setPort(dbconfig.getPort());
      sp.getDbconfig().setDatabase_name(dbconfig.getDatabase_name());
      sp.getDbconfig().setUsername(dbconfig.getUsername());
      sp.getDbconfig().setPassword(dbconfig.getPassword());
    }
    hb_session.saveOrUpdate(sp);
    hb_session.getTransaction().commit();

    // save persisted process in session
    getSession().put("process", sp);

    setSaveResult(true);
    String logContent =
        "数据库-企业数据库-模板映射—数据库配置,配置信息如下:Host:"
            + dbconfig.getHost()
            + ",port:"
            + dbconfig.getPort()
            + ",Database Name:"
            + dbconfig.getDatabase_name()
            + ",User name:"
            + dbconfig.getUsername()
            + ",password:"******"11",
        "数据库配置",
        new Date(),
        logContent,
        Constant.DATABASE_OPERATION,
        this.getClass().getName());
    return SUCCESS;
  }
Example #3
0
  public String test() {
    testResult = false;

    if ("mysql".equalsIgnoreCase(dbconfig.getType())) {
      testResult = testMysql();
    }
    SaveLog.saveLog(
        new Users((long) 1),
        "11",
        "数据库连接测试",
        new Date(),
        "数据库-企业数据库-模板映射—数据库连接测试",
        Constant.DATABASE_OPERATION,
        this.getClass().getName());

    return SUCCESS;
  }