FullyQualifiedJavaType types = new FullyQualifiedJavaType("java.util.Map<java.lang.String, java.lang.Object>");
Rules rules = introspectedTable.getRules();
if (rules.generateUpdateByExampleSelective() || rules.generateUpdateByExampleWithBLOBs()
|| rules.generateUpdateByExampleWithoutBLOBs()) {
Method method = new Method();
method.setVisibility(JavaVisibility.PROTECTED);
method.setConstructor(true);
method.setName(criteria.getShortName());
method.addParameter(new Parameter(criteria, "example")); //$NON-NLS-1$
method.addBodyLine("this.orderByClause = example.orderByClause;"); //$NON-NLS-1$
method.addBodyLine("this.condition = example.condition;"); //$NON-NLS-1$
method.addBodyLine("this.distinct = example.distinct;"); //$NON-NLS-1$
method.addBodyLine("this.limit = example.limit;"); //$NON-NLS-1$
method.addBodyLine("this.start = example.start;"); //$NON-NLS-1$
topLevelClass.addMethod(method);
}
Field field = new Field();
field.setVisibility(JavaVisibility.PRIVATE);
field.setType(types);
field.setName("condition"); //$NON-NLS-1$
addFieldComment(field, "存放条件查询值");
topLevelClass.addField(field);
// add field, getter, setter for distinct
field = new Field();
field.setVisibility(JavaVisibility.PROTECTED);
field.setType(FullyQualifiedJavaType.getBooleanPrimitiveInstance());
field.setName("distinct"); //$NON-NLS-1$
addFieldComment(field, "是否相异");
topLevelClass.addField(field);
// add field, getter, setter for orderby clause
field = new Field();
field.setVisibility(JavaVisibility.PROTECTED);
field.setType(FullyQualifiedJavaType.getStringInstance());
field.setName("orderByClause"); //$NON-NLS-1$
addFieldComment(field, "排序字段");
topLevelClass.addField(field);
Method method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setConstructor(true);
method.setName("Criteria"); //$NON-NLS-1$
method.addBodyLine("this.condition = new HashMap<String, Object>();"); //$NON-NLS-1$
topLevelClass.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setName("clear"); //$NON-NLS-1$
method.addBodyLine("this.condition.clear();"); //$NON-NLS-1$
method.addBodyLine("this.orderByClause = null;"); //$NON-NLS-1$
method.addBodyLine("this.distinct = false;"); //$NON-NLS-1$
method.addBodyLine("this.limit=null;"); //$NON-NLS-1$
method.addBodyLine("this.start=null;"); //$NON-NLS-1$
topLevelClass.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(criteria);
method.setName("put"); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "condition")); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getObjectInstance(), "value")); //$NON-NLS-1$
method.addBodyLine("this.condition.put(condition, value);"); //$NON-NLS-1$
method.addBodyLine("return (Criteria) this;"); //$NON-NLS-1$
addSetterComment(method, OutputUtilities.lineSeparator+"\t * 查询的条件名称"+OutputUtilities.lineSeparator+"\t * @param value"+OutputUtilities.lineSeparator+"\t * 查询的值", "condition");
topLevelClass.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setName("setOrderByClause"); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "orderByClause")); //$NON-NLS-1$
method.addBodyLine("this.orderByClause = orderByClause;"); //$NON-NLS-1$
addSetterComment(method, OutputUtilities.lineSeparator+"\t * 排序字段", "orderByClause");
topLevelClass.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setName("setDistinct"); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getBooleanPrimitiveInstance(), "distinct")); //$NON-NLS-1$
method.addBodyLine("this.distinct = distinct;"); //$NON-NLS-1$
addSetterComment(method, OutputUtilities.lineSeparator+"\t * 是否相异", "distinct");
topLevelClass.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setName("setCondition"); //$NON-NLS-1$
method.addParameter(new Parameter(types, "condition")); //$NON-NLS-1$
method.addBodyLine("this.condition = condition;"); //$NON-NLS-1$
topLevelClass.addMethod(method);
method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(types);
method.setName("getCondition"); //$NON-NLS-1$
method.addBodyLine("return condition;"); //$NON-NLS-1$
topLevelClass.addMethod(method);
field = new Field();
field.setVisibility(JavaVisibility.PRIVATE);
field.setType(FullyQualifiedJavaType.getInteger());
field.setName("limit"); //$NON-NLS-1$
addFieldComment(field, "每页大小,即mysql中的length");
topLevelClass.addField(field);
method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setName("setLimit"); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getInteger(), "limit")); //$NON-NLS-1$
method.addBodyLine("this.limit = limit;"); //$NON-NLS-1$
addSetterComment(method, OutputUtilities.lineSeparator+"\t * 每页大小,即mysql中的length", "limit");
topLevelClass.addMethod(method);
field = new Field();
field.setVisibility(JavaVisibility.PRIVATE);
field.setType(FullyQualifiedJavaType.getInteger());
field.setName("start"); //$NON-NLS-1$
addFieldComment(field, "开始行数,即mysql中的offset");
topLevelClass.addField(field);
method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setName("setStart"); //$NON-NLS-1$
method.addParameter(new Parameter(FullyQualifiedJavaType.getInteger(), "start")); //$NON-NLS-1$
method.addBodyLine("this.start = start;"); //$NON-NLS-1$
addSetterComment(method, OutputUtilities.lineSeparator+"\t * 开始行数,即mysql中的offset", "start");
topLevelClass.addMethod(method);
GeneratedJavaFile file = new GeneratedJavaFile(topLevelClass, context.getJavaModelGeneratorConfiguration()
.getTargetProject());