Skip to content

Commit

Permalink
[TOOLS-4565] Improved details information output in object mapping pa…
Browse files Browse the repository at this point in the history
…ge (#156)

http://jira.cubrid.org/browse/TOOLS-4565

- PK warning message is sort.
- Prevents warning messages related to column length from being output.
  • Loading branch information
hwany7seo committed Feb 28, 2024
1 parent 890621a commit 0d00f56
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,9 @@ private boolean validateConfig() {
setErrorMessage(null);
// Show confirm dialog.
StringBuffer detailMsg = new StringBuffer();
if (result.hasPKConfirm()) {
detailMsg.append(result.getPKConfirmMessage()).append("\r\n");
}
if (result.hasConfirm()) {
detailMsg.append(result.getConfirmMessage()).append("\r\n");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ public VerifyResultMessages checkAll(MigrationConfiguration config) {
try {
StringBuffer sbWarning = new StringBuffer();
StringBuffer sbConfirm = new StringBuffer();
StringBuffer pkConfirm = new StringBuffer();
if (!config.hasObjects2Export()) {
throw new MigrationConfigurationCheckingErrorException(
"There is no object to be migrated.");
Expand All @@ -231,16 +232,17 @@ public VerifyResultMessages checkAll(MigrationConfiguration config) {
result = checkCSVCfg(config);
} else {
result = checkEntryTableCfg(config);
mergeVerifyResults(sbWarning, sbConfirm, result);
mergeVerifyResults(sbWarning, sbConfirm, pkConfirm, result);
result = checkSQLTableCfg(config);
mergeVerifyResults(sbWarning, sbConfirm, result);
mergeVerifyResults(sbWarning, sbConfirm, pkConfirm, result);
result = checkViewCfg(config);
mergeVerifyResults(sbWarning, sbConfirm, result);
mergeVerifyResults(sbWarning, sbConfirm, pkConfirm, result);
result = checkSerialCfg(config);
mergeVerifyResults(sbWarning, sbConfirm, result);
mergeVerifyResults(sbWarning, sbConfirm, pkConfirm, result);
}
result.setWarningMessage(sbWarning.toString().trim());
result.setConfirmMessage(sbConfirm.toString().trim());
result.setPKConfirmMessage(pkConfirm.toString().trim());
return result;
} catch (MigrationConfigurationCheckingErrorException ex) {
return new VerifyResultMessages(ex.getMessage(), null, null);
Expand Down Expand Up @@ -316,6 +318,7 @@ protected VerifyResultMessages checkCSVCfg(MigrationConfiguration config) {
protected VerifyResultMessages checkEntryTableCfg(MigrationConfiguration config) {
StringBuffer sbWarning = new StringBuffer();
StringBuffer sbConfirm = new StringBuffer();
StringBuffer pkConfirm = new StringBuffer();
for (SourceEntryTableConfig setc : config.getExpEntryTableCfg()) {
VerifyResultMessages result = checkEntryTableCfg(config, setc);
if (result.hasWarning() && sbWarning.indexOf(result.getWarningMessage()) < 0) {
Expand All @@ -324,9 +327,15 @@ protected VerifyResultMessages checkEntryTableCfg(MigrationConfiguration config)
if (result.hasConfirm() && sbConfirm.indexOf(result.getConfirmMessage()) < 0) {
sbConfirm.append(result.getConfirmMessage()).append(LINE_SEP);
}
if (result.hasPKConfirm() && pkConfirm.indexOf(result.getPKConfirmMessage()) < 0) {
pkConfirm.append(result.getPKConfirmMessage()).append(LINE_SEP);
}
}
return new VerifyResultMessages(
null, sbWarning.toString().trim(), sbConfirm.toString().trim());
null,
sbWarning.toString().trim(),
sbConfirm.toString().trim(),
pkConfirm.toString().trim());
}

/**
Expand Down Expand Up @@ -371,6 +380,7 @@ protected VerifyResultMessages checkEntryTableCfg(
StringBuffer sbWarn = new StringBuffer();
StringBuffer sbConfirm = new StringBuffer();
StringBuffer sbNoPkTable = new StringBuffer();
StringBuffer sbpkConfirm = new StringBuffer();
// If there is no PK in the source table, output a warning.
if (!srcTable.hasPK()) {
if (config.getSrcCatalog().getSchemas().size() > 1) {
Expand All @@ -379,14 +389,13 @@ protected VerifyResultMessages checkEntryTableCfg(

sbNoPkTable.append(srcTable.getName());

String errorMessage =
NLS.bind(Messages.objectMapPageErrMsgNoPK, sbNoPkTable.toString());
sbConfirm.append(errorMessage).append(LINE_SEP);
sbpkConfirm.append(NLS.bind(Messages.objectMapPageErrMsgNoPK, sbNoPkTable.toString()));
sbpkConfirm.append(LINE_SEP);
}
checkTableIsInTargetDb(config, setc, targetTable, sbConfirm);
checkTableColumns(config, setc, srcTable, targetTable, sbConfirm);
checkEntryTableConstrains(setc, targetTable, sbWarn, sbConfirm);
return createVerifyResult(sbWarn, sbConfirm);
return createVerifyResult(sbWarn, sbConfirm, sbpkConfirm);
}

/**
Expand Down Expand Up @@ -664,17 +673,6 @@ protected VerifyResultMessages checkSQLTableCfg(
String errorMessage =
NLS.bind(Messages.objectMapPageErrMsgColumnNotMatched, bindings);
sbConfirm.append(errorMessage).append(LINE_SEP);
} else if (verifyInfo.getResult() == VerifyInfo.TYPE_NOENOUGH_LENGTH) {
String[] bindings =
new String[] {
scol.getName(),
scol.getShownDataType(),
tcol.getName(),
tcol.getShownDataType(),
srcTable.getName()
};
String errorMessage = NLS.bind(Messages.msgErrColumnNotEnoughLength, bindings);
sbConfirm.append(errorMessage).append(LINE_SEP);
}
}
return createVerifyResult(sbWarn, sbConfirm);
Expand Down Expand Up @@ -753,17 +751,6 @@ protected void checkTableColumns(
String errorMessage =
NLS.bind(Messages.objectMapPageErrMsgColumnNotMatched, bindings);
sbConfirm.append(errorMessage).append(LINE_SEP);
} else if (verifyInfo.getResult() == VerifyInfo.TYPE_NOENOUGH_LENGTH) {
String[] bindings =
new String[] {
scol.getName(),
scol.getShownDataType(),
tcol.getName(),
tcol.getShownDataType(),
srcTable.getName()
};
String errorMessage = NLS.bind(Messages.msgErrColumnNotEnoughLength, bindings);
sbConfirm.append(errorMessage).append(LINE_SEP);
}
}
// If no column to be migrated
Expand Down Expand Up @@ -889,6 +876,17 @@ protected VerifyResultMessages createVerifyResult(StringBuffer sbWarn, StringBuf
return result;
}

protected VerifyResultMessages createVerifyResult(
StringBuffer sbWarn, StringBuffer sbConfirm, StringBuffer pkConfirm) {
VerifyResultMessages result = createVerifyResult(sbWarn, sbConfirm);

if (pkConfirm.length() > 0) {
result.setPKConfirmMessage(pkConfirm.toString().trim());
}

return result;
}

/** @return true if user should change the target character type's size to avoid data lost. */
public boolean doesNeedToChangeCharacterTypeSize() {
return DatabaseType.MYSQL.equals(config.getSourceDBType())
Expand Down Expand Up @@ -946,13 +944,19 @@ protected int getRightCharacerTypePrecision(long precision) {
* @param result VerifyResultMessages
*/
protected void mergeVerifyResults(
StringBuffer sbWarning, StringBuffer sbConfirm, VerifyResultMessages result) {
StringBuffer sbWarning,
StringBuffer sbConfirm,
StringBuffer pkConfirm,
VerifyResultMessages result) {
if (result.hasWarning()) {
sbWarning.append(result.getWarningMessage()).append(LINE_SEP);
}
if (result.hasConfirm()) {
sbConfirm.append(result.getConfirmMessage()).append(LINE_SEP);
}
if (result.hasPKConfirm()) {
pkConfirm.append(result.getPKConfirmMessage()).append(LINE_SEP);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class VerifyResultMessages {
private String errorMessage;
private String warningMessage;
private String confirmMessage;
private String pkConfirmMsg;

public VerifyResultMessages() {
// do nothing.
Expand All @@ -50,6 +51,18 @@ public VerifyResultMessages(String errorMessage, String warningMessage, String c
this.errorMessage = errorMessage;
this.warningMessage = warningMessage;
this.confirmMessage = confirmMessage;
this.pkConfirmMsg = "";
}

public VerifyResultMessages(
String errorMessage,
String warningMessage,
String confirmMessage,
String pkConfirmMsg) {
this.errorMessage = errorMessage;
this.warningMessage = warningMessage;
this.confirmMessage = confirmMessage;
this.pkConfirmMsg = pkConfirmMsg;
}

/**
Expand Down Expand Up @@ -79,6 +92,10 @@ public boolean hasConfirm() {
return !StringUtils.isEmpty(confirmMessage);
}

public boolean hasPKConfirm() {
return !StringUtils.isEmpty(pkConfirmMsg);
}

public String getErrorMessage() {
return errorMessage;
}
Expand All @@ -102,4 +119,12 @@ public String getConfirmMessage() {
public void setConfirmMessage(String confirmMessage) {
this.confirmMessage = confirmMessage;
}

public String getPKConfirmMessage() {
return pkConfirmMsg;
}

public void setPKConfirmMessage(String pkConfirmMsg) {
this.pkConfirmMsg = pkConfirmMsg;
}
}

0 comments on commit 0d00f56

Please sign in to comment.