コード例 #1
0
 private ParameterMapping oldParseMapping(
     String token, Class parameterClass, TypeHandlerRegistry typeHandlerRegistry) {
   if (token.indexOf(PARAM_DELIM) > -1) {
     StringTokenizer paramParser = new StringTokenizer(token, PARAM_DELIM, true);
     int n1 = paramParser.countTokens();
     if (n1 == 3) {
       String name = paramParser.nextToken();
       paramParser.nextToken(); // ignore ":"
       String type = paramParser.nextToken();
       TypeHandler handler;
       if (parameterClass == null) {
         handler = typeHandlerRegistry.getUnknownTypeHandler();
       } else {
         handler = resolveTypeHandler(parameterClass, name, null, JdbcType.valueOf(type));
       }
       ParameterMapping.Builder mapping =
           new ParameterMapping.Builder(configuration, name, handler);
       mapping.jdbcType(JdbcType.valueOf(type));
       return mapping.build();
     } else if (n1 >= 5) {
       throw new UnsupportedOperationException(
           "iBATIS 3 does not support null value substitution.");
     } else {
       throw new SqlMapException("Incorrect inline parameter map format: " + token);
     }
   } else {
     TypeHandler handler;
     if (parameterClass == null) {
       handler = typeHandlerRegistry.getUnknownTypeHandler();
     } else {
       handler = resolveTypeHandler(parameterClass, token, null, null);
     }
     ParameterMapping.Builder mapping =
         new ParameterMapping.Builder(configuration, token, handler);
     return mapping.build();
   }
 }
コード例 #2
0
  private ParameterMapping newParseMapping(String token, Class parameterClass) {

    // #propertyName,javaType=string,jdbcType=VARCHAR,mode=IN,nullValue=N/A,handler=string,numericScale=2#

    StringTokenizer paramParser = new StringTokenizer(token, "=, ", false);
    String propertyName = paramParser.nextToken();
    TypeHandler typeHandler = null;
    Class javaType = null;
    JdbcType jdbcType = null;
    ParameterMode parameterMode = null;
    Integer numericScale = null;

    while (paramParser.hasMoreTokens()) {
      String field = paramParser.nextToken();
      if (paramParser.hasMoreTokens()) {
        String value = paramParser.nextToken();
        if ("javaType".equals(field)) {
          try {
            javaType = typeAliasRegistry.resolveAlias(value);
          } catch (Exception e) {
            throw new SqlMapException("Error loading javaType class");
          }
        } else if ("jdbcType".equals(field)) {
          jdbcType = JdbcType.valueOf(value);
        } else if ("mode".equals(field)) {
          parameterMode = ParameterMode.valueOf(value);
        } else if ("nullValue".equals(field)) {
          throw new UnsupportedOperationException(
              "iBATIS 3 does not support null value substitution.");
        } else if ("handler".equals(field)) {
          try {
            Object impl = typeAliasRegistry.resolveAlias(value).newInstance();
            typeHandler = ((TypeHandler) impl);
          } catch (Exception e) {
            throw new SqlMapException(
                "Error loading class specified by handler field in " + token + ".  Cause: " + e, e);
          }
        } else if ("numericScale".equals(field)) {
          try {
            numericScale = Integer.valueOf(value);
            if (numericScale < 0) {
              throw new SqlMapException(
                  "Value specified for numericScale must be greater than or equal to zero");
            }
          } catch (NumberFormatException e) {
            throw new SqlMapException("Value specified for numericScale is not a valid Integer");
          }
        } else {
          throw new SqlMapException(
              "Unrecognized parameter mapping field: '" + field + "' in " + token);
        }
      } else {
        throw new SqlMapException(
            "Incorrect inline parameter map format (missmatched name=value pairs): " + token);
      }
    }

    if (typeHandler == null) {
      if (parameterClass == null) {
        typeHandler = typeHandlerRegistry.getUnknownTypeHandler();
      } else {
        String javaTypeString = javaType == null ? null : javaType.getName();
        typeHandler = resolveTypeHandler(parameterClass, propertyName, javaTypeString, jdbcType);
      }
    }

    if (propertyName != null && propertyName.startsWith("[")) {
      propertyName = "_collection" + propertyName;
    }

    ParameterMapping.Builder mapping =
        new ParameterMapping.Builder(configuration, propertyName, typeHandler);
    mapping.javaType(javaType);
    mapping.jdbcType(jdbcType);
    mapping.mode(parameterMode);
    mapping.numericScale(numericScale);

    return mapping.build();
  }