use of org.mybatis.generator.api.dom.java.Parameter in project generator by mybatis.
the class ProviderInsertSelectiveMethodGenerator method addClassElements.
@Override
public void addClassElements(TopLevelClass topLevelClass) {
Set<String> staticImports = new TreeSet<String>();
Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
if (useLegacyBuilder) {
//$NON-NLS-1$
staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.BEGIN");
//$NON-NLS-1$
staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.INSERT_INTO");
//$NON-NLS-1$
staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SQL");
//$NON-NLS-1$
staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.VALUES");
} else {
importedTypes.add(NEW_BUILDER_IMPORT);
}
FullyQualifiedJavaType fqjt = introspectedTable.getRules().calculateAllFieldsClass();
importedTypes.add(fqjt);
Method method = new Method(introspectedTable.getInsertSelectiveStatementId());
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(FullyQualifiedJavaType.getStringInstance());
//$NON-NLS-1$
method.addParameter(new Parameter(fqjt, "record"));
context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
if (useLegacyBuilder) {
//$NON-NLS-1$
method.addBodyLine("BEGIN();");
} else {
//$NON-NLS-1$
method.addBodyLine("SQL sql = new SQL();");
}
method.addBodyLine(//$NON-NLS-1$
String.format(//$NON-NLS-1$
"%sINSERT_INTO(\"%s\");", builderPrefix, escapeStringForJava(introspectedTable.getFullyQualifiedTableNameAtRuntime())));
for (IntrospectedColumn introspectedColumn : ListUtilities.removeIdentityAndGeneratedAlwaysColumns(introspectedTable.getAllColumns())) {
//$NON-NLS-1$
method.addBodyLine("");
if (!introspectedColumn.getFullyQualifiedJavaType().isPrimitive() && !introspectedColumn.isSequenceColumn()) {
method.addBodyLine(//$NON-NLS-1$
String.format(//$NON-NLS-1$
"if (record.%s() != null) {", getGetterMethodName(introspectedColumn.getJavaProperty(), introspectedColumn.getFullyQualifiedJavaType())));
}
method.addBodyLine(//$NON-NLS-1$
String.format(//$NON-NLS-1$
"%sVALUES(\"%s\", \"%s\");", builderPrefix, escapeStringForJava(getEscapedColumnName(introspectedColumn)), getParameterClause(introspectedColumn)));
if (!introspectedColumn.getFullyQualifiedJavaType().isPrimitive() && !introspectedColumn.isSequenceColumn()) {
//$NON-NLS-1$
method.addBodyLine("}");
}
}
//$NON-NLS-1$
method.addBodyLine("");
if (useLegacyBuilder) {
//$NON-NLS-1$
method.addBodyLine("return SQL();");
} else {
//$NON-NLS-1$
method.addBodyLine("return sql.toString();");
}
if (context.getPlugins().providerInsertSelectiveMethodGenerated(method, topLevelClass, introspectedTable)) {
topLevelClass.addStaticImports(staticImports);
topLevelClass.addImportedTypes(importedTypes);
topLevelClass.addMethod(method);
}
}
use of org.mybatis.generator.api.dom.java.Parameter in project generator by mybatis.
the class RecordWithBLOBsGenerator method addParameterizedConstructor.
private void addParameterizedConstructor(TopLevelClass topLevelClass) {
Method method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setConstructor(true);
method.setName(topLevelClass.getType().getShortName());
context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
for (IntrospectedColumn introspectedColumn : introspectedTable.getAllColumns()) {
method.addParameter(new Parameter(introspectedColumn.getFullyQualifiedJavaType(), introspectedColumn.getJavaProperty()));
topLevelClass.addImportedType(introspectedColumn.getFullyQualifiedJavaType());
}
boolean comma = false;
StringBuilder sb = new StringBuilder();
//$NON-NLS-1$
sb.append("super(");
for (IntrospectedColumn introspectedColumn : introspectedTable.getNonBLOBColumns()) {
if (comma) {
//$NON-NLS-1$
sb.append(", ");
} else {
comma = true;
}
sb.append(introspectedColumn.getJavaProperty());
}
//$NON-NLS-1$
sb.append(");");
method.addBodyLine(sb.toString());
for (IntrospectedColumn introspectedColumn : introspectedTable.getBLOBColumns()) {
sb.setLength(0);
//$NON-NLS-1$
sb.append("this.");
sb.append(introspectedColumn.getJavaProperty());
//$NON-NLS-1$
sb.append(" = ");
sb.append(introspectedColumn.getJavaProperty());
sb.append(';');
method.addBodyLine(sb.toString());
}
topLevelClass.addMethod(method);
}
use of org.mybatis.generator.api.dom.java.Parameter in project generator by mybatis.
the class SimpleModelGenerator method addParameterizedConstructor.
private void addParameterizedConstructor(TopLevelClass topLevelClass) {
Method method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setConstructor(true);
method.setName(topLevelClass.getType().getShortName());
context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
List<IntrospectedColumn> constructorColumns = introspectedTable.getAllColumns();
for (IntrospectedColumn introspectedColumn : constructorColumns) {
method.addParameter(new Parameter(introspectedColumn.getFullyQualifiedJavaType(), introspectedColumn.getJavaProperty()));
}
StringBuilder sb = new StringBuilder();
if (introspectedTable.getRules().generatePrimaryKeyClass()) {
boolean comma = false;
//$NON-NLS-1$
sb.append("super(");
for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
if (comma) {
//$NON-NLS-1$
sb.append(", ");
} else {
comma = true;
}
sb.append(introspectedColumn.getJavaProperty());
}
//$NON-NLS-1$
sb.append(");");
method.addBodyLine(sb.toString());
}
List<IntrospectedColumn> introspectedColumns = introspectedTable.getAllColumns();
for (IntrospectedColumn introspectedColumn : introspectedColumns) {
sb.setLength(0);
//$NON-NLS-1$
sb.append("this.");
sb.append(introspectedColumn.getJavaProperty());
//$NON-NLS-1$
sb.append(" = ");
sb.append(introspectedColumn.getJavaProperty());
sb.append(';');
method.addBodyLine(sb.toString());
}
topLevelClass.addMethod(method);
}
use of org.mybatis.generator.api.dom.java.Parameter in project generator by mybatis.
the class CountByExampleMethodGenerator method addInterfaceElements.
@Override
public void addInterfaceElements(Interface interfaze) {
FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(introspectedTable.getExampleType());
Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
importedTypes.add(fqjt);
Method method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
//$NON-NLS-1$
method.setReturnType(new FullyQualifiedJavaType("long"));
method.setName(introspectedTable.getCountByExampleStatementId());
//$NON-NLS-1$
method.addParameter(new Parameter(fqjt, "example"));
context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
addMapperAnnotations(method);
if (context.getPlugins().clientCountByExampleMethodGenerated(method, interfaze, introspectedTable)) {
addExtraImports(interfaze);
interfaze.addImportedTypes(importedTypes);
interfaze.addMethod(method);
}
}
use of org.mybatis.generator.api.dom.java.Parameter in project generator by mybatis.
the class DeleteByExampleMethodGenerator method addInterfaceElements.
@Override
public void addInterfaceElements(Interface interfaze) {
Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getExampleType());
importedTypes.add(type);
Method method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(FullyQualifiedJavaType.getIntInstance());
method.setName(introspectedTable.getDeleteByExampleStatementId());
//$NON-NLS-1$
method.addParameter(new Parameter(type, "example"));
context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
addMapperAnnotations(method);
if (context.getPlugins().clientDeleteByExampleMethodGenerated(method, interfaze, introspectedTable)) {
addExtraImports(interfaze);
interfaze.addImportedTypes(importedTypes);
interfaze.addMethod(method);
}
}
Aggregations