Skip to content

Commit

Permalink
Removes use of JAXB API via jackson-dataformat-xml
Browse files Browse the repository at this point in the history
  • Loading branch information
linghengqian committed Dec 12, 2023
1 parent f32600e commit a9c5fdd
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 99 deletions.
23 changes: 7 additions & 16 deletions distribution/proxy/src/main/release-docs/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,13 @@ The text of each license is the standard Apache 2.0 license.
httpcore5-h2 5.1.3: https://hc.apache.org/httpcomponents-core-5.1.x, Apache 2.0
httpcore5 5.1.3: https://hc.apache.org/httpcomponents-core-5.1.x, Apache 2.0
j2objc-annotations 1.3 https://github.com/google/j2objc/, Apache 2.0
jackson-annotations 2.14.0: http://github.com/FasterXML/jackson, Apache 2.0
jackson-core 2.14.0: http://github.com/FasterXML/jackson, Apache 2.0
jackson-databind 2.14.0: http://github.com/FasterXML/jackson, Apache 2.0
jackson-dataformat-yaml 2.14.0: http://github.com/FasterXML/jackson, Apache 2.0
jackson-datatype-jsr310 2.14.0: http://github.com/FasterXML/jackson, Apache 2.0
jackson-annotations 2.16.0: http://github.com/FasterXML/jackson, Apache 2.0
jackson-core 2.16.0: http://github.com/FasterXML/jackson, Apache 2.0
jackson-databind 2.16.0: http://github.com/FasterXML/jackson, Apache 2.0
jackson-dataformat-xml 2.16.0: https://github.com/FasterXML/jackson-dataformat-xml, Apache 2.0
jackson-dataformat-yaml 2.16.0: http://github.com/FasterXML/jackson, Apache 2.0
jackson-datatype-jdk8 2.16.0: http://github.com/FasterXML/jackson-modules-java8, Apache 2.0
jackson-datatype-jsr310 2.16.0: http://github.com/FasterXML/jackson, Apache 2.0
jcl-over-slf4j 1.7.36: https://github.com/qos-ch/slf4j, Apache 2.0
jetcd-api 0.7.6: https://github.com/etcd-io/jetcd, Apache 2.0
jetcd-common 0.7.6: https://github.com/etcd-io/jetcd, Apache 2.0
Expand Down Expand Up @@ -336,17 +338,6 @@ The text of each license is also included at licenses/LICENSE-[project].txt.
jts-io-common 1.19.0: https://github.com/locationtech/jts, EDL 1.0
jts-core 1.19.0: https://github.com/locationtech/jts, EDL 1.0

========================================================================
EDL licenses
========================================================================

The following components are provided under the EDL License. See project link for details.
The text of each license is also included at licenses/LICENSE-[project].txt.

jakarta.activation-api 1.2.2: https://github.com/jakartaee/jaf-api, EDL 1.0
jakarta.xml.bind-api 2.3.3: https://github.com/jakartaee/jaxb-api, EDL 1.0
jaxb-runtime 2.3.9 https://eclipse-ee4j.github.io/jaxb-ri/, EDL 1.0

========================================================================
EPL licenses
========================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,15 @@ spring.datasource.url=jdbc:shardingsphere:classpath:xxx.yaml

直接使用该数据源;或者将 ShardingSphereDataSource 配置在 JPA、Hibernate、MyBatis 等 ORM 框架中配合使用。

## 针对 Spring Boot OSS 3 的特殊处理
## 针对 Spring Boot OSS 3 的处理

Spring Boot OSS 3 对 Jakarta EE 和 Java 17 进行了 “大爆炸” 升级,涉及大量复杂情况。

对于正在使用 Java EE 8 API 及其实现的 ShardingSphere JDBC 而言,如果用户希望在 Spring Boot OSS 3 等基于 Jakarta EE 9+ API 的 Web
Framework 上使用 ShardingSphere JDBC,则需要引入 Java EE 8 的 JAXB 的实现。

这在 Maven 的 `pom.xml` 体现为如下内容。你也可以使用其他的 JAXB API 的实现。此配置同样适用于其他基于 Jakarta EE 的 Web Framework,如
ShardingSphere 的 XA 分布式事务尚未在 Spring Boot OSS 3 上就绪,此限制同样适用于其他基于 Jakarta EE 9+ 的 Web Framework,如
Quarkus 3,Micronaut Framework 4 和 Helidon 3。

用户仅需要配置如下。

```xml
<project>
<dependencies>
Expand All @@ -53,17 +52,10 @@ Quarkus 3,Micronaut Framework 4 和 Helidon 3。
<artifactId>shardingsphere-jdbc-core</artifactId>
<version>${shardingsphere.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.9</version>
</dependency>
</dependencies>
</project>
```

此外,ShardingSphere 的 XA 分布式事务尚未在 Spring Boot OSS 3 上就绪。

## 针对低版本的 Spring Boot OSS 2 的特殊处理

ShardingSphere 的所有特性均可在 Spring Boot OSS 2 上使用,但低版本的 Spring Boot OSS 可能需要手动指定 SnakeYAML 的版本为 2.2 。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,14 @@ The YAML configuration file in 'spring.datasource.url' currently support in two

Use this data source directly; or configure ShardingSphereDataSource to be used in conjunction with ORM frameworks such as JPA, Hibernate, and MyBatis.

## Special handling for Spring Boot OSS 3
## Handling for Spring Boot OSS 3

Spring Boot OSS 3 has made a "big bang" upgrade to Jakarta EE and Java 17, with all complications involved.

For ShardingSphere JDBC that is using the Java EE 8 API and its implementation, if you want to use ShardingSphere JDBC
on a Jakarta EE 9+ API-based web framework such as Spring Boot OSS 3, you need to introduce a JAXB implementation of
Java EE 8.
ShardingSphere's XA distributed transactions are not yet ready on Spring Boot OSS 3. This limitation also applies to other
Jakarta EE 9+ based Web Frameworks, such as Quarkus 3, Micronaut Framework 4 and Helidon 3.

This is reflected in Maven's `pom.xml` as follows. You can also use other JAXB API implementations. This configuration
also applies to other Jakarta EE-based Web Frameworks, such as Quarkus 3, Micronaut Framework 4 and Helidon 3.
Users only need to configure as follows.

```xml
<project>
Expand All @@ -54,17 +52,10 @@ also applies to other Jakarta EE-based Web Frameworks, such as Quarkus 3, Micron
<artifactId>shardingsphere-jdbc-core</artifactId>
<version>${shardingsphere.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.9</version>
</dependency>
</dependencies>
</project>
```

In addition, ShardingSphere's XA distributed transactions are not yet ready on Spring Boot OSS 3.

## Special handling for earlier versions of Spring Boot OSS 2

All features of ShardingSphere are available on Spring Boot OSS 2, but earlier versions of Spring Boot OSS may require
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,12 @@ weight = 2

- [arjuna-5.12.4.Final.jar](https://repo1.maven.org/maven2/org/jboss/narayana/arjunacore/arjuna/5.12.4.Final/arjuna-5.12.4.Final.jar)
- [common-5.12.4.Final.jar](https://repo1.maven.org/maven2/org/jboss/narayana/common/5.12.4.Final/common-5.12.4.Final.jar)
- [istack-commons-runtime-3.0.12.jar](https://repo1.maven.org/maven2/com/sun/istack/istack-commons-runtime/3.0.12/istack-commons-runtime-3.0.12.jar)
- [jakarta.activation-api-1.2.2.jar](https://repo1.maven.org/maven2/jakarta/activation/jakarta.activation-api/1.2.2/jakarta.activation-api-1.2.2.jar)
- [jakarta.xml.bind-api-2.3.3.jar](https://repo1.maven.org/maven2/jakarta/xml/bind/jakarta.xml.bind-api/2.3.3/jakarta.xml.bind-api-2.3.3.jar)
- [jaxb-runtime-2.3.9.jar](https://repo1.maven.org/maven2/org/glassfish/jaxb/jaxb-runtime/2.3.9/jaxb-runtime-2.3.9.jar)
- [jboss-connector-api_1.7_spec-1.0.0.Final.jar](https://repo1.maven.org/maven2/org/jboss/spec/javax/resource/jboss-connector-api_1.7_spec/1.0.0.Final/jboss-connector-api_1.7_spec-1.0.0.Final.jar)
- [jboss-logging-3.2.1.Final.jar](https://repo1.maven.org/maven2/org/jboss/logging/jboss-logging/3.2.1.Final/jboss-logging-3.2.1.Final.jar)
- [jboss-transaction-api_1.2_spec-1.0.0.Alpha3.jar](https://repo1.maven.org/maven2/org/jboss/spec/javax/transaction/jboss-transaction-api_1.2_spec/1.0.0.Alpha3/jboss-transaction-api_1.2_spec-1.0.0.Alpha3.jar)
- [jboss-transaction-spi-7.6.0.Final.jar](https://repo1.maven.org/maven2/org/jboss/jboss-transaction-spi/7.6.0.Final/jboss-transaction-spi-7.6.0.Final.jar)
- [jta-5.12.4.Final.jar](https://repo1.maven.org/maven2/org/jboss/narayana/jta/jta/5.12.4.Final/jta-5.12.4.Final.jar)
- [narayana-jts-integration-5.12.4.Final.jar](https://repo1.maven.org/maven2/org/jboss/narayana/jts/narayana-jts-integration/5.12.4.Final/narayana-jts-integration-5.12.4.Final.jar)
- [shardingsphere-transaction-xa-narayana.jar](https://mvnrepository.com/artifact/org.apache.shardingsphere/shardingsphere-transaction-xa-narayana)
- [txw2-2.3.9.jar](https://repo1.maven.org/maven2/org/glassfish/jaxb/txw2/2.3.9/txw2-2.3.9.jar)

请根据 `proxy` 版本下载对应 `shardingsphere-transaction-xa-narayana.jar` 文件。
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,12 @@ Adding Narayana dependencies requires downloading the following jar files and ad

- [arjuna-5.12.4.Final.jar](https://repo1.maven.org/maven2/org/jboss/narayana/arjunacore/arjuna/5.12.4.Final/arjuna-5.12.4.Final.jar)
- [common-5.12.4.Final.jar](https://repo1.maven.org/maven2/org/jboss/narayana/common/5.12.4.Final/common-5.12.4.Final.jar)
- [istack-commons-runtime-3.0.12.jar](https://repo1.maven.org/maven2/com/sun/istack/istack-commons-runtime/3.0.12/istack-commons-runtime-3.0.12.jar)
- [jakarta.activation-api-1.2.2.jar](https://repo1.maven.org/maven2/jakarta/activation/jakarta.activation-api/1.2.2/jakarta.activation-api-1.2.2.jar)
- [jakarta.xml.bind-api-2.3.3.jar](https://repo1.maven.org/maven2/jakarta/xml/bind/jakarta.xml.bind-api/2.3.3/jakarta.xml.bind-api-2.3.3.jar)
- [jaxb-runtime-2.3.9.jar](https://repo1.maven.org/maven2/org/glassfish/jaxb/jaxb-runtime/2.3.9/jaxb-runtime-2.3.9.jar)
- [jboss-connector-api_1.7_spec-1.0.0.Final.jar](https://repo1.maven.org/maven2/org/jboss/spec/javax/resource/jboss-connector-api_1.7_spec/1.0.0.Final/jboss-connector-api_1.7_spec-1.0.0.Final.jar)
- [jboss-logging-3.2.1.Final.jar](https://repo1.maven.org/maven2/org/jboss/logging/jboss-logging/3.2.1.Final/jboss-logging-3.2.1.Final.jar)
- [jboss-transaction-api_1.2_spec-1.0.0.Alpha3.jar](https://repo1.maven.org/maven2/org/jboss/spec/javax/transaction/jboss-transaction-api_1.2_spec/1.0.0.Alpha3/jboss-transaction-api_1.2_spec-1.0.0.Alpha3.jar)
- [jboss-transaction-spi-7.6.0.Final.jar](https://repo1.maven.org/maven2/org/jboss/jboss-transaction-spi/7.6.0.Final/jboss-transaction-spi-7.6.0.Final.jar)
- [jta-5.12.4.Final.jar](https://repo1.maven.org/maven2/org/jboss/narayana/jta/jta/5.12.4.Final/jta-5.12.4.Final.jar)
- [narayana-jts-integration-5.12.4.Final.jar](https://repo1.maven.org/maven2/org/jboss/narayana/jts/narayana-jts-integration/5.12.4.Final/narayana-jts-integration-5.12.4.Final.jar)
- [shardingsphere-transaction-xa-narayana.jar](https://mvnrepository.com/artifact/org.apache.shardingsphere/shardingsphere-transaction-xa-narayana)
- [txw2-2.3.9.jar](https://repo1.maven.org/maven2/org/glassfish/jaxb/txw2/2.3.9/txw2-2.3.9.jar)

Please download the corresponding `shardingsphere-transaction-xa-narayana.jar` file according to the `proxy` version.
5 changes: 4 additions & 1 deletion infra/util/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
</dependency>

<dependency>
Expand Down
13 changes: 0 additions & 13 deletions kernel/transaction/type/xa/provider/narayana/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,5 @@
<version>${jboss-logging.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
</dependency>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
</dependency>
</dependencies>
</project>
12 changes: 2 additions & 10 deletions mode/type/standalone/repository/provider/jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,8 @@
</dependency>

<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
</dependency>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,41 @@

package org.apache.shardingsphere.mode.repository.standalone.jdbc.sql;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import lombok.Getter;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
* JDBC repository SQL.
*/
@XmlRootElement(name = "sql")
@JacksonXmlRootElement(localName = "sql")
@Getter
public final class JDBCRepositorySQL {

@XmlAttribute(required = true)
@JacksonXmlProperty(isAttribute = true)
private String type;

@XmlAttribute(name = "driver-class-name", required = true)
@JacksonXmlProperty(localName = "driver-class-name", isAttribute = true)
private String driverClassName;

@XmlAttribute(name = "default")
@JacksonXmlProperty(localName = "default", isAttribute = true)
private boolean isDefault;

@XmlElement(name = "create-table", required = true)
@JacksonXmlProperty(localName = "create-table")
private String createTableSQL;

@XmlElement(name = "select-by-key", required = true)
@JacksonXmlProperty(localName = "select-by-key")
private String selectByKeySQL;

@XmlElement(name = "select-by-parent", required = true)
@JacksonXmlProperty(localName = "select-by-parent")
private String selectByParentKeySQL;

@XmlElement(name = "insert", required = true)
@JacksonXmlProperty(localName = "insert")
private String insertSQL;

@XmlElement(name = "update", required = true)
@JacksonXmlProperty(localName = "update")
private String updateSQL;

@XmlElement(name = "delete", required = true)
@JacksonXmlProperty(localName = "delete")
private String deleteSQL;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

package org.apache.shardingsphere.mode.repository.standalone.jdbc.sql;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.SneakyThrows;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import java.io.IOException;
import java.io.InputStream;
import java.net.JarURLConnection;
Expand Down Expand Up @@ -58,13 +58,15 @@ public final class JDBCRepositorySQLLoader {

private static final Collection<String> JAR_URL_PROTOCOLS = new HashSet<>(Arrays.asList("jar", "war", "zip", "wsjar", "vfszip"));

private static final ObjectMapper XML_MAPPER = new XmlMapper();

/**
* Load JDBC repository SQL.
*
* @param type type of JDBC repository SQL
* @return loaded JDBC repository SQL
*/
@SneakyThrows({JAXBException.class, IOException.class, URISyntaxException.class})
@SneakyThrows({IOException.class, URISyntaxException.class})
public static JDBCRepositorySQL load(final String type) {
Enumeration<URL> resources = Thread.currentThread().getContextClassLoader().getResources(ROOT_DIRECTORY);
if (null == resources) {
Expand Down Expand Up @@ -126,11 +128,11 @@ private static JDBCRepositorySQL loadFromDirectoryInNativeImage(final URL url, f
final JDBCRepositorySQL[] result = new JDBCRepositorySQL[1];
Files.walkFileTree(Paths.get(url.toURI()), new SimpleFileVisitor<Path>() {

@SneakyThrows(JAXBException.class)
@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attributes) throws IOException {
if (file.toString().endsWith(FILE_EXTENSION)) {
JDBCRepositorySQL provider = (JDBCRepositorySQL) JAXBContext.newInstance(JDBCRepositorySQL.class).createUnmarshaller().unmarshal(Files.newInputStream(file.toAbsolutePath()));
InputStream inputStream = Files.newInputStream(file.toAbsolutePath());
JDBCRepositorySQL provider = XML_MAPPER.readValue(inputStream, JDBCRepositorySQL.class);
if (provider.isDefault()) {
result[0] = provider;
}
Expand All @@ -149,11 +151,11 @@ private static JDBCRepositorySQL loadFromDirectoryLegacy(final URL url, final St
final JDBCRepositorySQL[] result = new JDBCRepositorySQL[1];
Files.walkFileTree(Paths.get(url.toURI()), new SimpleFileVisitor<Path>() {

@SneakyThrows(JAXBException.class)
@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attributes) throws IOException {
if (file.toString().endsWith(FILE_EXTENSION)) {
JDBCRepositorySQL provider = (JDBCRepositorySQL) JAXBContext.newInstance(JDBCRepositorySQL.class).createUnmarshaller().unmarshal(Files.newInputStream(file.toFile().toPath()));
InputStream inputStream = Files.newInputStream(file.toFile().toPath());
JDBCRepositorySQL provider = XML_MAPPER.readValue(inputStream, JDBCRepositorySQL.class);
if (provider.isDefault()) {
result[0] = provider;
}
Expand All @@ -168,7 +170,7 @@ public FileVisitResult visitFile(final Path file, final BasicFileAttributes attr
return result[0];
}

private static JDBCRepositorySQL loadFromJar(final URL url, final String type) throws JAXBException, IOException {
private static JDBCRepositorySQL loadFromJar(final URL url, final String type) throws IOException {
JDBCRepositorySQL result = null;
try (JarFile jar = ((JarURLConnection) url.openConnection()).getJarFile()) {
Enumeration<JarEntry> entries = jar.entries();
Expand All @@ -178,7 +180,7 @@ private static JDBCRepositorySQL loadFromJar(final URL url, final String type) t
continue;
}
final InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(name);
JDBCRepositorySQL provider = (JDBCRepositorySQL) JAXBContext.newInstance(JDBCRepositorySQL.class).createUnmarshaller().unmarshal(inputStream);
JDBCRepositorySQL provider = XML_MAPPER.readValue(inputStream, JDBCRepositorySQL.class);
if (provider.isDefault()) {
result = provider;
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<antlr4.version>4.10.1</antlr4.version>
<snakeyaml.version>2.2</snakeyaml.version>
<gson.version>2.10.1</gson.version>
<jackson.version>2.14.0</jackson.version>
<jackson.version>2.16.0</jackson.version>
<json-path.version>2.8.0</json-path.version>
<json-smart.version>2.4.10</json-smart.version>
<accessors-smart.version>2.4.9</accessors-smart.version>
Expand Down

0 comments on commit a9c5fdd

Please sign in to comment.