Skip to content

Commit

Permalink
Uppercase the domain object name after applying the renaming rule
Browse files Browse the repository at this point in the history
  • Loading branch information
yidongnan committed Jul 22, 2018
1 parent 3a55601 commit 7623bef
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.mybatis.generator.internal.util.HashCodeUtil.SEED;
import static org.mybatis.generator.internal.util.HashCodeUtil.hash;
import static org.mybatis.generator.internal.util.JavaBeansUtil.getCamelCaseString;
import static org.mybatis.generator.internal.util.JavaBeansUtil.getFirstCharacterUppercase;
import static org.mybatis.generator.internal.util.StringUtility.composeFullyQualifiedTableName;
import static org.mybatis.generator.internal.util.StringUtility.stringHasValue;

Expand Down Expand Up @@ -242,7 +243,7 @@ public String getDomainObjectName() {
String replaceString = domainObjectRenamingRule.getReplaceString();
replaceString = replaceString == null ? "" : replaceString; //$NON-NLS-1$
Matcher matcher = pattern.matcher(finalDomainObjectName);
finalDomainObjectName = getCamelCaseString(matcher.replaceAll(replaceString), true);
finalDomainObjectName = getFirstCharacterUppercase(matcher.replaceAll(replaceString));
}
return finalDomainObjectName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ public static String getSetterMethodName(String property) {
return sb.toString();
}

public static String getFirstCharacterUppercase(String inputString) {
StringBuilder sb = new StringBuilder(inputString);
sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
return sb.toString();
}

public static String getCamelCaseString(String inputString,
boolean firstCharacterUppercase) {
StringBuilder sb = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public class FullyQualifiedTableTest {
@Test
public void testNormalCase() {
FullyQualifiedTable fqt = new FullyQualifiedTable(null, "myschema", "mytable", null, null, false, null, null, null, false, null, null);

assertThat(fqt.getDomainObjectName()).isEqualTo("Mytable");
}

@Test
public void testNormalCaseWithPrefix() {
FullyQualifiedTable fqt = new FullyQualifiedTable(null, "myschema", "sys_mytable", null, null, false, null, null, null, false, null, null);

assertThat(fqt.getDomainObjectName()).isEqualTo("SysMytable");
}

Expand All @@ -42,17 +42,37 @@ public void testRenamingRule() {
renamingRule.setSearchString("^Sys");
renamingRule.setReplaceString("");
FullyQualifiedTable fqt = new FullyQualifiedTable(null, "myschema", "sys_mytable", null, null, false, null, null, null, false, renamingRule, null);

assertThat(fqt.getDomainObjectName()).isEqualTo("Mytable");
}

@Test
public void testRenamingRule2() {
DomainObjectRenamingRule renamingRule = new DomainObjectRenamingRule();
renamingRule.setSearchString("^Sys");
renamingRule.setReplaceString("");
FullyQualifiedTable fqt = new FullyQualifiedTable(null, "myschema", "sys_my_table", null, null, false, null, null, null, false, renamingRule, null);

assertThat(fqt.getDomainObjectName()).isEqualTo("MyTable");
}

@Test
public void testRenamingRuleNoUnderscore() {
DomainObjectRenamingRule renamingRule = new DomainObjectRenamingRule();
renamingRule.setSearchString("^Sys");
renamingRule.setReplaceString("");
FullyQualifiedTable fqt = new FullyQualifiedTable(null, "myschema", "sysmytable", null, null, false, null, null, null, false, renamingRule, null);

assertThat(fqt.getDomainObjectName()).isEqualTo("Mytable");
}

@Test
public void testRenamingRuleNoUnderscore2() {
DomainObjectRenamingRule renamingRule = new DomainObjectRenamingRule();
renamingRule.setSearchString("^Sys");
renamingRule.setReplaceString("");
FullyQualifiedTable fqt = new FullyQualifiedTable(null, "myschema", "sysmy_table", null, null, false, null, null, null, false, renamingRule, null);

assertThat(fqt.getDomainObjectName()).isEqualTo("MyTable");
}
}

0 comments on commit 7623bef

Please sign in to comment.