Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge pull request #1 from zhengganglee/lombok-plugin-support #293

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ public void generate() throws Exception {
pluginConfiguration.setConfigurationType("com.softwareloop.mybatis.generator.plugins.LombokPlugin");
context.addPluginConfiguration(pluginConfiguration);
}


// toString, hashCode, equals插件
else if (generatorConfig.isNeedToStringHashcodeEquals()) {
PluginConfiguration pluginConfiguration1 = new PluginConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.*;
import org.mybatis.generator.api.dom.xml.XmlElement;
import org.mybatis.generator.internal.util.StringUtility;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Properties;
import java.util.Set;

Expand All @@ -40,31 +41,33 @@ public class DbRemarksCommentGenerator implements CommentGenerator {
private Properties properties;
private boolean columnRemarks;
private boolean isAnnotations;
private SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

public DbRemarksCommentGenerator() {
super();
properties = new Properties();
}


@Override
public void addJavaFileComment(CompilationUnit compilationUnit) {
// add no file level comments by default
if (isAnnotations) {
compilationUnit.addImportedType(new FullyQualifiedJavaType("javax.persistence.Table"));
compilationUnit.addImportedType(new FullyQualifiedJavaType("javax.persistence.Id"));
compilationUnit.addImportedType(new FullyQualifiedJavaType("javax.persistence.Column"));
compilationUnit.addImportedType(new FullyQualifiedJavaType("javax.persistence.GeneratedValue"));
compilationUnit.addImportedType(new FullyQualifiedJavaType("javax.persistence.*"));
compilationUnit.addImportedType(new FullyQualifiedJavaType("org.hibernate.validator.constraints.NotEmpty"));
}
compilationUnit.addImportedType(new FullyQualifiedJavaType("io.swagger.annotations.ApiModelProperty"));
}

/**
* Adds a suitable comment to warn users that the element was generated, and
* when it was generated.
*/
@Override
public void addComment(XmlElement xmlElement) {
}

@Override
public void addRootComment(XmlElement rootElement) {
// add no document level comments by default
return;
Expand Down Expand Up @@ -96,58 +99,67 @@ public void addClassAnnotation(InnerClass innerClass, IntrospectedTable introspe

}

public void addConfigurationProperties(Properties properties) {
@Override
public void addConfigurationProperties(Properties properties) {
this.properties.putAll(properties);
columnRemarks = isTrue(properties
.getProperty("columnRemarks"));
isAnnotations = isTrue(properties
.getProperty("annotations"));
}

@Override
public void addClassComment(InnerClass innerClass,
IntrospectedTable introspectedTable) {
IntrospectedTable introspectedTable) {
}

@Override
public void addModelClassComment(TopLevelClass topLevelClass,
IntrospectedTable introspectedTable) {
IntrospectedTable introspectedTable) {

topLevelClass.addJavaDocLine("/**");
topLevelClass.addJavaDocLine(" * " + introspectedTable.getFullyQualifiedTable().getIntrospectedTableName());
topLevelClass.addJavaDocLine(" * @author ");
topLevelClass.addJavaDocLine(" * @Description : ");
topLevelClass.addJavaDocLine(" * @Author : ChenChunlei ");
topLevelClass.addJavaDocLine(" * @Date : "+dateFormat.format(Calendar.getInstance().getTime()));
topLevelClass.addJavaDocLine(" */");
if(isAnnotations) {
topLevelClass.addAnnotation("@Table(name=\"" + introspectedTable.getFullyQualifiedTableNameAtRuntime() + "\")");
}
}

@Override
public void addEnumComment(InnerEnum innerEnum,
IntrospectedTable introspectedTable) {
IntrospectedTable introspectedTable) {
}

@Override
public void addFieldComment(Field field,
IntrospectedTable introspectedTable,
IntrospectedColumn introspectedColumn) {
if (StringUtility.stringHasValue(introspectedColumn.getRemarks())) {
field.addJavaDocLine("/**");
StringBuilder sb = new StringBuilder();
sb.append(" * ");
sb.append(introspectedColumn.getRemarks());
field.addJavaDocLine(sb.toString());
field.addJavaDocLine(" */");
}
IntrospectedTable introspectedTable,
IntrospectedColumn introspectedColumn) {
// if (StringUtility.stringHasValue(introspectedColumn.getRemarks())) {
// field.addJavaDocLine("/**");
// StringBuilder sb = new StringBuilder();
// sb.append(" * ");
// sb.append(introspectedColumn.getRemarks());
// field.addJavaDocLine(sb.toString());
// field.addJavaDocLine(" */");
// }
field.addJavaDocLine("@ApiModelProperty(value=\""+introspectedColumn.getRemarks()+"\")");

if (isAnnotations) {
boolean isId = false;
for (IntrospectedColumn column : introspectedTable.getPrimaryKeyColumns()) {
if (introspectedColumn == column) {
isId = true;
field.addAnnotation("@Id");
field.addAnnotation("@GeneratedValue");
break;
}
}
if (!introspectedColumn.isNullable() && !isId){
field.addAnnotation("@NotEmpty");
}
// boolean isId = false;
// for (IntrospectedColumn column : introspectedTable.getPrimaryKeyColumns()) {
// if (introspectedColumn == column) {
//// isId = true;
// field.addAnnotation("@Id");
//// field.addAnnotation("@GeneratedValue");
// break;
// }
// }
// if (!introspectedColumn.isNullable() && !isId){
// field.addAnnotation("@NotEmpty");
// }
if (introspectedColumn.isIdentity()) {
if (introspectedTable.getTableConfiguration().getGeneratedKey().getRuntimeSqlStatement().equals("JDBC")) {
field.addAnnotation("@GeneratedValue(generator = \"JDBC\")");
Expand All @@ -160,25 +172,30 @@ public void addFieldComment(Field field,
}
}

@Override
public void addFieldComment(Field field, IntrospectedTable introspectedTable) {
}

@Override
public void addGeneralMethodComment(Method method,
IntrospectedTable introspectedTable) {
IntrospectedTable introspectedTable) {
}

@Override
public void addGetterComment(Method method,
IntrospectedTable introspectedTable,
IntrospectedColumn introspectedColumn) {
IntrospectedTable introspectedTable,
IntrospectedColumn introspectedColumn) {
}

@Override
public void addSetterComment(Method method,
IntrospectedTable introspectedTable,
IntrospectedColumn introspectedColumn) {
IntrospectedTable introspectedTable,
IntrospectedColumn introspectedColumn) {
}

@Override
public void addClassComment(InnerClass innerClass,
IntrospectedTable introspectedTable, boolean markAsDoNotDelete) {
IntrospectedTable introspectedTable, boolean markAsDoNotDelete) {
innerClass.addJavaDocLine("/**"); //$NON-NLS-1$
innerClass.addJavaDocLine(" */"); //$NON-NLS-1$
}
Expand Down