mirror of
https://github.com/vran-dev/databasir.git
synced 2025-08-09 17:48:14 +08:00
feat:support custom url pattern
This commit is contained in:
@@ -31,6 +31,7 @@ public enum DomainErrors implements DatabasirErrors {
|
||||
DATABASE_TYPE_NAME_DUPLICATE("A_10016", "数据库类型名已存在"),
|
||||
MUST_NOT_MODIFY_SYSTEM_DEFAULT_DATABASE_TYPE("A_10017", "禁止修改系统默认数据库类型"),
|
||||
DOWNLOAD_DRIVER_ERROR("A_10018", "驱动下载失败"),
|
||||
INVALID_DATABASE_TYPE_URL_PATTERN("A_10019", "不合法的 url pattern"),
|
||||
;
|
||||
|
||||
private final String errCode;
|
||||
|
@@ -23,4 +23,8 @@ public class DatabaseTypeCreateRequest {
|
||||
|
||||
@NotBlank
|
||||
private String jdbcProtocol;
|
||||
|
||||
@NotBlank
|
||||
private String urlPattern;
|
||||
|
||||
}
|
||||
|
@@ -21,6 +21,8 @@ public class DatabaseTypeDetailResponse {
|
||||
|
||||
private String jdbcProtocol;
|
||||
|
||||
private String urlPattern;
|
||||
|
||||
private Boolean deleted;
|
||||
|
||||
private Integer deletedToken;
|
||||
|
@@ -27,6 +27,8 @@ public class DatabaseTypePageResponse {
|
||||
|
||||
private Integer projectCount;
|
||||
|
||||
private String urlPattern;
|
||||
|
||||
private LocalDateTime updateAt;
|
||||
|
||||
private LocalDateTime createAt;
|
||||
|
@@ -27,4 +27,7 @@ public class DatabaseTypeUpdateRequest {
|
||||
|
||||
@NotBlank
|
||||
private String jdbcProtocol;
|
||||
|
||||
@NotBlank
|
||||
private String urlPattern;
|
||||
}
|
||||
|
@@ -107,7 +107,18 @@ public class DocumentService {
|
||||
documentPojoConverter.toColumnPojo(docId, tableMetaId, table.getColumns());
|
||||
tableColumnDocumentDao.batchInsert(tableColumnMetas);
|
||||
List<TableIndexDocumentPojo> tableIndexMetas =
|
||||
documentPojoConverter.toIndexPojo(docId, tableMetaId, table.getIndexes());
|
||||
documentPojoConverter.toIndexPojo(docId, tableMetaId, table.getIndexes())
|
||||
.stream()
|
||||
.filter(index -> {
|
||||
if (index.getName() != null) {
|
||||
return true;
|
||||
} else {
|
||||
log.warn("ignore table {} index {}, cause name is null", table.getName(), index);
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
tableIndexDocumentDao.batchInsert(tableIndexMetas);
|
||||
List<TableTriggerDocumentPojo> tableTriggerMetas =
|
||||
documentPojoConverter.toTriggerPojo(docId, tableMetaId, table.getTriggers());
|
||||
|
@@ -6,6 +6,7 @@ import com.databasir.dao.impl.DatabaseTypeDao;
|
||||
import com.databasir.dao.tables.pojos.DatabaseTypePojo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.File;
|
||||
@@ -22,6 +23,7 @@ import java.util.Properties;
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
@Order
|
||||
public class CustomDatabaseConnectionFactory implements DatabaseConnectionFactory {
|
||||
|
||||
private final DatabaseTypeDao databaseTypeDao;
|
||||
@@ -73,10 +75,13 @@ public class CustomDatabaseConnectionFactory implements DatabaseConnectionFactor
|
||||
throw DomainErrors.CONNECT_DATABASE_FAILED.exception("驱动初始化异常:" + e.getMessage());
|
||||
}
|
||||
|
||||
String urlPattern = type.getUrlPattern();
|
||||
String jdbcUrl = urlPattern.replace("{{jdbc.protocol}}", type.getJdbcProtocol())
|
||||
.replace("{{db.url}}", context.getUrl())
|
||||
.replace("{{db.name}}", context.getSchema());
|
||||
Properties info = new Properties();
|
||||
info.put("user", context.getUsername());
|
||||
info.put("password", context.getPassword());
|
||||
String jdbcUrl = type.getJdbcProtocol() + "://" + context.getUrl() + "/" + context.getSchema();
|
||||
return driver.connect(jdbcUrl, info);
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.databasir.core.infrastructure.connection;
|
||||
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.Connection;
|
||||
@@ -8,6 +9,7 @@ import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
@Component
|
||||
@Order(1)
|
||||
public class MysqlDatabaseConnectionFactory implements DatabaseConnectionFactory {
|
||||
|
||||
@Override
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.databasir.core.infrastructure.connection;
|
||||
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.Connection;
|
||||
@@ -8,6 +9,7 @@ import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
@Component
|
||||
@Order(2)
|
||||
public class PostgresqlDatabaseConnectionFactory implements DatabaseConnectionFactory {
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user