Package org.fto.jthink.jdbc

Examples of org.fto.jthink.jdbc.SQL


          }
      }
      System.out.println("constructSQLForCount 测试 次数:"+count+", 总用时:"+NumberHelper.formatNumber(totalUseTime, NumberHelper.NUMBER_I_6_0)+", 平均用时(毫秒):"+NumberHelper.formatNumber((totalUseTime/count), NumberHelper.NUMBER_I_6_0));
   

    SQL sqlStatement = sqlBuilder.
            constructSQLForCount("departments","*", "DeptCount", condn);
    System.out.println("sqlStatement.getSQLStatement().size():"+sqlStatement.getSQLStatement().size());
    System.out.println(sqlStatement.getSQLString());
    if(!"SELECT COUNT(*) AS DeptCount FROM departments WHERE NOT DeptName like ? AND ( DeptId != ? OR ( DeptId != ? OR DeptId Between ? AND ? ) ) ".equals(sqlStatement.getSQLString())){
      super.fail();
    }
   
    printObjects(sqlStatement.getValues());  
   
   
    sqlStatement = sqlBuilder.
      constructSQLForCount("departments","DeptId", "DeptCount", null);
    System.out.println(sqlStatement.getSQLString());
    if(!"SELECT COUNT(DeptId) AS DeptCount FROM departments".equals(sqlStatement.getSQLString())){
      super.fail();
    }
    printObjects(sqlStatement.getValues());  
  }
View Full Code Here


  public void testHsqlSQLBuilder(){
    System.out.println("\n[正在测试方法: HsqlSQLBuilder.constructSQLForSelect()...]");
   
   
    Condition condn = new Condition();
    condn.add(new ConditionItem("DEPT_NAME", "IN", new SQL(SQL.SELECT, "SELECT DEPT_NAME FROM ALL_DEPTS WHERE D.DEPT_ID=C.DEPT_ID", null)));
    condn.add(new ConditionItem("DEPT_NO", "IS", "NOT NULL"));
    condn.add(new ConditionItem("F1", "=", "1"));
    condn.add(new ConditionItem("F2", "=", "2"));
    condn.add(new ConditionItem("F3", "=", "3"));
    condn.add(new ConditionItem("F4", "=", "4"));
    condn.add(new ConditionItem("F5", "=", "5"));
    condn.add(new ConditionItem("F6", "in", new Object[]{"1", "2", "3", "4"}));
   
   
    Column[] columns = new Column[]{
        new Column("DEPT_ID"),
        new Column("DEPT_NAME", new SQL(SQL.SELECT, "SELECT DEPT_NAME FROM ALL_DEPTS WHERE D.DEPT_ID=C.DEPT_ID", null)),
        new Column("F1"),
        new Column("F2"),
        new Column("F3"),
        new Column("F4"),
        new Column("F5"),
        new Column("F6"),
    };
   
    /* constructSQLForSelect测试开始 */
    {
      double totalUseTime = 0;
      int count = 0;
      for(int i=0;i<2000;i++){//在此设置测试次数
          long stime = System.nanoTime();       
         
          condn = new Condition();
          condn.add(new ConditionItem("DEPT_NAME", "IN", new SQL(SQL.SELECT, "SELECT DEPT_NAME FROM ALL_DEPTS WHERE D.DEPT_ID=C.DEPT_ID", null)));
          condn.add(new ConditionItem("DEPT_NO", "IS", "NOT NULL"));
          condn.add(new ConditionItem("F1", "=", "1"));
          condn.add(new ConditionItem("F2", "=", "2"));
          condn.add(new ConditionItem("F3", "=", "3"));
          condn.add(new ConditionItem("F4", "=", "4"));
          condn.add(new ConditionItem("F5", "=", "5"));
          condn.add(new ConditionItem("F6", "in", new Object[]{"1", "2", "3", "4"}));
         
         
          columns = new Column[]{
              new Column("DEPT_ID"),
              new Column("DEPT_NAME", new SQL(SQL.SELECT, "SELECT DEPT_NAME FROM ALL_DEPTS WHERE D.DEPT_ID=C.DEPT_ID", null)),
              new Column("F1"),
              new Column("F2"),
              new Column("F3"),
              new Column("F4"),
              new Column("F5"),
              new Column("F6"),
          };         
         
          /* 测试代码 开始 */
          hsqlBuilder.constructSQLForSelect("departments",false, columns, condn, "DeptId", "DeptName", 5, 20).getSQLString();
          /* 测试代码 结束 */
         
          double usetime = (System.nanoTime()-stime)/1000000f;
          if(usetime<0.09 && usetime>0){//大于50可认为是随机峰值,不参加统计,可根据情况调整
              totalUseTime += usetime;
              count++;
          }
      }
      System.out.println("constructSQLForSelect 测试 次数:"+count+", 总用时:"+NumberHelper.formatNumber(totalUseTime, NumberHelper.NUMBER_I_6_0)+", 平均用时(毫秒):"+NumberHelper.formatNumber((totalUseTime/count), NumberHelper.NUMBER_I_6_0));
   
   
    SQL sqlStatement = hsqlBuilder.constructSQLForSelect("departments",false, columns, condn, "DeptId", "DeptName", 5, 20);
    System.out.println(sqlStatement.getSQLString());
    if(!"SELECT  LIMIT 5 20 DEPT_ID,(SELECT DEPT_NAME FROM ALL_DEPTS WHERE D.DEPT_ID=C.DEPT_ID) AS DEPT_NAME,F1,F2,F3,F4,F5,F6 FROM departments WHERE  DEPT_NAME IN (SELECT DEPT_NAME FROM ALL_DEPTS WHERE D.DEPT_ID=C.DEPT_ID) AND DEPT_NO IS NOT NULL AND F1 = ? AND F2 = ? AND F3 = ? AND F4 = ? AND F5 = ? AND F6 in (? ,? ,? ,? )  GROUP BY DeptId ORDER BY DeptName".equals(sqlStatement.getSQLString())){
      super.fail();
    }
    printObjects(sqlStatement.getValues());  
   
    sqlStatement = hsqlBuilder.constructSQLForSelect("departments",false, null, null, "DeptId", "DeptName", 5, 20);
    System.out.println(sqlStatement.getSQLString());
    if(!"SELECT  LIMIT 5 20 * FROM departments GROUP BY DeptId ORDER BY DeptName".equals(sqlStatement.getSQLString())){
      super.fail();
    }
  }
View Full Code Here

  public void testMssqlSQLBuilder(){
    System.out.println("\n[正在测试方法: MssqlSQLBuilder.constructSQLForSelect()...]");
   
   
    Condition condn = new Condition();
    condn.add(new ConditionItem("DEPT_NAME", "IN", new SQL(SQL.SELECT, "SELECT DEPT_NAME FROM ALL_DEPTS WHERE D.DEPT_ID=C.DEPT_ID", null)));
    condn.add(new ConditionItem("DEPT_NO", "IS", "NOT NULL"));
    condn.add(new ConditionItem("F1", "=", "1"));
    condn.add(new ConditionItem("F2", "=", "2"));
    condn.add(new ConditionItem("F3", "=", "3"));
    condn.add(new ConditionItem("F4", "=", "4"));
    condn.add(new ConditionItem("F5", "=", "5"));
    condn.add(new ConditionItem("F6", "in", new Object[]{"1", "2", "3", "4"}));
   
   
    Column[] columns = new Column[]{
        new Column("DEPT_ID"),
        new Column("DEPT_NAME", new SQL(SQL.SELECT, "SELECT DEPT_NAME FROM ALL_DEPTS WHERE D.DEPT_ID=C.DEPT_ID", null)),
        new Column("F1"),
        new Column("F2"),
        new Column("F3"),
        new Column("F4"),
        new Column("F5"),
        new Column("F6"),
    };
   
    /* constructSQLForSelect测试开始 */
    {
      double totalUseTime = 0;
      int count = 0;
      for(int i=0;i<2000;i++){//在此设置测试次数
          long stime = System.nanoTime();       
         
          Condition condnA = new Condition();
          condnA.add(new ConditionItem("DEPT_NAME", "IN", new SQL(SQL.SELECT, "SELECT DEPT_NAME FROM ALL_DEPTS WHERE D.DEPT_ID=?", new Object[]{1})));
          condnA.add(new ConditionItem("DEPT_NAME", "IN", new SQL(SQL.SELECT, "SELECT DEPT_NAME FROM ALL_DEPTS WHERE D.DEPT_ID in (?)", new Object[]{1, 2, 3, 4})));
          condnA.add(new ConditionItem("DEPT_NO", "IS", "NOT NULL"));
          condnA.add(new ConditionItem("F1", "=", "1"));
          condnA.add(new ConditionItem("F2", "=", "2"));
          condnA.add(new ConditionItem("F3", "=", "3"));
          condnA.add(new ConditionItem("F4", "=", "4"));
          condnA.add(new ConditionItem("F5", "=", "5"));
          condnA.add(new ConditionItem("F6", "in", new Object[]{"1", "2", "3", "4"}));
         
         
          columns = new Column[]{
              new Column("DEPT_ID"),
              new Column("DEPT_NAME", new SQL(SQL.SELECT, "SELECT DEPT_NAME FROM ALL_DEPTS WHERE D.DEPT_ID=C.DEPT_ID", null)),
              new Column("F1"),
              new Column("F2"),
              new Column("F3"),
              new Column("F4"),
              new Column("F5"),
              new Column("F6"),
          };
         
          /* 测试代码 开始 */
          mssqlSQLBuilder.constructSQLForSelect("departments",false, columns, condnA, "DeptId", "DeptName", 5, 20).getSQLString();
          /* 测试代码 结束 */
         
          double usetime = (System.nanoTime()-stime)/1000000f;
          if(usetime<0.09 && usetime>0){//大于50可认为是随机峰值,不参加统计,可根据情况调整
              totalUseTime += usetime;
              count++;
          }
      }
      System.out.println("constructSQLForSelect 测试 次数:"+count+", 总用时:"+NumberHelper.formatNumber(totalUseTime, NumberHelper.NUMBER_I_6_0)+", 平均用时(毫秒):"+NumberHelper.formatNumber((totalUseTime/count), NumberHelper.NUMBER_I_6_0));
   
   
    SQL sqlStatement = mssqlSQLBuilder.constructSQLForSelect("departments",false, columns, condn, "DeptId", "DeptName", 5, 20);
    System.out.println(sqlStatement.getSQLString());
    if(!"SELECT  TOP 25 DEPT_ID,(SELECT DEPT_NAME FROM ALL_DEPTS WHERE D.DEPT_ID=C.DEPT_ID) AS DEPT_NAME,F1,F2,F3,F4,F5,F6 FROM departments WHERE  DEPT_NAME IN (SELECT DEPT_NAME FROM ALL_DEPTS WHERE D.DEPT_ID=C.DEPT_ID) AND DEPT_NO IS NOT NULL AND F1 = ? AND F2 = ? AND F3 = ? AND F4 = ? AND F5 = ? AND F6 in (? ,? ,? ,? )  GROUP BY DeptId ORDER BY DeptName".equals(sqlStatement.getSQLString())){
      super.fail();
    }
    printObjects(sqlStatement.getValues());  
    if(!getObjects(sqlStatement.getValues()).equals("1,2,3,4,5,1,2,3,4,")){
      super.fail();
    }
   
    sqlStatement = mssqlSQLBuilder.constructSQLForSelect("departments",false, null, null, "DeptId", "DeptName", 5, 20);
    System.out.println(sqlStatement.getSQLString());
    //if(!"SELECT  TOP 25 DEPT_ID,(SELECT DEPT_NAME FROM ALL_DEPTS WHERE D.DEPT_ID=C.DEPT_ID) AS DEPT_NAME,F1,F2,F3,F4,F5,F6 FROM departments WHERE  DEPT_NAME IN (SELECT DEPT_NAME FROM ALL_DEPTS WHERE D.DEPT_ID=C.DEPT_ID) AND DEPT_NO IS NOT NULL AND F1 = ? AND F2 = ? AND F3 = ? AND F4 = ? AND F5 = ? AND F6 in (? ,? ,? ,? )  GROUP BY DeptId ORDER BY DeptName".equals(sqlStatement.getSQLString())){
    //  super.fail();
    //}
   
   
View Full Code Here

  public void testMysqlSQLBuilder(){
    System.out.println("\n[正在测试方法: MysqlSQLBuilder.constructSQLForSelect()...]");
   
   
    Condition condn = new Condition();
    condn.add(new ConditionItem("DEPT_NAME", "IN", new SQL(SQL.SELECT, "SELECT DEPT_NAME FROM ALL_DEPTS WHERE D.DEPT_ID=C.DEPT_ID", null)));
    condn.add(new ConditionItem("DEPT_NO", "IS", "NOT NULL"));
    condn.add(new ConditionItem("F1", "=", "1"));
    condn.add(new ConditionItem("F2", "=", "2"));
    condn.add(new ConditionItem("F3", "=", "3"));
    condn.add(new ConditionItem("F4", "=", "4"));
    condn.add(new ConditionItem("F5", "=", "5"));
    condn.add(new ConditionItem("F6", "in", new Object[]{"1", "2", "3", "4"}));
   
   
    Column[] columns = new Column[]{
        new Column("DEPT_ID"),
        new Column("DEPT_NAME", new SQL(SQL.SELECT, "SELECT DEPT_NAME FROM ALL_DEPTS WHERE D.DEPT_ID=C.DEPT_ID", null)),
        new Column("F1"),
        new Column("F2"),
        new Column("F3"),
        new Column("F4"),
        new Column("F5"),
        new Column("F6"),
    };
   
    /* constructSQLForSelect测试开始 */
    {
      double totalUseTime = 0;
      int count = 0;
      for(int i=0;i<2000;i++){//在此设置测试次数
          long stime = System.nanoTime();       
         
         
          condn = new Condition();
          condn.add(new ConditionItem("DEPT_NAME", "IN", new SQL(SQL.SELECT, "SELECT DEPT_NAME FROM ALL_DEPTS WHERE D.DEPT_ID=C.DEPT_ID", null)));
          condn.add(new ConditionItem("DEPT_NO", "IS", "NOT NULL"));
          condn.add(new ConditionItem("F1", "=", "1"));
          condn.add(new ConditionItem("F2", "=", "2"));
          condn.add(new ConditionItem("F3", "=", "3"));
          condn.add(new ConditionItem("F4", "=", "4"));
          condn.add(new ConditionItem("F5", "=", "5"));
          condn.add(new ConditionItem("F6", "in", new Object[]{"1", "2", "3", "4"}));
         
         
          columns = new Column[]{
              new Column("DEPT_ID"),
              new Column("DEPT_NAME", new SQL(SQL.SELECT, "SELECT DEPT_NAME FROM ALL_DEPTS WHERE D.DEPT_ID=C.DEPT_ID", null)),
              new Column("F1"),
              new Column("F2"),
              new Column("F3"),
              new Column("F4"),
              new Column("F5"),
              new Column("F6"),
          };
         
          /* 测试代码 开始 */
          mysqlSQLBuilder.constructSQLForSelect("departments",false, columns, condn, "DeptId", "DeptName", 5, 20).getSQLString();
          /* 测试代码 结束 */
         
          double usetime = (System.nanoTime()-stime)/1000000f;
          if(usetime<0.05 && usetime>0){//大于50可认为是随机峰值,不参加统计,可根据情况调整
              totalUseTime += usetime;
              count++;
          }
      }
      System.out.println("constructSQLForSelect 测试 次数:"+count+", 总用时:"+NumberHelper.formatNumber(totalUseTime, NumberHelper.NUMBER_I_6_0)+", 平均用时(毫秒):"+NumberHelper.formatNumber((totalUseTime/count), NumberHelper.NUMBER_I_6_0));
   
   
    SQL sqlStatement = mysqlSQLBuilder.constructSQLForSelect("departments",false, columns, condn, "DeptId", "DeptName", 5, 20);
    System.out.println(sqlStatement.getSQLString());
    if(!"SELECT DEPT_ID,(SELECT DEPT_NAME FROM ALL_DEPTS WHERE D.DEPT_ID=C.DEPT_ID) AS DEPT_NAME,F1,F2,F3,F4,F5,F6 FROM departments WHERE  DEPT_NAME IN (SELECT DEPT_NAME FROM ALL_DEPTS WHERE D.DEPT_ID=C.DEPT_ID) AND DEPT_NO IS NOT NULL AND F1 = ? AND F2 = ? AND F3 = ? AND F4 = ? AND F5 = ? AND F6 in (? ,? ,? ,? )  GROUP BY DeptId ORDER BY DeptName LIMIT 5,20".equals(sqlStatement.getSQLString())){
      super.fail();
    }
    printObjects(sqlStatement.getValues());  
    if(!getObjects(sqlStatement.getValues()).equals("1,2,3,4,5,1,2,3,4,")){
      super.fail();
    }
   
    sqlStatement = mysqlSQLBuilder.constructSQLForSelect("departments",false, null, null, "DeptId", "DeptName", 5, 20);
    System.out.println(sqlStatement.getSQLString());
  }
View Full Code Here

//      /* 构建查询条件 */
//      Condition condition = new Condition();
//      condition.add(new ConditionItem("Id","=",id));
     
      /* 通过SQLBuilder来构建SQL语句 */
      SQL sql = sqlBuilder.constructSQLForSelect("Messages",false,new Column[]{new Column("SUBJECT"),new Column("SENDER")},condition,null,null,3,2);
      //SQL sql = sqlBuilder.constructSQLForSelect("Messages",true,null,condition,null,null);
     
      logger.debug("通过SQLBuilder构建的SQL: " + sql.getSQLString());
     
      return (List)sqlExecutor.execute(sql);
     
    }finally{
      /* 关闭事务 */
 
View Full Code Here

      sqlStr.append(" DISTINCT ");
    }
   
    /* 生成返回列的串 */
    if (columns != null && columns.length != 0) {
      SQL columnSQL = constructSelectedColumn(columns);
      sqlStr.append(columnSQL.getSQLStatement());
      values = columnSQL.getValueBuffered();
    }else{
      sqlStr.append("*");
    }

    /* 生成FROM子串, 如果tableName为空,将不构建FROM子句 */
    if (tableName != null && tableName.length() != 0) {
      sqlStr.append(" FROM ").append(tableName);
    }
   
    /* 生成查询条件串 */
    if (condition != null && condition.size() != 0) {
      sqlStr.append(" WHERE ").append(condition.getConditionStatement());
      if(values==null){
        values = condition.getValueBuffered();
      }else{
        values.append(condition.getValueBuffered());
      }
    }
   
    /* 生成GROUP BY串 */
    if (groupby != null && groupby.length() != 0) {
      sqlStr.append(" GROUP BY ").append(groupby);
    }
   
    /* 生成ORDER BY串 */
    if (orderby != null && orderby.length() != 0) {
      sqlStr.append(" ORDER BY ").append(orderby);
    }
   
    /* 生成limit串 */
    if (rowLen != -1) {
      sqlStr.append(" LIMIT ").append(startIndex).append(",").append(rowLen);
    }
   
    return new SQL(SQL.SELECT, sqlStr, values, startIndex, rowLen);
   
  }
View Full Code Here

      /* 条件 */
      Condition condition = new Condition();
      condition.add(new ConditionItem("ID","=", request.getParameter("ID")));
     
      /* 构建SQL语句 */
      SQL sql = sqlBuilder.constructSQLForSelect("Messages", column, condition);
      /* 执行SQL语句,并返回结果 */
      Iterator it = ((List)sqlExecutor.execute(sql)).iterator();
     
      if(it.hasNext()){
        return (Element)it.next();
View Full Code Here

      Condition condition = new Condition();
      condition.add(new ConditionItem("ID","=", request.getParameter("ID")));


      SQL sql = sqlBuilder.constructSQLForUpdate("Messages", msgsHM, condition);
     
      /* 执行SQL语句 */
      sqlExecutor.execute(sql);
     
      /* 提交事务 */
 
View Full Code Here

      transactionManager.begin();
     
      Condition condition = new Condition();
      condition.add(new ConditionItem("ID","=", request.getParameter("ID")));
     
      SQL sql = sqlBuilder.constructSQLForDelete("Messages", condition);
     
      /* 执行SQL语句 */
      sqlExecutor.execute(sql);
     
      /* 提交事务 */
 
View Full Code Here

  public List searchMessages() throws Exception{
    try{
      transaction.begin();
     
      /* 构建SQL语句 */
      SQL sql = sqlBuilder.constructSQLForSelect("Messages", false, null, null, "", "SendTime desc", (getPageOffset()-1)*getPageRows(), getPageRows());
      /* 执行SQL语句,并返回结果 */
      List messages = (List)sqlExecutor.execute(sql, Message.class);
      Iterator messagesIT = messages.iterator();
      while(messagesIT.hasNext()){
        Message message = (Message)messagesIT.next();
View Full Code Here

TOP

Related Classes of org.fto.jthink.jdbc.SQL

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.