Skip to content

Commit

Permalink
optimize: remove mysql dependency from the distribution package (#6332)
Browse files Browse the repository at this point in the history
  • Loading branch information
slievrly authored Feb 17, 2024
1 parent 65610d0 commit f80a0fa
Show file tree
Hide file tree
Showing 9 changed files with 625 additions and 29 deletions.
1 change: 1 addition & 0 deletions changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#6330](https://github.com/apache/incubator-seata/pull/6330)] remove mariadb API
- [[#6329](https://github.com/apache/incubator-seata/pull/6312)] add saga subcomponent-level io.seata compatible api
- [[#6254](https://github.com/apache/incubator-seata/pull/6254)] optimize Hessian Serialize
- [[#6332](https://github.com/apache/incubator-seata/pull/6332)] remove mysql dependency from the distribution package
- [[#6343](https://github.com/apache/incubator-seata/pull/6343)] compatible with tm module and rm-datasource module

### security:
Expand Down
1 change: 1 addition & 0 deletions changes/zh-cn/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
- [[#6330](https://github.com/apache/incubator-seata/pull/6330)] 去除 mariadb API
- [[#6329](https://github.com/apache/incubator-seata/pull/6312)] 添加saga子组件的io.seata兼容性API
- [[#6254](https://github.com/apache/incubator-seata/pull/6254)] 优化Hessian 序列化
- [[#6332](https://github.com/apache/incubator-seata/pull/6332)] 分发包中移除 mysql 依赖
- [[#6343](https://github.com/apache/incubator-seata/pull/6343)] 兼容tm 模块和rm-datasource模块


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import java.util.Map;
import java.util.Objects;
import java.util.stream.Stream;

import javax.sql.DataSource;

import org.apache.seata.common.exception.StoreException;
import org.apache.seata.common.executor.Initialize;
import org.apache.seata.common.util.ConfigTools;
Expand Down Expand Up @@ -78,11 +80,36 @@ public DataSource provide() {
return this.dataSource;
}

public DataSource generate() {
validate();
return doGenerate();
}

public void validate() {
//valid driver class name
String driverClassName = getDriverClassName();
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (null == loader) {
throw new StoreException("class loader set error, you should not use the Bootstrap classloader");
}
try {
loader.loadClass(driverClassName);
} catch (ClassNotFoundException exx) {
String driverClassPath = null;
String folderPath = System.getProperty("loader.path");
if (null != folderPath) {
driverClassPath = folderPath + "/jdbc/";
}
throw new StoreException(String.format(
"the {%s} can't be found in the path %s, please copy database driver dependencies, such as `mysql-connector-java.jar` to the path.", driverClassName, driverClassPath));
}

}
/**
* generate the datasource
* @return datasource
*/
public abstract DataSource generate();
public abstract DataSource doGenerate();

/**
* Get db type db type.
Expand Down
Loading

0 comments on commit f80a0fa

Please sign in to comment.