Package com.scooterframework.orm.sqldataexpress.object

Examples of com.scooterframework.orm.sqldataexpress.object.JdbcStatementParameter


  private JdbcStatement furtherLookupJdbcStatement(
      UserDatabaseConnection udc, JdbcStatement st) {
    Collection<Parameter> parameters = st.getParameters();
    Iterator<Parameter> it = parameters.iterator();
    while (it.hasNext()) {
      JdbcStatementParameter jdbcParam = (JdbcStatementParameter) it
          .next();
      if (jdbcParam.isUsedByCount())
        continue;
      if (jdbcParam.getSqlDataType() != Parameter.UNKNOWN_SQL_DATA_TYPE) {
        // do not furtherLookup if the sql data type is already known.
        continue;
      }

      String tableName = jdbcParam.getTableName();
      String columnName = jdbcParam.getColumnName();

      int sqlDataType = 0;
      String sqlDataTypeName = null;
      String javaClassName = null;

      if (tableName != null && columnName != null) {
        // find more properties of this column
        TableInfo ti = SqlExpressUtil.lookupTableInfo(udc, tableName);

        // add more properties for this column
        RowInfo header = ti.getHeader();
        int columnIndex = header.getColumnPositionIndex(columnName);

        sqlDataType = header.getColumnSqlDataType(columnIndex);
        sqlDataTypeName = header.getColmnDataTypeName(columnIndex);
        javaClassName = header.getColumnJavaClassName(columnIndex);

        jdbcParam.setSqlDataType(sqlDataType);
        jdbcParam.setSqlDataTypeName(sqlDataTypeName);
        jdbcParam.setJavaClassName(javaClassName);
      } else {
        log.error("Can not detecting parameter properties because "
            + "either table name or column name is null for the "
            + "parameter with index " + jdbcParam.getIndex());
      }
    }

    return st;
  }
View Full Code Here


        int qmarkIndex = 1;
        for (int j = 0; j < totalTokens; j++) {
            String token = tokens[j];
           
            if (token.startsWith("?")) {
                JdbcStatementParameter param = new JdbcStatementParameter();
                param.setIndex(qmarkIndex);
                param.setName(getNameFromToken(qmarkIndex, token));
                st.addParameter(param);
               
                qmarkIndex = qmarkIndex + 1;
               
                //get inline sql data type
                int sqlDataType = getInlineSqlDataTypeFromToken(token);
                if (sqlDataType != JdbcStatementParameter.UNKNOWN_SQL_DATA_TYPE) {
                    param.setSqlDataType(sqlDataType);
                    continue;//no need to parse
                }
               
                String columnName = "";
                String tableName = "";
                int dotPosition = token.indexOf('.');
                if (dotPosition != -1) {
                    String[] results = getTableAndColumnFromDottedToken(token);
                    if (results != null) {
                        tableName = results[0];
                        columnName = results[1];
                        param.setColumnName(columnName);
                        param.setTableName(tableName);
                        continue;
                    }
                }
               
                String columnNameToken = "";
                if (j>=2 && "BETWEEN".equalsIgnoreCase(tokens[j-1])) {
                    columnNameToken = tokens[j-2];
                }
                else if (j>=4 && "BETWEEN".equalsIgnoreCase(tokens[j-3]) && "AND".equalsIgnoreCase(tokens[j-1])) {
                    columnNameToken = tokens[j-4];
                }
                else if (j>=2 && "COUNT".equalsIgnoreCase(tokens[j-1])) {
                    columnNameToken = "COUNT(*)";
                    param.setUsedByCount(true);
                }
                else if (j>=2 && "COUNT".equalsIgnoreCase(tokens[j-2])) {
                    columnNameToken = tokens[j-1];
                    param.setUsedByCount(true);
                }
                else if (j>=2 && "IN".equalsIgnoreCase(tokens[j-1])) {
                    columnNameToken = tokens[j-2];
                }
                else if (j>=2 && "LIKE".equalsIgnoreCase(tokens[j-1])) {
                    columnNameToken = tokens[j-2];
                }
                else if (!"?".equals(tokens[j-1])) {
                    columnNameToken = tokens[j-1];
                }
                else {
                    log.warn("Failed to detect column name for ? with index " + qmarkIndex +
                             ", suggest to use inline sql type declaration if " +
                             "the underlying database doesn't support ParameterMetaData.");
                    continue;
                }
               
                dotPosition = columnNameToken.indexOf('.');
                if (dotPosition == -1) {
                    columnName = columnNameToken;
                    tableName = getTableName(j, tokens, columnName);
                }
                else {
                    columnName = columnNameToken.substring(dotPosition + 1, columnNameToken.length());
                    tableName  = columnNameToken.substring(0, dotPosition);
                }
               
                //set the found column and table names
                if (tableName != null) {
                    param.setColumnName(columnName);
                    param.setTableName(tableName);
                }
            }
        }
    }
View Full Code Here

        int qmarkIndex = 1;
        for (int l = 0; l < length; l++) {
            String columnName = columns.get(l);
            String value = values.get(l);
            if (value.startsWith("?")) {
                JdbcStatementParameter param = new JdbcStatementParameter();
                param.setIndex(qmarkIndex);
                param.setColumnName(columnName);
                param.setTableName(tableName);
                param.setName(getNameFromToken(qmarkIndex, value));
                st.addParameter(param);
               
                //get inline sql data type
                int sqlDataType = getInlineSqlDataTypeFromToken(value);
                if (sqlDataType != JdbcStatementParameter.UNKNOWN_SQL_DATA_TYPE) {
                    param.setSqlDataType(sqlDataType);
                    continue;//no need to parse
                }
               
                qmarkIndex = qmarkIndex + 1;
            }
View Full Code Here

        int qmarkIndex = 1;
        for ( int j = 0; j < totalTokens; j++ ) {
            String token = tokens[j];
           
            if (token.startsWith("?")) {
                JdbcStatementParameter param = new JdbcStatementParameter();
                param.setIndex(qmarkIndex);
                param.setName(getNameFromToken(qmarkIndex, token));
                st.addParameter(param);
               
                qmarkIndex = qmarkIndex + 1;
            }
        }
View Full Code Here

TOP

Related Classes of com.scooterframework.orm.sqldataexpress.object.JdbcStatementParameter

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.