Examples of SQLRunner


Examples of com.lucidera.luciddb.test.udr.SQLRunner

            + "APPLIB.REMOTE_ROWS(cursor( "
            + "select cast(null as int) as id, cast(null as varchar(255)) as name, "
            + "cast(null as boolean) as is_married " + "from (values(0)) "
            + "),7778,FALSE) " + ")");
       
        SQLRunner runner = new SQLRunner(ps);

        runner.start();
       
        Thread.sleep(5000);
       
        Socket client = new Socket("localhost", 7778);

        ObjectOutputStream objOut = new ObjectOutputStream(
            client.getOutputStream());
        List<Object> header = new ArrayList<Object>();
      
        header.add("1"); // version
       
        List format = new ArrayList();
        // KS 10-APR-2011
        // The "Mismatch" here is on types, but the RemoteRowsUDX only checks
        // for column count. Thus the final STRING is what triggers the
        // mismatch as of this date.
        // Also, the indexOf message match below was initially wrong with what
        // the UDX produces.
        format.add("STRING"); // Mismatch
        format.add("STRING");
        format.add("BOOLEAN");
        format.add("STRING"); // mismatched columns
       
        header.add(format);
        objOut.writeObject(header);
       
        objOut.close();
        client.close();
        runner.join();
       
        ps.close();
        conn.close();
              
        String errorMsg = runner.getErrorMsg();
        if (errorMsg == null) {
          errorMsg = "";
        }
        boolean test = false;
        if(errorMsg.indexOf("Header Mismatch:")!=-1){
            test = true;
        }
           
        assertTrue("Header mismatch test is not passed: ",test);
       
        //Case2: Bad objects sent across (wrong datatypes in actual rows)
        conn = driver.connect(driverURI, props);
        ps = conn.prepareStatement(
            "insert into s.t " +
            "select * from table( "
            + "APPLIB.REMOTE_ROWS(cursor( "
            + "select cast(null as int) as id, cast(null as varchar(255)) as name, "
            + "cast(null as boolean) as is_married " + "from (values(0)) "
            + "),7778,FALSE) " + ")");
       
        runner = new SQLRunner(ps);

        runner.start();
       
        Thread.sleep(5000);
       
        client = new Socket("localhost", 7778);

        objOut = new ObjectOutputStream(
            client.getOutputStream());
        header = new ArrayList<Object>();
      
        header.add("1"); // version
       
        format = new ArrayList();
        format.add("INTEGER");
        format.add("STRING");
        format.add("BOOLEAN");
       
        header.add(format);
        objOut.writeObject(header);
       
        objOut.reset();
        objOut.flush();

        List<Object> list = new ArrayList<Object>();
        list.add("Test1"); // wrong type.
        list.add(111); // wrong type.
        list.add(true);
       
        objOut.writeObject(list);
        objOut.close();
        client.close();
        runner.join();
       
        ps.close();
        conn.close();
              
        errorMsg = runner.getErrorMsg();
        test = false;
        if(errorMsg.indexOf("Value 'Test1' cannot be converted to parameter of type INTEGER")!=-1){
            test = true;
        }
           
        assertTrue("Bad objects sent across: ",test);
       
        //Casee3: Compress stream
        conn = driver.connect(driverURI, props);
        ps = conn.prepareStatement(
            "insert into s.t " +
            "select * from table( "
            + "APPLIB.REMOTE_ROWS(cursor( "
            + "select cast(null as int) as id, cast(null as varchar(255)) as name, "
            + "cast(null as boolean) as is_married " + "from (values(0)) "
            + "),7778,TRUE) " + ")"); // TRUE
       
        runner = new SQLRunner(ps);

        runner.start();
       
        Thread.sleep(5000);
       
        client = new Socket("localhost", 7778);

        GZIPOutputStream gzOut = new GZIPOutputStream(client.getOutputStream());
        objOut = new ObjectOutputStream(
          gzOut);
        header = new ArrayList<Object>();
      
        header.add("1"); // version
       
        format = new ArrayList();
        format.add("INTEGER");
        format.add("STRING");
        format.add("BOOLEAN");
       
        header.add(format);
        objOut.writeObject(header);
       
        objOut.reset();
        objOut.flush();

        list = new ArrayList<Object>();
        list.add(111);
        list.add("Test1");
        list.add(true);
       
        objOut.writeObject(list);
        objOut.close();
        client.close();
        runner.join();
       
        ps.close();
        conn.close();
              
        errorMsg = runner.getErrorMsg();
        test = false;
        if(errorMsg == null){
            test = true;
        }
           
View Full Code Here

Examples of com.xiaoleilu.hutool.db.SqlRunner

  private static void sqlRunnerDemo(DataSource ds) {
    Entity entity = Entity.create(TABLE_NAME).set("字段1", "值").set("字段2", 2);
    Entity where = Entity.create(TABLE_NAME).set("条件1", "条件值");

    try {
      SqlRunner runner = SqlRunner.create(ds);
      // 根据DataSource会自动识别数据库方言
      runner = SqlRunner.create(ds);

      // 增,生成SQL为 INSERT INTO `table_name` SET(`字段1`, `字段2`) VALUES(?,?)
      runner.insert(entity);

      // 删,生成SQL为 DELETE FROM `table_name` WHERE `条件1` = ?
      runner.del(where);

      // 改,生成SQL为 UPDATE `table_name` SET `字段1` = ?, `字段2` = ? WHERE `条件1` = ?
      runner.update(entity, where);

      // 查,生成SQL为 SELECT * FROM `table_name` WHERE WHERE `条件1` = ? 第一个参数为返回的字段列表,如果null则返回所有字段
      List<Entity> entityList = runner.find(null, where, new EntityHandler());
      log.info("{}", entityList);

      // 分页,注意,ANSI SQL中不支持分页!
      List<Entity> pagedEntityList = runner.page(null, where, 0, 20, new EntityHandler());
      log.info("{}", pagedEntityList);

      // 满足条件的结果数,生成SQL为 SELECT count(1) FROM `table_name` WHERE WHERE `条件1` = ?
      int count = runner.count(where);
      log.info("count: {}", count);
    } catch (SQLException e) {
      Log.error(log, e, "SQL error!");
    } finally {
    }
View Full Code Here

Examples of io.lumify.palantir.dataImport.sqlrunner.SqlRunner

        this.outputDirectory = f;

        this.systemUser = userRepository.getSystemUser();
        this.visibility = p.getVisibility();
        this.authorizations = p.getAuthorizations();
        sqlRunner = new SqlRunner(
                p.getConnectionString(),
                p.getUsername(),
                p.getPassword(),
                p.getTableNamespace());
        this.idPrefix = p.getIdPrefix();
View Full Code Here

Examples of org.apache.ibatis.jdbc.SqlRunner

      throw new MigrationException("Error undoing last migration.  Cause: " + e, e);
    }
  }

  protected void deleteChange(Change change) {
    SqlRunner runner = getSqlRunner();
    try {
      runner.delete("delete from " + changelogTable() + " where id = ?", change.getId());
    } catch (SQLException e) {
      throw new MigrationException("Error querying last applied migration.  Cause: " + e, e);
    } finally {
      runner.closeConnection();
    }
  }
View Full Code Here

Examples of org.apache.ibatis.jdbc.SqlRunner

    }
    return migrations;
  }

  protected List<Change> getChangelog() {
    SqlRunner runner = getSqlRunner();
    try {
      List<Map<String, Object>> changelog = runner.selectAll("select ID, APPLIED_AT, DESCRIPTION from " + changelogTable() + " order by id");
      List<Change> changes = new ArrayList<Change>();
      for (Map<String, Object> change : changelog) {
        String id = change.get("ID") == null ? null : change.get("ID").toString();
        String appliedAt = change.get("APPLIED_AT") == null ? null : change.get("APPLIED_AT").toString();
        String description = change.get("DESCRIPTION") == null ? null : change.get("DESCRIPTION").toString();
        changes.add(new Change(new BigDecimal(id), appliedAt, description));
      }
      return changes;
    } catch (SQLException e) {
      throw new MigrationException("Error querying last applied migration.  Cause: " + e, e);
    } finally {
      runner.closeConnection();
    }
  }
View Full Code Here

Examples of org.apache.ibatis.jdbc.SqlRunner

    List<Change> changelog = getChangelog();
    return changelog.get(changelog.size() - 1);
  }

  protected boolean changelogExists() {
    SqlRunner runner = getSqlRunner();
    try {
      runner.selectAll("select ID, APPLIED_AT, DESCRIPTION from " + changelogTable());
      return true;
    } catch (SQLException e) {
      return false;
    } finally {
      runner.closeConnection();
    }
  }
View Full Code Here

Examples of org.apache.ibatis.jdbc.SqlRunner

      String username = props.getProperty("username");
      String password = props.getProperty("password");

      UnpooledDataSource dataSource = new UnpooledDataSource(driverClassLoader, driver, url, username, password);
      dataSource.setAutoCommit(true);
      return new SqlRunner(dataSource.getConnection());
    } catch (SQLException e) {
      throw new MigrationException("Could not create SqlRunner. Cause: " + e, e);
    }
  }
View Full Code Here

Examples of org.apache.ibatis.jdbc.SqlRunner

      }
    }
  }

  protected void insertChangelog(Change change) {
    SqlRunner runner = getSqlRunner();
    change.setAppliedTimestamp(generateAppliedTimeStampAsString());
    try {
      runner.insert("insert into " + changelogTable() + " (ID, APPLIED_AT, DESCRIPTION) values (?,?,?)", change.getId(), change.getAppliedTimestamp(), change.getDescription());
    } catch (SQLException e) {
      throw new MigrationException("Error querying last applied migration.  Cause: " + e, e);
    } finally {
      runner.closeConnection();
    }
  }
View Full Code Here

Examples of org.apache.ibatis.jdbc.SqlRunner

    }
    return migrations;
  }

  protected List<Change> getChangelog() {
    SqlRunner runner = getSqlRunner();
    try {
      List<Map<String, Object>> changelog = runner.selectAll("select ID, APPLIED_AT, DESCRIPTION from " + changelogTable() + " order by id");
      List<Change> changes = new ArrayList<Change>();
      for (Map<String, Object> change : changelog) {
        String id = change.get("ID") == null ? null : change.get("ID").toString();
        String appliedAt = change.get("APPLIED_AT") == null ? null : change.get("APPLIED_AT").toString();
        String description = change.get("DESCRIPTION") == null ? null : change.get("DESCRIPTION").toString();
        changes.add(new Change(new BigDecimal(id), appliedAt, description));
      }
      return changes;
    } catch (SQLException e) {
      throw new MigrationException("Error querying last applied migration.  Cause: " + e, e);
    } finally {
      runner.closeConnection();
    }
  }
View Full Code Here

Examples of org.apache.ibatis.jdbc.SqlRunner

    List<Change> changelog = getChangelog();
    return changelog.get(changelog.size() - 1);
  }

  protected boolean changelogExists() {
    SqlRunner runner = getSqlRunner();
    try {
      runner.selectAll("select ID, APPLIED_AT, DESCRIPTION from " + changelogTable());
      return true;
    } catch (SQLException e) {
      return false;
    } finally {
      runner.closeConnection();
    }
  }
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.