@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; }
@Override public void addElements(XmlElement parentElement) { XmlElement answer = new XmlElement("update"); // $NON-NLS-1$ answer.addAttribute( new Attribute( "id", introspectedTable.getUpdateByPrimaryKeyWithBLOBsStatementId())); // $NON-NLS-1$ String parameterType; if (introspectedTable.getRules().generateRecordWithBLOBsClass()) { parameterType = introspectedTable.getRecordWithBLOBsType(); } else { parameterType = introspectedTable.getBaseRecordType(); } answer.addAttribute( new Attribute( "parameterClass", //$NON-NLS-1$ parameterType)); ibatorContext.getCommentGenerator().addComment(answer); StringBuilder sb = new StringBuilder(); sb.append("update "); // $NON-NLS-1$ sb.append(introspectedTable.getFullyQualifiedTableNameAtRuntime()); answer.addElement(new TextElement(sb.toString())); // set up for first column sb.setLength(0); sb.append("set "); // $NON-NLS-1$ Iterator<IntrospectedColumn> iter = introspectedTable.getNonPrimaryKeyColumns().iterator(); while (iter.hasNext()) { IntrospectedColumn introspectedColumn = iter.next(); sb.append(Ibatis2FormattingUtilities.getEscapedColumnName(introspectedColumn)); sb.append(" = "); // $NON-NLS-1$ sb.append(Ibatis2FormattingUtilities.getParameterClause(introspectedColumn)); if (iter.hasNext()) { sb.append(','); } answer.addElement(new TextElement(sb.toString())); // set up for the next column if (iter.hasNext()) { sb.setLength(0); OutputUtilities.xmlIndent(sb, 1); } } boolean and = false; for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) { sb.setLength(0); if (and) { sb.append(" and "); // $NON-NLS-1$ } else { sb.append("where "); // $NON-NLS-1$ and = true; } sb.append(Ibatis2FormattingUtilities.getEscapedColumnName(introspectedColumn)); sb.append(" = "); // $NON-NLS-1$ sb.append(Ibatis2FormattingUtilities.getParameterClause(introspectedColumn)); answer.addElement(new TextElement(sb.toString())); } if (ibatorContext .getPlugins() .sqlMapUpdateByPrimaryKeyWithBLOBsElementGenerated(answer, introspectedTable)) { parentElement.addElement(answer); } }