Skip to content

Commit a65018f

Browse files
committed
Refactor JdbcAdmin (#3121)
1 parent d627c8b commit a65018f

20 files changed

+2974
-2953
lines changed

core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcAdminImportTestUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public List<TestData> createExistingDatabaseWithAllDataTypes(String namespace)
145145
}
146146

147147
public void createExistingDatabase(String namespace) throws SQLException {
148-
execute(rdbEngine.createNamespaceSqls(rdbEngine.enclose(namespace)));
148+
execute(rdbEngine.createSchemaSqls(namespace));
149149
}
150150

151151
public List<String> getIntCompatibleColumnNamesOnExistingDatabase(String table) {

core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcAdminTestUtils.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public JdbcAdminTestUtils(Properties properties) {
3131
@Override
3232
public void dropMetadataTable() throws SQLException {
3333
execute(
34-
"DROP TABLE " + rdbEngine.encloseFullTableName(metadataSchema, JdbcAdmin.METADATA_TABLE));
34+
"DROP TABLE "
35+
+ rdbEngine.encloseFullTableName(metadataSchema, TableMetadataService.TABLE_NAME));
3536

3637
String dropNamespaceStatement = rdbEngine.dropNamespaceSql(metadataSchema);
3738
execute(dropNamespaceStatement);
@@ -40,7 +41,7 @@ public void dropMetadataTable() throws SQLException {
4041
@Override
4142
public void truncateMetadataTable() throws Exception {
4243
String truncateTableStatement =
43-
rdbEngine.truncateTableSql(metadataSchema, JdbcAdmin.METADATA_TABLE);
44+
rdbEngine.truncateTableSql(metadataSchema, TableMetadataService.TABLE_NAME);
4445
execute(truncateTableStatement);
4546
}
4647

@@ -49,7 +50,7 @@ public void truncateMetadataTable() throws Exception {
4950
public void corruptMetadata(String namespace, String table) throws Exception {
5051
String insertCorruptedMetadataStatement =
5152
"INSERT INTO "
52-
+ rdbEngine.encloseFullTableName(metadataSchema, JdbcAdmin.METADATA_TABLE)
53+
+ rdbEngine.encloseFullTableName(metadataSchema, TableMetadataService.TABLE_NAME)
5354
+ " VALUES ('"
5455
+ getFullTableName(namespace, table)
5556
+ "','corrupted','corrupted','corrupted','corrupted','0','0')";
@@ -60,9 +61,9 @@ public void corruptMetadata(String namespace, String table) throws Exception {
6061
public void deleteMetadata(String namespace, String table) throws Exception {
6162
String deleteMetadataStatement =
6263
"DELETE FROM "
63-
+ rdbEngine.encloseFullTableName(metadataSchema, JdbcAdmin.METADATA_TABLE)
64+
+ rdbEngine.encloseFullTableName(metadataSchema, TableMetadataService.TABLE_NAME)
6465
+ " WHERE "
65-
+ rdbEngine.enclose(JdbcAdmin.METADATA_COL_FULL_TABLE_NAME)
66+
+ rdbEngine.enclose(TableMetadataService.COL_FULL_TABLE_NAME)
6667
+ " = ?";
6768
try (Connection connection = dataSource.getConnection();
6869
PreparedStatement preparedStatement =

core/src/integration-test/java/com/scalar/db/storage/multistorage/MultiStorageAdminTestUtils.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
import com.datastax.driver.core.schemabuilder.SchemaBuilder;
77
import com.scalar.db.config.DatabaseConfig;
88
import com.scalar.db.storage.cassandra.ClusterManager;
9-
import com.scalar.db.storage.jdbc.JdbcAdmin;
109
import com.scalar.db.storage.jdbc.JdbcConfig;
1110
import com.scalar.db.storage.jdbc.JdbcTestUtils;
1211
import com.scalar.db.storage.jdbc.JdbcUtils;
1312
import com.scalar.db.storage.jdbc.RdbEngineFactory;
14-
import com.scalar.db.storage.jdbc.RdbEngineOracle;
1513
import com.scalar.db.storage.jdbc.RdbEngineStrategy;
14+
import com.scalar.db.storage.jdbc.TableMetadataService;
1615
import com.scalar.db.util.AdminTestUtils;
1716
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
1817
import java.sql.Connection;
@@ -52,14 +51,9 @@ public void dropMetadataTable() throws SQLException {
5251
// for JDBC
5352
execute(
5453
"DROP TABLE "
55-
+ rdbEngine.encloseFullTableName(jdbcMetadataSchema, JdbcAdmin.METADATA_TABLE));
54+
+ rdbEngine.encloseFullTableName(jdbcMetadataSchema, TableMetadataService.TABLE_NAME));
5655

57-
String dropNamespaceStatement;
58-
if (rdbEngine instanceof RdbEngineOracle) {
59-
dropNamespaceStatement = "DROP USER " + rdbEngine.enclose(jdbcMetadataSchema);
60-
} else {
61-
dropNamespaceStatement = "DROP SCHEMA " + rdbEngine.enclose(jdbcMetadataSchema);
62-
}
56+
String dropNamespaceStatement = rdbEngine.dropNamespaceSql(jdbcMetadataSchema);
6357
execute(dropNamespaceStatement);
6458
}
6559

@@ -70,7 +64,7 @@ public void truncateMetadataTable() throws Exception {
7064
// for JDBC
7165
String truncateTableStatement =
7266
"TRUNCATE TABLE "
73-
+ rdbEngine.encloseFullTableName(jdbcMetadataSchema, JdbcAdmin.METADATA_TABLE);
67+
+ rdbEngine.encloseFullTableName(jdbcMetadataSchema, TableMetadataService.TABLE_NAME);
7468
execute(truncateTableStatement);
7569
}
7670

@@ -82,7 +76,7 @@ public void corruptMetadata(String namespace, String table) throws Exception {
8276
// for JDBC
8377
String insertCorruptedMetadataStatement =
8478
"INSERT INTO "
85-
+ rdbEngine.encloseFullTableName(jdbcMetadataSchema, JdbcAdmin.METADATA_TABLE)
79+
+ rdbEngine.encloseFullTableName(jdbcMetadataSchema, TableMetadataService.TABLE_NAME)
8680
+ " VALUES ('"
8781
+ getFullTableName(namespace, table)
8882
+ "','corrupted','corrupted','corrupted','corrupted','0','0')";
@@ -96,9 +90,9 @@ public void deleteMetadata(String namespace, String table) throws Exception {
9690
// for JDBC
9791
String deleteMetadataStatement =
9892
"DELETE FROM "
99-
+ rdbEngine.encloseFullTableName(jdbcMetadataSchema, JdbcAdmin.METADATA_TABLE)
93+
+ rdbEngine.encloseFullTableName(jdbcMetadataSchema, TableMetadataService.TABLE_NAME)
10094
+ " WHERE "
101-
+ rdbEngine.enclose(JdbcAdmin.METADATA_COL_FULL_TABLE_NAME)
95+
+ rdbEngine.enclose(TableMetadataService.COL_FULL_TABLE_NAME)
10296
+ " = ?";
10397
try (Connection connection = dataSource.getConnection();
10498
PreparedStatement preparedStatement =

core/src/main/java/com/scalar/db/common/CommonDistributedStorageAdmin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ public Set<String> getNamespaceNames() throws ExecutionException {
464464

465465
@Override
466466
public StorageInfo getStorageInfo(String namespace) throws ExecutionException {
467-
if (!namespaceExists(namespace)) {
467+
if (checkNamespace && !namespaceExists(namespace)) {
468468
throw new IllegalArgumentException(CoreError.NAMESPACE_NOT_FOUND.buildMessage(namespace));
469469
}
470470

0 commit comments

Comments
 (0)