Part of the English translation work, and some typos in the original project were corrected.

This commit is contained in:
Suyue
2024-02-29 22:55:03 +08:00
parent 7399955384
commit 064d15bd5a
278 changed files with 1978 additions and 1966 deletions

View File

@ -10,7 +10,7 @@ import org.junit.jupiter.api.TestMethodOrder;
import org.springframework.boot.test.context.SpringBootTest;
/**
* 基础测试类
* Basic test class
*
* @author Jiaju Zhuang
**/

View File

@ -19,7 +19,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
/**
* 数据源测试
* Data source testing
*
* @author Jiaju Zhuang
*/
@ -48,14 +48,14 @@ public class ConsoleOperationsTest extends BaseTest {
dataSourceCreateParam.setPassword(dialectProperties.getPassword());
dataSourceService.preConnect(dataSourceCreateParam);
// 创建
// creat
ConsoleConnectParam consoleCreateParam = new ConsoleConnectParam();
consoleCreateParam.setDataSourceId(dataSourceId);
consoleCreateParam.setConsoleId(consoleId);
consoleCreateParam.setDatabaseName(dialectProperties.getDatabaseName());
consoleService.createConsole(consoleCreateParam);
// 关闭
// close
ConsoleCloseParam consoleCloseParam = new ConsoleCloseParam();
consoleCloseParam.setDataSourceId(dataSourceId);
consoleCloseParam.setConsoleId(consoleId);
@ -102,7 +102,7 @@ public class ConsoleOperationsTest extends BaseTest {
dataSourceCreateParam.setPassword(dialectProperties.getPassword());
dataSourceService.preConnect(dataSourceCreateParam);
// 创建控制台
// Create a console
ConsoleConnectParam consoleCreateParam = new ConsoleConnectParam();
consoleCreateParam.setDataSourceId(dataSourceId);
consoleCreateParam.setConsoleId(consoleId);

View File

@ -22,7 +22,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
/**
* 数据库测试
* Database testing
*
* @author Jiaju Zhuang
*/
@ -42,7 +42,7 @@ public class DatabaseOperationsTest extends BaseTest {
String dbTypeEnum = dialectProperties.getDbType();
Long dataSourceId = TestUtils.nextLong();
// 准备上下文
// Prepare context
putConnect(dialectProperties.getUrl(), dialectProperties.getUsername(), dialectProperties.getPassword(),
dialectProperties.getDbType(), dialectProperties.getDatabaseName(), dataSourceId, null);
@ -57,13 +57,13 @@ public class DatabaseOperationsTest extends BaseTest {
DatabaseQueryAllParam databaseQueryAllParam = new DatabaseQueryAllParam();
databaseQueryAllParam.setDataSourceId(dataSourceId);
ListResult<Database> databaseList = databaseService.queryAll(databaseQueryAllParam);
log.info("查询数据库返回:{}", JSON.toJSONString(databaseList));
log.info("Querying the database returns: {}", JSON.toJSONString(databaseList));
Database Database = databaseList.getData().stream()
.filter(database -> dialectProperties.getDatabaseName().equals(database.getName()))
.findFirst()
.orElse(null);
Assertions.assertNotNull(Database, "查询数据库失败");
Assertions.assertNotNull(Database, "Query database failed");
removeConnect();
}

View File

@ -16,7 +16,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
/**
* 样例
* Sample
*
* @author Jiaju Zhuang
*/
@ -33,11 +33,11 @@ public class ExampleOperationsTest extends BaseTest {
public void example() {
for (DialectProperties dialectProperties : dialectPropertiesList) {
DataResult<String> createTable = tableService.createTableExample(dialectProperties.getDbType());
log.info("返回建表语句:{}", createTable);
Assertions.assertNotNull(createTable, "查询样例失败");
log.info("Return table creation statement: {}", createTable);
Assertions.assertNotNull(createTable, "Query sample failed");
DataResult<String> alterTable = tableService.alterTableExample(dialectProperties.getDbType());
log.info("返回建修改表语句:{}", alterTable);
Assertions.assertNotNull(alterTable, "查询样例失败");
log.info("Return the statement to create and modify the table: {}", alterTable);
Assertions.assertNotNull(alterTable, "Query sample failed");
}
}

View File

@ -28,14 +28,14 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
/**
* 查询测试
* query test
*
* @author Jiaju Zhuang
*/
@Slf4j
public class JdbcOperationsTest extends BaseTest {
/**
* 表名
* Table Name
*/
public static final String TABLE_NAME = "DATA_OPS_TEMPLATE_TEST_" + System.currentTimeMillis();
private final static String STRING = "STR";
@ -61,7 +61,7 @@ public class JdbcOperationsTest extends BaseTest {
Long dataSourceId = TestUtils.nextLong();
Long consoleId = TestUtils.nextLong();
// 准备上下文
// Prepare context
putConnect(dialectProperties.getUrl(), dialectProperties.getUsername(), dialectProperties.getPassword(),
dialectProperties.getDbType(), dialectProperties.getDatabaseName(), dataSourceId, consoleId);
@ -72,7 +72,7 @@ public class JdbcOperationsTest extends BaseTest {
dataSourceCreateParam.setPassword(dialectProperties.getPassword());
dataSourceService.preConnect(dataSourceCreateParam);
// 创建控制台
// Create a console
ConsoleConnectParam consoleCreateParam = new ConsoleConnectParam();
consoleCreateParam.setDataSourceId(dataSourceId);
consoleCreateParam.setConsoleId(consoleId);
@ -85,46 +85,46 @@ public class JdbcOperationsTest extends BaseTest {
templateQueryParam.setSql(dialectProperties.getCrateTableSql(TABLE_NAME));
dlTemplateService.execute(templateQueryParam);
// 插入
// insert
templateQueryParam = new DlExecuteParam();
templateQueryParam.setConsoleId(consoleId);
templateQueryParam.setDataSourceId(dataSourceId);
templateQueryParam.setSql(dialectProperties.getInsertSql(TABLE_NAME, DATE, NUMBER, STRING));
ListResult<ExecuteResult> executeResult = dlTemplateService.execute(templateQueryParam);
Assertions.assertTrue(executeResult.getSuccess(), "查询数据失败");
// Assertions.assertEquals(1, listResult.getUpdateCount(), "查询数据失败");
Assertions.assertTrue(executeResult.getSuccess(), "Query data failed");
// Assertions.assertEquals(1, listResult.getUpdateCount(), "Query data failed");
// 查询
// query
templateQueryParam = new DlExecuteParam();
templateQueryParam.setConsoleId(consoleId);
templateQueryParam.setDataSourceId(dataSourceId);
templateQueryParam.setSql(dialectProperties.getSelectSqlById(TABLE_NAME, 1L));
executeResult = dlTemplateService.execute(templateQueryParam);
log.info("返回数据:{}", JSON.toJSONString(executeResult));
Assertions.assertTrue(executeResult.getSuccess(), "查询数据失败");
log.info("Return data:{}", JSON.toJSONString(executeResult));
Assertions.assertTrue(executeResult.getSuccess(), "Query data failed");
List<Header> headerList = executeResult.getData().get(0).getHeaderList();
Assertions.assertEquals(4L, headerList.size(), "查询数据失败");
Assertions.assertEquals(dialectProperties.toCase("ID"), headerList.get(0).getName(), "查询数据失败");
Assertions.assertEquals(4L, headerList.size(), "Query data failed");
Assertions.assertEquals(dialectProperties.toCase("ID"), headerList.get(0).getName(), "Query data failed");
List<List<String>> dataList = executeResult.getData().get(0).getDataList();
Assertions.assertEquals(1L, dataList.size(), "查询数据失败");
Assertions.assertEquals(1L, dataList.size(), "Query data failed");
List<String> data1 = dataList.get(0);
Assertions.assertEquals(Long.toString(NUMBER), data1.get(0), "查询数据失败");
Assertions.assertEquals(Long.toString(NUMBER), data1.get(0), "Query data failed");
log.info("date:{},{}", DATE, data1.get(1));
Assertions.assertEquals(DateUtil.format(DATE, DatePattern.NORM_DATETIME_FORMAT), data1.get(1),
"查询数据失败");
Assertions.assertEquals(Long.toString(NUMBER), data1.get(2), "查询数据失败");
Assertions.assertEquals(STRING, data1.get(3), "查询数据失败");
"Query data failed");
Assertions.assertEquals(Long.toString(NUMBER), data1.get(2), "Query data failed");
Assertions.assertEquals(STRING, data1.get(3), "Query data failed");
// 异常sql
// Exception sql
templateQueryParam = new DlExecuteParam();
templateQueryParam.setConsoleId(consoleId);
templateQueryParam.setDataSourceId(dataSourceId);
templateQueryParam.setSql(dialectProperties.getTableNotFoundSqlById(TABLE_NAME));
executeResult = dlTemplateService.execute(templateQueryParam);
log.info("异常sql执行结果:{}", JSON.toJSONString(executeResult));
Assertions.assertFalse(executeResult.getSuccess(), "异常sql错误");
Assertions.assertNotNull(executeResult.getErrorMessage(), "异常sql错误");
log.info("Abnormal sql execution result: {}", JSON.toJSONString(executeResult));
Assertions.assertFalse(executeResult.getSuccess(), "Exception sql error");
Assertions.assertNotNull(executeResult.getErrorMessage(), "Exception sql error");
removeConnect();
}
@ -146,21 +146,21 @@ public class JdbcOperationsTest extends BaseTest {
dataSourceCreateParam.setPassword(dialectProperties.getPassword());
dataSourceService.preConnect(dataSourceCreateParam);
// 创建控制台
// Create a console
ConsoleConnectParam consoleCreateParam = new ConsoleConnectParam();
consoleCreateParam.setDataSourceId(dataSourceId);
consoleCreateParam.setConsoleId(consoleId);
consoleCreateParam.setDatabaseName(dialectProperties.getDatabaseName());
consoleService.createConsole(consoleCreateParam);
// 创建表结构
// Create table structure
DlExecuteParam templateQueryParam = new DlExecuteParam();
templateQueryParam.setConsoleId(consoleId);
templateQueryParam.setDataSourceId(dataSourceId);
templateQueryParam.setSql(dialectProperties.getDropTableSql(TABLE_NAME));
dlTemplateService.execute(templateQueryParam);
} catch (Exception e) {
log.warn("删除表结构失败.", e);
log.warn("Failed to delete table structure.", e);
}
}
}

View File

@ -19,7 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
/**
* 数据源测试
* Data source testing
*
* @author Jiaju Zhuang
*/
@ -37,7 +37,7 @@ public class SQLExecutorOperationsTest extends BaseTest {
String dbTypeEnum = dialectProperties.getDbType();
Long dataSourceId = TestUtils.nextLong();
TestUtils.buildContext(dialectProperties, dataSourceId, null);
// 创建
// creat
DataSourcePreConnectParam dataSourceCreateParam = new DataSourcePreConnectParam();
dataSourceCreateParam.setType(dbTypeEnum);
@ -45,10 +45,10 @@ public class SQLExecutorOperationsTest extends BaseTest {
dataSourceCreateParam.setUser(dialectProperties.getUsername());
dataSourceCreateParam.setPassword(dialectProperties.getPassword());
ActionResult dataSourceConnect = dataSourceService.preConnect(dataSourceCreateParam);
Assertions.assertTrue(dataSourceConnect.getSuccess(), "创建数据库连接池失败");
// Assertions.assertTrue(DataCenterUtils.JDBC_ACCESSOR_MAP.containsKey(dataSourceId), "创建数据库连接池失败");
Assertions.assertTrue(dataSourceConnect.getSuccess(), "Failed to create database connection pool");
// Assertions.assertTrue(DataCenterUtils.JDBC_ACCESSOR_MAP.containsKey(dataSourceId), "Failed to create database connection pool");
// 关闭
// cloes
dataSourceService.close(dataSourceId);
TestUtils.remove();
}
@ -60,7 +60,7 @@ public class SQLExecutorOperationsTest extends BaseTest {
for (DialectProperties dialectProperties : dialectPropertiesList) {
String dbTypeEnum = dialectProperties.getDbType();
// 创建
// creat
DataSourcePreConnectParam dataSourceCreateParam = new DataSourcePreConnectParam();
dataSourceCreateParam.setType(dbTypeEnum);
@ -68,8 +68,8 @@ public class SQLExecutorOperationsTest extends BaseTest {
dataSourceCreateParam.setUser(dialectProperties.getUsername());
dataSourceCreateParam.setPassword(dialectProperties.getPassword());
ActionResult dataSourceConnect = dataSourceService.preConnect(dataSourceCreateParam);
log.info("创建数据库返回:{}", JSON.toJSONString(dataSourceConnect));
Assertions.assertFalse(dataSourceConnect.getSuccess(), "创建数据库失败错误");
log.info("Create database returns: {}", JSON.toJSONString(dataSourceConnect));
Assertions.assertFalse(dataSourceConnect.getSuccess(), "Database creation failed error");
}
}
@Test
@ -82,7 +82,7 @@ public class SQLExecutorOperationsTest extends BaseTest {
String dbTypeEnum = dialectProperties.getDbType();
Long dataSourceId = TestUtils.nextLong();
TestUtils.buildContext(dialectProperties, dataSourceId, null);
// 创建
// creat
DataSourceCreateParam dataSourceCreateParam = new DataSourceCreateParam();
dataSourceCreateParam.setAlias(dialectProperties.getDbType()+"_unittest_"+dialectProperties.getDbType());
dataSourceCreateParam.setType(dbTypeEnum);
@ -90,8 +90,8 @@ public class SQLExecutorOperationsTest extends BaseTest {
dataSourceCreateParam.setUserName(dialectProperties.getUsername());
dataSourceCreateParam.setPassword(dialectProperties.getPassword());
DataResult<Long> dataSourceConnect = dataSourceService.createWithPermission(dataSourceCreateParam);
Assertions.assertTrue(dataSourceConnect.getSuccess(), "创建数据库连接池失败");
// Assertions.assertTrue(DataCenterUtils.JDBC_ACCESSOR_MAP.containsKey(dataSourceId), "创建数据库连接池失败");
Assertions.assertTrue(dataSourceConnect.getSuccess(), "Failed to create database connection pool");
// Assertions.assertTrue(DataCenterUtils.JDBC_ACCESSOR_MAP.containsKey(dataSourceId), "Failed to create database connection pool");
}
}

View File

@ -39,14 +39,14 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
/**
* 数据源测试
* Data source testing
*
* @author Jiaju Zhuang
*/
@Slf4j
public class TableOperationsTest extends BaseTest {
/**
* 表名
* Table Name
*/
public static final String TABLE_NAME = "data_ops_table_test_" + System.currentTimeMillis();
@ -72,7 +72,7 @@ public class TableOperationsTest extends BaseTest {
Long dataSourceId = TestUtils.nextLong();
Long consoleId = TestUtils.nextLong();
// 准备上下文
// Prepare context
putConnect(dialectProperties.getUrl(), dialectProperties.getUsername(), dialectProperties.getPassword(),
dialectProperties.getDbType(), dialectProperties.getDatabaseName(), dataSourceId, consoleId);
@ -84,21 +84,21 @@ public class TableOperationsTest extends BaseTest {
dataSourceCreateParam.setPassword(dialectProperties.getPassword());
dataSourceService.preConnect(dataSourceCreateParam);
// 创建控制台
// Create a console
ConsoleConnectParam consoleCreateParam = new ConsoleConnectParam();
consoleCreateParam.setDataSourceId(dataSourceId);
consoleCreateParam.setConsoleId(consoleId);
consoleCreateParam.setDatabaseName(dialectProperties.getDatabaseName());
consoleService.createConsole(consoleCreateParam);
// 创建表结构
// Create table structure
DlExecuteParam templateQueryParam = new DlExecuteParam();
templateQueryParam.setConsoleId(consoleId);
templateQueryParam.setDataSourceId(dataSourceId);
templateQueryParam.setSql(dialectProperties.getCrateTableSql(TABLE_NAME));
dlTemplateService.execute(templateQueryParam);
// 查询建表语句
// Query table creation statement
ShowCreateTableParam showCreateTableParam = ShowCreateTableParam.builder()
.dataSourceId(dataSourceId)
.databaseName(dialectProperties.getDatabaseName())
@ -109,13 +109,13 @@ public class TableOperationsTest extends BaseTest {
}
DataResult<String> createTable = tableService.showCreateTable(showCreateTableParam);
log.info("建表语句:{}", createTable.getData());
log.info("Table creation statement: {}", createTable.getData());
if (dialectProperties.getDbType() != "H2") {
Assertions.assertTrue(createTable.getData().contains(dialectProperties.toCase(TABLE_NAME)),
"查询表结构失败");
"Query table structure failed");
}
// 查询表结构
// Query table structure
TablePageQueryParam tablePageQueryParam = new TablePageQueryParam();
tablePageQueryParam.setDataSourceId(dataSourceId);
tablePageQueryParam.setDatabaseName(dialectProperties.getDatabaseName());
@ -127,12 +127,12 @@ public class TableOperationsTest extends BaseTest {
.columnList(Boolean.TRUE)
.indexList(Boolean.TRUE)
.build()).getData();
log.info("分析数据返回{}", JSON.toJSONString(tableList));
Assertions.assertNotEquals(0L, tableList.size(), "查询表结构失败");
log.info("Analyzing data returns {}", JSON.toJSONString(tableList));
Assertions.assertNotEquals(0L, tableList.size(), "Query table structure failed");
Table table = tableList.get(0);
// Assertions.assertEquals(dialectProperties.toCase(TABLE_NAME), table.getName(), "查询表结构失败");
// Assertions.assertEquals(dialectProperties.toCase(TABLE_NAME), table.getName(), "Query table structure failed");
if (dialectProperties.getDbType() != "POSTGRESQL") {
Assertions.assertEquals("测试表", table.getComment(), "查询表结构失败");
Assertions.assertEquals("Test table", table.getComment(), "Query table structure failed");
}
TableQueryParam tableQueryParam = new TableQueryParam();
tableQueryParam.setTableName(table.getName());
@ -142,50 +142,50 @@ public class TableOperationsTest extends BaseTest {
tableQueryParam.setSchemaName("public");
}
List<TableColumn> columnList = tableService.queryColumns(tableQueryParam);
Assertions.assertEquals(4L, columnList.size(), "查询表结构失败");
Assertions.assertEquals(4L, columnList.size(), "Query table structure failed");
TableColumn id = columnList.get(0);
Assertions.assertEquals(dialectProperties.toCase("id"), id.getName(), "查询表结构失败");
Assertions.assertEquals("主键自增", id.getComment(), "查询表结构失败");
Assertions.assertTrue(id.getAutoIncrement(), "查询表结构失败");
//Assertions.assertFalse(id.getNullable(), "查询表结构失败");
Assertions.assertEquals(dialectProperties.toCase("id"), id.getName(), "Query table structure failed");
Assertions.assertEquals("Primary key auto-increment", id.getComment(), "Query table structure failed");
Assertions.assertTrue(id.getAutoIncrement(), "Query table structure failed");
//Assertions.assertFalse(id.getNullable(), "Query table structure failed");
TableColumn string = columnList.get(3);
Assertions.assertEquals(dialectProperties.toCase("string"), string.getName(), "查询表结构失败");
//Assertions.assertTrue(string.getNullable(), "查询表结构失败");
Assertions.assertEquals(dialectProperties.toCase("string"), string.getName(), "Query table structure failed");
//Assertions.assertTrue(string.getNullable(), "Query table structure failed");
Assertions.assertEquals("DATA", TestUtils.unWrapperDefaultValue(string.getDefaultValue()),
"查询表结构失败");
"Query table structure failed");
if (dialectProperties.getDbType() == "POSTGRESQL") {
tablePageQueryParam.setSchemaName("public");
}
List<TableIndex> tableIndexList = tableService.queryIndexes(tableQueryParam);
log.info("分析数据返回{}", JSON.toJSONString(tableIndexList));
Assertions.assertEquals(4L, tableIndexList.size(), "查询表结构失败");
log.info("Analyzing data returns {}", JSON.toJSONString(tableIndexList));
Assertions.assertEquals(4L, tableIndexList.size(), "Query table structure failed");
Map<String, TableIndex> tableIndexMap = EasyCollectionUtils.toIdentityMap(tableIndexList,
TableIndex::getName);
TableIndex idxDate = tableIndexMap.get(dialectProperties.toCase(TABLE_NAME + "_idx_date"));
Assertions.assertEquals("日期索引", idxDate.getComment(), "查询表结构失败");
Assertions.assertEquals(IndexTypeEnum.NORMAL.getCode(), idxDate.getType(), "查询表结构失败");
Assertions.assertEquals(1L, idxDate.getColumnList().size(), "查询表结构失败");
Assertions.assertEquals("date index", idxDate.getComment(), "Query table structure failed");
Assertions.assertEquals(IndexTypeEnum.NORMAL.getCode(), idxDate.getType(), "Query table structure failed");
Assertions.assertEquals(1L, idxDate.getColumnList().size(), "Query table structure failed");
Assertions.assertEquals(dialectProperties.toCase("date"), idxDate.getColumnList().get(0).getColumnName(),
"查询表结构失败");
"Query table structure failed");
Assertions.assertEquals(CollationEnum.DESC.getCode(), idxDate.getColumnList().get(0).getCollation(),
"查询表结构失败");
"Query table structure failed");
TableIndex ukNumber = tableIndexMap.get(dialectProperties.toCase(TABLE_NAME + "_uk_number"));
Assertions.assertEquals("唯一索引", ukNumber.getComment(), "查询表结构失败");
Assertions.assertEquals(IndexTypeEnum.UNIQUE.getCode(), ukNumber.getType(), "查询表结构失败");
Assertions.assertEquals("unique index", ukNumber.getComment(), "Query table structure failed");
Assertions.assertEquals(IndexTypeEnum.UNIQUE.getCode(), ukNumber.getType(), "Query table structure failed");
TableIndex idxNumberString = tableIndexMap.get(dialectProperties.toCase(TABLE_NAME + "_idx_number_string"));
Assertions.assertEquals(2, idxNumberString.getColumnList().size(), "查询表结构失败");
Assertions.assertEquals(2, idxNumberString.getColumnList().size(), "Query table structure failed");
// 删除表结构
// Delete table structure
DropParam dropParam = DropParam.builder()
.dataSourceId(dataSourceId)
.databaseName(dialectProperties.getDatabaseName())
.tableName(dialectProperties.toCase(TABLE_NAME))
.build();
tableService.drop(dropParam);
// 查询表结构
// Query table structure
tablePageQueryParam = new TablePageQueryParam();
tablePageQueryParam.setDataSourceId(dataSourceId);
tablePageQueryParam.setDatabaseName(dialectProperties.getDatabaseName());
@ -194,10 +194,10 @@ public class TableOperationsTest extends BaseTest {
.columnList(Boolean.TRUE)
.indexList(Boolean.TRUE)
.build()).getData();
log.info("删除表后数据返回{}", JSON.toJSONString(tableList));
Assertions.assertEquals(0L, tableList.size(), "查询表结构失败");
log.info("After deleting the table, the data returns {}", JSON.toJSONString(tableList));
Assertions.assertEquals(0L, tableList.size(), "Query table structure failed");
// 测试建表语句
// Test the table creation statement
testBuildSql(dialectProperties, dataSourceId, consoleId);
removeConnect();
@ -207,36 +207,36 @@ public class TableOperationsTest extends BaseTest {
private void testBuildSql(DialectProperties dialectProperties, Long dataSourceId, Long consoleId) {
if (dialectProperties.getDbType() != "MYSQL") {
log.error("目前测试案例只支持mysql");
log.error("Currently the test case only supports mysql");
return;
}
// 新建表
// Create new table
// CREATE TABLE `DATA_OPS_TEMPLATE_TEST_1673093980449`
// (
// `id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT '主键自增',
// `date` datetime(3) not null COMMENT '日期',
// `number` bigint COMMENT '长整型',
// `string` VARCHAR(100) default 'DATA' COMMENT '名字',
// index DATA_OPS_TEMPLATE_TEST_1673093980449_idx_date (date desc) comment '日期索引',
// unique DATA_OPS_TEMPLATE_TEST_1673093980449_uk_number (number) comment '唯一索引',
// index DATA_OPS_TEMPLATE_TEST_1673093980449_idx_number_string (number, date) comment '联合索引'
//) COMMENT ='测试表';
// * 大小写看具体的数据库决定:
//* 创建表表结构 : 测试表
// * 字段:
//* id 主键自增
//* date 日期 非空
// * number 长整型
// * string 字符串 长度100 默认值 "DATA"
// `id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT 'Primary key auto-increment',
// `date` datetime(3) not null COMMENT 'date',
// `number` bigint COMMENT 'long integer',
// `string` VARCHAR(100) default 'DATA' COMMENT 'name',
// index DATA_OPS_TEMPLATE_TEST_1673093980449_idx_date (date desc) comment 'date index',
// unique DATA_OPS_TEMPLATE_TEST_1673093980449_uk_number (number) comment 'unique index',
// index DATA_OPS_TEMPLATE_TEST_1673093980449_idx_number_string (number, date) comment 'Union index'
//) COMMENT ='Test table';
// * The case depends on the specific database:
//* Create table structure: Test table
// * Fields:
//* id Primary key auto-increment
//* date date is not null
// * number long integer
// * string String length 100 default value "DATA"
// *
//* 索引(加上$tableName_ 原因是 有些数据库索引是全局唯一的)
//* $tableName_idx_date 日期索引 倒序
// * $tableName_uk_number 唯一索引
// * $tableName_idx_number_string 联合索引
//* Index (plus $tableName_ because some database indexes are globally unique):
//* $tableName_idx_date date index reverse order
// * $tableName_uk_number unique index
// * $tableName_idx_number_string Union index
String tableName = dialectProperties.toCase("data_ops_table_test_" + System.currentTimeMillis());
Table newTable = new Table();
newTable.setName(tableName);
newTable.setComment("测试表");
newTable.setComment("Test table");
List<TableColumn> tableColumnList = new ArrayList<>();
newTable.setColumnList(tableColumnList);
//id
@ -245,7 +245,7 @@ public class TableOperationsTest extends BaseTest {
idTableColumn.setAutoIncrement(Boolean.TRUE);
idTableColumn.setPrimaryKey(Boolean.TRUE);
//idTableColumn.setNullable(Boolean.FALSE);
idTableColumn.setComment("主键自增");
idTableColumn.setComment("Primary key auto-increment");
idTableColumn.setColumnType("bigint");
tableColumnList.add(idTableColumn);
@ -253,54 +253,54 @@ public class TableOperationsTest extends BaseTest {
TableColumn dateTableColumn = new TableColumn();
dateTableColumn.setName("date");
//dateTableColumn.setNullable(Boolean.FALSE);
dateTableColumn.setComment("日期");
dateTableColumn.setComment("date");
dateTableColumn.setColumnType("datetime(3)");
tableColumnList.add(dateTableColumn);
// number
TableColumn numberTableColumn = new TableColumn();
numberTableColumn.setName("number");
numberTableColumn.setComment("长整型");
numberTableColumn.setComment("long integer");
numberTableColumn.setColumnType("bigint");
tableColumnList.add(numberTableColumn);
// string
TableColumn stringTableColumn = new TableColumn();
stringTableColumn.setName("string");
stringTableColumn.setComment("名字");
stringTableColumn.setComment("name");
stringTableColumn.setColumnType("varchar(100)");
stringTableColumn.setDefaultValue("DATA");
tableColumnList.add(stringTableColumn);
// 索引
// index
List<TableIndex> tableIndexList = new ArrayList<>();
newTable.setIndexList(tableIndexList);
// index DATA_OPS_TEMPLATE_TEST_1673093980449_idx_date (date desc) comment '日期索引',
// index DATA_OPS_TEMPLATE_TEST_1673093980449_idx_date (date desc) comment 'date index',
tableIndexList.add(TableIndex.builder()
.name(tableName + "_idx_date")
.type(IndexTypeEnum.NORMAL.getCode())
.comment("日期索引")
.comment("date index")
.columnList(Lists.newArrayList(TableIndexColumn.builder()
.columnName("date")
.collation(CollationEnum.DESC.getCode())
.build()))
.build());
// unique DATA_OPS_TEMPLATE_TEST_1673093980449_uk_number (number) comment '唯一索引',
// unique DATA_OPS_TEMPLATE_TEST_1673093980449_uk_number (number) comment 'unique index',
tableIndexList.add(TableIndex.builder()
.name(tableName + "_uk_number")
.type(IndexTypeEnum.UNIQUE.getCode())
.comment("唯一索引")
.comment("unique index")
.columnList(Lists.newArrayList(TableIndexColumn.builder()
.columnName("number")
.build()))
.build());
// index DATA_OPS_TEMPLATE_TEST_1673093980449_idx_number_string (number, date) comment '联合索引'
// index DATA_OPS_TEMPLATE_TEST_1673093980449_idx_number_string (number, date) comment 'Union index'
tableIndexList.add(TableIndex.builder()
.name(tableName + "_idx_number_string")
.type(IndexTypeEnum.NORMAL.getCode())
.comment("联合索引")
.comment("Union index")
.columnList(Lists.newArrayList(TableIndexColumn.builder()
.columnName("number")
.build(),
@ -308,9 +308,9 @@ public class TableOperationsTest extends BaseTest {
.columnName("date")
.build()))
.build());
// 构建sql
// build sql
List<Sql> buildTableSqlList = tableService.buildSql(null, newTable).getData();
log.info("创建表的结构语句是:{}", JSON.toJSONString(buildTableSqlList));
log.info("The structural statement to create a table is:{}", JSON.toJSONString(buildTableSqlList));
for (Sql sql : buildTableSqlList) {
DlExecuteParam templateQueryParam = new DlExecuteParam();
templateQueryParam.setConsoleId(consoleId);
@ -319,10 +319,10 @@ public class TableOperationsTest extends BaseTest {
dlTemplateService.execute(templateQueryParam);
}
// 校验表结构
// Check table structure
checkTable(tableName, dialectProperties, dataSourceId);
// 去数据库查询表结构
// Go to the database to query the table structure
TableQueryParam tablePageQueryParam = new TableQueryParam();
tablePageQueryParam.setDataSourceId(dataSourceId);
tablePageQueryParam.setDatabaseName(dialectProperties.getDatabaseName());
@ -331,20 +331,20 @@ public class TableOperationsTest extends BaseTest {
.columnList(Boolean.TRUE)
.indexList(Boolean.TRUE)
.build()).getData();
log.info("分析数据返回{}", JSON.toJSONString(table));
Assertions.assertNotNull(table, "查询表结构失败");
log.info("Analyzing data returns {}", JSON.toJSONString(table));
Assertions.assertNotNull(table, "Query table structure failed");
Table oldTable = table;
Assertions.assertEquals(dialectProperties.toCase(tableName), oldTable.getName(), "查询表结构失败");
Assertions.assertEquals("测试表", oldTable.getComment(), "查询表结构失败");
Assertions.assertEquals(dialectProperties.toCase(tableName), oldTable.getName(), "Query table structure failed");
Assertions.assertEquals("Test table", oldTable.getComment(), "Query table structure failed");
// 修改表结构
// 构建sql
// Modify table structure
// build sql
log.info("oldTable{}", JSON.toJSONString(oldTable));
log.info("newTable{}", JSON.toJSONString(newTable));
buildTableSqlList = tableService.buildSql(oldTable, newTable).getData();
log.info("修改表结构是:{}", JSON.toJSONString(buildTableSqlList));
log.info("Modify the table structure: {}", JSON.toJSONString(buildTableSqlList));
Assertions.assertTrue(!buildTableSqlList.isEmpty(), "构建sql失败");
// 重新去查询下 这样有2个对象
// Lets query again. There will be 2 objects.
tablePageQueryParam = new TableQueryParam();
tablePageQueryParam.setDataSourceId(dataSourceId);
tablePageQueryParam.setDatabaseName(dialectProperties.getDatabaseName());
@ -354,45 +354,45 @@ public class TableOperationsTest extends BaseTest {
.indexList(Boolean.TRUE)
.build()).getData();
// 修改字段
// Modify fields
// 新增一个字段
// Add a new field
newTable.getColumnList().add(TableColumn.builder()
.name("add_string")
.columnType("varchar(20)")
.comment("新增的字符串")
.comment("New string")
.build());
// 新增一个索引
// Add a new index
newTable.getIndexList().add(TableIndex.builder()
.name(tableName + "_idx_string_new")
.type(IndexTypeEnum.NORMAL.getCode())
.comment("新的字符串索引")
.comment("new string index")
.columnList(Lists.newArrayList(TableIndexColumn.builder()
.columnName("add_string")
.collation(CollationEnum.DESC.getCode())
.build()))
.build());
// 查询表结构变更
// Query table structure changes
log.info("oldTable{}", JSON.toJSONString(oldTable));
log.info("newTable{}", JSON.toJSONString(newTable));
buildTableSqlList = tableService.buildSql(oldTable, newTable).getData();
log.info("修改表结构是:{}", JSON.toJSONString(buildTableSqlList));
log.info("Modify the table structure: {}", JSON.toJSONString(buildTableSqlList));
// 删除表结构
// Delete table structure
dropTable(tableName, dialectProperties, dataSourceId);
}
private void dropTable(String tableName, DialectProperties dialectProperties, Long dataSourceId) {
// 删除表结构
// Delete table structure
DropParam dropParam = DropParam.builder()
.dataSourceId(dataSourceId)
.databaseName(dialectProperties.getDatabaseName())
.tableName(dialectProperties.toCase(tableName))
.build();
tableService.drop(dropParam);
// 查询表结构
// Query table structure
TablePageQueryParam tablePageQueryParam = new TablePageQueryParam();
tablePageQueryParam.setDataSourceId(dataSourceId);
tablePageQueryParam.setDatabaseName(dialectProperties.getDatabaseName());
@ -401,12 +401,12 @@ public class TableOperationsTest extends BaseTest {
.columnList(Boolean.TRUE)
.indexList(Boolean.TRUE)
.build()).getData();
log.info("删除表后数据返回{}", JSON.toJSONString(tableList));
Assertions.assertEquals(0L, tableList.size(), "查询表结构失败");
log.info("After deleting the table, the data returns {}", JSON.toJSONString(tableList));
Assertions.assertEquals(0L, tableList.size(), "Query table structure failed");
}
private void checkTable(String tableName, DialectProperties dialectProperties, Long dataSourceId) {
// 查询表结构
// Query table structure
TablePageQueryParam tablePageQueryParam = new TablePageQueryParam();
tablePageQueryParam.setDataSourceId(dataSourceId);
tablePageQueryParam.setDatabaseName(dialectProperties.getDatabaseName());
@ -416,50 +416,50 @@ public class TableOperationsTest extends BaseTest {
.indexList(Boolean.TRUE)
.build()).getData();
log.info("分析数据返回{}", JSON.toJSONString(tableList));
Assertions.assertEquals(1L, tableList.size(), "查询表结构失败");
log.info("Analyzing data returns {}", JSON.toJSONString(tableList));
Assertions.assertEquals(1L, tableList.size(), "Query table structure failed");
Table table = tableList.get(0);
Assertions.assertEquals(dialectProperties.toCase(tableName), table.getName(), "查询表结构失败");
Assertions.assertEquals("测试表", table.getComment(), "查询表结构失败");
Assertions.assertEquals(dialectProperties.toCase(tableName), table.getName(), "Query table structure failed");
Assertions.assertEquals("Test table", table.getComment(), "Query table structure failed");
TableQueryParam tableQueryParam = new TableQueryParam();
tableQueryParam.setTableName(table.getName());
tableQueryParam.setDataSourceId(dataSourceId);
tableQueryParam.setDatabaseName(dialectProperties.getDatabaseName());
List<TableColumn> columnList = tableService.queryColumns(tableQueryParam);
Assertions.assertEquals(4L, columnList.size(), "查询表结构失败");
Assertions.assertEquals(4L, columnList.size(), "Query table structure failed");
TableColumn id = columnList.get(0);
Assertions.assertEquals(dialectProperties.toCase("id"), id.getName(), "查询表结构失败");
Assertions.assertEquals("主键自增", id.getComment(), "查询表结构失败");
Assertions.assertTrue(id.getAutoIncrement(), "查询表结构失败");
//Assertions.assertFalse(id.getNullable(), "查询表结构失败");
Assertions.assertTrue(id.getPrimaryKey(), "查询表结构失败");
Assertions.assertEquals(dialectProperties.toCase("id"), id.getName(), "Query table structure failed");
Assertions.assertEquals("Primary key auto-increment", id.getComment(), "Query table structure failed");
Assertions.assertTrue(id.getAutoIncrement(), "Query table structure failed");
//Assertions.assertFalse(id.getNullable(), "Query table structure failed");
Assertions.assertTrue(id.getPrimaryKey(), "Query table structure failed");
TableColumn string = columnList.get(3);
Assertions.assertEquals(dialectProperties.toCase("string"), string.getName(), "查询表结构失败");
//Assertions.assertTrue(string.getNullable(), "查询表结构失败");
Assertions.assertEquals(dialectProperties.toCase("string"), string.getName(), "Query table structure failed");
//Assertions.assertTrue(string.getNullable(), "Query table structure failed");
Assertions.assertEquals("DATA", TestUtils.unWrapperDefaultValue(string.getDefaultValue()),
"查询表结构失败");
"Query table structure failed");
List<TableIndex> tableIndexList = tableService.queryIndexes(tableQueryParam);
Assertions.assertEquals(4L, tableIndexList.size(), "查询表结构失败");
Assertions.assertEquals(4L, tableIndexList.size(), "Query table structure failed");
Map<String, TableIndex> tableIndexMap = EasyCollectionUtils.toIdentityMap(tableIndexList,
TableIndex::getName);
TableIndex idxDate = tableIndexMap.get(dialectProperties.toCase(tableName + "_idx_date"));
Assertions.assertEquals("日期索引", idxDate.getComment(), "查询表结构失败");
Assertions.assertEquals(IndexTypeEnum.NORMAL.getCode(), idxDate.getType(), "查询表结构失败");
Assertions.assertEquals(1L, idxDate.getColumnList().size(), "查询表结构失败");
Assertions.assertEquals("date index", idxDate.getComment(), "Query table structure failed");
Assertions.assertEquals(IndexTypeEnum.NORMAL.getCode(), idxDate.getType(), "Query table structure failed");
Assertions.assertEquals(1L, idxDate.getColumnList().size(), "Query table structure failed");
Assertions.assertEquals(dialectProperties.toCase("date"), idxDate.getColumnList().get(0).getColumnName(),
"查询表结构失败");
"Query table structure failed");
Assertions.assertEquals(CollationEnum.DESC.getCode(), idxDate.getColumnList().get(0).getCollation(),
"查询表结构失败");
"Query table structure failed");
TableIndex ukNumber = tableIndexMap.get(dialectProperties.toCase(tableName + "_uk_number"));
Assertions.assertEquals("唯一索引", ukNumber.getComment(), "查询表结构失败");
Assertions.assertEquals(IndexTypeEnum.UNIQUE.getCode(), ukNumber.getType(), "查询表结构失败");
Assertions.assertEquals("unique index", ukNumber.getComment(), "Query table structure failed");
Assertions.assertEquals(IndexTypeEnum.UNIQUE.getCode(), ukNumber.getType(), "Query table structure failed");
TableIndex idxNumberString = tableIndexMap.get(dialectProperties.toCase(tableName + "_idx_number_string"));
Assertions.assertEquals(2, idxNumberString.getColumnList().size(), "查询表结构失败");
Assertions.assertEquals(2, idxNumberString.getColumnList().size(), "Query table structure failed");
}
@Test
@ -478,21 +478,21 @@ public class TableOperationsTest extends BaseTest {
dataSourceCreateParam.setPassword(dialectProperties.getPassword());
dataSourceService.preConnect(dataSourceCreateParam);
// 创建控制台
// Create a console
ConsoleConnectParam consoleCreateParam = new ConsoleConnectParam();
consoleCreateParam.setDataSourceId(dataSourceId);
consoleCreateParam.setConsoleId(consoleId);
consoleCreateParam.setDatabaseName(dialectProperties.getDatabaseName());
consoleService.createConsole(consoleCreateParam);
// 创建表结构
// Create table structure
DlExecuteParam templateQueryParam = new DlExecuteParam();
templateQueryParam.setConsoleId(consoleId);
templateQueryParam.setDataSourceId(dataSourceId);
templateQueryParam.setSql(dialectProperties.getDropTableSql(TABLE_NAME));
dlTemplateService.execute(templateQueryParam);
} catch (Exception e) {
log.warn("删除表结构失败.", e);
log.warn("Failed to delete table structure.", e);
}
}
}

View File

@ -49,17 +49,17 @@ public class ClickHouseDialectProperties implements DialectProperties {
+ " number int,\n"
+ " string varchar(100) default 'DATA'\n"
+ ");\n";
sql += "comment on table " + tableName + " is '测试表';\n";
sql += "comment on column " + tableName + ".id is '主键自增';\n";
sql += "comment on column " + tableName + ".date is '日期';\n";
sql += "comment on column " + tableName + ".number is '长整型';\n";
sql += "comment on column " + tableName + ".string is '名字';\n";
sql += "comment on table " + tableName + " is 'Test table';\n";
sql += "comment on column " + tableName + ".id is 'Primary key auto-increment';\n";
sql += "comment on column " + tableName + ".date is 'date';\n";
sql += "comment on column " + tableName + ".number is 'long integer';\n";
sql += "comment on column " + tableName + ".string is 'name';\n";
sql += "create index " + tableName + "idx_date on " + tableName + " (date desc);";
sql += "create unique index " + tableName + "_uk_number on " + tableName + " (number);";
sql += "create index " + tableName + "_idx_number_string on " + tableName + " (number, date);";
sql += "comment on index " + tableName + "_uk_number is '日期索引';";
sql += "comment on index " + tableName + "_uk_number is '唯一索引';";
sql += "comment on index " + tableName + "_idx_number_string is '联合索引';";
sql += "comment on index " + tableName + "_uk_number is 'date index';";
sql += "comment on index " + tableName + "_uk_number is 'unique index';";
sql += "comment on index " + tableName + "_idx_number_string is 'Union index';";
return sql;
}

View File

@ -5,35 +5,35 @@ import java.util.Date;
/**
* 方言配置
* Dialect configuration
*
* @author Jiaju Zhuang
*/
public interface DialectProperties {
/**
* 支持的数据库类型
* Supported database types
*
* @return
*/
String getDbType();
/**
* 连接
* connection
*
* @return
*/
String getUrl();
/**
* 异常连接
* Abnormal connection
*
* @return
*/
String getErrorUrl();
/**
* 用户名
* userName
*
* @return
*/
@ -41,69 +41,69 @@ public interface DialectProperties {
String getUsername();
/**
* 密码
* password
*
* @return
*/
String getPassword();
/**
* 数据库名称
* Name database
*
* @return
*/
String getDatabaseName();
/**
* 大小写看具体的数据库决定:
* 创建表表结构 : 测试表
* 字段:
* id 主键自增
* date 日期 非空
* number 长整型
* string 字符串 长度100 默认值 "DATA"
* The case depends on the specific database:
* Create table structure: test table
* Field:
* id primary key auto-increment
* date date is not empty
* number long integer type
* string string length 100 default value "DATA"
*
* 索引(加上$tableName_ 原因是 有些数据库索引是全局唯一的)
* $tableName_idx_date 日期索引 倒序
* $tableName_uk_number 唯一索引
* $tableName_idx_number_string 联合索引
* Index (plus $tableName_ because some database indexes are globally unique):
* $tableName_idx_date date index reverse order
* $tableName_uk_number unique index
* $tableName_idx_number_string joint index
*
* @return
*/
String getCrateTableSql(String tableName);
/**
* 创建表表结构
* Create table structure
*
* @return
*/
String getDropTableSql(String tableName);
/**
* 创建一条数据
* Create a piece of data
*
* @return
*/
String getInsertSql(String tableName, Date date, Long number, String string);
/**
* 查询一条查询sql
* Query a query sql
*
* @return
*/
String getSelectSqlById(String tableName, Long id);
/**
* 获取一条表结构不存在的sql
* Get a sql whose table structure does not exist
*
* @return
*/
String getTableNotFoundSqlById(String tableName);
/**
* 转换大小写
* 有些数据库表结构默认存储大写
* 有些数据库默认存储小写
* Convert case
* Some database table structures store uppercase letters by default
* Some databases store lowercase by default
*
* @param string
* @return

View File

@ -48,21 +48,21 @@ public class H2DialectProperties implements DialectProperties {
@Override
public String getCrateTableSql(String tableName) {
// TODO druid有sql解析的bug
// TODO druid has sql parsing bug
String sql = "CREATE TABLE `" + tableName + "`\n\t"
+ "(\n\t"
+ " `id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT '主键自增',\n\t"
+ " `date` datetime not null COMMENT '日期',\n\t"
+ " `number` bigint COMMENT '长整型',\n\t"
+ " `string` VARCHAR(100) default 'DATA' COMMENT '名字'\n\t"
+ " `id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT 'Primary key auto-increment',\n\t"
+ " `date` datetime not null COMMENT 'date',\n\t"
+ " `number` bigint COMMENT 'long integer',\n\t"
+ " `string` VARCHAR(100) default 'DATA' COMMENT 'name'\n\t"
+ ");\n\t";
sql += "comment on table " + tableName + " is '测试表';\n\t";
sql += "comment on table " + tableName + " is 'Test table';\n\t";
sql += "create index " + tableName + "_idx_date on " + tableName + "(DATE desc);\n\t";
sql += "comment on index " + tableName + "_idx_date is '日期索引';\n\t";
sql += "comment on index " + tableName + "_idx_date is 'date index';\n\t";
sql += "create unique index " + tableName + "_uk_number on " + tableName + "(NUMBER);\n\t";
sql += "comment on index " + tableName + "_uk_number is '唯一索引';\n\t";
sql += "comment on index " + tableName + "_uk_number is 'unique index';\n\t";
sql += "create index " + tableName + "_idx_number_string on " + tableName + "(NUMBER, DATE);\n\t";
sql += "comment on index " + tableName + "_idx_number_string is '联合索引';\n\t";
sql += "comment on index " + tableName + "_idx_number_string is 'Union index';\n\t";
return sql;
}

View File

@ -50,14 +50,14 @@ public class MysqlDialectProperties implements DialectProperties {
public String getCrateTableSql(String tableName) {
return "CREATE TABLE `" + tableName + "`\n\t"
+ "(\n\t"
+ " `id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT '主键自增',\n\t"
+ " `date` datetime(3) not null COMMENT '日期',\n\t"
+ " `number` bigint COMMENT '长整型',\n\t"
+ " `string` VARCHAR(100) default 'DATA' COMMENT '名字',\n\t"
+ " index " + tableName + "_idx_date (date desc) comment '日期索引',\n\t"
+ " unique " + tableName + "_uk_number (number) comment '唯一索引',\n\t"
+ " index " + tableName + "_idx_number_string (number, date) comment '联合索引'\n\t"
+ ") COMMENT ='测试表';";
+ " `id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT 'Primary key auto-increment',\n\t"
+ " `date` datetime(3) not null COMMENT 'date',\n\t"
+ " `number` bigint COMMENT 'long integer',\n\t"
+ " `string` VARCHAR(100) default 'DATA' COMMENT 'name',\n\t"
+ " index " + tableName + "_idx_date (date desc) comment 'date index',\n\t"
+ " unique " + tableName + "_uk_number (number) comment 'unique index',\n\t"
+ " index " + tableName + "_idx_number_string (number, date) comment 'Union index'\n\t"
+ ") COMMENT ='Test table';";
}
@Override

View File

@ -43,14 +43,14 @@ public class OracleDialectProperties implements DialectProperties {
public String getCrateTableSql(String tableName) {
return "CREATE TABLE `" + tableName + "`\n\t"
+ "(\n\t"
+ " `id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT '主键自增',\n\t"
+ " `date` datetime(3) not null COMMENT '日期',\n\t"
+ " `number` bigint COMMENT '长整型',\n\t"
+ " `string` VARCHAR(100) default 'DATA' COMMENT '名字',\n\t"
+ " index " + tableName + "_idx_date (date desc) comment '日期索引',\n\t"
+ " unique " + tableName + "_uk_number (number) comment '唯一索引',\n\t"
+ " index " + tableName + "_idx_number_string (number, date) comment '联合索引'\n\t"
+ ") COMMENT ='测试表';";
+ " `id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT 'Primary key auto-increment',\n\t"
+ " `date` datetime(3) not null COMMENT 'date',\n\t"
+ " `number` bigint COMMENT 'long integer',\n\t"
+ " `string` VARCHAR(100) default 'DATA' COMMENT 'name',\n\t"
+ " index " + tableName + "_idx_date (date desc) comment 'date index',\n\t"
+ " unique " + tableName + "_uk_number (number) comment 'unique index',\n\t"
+ " index " + tableName + "_idx_number_string (number, date) comment 'Union index'\n\t"
+ ") COMMENT ='Test table';";
}
@Override

View File

@ -14,7 +14,7 @@ import org.springframework.stereotype.Component;
/**
* @author jipengfei
* @version : PgDialectProperties.java, v 0.1 2022年12月13日 21:48 jipengfei Exp $
* @version : PgDialectProperties.java, v 0.1 December 13, 2022 21:48 jipengfei Exp $
*/
@Component
public class PostgresqlDialectProperties implements DialectProperties {
@ -59,17 +59,17 @@ public class PostgresqlDialectProperties implements DialectProperties {
+ " number int,\n"
+ " string varchar(100) default 'DATA'\n"
+ ");\n";
sql += "comment on table " + tableName + " is '测试表';\n";
sql += "comment on column " + tableName + ".id is '主键自增';\n";
sql += "comment on column " + tableName + ".date is '日期';\n";
sql += "comment on column " + tableName + ".number is '长整型';\n";
sql += "comment on column " + tableName + ".string is '名字';\n";
sql += "comment on table " + tableName + " is 'Test table';\n";
sql += "comment on column " + tableName + ".id is 'Primary key auto-increment';\n";
sql += "comment on column " + tableName + ".date is 'date';\n";
sql += "comment on column " + tableName + ".number is 'long integer';\n";
sql += "comment on column " + tableName + ".string is 'name';\n";
sql += "create index " + tableName + "idx_date on " + tableName + " (date desc);";
sql += "create unique index " + tableName + "_uk_number on " + tableName + " (number);";
sql += "create index " + tableName + "_idx_number_string on " + tableName + " (number, date);";
sql += "comment on index " + tableName + "_uk_number is '日期索引';";
sql += "comment on index " + tableName + "_uk_number is '唯一索引';";
sql += "comment on index " + tableName + "_idx_number_string is '联合索引';";
sql += "comment on index " + tableName + "_uk_number is 'date index';";
sql += "comment on index " + tableName + "_uk_number is 'unique index';";
sql += "comment on index " + tableName + "_idx_number_string is 'Union index';";
return sql;
}

View File

@ -48,14 +48,14 @@ public class SQLITEDialectProperties implements DialectProperties{
public String getCrateTableSql(String tableName) {
return "CREATE TABLE `" + tableName + "`\n\t"
+ "(\n\t"
+ " `id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT '主键自增',\n\t"
+ " `date` datetime(3) not null COMMENT '日期',\n\t"
+ " `number` bigint COMMENT '长整型',\n\t"
+ " `string` VARCHAR(100) default 'DATA' COMMENT '名字',\n\t"
+ " index " + tableName + "_idx_date (date desc) comment '日期索引',\n\t"
+ " unique " + tableName + "_uk_number (number) comment '唯一索引',\n\t"
+ " index " + tableName + "_idx_number_string (number, date) comment '联合索引'\n\t"
+ ") COMMENT ='测试表';";
+ " `id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT 'Primary key auto-increment',\n\t"
+ " `date` datetime(3) not null COMMENT 'date',\n\t"
+ " `number` bigint COMMENT 'long integer',\n\t"
+ " `string` VARCHAR(100) default 'DATA' COMMENT 'name',\n\t"
+ " index " + tableName + "_idx_date (date desc) comment 'date index',\n\t"
+ " unique " + tableName + "_uk_number (number) comment 'unique index',\n\t"
+ " index " + tableName + "_idx_number_string (number, date) comment 'Union index'\n\t"
+ ") COMMENT ='Test table';";
}
@Override

View File

@ -7,7 +7,7 @@ import ai.chat2db.spi.sql.Chat2DBContext;
import ai.chat2db.spi.sql.ConnectInfo;
/**
* 测试工具类
* Test tool class
*
* @author Jiaju Zhuang
*/
@ -16,7 +16,7 @@ public class TestUtils {
public static final AtomicLong ATOMIC_LONG = new AtomicLong();
/**
* 一个全局唯一的long
* a globally unique long
*
* @return
*/
@ -25,8 +25,8 @@ public class TestUtils {
}
/**
* 如果默认值类似于 'DATA'
* 则需要把'' 去掉
* If the default value is something like 'DATA'
* then you need to remove ''
*
* @param defaultValue
* @return

View File

@ -22,12 +22,12 @@ public class SQLParseTest {
Statements statements = CCJSqlParserUtil.parseStatements(sql);
// 如果是多条语句,解析后的实际类型是StatementList
// If there are multiple statements, the actual type after parsing is StatementList
// 遍历每个语句
// Iterate through each statement
for (Statement stmt : statements.getStatements()) {
// 如果是单条语句,实际类型是Statement
// If it is a single statement, the actual type is Statement
System.out.println(stmt.toString());
System.out.println(" dddd:"+SqlFormatter.format(stmt.toString()));

View File

@ -41,7 +41,7 @@ public class SqlTeset extends BaseTest {
@Test
public void test() {
// 创建
// creat
DataSourcePreConnectParam dataSourceCreateParam = new DataSourcePreConnectParam();
dataSourceCreateParam.setType("MYSQL");
@ -58,14 +58,14 @@ public class SqlTeset extends BaseTest {
List<Sql> sqlList = new ArrayList<>();
sqlList.add(Sql.builder().sql(createTable.getData()).build());
// 创建控制台
// Create a console
ConsoleConnectParam consoleCreateParam = new ConsoleConnectParam();
consoleCreateParam.setDataSourceId(1L);
consoleCreateParam.setConsoleId(1L);
consoleCreateParam.setDatabaseName(mysqlDialectProperties.getDatabaseName());
consoleService.createConsole(consoleCreateParam);
// 删除
// delete
DlExecuteParam templateQueryParam = new DlExecuteParam();
templateQueryParam.setConsoleId(1L);
templateQueryParam.setDataSourceId(1L);
@ -73,7 +73,7 @@ public class SqlTeset extends BaseTest {
ListResult<ExecuteResult> executeResult = dlTemplateService.execute(templateQueryParam);
log.info("result:{}", JSON.toJSONString(executeResult));
// 创建表结构
// Create table structure
templateQueryParam = new DlExecuteParam();
templateQueryParam.setConsoleId(1L);
templateQueryParam.setDataSourceId(1L);