Package org.fto.jthink.lang

Examples of org.fto.jthink.lang.StringBuffered


      throw new JThinkRuntimeException("rowLen不能小于0!");
    }

    ObjectBuffered values = null;   

    StringBuffered sqlStr = new StringBuffered(16)
      .append("SELECT ");

    /* 生成DISTINCT串 */
    if (distinct) {
      sqlStr.append(" DISTINCT ");
    }
   
    /* 生成TOP串 */
    if (rowLen != -1) {
      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


   *
   * @return 描述此列的SQL语句
   *
   */
  public SQL getColumn(){
    StringBuffered column=null;
    ObjectBuffered values=null;
    if(columnValue instanceof java.lang.String){
      if(columnName==columnValue){
        return new SQL(SQL.UNDEFINED, columnName, null);
      }else{
        column = new StringBuffered(4).append("(").append(columnValue).append(") AS ").append(columnName);
      }
    }else{
      SQL sql = (SQL)columnValue;
      StringBuffered sqlStatement = sql.getSQLStatement();
      column = new StringBuffered(3+sqlStatement.size()).append("(").append(sqlStatement).append(") AS ").append(columnName);
      values = sql.getValueBuffered();
    }
    return new SQL(SQL.UNDEFINED, column, values);
  }
View Full Code Here

   *
   * @deprecated
   */
  public String getConditionItemString(){
    if(sql!=null){
      return new StringBuffered(name).append(" ").append(operator).append(" (").append(sql.getSQLString()).append(") ").toString();
    }
    if(isValidOperator(OPERATOR_SIGNS_SINGLE, operator)){
      if(isQuote){
        return new StringBuffered(name).append(" ").append(operator).append(" ").append(values[0]).append(" ").toString();
      }else{
        return new StringBuffered(name).append(" ").append(operator).append(" ? ").toString();
      }
    }else{
      if(isValidOperator(OPERATOR_SIGNS_BETWEEN, operator)){
          return new StringBuffered(name).append(" ").append(operator).append(" ? AND ? ").toString();
      }else{
        StringBuffered valuesStr = new StringBuffered(name).append(" ").append(operator).append(" (");
        int valuesCount = values.length;
        for(int i=0; i<valuesCount; i++){
          valuesStr.append(i==0?"? ":",? ");
        }
        return valuesStr.append(") ").toString();
      }
    }
  }
View Full Code Here

  /**
   * 返回SQL串形式的条件单项
   */
  public StringBuffered getConditionItemStatement(){
    if(sql!=null){
      return new StringBuffered(name).append(" ").append(operator).append(" (").append(sql.getSQLString()).append(") ");
    }
    if(isValidOperator(OPERATOR_SIGNS_SINGLE, operator)){
      if(isQuote){
        return new StringBuffered(name).append(" ").append(operator).append(" ").append(values[0]).append(" ");
      }else{
        return new StringBuffered(name).append(" ").append(operator).append(" ? ");
      }
    }else{
      if(isValidOperator(OPERATOR_SIGNS_BETWEEN, operator)){
          return new StringBuffered(name).append(" ").append(operator).append(" ? AND ? ");
      }else{
        StringBuffered valuesStr = new StringBuffered(name).append(" ").append(operator).append(" (");
        int valuesCount = values.length;
        for(int i=0; i<valuesCount; i++){
          valuesStr.append(i==0?"? ":",? ");
        }
        return valuesStr.append(") ");
      }
    }
  }
View Full Code Here

//    if (condition != null && condition.size() != 0) {
//      conditionStatement = condition.getConditionStatement();
//      conditionStatementSize = conditionStatement.size();
//    }
   
    StringBuffered sqlStr = new StringBuffered(17)
      .append("SELECT ");
    ObjectBuffered values = null;//new ObjectBuffered();
   
    /* 生成DISTINCT串 */
    if (distinct) {
      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

    if(columns.size()==0){
      throw new IllegalArgumentException(
          "The value of an columns cannot be empty.");
    }
    int size = columns.size();
    StringBuffered names = new StringBuffered(size*2);
    StringBuffered valueStatement = new StringBuffered(size);
    ObjectBuffered values  = new ObjectBuffered(size);
    Iterator columnsIT = columns.entrySet().iterator();
   
    for(int i=0;i<size;i++){
    //while(columnsIT.hasNext()){
      Map.Entry column = (Map.Entry)columnsIT.next();
      Object value = column.getValue();
      if(value!=null){
        if(values.size()==0){
          names.append(column.getKey());
          valueStatement.append("?");
        }else{
          names.append(",").append(column.getKey());
          valueStatement.append(",?");
        }
        values.append(value);
      };     
    }
    StringBuffered sql = new StringBuffered(5+names.size()+valueStatement.size())
      .append("INSERT INTO ")
      .append(tableName)
      .append(" (").append(names)
      .append(") VALUES (").append(valueStatement)
      .append(") ");
View Full Code Here

          "The value of an columns cannot be empty.");
    }
    int columnsCapacity = columns.size();

    ObjectBuffered values  = new ObjectBuffered(columnsCapacity+1);
    StringBuffered sql = new StringBuffered(columnsCapacity+columnsCapacity+columnsCapacity+4)
    .append("UPDATE ")
    .append(tableName)
    .append(" SET ");

    /* 处理被更新的字段 */
    Iterator columnsIT = columns.entrySet().iterator();
    //while(columnsIT.hasNext()){
    for(int i=0;i<columnsCapacity;i++){
      Map.Entry column = (Map.Entry)columnsIT.next();
      Object value = column.getValue();
      int valuesSize = values.size();
      if(value==null){
        sql.append(valuesSize>0?",":"").append(column.getKey()).append("=NULL");
      }else{
        sql.append(valuesSize>0?",":"").append(column.getKey()).append("=?");
        values.append(value);
      }
    }
    /* 处理条件 */
    if(condition!=null && condition.size()!=0){
      sql.append(" WHERE ").append(condition.getConditionStatement());
      values.append(condition.getValueBuffered());
    }
    return new SQL(SQL.UPDATE, sql, values);
 
View Full Code Here

  public SQL constructSQLForDelete(String tableName, Condition condition){
    if(tableName==null){
      throw new IllegalArgumentException(
          "The name of an table cannot be null.");
    }
    StringBuffered sqlstr = new StringBuffered(4)
      .append("DELETE FROM ")
      .append(tableName);
    ObjectBuffered values = null;
    if (condition != null && condition.size()>0) {
      sqlstr.append(" WHERE ").append(condition.getConditionStatement());
      values = condition.getValueBuffered();
    }
    return new SQL(SQL.UPDATE, sqlstr, values);
  }
View Full Code Here

    if(tableName==null){
      throw new IllegalArgumentException(
          "The name of an table cannot be null.");
    }
   
    StringBuffered sqlStr = new StringBuffered(11)
    .append("SELECT ");
    ObjectBuffered values = null;

    /* 生成DISTINCT串 */
    if (distinct) {
      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);
    }
    return new SQL(SQL.SELECT, sqlStr, values);
  }
View Full Code Here

   */
  public SQL constructSQLForCount(
      String tableName, String fieldName, String attrName,Condition condition) {
    fieldName = fieldName==null?"*":fieldName;

    StringBuffered sqlstr = new StringBuffered(8)
      .append("SELECT COUNT(").append(fieldName).append(") AS ").append(attrName).append(" FROM ").append(tableName);
    ObjectBuffered values = null;
    if (condition != null && condition.size() != 0) {
      sqlstr.append(" WHERE ").append(condition.getConditionStatement());
      values = condition.getValueBuffered();
    }
    return new SQL(SQL.SELECT, sqlstr, values);
  }
View Full Code Here

TOP

Related Classes of org.fto.jthink.lang.StringBuffered

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.