Examples of DBEnvironment


Examples of org.jtester.module.database.environment.DBEnvironment

   * @param fileName
   * @throws SQLException
   * @throws FileNotFoundException
   */
  public static void executeFromFile(Class clazz, String fileName) {
    DBEnvironment environment = DBEnvironmentFactory.getCurrentDBEnvironment();
    environment.connectIfNeeded();

    String sqls;
    try {
      sqls = ResourceHelper.readFromFile(clazz, fileName);
    } catch (FileNotFoundException e1) {
      throw new RuntimeException(e1);
    }

    String[] statements = DBHelper.parseSQL(sqls);
    for (String statment : statements) {
      PreparedStatement st = null;
      try {
        st = environment.createStatementWithBoundFixtureSymbols(statment);
        st.execute();
      } catch (Throwable e) {
        throw new DbFitException("there are some error when execute sql file [" + fileName + "]", e);
      } finally {
        DBHelper.closeStatement(st);
View Full Code Here

Examples of org.jtester.module.database.environment.DBEnvironment

   * @param result
   * @return
   * @throws SQLException
   */
  public static <T> T query(String sql, Class<T> claz) {
    DBEnvironment environment = DBEnvironmentFactory.getCurrentDBEnvironment();
    environment.connectIfNeeded();
    PreparedStatement st = null;
    ResultSet rs = null;
    try {
      st = environment.createStatementWithBoundFixtureSymbols(sql);
      rs = st.executeQuery();
      if (rs.next() == false) {
        throw new RuntimeException("there are no result for statement:" + sql);
      }
      ResultSetMetaData rsmd = rs.getMetaData();
View Full Code Here

Examples of org.jtester.module.database.environment.DBEnvironment

   * @param result
   * @return
   * @throws SQLException
   */
  public static <T> List<T> queryList(String sql, Class<T> clazz) {
    DBEnvironment environment = DBEnvironmentFactory.getCurrentDBEnvironment();
    environment.connectIfNeeded();
    PreparedStatement st = null;
    ResultSet rs = null;
    try {
      st = environment.createStatementWithBoundFixtureSymbols(sql);
      rs = st.executeQuery();

      ResultSetMetaData rsmd = rs.getMetaData();
      if (Map.class.isAssignableFrom(clazz)) {
        List<Map> maps = DBHelper.getListMapFromResult(rs, rsmd, false);
View Full Code Here

Examples of org.jtester.module.database.environment.DBEnvironment

  }

  public IDBOperator useDB(String dataSource) {
    IN_DB_OPERATOR.set(true);
    try {
      DBEnvironment environment = DBEnvironmentFactory.getDBEnvironment(dataSource);
      DBEnvironmentFactory.changeDBEnvironment(environment);
      return this;
    } finally {
      IN_DB_OPERATOR.set(false);
    }
View Full Code Here

Examples of org.jtester.module.database.environment.DBEnvironment

  }

  public IDBOperator useDefaultDB() {
    IN_DB_OPERATOR.set(true);
    try {
      DBEnvironment environment = DBEnvironmentFactory.getDBEnvironment();
      DBEnvironmentFactory.changeDBEnvironment(environment);
      return this;
    } finally {
      IN_DB_OPERATOR.set(false);
    }
View Full Code Here

Examples of org.jtester.module.database.environment.DBEnvironment

      DBHelper.closeStatement(st);
    }
  }

  public static <T> List<T> queryMapList(String sql) {
    DBEnvironment environment = DBEnvironmentFactory.getCurrentDBEnvironment();
    environment.connectIfNeeded();
    PreparedStatement st = null;
    ResultSet rs = null;
    try {
      st = environment.createStatementWithBoundFixtureSymbols(sql);
      rs = st.executeQuery();

      ResultSetMetaData rsmd = rs.getMetaData();
      List<Map> maps = DBHelper.getListMapFromResult(rs, rsmd, false);
      return (List<T>) maps;
View Full Code Here

Examples of org.jtester.module.database.environment.DBEnvironment

      DBHelper.closeStatement(st);
    }
  }

  public static <T> List<T> queryMapList(String sql, DataMap where) {
    DBEnvironment environment = DBEnvironmentFactory.getCurrentDBEnvironment();
    environment.connectIfNeeded();
    PreparedStatement st = null;
    ResultSet rs = null;
    try {
      st = environment.createStatementWithBoundFixtureSymbols(sql);
      int index = 1;
      for (String key : where.keySet()) {
        try {
          Object value = where.get(key);
          if (value instanceof InputStream) {
View Full Code Here

Examples of org.jtester.module.database.environment.DBEnvironment

  /**
   * 使用默认的数据源执行相关sql操作
   */
  public void useDefaultDataSource() {
    DBEnvironment environment = DBEnvironmentFactory.getDBEnvironment();
    DBEnvironmentFactory.changeDBEnvironment(environment);
  }
View Full Code Here

Examples of org.jtester.module.database.environment.DBEnvironment

   * 使用指定的数据源执行相关sql操作
   *
   * @param dataSourceName
   */
  public void useSpecDataSource(String dataSourceName) {
    DBEnvironment environment = DBEnvironmentFactory.getDBEnvironment(dataSourceName);
    DBEnvironmentFactory.changeDBEnvironment(environment);
  }
View Full Code Here

Examples of org.jtester.module.database.environment.DBEnvironment

   *            数据源名称
   * @param dataSourceFrom
   *            数据源配置文件
   */
  public void useSpecDataSource(String dataSourceName, String dataSourceFrom) {
    DBEnvironment environment = DBEnvironmentFactory.getDBEnvironment(dataSourceName, dataSourceFrom);
    DBEnvironmentFactory.changeDBEnvironment(environment);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.