}
@Override
public void addImplementationElements(TopLevelClass topLevelClass) {
Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
Method method = getMethodShell(importedTypes);
StringBuilder sb = new StringBuilder();
if (!introspectedTable.getRules().generatePrimaryKeyClass()) {
// no primary key class, but primary key is enabled. Primary
// key columns must be in the base class.
FullyQualifiedJavaType keyType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
topLevelClass.addImportedType(keyType);
sb.setLength(0);
sb.append(keyType.getShortName());
sb.append(" _key = new "); //$NON-NLS-1$
sb.append(keyType.getShortName());
sb.append("();"); //$NON-NLS-1$
method.addBodyLine(sb.toString());
for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
sb.setLength(0);
sb.append("_key."); //$NON-NLS-1$
sb.append(getSetterMethodName(introspectedColumn.getJavaProperty()));
sb.append('(');
sb.append(introspectedColumn.getJavaProperty());
sb.append(");"); //$NON-NLS-1$
method.addBodyLine(sb.toString());
}
}
sb.setLength(0);
sb.append("int rows = "); //$NON-NLS-1$
sb.append(daoTemplate.getDeleteMethod(introspectedTable.getIbatis2SqlMapNamespace(),
introspectedTable.getDeleteByPrimaryKeyStatementId(), "_key")); //$NON-NLS-1$
method.addBodyLine(sb.toString());
method.addBodyLine("return rows;"); //$NON-NLS-1$
if (context.getPlugins().clientDeleteByPrimaryKeyMethodGenerated(method, topLevelClass, introspectedTable)) {
topLevelClass.addImportedTypes(importedTypes);
topLevelClass.addMethod(method);
}