Skip to content

Commit

Permalink
optimize: add a compatible module to support io.seata APIs (#6283)
Browse files Browse the repository at this point in the history
  • Loading branch information
slievrly committed Jan 23, 2024
1 parent ec73332 commit 698080b
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 0 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 @@ -68,6 +68,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#6265](https://github.com/apache/incubator-seata/pull/6265)] optimization fails to build frontend on arm64
- [[#6267](https://github.com/apache/incubator-seata/pull/6267)] add Server deserialization validation
- [[#6275](https://github.com/apache/incubator-seata/pull/6275)] optimize the label's format in .asf.yaml
- [[#6283](https://github.com/apache/incubator-seata/pull/6283)] add a compatible module to support io.seata APIs

### security:
- [[#6069](https://github.com/apache/incubator-seata/pull/6069)] Upgrade Guava dependencies to fix security vulnerabilities
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 @@ -66,6 +66,7 @@
- [[#6265](https://github.com/apache/incubator-seata/pull/6265)] 优化在 arm64 上构建前端失败的问题
- [[#6267](https://github.com/apache/incubator-seata/pull/6267)] 增加 Server 反序列化校验
- [[#6275](https://github.com/apache/incubator-seata/pull/6275)] 优化.asf.yaml文件中的label格式
- [[#6283](https://github.com/apache/incubator-seata/pull/6283)] 增加兼容模块支持 io.seata APIs

### security:
- [[#6069](https://github.com/apache/incubator-seata/pull/6069)] 升级Guava依赖版本,修复安全漏洞
Expand Down
4 changes: 4 additions & 0 deletions compatible/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Seata-compatible
Starting from version 2.1.x, Seata's package name has been changed from "io.seata" to "org.apache.seata". To assist users with a smooth upgrade from older versions, we have implemented compatibility for the following commonly used APIs.
- RootContext

41 changes: 41 additions & 0 deletions compatible/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>io.seata</groupId>
<artifactId>seata-parent</artifactId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>seata-compatible</artifactId>
<packaging>pom</packaging>
<name>seata-compatible ${project.version}</name>
<description>compatible with io.seata API</description>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>seata-core</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
181 changes: 181 additions & 0 deletions compatible/src/main/java/io/seata/tmp/core/context/RootContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.tmp.core.context;

import java.util.Map;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import io.seata.core.model.BranchType;

/**
* The type Root context.
*/
public class RootContext {

/**
* Sets default branch type.
*
* @param defaultBranchType the default branch type
*/
public static void setDefaultBranchType(BranchType defaultBranchType) {
io.seata.core.context.RootContext.setDefaultBranchType(defaultBranchType);
}

/**
* Gets xid.
*
* @return the xid
*/
@Nullable
public static String getXID() {
return io.seata.core.context.RootContext.getXID();
}

/**
* Bind.
*
* @param xid the xid
*/
public static void bind(@Nonnull String xid) {
io.seata.core.context.RootContext.bind(xid);
}

/**
* Gets timeout.
*
* @return the timeout
*/
public static Integer getTimeout() {
return io.seata.core.context.RootContext.getTimeout();
}

/**
* Sets timeout.
*
* @param timeout the timeout
*/
public static void setTimeout(Integer timeout) {
io.seata.core.context.RootContext.setTimeout(timeout);
}

/**
* Bind global lock flag.
*/
public static void bindGlobalLockFlag() {
io.seata.core.context.RootContext.bindGlobalLockFlag();
}

/**
* Unbind string.
*
* @return the string
*/
@Nullable
public static String unbind() {
return io.seata.core.context.RootContext.unbind();
}

/**
* Unbind global lock flag.
*/
public static void unbindGlobalLockFlag() {
io.seata.core.context.RootContext.unbindGlobalLockFlag();
}

/**
* In global transaction boolean.
*
* @return the boolean
*/
public static boolean inGlobalTransaction() {
return io.seata.core.context.RootContext.inGlobalTransaction();
}

/**
* In tcc branch boolean.
*
* @return the boolean
*/
public static boolean inTccBranch() {
return io.seata.core.context.RootContext.inTccBranch();
}

/**
* In saga branch boolean.
*
* @return the boolean
*/
public static boolean inSagaBranch() {
return io.seata.core.context.RootContext.inSagaBranch();
}

/**
* Gets branch type.
*
* @return the branch type
*/
@Nullable
public static BranchType getBranchType() {
return io.seata.core.context.RootContext.getBranchType();
}

/**
* Bind branch type.
*
* @param branchType the branch type
*/
public static void bindBranchType(@Nonnull BranchType branchType) {
io.seata.core.context.RootContext.bindBranchType(branchType);
}

/**
* Unbind branch type branch type.
*
* @return the branch type
*/
@Nullable
public static BranchType unbindBranchType() {
return io.seata.core.context.RootContext.unbindBranchType();
}

/**
* Require global lock boolean.
*
* @return the boolean
*/
public static boolean requireGlobalLock() {
return io.seata.core.context.RootContext.requireGlobalLock();
}

/**
* Assert not in global transaction.
*/
public static void assertNotInGlobalTransaction() {
io.seata.core.context.RootContext.assertNotInGlobalTransaction();
}

/**
* Entries map.
*
* @return the map
*/
public static Map<String, Object> entries() {
return io.seata.core.context.RootContext.entries();
}
}

0 comments on commit 698080b

Please sign in to comment.