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

[TOOLS-4629] Fix Oracle comments not migrating during console migration #221

Merged
merged 1 commit into from
Jun 24, 2024
Merged
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 @@ -515,7 +515,7 @@ public void addExpTriggerCfg(String name) {
* @param viewName String
* @param target String
*/
public void addExpViewCfg(String schema, String viewName, String target) {
public void addExpViewCfg(String schema, String viewName, String target, String comment) {
if (srcCatalog != null) {
throw new RuntimeException("Source database was specified.");
}
Expand All @@ -524,6 +524,7 @@ public void addExpViewCfg(String schema, String viewName, String target) {
sc = new SourceViewConfig();
sc.setName(viewName);
sc.setOwner(schema);
sc.setComment(comment);
expViews.add(sc);
}
sc.setTarget(StringUtils.lowerCase(target));
Expand Down Expand Up @@ -1082,7 +1083,7 @@ private void buildTableCfg(boolean isReset) {
for (Schema sourceDBSchema : schemas) {
String prefix = "";
if (StringUtils.isNotBlank(sourceDBSchema.getName())) {
prefix = sourceDBSchema.getTargetSchemaName() + ".";
prefix = sourceDBSchema.getName() + ".";
}
for (Table srcTable : sourceDBSchema.getTables()) {
SourceEntryTableConfig setc =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ private void parseTargetColumn(Attributes attributes) {
if (StringUtils.isEmpty(type)) {
System.out.println(targetTable.getName() + ":" + column.getName());
}
column.setComment(attributes.getValue(TemplateTags.ATTR_COMMENT));
dtHelper.setColumnDataType(type, column);
targetTable.addColumn(column);
// column.setUnique(unique);
Expand Down Expand Up @@ -462,7 +463,7 @@ private void parseTargetTable(Attributes attributes) {
targetTable.setOwner(null);
}
}

targetTable.setComment(attributes.getValue(TemplateTags.ATTR_COMMENT));
config.addTargetTableSchema(targetTable);
}

Expand All @@ -477,6 +478,7 @@ private void parseTargetView(Attributes attributes) {
targetView.setTargetOwner(attributes.getValue(TemplateTags.ATTR_TARGET_OWNER));
targetView.setName(attributes.getValue(TemplateTags.ATTR_NAME));
targetView.setSourceOwner(attributes.getValue(TemplateTags.ATTR_SOURCE_OWNER));
targetView.setComment(attributes.getValue(TemplateTags.ATTR_COMMENT));
config.addTargetViewSchema(targetView);
}

Expand All @@ -490,6 +492,7 @@ private void parseTargetViewColumn(Attributes attributes) {
targetView.addColumn(column);
column.setTableOrView(targetView);
column.setName(attributes.getValue(TemplateTags.ATTR_NAME));
column.setComment(attributes.getValue(TemplateTags.ATTR_COMMENT));
dtHelper.setColumnDataType(attributes.getValue(TemplateTags.ATTR_TYPE), column);
}

Expand Down Expand Up @@ -653,6 +656,7 @@ private void startSourceElement(String qName, Attributes attributes) throws SAXE
getBoolean(attributes.getValue(TemplateTags.ATTR_EXP_OPT_COL), true));
setc.setStartFromTargetMax(
getBoolean(attributes.getValue(TemplateTags.ATTR_START_TAR_MAX), false));
setc.setComment(attributes.getValue(TemplateTags.ATTR_COMMENT));
config.addExpEntryTableCfg(setc);

} else if (TemplateTags.TAG_COLUMN.equals(qName)) {
Expand All @@ -663,6 +667,7 @@ private void startSourceElement(String qName, Attributes attributes) throws SAXE
scc.setNeedTrim(getBoolean(attributes.getValue(TemplateTags.ATTR_TRIM), false));
scc.setReplaceExpression(attributes.getValue(TemplateTags.ATTR_REPLACE_EXPRESSION));
scc.setUserDataHandler(attributes.getValue(TemplateTags.ATTR_USER_DATA_HANDLER));
scc.setComment(attributes.getValue(TemplateTags.ATTR_COMMENT));
} else if (TemplateTags.TAG_FK.equals(qName)) {
((SourceEntryTableConfig) srcTableCfg)
.addFKConfig(
Expand Down Expand Up @@ -712,7 +717,8 @@ private void startSourceElement(String qName, Attributes attributes) throws SAXE
config.addExpViewCfg(
attributes.getValue(TemplateTags.ATTR_OWNER),
attributes.getValue(TemplateTags.ATTR_NAME),
attributes.getValue(TemplateTags.ATTR_TARGET));
attributes.getValue(TemplateTags.ATTR_TARGET),
attributes.getValue(TemplateTags.ATTR_COMMENT));
} else if (TemplateTags.TAG_GRANT.equals(qName)) {
config.addExpGrantCfg(
attributes.getValue(TemplateTags.ATTR_OWNER),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ private static void createTargetViewNodes(
colNode.setAttribute(TemplateTags.ATTR_NAME, col.getName());
colNode.setAttribute(TemplateTags.ATTR_TYPE, col.getShownDataType());
colNode.setAttribute(TemplateTags.ATTR_BASE_TYPE, col.getDataType());
colNode.setAttribute(TemplateTags.ATTR_COMMENT, col.getComment());
if (col.getSubDataType() != null) {
colNode.setAttribute(TemplateTags.ATTR_SUB_TYPE, col.getSubDataType());
}
Expand Down Expand Up @@ -449,6 +450,7 @@ private static void createTargetTableNodes(
table.setAttribute(
TemplateTags.ATTR_REUSE_OID, getBooleanString(targetTable.isReuseOID()));
table.setAttribute(TemplateTags.ATTR_SOURCE_OWNER, targetTable.getSourceOwner());
table.setAttribute(TemplateTags.ATTR_COMMENT, targetTable.getComment());

Element columns = createElement(document, table, TemplateTags.TAG_COLUMNS);
List<Column> cols = targetTable.getColumns();
Expand All @@ -460,6 +462,7 @@ private static void createTargetTableNodes(
colNode.setAttribute(TemplateTags.ATTR_NULL, getBooleanString(col.isNullable()));
colNode.setAttribute(
TemplateTags.ATTR_AUTO_INCREMENT, getBooleanString(col.isAutoIncrement()));
colNode.setAttribute(TemplateTags.ATTR_COMMENT, col.getComment());

colNode.setAttribute(TemplateTags.ATTR_UNIQUE, getBooleanString(col.isUnique()));
colNode.setAttribute(TemplateTags.ATTR_SHARED, getBooleanString(col.isShared()));
Expand Down Expand Up @@ -864,6 +867,7 @@ private static void createSourceNode(
tbe.setAttribute(TemplateTags.ATTR_TARGET_SCHEMA, setc.getTargetOwner());
tbe.setAttribute(
TemplateTags.ATTR_CHANGE_NAME, getBooleanString(setc.isChangeTableName()));
tbe.setAttribute(TemplateTags.ATTR_COMMENT, setc.getComment());
if (setc.isEnableExpOpt()) {
tbe.setAttribute(
TemplateTags.ATTR_EXP_OPT_COL, getBooleanString(setc.isEnableExpOpt()));
Expand All @@ -881,6 +885,7 @@ private static void createSourceNode(
col.setAttribute(TemplateTags.ATTR_TRIM, getBooleanString(scc.isNeedTrim()));
col.setAttribute(TemplateTags.ATTR_REPLACE_EXPRESSION, scc.getReplaceExp());
col.setAttribute(TemplateTags.ATTR_USER_DATA_HANDLER, scc.getUserDataHandler());
col.setAttribute(TemplateTags.ATTR_COMMENT, scc.getComment());
}

List<SourceIndexConfig> indexConfigList = setc.getIndexConfigList();
Expand Down Expand Up @@ -971,6 +976,7 @@ private static void createSourceNode(
vwNode.setAttribute(TemplateTags.ATTR_OWNER, sc.getOwner());
vwNode.setAttribute(TemplateTags.ATTR_NAME, sc.getName());
vwNode.setAttribute(TemplateTags.ATTR_TARGET, sc.getTarget());
vwNode.setAttribute(TemplateTags.ATTR_COMMENT, sc.getComment());
}
}
// source grants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ private TemplateTags() {
public static final String ATTR_CACHE_SIZE = "cache_size";
public static final String ATTR_CHANGE_NAME = "change_name";
public static final String ATTR_CHARSET = "charset";
public static final String ATTR_COMMENT = "comment";
public static final String ATTR_COMMIT_COUNT = "commit_count";
public static final String ATTR_CREATE = "create";
public static final String ATTR_CREATE_USER_SQL = "create_user_sql";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ private String getColumnDDL(Column column, PK pk) {
if (!column.isNullable() && isNotPKColumn) {
bf.append(" NOT NULL");
}
if (column.getComment() != null) {
bf.append(" comment \'" + column.getComment() + "\'");
if (column.getComment() != null && !column.getComment().isEmpty()) {
bf.append(" COMMENT \'" + column.getComment() + "\'");
}
if (column.isShared() || !column.isUnique() || !isNotPKColumn) {
return bf.toString();
Expand Down Expand Up @@ -490,8 +490,8 @@ public String getTableDDL(Table table, boolean addUserSchema) {
if (table.isReuseOID()) {
bf.append(" REUSE_OID");
}
if (table.getComment() != null) {
bf.append(" comment = \'" + table.getComment() + "\'");
if (table.getComment() != null && !table.getComment().isEmpty()) {
bf.append(" COMMENT = \'" + table.getComment() + "\'");
}
if (DBUtils.supportedCubridPartition(table.getPartitionInfo())) {
bf.append(NEWLINE).append(table.getPartitionInfo().getDDL());
Expand Down Expand Up @@ -662,14 +662,14 @@ public String getViewDDL(View view, boolean addUserSchema) {
sb.append(getQuotedObjName(col.getName()));
sb.append(" ").append(col.getShownDataType());

if (col.getComment() != null) {
sb.append(" COMMENT ").append(col.getComment());
if (col.getComment() != null && !col.getComment().isEmpty()) {
sb.append(" COMMENT \'").append(col.getComment()).append("\'");
}
}
sb.append(NEWLINE).append(")");
}

if (view.getComment() != null) {
if (view.getComment() != null && !view.getComment().isEmpty()) {
sb.append(" ").append("COMMENT \'" + view.getComment() + "\'");
}
sb.append(NEWLINE).append(END_LINE_CHAR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ private String getViewColumnComment(
comment = commentEditor(comment);
}

return "\'" + comment + "\'";
return comment;
} catch (Exception e) {
e.printStackTrace();
return null;
Expand Down
Loading