use of org.mybatis.generator.api.dom.java.Field in project generator by mybatis.
the class GenericCIDAOTemplate 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);
}
use of org.mybatis.generator.api.dom.java.Field in project generator by mybatis.
the class BaseRecordGenerator method getCompilationUnits.
@Override
public List<CompilationUnit> getCompilationUnits() {
FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
progressCallback.startTask(getString("Progress.8", //$NON-NLS-1$
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 = getColumnsInThisClass();
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 ExampleGenerator method getCriterionInnerClass.
private InnerClass getCriterionInnerClass() {
Field field;
Method method;
InnerClass answer = new InnerClass(new FullyQualifiedJavaType(//$NON-NLS-1$
"Criterion"));
answer.setVisibility(JavaVisibility.PUBLIC);
answer.setStatic(true);
context.getCommentGenerator().addClassComment(answer, introspectedTable);
field = new Field();
//$NON-NLS-1$
field.setName("condition");
field.setType(FullyQualifiedJavaType.getStringInstance());
field.setVisibility(JavaVisibility.PRIVATE);
answer.addField(field);
answer.addMethod(getGetter(field));
field = new Field();
//$NON-NLS-1$
field.setName("value");
field.setType(FullyQualifiedJavaType.getObjectInstance());
field.setVisibility(JavaVisibility.PRIVATE);
answer.addField(field);
answer.addMethod(getGetter(field));
field = new Field();
//$NON-NLS-1$
field.setName("secondValue");
field.setType(FullyQualifiedJavaType.getObjectInstance());
field.setVisibility(JavaVisibility.PRIVATE);
answer.addField(field);
answer.addMethod(getGetter(field));
field = new Field();
//$NON-NLS-1$
field.setName("noValue");
field.setType(FullyQualifiedJavaType.getBooleanPrimitiveInstance());
field.setVisibility(JavaVisibility.PRIVATE);
answer.addField(field);
answer.addMethod(getGetter(field));
field = new Field();
//$NON-NLS-1$
field.setName("singleValue");
field.setType(FullyQualifiedJavaType.getBooleanPrimitiveInstance());
field.setVisibility(JavaVisibility.PRIVATE);
answer.addField(field);
answer.addMethod(getGetter(field));
field = new Field();
//$NON-NLS-1$
field.setName("betweenValue");
field.setType(FullyQualifiedJavaType.getBooleanPrimitiveInstance());
field.setVisibility(JavaVisibility.PRIVATE);
answer.addField(field);
answer.addMethod(getGetter(field));
field = new Field();
//$NON-NLS-1$
field.setName("listValue");
field.setType(FullyQualifiedJavaType.getBooleanPrimitiveInstance());
field.setVisibility(JavaVisibility.PRIVATE);
answer.addField(field);
answer.addMethod(getGetter(field));
field = new Field();
//$NON-NLS-1$
field.setName("typeHandler");
field.setType(FullyQualifiedJavaType.getStringInstance());
field.setVisibility(JavaVisibility.PRIVATE);
answer.addField(field);
answer.addMethod(getGetter(field));
method = new Method();
method.setVisibility(JavaVisibility.PROTECTED);
//$NON-NLS-1$
method.setName("Criterion");
method.setConstructor(true);
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), //$NON-NLS-1$
"condition"));
//$NON-NLS-1$
method.addBodyLine("super();");
//$NON-NLS-1$
method.addBodyLine("this.condition = condition;");
//$NON-NLS-1$
method.addBodyLine("this.typeHandler = null;");
//$NON-NLS-1$
method.addBodyLine("this.noValue = true;");
answer.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PROTECTED);
//$NON-NLS-1$
method.setName("Criterion");
method.setConstructor(true);
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), //$NON-NLS-1$
"condition"));
method.addParameter(new Parameter(FullyQualifiedJavaType.getObjectInstance(), //$NON-NLS-1$
"value"));
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), //$NON-NLS-1$
"typeHandler"));
//$NON-NLS-1$
method.addBodyLine("super();");
//$NON-NLS-1$
method.addBodyLine("this.condition = condition;");
//$NON-NLS-1$
method.addBodyLine("this.value = value;");
//$NON-NLS-1$
method.addBodyLine("this.typeHandler = typeHandler;");
//$NON-NLS-1$
method.addBodyLine("if (value instanceof List<?>) {");
//$NON-NLS-1$
method.addBodyLine("this.listValue = true;");
//$NON-NLS-1$
method.addBodyLine("} else {");
//$NON-NLS-1$
method.addBodyLine("this.singleValue = true;");
//$NON-NLS-1$
method.addBodyLine("}");
answer.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PROTECTED);
//$NON-NLS-1$
method.setName("Criterion");
method.setConstructor(true);
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), //$NON-NLS-1$
"condition"));
method.addParameter(new Parameter(FullyQualifiedJavaType.getObjectInstance(), //$NON-NLS-1$
"value"));
//$NON-NLS-1$
method.addBodyLine("this(condition, value, null);");
answer.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PROTECTED);
//$NON-NLS-1$
method.setName("Criterion");
method.setConstructor(true);
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), //$NON-NLS-1$
"condition"));
method.addParameter(new Parameter(FullyQualifiedJavaType.getObjectInstance(), //$NON-NLS-1$
"value"));
method.addParameter(new Parameter(FullyQualifiedJavaType.getObjectInstance(), //$NON-NLS-1$
"secondValue"));
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), //$NON-NLS-1$
"typeHandler"));
//$NON-NLS-1$
method.addBodyLine("super();");
//$NON-NLS-1$
method.addBodyLine("this.condition = condition;");
//$NON-NLS-1$
method.addBodyLine("this.value = value;");
//$NON-NLS-1$
method.addBodyLine("this.secondValue = secondValue;");
//$NON-NLS-1$
method.addBodyLine("this.typeHandler = typeHandler;");
//$NON-NLS-1$
method.addBodyLine("this.betweenValue = true;");
answer.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PROTECTED);
//$NON-NLS-1$
method.setName("Criterion");
method.setConstructor(true);
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), //$NON-NLS-1$
"condition"));
method.addParameter(new Parameter(FullyQualifiedJavaType.getObjectInstance(), //$NON-NLS-1$
"value"));
method.addParameter(new Parameter(FullyQualifiedJavaType.getObjectInstance(), //$NON-NLS-1$
"secondValue"));
//$NON-NLS-1$
method.addBodyLine("this(condition, value, secondValue, null);");
answer.addMethod(method);
return answer;
}
use of org.mybatis.generator.api.dom.java.Field in project generator by mybatis.
the class ToStringPlugin method generateToString.
private void generateToString(IntrospectedTable introspectedTable, TopLevelClass topLevelClass) {
Method method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(FullyQualifiedJavaType.getStringInstance());
//$NON-NLS-1$
method.setName("toString");
if (introspectedTable.isJava5Targeted()) {
//$NON-NLS-1$
method.addAnnotation("@Override");
}
context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
//$NON-NLS-1$
method.addBodyLine("StringBuilder sb = new StringBuilder();");
//$NON-NLS-1$
method.addBodyLine("sb.append(getClass().getSimpleName());");
//$NON-NLS-1$
method.addBodyLine("sb.append(\" [\");");
//$NON-NLS-1$
method.addBodyLine("sb.append(\"Hash = \").append(hashCode());");
StringBuilder sb = new StringBuilder();
for (Field field : topLevelClass.getFields()) {
String property = field.getName();
sb.setLength(0);
//$NON-NLS-1$ //$NON-NLS-2$
sb.append("sb.append(\"").append(", ").append(property).append("=\")").append(".append(").append(//$NON-NLS-1$ //$NON-NLS-2$
property).append(//$NON-NLS-1$
");");
method.addBodyLine(sb.toString());
}
//$NON-NLS-1$
method.addBodyLine("sb.append(\"]\");");
if (useToStringFromRoot && topLevelClass.getSuperClass() != null) {
//$NON-NLS-1$
method.addBodyLine("sb.append(\", from super class \");");
//$NON-NLS-1$
method.addBodyLine("sb.append(super.toString());");
}
//$NON-NLS-1$
method.addBodyLine("return sb.toString();");
topLevelClass.addMethod(method);
}
use of org.mybatis.generator.api.dom.java.Field in project generator by mybatis.
the class JavaBeansUtil method getJavaBeansField.
/**
* Gets the java beans field.
*
* @param introspectedColumn
* the introspected column
* @param context
* the context
* @param introspectedTable
* the introspected table
* @return the java beans field
*/
public static Field getJavaBeansField(IntrospectedColumn introspectedColumn, Context context, IntrospectedTable introspectedTable) {
FullyQualifiedJavaType fqjt = introspectedColumn.getFullyQualifiedJavaType();
String property = introspectedColumn.getJavaProperty();
Field field = new Field();
field.setVisibility(JavaVisibility.PRIVATE);
field.setType(fqjt);
field.setName(property);
context.getCommentGenerator().addFieldComment(field, introspectedTable, introspectedColumn);
return field;
}
Aggregations