use of org.mybatis.generator.api.dom.java.Method in project generator by mybatis.
the class SelectByExampleWithBLOBsMethodGenerator method addInterfaceElements.
@Override
public void addInterfaceElements(Interface interfaze) {
if (getExampleMethodVisibility() == JavaVisibility.PUBLIC) {
Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
Method method = getMethodShell(importedTypes);
if (context.getPlugins().clientSelectByExampleWithBLOBsMethodGenerated(method, interfaze, introspectedTable)) {
interfaze.addImportedTypes(importedTypes);
interfaze.addMethod(method);
}
}
}
use of org.mybatis.generator.api.dom.java.Method in project generator by mybatis.
the class DAOGenerator method getTopLevelClassShell.
protected TopLevelClass getTopLevelClassShell() {
FullyQualifiedJavaType interfaceType = new FullyQualifiedJavaType(introspectedTable.getDAOInterfaceType());
FullyQualifiedJavaType implementationType = new FullyQualifiedJavaType(introspectedTable.getDAOImplementationType());
CommentGenerator commentGenerator = context.getCommentGenerator();
TopLevelClass answer = new TopLevelClass(implementationType);
answer.setVisibility(JavaVisibility.PUBLIC);
answer.setSuperClass(daoTemplate.getSuperClass());
answer.addImportedType(daoTemplate.getSuperClass());
answer.addSuperInterface(interfaceType);
answer.addImportedType(interfaceType);
for (FullyQualifiedJavaType fqjt : daoTemplate.getImplementationImports()) {
answer.addImportedType(fqjt);
}
commentGenerator.addJavaFileComment(answer);
// add constructor from the template
answer.addMethod(daoTemplate.getConstructorClone(commentGenerator, implementationType, introspectedTable));
// add any fields from the template
for (Field field : daoTemplate.getFieldClones(commentGenerator, introspectedTable)) {
answer.addField(field);
}
// add any methods from the template
for (Method method : daoTemplate.getMethodClones(commentGenerator, introspectedTable)) {
answer.addMethod(method);
}
return answer;
}
use of org.mybatis.generator.api.dom.java.Method in project generator by mybatis.
the class CountByExampleMethodGenerator method addInterfaceElements.
@Override
public void addInterfaceElements(Interface interfaze) {
if (getExampleMethodVisibility() == JavaVisibility.PUBLIC) {
Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
Method method = getMethodShell(importedTypes);
if (context.getPlugins().clientCountByExampleMethodGenerated(method, interfaze, introspectedTable)) {
interfaze.addImportedTypes(importedTypes);
interfaze.addMethod(method);
}
}
}
use of org.mybatis.generator.api.dom.java.Method in project generator by mybatis.
the class CountByExampleMethodGenerator method addImplementationElements.
@Override
public void addImplementationElements(TopLevelClass topLevelClass) {
Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
Method method = getMethodShell(importedTypes);
// generate the implementation method
StringBuilder sb = new StringBuilder();
//$NON-NLS-1$
sb.append("Long count = (Long) ");
sb.append(daoTemplate.getQueryForObjectMethod(introspectedTable.getIbatis2SqlMapNamespace(), introspectedTable.getCountByExampleStatementId(), //$NON-NLS-1$
"example"));
method.addBodyLine(sb.toString());
if (generateForJava5) {
//$NON-NLS-1$
method.addBodyLine("return count;");
} else {
//$NON-NLS-1$
method.addBodyLine("return count.longValue();");
}
if (context.getPlugins().clientCountByExampleMethodGenerated(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 CountByExampleMethodGenerator method getMethodShell.
private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getExampleType());
importedTypes.add(type);
Method method = new Method();
method.setVisibility(getExampleMethodVisibility());
//$NON-NLS-1$
method.setReturnType(new FullyQualifiedJavaType("long"));
method.setName(getDAOMethodNameCalculator().getCountByExampleMethodName(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