コード例 #1
0
  private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
    FullyQualifiedJavaType type = introspectedTable.getConditionType();

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);

    FullyQualifiedJavaType returnType = FullyQualifiedJavaType.getNewListInstance();
    returnType.addTypeArgument(introspectedTable.getConditionType());
    method.setReturnType(returnType);
    importedTypes.add(returnType);
    importedTypes.add(introspectedTable.getConditionType());

    method.setName(
        getServiceMethodNameCalculator().getSelectByConditionMethodName(introspectedTable));

    method.addParameter(new Parameter(type, "condition"));

    for (FullyQualifiedJavaType fqjt : serviceTemplate.getCheckedExceptions()) {
      method.addException(fqjt);
      importedTypes.add(fqjt);
    }

    ibatorContext.getCommentGenerator().addGeneralMethodComment(method, table);

    return method;
  }
コード例 #2
0
  @Override
  public boolean modelExampleClassGenerated(
      TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {

    InnerClass criteria = null;
    // first, find the Criteria inner class
    for (InnerClass innerClass : topLevelClass.getInnerClasses()) {
      if ("Criteria".equals(innerClass.getType().getShortName())) { // $NON-NLS-1$
        criteria = innerClass;
        break;
      }
    }

    if (criteria == null) {
      // can't find the inner class for some reason, bail out.
      return true;
    }

    for (IntrospectedColumn introspectedColumn : introspectedTable.getNonBLOBColumns()) {
      if (!introspectedColumn.isJdbcCharacterColumn() || !introspectedColumn.isStringColumn()) {
        continue;
      }

      Method method = new Method();
      method.setVisibility(JavaVisibility.PUBLIC);
      method.addParameter(
          new Parameter(introspectedColumn.getFullyQualifiedJavaType(), "value")); // $NON-NLS-1$

      StringBuilder sb = new StringBuilder();
      sb.append(introspectedColumn.getJavaProperty());
      sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
      sb.insert(0, "and"); // $NON-NLS-1$
      sb.append("LikeInsensitive"); // $NON-NLS-1$
      method.setName(sb.toString());
      method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());

      sb.setLength(0);
      sb.append("addCriterion(\"upper("); // $NON-NLS-1$
      sb.append(Ibatis2FormattingUtilities.getAliasedActualColumnName(introspectedColumn));
      sb.append(") like\", value.toUpperCase(), \""); // $NON-NLS-1$
      sb.append(introspectedColumn.getJavaProperty());
      sb.append("\");"); // $NON-NLS-1$
      method.addBodyLine(sb.toString());
      method.addBodyLine("return this;"); // $NON-NLS-1$

      criteria.addMethod(method);
    }

    return true;
  }
コード例 #3
0
  private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
    Method method = new Method();

    FullyQualifiedJavaType returnType;
    if (introspectedTable.getGeneratedKey() != null) {
      IntrospectedColumn introspectedColumn =
          introspectedTable.getColumn(introspectedTable.getGeneratedKey().getColumn());
      if (introspectedColumn == null) {
        // the specified column doesn't exist, so don't do the generated
        // key
        // (the warning has already been reported)
        returnType = null;
      } else {
        returnType = introspectedColumn.getFullyQualifiedJavaType();
        importedTypes.add(returnType);
      }
    } else {
      returnType = null;
    }

    method.setReturnType(returnType);
    method.setVisibility(JavaVisibility.PUBLIC);
    DAOMethodNameCalculator methodNameCalculator = getDAOMethodNameCalculator();
    method.setName(methodNameCalculator.getInsertMethodName(introspectedTable));

    FullyQualifiedJavaType parameterType = introspectedTable.getRules().calculateAllFieldsClass();

    importedTypes.add(parameterType);
    method.addParameter(new Parameter(parameterType, "record")); // $NON-NLS-1$

    for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
      method.addException(fqjt);
      importedTypes.add(fqjt);
    }

    ibatorContext.getCommentGenerator().addGeneralMethodComment(method, table);

    return method;
  }