use of org.mybatis.generator.api.dom.java.Field in project generator by mybatis.
the class RecordWithBLOBsGenerator method getCompilationUnits.
@Override
public List<CompilationUnit> getCompilationUnits() {
FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
progressCallback.startTask(getString("Progress.9", //$NON-NLS-1$
table.toString()));
Plugin plugins = context.getPlugins();
CommentGenerator commentGenerator = context.getCommentGenerator();
TopLevelClass topLevelClass = new TopLevelClass(introspectedTable.getRecordWithBLOBsType());
topLevelClass.setVisibility(JavaVisibility.PUBLIC);
commentGenerator.addJavaFileComment(topLevelClass);
String rootClass = getRootClass();
if (introspectedTable.getRules().generateBaseRecordClass()) {
topLevelClass.setSuperClass(introspectedTable.getBaseRecordType());
} else {
topLevelClass.setSuperClass(introspectedTable.getPrimaryKeyType());
}
commentGenerator.addModelClassComment(topLevelClass, introspectedTable);
if (introspectedTable.isConstructorBased()) {
addParameterizedConstructor(topLevelClass);
if (!introspectedTable.isImmutable()) {
addDefaultConstructor(topLevelClass);
}
}
for (IntrospectedColumn introspectedColumn : introspectedTable.getBLOBColumns()) {
if (RootClassInfo.getInstance(rootClass, warnings).containsProperty(introspectedColumn)) {
continue;
}
Field field = getJavaBeansField(introspectedColumn, context, introspectedTable);
if (plugins.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.RECORD_WITH_BLOBS)) {
topLevelClass.addField(field);
topLevelClass.addImportedType(field.getType());
}
Method method = getJavaBeansGetter(introspectedColumn, context, introspectedTable);
if (plugins.modelGetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.RECORD_WITH_BLOBS)) {
topLevelClass.addMethod(method);
}
if (!introspectedTable.isImmutable()) {
method = getJavaBeansSetter(introspectedColumn, context, introspectedTable);
if (plugins.modelSetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.RECORD_WITH_BLOBS)) {
topLevelClass.addMethod(method);
}
}
}
List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
if (context.getPlugins().modelRecordWithBLOBsClassGenerated(topLevelClass, introspectedTable)) {
answer.add(topLevelClass);
}
return answer;
}
use of org.mybatis.generator.api.dom.java.Field in project generator by mybatis.
the class SimpleModelGenerator method getCompilationUnits.
@Override
public List<CompilationUnit> getCompilationUnits() {
FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
//$NON-NLS-1$
progressCallback.startTask(getString("Progress.8", table.toString()));
Plugin plugins = context.getPlugins();
CommentGenerator commentGenerator = context.getCommentGenerator();
FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
TopLevelClass topLevelClass = new TopLevelClass(type);
topLevelClass.setVisibility(JavaVisibility.PUBLIC);
commentGenerator.addJavaFileComment(topLevelClass);
FullyQualifiedJavaType superClass = getSuperClass();
if (superClass != null) {
topLevelClass.setSuperClass(superClass);
topLevelClass.addImportedType(superClass);
}
commentGenerator.addModelClassComment(topLevelClass, introspectedTable);
List<IntrospectedColumn> introspectedColumns = introspectedTable.getAllColumns();
if (introspectedTable.isConstructorBased()) {
addParameterizedConstructor(topLevelClass);
if (!introspectedTable.isImmutable()) {
addDefaultConstructor(topLevelClass);
}
}
String rootClass = getRootClass();
for (IntrospectedColumn introspectedColumn : introspectedColumns) {
if (RootClassInfo.getInstance(rootClass, warnings).containsProperty(introspectedColumn)) {
continue;
}
Field field = getJavaBeansField(introspectedColumn, context, introspectedTable);
if (plugins.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.BASE_RECORD)) {
topLevelClass.addField(field);
topLevelClass.addImportedType(field.getType());
}
Method method = getJavaBeansGetter(introspectedColumn, context, introspectedTable);
if (plugins.modelGetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.BASE_RECORD)) {
topLevelClass.addMethod(method);
}
if (!introspectedTable.isImmutable()) {
method = getJavaBeansSetter(introspectedColumn, context, introspectedTable);
if (plugins.modelSetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable, Plugin.ModelClassType.BASE_RECORD)) {
topLevelClass.addMethod(method);
}
}
}
List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
if (context.getPlugins().modelBaseRecordClassGenerated(topLevelClass, introspectedTable)) {
answer.add(topLevelClass);
}
return answer;
}
use of org.mybatis.generator.api.dom.java.Field in project generator by mybatis.
the class TestResourceGenerator method simpleClassWithGeneratedAndCustomItems.
public static String simpleClassWithGeneratedAndCustomItems() {
TopLevelClass tlc = new TopLevelClass(new FullyQualifiedJavaType("org.mybatis.test.SimpleClass"));
tlc.setVisibility(JavaVisibility.PUBLIC);
Field field = new Field("description", FullyQualifiedJavaType.getStringInstance());
field.setVisibility(JavaVisibility.PRIVATE);
commentGenerator.addFieldComment(field);
tlc.addField(field);
Method method = new Method("getDescription");
method.setReturnType(FullyQualifiedJavaType.getStringInstance());
method.addBodyLine("return description;");
method.setVisibility(JavaVisibility.PUBLIC);
commentGenerator.addMethodComment(method);
tlc.addMethod(method);
method = new Method("setDescription");
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "description"));
method.addBodyLine("this.description = description;");
method.setVisibility(JavaVisibility.PUBLIC);
commentGenerator.addMethodComment(method);
tlc.addMethod(method);
// no comments on these items - they should survive a merge
FullyQualifiedJavaType bigDecimal = new FullyQualifiedJavaType("java.math.BigDecimal");
tlc.addImportedType(bigDecimal);
field = new Field("amount", bigDecimal);
field.setVisibility(JavaVisibility.PRIVATE);
tlc.addField(field);
method = new Method("getAmount");
method.setReturnType(bigDecimal);
method.addBodyLine("return amount;");
method.setVisibility(JavaVisibility.PUBLIC);
tlc.addMethod(method);
method = new Method("setAmount");
method.addParameter(new Parameter(bigDecimal, "amount"));
method.addBodyLine("this.amount = amount;");
method.setVisibility(JavaVisibility.PUBLIC);
tlc.addMethod(method);
return tlc.getFormattedContent();
}
use of org.mybatis.generator.api.dom.java.Field in project generator by mybatis.
the class TestResourceGenerator method simpleClassWithAllGeneratedItems.
public static String simpleClassWithAllGeneratedItems() {
TopLevelClass tlc = new TopLevelClass(new FullyQualifiedJavaType("org.mybatis.test.SimpleClass"));
tlc.setVisibility(JavaVisibility.PUBLIC);
Field field = new Field("id", FullyQualifiedJavaType.getIntInstance());
field.setVisibility(JavaVisibility.PRIVATE);
commentGenerator.addFieldComment(field);
tlc.addField(field);
Method method = new Method("getId");
method.setReturnType(FullyQualifiedJavaType.getIntInstance());
method.addBodyLine("return id;");
method.setVisibility(JavaVisibility.PUBLIC);
commentGenerator.addMethodComment(method);
tlc.addMethod(method);
method = new Method("setId");
method.addParameter(new Parameter(FullyQualifiedJavaType.getIntInstance(), "id"));
method.addBodyLine("this.id = id;");
method.setVisibility(JavaVisibility.PUBLIC);
commentGenerator.addMethodComment(method);
tlc.addMethod(method);
return tlc.getFormattedContent();
}
use of org.mybatis.generator.api.dom.java.Field in project generator by mybatis.
the class GenericSIDAOTemplate method configureFields.
@Override
protected void configureFields() {
Field field = new Field();
field.setVisibility(JavaVisibility.PRIVATE);
field.setType(sqlMapClientType);
//$NON-NLS-1$
field.setName("sqlMapClient");
addField(field);
}
Aggregations