コード例 #1
0
  @Override
  public void addImplementationElements(TopLevelClass topLevelClass) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    Method method = getMethodShell(importedTypes);

    // generate the implementation method
    StringBuilder sb = new StringBuilder();

    FullyQualifiedJavaType dao = introspectedTable.getDAOInterfaceType();

    FullyQualifiedJavaType returnType = method.getReturnType();

    sb.setLength(0);
    sb.append(returnType.getShortName());
    sb.append(" records = "); // $NON-NLS-1$
    sb.append(
        serviceTemplate.getQueryForObjectMethod(
            JavaBeansUtil.getPropertyName(dao.getShortName()),
            getServiceMethodNameCalculator().getSelectByConditionMethodName(introspectedTable),
            "condition")); //$NON-NLS-1$
    method.addBodyLine(sb.toString());
    method.addBodyLine("return records;"); // $NON-NLS-1$

    if (ibatorContext
        .getPlugins()
        .daoSelectByConditionMethodGenerated(method, topLevelClass, introspectedTable)) {
      topLevelClass.addImportedTypes(importedTypes);
      topLevelClass.addMethod(method);
    }
  }
コード例 #2
0
  @Override
  public void addImplementationElements(TopLevelClass topLevelClass) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    Method method = getMethodShell(importedTypes);

    FullyQualifiedJavaType returnType = method.getReturnType();
    FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();

    StringBuilder sb = new StringBuilder();

    if (returnType != null) {
      sb.append("Object newKey = "); // $NON-NLS-1$
    }

    sb.append(
        daoTemplate.getInsertMethod(
            table.getSqlMapNamespace(), XmlConstants.INSERT_STATEMENT_ID, "record")); // $NON-NLS-1$
    method.addBodyLine(sb.toString());

    if (returnType != null) {
      if ("Object".equals(returnType.getShortName())) { // $NON-NLS-1$
        // no need to cast if the return type is Object
        method.addBodyLine("return newKey;"); // $NON-NLS-1$
      } else {
        sb.setLength(0);

        if (returnType.isPrimitive()) {
          PrimitiveTypeWrapper ptw = returnType.getPrimitiveTypeWrapper();
          sb.append("return (("); // $NON-NLS-1$
          sb.append(ptw.getShortName());
          sb.append(") newKey"); // $NON-NLS-1$
          sb.append(")."); // $NON-NLS-1$
          sb.append(ptw.getToPrimitiveMethod());
          sb.append(';');
        } else {
          sb.append("return ("); // $NON-NLS-1$
          sb.append(returnType.getShortName());
          sb.append(") newKey;"); // $NON-NLS-1$
        }

        method.addBodyLine(sb.toString());
      }
    }

    if (ibatorContext
        .getPlugins()
        .daoInsertMethodGenerated(method, topLevelClass, introspectedTable)) {
      topLevelClass.addImportedTypes(importedTypes);
      topLevelClass.addMethod(method);
    }
  }
コード例 #3
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;
  }