Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: fix the column TINYINT(1) in MySql being resolved to BIT type #6070

Open
wants to merge 17 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
matrix:
java: [ 8, 11, 17, 21 ]
springboot: [
2.7.16 -Dspring-framework.version=5.3.30,
2.7.17 -Dspring-framework.version=5.3.30,
2.6.15 -Dspring-framework.version=5.3.27,
2.5.15 -Dspring-framework.version=5.3.27,
2.4.13 -Dspring-framework.version=5.3.13,
Expand Down Expand Up @@ -89,7 +89,7 @@ jobs:
fail-fast: false
matrix:
springboot: [
2.7.16 -Dspring-framework.version=5.3.30,
2.7.17 -Dspring-framework.version=5.3.30,
2.6.15 -Dspring-framework.version=5.3.27,
2.5.15 -Dspring-framework.version=5.3.27,
2.4.13 -Dspring-framework.version=5.3.13,
Expand Down
10 changes: 10 additions & 0 deletions all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-rm-datasource-mysql5</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-rm-datasource-mysql8</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-sqlparser-core</artifactId>
Expand Down
10 changes: 10 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@
<artifactId>seata-rm-datasource</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-rm-datasource-mysql5</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-rm-datasource-mysql8</artifactId>
<version>${project.version}</version>
</dependency>
<!-- the 'seata-server' is an application, not a dependency
<dependency>
<groupId>io.seata</groupId>
Expand Down
4 changes: 2 additions & 2 deletions build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<!-- The version of spring-boot for 'spring-boot-dependencies' and 'spring-boot-maven-plugin' -->
<spring-boot.version>2.5.13</spring-boot.version>
<spring-framework.version>5.3.20</spring-framework.version>
<spring-boot.version>2.7.17</spring-boot.version>
<spring-framework.version>5.3.30</spring-framework.version>

<!-- For test -->
<junit-jupiter.version>5.8.2</junit-jupiter.version>
Expand Down
1 change: 1 addition & 0 deletions changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#PR_NO](https://github.com/seata/seata/pull/PR_NO)] A brief and accurate description of PR

### bugfix:
- [[#6070](https://github.com/seata/seata/pull/6070)] fix the column `TINYINT(1)` in MySql being resolved to `BIT` type
- [[#6090](https://github.com/seata/seata/pull/6090)] fix the TCC aspect exception handling process, do not wrapping the internal call exceptions
- [[#6075](https://github.com/seata/seata/pull/6075)] fix missing table alias for on update column of image SQL
- [[#6086](https://github.com/seata/seata/pull/6086)] fix oracle column alias cannot find
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 @@ -6,6 +6,7 @@
- [[#PR_NO](https://github.com/seata/seata/pull/PR_NO)] 准确简要的PR描述

### bugfix:
- [[#6070](https://github.com/seata/seata/pull/6070)] 修复 “MySql中的 `TINYINT(1)` 类型字段被解析为`BIT`,导致回滚后的值要么是0,要么是1。而不是原来的值。” 的问题。
- [[#6090](https://github.com/seata/seata/pull/6090)] 修复tcc切面异常处理过程,不对内部调用异常做包装处理,直接向外抛出
- [[#6075](https://github.com/seata/seata/pull/6075)] 修复镜像SQL对于on update列没有添加表别名的问题
- [[#6086](https://github.com/seata/seata/pull/6086)] 修复oracle alias 解析异常
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.seata.common.loader;

/**
* The DependsOn Exception
*
* @author wang.liang
*/
class DependsOnException extends Exception {

public DependsOnException(String message) {
super(message);
}

public DependsOnException(String message, Throwable cause) {
super(message, cause);
}

public DependsOnException(Throwable cause) {
super(cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import io.seata.common.Constants;
import io.seata.common.executor.Initialize;
import io.seata.common.util.CollectionUtils;
import io.seata.common.util.ReflectionUtil;
import io.seata.common.util.StringUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -338,7 +339,7 @@ private S load(String activateName, Object[] args, ClassLoader loader)
* @param activateName the activate name
* @param argsType the args type
* @param args the args
* @param loader the class loader
* @param loader the class loader
* @return the s
* @throws EnhancedServiceNotFoundException the enhanced service not found exception
*/
Expand All @@ -349,8 +350,8 @@ private S load(String activateName, Class<?>[] argsType, Object[] args, ClassLoa

/**
* get all implements
* @param loader the class loader
*
* @param loader the class loader
* @return list list
*/
private List<S> loadAll(ClassLoader loader) {
Expand Down Expand Up @@ -540,7 +541,7 @@ private void loadFile(String dir, ClassLoader loader, List<ExtensionDefinition<S
continue;
}
extensions.add(extensionDefinition);
} catch (LinkageError | ClassNotFoundException e) {
} catch (LinkageError | ClassNotFoundException | DependsOnException e) {
LOGGER.warn("Load [{}] class fail: {}", line, e.getMessage());
} catch (ClassCastException e) {
LOGGER.error("Load [{}] class fail, please make sure the extension" +
Expand Down Expand Up @@ -569,7 +570,7 @@ private void loadFile(String dir, ClassLoader loader, List<ExtensionDefinition<S

@SuppressWarnings("unchecked")
private ExtensionDefinition<S> getUnloadedExtensionDefinition(String className, ClassLoader loader)
throws ClassNotFoundException, ClassCastException {
throws ClassNotFoundException, ClassCastException, DependsOnException {
//Check whether the definition has been loaded
if (!isDefinitionContainsClazz(className, loader)) {
Class<?> clazz = Class.forName(className, true, loader);
Expand All @@ -581,11 +582,17 @@ private ExtensionDefinition<S> getUnloadedExtensionDefinition(String className,
String serviceName = null;
int priority = 0;
Scope scope = Scope.SINGLETON;
LoadLevel loadLevel = clazz.getAnnotation(LoadLevel.class);
if (loadLevel != null) {
serviceName = loadLevel.name();
priority = loadLevel.order();
scope = loadLevel.scope();
try {
LoadLevel loadLevel = clazz.getAnnotation(LoadLevel.class);
if (loadLevel != null) {
serviceName = loadLevel.name();
priority = loadLevel.order();
scope = loadLevel.scope();

this.verifyDependsOn(loadLevel);
}
} catch (ArrayStoreException | TypeNotPresentException e) {
throw new DependsOnException("Verify depends on classes failed.", e);
}
ExtensionDefinition<S> result = new ExtensionDefinition<>(serviceName, priority, scope, enhancedServiceClass);
classToDefinitionMap.put(clazz, result);
Expand All @@ -598,6 +605,20 @@ private ExtensionDefinition<S> getUnloadedExtensionDefinition(String className,
return null;
}

private void verifyDependsOn(LoadLevel loadLevel) throws DependsOnException {
// In java11 and above, a TypeNotPresentException will throw only after obtaining it once,
// if any dependent class does not exist.
@SuppressWarnings("unused")
Class<?>[] dependsOnClasses = loadLevel.dependsOnClasses();

// verify depends on class names
for (String className : loadLevel.dependsOnClassNames()) {
if (!ReflectionUtil.existsClass(className)) {
throw new DependsOnException("The dependent class '" + className + "' does not exist");
}
}
}

private boolean isDefinitionContainsClazz(String className, ClassLoader loader) {
for (Map.Entry<Class<?>, ExtensionDefinition<S>> entry : classToDefinitionMap.entrySet()) {
if (!entry.getKey().getName().equals(className)) {
Expand Down Expand Up @@ -651,6 +672,7 @@ private S initInstance(Class<S> implClazz, Class<?>[] argTypes, Object[] args)

/**
* Helper Class for hold a value.
*
* @param <T>
*/
private static class Holder<T> {
Expand Down
14 changes: 14 additions & 0 deletions common/src/main/java/io/seata/common/loader/LoadLevel.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,18 @@
* Scope enum.
*/
Scope scope() default Scope.SINGLETON;

/**
* Depends on classes.
*
* @return the classes
*/
Class<?>[] dependsOnClasses() default {};

/**
* Depends on class names.
*
* @return the class names
*/
String[] dependsOnClassNames() default {};
}
15 changes: 15 additions & 0 deletions common/src/main/java/io/seata/common/util/ReflectionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,21 @@ public static Class<?> getWrappedClass(Class<?> clazz) {
return clazz;
}

/**
* Whether the class exists
*
* @param className the class name
* @return the boolean
*/
public static boolean existsClass(String className) {
try {
getClassByName(className);
return true;
} catch (ClassNotFoundException e) {
return false;
}
}

//endregion


Expand Down
25 changes: 25 additions & 0 deletions common/src/test/java/io/seata/common/loader/AfricaHello.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.seata.common.loader;

/**
* The type Africa hello.
*
* @author wang.liang
*/
@LoadLevel(name = "AfricaHello", dependsOnClasses = String.class, dependsOnClassNames = "java.lang.Integer")
public class AfricaHello implements Hello3 {
}
25 changes: 25 additions & 0 deletions common/src/test/java/io/seata/common/loader/AustraliaHello.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.seata.common.loader;

/**
* The type Australia hello.
*
* @author wang.liang
*/
@LoadLevel(name = "AustraliaHello", dependsOnClassNames = "io.seata.Xxxxx")
public class AustraliaHello implements Hello3 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,10 @@ public void testUnloadByClassAndActivateName() throws NoSuchFieldException, Ille
assertThat(classToDefinitionMap.get(EnglishHello.class)).isNull();
}

@Test
public void testDependsOn() {
List<Hello3> hello3List = EnhancedServiceLoader.loadAll(Hello3.class);
assertThat(hello3List.size()).isEqualTo(1);
assertThat(hello3List.get(0).getClass()).isEqualTo(AfricaHello.class);
}
}
22 changes: 22 additions & 0 deletions common/src/test/java/io/seata/common/loader/Hello3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.seata.common.loader;

/**
* @author wang.liang
*/
interface Hello3 {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
io.seata.common.loader.AfricaHello
io.seata.common.loader.AustraliaHello
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @author ph3636
*/
@LoadLevel(name = "FastThreadLocalContextCore", order = Integer.MIN_VALUE + 1)
@LoadLevel(name = "FastThreadLocalContextCore", order = Integer.MIN_VALUE + 1, dependsOnClasses = FastThreadLocal.class)
public class FastThreadLocalContextCore implements ContextCore {

private FastThreadLocal<Map<String, Object>> fastThreadLocal = new FastThreadLocal<Map<String, Object>>() {
Expand Down
Loading
Loading