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

refactor(DBTableEditor): DBTableEditor adapt for native mysql and ob mysql #406

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 @@ -32,7 +32,6 @@
import com.oceanbase.tools.dbbrowser.model.DBConstraintType;
import com.oceanbase.tools.dbbrowser.model.DBIndexType;
import com.oceanbase.tools.dbbrowser.model.DBTable;
import com.oceanbase.tools.dbbrowser.model.DBTable.DBTableOptions;
import com.oceanbase.tools.dbbrowser.model.DBTableColumn;
import com.oceanbase.tools.dbbrowser.model.DBTableConstraint;
import com.oceanbase.tools.dbbrowser.model.DBTableIndex;
Expand Down Expand Up @@ -125,23 +124,7 @@ public String generateCreateObjectDDL(@NotNull DBTable table) {

protected abstract boolean createIndexWhenCreatingTable();

protected void appendTableOptions(DBTable table, SqlBuilder sqlBuilder) {
if (Objects.isNull(table.getTableOptions())) {
return;
}
DBTableOptions options = table.getTableOptions();

if (Objects.nonNull(options.getReplicaNum())) {
sqlBuilder.append("REPLICA_NUM = ").append(String.valueOf(options.getReplicaNum())).space();
}

if (Objects.nonNull(options.getUseBloomFilter())) {
sqlBuilder.append("USE_BLOOM_FILTER = ").append(options.getUseBloomFilter() ? "TRUE" : "FALSE").space();
}
if (Objects.nonNull(options.getTabletSize())) {
sqlBuilder.append("TABLET_SIZE = ").append(String.valueOf(options.getTabletSize())).space();
}
}
protected abstract void appendTableOptions(DBTable table, SqlBuilder sqlBuilder);

@Override
public String generateCreateDefinitionDDL(@NotNull DBTable table) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ protected void appendTableOptions(DBTable table, SqlBuilder sqlBuilder) {
if (StringUtils.isNotBlank(options.getCompressionOption())) {
sqlBuilder.append("COMPRESSION = ").append(options.getCompressionOption()).space();
}
super.appendTableOptions(table, sqlBuilder);
appendMoreTableOptions(table, sqlBuilder);
if (StringUtils.isNotEmpty(options.getComment())) {
sqlBuilder.append("COMMENT = ").value(options.getComment()).space();
}
}

protected void appendMoreTableOptions(DBTable table, SqlBuilder sqlBuilder) {}

@Override
protected void generateUpdateTableOptionDDL(@NonNull DBTable oldTable, @NonNull DBTable newTable,
@NonNull SqlBuilder sqlBuilder) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2023 OceanBase.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.oceanbase.tools.dbbrowser.editor.mysql;

import java.util.Objects;

import com.oceanbase.tools.dbbrowser.editor.DBObjectEditor;
import com.oceanbase.tools.dbbrowser.model.DBTable;
import com.oceanbase.tools.dbbrowser.model.DBTable.DBTableOptions;
import com.oceanbase.tools.dbbrowser.model.DBTableColumn;
import com.oceanbase.tools.dbbrowser.model.DBTableConstraint;
import com.oceanbase.tools.dbbrowser.model.DBTableIndex;
import com.oceanbase.tools.dbbrowser.model.DBTablePartition;
import com.oceanbase.tools.dbbrowser.util.SqlBuilder;

/**
* @author jingtian
* @date 2023/9/25
* @since ODC_release_4.2.2
*/
public class OBMySQLTableEditor extends MySQLTableEditor {
public OBMySQLTableEditor(DBObjectEditor<DBTableIndex> indexEditor,
DBObjectEditor<DBTableColumn> columnEditor,
DBObjectEditor<DBTableConstraint> constraintEditor,
DBObjectEditor<DBTablePartition> partitionEditor) {
super(indexEditor, columnEditor, constraintEditor, partitionEditor);
}

@Override
protected void appendMoreTableOptions(DBTable table, SqlBuilder sqlBuilder) {
if (Objects.isNull(table.getTableOptions())) {
return;
}

DBTableOptions options = table.getTableOptions();
if (Objects.nonNull(options.getReplicaNum())) {
sqlBuilder.append("REPLICA_NUM = ").append(String.valueOf(options.getReplicaNum())).space();
}
if (Objects.nonNull(options.getUseBloomFilter())) {
sqlBuilder.append("USE_BLOOM_FILTER = ").append(options.getUseBloomFilter() ? "TRUE" : "FALSE").space();
}
if (Objects.nonNull(options.getTabletSize())) {
sqlBuilder.append("TABLET_SIZE = ").append(String.valueOf(options.getTabletSize())).space();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@ protected void appendTableOptions(DBTable table, SqlBuilder sqlBuilder) {
if (StringUtils.isNotBlank(options.getCompressionOption())) {
sqlBuilder.append("COMPRESS ").append(options.getCompressionOption()).space();
}
super.appendTableOptions(table, sqlBuilder);
if (Objects.nonNull(options.getReplicaNum())) {
sqlBuilder.append("REPLICA_NUM = ").append(String.valueOf(options.getReplicaNum())).space();
}
if (Objects.nonNull(options.getUseBloomFilter())) {
sqlBuilder.append("USE_BLOOM_FILTER = ").append(options.getUseBloomFilter() ? "TRUE" : "FALSE").space();
}
if (Objects.nonNull(options.getTabletSize())) {
sqlBuilder.append("TABLET_SIZE = ").append(String.valueOf(options.getTabletSize())).space();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import com.oceanbase.tools.dbbrowser.editor.mysql.MySQLColumnEditor;
import com.oceanbase.tools.dbbrowser.editor.mysql.MySQLConstraintEditor;
import com.oceanbase.tools.dbbrowser.editor.mysql.MySQLDBTablePartitionEditor;
import com.oceanbase.tools.dbbrowser.editor.mysql.MySQLTableEditor;
import com.oceanbase.tools.dbbrowser.editor.mysql.OBMySQLIndexEditor;
import com.oceanbase.tools.dbbrowser.editor.mysql.OBMySQLTableEditor;
import com.oceanbase.tools.dbbrowser.editor.util.DBObjectTestUtils;
import com.oceanbase.tools.dbbrowser.model.DBTable;
import com.oceanbase.tools.dbbrowser.model.DBTableConstraint;
Expand All @@ -37,7 +37,7 @@ public class DBTableEditorTest {

@BeforeClass
public static void setUp() {
tableEditor = new MySQLTableEditor(new OBMySQLIndexEditor(), new MySQLColumnEditor(),
tableEditor = new OBMySQLTableEditor(new OBMySQLIndexEditor(), new MySQLColumnEditor(),
new MySQLConstraintEditor(), new MySQLDBTablePartitionEditor());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
import com.oceanbase.tools.dbbrowser.editor.mysql.MySQLColumnEditor;
import com.oceanbase.tools.dbbrowser.editor.mysql.MySQLConstraintEditor;
import com.oceanbase.tools.dbbrowser.editor.mysql.MySQLDBTablePartitionEditor;
import com.oceanbase.tools.dbbrowser.editor.mysql.MySQLTableEditor;
import com.oceanbase.tools.dbbrowser.editor.mysql.OBMySQLIndexEditor;
import com.oceanbase.tools.dbbrowser.editor.mysql.OBMySQLTableEditor;

public class MySQLTableEditorTest {

private DBTableEditor tableEditor;

@Before
public void setUp() {
tableEditor = new MySQLTableEditor(new OBMySQLIndexEditor(), new MySQLColumnEditor(),
tableEditor = new OBMySQLTableEditor(new OBMySQLIndexEditor(), new MySQLColumnEditor(),
new MySQLConstraintEditor(), new MySQLDBTablePartitionEditor());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.oceanbase.tools.dbbrowser.editor.DBTableIndexEditor;
import com.oceanbase.tools.dbbrowser.editor.DBTablePartitionEditor;
import com.oceanbase.tools.dbbrowser.editor.mysql.MySQLTableEditor;
import com.oceanbase.tools.dbbrowser.editor.mysql.OBMySQLTableEditor;
import com.oceanbase.tools.dbbrowser.editor.oracle.OracleTableEditor;

/**
Expand Down Expand Up @@ -52,9 +53,11 @@ public DBTableEditor create() {
new DBTablePartitionEditorFactory(connectType, dbVersion);
switch (connectType) {
case OB_MYSQL:
case MYSQL:
case CLOUD_OB_MYSQL:
case ODP_SHARDING_OB_MYSQL:
return new OBMySQLTableEditor(indexEditorFactory.create(), columnEditorFactory.create(),
constraintEditorFactory.create(), partitionEditorFactory.create());
case MYSQL:
return new MySQLTableEditor(indexEditorFactory.create(), columnEditorFactory.create(),
constraintEditorFactory.create(), partitionEditorFactory.create());
case CLOUD_OB_ORACLE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
import com.oceanbase.tools.dbbrowser.editor.mysql.MySQLConstraintEditor;
import com.oceanbase.tools.dbbrowser.editor.mysql.MySQLDBTablePartitionEditor;
import com.oceanbase.tools.dbbrowser.editor.mysql.MySQLObjectOperator;
import com.oceanbase.tools.dbbrowser.editor.mysql.MySQLTableEditor;
import com.oceanbase.tools.dbbrowser.editor.mysql.OBMySQLIndexEditor;
import com.oceanbase.tools.dbbrowser.editor.mysql.OBMySQLLessThan2277PartitionEditor;
import com.oceanbase.tools.dbbrowser.editor.mysql.OBMySQLTableEditor;
import com.oceanbase.tools.dbbrowser.model.DBObjectIdentity;
import com.oceanbase.tools.dbbrowser.model.DBObjectType;
import com.oceanbase.tools.dbbrowser.model.DBTable;
Expand Down Expand Up @@ -121,7 +121,7 @@ public String generateUpdateDDL(@NonNull Connection connection, @NonNull DBTable
}

protected DBTableEditor getTableEditor(Connection connection) {
return new MySQLTableEditor(new OBMySQLIndexEditor(), new MySQLColumnEditor(), new MySQLConstraintEditor(),
return new OBMySQLTableEditor(new OBMySQLIndexEditor(), new MySQLColumnEditor(), new MySQLConstraintEditor(),
getDBTablePartitionEditor(connection));
}

Expand Down