Package org.fto.jthink.jdbc

Examples of org.fto.jthink.jdbc.SQL


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

    SQL sqlStatement = sqlBuilder.constructSQLForInsert("departments", columns);
    System.out.println(sqlStatement.getSQLString());
    if(!"INSERT INTO departments (F1,DeptName,DeptId,F3,F2) VALUES (?,?,?,?,?) ".equals(sqlStatement.getSQLString())){
      super.fail();
    }
    printObjects(sqlStatement.getValues());
   
    DataObject data = new DefaultDataObject();
    data.setTableName("departments");
    data.set("DeptId", "1");
    sqlStatement = sqlBuilder.constructSQLForInsert(data);
    System.out.println(sqlStatement.getSQLString());
    printObjects(sqlStatement.getValues());
   
    //List a;
    //a.addAll(c)
  }
View Full Code Here


          }
      }
      System.out.println("constructSQLForUpdate测试 次数:"+count+", 总用时:"+NumberHelper.formatNumber(totalUseTime, NumberHelper.NUMBER_I_6_0)+", 平均用时(毫秒):"+NumberHelper.formatNumber((totalUseTime/count), NumberHelper.NUMBER_I_6_0));
    }  
   
    SQL sqlStatement = sqlBuilder.constructSQLForUpdate("departments", columns, condn);
    System.out.println("columns.size()+condn.size():"+(columns.size()*3+4));
    System.out.println("sqlStatement.getSQLStatement().size():"+sqlStatement.getSQLStatement().size());
    System.out.println(sqlStatement.getSQLString());
    if(!"UPDATE departments SET F1=?,DeptName=?,F5=?,F4=?,F3=?,F2=?,DeptDesc=NULL WHERE NOT DeptName like ? AND ( DeptId != ? OR ( DeptId Between ? AND ? ) ) AND NOT DeptDesc like ? ".equals(sqlStatement.getSQLString())){
      super.fail();
    }
    printObjects(sqlStatement.getValues());
   
   
    sqlStatement = sqlBuilder.constructSQLForUpdate("departments", columns, null);
    System.out.println(sqlStatement.getSQLString());
    //UPDATE departments SET DeptName=?,DeptDesc=NULL
    if(!"UPDATE departments SET F1=?,DeptName=?,F5=?,F4=?,F3=?,F2=?,DeptDesc=NULL".equals(sqlStatement.getSQLString())){
      super.fail();
    }
   
    DefaultDataObject ddo = new DefaultDataObject();
    ddo.setTableName("table1");
    ddo.addPrimaryKey("PK1");
    ddo.addPrimaryKey("PK2");
    ddo.set("PK1", "v1");
    ddo.set("PK2", "v2");
    ddo.set("F3", "v3");
    ddo.set("F4", "v4");
    sqlStatement = sqlBuilder.constructSQLForUpdate(ddo);
    System.out.println(sqlStatement.getSQLString());
    if(!"UPDATE table1 SET F4=?,F3=?,PK1=?,PK2=? WHERE  PK1 = ? AND PK2 = ? ".equals(sqlStatement.getSQLString())){
      super.fail();
    }
   
    printObjects(sqlStatement.getValues());
  }
View Full Code Here

      sqlStr.append(" TOP ").append((startIndex + rowLen)).append(" ");
    }
   
    /* 生成返回列的串 */
    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);
    }
   
    return new SQL(SQL.SELECT, sqlStr, values, startIndex, rowLen);

  }
View Full Code Here

          }
      }
      System.out.println("constructSQLForDelete测试 次数:"+count+", 总用时:"+NumberHelper.formatNumber(totalUseTime, NumberHelper.NUMBER_I_6_0)+", 平均用时(毫秒):"+NumberHelper.formatNumber((totalUseTime/count), NumberHelper.NUMBER_I_6_0));
    }  
   
    SQL sqlStatement = sqlBuilder.constructSQLForDelete("departments", condn);
    System.out.println(sqlStatement.getSQLString());
        //DELETE FROM departments WHERE  DeptName like ? AND ( DeptId != ? OR ( DeptId Between ? AND ? ) )
    if(!"DELETE FROM departments WHERE NOT DeptName like ? AND ( DeptId != ? OR ( DeptId Between ? AND ? ) ) ".equals(sqlStatement.getSQLString())){
      super.fail();
    }
   
    DefaultDataObject ddo = new DefaultDataObject();
    ddo.setTableName("table1");
    ddo.addPrimaryKey("PK1");
    ddo.addPrimaryKey("PK2");
    ddo.set("PK1", "v1");
    ddo.set("PK2", "v2");
    sqlStatement = sqlBuilder.constructSQLForDelete(ddo);
    System.out.println(sqlStatement.getSQLString());
    if(!"DELETE FROM table1 WHERE  PK1 = ? AND PK2 = ? ".equals(sqlStatement.getSQLString())){
      super.fail();
    }
   
    printObjects(sqlStatement.getValues());
  }
View Full Code Here

   */
  public void testconstructSQL_ForSelect$Condition() {
    System.out.println("\n[正在测试方法: SQLBuilder.testconstructSQL_ForSelect$Condition()...]");
   
    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();       
         
          /* 测试代码 开始 */
          sqlBuilder.constructSQLForSelect("departments",false, columns, condn, (String)null, (String)null).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 = sqlBuilder.constructSQLForSelect("departments", columns, condn);
    System.out.println("sqlStatement.getValues().length:"+sqlStatement.getValues().length);
    System.out.println("sqlStatement.getValueBuffered().size():"+sqlStatement.getValueBuffered().size());
    //System.out.println("sqlStatement.getValueBuffered().length():"+sqlStatement.getValueBuffered().length());
    //System.out.println("sqlStatement.getSQLStatement().size():"+sqlStatement.getSQLStatement().size());
    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 (? ,? ,? ,? ) ".equals(sqlStatement.getSQLString())){
      super.fail();
    }
    printObjects(sqlStatement.getValues());  
  }
View Full Code Here

   
    condn.add(Condition.AND_NOT, new ConditionItem("DeptName", "like", "%部%"));
    condn.add(Condition.AND, condn1);
//    condn.add(Condition.AND_NOT, "DeptDesc", "like", "%技术%");
   
    SQL sqlStatement = sqlBuilder.
          constructSQLForSelect("departments",
                true, null, condn, null, null);
   
    System.out.println(sqlStatement.getSQLString());
    if(!"SELECT  DISTINCT * FROM departments WHERE NOT DeptName like ? AND ( DeptId != ? OR ( DeptId != ? OR DeptId Between ? AND ? ) ) ".equals(sqlStatement.getSQLString())){
      super.fail();
    }
   
    printObjects(sqlStatement.getValues());
   
    Condition userNameCDN = new Condition();
    userNameCDN.add(new ConditionItem("Users.UserId", "=", "Departments.UserId", true));
    SQL userNameSQL = sqlBuilder.constructSQLForSelect("Users", new Column[]{new Column("UserName")}, userNameCDN);
   
    Column[] columns = new Column[]{
      new Column("DeptId"),
      new Column("DeptName", "DeptName"),
      new Column("DeptXXX1", "DeptName"),
      new Column("DeptXXX2", "DeptId*100/6"),
      new Column("DeptXXX3", (String)null),
      new Column("UserName", userNameSQL),
    };
//    new String[]{"DeptId, DeptName, DeptDesc"}

    //System.out.println("str comp:"+("DeptName"=="DeptName"));
   
    /* constructSQLForSelect测试开始 */
    {
      double totalUseTime = 0;
      int count = 0;
      for(int i=0;i<2000;i++){//在此设置测试次数
          long stime = System.nanoTime();       
         
          /* 测试代码 开始 */
          SQL sql = sqlBuilder.constructSQLForSelect("departments",
              false, columns, condn, "DeptName", "DeptId");
          sql.getSQLString();
          //sql.getValueList().toArray();
          /* 测试代码 结束 */
         
          double usetime = (System.nanoTime()-stime)/1000000f;
          if(usetime<0.09 && usetime>0){//大于50可认为是随机峰值,不参加统计,可根据情况调整
View Full Code Here

      //logger.debug("getTransactionLevel():"+transaction.getTransactionLevel("SampleDataSource"));
     
      messagesHM.put("ID", generateID(sqlExecutor));
      messagesHM.put("SendTime", DateTimeHelper.formatDateTimetoString(DateTimeHelper.getSystemDate()));
     
      SQL sql = sqlBuilder.constructSQLForInsert("Messages", messagesHM);
      if(logger.isDebugEnabled()){
        logger.debug("通过SQLBuilder构建的SQL: " + sql.getSQLString()+"     "+messagesHM);
      }
      /* 执行SQ语句 */
      sqlExecutor.execute(sql);
     
      /* 提交事务 */
 
View Full Code Here

      transaction.begin();

      Condition condi = new Condition();
      condi.add(new ConditionItem("ID","=",id));
     
      SQL sql = sqlBuilder.constructSQLForUpdate("Messages", messagesHM, condi);
      if(logger.isDebugEnabled()){
        logger.debug("通过SQLBuilder构建的SQL: " + sql.getSQLString()+"     "+messagesHM);
      }
      /* 执行SQ语句 */
      Object rs = sqlExecutor.execute(sql);
     
      System.out.println("update rows="+rs);
View Full Code Here

      transaction.begin();

      Condition condi = new Condition();
      condi.add(new ConditionItem("ID","=",id));
     
      SQL sql = sqlBuilder.constructSQLForDelete("Messages", condi);
      if(logger.isDebugEnabled()){
        logger.debug("通过SQLBuilder构建的SQL: " + sql.getSQLString()+"     ");
      }
      /* 执行SQ语句 */
      Object rs = sqlExecutor.execute(sql);
     
      System.out.println("delete rows="+rs);
View Full Code Here

    assertEquals(condn.getConditionString().trim(), "NOT DeptName like ? AND ( DeptId != ? OR ( DeptId = ? OR DeptId Between ? AND ? ) ) AND NOT DeptDesc like ?");
    printObjects(condn.getValues());
   
    Condition deptCondn = new Condition();
    deptCondn.add(new ConditionItem("Depts.DeptId", "=", "Users.DeptId", true));
    SQL sql = sqlBuilder.constructSQLForSelect("Depts", new Column[]{new Column("DeptName")},deptCondn);
   
    condn = new Condition();
    condn.add(new ConditionItem("DeptName", "like", "%部%", true));
    condn.add(new ConditionItem("Depts.DeptId", "=", "Users.DeptId", true));
    condn.add(new ConditionItem("DeptName", "=", sql));
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.