use of org.mybatis.generator.api.dom.java.Method in project generator by mybatis.
the class AbstractDAOTemplate method getConstructorClone.
/**
* Gets the constructor clone.
*
* @param commentGenerator
* the comment generator
* @param type
* the type
* @param introspectedTable
* the introspected table
* @return the constructor clone
*/
public final Method getConstructorClone(CommentGenerator commentGenerator, FullyQualifiedJavaType type, IntrospectedTable introspectedTable) {
configure();
Method answer = new Method();
answer.setConstructor(true);
answer.setName(type.getShortName());
answer.setVisibility(constructorTemplate.getVisibility());
for (Parameter parm : constructorTemplate.getParameters()) {
answer.addParameter(parm);
}
for (String bodyLine : constructorTemplate.getBodyLines()) {
answer.addBodyLine(bodyLine);
}
for (FullyQualifiedJavaType fqjt : constructorTemplate.getExceptions()) {
answer.addException(fqjt);
}
commentGenerator.addGeneralMethodComment(answer, introspectedTable);
return answer;
}
use of org.mybatis.generator.api.dom.java.Method in project generator by mybatis.
the class GenericCIDAOTemplate method configureConstructorTemplate.
@Override
protected void configureConstructorTemplate() {
Method constructor = new Method();
constructor.setConstructor(true);
constructor.setVisibility(JavaVisibility.PUBLIC);
constructor.addParameter(//$NON-NLS-1$
new Parameter(sqlMapClientType, "sqlMapClient"));
//$NON-NLS-1$
constructor.addBodyLine("super();");
//$NON-NLS-1$
constructor.addBodyLine("this.sqlMapClient = sqlMapClient;");
setConstructorTemplate(constructor);
}
use of org.mybatis.generator.api.dom.java.Method in project generator by mybatis.
the class GenericSIDAOTemplate method configureMethods.
@Override
protected void configureMethods() {
Method method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
//$NON-NLS-1$
method.setName("setSqlMapClient");
//$NON-NLS-1$
method.addParameter(new Parameter(sqlMapClientType, "sqlMapClient"));
//$NON-NLS-1$
method.addBodyLine("this.sqlMapClient = sqlMapClient;");
addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
//$NON-NLS-1$
method.setName("getSqlMapClient");
method.setReturnType(sqlMapClientType);
//$NON-NLS-1$
method.addBodyLine("return sqlMapClient;");
addMethod(method);
}
use of org.mybatis.generator.api.dom.java.Method in project generator by mybatis.
the class SelectByExampleWithoutBLOBsMethodGenerator method addImplementationElements.
@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());
//$NON-NLS-1$
sb.append(" list = ");
sb.append(daoTemplate.getQueryForListMethod(introspectedTable.getIbatis2SqlMapNamespace(), introspectedTable.getSelectByExampleStatementId(), //$NON-NLS-1$
"example"));
method.addBodyLine(sb.toString());
//$NON-NLS-1$
method.addBodyLine("return list;");
if (context.getPlugins().clientSelectByExampleWithoutBLOBsMethodGenerated(method, topLevelClass, introspectedTable)) {
topLevelClass.addImportedTypes(importedTypes);
topLevelClass.addMethod(method);
}
}
use of org.mybatis.generator.api.dom.java.Method in project generator by mybatis.
the class SelectByExampleWithoutBLOBsMethodGenerator 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().generateBaseRecordClass()) {
fqjt = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
} else if (introspectedTable.getRules().generatePrimaryKeyClass()) {
fqjt = new FullyQualifiedJavaType(introspectedTable.getPrimaryKeyType());
} else {
//$NON-NLS-1$
throw new RuntimeException(getString("RuntimeError.12"));
}
importedTypes.add(fqjt);
returnType.addTypeArgument(fqjt);
}
method.setReturnType(returnType);
method.setName(getDAOMethodNameCalculator().getSelectByExampleWithoutBLOBsMethodName(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;
}
Aggregations