}
@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.getInsertStatementId(), "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().clientInsertMethodGenerated(method, topLevelClass, introspectedTable)) {
topLevelClass.addImportedTypes(importedTypes);