Package org.jtester.module.database.environment

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


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

    String sqls = ResourceHelper.readFromFile(fileName);
    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


   *
   * @param is
   * @throws Exception
   */
  public static void executeFromStream(InputStream is) throws Exception {
    DBEnvironment environment = DBEnvironmentFactory.getCurrentDBEnvironment();
    environment.connectIfNeeded();

    String sqls = ResourceHelper.readFromStream(is);
    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.", e);
      } finally {
        DBHelper.closeStatement(st);
View Full Code Here

   * @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

   * @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

   * @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

  }

  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

  }

  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

      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

      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

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

TOP

Related Classes of org.jtester.module.database.environment.DBEnvironment

Copyright © 2018 www.massapicom. 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.