Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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 @@ -150,7 +150,7 @@ public String getSelectByPrimaryKeyQueryId() {
return tableConfiguration.getSelectByPrimaryKeyQueryId();
}

public GeneratedKey getGeneratedKey() {
public Optional<GeneratedKey> getGeneratedKey() {
return tableConfiguration.getGeneratedKey();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
*/
public class MyBatisGenerator {

private static final ProgressCallback NULL_PROGRESS_CALLBACK = new ProgressCallback() {};

private final Configuration configuration;

private final ShellCallback shellCallback;
Expand Down Expand Up @@ -211,7 +213,7 @@ public void generate(ProgressCallback callback, Set<String> contextIds,
IOException, InterruptedException {

if (callback == null) {
callback = new ProgressCallback() {};
callback = NULL_PROGRESS_CALLBACK;
}

generatedJavaFiles.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public String getProject() {
}

public static Method getGetter(Field field) {
Method method = new Method(getGetterMethodName(field.getName(), field
.getType()));
Method method = new Method(getGetterMethodName(field.getName(), field.getType()));
method.setReturnType(field.getType());
method.setVisibility(JavaVisibility.PUBLIC);
String s = "return " + field.getName() + ';'; //$NON-NLS-1$
Expand All @@ -52,11 +51,9 @@ public static Method getGetter(Field field) {
}

public String getRootClass() {
String rootClass = introspectedTable
.getTableConfigurationProperty(PropertyRegistry.ANY_ROOT_CLASS);
String rootClass = introspectedTable.getTableConfigurationProperty(PropertyRegistry.ANY_ROOT_CLASS);
if (rootClass == null) {
Properties properties = context
.getJavaModelGeneratorConfiguration().getProperties();
Properties properties = context.getJavaModelGeneratorConfiguration().getProperties();
rootClass = properties.getProperty(PropertyRegistry.ANY_ROOT_CLASS);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2020 the original author or authors.
* Copyright 2006-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,8 +42,7 @@ public class RootClassInfo {
rootClassInfoMap = Collections.synchronizedMap(new HashMap<>());
}

public static RootClassInfo getInstance(String className,
List<String> warnings) {
public static RootClassInfo getInstance(String className, List<String> warnings) {
return rootClassInfoMap.computeIfAbsent(className, k -> new RootClassInfo(k, warnings));
}

Expand Down Expand Up @@ -125,11 +124,9 @@ private boolean isProperType(String propertyName, String propertyType, PropertyD
String introspectedPropertyType = propertyDescriptor.getPropertyType().getName();
if (genericMode && introspectedPropertyType.equals("java.lang.Object")) { //$NON-NLS-1$
// OK - but add a warning
warnings.add(getString("Warning.28", //$NON-NLS-1$
propertyName, className));
warnings.add(getString("Warning.28", propertyName, className)); //$NON-NLS-1$
} else if (!introspectedPropertyType.equals(propertyType)) {
warnings.add(getString("Warning.21", //$NON-NLS-1$
propertyName, className, propertyType));
warnings.add(getString("Warning.21", propertyName, className, propertyType)); //$NON-NLS-1$
return false;
}

Expand All @@ -138,8 +135,7 @@ private boolean isProperType(String propertyName, String propertyType, PropertyD

private boolean hasGetter(String propertyName, PropertyDescriptor propertyDescriptor) {
if (propertyDescriptor.getReadMethod() == null) {
warnings.add(getString("Warning.22", //$NON-NLS-1$
propertyName, className));
warnings.add(getString("Warning.22", propertyName, className)); //$NON-NLS-1$
return false;
}

Expand All @@ -148,8 +144,7 @@ private boolean hasGetter(String propertyName, PropertyDescriptor propertyDescri

private boolean hasSetter(String propertyName, PropertyDescriptor propertyDescriptor) {
if (propertyDescriptor.getWriteMethod() == null) {
warnings.add(getString("Warning.23", //$NON-NLS-1$
propertyName, className));
warnings.add(getString("Warning.23", propertyName, className)); //$NON-NLS-1$
return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2020 the original author or authors.
* Copyright 2006-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -121,8 +121,7 @@ protected AbstractJavaClientGenerator createJavaClientGenerator() {
} else if ("MAPPER".equalsIgnoreCase(type)) { //$NON-NLS-1$
javaGenerator = new JavaMapperGenerator(getClientProject());
} else {
javaGenerator = (AbstractJavaClientGenerator) ObjectFactory
.createInternalObject(type);
javaGenerator = (AbstractJavaClientGenerator) ObjectFactory.createInternalObject(type);
}

return javaGenerator;
Expand All @@ -132,36 +131,31 @@ protected void calculateJavaModelGenerators(List<String> warnings,
ProgressCallback progressCallback) {
if (getRules().generateExampleClass()) {
AbstractJavaGenerator javaGenerator = new ExampleGenerator(getExampleProject());
initializeAbstractGenerator(javaGenerator, warnings,
progressCallback);
initializeAbstractGenerator(javaGenerator, warnings, progressCallback);
javaGenerators.add(javaGenerator);
}

if (getRules().generatePrimaryKeyClass()) {
AbstractJavaGenerator javaGenerator = new PrimaryKeyGenerator(getModelProject());
initializeAbstractGenerator(javaGenerator, warnings,
progressCallback);
initializeAbstractGenerator(javaGenerator, warnings, progressCallback);
javaGenerators.add(javaGenerator);
}

if (getRules().generateBaseRecordClass()) {
AbstractJavaGenerator javaGenerator = new BaseRecordGenerator(getModelProject());
initializeAbstractGenerator(javaGenerator, warnings,
progressCallback);
initializeAbstractGenerator(javaGenerator, warnings, progressCallback);
javaGenerators.add(javaGenerator);
}

if (getRules().generateRecordWithBLOBsClass()) {
AbstractJavaGenerator javaGenerator = new RecordWithBLOBsGenerator(getModelProject());
initializeAbstractGenerator(javaGenerator, warnings,
progressCallback);
initializeAbstractGenerator(javaGenerator, warnings, progressCallback);
javaGenerators.add(javaGenerator);
}
}

protected void initializeAbstractGenerator(
AbstractGenerator abstractGenerator, List<String> warnings,
ProgressCallback progressCallback) {
protected void initializeAbstractGenerator(AbstractGenerator abstractGenerator, List<String> warnings,
ProgressCallback progressCallback) {
if (abstractGenerator == null) {
return;
}
Expand All @@ -177,8 +171,7 @@ public List<GeneratedJavaFile> getGeneratedJavaFiles() {
List<GeneratedJavaFile> answer = new ArrayList<>();

for (AbstractJavaGenerator javaGenerator : javaGenerators) {
List<CompilationUnit> compilationUnits = javaGenerator
.getCompilationUnits();
List<CompilationUnit> compilationUnits = javaGenerator.getCompilationUnits();
for (CompilationUnit compilationUnit : compilationUnits) {
GeneratedJavaFile gjf = new GeneratedJavaFile(compilationUnit,
javaGenerator.getProject(),
Expand Down Expand Up @@ -248,14 +241,12 @@ public List<GeneratedXmlFile> getGeneratedXmlFiles() {

@Override
public int getGenerationSteps() {
return javaGenerators.size()
+ (xmlMapperGenerator == null ? 0 : 1);
return javaGenerators.size() + (xmlMapperGenerator == null ? 0 : 1);
}

@Override
public boolean requiresXMLGenerator() {
AbstractJavaClientGenerator javaClientGenerator =
createJavaClientGenerator();
AbstractJavaClientGenerator javaClientGenerator = createJavaClientGenerator();

if (javaClientGenerator == null) {
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2020 the original author or authors.
* Copyright 2006-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -50,8 +50,7 @@ protected void calculateXmlMapperGenerator(AbstractJavaClientGenerator javaClien
xmlMapperGenerator = javaClientGenerator.getMatchedXMLGenerator();
}

initializeAbstractGenerator(xmlMapperGenerator, warnings,
progressCallback);
initializeAbstractGenerator(xmlMapperGenerator, warnings, progressCallback);
}

@Override
Expand All @@ -60,8 +59,7 @@ protected AbstractJavaClientGenerator createJavaClientGenerator() {
return null;
}

String type = context.getJavaClientGeneratorConfiguration()
.getConfigurationType();
String type = context.getJavaClientGeneratorConfiguration().getConfigurationType();

AbstractJavaClientGenerator javaGenerator;
if ("XMLMAPPER".equalsIgnoreCase(type)) { //$NON-NLS-1$
Expand All @@ -71,20 +69,17 @@ protected AbstractJavaClientGenerator createJavaClientGenerator() {
} else if ("MAPPER".equalsIgnoreCase(type)) { //$NON-NLS-1$
javaGenerator = new SimpleJavaClientGenerator(getClientProject());
} else {
javaGenerator = (AbstractJavaClientGenerator) ObjectFactory
.createInternalObject(type);
javaGenerator = (AbstractJavaClientGenerator) ObjectFactory.createInternalObject(type);
}

return javaGenerator;
}

@Override
protected void calculateJavaModelGenerators(List<String> warnings,
ProgressCallback progressCallback) {
protected void calculateJavaModelGenerators(List<String> warnings, ProgressCallback progressCallback) {

AbstractJavaGenerator javaGenerator = new SimpleModelGenerator(getModelProject());
initializeAbstractGenerator(javaGenerator, warnings,
progressCallback);
initializeAbstractGenerator(javaGenerator, warnings, progressCallback);
javaGenerators.add(javaGenerator);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ private MyBatis3FormattingUtilities() {
super();
}

public static String getParameterClause(
IntrospectedColumn introspectedColumn) {
public static String getParameterClause(IntrospectedColumn introspectedColumn) {
return getParameterClause(introspectedColumn, null);
}

public static String getParameterClause(
IntrospectedColumn introspectedColumn, String prefix) {
public static String getParameterClause(IntrospectedColumn introspectedColumn, String prefix) {
StringBuilder sb = new StringBuilder();

sb.append("#{"); //$NON-NLS-1$
Expand All @@ -58,16 +56,14 @@ public static String getParameterClause(
* the introspected column
* @return the proper phrase
*/
public static String getSelectListPhrase(
IntrospectedColumn introspectedColumn) {
public static String getSelectListPhrase(IntrospectedColumn introspectedColumn) {
if (stringHasValue(introspectedColumn.getTableAlias())) {
StringBuilder sb = new StringBuilder();

sb.append(getAliasedEscapedColumnName(introspectedColumn));
sb.append(" as "); //$NON-NLS-1$
if (introspectedColumn.isColumnNameDelimited()) {
sb.append(introspectedColumn.getContext()
.getBeginningDelimiter());
sb.append(introspectedColumn.getContext().getBeginningDelimiter());
}
sb.append(introspectedColumn.getTableAlias());
sb.append('_');
Expand All @@ -81,25 +77,21 @@ public static String getSelectListPhrase(
}
}

public static String getEscapedColumnName(
IntrospectedColumn introspectedColumn) {
public static String getEscapedColumnName(IntrospectedColumn introspectedColumn) {
StringBuilder sb = new StringBuilder();
sb.append(introspectedColumn.getActualColumnName());

if (introspectedColumn.isColumnNameDelimited()) {
sb.insert(0, introspectedColumn.getContext()
.getBeginningDelimiter());
sb.insert(0, introspectedColumn.getContext().getBeginningDelimiter());
sb.append(introspectedColumn.getContext().getEndingDelimiter());
}

return sb.toString();
}

public static String getAliasedEscapedColumnName(
IntrospectedColumn introspectedColumn) {
public static String getAliasedEscapedColumnName(IntrospectedColumn introspectedColumn) {
if (stringHasValue(introspectedColumn.getTableAlias())) {
return introspectedColumn.getTableAlias() + '.'
+ getEscapedColumnName(introspectedColumn);
return introspectedColumn.getTableAlias() + '.' + getEscapedColumnName(introspectedColumn);
} else {
return getEscapedColumnName(introspectedColumn);
}
Expand All @@ -117,24 +109,21 @@ public static String getAliasedEscapedColumnName(
* the introspected column
* @return the aliased column name
*/
public static String getAliasedActualColumnName(
IntrospectedColumn introspectedColumn) {
public static String getAliasedActualColumnName(IntrospectedColumn introspectedColumn) {
StringBuilder sb = new StringBuilder();
if (stringHasValue(introspectedColumn.getTableAlias())) {
sb.append(introspectedColumn.getTableAlias());
sb.append('.');
}

if (introspectedColumn.isColumnNameDelimited()) {
sb.append(escapeStringForJava(introspectedColumn
.getContext().getBeginningDelimiter()));
sb.append(escapeStringForJava(introspectedColumn.getContext().getBeginningDelimiter()));
}

sb.append(introspectedColumn.getActualColumnName());

if (introspectedColumn.isColumnNameDelimited()) {
sb.append(escapeStringForJava(introspectedColumn
.getContext().getEndingDelimiter()));
sb.append(escapeStringForJava(introspectedColumn.getContext().getEndingDelimiter()));
}

return sb.toString();
Expand All @@ -148,8 +137,7 @@ public static String getAliasedActualColumnName(
* the introspected column
* @return the renamed column name
*/
public static String getRenamedColumnNameForResultMap(
IntrospectedColumn introspectedColumn) {
public static String getRenamedColumnNameForResultMap(IntrospectedColumn introspectedColumn) {
if (stringHasValue(introspectedColumn.getTableAlias())) {
return introspectedColumn.getTableAlias() + '_' + introspectedColumn.getActualColumnName();
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2020 the original author or authors.
* Copyright 2006-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -63,22 +63,19 @@ public List<CompilationUnit> getCompilationUnits() {
introspectedTable.getFullyQualifiedTable().toString()));
CommentGenerator commentGenerator = context.getCommentGenerator();

FullyQualifiedJavaType type = new FullyQualifiedJavaType(
introspectedTable.getMyBatis3JavaMapperType());
FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getMyBatis3JavaMapperType());
Interface interfaze = new Interface(type);
interfaze.setVisibility(JavaVisibility.PUBLIC);
commentGenerator.addJavaFileComment(interfaze);

String rootInterface = introspectedTable
.getTableConfigurationProperty(PropertyRegistry.ANY_ROOT_INTERFACE);
String rootInterface = introspectedTable.getTableConfigurationProperty(PropertyRegistry.ANY_ROOT_INTERFACE);
if (!stringHasValue(rootInterface)) {
rootInterface = context.getJavaClientGeneratorConfiguration()
.getProperty(PropertyRegistry.ANY_ROOT_INTERFACE);
}

if (stringHasValue(rootInterface)) {
FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(
rootInterface);
FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(rootInterface);
interfaze.addSuperInterface(fqjt);
interfaze.addImportedType(fqjt);
}
Expand Down Expand Up @@ -210,9 +207,8 @@ protected void addUpdateByPrimaryKeyWithoutBLOBsMethod(Interface interfaze) {
}
}

protected void initializeAndExecuteGenerator(
AbstractJavaMapperMethodGenerator methodGenerator,
Interface interfaze) {
protected void initializeAndExecuteGenerator(AbstractJavaMapperMethodGenerator methodGenerator,
Interface interfaze) {
methodGenerator.setContext(context);
methodGenerator.setIntrospectedTable(introspectedTable);
methodGenerator.setProgressCallback(progressCallback);
Expand Down
Loading