use of org.mybatis.generator.api.dom.java.Method in project generator by mybatis.
the class SelectByExampleWithBLOBsMethodGenerator method getMethodShell.
private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getExampleType());
importedTypes.add(type);
importedTypes.add(FullyQualifiedJavaType.getNewListInstance());
Method method = new Method();
method.setVisibility(getExampleMethodVisibility());
FullyQualifiedJavaType returnType = FullyQualifiedJavaType.getNewListInstance();
if (generateForJava5) {
FullyQualifiedJavaType fqjt;
if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
fqjt = new FullyQualifiedJavaType(introspectedTable.getRecordWithBLOBsType());
} else {
// the blob fields must be rolled up into the base class
fqjt = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
}
importedTypes.add(fqjt);
returnType.addTypeArgument(fqjt);
}
method.setReturnType(returnType);
method.setName(getDAOMethodNameCalculator().getSelectByExampleWithBLOBsMethodName(introspectedTable));
//$NON-NLS-1$
method.addParameter(new Parameter(type, "example"));
for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
method.addException(fqjt);
importedTypes.add(fqjt);
}
context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
return method;
}
use of org.mybatis.generator.api.dom.java.Method in project generator by mybatis.
the class TestResourceGenerator method simpleInterfaceWithGeneratedAndCustomItems.
public static String simpleInterfaceWithGeneratedAndCustomItems() {
Interface itf = new Interface(new FullyQualifiedJavaType("org.mybatis.test.SimpleInterface"));
itf.setVisibility(JavaVisibility.PUBLIC);
Method method = new Method("subtract");
method.addParameter(new Parameter(FullyQualifiedJavaType.getIntInstance(), "a"));
method.addParameter(new Parameter(FullyQualifiedJavaType.getIntInstance(), "b"));
method.setReturnType(FullyQualifiedJavaType.getIntInstance());
commentGenerator.addMethodComment(method);
itf.addMethod(method);
method = new Method("nonGeneratedMethod");
method.setReturnType(FullyQualifiedJavaType.getIntInstance());
itf.addMethod(method);
return itf.getFormattedContent();
}
use of org.mybatis.generator.api.dom.java.Method in project generator by mybatis.
the class AbstractJavaGenerator method getGetter.
public static Method getGetter(Field field) {
Method method = new Method();
method.setName(getGetterMethodName(field.getName(), field.getType()));
method.setReturnType(field.getType());
method.setVisibility(JavaVisibility.PUBLIC);
StringBuilder sb = new StringBuilder();
//$NON-NLS-1$
sb.append("return ");
sb.append(field.getName());
sb.append(';');
method.addBodyLine(sb.toString());
return method;
}
use of org.mybatis.generator.api.dom.java.Method in project generator by mybatis.
the class AbstractJavaGenerator method addDefaultConstructor.
protected void addDefaultConstructor(TopLevelClass topLevelClass) {
Method method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setConstructor(true);
method.setName(topLevelClass.getType().getShortName());
//$NON-NLS-1$
method.addBodyLine("super();");
context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
topLevelClass.addMethod(method);
}
use of org.mybatis.generator.api.dom.java.Method in project generator by mybatis.
the class DeleteByExampleMethodGenerator method addImplementationElements.
@Override
public void addImplementationElements(TopLevelClass topLevelClass) {
Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
Method method = getMethodShell(importedTypes);
StringBuilder sb = new StringBuilder();
//$NON-NLS-1$
sb.append("int rows = ");
sb.append(daoTemplate.getDeleteMethod(introspectedTable.getIbatis2SqlMapNamespace(), introspectedTable.getDeleteByExampleStatementId(), //$NON-NLS-1$
"example"));
method.addBodyLine(sb.toString());
//$NON-NLS-1$
method.addBodyLine("return rows;");
if (context.getPlugins().clientDeleteByExampleMethodGenerated(method, topLevelClass, introspectedTable)) {
topLevelClass.addImportedTypes(importedTypes);
topLevelClass.addMethod(method);
}
}
Aggregations