@Override public void addImplementationElements(TopLevelClass topLevelClass) { Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); Method method = getMethodShell(importedTypes); if (generateForJava5) { method.addSuppressTypeWarningsAnnotation(); } StringBuilder sb = new StringBuilder(); sb.append(method.getReturnType().getShortName()); sb.append(" list = "); // $NON-NLS-1$ sb.append( daoTemplate.getQueryForListMethod( introspectedTable.getIbatis2SqlMapNamespace(), introspectedTable.getSelectByExampleStatementId(), "example")); //$NON-NLS-1$ method.addBodyLine(sb.toString()); method.addBodyLine("return list;"); // $NON-NLS-1$ if (context .getPlugins() .clientSelectByExampleWithoutBLOBsMethodGenerated( method, topLevelClass, introspectedTable)) { topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
private void addCriteriaMethods(TopLevelClass topLevelClass, int newMethodsStart) { if (!generateCriteriaMethods) return; InnerClass criteria = null; for (InnerClass c : topLevelClass.getInnerClasses()) { if (c.getType().getShortName().equals("Criteria")) criteria = c; } if (criteria == null) return; boolean owner = false; for (Field f : criteria.getFields()) if (ExampleMethodsChainPlugin.OWNER.equals(f.getName())) owner = true; if (!owner) return; for (ListIterator<Method> methods = topLevelClass.getMethods().listIterator(newMethodsStart); methods.hasNext(); ) { Method base = methods.next(); if (base.getVisibility() != PUBLIC || base.isStatic() || base.isConstructor()) continue; Method m = method(PUBLIC, base.getReturnType(), base.getName()); StringBuilder sb = new StringBuilder(); sb.append("return ").append(ExampleMethodsChainPlugin.OWNER).append(".").append(base.getName()).append("("); for (ListIterator<Parameter> params = base.getParameters().listIterator(); params.hasNext(); ) { if (params.hasPrevious()) sb.append(", "); Parameter p = params.next(); m.addParameter(new Parameter(p.getType(), p.getName())); sb.append(p.getName()); } sb.append(");"); m.addBodyLine(sb.toString()); criteria.addMethod(m); } }
@Override public void addImplementationElements(TopLevelClass topLevelClass) { Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>(); Method method = getMethodShell(importedTypes); FullyQualifiedJavaType returnType = method.getReturnType(); StringBuilder sb = new StringBuilder(); if (returnType != null) { sb.append("Object newKey = "); // $NON-NLS-1$ } sb.append( daoTemplate.getInsertMethod( introspectedTable.getIbatis2SqlMapNamespace(), introspectedTable.getInsertSelectiveStatementId(), "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 (context .getPlugins() .clientInsertSelectiveMethodGenerated(method, topLevelClass, introspectedTable)) { topLevelClass.addImportedTypes(importedTypes); topLevelClass.addMethod(method); } }
public boolean clientInsertMethodGenerated( Method method, Interface interfaze, IntrospectedTable introspectedTable) { returnType = method.getReturnType(); return true; }