Skip to content
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
2 changes: 1 addition & 1 deletion example/example-app/example-app-cmd-domain/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-app</artifactId>
<version>3.4.33</version>
<version>3.4.34</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-app/example-app-cmd-meta/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-app</artifactId>
<version>3.4.33</version>
<version>3.4.34</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-app/example-app-query/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-app</artifactId>
<version>3.4.33</version>
<version>3.4.34</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-example</artifactId>
<version>3.4.33</version>
<version>3.4.34</version>
<relativePath>../pom.xml</relativePath>
</parent>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion example/example-domain/example-domain-leave/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-domain</artifactId>
<version>3.4.33</version>
<version>3.4.34</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-domain/example-domain-user/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-domain</artifactId>
<version>3.4.33</version>
<version>3.4.34</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-domain/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-example</artifactId>
<version>3.4.33</version>
<version>3.4.34</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion example/example-infra/example-infra-flow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-infra</artifactId>
<version>3.4.33</version>
<version>3.4.34</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-infra/example-infra-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-infra</artifactId>
<version>3.4.33</version>
<version>3.4.34</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-infra/example-infra-security/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-infra</artifactId>
<version>3.4.33</version>
<version>3.4.34</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-infra/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-example</artifactId>
<version>3.4.33</version>
<version>3.4.34</version>
<relativePath>../pom.xml</relativePath>
</parent>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion example/example-interface/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-example</artifactId>
<version>3.4.33</version>
<version>3.4.34</version>
</parent>

<artifactId>example-interface</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion example/example-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>springboot-example</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.4.33</version>
<version>3.4.34</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</parent>

<artifactId>springboot-example</artifactId>
<version>3.4.33</version>
<version>3.4.34</version>

<name>springboot-example</name>
<description>springboot-example project for Spring Boot</description>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-parent</artifactId>
<version>3.4.33</version>
<version>3.4.34</version>

<url>https://github.com/codingapi/springboot-framewrok</url>
<name>springboot-parent</name>
Expand Down
2 changes: 1 addition & 1 deletion springboot-starter-data-authorization/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-parent</artifactId>
<version>3.4.33</version>
<version>3.4.34</version>
</parent>

<name>springboot-starter-data-authorization</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,130 @@
import java.sql.*;
import java.util.Enumeration;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.logging.Level;
import java.util.logging.Logger;

public class AuthorizationJdbcDriver implements Driver {

private Driver driver;
private static final ConcurrentMap<String, Driver> DRIVER_CACHE = new ConcurrentHashMap<>();
private static final Logger LOGGER = Logger.getLogger(AuthorizationJdbcDriver.class.getName());

static {
try {
DriverManager.registerDriver(new AuthorizationJdbcDriver());
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Failed to register AuthorizationJdbcDriver", e);
throw new RuntimeException("Failed to register AuthorizationJdbcDriver", e);
}
LOGGER.info("AuthorizationJdbcDriver initialized and registered");
}


@Override
public Connection connect(String url, Properties info) throws SQLException {
if (url == null) {
throw new SQLException("URL cannot be null");
}

Driver driver = findDriver(url);
if (driver == null) {
throw new SQLException("No suitable driver found for " + url);
}
return new ConnectionProxy(driver.connect(url, info));
}

@Override
public boolean acceptsURL(String url) throws SQLException {

/**
* 查找接受指定 URL 的真实 JDBC 驱动
*
* @param url JDBC URL
* @return 真实的 JDBC 驱动,如果未找到则返回 null
*/
private Driver findDriver(String url) throws SQLException {
if (url == null) {
return null;
}

// 从缓存中查找(使用 URL 前缀作为 key)
Driver cachedDriver = DRIVER_CACHE.get(url);
if (cachedDriver != null) {
try {
// 验证缓存的驱动仍然接受该 URL
if (cachedDriver.acceptsURL(url)) {
return cachedDriver;
} else {
// 如果缓存的驱动不再接受该 URL,从缓存中移除
DRIVER_CACHE.remove(url, cachedDriver);
}
} catch (SQLException e) {
// 如果验证失败,从缓存中移除并继续查找
DRIVER_CACHE.remove(url, cachedDriver);
LOGGER.log(Level.FINE, "Cached driver no longer accepts URL: " + url, e);
}
}

// 遍历所有已注册的驱动
Enumeration<Driver> drivers = DriverManager.getDrivers();
while (drivers.hasMoreElements()) {
Driver driver = drivers.nextElement();
if (driver.acceptsURL(url)) {
this.driver = driver;
return true;
if (driver.getClass().equals(AuthorizationJdbcDriver.class)) {
continue;
}
try {
if (driver.acceptsURL(url)) {
// 缓存驱动(使用 URL 的前缀作为 key,因为同一个数据库类型的 URL 前缀相同)
DRIVER_CACHE.putIfAbsent(url, driver);
return driver;
}
} catch (SQLException e) {
// 忽略单个驱动的异常,继续查找
LOGGER.log(Level.FINE, "Driver " + driver.getClass().getName() + " does not accept URL: " + url, e);
}
}
return false;
return null;
}

@Override
public boolean acceptsURL(String url) throws SQLException {
if (url == null) {
return false;
}
Driver driver = findDriver(url);
return driver != null;
}

@Override
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
Driver driver = findDriver(url);
if (driver == null) {
throw new SQLException("No suitable driver found for " + url);
}
return driver.getPropertyInfo(url, info);
}

@Override
public int getMajorVersion() {
return driver.getMajorVersion();
// 返回代理驱动的主版本号
return 1;
}

@Override
public int getMinorVersion() {
return driver.getMinorVersion();
// 返回代理驱动的次版本号
return 0;
}

@Override
public boolean jdbcCompliant() {
return driver.jdbcCompliant();
// 代理驱动本身不直接兼容 JDBC,它依赖于底层驱动
return false;
}


@Override
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
return driver.getParentLogger();
return LOGGER;
}
}
2 changes: 1 addition & 1 deletion springboot-starter-data-fast/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>springboot-parent</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.4.33</version>
<version>3.4.34</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion springboot-starter-flow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>springboot-parent</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.4.33</version>
<version>3.4.34</version>
</parent>

<name>springboot-starter-flow</name>
Expand Down
2 changes: 1 addition & 1 deletion springboot-starter-security/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>springboot-parent</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.4.33</version>
<version>3.4.34</version>
</parent>

<artifactId>springboot-starter-security</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion springboot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-parent</artifactId>
<version>3.4.33</version>
<version>3.4.34</version>
</parent>
<artifactId>springboot-starter</artifactId>

Expand Down