use of org.mybatis.generator.api.dom.java.TopLevelClass in project generator by mybatis.
the class Test1Generator method generateTestClassSub1.
private TopLevelClass generateTestClassSub1() {
FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(BASE_PACKAGE + ".sub1.SomeClass");
TopLevelClass tlc = new TopLevelClass(fqjt);
tlc.setVisibility(JavaVisibility.PUBLIC);
Method m = new Method();
m.setVisibility(JavaVisibility.PUBLIC);
m.setName("testClassMethod");
m.addBodyLine("System.out.println(\"testClass sub1 method\");");
tlc.addMethod(m);
return tlc;
}
use of org.mybatis.generator.api.dom.java.TopLevelClass 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.TopLevelClass in project generator by mybatis.
the class PrimaryKeyGenerator method getCompilationUnits.
@Override
public List<CompilationUnit> getCompilationUnits() {
FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
progressCallback.startTask(getString("Progress.7", //$NON-NLS-1$
table.toString()));
Plugin plugins = context.getPlugins();
CommentGenerator commentGenerator = context.getCommentGenerator();
TopLevelClass topLevelClass = new TopLevelClass(introspectedTable.getPrimaryKeyType());
topLevelClass.setVisibility(JavaVisibility.PUBLIC);
commentGenerator.addJavaFileComment(topLevelClass);
String rootClass = getRootClass();
if (rootClass != null) {
topLevelClass.setSuperClass(new FullyQualifiedJavaType(rootClass));
topLevelClass.addImportedType(topLevelClass.getSuperClass());
}
for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
if (RootClassInfo.getInstance(rootClass, warnings).containsProperty(introspectedColumn)) {
continue;
}
Field field = getJavaBeansField(introspectedColumn, context, introspectedTable);
if (plugins.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.PRIMARY_KEY)) {
topLevelClass.addField(field);
topLevelClass.addImportedType(field.getType());
}
Method method = getJavaBeansGetter(introspectedColumn, context, introspectedTable);
if (plugins.modelGetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.PRIMARY_KEY)) {
topLevelClass.addMethod(method);
}
method = getJavaBeansSetter(introspectedColumn, context, introspectedTable);
if (plugins.modelSetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.PRIMARY_KEY)) {
topLevelClass.addMethod(method);
}
}
List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
if (context.getPlugins().modelPrimaryKeyClassGenerated(topLevelClass, introspectedTable)) {
answer.add(topLevelClass);
}
return answer;
}
Aggregations