chore(project): 添加项目配置文件和忽略规则
- 添加 Babel 配置文件支持 ES6+ 语法转换 - 添加 ESLint 忽略规则和配置文件 - 添加 Git 忽略规则文件 - 添加 Travis CI 配置文件 - 添加 1.4.2 版本变更日志文件 - 添加 Helm 图表辅助模板文件 - 添加 Helm 忽略规则文件
This commit is contained in:
46
serializer/seata-serializer-protobuf/pom.xml
Normal file
46
serializer/seata-serializer-protobuf/pom.xml
Normal file
@@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
<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-serializer</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>seata-serializer-protobuf</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>seata-serializer-protobuf ${project.version}</name>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>seata-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>seata-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-java</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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.serializer.protobuf;
|
||||
|
||||
import com.google.protobuf.MessageLite;
|
||||
import io.seata.common.exception.ShouldNeverHappenException;
|
||||
import io.seata.common.util.CollectionUtils;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class ProtobufHelper {
|
||||
|
||||
/**
|
||||
* Cache of parseFrom method
|
||||
*/
|
||||
ConcurrentMap<Class, Method> parseFromMethodMap = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* Cache of toByteArray method
|
||||
*/
|
||||
ConcurrentMap<Class, Method> toByteArrayMethodMap = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* {className:class}
|
||||
*/
|
||||
private ConcurrentMap<String, Class> requestClassCache = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param clazzName
|
||||
* @return
|
||||
*/
|
||||
public Class getPbClass(String clazzName) {
|
||||
return CollectionUtils.computeIfAbsent(requestClassCache, clazzName, key -> {
|
||||
// get the parameter and result
|
||||
Class clazz;
|
||||
try {
|
||||
clazz = Class.forName(clazzName);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new ShouldNeverHappenException("get class occurs exception", e);
|
||||
}
|
||||
if (clazz == void.class || !isProtoBufMessageClass(clazz)) {
|
||||
throw new ShouldNeverHappenException("class based protobuf: " + clazz.getName()
|
||||
+ ", only support return protobuf message!");
|
||||
}
|
||||
return clazz;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this class is assignable from MessageLite
|
||||
*
|
||||
* @param clazz unknown class
|
||||
* @return is assignable from MessageLite
|
||||
*/
|
||||
boolean isProtoBufMessageClass(Class clazz) {
|
||||
return clazz != null && MessageLite.class.isAssignableFrom(clazz);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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.serializer.protobuf;
|
||||
|
||||
import io.seata.common.exception.ShouldNeverHappenException;
|
||||
import io.seata.common.util.CollectionUtils;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class ProtobufInnerSerializer {
|
||||
|
||||
private static final ProtobufHelper PROTOBUF_HELPER = new ProtobufHelper();
|
||||
|
||||
/**
|
||||
* Encode method name
|
||||
*/
|
||||
private static final String METHOD_TOBYTEARRAY = "toByteArray";
|
||||
/**
|
||||
* Decode method name
|
||||
*/
|
||||
private static final String METHOD_PARSEFROM = "parseFrom";
|
||||
|
||||
public static byte[] serializeContent(Object request) {
|
||||
Class clazz = request.getClass();
|
||||
Method method = CollectionUtils.computeIfAbsent(PROTOBUF_HELPER.toByteArrayMethodMap, clazz, key -> {
|
||||
try {
|
||||
Method m = clazz.getMethod(METHOD_TOBYTEARRAY);
|
||||
m.setAccessible(true);
|
||||
return m;
|
||||
} catch (Exception e) {
|
||||
throw new ShouldNeverHappenException("Cannot found method " + clazz.getName()
|
||||
+ ".toByteArray(), please check the generated code.", e);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
return (byte[])method.invoke(request);
|
||||
} catch (Exception e) {
|
||||
throw new ShouldNeverHappenException("serialize occurs exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T deserializeContent(String responseClazz, byte[] content) {
|
||||
if (content == null || content.length == 0) {
|
||||
return null;
|
||||
}
|
||||
Class clazz = PROTOBUF_HELPER.getPbClass(responseClazz);
|
||||
|
||||
Method method = CollectionUtils.computeIfAbsent(PROTOBUF_HELPER.parseFromMethodMap, clazz, key -> {
|
||||
try {
|
||||
Method m = clazz.getMethod(METHOD_PARSEFROM, byte[].class);
|
||||
if (!Modifier.isStatic(m.getModifiers())) {
|
||||
throw new ShouldNeverHappenException("Cannot found static method " + clazz.getName()
|
||||
+ ".parseFrom(byte[]), please check the generated code");
|
||||
}
|
||||
m.setAccessible(true);
|
||||
return m;
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new ShouldNeverHappenException("Cannot found method " + clazz.getName()
|
||||
+ ".parseFrom(byte[]), please check the generated code", e);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
return (T)method.invoke(null, content);
|
||||
} catch (Exception e) {
|
||||
throw new ShouldNeverHappenException("Error when invoke " + clazz.getName() + ".parseFrom(byte[]).", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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.serializer.protobuf;
|
||||
|
||||
import com.google.protobuf.GeneratedMessageV3;
|
||||
import io.seata.common.loader.LoadLevel;
|
||||
import io.seata.core.serializer.Serializer;
|
||||
import io.seata.serializer.protobuf.convertor.PbConvertor;
|
||||
import io.seata.serializer.protobuf.manager.ProtobufConvertManager;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* The type Protobuf codec.
|
||||
*
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
@LoadLevel(name = "PROTOBUF", order = 0)
|
||||
public class ProtobufSerializer implements Serializer {
|
||||
|
||||
protected static final Charset UTF8 = StandardCharsets.UTF_8;
|
||||
|
||||
@Override
|
||||
public <T> byte[] serialize(T t) {
|
||||
if (t == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
//translate to pb
|
||||
final PbConvertor pbConvertor = ProtobufConvertManager.getInstance().fetchConvertor(
|
||||
t.getClass().getName());
|
||||
//for cross language,write FullName to data,which defines in proto file
|
||||
GeneratedMessageV3 newBody = (GeneratedMessageV3)pbConvertor.convert2Proto(t);
|
||||
byte[] body = ProtobufInnerSerializer.serializeContent(newBody);
|
||||
final String name = newBody.getDescriptorForType().getFullName();
|
||||
final byte[] nameBytes = name.getBytes(UTF8);
|
||||
ByteBuffer byteBuffer = ByteBuffer.allocate(4 + nameBytes.length + body.length);
|
||||
byteBuffer.putInt(nameBytes.length);
|
||||
byteBuffer.put(nameBytes);
|
||||
byteBuffer.put(body);
|
||||
byteBuffer.flip();
|
||||
byte[] content = new byte[byteBuffer.limit()];
|
||||
byteBuffer.get(content);
|
||||
return content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T deserialize(byte[] bytes) {
|
||||
if (bytes == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
|
||||
int clazzNameLength = byteBuffer.getInt();
|
||||
byte[] clazzName = new byte[clazzNameLength];
|
||||
byteBuffer.get(clazzName);
|
||||
byte[] body = new byte[bytes.length - clazzNameLength - 4];
|
||||
byteBuffer.get(body);
|
||||
final String descriptorName = new String(clazzName, UTF8);
|
||||
Class protobufClazz = ProtobufConvertManager.getInstance().fetchProtoClass(descriptorName);
|
||||
Object protobufObject = ProtobufInnerSerializer.deserializeContent(protobufClazz.getName(), body);
|
||||
//translate back to core model
|
||||
final PbConvertor pbConvertor = ProtobufConvertManager.getInstance().fetchReversedConvertor(protobufClazz.getName());
|
||||
Object newBody = pbConvertor.convert2Model(protobufObject);
|
||||
return (T)newBody;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.core.model.BranchType;
|
||||
import io.seata.serializer.protobuf.generated.AbstractBranchEndRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractTransactionRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.BranchCommitRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.BranchTypeProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.core.protocol.transaction.BranchCommitRequest;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class BranchCommitRequestConvertor implements PbConvertor<BranchCommitRequest, BranchCommitRequestProto> {
|
||||
@Override
|
||||
public BranchCommitRequestProto convert2Proto(BranchCommitRequest branchCommitRequest) {
|
||||
final short typeCode = branchCommitRequest.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
final AbstractTransactionRequestProto abstractTransactionRequestProto = AbstractTransactionRequestProto
|
||||
.newBuilder().setAbstractMessage(abstractMessage).build();
|
||||
|
||||
final String applicationData = branchCommitRequest.getApplicationData();
|
||||
final AbstractBranchEndRequestProto abstractBranchEndRequestProto = AbstractBranchEndRequestProto.newBuilder().
|
||||
setAbstractTransactionRequest(abstractTransactionRequestProto).setXid(branchCommitRequest.getXid())
|
||||
.setBranchId(branchCommitRequest.getBranchId()).setBranchType(
|
||||
BranchTypeProto.valueOf(branchCommitRequest.getBranchType().name())).setApplicationData(
|
||||
applicationData == null ? "" : applicationData).setResourceId(branchCommitRequest.getResourceId())
|
||||
.build();
|
||||
|
||||
BranchCommitRequestProto result = BranchCommitRequestProto.newBuilder().setAbstractBranchEndRequest(
|
||||
abstractBranchEndRequestProto).build();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BranchCommitRequest convert2Model(BranchCommitRequestProto branchCommitRequestProto) {
|
||||
BranchCommitRequest branchCommitRequest = new BranchCommitRequest();
|
||||
branchCommitRequest.setApplicationData(
|
||||
branchCommitRequestProto.getAbstractBranchEndRequest().getApplicationData());
|
||||
branchCommitRequest.setBranchId(branchCommitRequestProto.getAbstractBranchEndRequest().getBranchId());
|
||||
branchCommitRequest.setResourceId(branchCommitRequestProto.getAbstractBranchEndRequest().getResourceId());
|
||||
branchCommitRequest.setXid(branchCommitRequestProto.getAbstractBranchEndRequest().getXid());
|
||||
branchCommitRequest.setBranchType(
|
||||
BranchType.valueOf(branchCommitRequestProto.getAbstractBranchEndRequest().getBranchType().name()));
|
||||
|
||||
return branchCommitRequest;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.core.exception.TransactionExceptionCode;
|
||||
import io.seata.core.model.BranchStatus;
|
||||
import io.seata.core.protocol.ResultCode;
|
||||
import io.seata.serializer.protobuf.generated.AbstractBranchEndResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractResultMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractTransactionResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.BranchCommitResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.BranchStatusProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.serializer.protobuf.generated.ResultCodeProto;
|
||||
import io.seata.serializer.protobuf.generated.TransactionExceptionCodeProto;
|
||||
import io.seata.core.protocol.transaction.BranchCommitResponse;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class BranchCommitResponseConvertor implements PbConvertor<BranchCommitResponse, BranchCommitResponseProto> {
|
||||
@Override
|
||||
public BranchCommitResponseProto convert2Proto(BranchCommitResponse branchCommitResponse) {
|
||||
final short typeCode = branchCommitResponse.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
final String msg = branchCommitResponse.getMsg();
|
||||
final AbstractResultMessageProto abstractResultMessageProto = AbstractResultMessageProto.newBuilder().setMsg(
|
||||
msg == null ? "" : msg).setResultCode(ResultCodeProto.valueOf(branchCommitResponse.getResultCode().name()))
|
||||
.setAbstractMessage(abstractMessage).build();
|
||||
|
||||
final AbstractTransactionResponseProto abstractTransactionRequestProto = AbstractTransactionResponseProto
|
||||
.newBuilder().setAbstractResultMessage(abstractResultMessageProto).setTransactionExceptionCode(
|
||||
TransactionExceptionCodeProto.valueOf(branchCommitResponse.getTransactionExceptionCode().name()))
|
||||
.build();
|
||||
|
||||
final AbstractBranchEndResponseProto abstractBranchEndResponse = AbstractBranchEndResponseProto.newBuilder().
|
||||
setAbstractTransactionResponse(abstractTransactionRequestProto).setXid(branchCommitResponse.getXid())
|
||||
.setBranchId(branchCommitResponse.getBranchId()).setBranchStatus(
|
||||
BranchStatusProto.forNumber(branchCommitResponse.getBranchStatus().getCode())).build();
|
||||
|
||||
BranchCommitResponseProto result = BranchCommitResponseProto.newBuilder().setAbstractBranchEndResponse(
|
||||
abstractBranchEndResponse).build();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BranchCommitResponse convert2Model(BranchCommitResponseProto branchCommitResponseProto) {
|
||||
|
||||
BranchCommitResponse branchCommitResponse = new BranchCommitResponse();
|
||||
branchCommitResponse.setBranchId(branchCommitResponseProto.getAbstractBranchEndResponse().getBranchId());
|
||||
branchCommitResponse.setBranchStatus(
|
||||
BranchStatus.get(branchCommitResponseProto.getAbstractBranchEndResponse().getBranchStatusValue()));
|
||||
branchCommitResponse.setXid(branchCommitResponseProto.getAbstractBranchEndResponse().getXid());
|
||||
branchCommitResponse.setMsg(
|
||||
branchCommitResponseProto.getAbstractBranchEndResponse().getAbstractTransactionResponse()
|
||||
.getAbstractResultMessage().getMsg());
|
||||
branchCommitResponse.setResultCode(ResultCode.valueOf(
|
||||
branchCommitResponseProto.getAbstractBranchEndResponse().getAbstractTransactionResponse()
|
||||
.getAbstractResultMessage().getResultCode().name()));
|
||||
|
||||
branchCommitResponse.setTransactionExceptionCode(TransactionExceptionCode.valueOf(
|
||||
branchCommitResponseProto.getAbstractBranchEndResponse().getAbstractTransactionResponse()
|
||||
.getTransactionExceptionCode().name()));
|
||||
return branchCommitResponse;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractTransactionRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.BranchRegisterRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.BranchTypeProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.core.model.BranchType;
|
||||
import io.seata.core.protocol.transaction.BranchRegisterRequest;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class BranchRegisterRequestConvertor implements PbConvertor<BranchRegisterRequest, BranchRegisterRequestProto> {
|
||||
@Override
|
||||
public BranchRegisterRequestProto convert2Proto(BranchRegisterRequest branchRegisterRequest) {
|
||||
final short typeCode = branchRegisterRequest.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
final AbstractTransactionRequestProto abstractTransactionRequestProto = AbstractTransactionRequestProto
|
||||
.newBuilder().setAbstractMessage(abstractMessage).build();
|
||||
|
||||
final String applicationData = branchRegisterRequest.getApplicationData();
|
||||
final String resourceId = branchRegisterRequest.getResourceId();
|
||||
final String lockKey = branchRegisterRequest.getLockKey();
|
||||
BranchRegisterRequestProto result = BranchRegisterRequestProto.newBuilder().setAbstractTransactionRequest(
|
||||
abstractTransactionRequestProto).setApplicationData(applicationData == null ? "" : applicationData)
|
||||
.setBranchType(BranchTypeProto.valueOf(branchRegisterRequest.getBranchType().name())).setLockKey(
|
||||
lockKey == null ? "" : lockKey).setResourceId(resourceId == null ? "" : resourceId).setXid(
|
||||
branchRegisterRequest.getXid()).build();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BranchRegisterRequest convert2Model(BranchRegisterRequestProto branchRegisterRequestProto) {
|
||||
BranchRegisterRequest branchRegisterRequest = new BranchRegisterRequest();
|
||||
branchRegisterRequest.setApplicationData(branchRegisterRequestProto.getApplicationData());
|
||||
branchRegisterRequest.setBranchType(BranchType.valueOf(branchRegisterRequestProto.getBranchType().name()));
|
||||
branchRegisterRequest.setLockKey(branchRegisterRequestProto.getLockKey());
|
||||
branchRegisterRequest.setResourceId(branchRegisterRequestProto.getResourceId());
|
||||
branchRegisterRequest.setXid(branchRegisterRequestProto.getXid());
|
||||
return branchRegisterRequest;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.core.exception.TransactionExceptionCode;
|
||||
import io.seata.core.protocol.ResultCode;
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractResultMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractTransactionResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.BranchRegisterResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.serializer.protobuf.generated.ResultCodeProto;
|
||||
import io.seata.serializer.protobuf.generated.TransactionExceptionCodeProto;
|
||||
import io.seata.core.protocol.transaction.BranchRegisterResponse;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class BranchRegisterResponseConvertor
|
||||
implements PbConvertor<BranchRegisterResponse, BranchRegisterResponseProto> {
|
||||
@Override
|
||||
public BranchRegisterResponseProto convert2Proto(BranchRegisterResponse branchRegisterResponse) {
|
||||
final short typeCode = branchRegisterResponse.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
final String msg = branchRegisterResponse.getMsg();
|
||||
final AbstractResultMessageProto abstractResultMessageProto = AbstractResultMessageProto.newBuilder().setMsg(
|
||||
msg == null ? "" : msg).setResultCode(
|
||||
ResultCodeProto.valueOf(branchRegisterResponse.getResultCode().name())).setAbstractMessage(abstractMessage)
|
||||
.build();
|
||||
|
||||
AbstractTransactionResponseProto abstractTransactionResponseProto = AbstractTransactionResponseProto
|
||||
.newBuilder().setAbstractResultMessage(abstractResultMessageProto).setTransactionExceptionCode(
|
||||
TransactionExceptionCodeProto.valueOf(branchRegisterResponse.getTransactionExceptionCode().name()))
|
||||
.build();
|
||||
|
||||
BranchRegisterResponseProto result = BranchRegisterResponseProto.newBuilder().setAbstractTransactionResponse(
|
||||
abstractTransactionResponseProto).setBranchId(branchRegisterResponse.getBranchId()).build();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BranchRegisterResponse convert2Model(BranchRegisterResponseProto branchRegisterResponseProto) {
|
||||
BranchRegisterResponse branchRegisterResponse = new BranchRegisterResponse();
|
||||
branchRegisterResponse.setBranchId(branchRegisterResponseProto.getBranchId());
|
||||
final AbstractResultMessageProto abstractResultMessage = branchRegisterResponseProto
|
||||
.getAbstractTransactionResponse().getAbstractResultMessage();
|
||||
branchRegisterResponse.setMsg(abstractResultMessage.getMsg());
|
||||
branchRegisterResponse.setResultCode(ResultCode.valueOf(abstractResultMessage.getResultCode().name()));
|
||||
branchRegisterResponse.setTransactionExceptionCode(TransactionExceptionCode.valueOf(
|
||||
branchRegisterResponseProto.getAbstractTransactionResponse().getTransactionExceptionCode().name()));
|
||||
|
||||
return branchRegisterResponse;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractTransactionRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.BranchReportRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.BranchStatusProto;
|
||||
import io.seata.serializer.protobuf.generated.BranchTypeProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.core.model.BranchStatus;
|
||||
import io.seata.core.model.BranchType;
|
||||
import io.seata.core.protocol.transaction.BranchReportRequest;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class BranchReportRequestConvertor implements PbConvertor<BranchReportRequest, BranchReportRequestProto> {
|
||||
@Override
|
||||
public BranchReportRequestProto convert2Proto(BranchReportRequest branchReportRequest) {
|
||||
final short typeCode = branchReportRequest.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
final AbstractTransactionRequestProto abstractTransactionRequestProto = AbstractTransactionRequestProto
|
||||
.newBuilder().setAbstractMessage(abstractMessage).build();
|
||||
|
||||
final String applicationData = branchReportRequest.getApplicationData();
|
||||
final String resourceId = branchReportRequest.getResourceId();
|
||||
BranchReportRequestProto result = BranchReportRequestProto.newBuilder().setAbstractTransactionRequest(
|
||||
abstractTransactionRequestProto).setXid(branchReportRequest.getXid()).setBranchId(
|
||||
branchReportRequest.getBranchId()).setBranchType(
|
||||
BranchTypeProto.valueOf(branchReportRequest.getBranchType().name())).setApplicationData(
|
||||
applicationData == null ? "" : applicationData).setResourceId(resourceId == null ? "" : resourceId)
|
||||
.setStatus(BranchStatusProto.valueOf(branchReportRequest.getStatus().name())).build();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BranchReportRequest convert2Model(BranchReportRequestProto branchReportRequestProto) {
|
||||
BranchReportRequest branchReportRequest = new BranchReportRequest();
|
||||
branchReportRequest.setApplicationData(branchReportRequestProto.getApplicationData());
|
||||
branchReportRequest.setBranchId(branchReportRequestProto.getBranchId());
|
||||
branchReportRequest.setResourceId(branchReportRequestProto.getResourceId());
|
||||
branchReportRequest.setXid(branchReportRequestProto.getXid());
|
||||
branchReportRequest.setBranchType(BranchType.valueOf(branchReportRequestProto.getBranchType().name()));
|
||||
branchReportRequest.setStatus(BranchStatus.valueOf(branchReportRequestProto.getStatus().name()));
|
||||
return branchReportRequest;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.core.exception.TransactionExceptionCode;
|
||||
import io.seata.core.protocol.ResultCode;
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractResultMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractTransactionResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.BranchReportResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.serializer.protobuf.generated.ResultCodeProto;
|
||||
import io.seata.serializer.protobuf.generated.TransactionExceptionCodeProto;
|
||||
import io.seata.core.protocol.transaction.BranchReportResponse;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class BranchReportResponseConvertor implements PbConvertor<BranchReportResponse, BranchReportResponseProto> {
|
||||
@Override
|
||||
public BranchReportResponseProto convert2Proto(BranchReportResponse branchReportResponse) {
|
||||
final short typeCode = branchReportResponse.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
final String msg = branchReportResponse.getMsg();
|
||||
final AbstractResultMessageProto abstractResultMessageProto = AbstractResultMessageProto.newBuilder().setMsg(
|
||||
msg == null ? "" : msg).setResultCode(ResultCodeProto.valueOf(branchReportResponse.getResultCode().name()))
|
||||
.setAbstractMessage(abstractMessage).build();
|
||||
|
||||
AbstractTransactionResponseProto abstractTransactionResponseProto = AbstractTransactionResponseProto
|
||||
.newBuilder().setAbstractResultMessage(abstractResultMessageProto).setTransactionExceptionCode(
|
||||
TransactionExceptionCodeProto.valueOf(branchReportResponse.getTransactionExceptionCode().name()))
|
||||
.build();
|
||||
|
||||
BranchReportResponseProto result = BranchReportResponseProto.newBuilder().setAbstractTransactionResponse(
|
||||
abstractTransactionResponseProto).build();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BranchReportResponse convert2Model(BranchReportResponseProto branchReportResponseProto) {
|
||||
BranchReportResponse branchRegisterResponse = new BranchReportResponse();
|
||||
final AbstractResultMessageProto abstractResultMessage = branchReportResponseProto
|
||||
.getAbstractTransactionResponse().getAbstractResultMessage();
|
||||
branchRegisterResponse.setMsg(abstractResultMessage.getMsg());
|
||||
branchRegisterResponse.setResultCode(ResultCode.valueOf(abstractResultMessage.getResultCode().name()));
|
||||
branchRegisterResponse.setTransactionExceptionCode(TransactionExceptionCode
|
||||
.valueOf(branchReportResponseProto.getAbstractTransactionResponse().getTransactionExceptionCode().name()));
|
||||
|
||||
return branchRegisterResponse;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.core.model.BranchType;
|
||||
import io.seata.serializer.protobuf.generated.AbstractBranchEndRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractTransactionRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.BranchRollbackRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.BranchTypeProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.core.protocol.transaction.BranchRollbackRequest;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class BranchRollbackRequestConvertor implements PbConvertor<BranchRollbackRequest, BranchRollbackRequestProto> {
|
||||
@Override
|
||||
public BranchRollbackRequestProto convert2Proto(BranchRollbackRequest branchRollbackRequest) {
|
||||
final short typeCode = branchRollbackRequest.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
final AbstractTransactionRequestProto abstractTransactionRequestProto = AbstractTransactionRequestProto
|
||||
.newBuilder().setAbstractMessage(abstractMessage).build();
|
||||
|
||||
final String applicationData = branchRollbackRequest.getApplicationData();
|
||||
final String resourceId = branchRollbackRequest.getResourceId();
|
||||
final AbstractBranchEndRequestProto abstractBranchEndRequestProto = AbstractBranchEndRequestProto.newBuilder().
|
||||
setAbstractTransactionRequest(abstractTransactionRequestProto).setXid(branchRollbackRequest.getXid())
|
||||
.setBranchId(branchRollbackRequest.getBranchId()).setBranchType(
|
||||
BranchTypeProto.valueOf(branchRollbackRequest.getBranchType().name())).setApplicationData(
|
||||
applicationData == null ? "" : applicationData).setResourceId(resourceId == null ? "" : resourceId)
|
||||
.build();
|
||||
|
||||
BranchRollbackRequestProto result = BranchRollbackRequestProto.newBuilder().setAbstractBranchEndRequest(
|
||||
abstractBranchEndRequestProto).build();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BranchRollbackRequest convert2Model(BranchRollbackRequestProto branchRollbackRequestProto) {
|
||||
BranchRollbackRequest branchCommitRequest = new BranchRollbackRequest();
|
||||
branchCommitRequest.setApplicationData(
|
||||
branchRollbackRequestProto.getAbstractBranchEndRequest().getApplicationData());
|
||||
branchCommitRequest.setBranchId(branchRollbackRequestProto.getAbstractBranchEndRequest().getBranchId());
|
||||
branchCommitRequest.setResourceId(branchRollbackRequestProto.getAbstractBranchEndRequest().getResourceId());
|
||||
branchCommitRequest.setXid(branchRollbackRequestProto.getAbstractBranchEndRequest().getXid());
|
||||
branchCommitRequest.setBranchType(
|
||||
BranchType.valueOf(branchRollbackRequestProto.getAbstractBranchEndRequest().getBranchType().name()));
|
||||
|
||||
return branchCommitRequest;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.core.exception.TransactionExceptionCode;
|
||||
import io.seata.core.model.BranchStatus;
|
||||
import io.seata.core.protocol.ResultCode;
|
||||
import io.seata.serializer.protobuf.generated.AbstractBranchEndResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractResultMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractTransactionResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.BranchRollbackResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.BranchStatusProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.serializer.protobuf.generated.ResultCodeProto;
|
||||
import io.seata.serializer.protobuf.generated.TransactionExceptionCodeProto;
|
||||
import io.seata.core.protocol.transaction.BranchRollbackResponse;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class BranchRollbackResponseConvertor
|
||||
implements PbConvertor<BranchRollbackResponse, BranchRollbackResponseProto> {
|
||||
@Override
|
||||
public BranchRollbackResponseProto convert2Proto(BranchRollbackResponse branchRollbackResponse) {
|
||||
final short typeCode = branchRollbackResponse.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
final String msg = branchRollbackResponse.getMsg();
|
||||
final AbstractResultMessageProto abstractResultMessageProto = AbstractResultMessageProto.newBuilder().setMsg(
|
||||
msg == null ? "" : msg).setResultCode(
|
||||
ResultCodeProto.valueOf(branchRollbackResponse.getResultCode().name())).setAbstractMessage(abstractMessage)
|
||||
.build();
|
||||
|
||||
final AbstractTransactionResponseProto abstractTransactionRequestProto = AbstractTransactionResponseProto
|
||||
.newBuilder().setAbstractResultMessage(abstractResultMessageProto).setTransactionExceptionCode(
|
||||
TransactionExceptionCodeProto.valueOf(branchRollbackResponse.getTransactionExceptionCode().name()))
|
||||
.build();
|
||||
|
||||
final AbstractBranchEndResponseProto abstractBranchEndResponse = AbstractBranchEndResponseProto.newBuilder().
|
||||
setAbstractTransactionResponse(abstractTransactionRequestProto).setXid(branchRollbackResponse.getXid())
|
||||
.setBranchId(branchRollbackResponse.getBranchId()).setBranchStatus(
|
||||
BranchStatusProto.forNumber(branchRollbackResponse.getBranchStatus().getCode())).build();
|
||||
|
||||
BranchRollbackResponseProto result = BranchRollbackResponseProto.newBuilder().setAbstractBranchEndResponse(
|
||||
abstractBranchEndResponse).build();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BranchRollbackResponse convert2Model(BranchRollbackResponseProto branchRollbackResponseProto) {
|
||||
BranchRollbackResponse branchCommitResponse = new BranchRollbackResponse();
|
||||
branchCommitResponse.setBranchId(branchRollbackResponseProto.getAbstractBranchEndResponse().getBranchId());
|
||||
branchCommitResponse.setBranchStatus(
|
||||
BranchStatus.get(branchRollbackResponseProto.getAbstractBranchEndResponse().getBranchStatusValue()));
|
||||
branchCommitResponse.setXid(branchRollbackResponseProto.getAbstractBranchEndResponse().getXid());
|
||||
branchCommitResponse.setMsg(
|
||||
branchRollbackResponseProto.getAbstractBranchEndResponse().getAbstractTransactionResponse()
|
||||
.getAbstractResultMessage().getMsg());
|
||||
branchCommitResponse.setResultCode(ResultCode.valueOf(
|
||||
branchRollbackResponseProto.getAbstractBranchEndResponse().getAbstractTransactionResponse()
|
||||
.getAbstractResultMessage().getResultCode().name()));
|
||||
|
||||
branchCommitResponse.setTransactionExceptionCode(TransactionExceptionCode.valueOf(
|
||||
branchRollbackResponseProto.getAbstractBranchEndResponse().getAbstractTransactionResponse()
|
||||
.getTransactionExceptionCode().name()));
|
||||
return branchCommitResponse;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractTransactionRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalBeginRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.core.protocol.transaction.GlobalBeginRequest;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class GlobalBeginRequestConvertor implements PbConvertor<GlobalBeginRequest, GlobalBeginRequestProto> {
|
||||
|
||||
@Override
|
||||
public GlobalBeginRequestProto convert2Proto(GlobalBeginRequest globalBeginRequest) {
|
||||
final short typeCode = globalBeginRequest.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
final AbstractTransactionRequestProto abstractTransactionRequestProto = AbstractTransactionRequestProto
|
||||
.newBuilder().setAbstractMessage(abstractMessage).build();
|
||||
|
||||
GlobalBeginRequestProto result = GlobalBeginRequestProto.newBuilder().setTimeout(
|
||||
globalBeginRequest.getTimeout()).setTransactionName(globalBeginRequest.getTransactionName())
|
||||
.setAbstractTransactionRequest(abstractTransactionRequestProto).build();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GlobalBeginRequest convert2Model(GlobalBeginRequestProto globalBeginRequestProto) {
|
||||
GlobalBeginRequest globalBeginRequest = new GlobalBeginRequest();
|
||||
globalBeginRequest.setTimeout(globalBeginRequestProto.getTimeout());
|
||||
globalBeginRequest.setTransactionName(globalBeginRequestProto.getTransactionName());
|
||||
return globalBeginRequest;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractResultMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractTransactionResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalBeginResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.serializer.protobuf.generated.ResultCodeProto;
|
||||
import io.seata.serializer.protobuf.generated.TransactionExceptionCodeProto;
|
||||
import io.seata.core.exception.TransactionExceptionCode;
|
||||
import io.seata.core.protocol.ResultCode;
|
||||
import io.seata.core.protocol.transaction.GlobalBeginResponse;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class GlobalBeginResponseConvertor implements PbConvertor<GlobalBeginResponse, GlobalBeginResponseProto> {
|
||||
@Override
|
||||
public GlobalBeginResponseProto convert2Proto(GlobalBeginResponse globalBeginResponse) {
|
||||
final short typeCode = globalBeginResponse.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
final String msg = globalBeginResponse.getMsg();
|
||||
final AbstractResultMessageProto abstractResultMessageProto = AbstractResultMessageProto.newBuilder().setMsg(
|
||||
msg == null ? "" : msg).setResultCode(ResultCodeProto.valueOf(globalBeginResponse.getResultCode().name()))
|
||||
.setAbstractMessage(abstractMessage).build();
|
||||
|
||||
final AbstractTransactionResponseProto abstractTransactionRequestProto = AbstractTransactionResponseProto
|
||||
.newBuilder().setAbstractResultMessage(abstractResultMessageProto).setTransactionExceptionCode(
|
||||
TransactionExceptionCodeProto.valueOf(globalBeginResponse.getTransactionExceptionCode().name()))
|
||||
.build();
|
||||
|
||||
final String extraData = globalBeginResponse.getExtraData();
|
||||
GlobalBeginResponseProto result = GlobalBeginResponseProto.newBuilder().setAbstractTransactionResponse(
|
||||
abstractTransactionRequestProto).setExtraData(extraData == null ? "" : extraData).setXid(
|
||||
globalBeginResponse.getXid()).build();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GlobalBeginResponse convert2Model(GlobalBeginResponseProto globalBeginResponseProto) {
|
||||
GlobalBeginResponse branchCommitResponse = new GlobalBeginResponse();
|
||||
branchCommitResponse.setXid(globalBeginResponseProto.getXid());
|
||||
branchCommitResponse.setExtraData(globalBeginResponseProto.getExtraData());
|
||||
branchCommitResponse.setMsg(
|
||||
globalBeginResponseProto.getAbstractTransactionResponse().getAbstractResultMessage().getMsg());
|
||||
branchCommitResponse.setResultCode(ResultCode.valueOf(
|
||||
globalBeginResponseProto.getAbstractTransactionResponse().getAbstractResultMessage().getResultCode()
|
||||
.name()));
|
||||
|
||||
branchCommitResponse.setTransactionExceptionCode(TransactionExceptionCode
|
||||
.valueOf(globalBeginResponseProto.getAbstractTransactionResponse().getTransactionExceptionCode().name()));
|
||||
return branchCommitResponse;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.AbstractGlobalEndRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractTransactionRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalCommitRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.core.protocol.transaction.GlobalCommitRequest;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class GlobalCommitRequestConvertor implements PbConvertor<GlobalCommitRequest, GlobalCommitRequestProto> {
|
||||
@Override
|
||||
public GlobalCommitRequestProto convert2Proto(GlobalCommitRequest globalCommitRequest) {
|
||||
final short typeCode = globalCommitRequest.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
final AbstractTransactionRequestProto abstractTransactionRequestProto = AbstractTransactionRequestProto
|
||||
.newBuilder().setAbstractMessage(abstractMessage).build();
|
||||
|
||||
final String extraData = globalCommitRequest.getExtraData();
|
||||
AbstractGlobalEndRequestProto abstractGlobalEndRequestProto = AbstractGlobalEndRequestProto.newBuilder()
|
||||
.setAbstractTransactionRequest(abstractTransactionRequestProto).setXid(globalCommitRequest.getXid())
|
||||
.setExtraData(extraData == null ? "" : extraData).build();
|
||||
|
||||
GlobalCommitRequestProto result = GlobalCommitRequestProto.newBuilder().setAbstractGlobalEndRequest(
|
||||
abstractGlobalEndRequestProto).build();
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public GlobalCommitRequest convert2Model(GlobalCommitRequestProto globalCommitRequestProto) {
|
||||
GlobalCommitRequest branchCommitRequest = new GlobalCommitRequest();
|
||||
branchCommitRequest.setExtraData(globalCommitRequestProto.getAbstractGlobalEndRequest().getExtraData());
|
||||
branchCommitRequest.setXid(globalCommitRequestProto.getAbstractGlobalEndRequest().getXid());
|
||||
return branchCommitRequest;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.core.exception.TransactionExceptionCode;
|
||||
import io.seata.core.model.GlobalStatus;
|
||||
import io.seata.core.protocol.ResultCode;
|
||||
import io.seata.serializer.protobuf.generated.AbstractGlobalEndResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractResultMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractTransactionResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalCommitResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalStatusProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.serializer.protobuf.generated.ResultCodeProto;
|
||||
import io.seata.serializer.protobuf.generated.TransactionExceptionCodeProto;
|
||||
import io.seata.core.protocol.transaction.GlobalCommitResponse;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class GlobalCommitResponseConvertor implements PbConvertor<GlobalCommitResponse, GlobalCommitResponseProto> {
|
||||
@Override
|
||||
public GlobalCommitResponseProto convert2Proto(GlobalCommitResponse globalCommitResponse) {
|
||||
final short typeCode = globalCommitResponse.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
final String msg = globalCommitResponse.getMsg();
|
||||
final AbstractResultMessageProto abstractResultMessageProto = AbstractResultMessageProto.newBuilder().setMsg(
|
||||
msg == null ? "" : msg).setResultCode(ResultCodeProto.valueOf(globalCommitResponse.getResultCode().name()))
|
||||
.setAbstractMessage(abstractMessage).build();
|
||||
|
||||
AbstractTransactionResponseProto abstractTransactionResponseProto = AbstractTransactionResponseProto
|
||||
.newBuilder().setAbstractResultMessage(abstractResultMessageProto).setTransactionExceptionCode(
|
||||
TransactionExceptionCodeProto.valueOf(globalCommitResponse.getTransactionExceptionCode().name()))
|
||||
.build();
|
||||
|
||||
AbstractGlobalEndResponseProto abstractGlobalEndResponseProto = AbstractGlobalEndResponseProto.newBuilder()
|
||||
.setAbstractTransactionResponse(abstractTransactionResponseProto).setGlobalStatus(
|
||||
GlobalStatusProto.valueOf(globalCommitResponse.getGlobalStatus().name())).build();
|
||||
|
||||
GlobalCommitResponseProto result = GlobalCommitResponseProto.newBuilder().setAbstractGlobalEndResponse(
|
||||
abstractGlobalEndResponseProto).build();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GlobalCommitResponse convert2Model(GlobalCommitResponseProto globalCommitResponseProto) {
|
||||
GlobalCommitResponse branchRegisterResponse = new GlobalCommitResponse();
|
||||
final AbstractGlobalEndResponseProto abstractGlobalEndResponse = globalCommitResponseProto
|
||||
.getAbstractGlobalEndResponse();
|
||||
AbstractTransactionResponseProto abstractResultMessage = abstractGlobalEndResponse
|
||||
.getAbstractTransactionResponse();
|
||||
branchRegisterResponse.setMsg(abstractResultMessage.getAbstractResultMessage().getMsg());
|
||||
branchRegisterResponse.setResultCode(
|
||||
ResultCode.valueOf(abstractResultMessage.getAbstractResultMessage().getResultCode().name()));
|
||||
branchRegisterResponse.setTransactionExceptionCode(
|
||||
TransactionExceptionCode.valueOf(abstractResultMessage.getTransactionExceptionCode().name()));
|
||||
branchRegisterResponse.setGlobalStatus(
|
||||
GlobalStatus.valueOf(abstractGlobalEndResponse.getGlobalStatus().name()));
|
||||
|
||||
return branchRegisterResponse;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractTransactionRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.BranchRegisterRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.BranchTypeProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalLockQueryRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.core.model.BranchType;
|
||||
import io.seata.core.protocol.transaction.GlobalLockQueryRequest;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class GlobalLockQueryRequestConvertor
|
||||
implements PbConvertor<GlobalLockQueryRequest, GlobalLockQueryRequestProto> {
|
||||
@Override
|
||||
public GlobalLockQueryRequestProto convert2Proto(GlobalLockQueryRequest globalLockQueryRequest) {
|
||||
final short typeCode = globalLockQueryRequest.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
final AbstractTransactionRequestProto abstractTransactionRequestProto = AbstractTransactionRequestProto
|
||||
.newBuilder().setAbstractMessage(abstractMessage).build();
|
||||
|
||||
final String applicationData = globalLockQueryRequest.getApplicationData();
|
||||
final String lockKey = globalLockQueryRequest.getLockKey();
|
||||
BranchRegisterRequestProto branchRegisterRequestProto = BranchRegisterRequestProto.newBuilder()
|
||||
.setAbstractTransactionRequest(abstractTransactionRequestProto).setApplicationData(
|
||||
applicationData == null ? "" : applicationData).setBranchType(
|
||||
BranchTypeProto.valueOf(globalLockQueryRequest.getBranchType().name())).setLockKey(
|
||||
lockKey == null ? "" : lockKey).setResourceId(globalLockQueryRequest.getResourceId()).setXid(
|
||||
globalLockQueryRequest.getXid()).build();
|
||||
|
||||
GlobalLockQueryRequestProto result = GlobalLockQueryRequestProto.newBuilder().setBranchRegisterRequest(
|
||||
branchRegisterRequestProto).build();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GlobalLockQueryRequest convert2Model(GlobalLockQueryRequestProto globalLockQueryRequestProto) {
|
||||
GlobalLockQueryRequest branchRegisterRequest = new GlobalLockQueryRequest();
|
||||
BranchRegisterRequestProto branchRegisterRequestProto = globalLockQueryRequestProto.getBranchRegisterRequest();
|
||||
branchRegisterRequest.setApplicationData(branchRegisterRequestProto.getApplicationData());
|
||||
branchRegisterRequest.setBranchType(BranchType.valueOf(branchRegisterRequestProto.getBranchType().name()));
|
||||
branchRegisterRequest.setLockKey(branchRegisterRequestProto.getLockKey());
|
||||
branchRegisterRequest.setResourceId(branchRegisterRequestProto.getResourceId());
|
||||
branchRegisterRequest.setXid(branchRegisterRequestProto.getXid());
|
||||
return branchRegisterRequest;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.core.exception.TransactionExceptionCode;
|
||||
import io.seata.core.protocol.ResultCode;
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractResultMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractTransactionResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalLockQueryResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.serializer.protobuf.generated.ResultCodeProto;
|
||||
import io.seata.serializer.protobuf.generated.TransactionExceptionCodeProto;
|
||||
import io.seata.core.protocol.transaction.GlobalLockQueryResponse;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class GlobalLockQueryResponseConvertor
|
||||
implements PbConvertor<GlobalLockQueryResponse, GlobalLockQueryResponseProto> {
|
||||
@Override
|
||||
public GlobalLockQueryResponseProto convert2Proto(GlobalLockQueryResponse globalLockQueryResponse) {
|
||||
final short typeCode = globalLockQueryResponse.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
final String msg = globalLockQueryResponse.getMsg();
|
||||
final AbstractResultMessageProto abstractResultMessageProto = AbstractResultMessageProto.newBuilder().setMsg(
|
||||
msg == null ? "" : msg).setResultCode(
|
||||
ResultCodeProto.valueOf(globalLockQueryResponse.getResultCode().name())).setAbstractMessage(abstractMessage)
|
||||
.build();
|
||||
|
||||
AbstractTransactionResponseProto abstractTransactionResponseProto = AbstractTransactionResponseProto
|
||||
.newBuilder().setAbstractResultMessage(abstractResultMessageProto).setTransactionExceptionCode(
|
||||
TransactionExceptionCodeProto.valueOf(globalLockQueryResponse.getTransactionExceptionCode().name()))
|
||||
.build();
|
||||
|
||||
GlobalLockQueryResponseProto result = GlobalLockQueryResponseProto.newBuilder().setLockable(
|
||||
globalLockQueryResponse.isLockable()).setAbstractTransactionResponse(abstractTransactionResponseProto)
|
||||
.build();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GlobalLockQueryResponse convert2Model(GlobalLockQueryResponseProto globalLockQueryResponseProto) {
|
||||
|
||||
GlobalLockQueryResponse branchRegisterResponse = new GlobalLockQueryResponse();
|
||||
AbstractTransactionResponseProto branchRegisterResponseProto = globalLockQueryResponseProto
|
||||
.getAbstractTransactionResponse();
|
||||
final AbstractResultMessageProto abstractResultMessage = branchRegisterResponseProto.getAbstractResultMessage();
|
||||
branchRegisterResponse.setMsg(abstractResultMessage.getMsg());
|
||||
branchRegisterResponse.setResultCode(ResultCode.valueOf(abstractResultMessage.getResultCode().name()));
|
||||
branchRegisterResponse.setTransactionExceptionCode(
|
||||
TransactionExceptionCode.valueOf(branchRegisterResponseProto.getTransactionExceptionCode().name()));
|
||||
branchRegisterResponse.setLockable(globalLockQueryResponseProto.getLockable());
|
||||
return branchRegisterResponse;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.AbstractGlobalEndRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractTransactionRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalReportRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalStatusProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.core.model.GlobalStatus;
|
||||
import io.seata.core.protocol.transaction.GlobalReportRequest;
|
||||
|
||||
/**
|
||||
* @author lorne.cl
|
||||
*/
|
||||
public class GlobalReportRequestConvertor implements PbConvertor<GlobalReportRequest, GlobalReportRequestProto> {
|
||||
@Override
|
||||
public GlobalReportRequestProto convert2Proto(GlobalReportRequest globalReportRequest) {
|
||||
final short typeCode = globalReportRequest.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
final AbstractTransactionRequestProto abstractTransactionRequestProto = AbstractTransactionRequestProto
|
||||
.newBuilder().setAbstractMessage(abstractMessage).build();
|
||||
|
||||
final String extraData = globalReportRequest.getExtraData();
|
||||
AbstractGlobalEndRequestProto abstractGlobalEndRequestProto = AbstractGlobalEndRequestProto.newBuilder()
|
||||
.setAbstractTransactionRequest(abstractTransactionRequestProto).setXid(globalReportRequest.getXid())
|
||||
.setExtraData(extraData == null ? "" : extraData).build();
|
||||
|
||||
GlobalReportRequestProto result = GlobalReportRequestProto.newBuilder().setAbstractGlobalEndRequest(
|
||||
abstractGlobalEndRequestProto).setGlobalStatus(
|
||||
GlobalStatusProto.valueOf(globalReportRequest.getGlobalStatus().name())).build();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GlobalReportRequest convert2Model(GlobalReportRequestProto globalReportRequestProto) {
|
||||
GlobalReportRequest globalReportRequest = new GlobalReportRequest();
|
||||
globalReportRequest.setExtraData(globalReportRequestProto.getAbstractGlobalEndRequest().getExtraData());
|
||||
globalReportRequest.setXid(globalReportRequestProto.getAbstractGlobalEndRequest().getXid());
|
||||
globalReportRequest.setGlobalStatus(GlobalStatus.valueOf(globalReportRequestProto.getGlobalStatus().name()));
|
||||
return globalReportRequest;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.AbstractGlobalEndResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractResultMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractTransactionResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalReportResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalStatusProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.serializer.protobuf.generated.ResultCodeProto;
|
||||
import io.seata.serializer.protobuf.generated.TransactionExceptionCodeProto;
|
||||
import io.seata.core.exception.TransactionExceptionCode;
|
||||
import io.seata.core.model.GlobalStatus;
|
||||
import io.seata.core.protocol.ResultCode;
|
||||
import io.seata.core.protocol.transaction.GlobalReportResponse;
|
||||
|
||||
/**
|
||||
* @author lorne.cl
|
||||
*/
|
||||
public class GlobalReportResponseConvertor implements PbConvertor<GlobalReportResponse, GlobalReportResponseProto> {
|
||||
@Override
|
||||
public GlobalReportResponseProto convert2Proto(GlobalReportResponse globalStatusResponse) {
|
||||
final short typeCode = globalStatusResponse.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
final String msg = globalStatusResponse.getMsg();
|
||||
final AbstractResultMessageProto abstractResultMessageProto = AbstractResultMessageProto.newBuilder().setMsg(
|
||||
msg == null ? "" : msg).setResultCode(ResultCodeProto.valueOf(globalStatusResponse.getResultCode().name()))
|
||||
.setAbstractMessage(abstractMessage).build();
|
||||
|
||||
AbstractTransactionResponseProto abstractTransactionResponseProto = AbstractTransactionResponseProto
|
||||
.newBuilder().setAbstractResultMessage(abstractResultMessageProto).setTransactionExceptionCode(
|
||||
TransactionExceptionCodeProto.valueOf(globalStatusResponse.getTransactionExceptionCode().name()))
|
||||
.build();
|
||||
|
||||
AbstractGlobalEndResponseProto abstractGlobalEndResponseProto = AbstractGlobalEndResponseProto.newBuilder()
|
||||
.setAbstractTransactionResponse(abstractTransactionResponseProto).setGlobalStatus(
|
||||
GlobalStatusProto.valueOf(globalStatusResponse.getGlobalStatus().name())).build();
|
||||
|
||||
GlobalReportResponseProto result = GlobalReportResponseProto.newBuilder().setAbstractGlobalEndResponse(
|
||||
abstractGlobalEndResponseProto).build();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GlobalReportResponse convert2Model(GlobalReportResponseProto globalStatusResponseProto) {
|
||||
GlobalReportResponse branchRegisterResponse = new GlobalReportResponse();
|
||||
final AbstractGlobalEndResponseProto abstractGlobalEndResponse = globalStatusResponseProto
|
||||
.getAbstractGlobalEndResponse();
|
||||
AbstractTransactionResponseProto abstractResultMessage = abstractGlobalEndResponse
|
||||
.getAbstractTransactionResponse();
|
||||
branchRegisterResponse.setMsg(abstractResultMessage.getAbstractResultMessage().getMsg());
|
||||
branchRegisterResponse.setResultCode(
|
||||
ResultCode.valueOf(abstractResultMessage.getAbstractResultMessage().getResultCode().name()));
|
||||
branchRegisterResponse.setTransactionExceptionCode(
|
||||
TransactionExceptionCode.valueOf(abstractResultMessage.getTransactionExceptionCode().name()));
|
||||
branchRegisterResponse.setGlobalStatus(
|
||||
GlobalStatus.valueOf(abstractGlobalEndResponse.getGlobalStatus().name()));
|
||||
|
||||
return branchRegisterResponse;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.AbstractGlobalEndRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractTransactionRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalRollbackRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.core.protocol.transaction.GlobalRollbackRequest;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class GlobalRollbackRequestConvertor implements PbConvertor<GlobalRollbackRequest, GlobalRollbackRequestProto> {
|
||||
@Override
|
||||
public GlobalRollbackRequestProto convert2Proto(GlobalRollbackRequest globalRollbackRequest) {
|
||||
final short typeCode = globalRollbackRequest.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
final AbstractTransactionRequestProto abstractTransactionRequestProto = AbstractTransactionRequestProto
|
||||
.newBuilder().setAbstractMessage(abstractMessage).build();
|
||||
|
||||
final String extraData = globalRollbackRequest.getExtraData();
|
||||
AbstractGlobalEndRequestProto abstractGlobalEndRequestProto = AbstractGlobalEndRequestProto.newBuilder()
|
||||
.setAbstractTransactionRequest(abstractTransactionRequestProto).setXid(globalRollbackRequest.getXid())
|
||||
.setExtraData(extraData == null ? "" : extraData).build();
|
||||
|
||||
GlobalRollbackRequestProto result = GlobalRollbackRequestProto.newBuilder().setAbstractGlobalEndRequest(
|
||||
abstractGlobalEndRequestProto).build();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GlobalRollbackRequest convert2Model(GlobalRollbackRequestProto globalRollbackRequestProto) {
|
||||
GlobalRollbackRequest branchCommitRequest = new GlobalRollbackRequest();
|
||||
branchCommitRequest.setExtraData(globalRollbackRequestProto.getAbstractGlobalEndRequest().getExtraData());
|
||||
branchCommitRequest.setXid(globalRollbackRequestProto.getAbstractGlobalEndRequest().getXid());
|
||||
return branchCommitRequest;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.core.exception.TransactionExceptionCode;
|
||||
import io.seata.core.model.GlobalStatus;
|
||||
import io.seata.core.protocol.ResultCode;
|
||||
import io.seata.serializer.protobuf.generated.AbstractGlobalEndResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractResultMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractTransactionResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalRollbackResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalStatusProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.serializer.protobuf.generated.ResultCodeProto;
|
||||
import io.seata.serializer.protobuf.generated.TransactionExceptionCodeProto;
|
||||
import io.seata.core.protocol.transaction.GlobalRollbackResponse;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class GlobalRollbackResponseConvertor
|
||||
implements PbConvertor<GlobalRollbackResponse, GlobalRollbackResponseProto> {
|
||||
@Override
|
||||
public GlobalRollbackResponseProto convert2Proto(GlobalRollbackResponse globalRollbackResponse) {
|
||||
final short typeCode = globalRollbackResponse.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
final String msg = globalRollbackResponse.getMsg();
|
||||
final AbstractResultMessageProto abstractResultMessageProto = AbstractResultMessageProto.newBuilder().setMsg(
|
||||
msg == null ? "" : msg).setResultCode(
|
||||
ResultCodeProto.valueOf(globalRollbackResponse.getResultCode().name())).setAbstractMessage(abstractMessage)
|
||||
.build();
|
||||
|
||||
AbstractTransactionResponseProto abstractTransactionResponseProto = AbstractTransactionResponseProto
|
||||
.newBuilder().setAbstractResultMessage(abstractResultMessageProto).setTransactionExceptionCode(
|
||||
TransactionExceptionCodeProto.valueOf(globalRollbackResponse.getTransactionExceptionCode().name()))
|
||||
.build();
|
||||
|
||||
AbstractGlobalEndResponseProto abstractGlobalEndResponseProto = AbstractGlobalEndResponseProto.newBuilder()
|
||||
.setAbstractTransactionResponse(abstractTransactionResponseProto).setGlobalStatus(
|
||||
GlobalStatusProto.valueOf(globalRollbackResponse.getGlobalStatus().name())).build();
|
||||
|
||||
GlobalRollbackResponseProto result = GlobalRollbackResponseProto.newBuilder().setAbstractGlobalEndResponse(
|
||||
abstractGlobalEndResponseProto).build();
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public GlobalRollbackResponse convert2Model(GlobalRollbackResponseProto globalRollbackResponseProto) {
|
||||
GlobalRollbackResponse branchRegisterResponse = new GlobalRollbackResponse();
|
||||
final AbstractGlobalEndResponseProto abstractGlobalEndResponse = globalRollbackResponseProto
|
||||
.getAbstractGlobalEndResponse();
|
||||
AbstractTransactionResponseProto abstractResultMessage = abstractGlobalEndResponse
|
||||
.getAbstractTransactionResponse();
|
||||
branchRegisterResponse.setMsg(abstractResultMessage.getAbstractResultMessage().getMsg());
|
||||
branchRegisterResponse.setResultCode(
|
||||
ResultCode.valueOf(abstractResultMessage.getAbstractResultMessage().getResultCode().name()));
|
||||
branchRegisterResponse.setTransactionExceptionCode(
|
||||
TransactionExceptionCode.valueOf(abstractResultMessage.getTransactionExceptionCode().name()));
|
||||
branchRegisterResponse.setGlobalStatus(
|
||||
GlobalStatus.valueOf(abstractGlobalEndResponse.getGlobalStatus().name()));
|
||||
|
||||
return branchRegisterResponse;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.AbstractGlobalEndRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractTransactionRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalStatusRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.core.protocol.transaction.GlobalStatusRequest;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class GlobalStatusRequestConvertor implements PbConvertor<GlobalStatusRequest, GlobalStatusRequestProto> {
|
||||
@Override
|
||||
public GlobalStatusRequestProto convert2Proto(GlobalStatusRequest globalStatusRequest) {
|
||||
final short typeCode = globalStatusRequest.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
final AbstractTransactionRequestProto abstractTransactionRequestProto = AbstractTransactionRequestProto
|
||||
.newBuilder().setAbstractMessage(abstractMessage).build();
|
||||
|
||||
final String extraData = globalStatusRequest.getExtraData();
|
||||
AbstractGlobalEndRequestProto abstractGlobalEndRequestProto = AbstractGlobalEndRequestProto.newBuilder()
|
||||
.setAbstractTransactionRequest(abstractTransactionRequestProto).setXid(globalStatusRequest.getXid())
|
||||
.setExtraData(extraData == null ? "" : extraData).build();
|
||||
|
||||
GlobalStatusRequestProto result = GlobalStatusRequestProto.newBuilder().setAbstractGlobalEndRequest(
|
||||
abstractGlobalEndRequestProto).build();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GlobalStatusRequest convert2Model(GlobalStatusRequestProto globalStatusRequestProto) {
|
||||
GlobalStatusRequest branchCommitRequest = new GlobalStatusRequest();
|
||||
branchCommitRequest.setExtraData(globalStatusRequestProto.getAbstractGlobalEndRequest().getExtraData());
|
||||
branchCommitRequest.setXid(globalStatusRequestProto.getAbstractGlobalEndRequest().getXid());
|
||||
return branchCommitRequest;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.core.exception.TransactionExceptionCode;
|
||||
import io.seata.core.model.GlobalStatus;
|
||||
import io.seata.core.protocol.ResultCode;
|
||||
import io.seata.serializer.protobuf.generated.AbstractGlobalEndResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractResultMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractTransactionResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalStatusProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalStatusResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.serializer.protobuf.generated.ResultCodeProto;
|
||||
import io.seata.serializer.protobuf.generated.TransactionExceptionCodeProto;
|
||||
import io.seata.core.protocol.transaction.GlobalStatusResponse;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class GlobalStatusResponseConvertor implements PbConvertor<GlobalStatusResponse, GlobalStatusResponseProto> {
|
||||
@Override
|
||||
public GlobalStatusResponseProto convert2Proto(GlobalStatusResponse globalStatusResponse) {
|
||||
final short typeCode = globalStatusResponse.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
final String msg = globalStatusResponse.getMsg();
|
||||
final AbstractResultMessageProto abstractResultMessageProto = AbstractResultMessageProto.newBuilder().setMsg(
|
||||
msg == null ? "" : msg).setResultCode(ResultCodeProto.valueOf(globalStatusResponse.getResultCode().name()))
|
||||
.setAbstractMessage(abstractMessage).build();
|
||||
|
||||
AbstractTransactionResponseProto abstractTransactionResponseProto = AbstractTransactionResponseProto
|
||||
.newBuilder().setAbstractResultMessage(abstractResultMessageProto).setTransactionExceptionCode(
|
||||
TransactionExceptionCodeProto.valueOf(globalStatusResponse.getTransactionExceptionCode().name()))
|
||||
.build();
|
||||
|
||||
AbstractGlobalEndResponseProto abstractGlobalEndResponseProto = AbstractGlobalEndResponseProto.newBuilder()
|
||||
.setAbstractTransactionResponse(abstractTransactionResponseProto).setGlobalStatus(
|
||||
GlobalStatusProto.valueOf(globalStatusResponse.getGlobalStatus().name())).build();
|
||||
|
||||
GlobalStatusResponseProto result = GlobalStatusResponseProto.newBuilder().setAbstractGlobalEndResponse(
|
||||
abstractGlobalEndResponseProto).build();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GlobalStatusResponse convert2Model(GlobalStatusResponseProto globalStatusResponseProto) {
|
||||
GlobalStatusResponse branchRegisterResponse = new GlobalStatusResponse();
|
||||
final AbstractGlobalEndResponseProto abstractGlobalEndResponse = globalStatusResponseProto
|
||||
.getAbstractGlobalEndResponse();
|
||||
AbstractTransactionResponseProto abstractResultMessage = abstractGlobalEndResponse
|
||||
.getAbstractTransactionResponse();
|
||||
branchRegisterResponse.setMsg(abstractResultMessage.getAbstractResultMessage().getMsg());
|
||||
branchRegisterResponse.setResultCode(
|
||||
ResultCode.valueOf(abstractResultMessage.getAbstractResultMessage().getResultCode().name()));
|
||||
branchRegisterResponse.setTransactionExceptionCode(
|
||||
TransactionExceptionCode.valueOf(abstractResultMessage.getTransactionExceptionCode().name()));
|
||||
branchRegisterResponse.setGlobalStatus(
|
||||
GlobalStatus.valueOf(abstractGlobalEndResponse.getGlobalStatus().name()));
|
||||
|
||||
return branchRegisterResponse;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.HeartbeatMessageProto;
|
||||
import io.seata.core.protocol.HeartbeatMessage;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class HeartbeatMessageConvertor implements PbConvertor<HeartbeatMessage, HeartbeatMessageProto> {
|
||||
@Override
|
||||
public HeartbeatMessageProto convert2Proto(HeartbeatMessage heartbeatMessage) {
|
||||
HeartbeatMessageProto result = HeartbeatMessageProto.newBuilder().setPing(heartbeatMessage.isPing()).build();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HeartbeatMessage convert2Model(HeartbeatMessageProto heartbeatMessageProto) {
|
||||
return heartbeatMessageProto.getPing() ? HeartbeatMessage.PING : HeartbeatMessage.PONG;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.protobuf.Any;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import com.google.protobuf.Message;
|
||||
import io.seata.common.exception.ShouldNeverHappenException;
|
||||
import io.seata.core.protocol.AbstractMessage;
|
||||
import io.seata.core.protocol.AbstractResultMessage;
|
||||
import io.seata.core.protocol.MergeResultMessage;
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.MergedResultMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.serializer.protobuf.manager.ProtobufConvertManager;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class MergeResultMessageConvertor implements PbConvertor<MergeResultMessage, MergedResultMessageProto> {
|
||||
@Override
|
||||
public MergedResultMessageProto convert2Proto(MergeResultMessage mergeResultMessage) {
|
||||
final short typeCode = mergeResultMessage.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
List<Any> lists = new ArrayList<>();
|
||||
for (AbstractMessage msg : mergeResultMessage.msgs) {
|
||||
final PbConvertor pbConvertor = ProtobufConvertManager.getInstance().fetchConvertor(
|
||||
msg.getClass().getName());
|
||||
lists.add(Any.pack((Message)pbConvertor.convert2Proto(msg)));
|
||||
}
|
||||
|
||||
MergedResultMessageProto mergedWarpMessageProto = MergedResultMessageProto.newBuilder().setAbstractMessage(
|
||||
abstractMessage).addAllMsgs(lists).build();
|
||||
|
||||
return mergedWarpMessageProto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MergeResultMessage convert2Model(MergedResultMessageProto mergedResultMessageProto) {
|
||||
MergeResultMessage result = new MergeResultMessage();
|
||||
List<Any> anys = mergedResultMessageProto.getMsgsList();
|
||||
|
||||
List<AbstractResultMessage> temp = new ArrayList<>();
|
||||
for (Any any : anys) {
|
||||
final Class clazz = ProtobufConvertManager.getInstance().fetchProtoClass(
|
||||
getTypeNameFromTypeUrl(any.getTypeUrl()));
|
||||
if (any.is(clazz)) {
|
||||
try {
|
||||
Object ob = any.unpack(clazz);
|
||||
final PbConvertor pbConvertor = ProtobufConvertManager.getInstance().fetchReversedConvertor(
|
||||
clazz.getName());
|
||||
Object model = pbConvertor.convert2Model(ob);
|
||||
temp.add((AbstractResultMessage)model);
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
throw new ShouldNeverHappenException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
result.setMsgs(temp.toArray(new AbstractResultMessage[temp.size()]));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static String getTypeNameFromTypeUrl(java.lang.String typeUrl) {
|
||||
int pos = typeUrl.lastIndexOf('/');
|
||||
return pos == -1 ? "" : typeUrl.substring(pos + 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.protobuf.Any;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import com.google.protobuf.Message;
|
||||
import io.seata.common.exception.ShouldNeverHappenException;
|
||||
import io.seata.core.protocol.AbstractMessage;
|
||||
import io.seata.core.protocol.MergedWarpMessage;
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.MergedWarpMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.serializer.protobuf.manager.ProtobufConvertManager;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class MergedWarpMessageConvertor implements PbConvertor<MergedWarpMessage, MergedWarpMessageProto> {
|
||||
|
||||
@Override
|
||||
public MergedWarpMessageProto convert2Proto(MergedWarpMessage mergedWarpMessage) {
|
||||
|
||||
final short typeCode = mergedWarpMessage.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
List<Any> lists = new ArrayList<>();
|
||||
for (AbstractMessage msg : mergedWarpMessage.msgs) {
|
||||
final PbConvertor pbConvertor = ProtobufConvertManager.getInstance().fetchConvertor(
|
||||
msg.getClass().getName());
|
||||
lists.add(Any.pack((Message)pbConvertor.convert2Proto(msg)));
|
||||
}
|
||||
|
||||
MergedWarpMessageProto mergedWarpMessageProto = MergedWarpMessageProto.newBuilder().setAbstractMessage(
|
||||
abstractMessage).addAllMsgs(lists).addAllMsgIds(mergedWarpMessage.msgIds).build();
|
||||
|
||||
return mergedWarpMessageProto;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public MergedWarpMessage convert2Model(MergedWarpMessageProto mergedWarpMessageProto) {
|
||||
MergedWarpMessage result = new MergedWarpMessage();
|
||||
List<Any> anys = mergedWarpMessageProto.getMsgsList();
|
||||
for (Any any : anys) {
|
||||
final Class clazz = ProtobufConvertManager.getInstance().fetchProtoClass(
|
||||
getTypeNameFromTypeUrl(any.getTypeUrl()));
|
||||
if (any.is(clazz)) {
|
||||
try {
|
||||
Object ob = any.unpack(clazz);
|
||||
final PbConvertor pbConvertor = ProtobufConvertManager.getInstance().fetchReversedConvertor(
|
||||
clazz.getName());
|
||||
Object model = pbConvertor.convert2Model(ob);
|
||||
result.msgs.add((AbstractMessage)model);
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
throw new ShouldNeverHappenException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
result.msgIds = mergedWarpMessageProto.getMsgIdsList();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static String getTypeNameFromTypeUrl(java.lang.String typeUrl) {
|
||||
int pos = typeUrl.lastIndexOf('/');
|
||||
return pos == -1 ? "" : typeUrl.substring(pos + 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public interface PbConvertor<T, S> {
|
||||
|
||||
public S convert2Proto(T t);
|
||||
|
||||
public T convert2Model(S s);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.AbstractIdentifyRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.serializer.protobuf.generated.RegisterRMRequestProto;
|
||||
import io.seata.core.protocol.RegisterRMRequest;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class RegisterRMRequestConvertor implements PbConvertor<RegisterRMRequest, RegisterRMRequestProto> {
|
||||
@Override
|
||||
public RegisterRMRequestProto convert2Proto(RegisterRMRequest registerRMRequest) {
|
||||
final short typeCode = registerRMRequest.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
final String extraData = registerRMRequest.getExtraData();
|
||||
AbstractIdentifyRequestProto abstractIdentifyRequestProto = AbstractIdentifyRequestProto.newBuilder()
|
||||
.setAbstractMessage(abstractMessage).setApplicationId(registerRMRequest.getApplicationId()).setExtraData(
|
||||
extraData == null ? "" : extraData).setTransactionServiceGroup(
|
||||
registerRMRequest.getTransactionServiceGroup()).setVersion(registerRMRequest.getVersion()).build();
|
||||
RegisterRMRequestProto result = RegisterRMRequestProto.newBuilder().setAbstractIdentifyRequest(
|
||||
abstractIdentifyRequestProto).setResourceIds(
|
||||
registerRMRequest.getResourceIds() == null ? "" : registerRMRequest.getResourceIds()).build();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegisterRMRequest convert2Model(RegisterRMRequestProto registerRMRequestProto) {
|
||||
RegisterRMRequest registerRMRequest = new RegisterRMRequest();
|
||||
|
||||
AbstractIdentifyRequestProto abstractIdentifyRequest = registerRMRequestProto.getAbstractIdentifyRequest();
|
||||
registerRMRequest.setResourceIds(registerRMRequestProto.getResourceIds());
|
||||
registerRMRequest.setApplicationId(abstractIdentifyRequest.getApplicationId());
|
||||
registerRMRequest.setExtraData(abstractIdentifyRequest.getExtraData());
|
||||
registerRMRequest.setTransactionServiceGroup(abstractIdentifyRequest.getTransactionServiceGroup());
|
||||
registerRMRequest.setVersion(abstractIdentifyRequest.getVersion());
|
||||
|
||||
return registerRMRequest;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.AbstractIdentifyResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractResultMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.serializer.protobuf.generated.RegisterRMResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.ResultCodeProto;
|
||||
import io.seata.core.protocol.RegisterRMResponse;
|
||||
import io.seata.core.protocol.ResultCode;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class RegisterRMResponseConvertor implements PbConvertor<RegisterRMResponse, RegisterRMResponseProto> {
|
||||
@Override
|
||||
public RegisterRMResponseProto convert2Proto(RegisterRMResponse registerRMResponse) {
|
||||
final short typeCode = registerRMResponse.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
final String msg = registerRMResponse.getMsg();
|
||||
|
||||
//for code
|
||||
if (registerRMResponse.getResultCode() == null) {
|
||||
if (registerRMResponse.isIdentified()) {
|
||||
registerRMResponse.setResultCode(ResultCode.Success);
|
||||
} else {
|
||||
registerRMResponse.setResultCode(ResultCode.Failed);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
final AbstractResultMessageProto abstractResultMessageProto = AbstractResultMessageProto.newBuilder().setMsg(
|
||||
msg == null ? "" : msg).setResultCode(ResultCodeProto.valueOf(registerRMResponse.getResultCode().name()))
|
||||
.setAbstractMessage(abstractMessage).build();
|
||||
|
||||
final String extraData = registerRMResponse.getExtraData();
|
||||
AbstractIdentifyResponseProto abstractIdentifyResponseProto = AbstractIdentifyResponseProto.newBuilder()
|
||||
.setAbstractResultMessage(abstractResultMessageProto).setExtraData(extraData == null ? "" : extraData)
|
||||
.setVersion(registerRMResponse.getVersion()).setIdentified(registerRMResponse.isIdentified()).build();
|
||||
|
||||
RegisterRMResponseProto result = RegisterRMResponseProto.newBuilder().setAbstractIdentifyResponse(
|
||||
abstractIdentifyResponseProto).build();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegisterRMResponse convert2Model(RegisterRMResponseProto registerRMResponseProto) {
|
||||
RegisterRMResponse registerRMRequest = new RegisterRMResponse();
|
||||
|
||||
AbstractIdentifyResponseProto abstractIdentifyRequestProto = registerRMResponseProto
|
||||
.getAbstractIdentifyResponse();
|
||||
registerRMRequest.setExtraData(abstractIdentifyRequestProto.getExtraData());
|
||||
registerRMRequest.setVersion(abstractIdentifyRequestProto.getVersion());
|
||||
registerRMRequest.setIdentified(abstractIdentifyRequestProto.getIdentified());
|
||||
|
||||
registerRMRequest.setMsg(abstractIdentifyRequestProto.getAbstractResultMessage().getMsg());
|
||||
registerRMRequest.setResultCode(
|
||||
ResultCode.valueOf(abstractIdentifyRequestProto.getAbstractResultMessage().getResultCode().name()));
|
||||
|
||||
return registerRMRequest;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.core.protocol.RegisterTMRequest;
|
||||
import io.seata.serializer.protobuf.generated.AbstractIdentifyRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.serializer.protobuf.generated.RegisterTMRequestProto;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class RegisterTMRequestConvertor implements PbConvertor<RegisterTMRequest, RegisterTMRequestProto> {
|
||||
@Override
|
||||
public RegisterTMRequestProto convert2Proto(RegisterTMRequest registerTMRequest) {
|
||||
final short typeCode = registerTMRequest.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
final String extraData = registerTMRequest.getExtraData();
|
||||
AbstractIdentifyRequestProto abstractIdentifyRequestProto = AbstractIdentifyRequestProto.newBuilder()
|
||||
.setAbstractMessage(abstractMessage).setApplicationId(registerTMRequest.getApplicationId()).setExtraData(
|
||||
extraData == null ? "" : extraData).setTransactionServiceGroup(
|
||||
registerTMRequest.getTransactionServiceGroup()).setVersion(registerTMRequest.getVersion()).build();
|
||||
|
||||
RegisterTMRequestProto result = RegisterTMRequestProto.newBuilder().setAbstractIdentifyRequest(
|
||||
abstractIdentifyRequestProto).build();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegisterTMRequest convert2Model(RegisterTMRequestProto registerTMRequestProto) {
|
||||
RegisterTMRequest registerRMRequest = new RegisterTMRequest();
|
||||
|
||||
AbstractIdentifyRequestProto abstractIdentifyRequest = registerTMRequestProto.getAbstractIdentifyRequest();
|
||||
registerRMRequest.setApplicationId(abstractIdentifyRequest.getApplicationId());
|
||||
registerRMRequest.setExtraData(abstractIdentifyRequest.getExtraData());
|
||||
registerRMRequest.setTransactionServiceGroup(abstractIdentifyRequest.getTransactionServiceGroup());
|
||||
registerRMRequest.setVersion(abstractIdentifyRequest.getVersion());
|
||||
|
||||
return registerRMRequest;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.AbstractIdentifyResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractResultMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.serializer.protobuf.generated.RegisterTMResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.ResultCodeProto;
|
||||
import io.seata.core.protocol.RegisterTMResponse;
|
||||
import io.seata.core.protocol.ResultCode;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class RegisterTMResponseConvertor implements PbConvertor<RegisterTMResponse, RegisterTMResponseProto> {
|
||||
@Override
|
||||
public RegisterTMResponseProto convert2Proto(RegisterTMResponse registerTMResponse) {
|
||||
final short typeCode = registerTMResponse.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
final String msg = registerTMResponse.getMsg();
|
||||
//for code
|
||||
if (registerTMResponse.getResultCode() == null) {
|
||||
if (registerTMResponse.isIdentified()) {
|
||||
registerTMResponse.setResultCode(ResultCode.Success);
|
||||
} else {
|
||||
registerTMResponse.setResultCode(ResultCode.Failed);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
final AbstractResultMessageProto abstractResultMessageProto = AbstractResultMessageProto.newBuilder().setMsg(
|
||||
msg == null ? "" : msg).setResultCode(ResultCodeProto.valueOf(registerTMResponse.getResultCode().name()))
|
||||
.setAbstractMessage(abstractMessage).build();
|
||||
|
||||
final String extraData = registerTMResponse.getExtraData();
|
||||
AbstractIdentifyResponseProto abstractIdentifyResponseProto = AbstractIdentifyResponseProto.newBuilder()
|
||||
.setAbstractResultMessage(abstractResultMessageProto).setExtraData(extraData == null ? "" : extraData)
|
||||
.setVersion(registerTMResponse.getVersion()).setIdentified(registerTMResponse.isIdentified()).build();
|
||||
|
||||
RegisterTMResponseProto result = RegisterTMResponseProto.newBuilder().setAbstractIdentifyResponse(
|
||||
abstractIdentifyResponseProto).build();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegisterTMResponse convert2Model(RegisterTMResponseProto registerTMResponseProto) {
|
||||
RegisterTMResponse registerRMRequest = new RegisterTMResponse();
|
||||
|
||||
AbstractIdentifyResponseProto abstractIdentifyRequestProto = registerTMResponseProto
|
||||
.getAbstractIdentifyResponse();
|
||||
registerRMRequest.setExtraData(abstractIdentifyRequestProto.getExtraData());
|
||||
registerRMRequest.setVersion(abstractIdentifyRequestProto.getVersion());
|
||||
registerRMRequest.setIdentified(abstractIdentifyRequestProto.getIdentified());
|
||||
|
||||
registerRMRequest.setMsg(abstractIdentifyRequestProto.getAbstractResultMessage().getMsg());
|
||||
registerRMRequest.setResultCode(
|
||||
ResultCode.valueOf(abstractIdentifyRequestProto.getAbstractResultMessage().getResultCode().name()));
|
||||
|
||||
return registerRMRequest;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.AbstractMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.AbstractTransactionRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.BranchTypeProto;
|
||||
import io.seata.serializer.protobuf.generated.MessageTypeProto;
|
||||
import io.seata.serializer.protobuf.generated.UndoLogDeleteRequestProto;
|
||||
import io.seata.core.model.BranchType;
|
||||
import io.seata.core.protocol.transaction.UndoLogDeleteRequest;
|
||||
|
||||
/**
|
||||
* @author yuanguoyao
|
||||
*/
|
||||
public class UndoLogDeleteRequestConvertor implements PbConvertor<UndoLogDeleteRequest, UndoLogDeleteRequestProto> {
|
||||
@Override
|
||||
public UndoLogDeleteRequestProto convert2Proto(UndoLogDeleteRequest undoLogDeleteRequest) {
|
||||
final short typeCode = undoLogDeleteRequest.getTypeCode();
|
||||
|
||||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(
|
||||
MessageTypeProto.forNumber(typeCode)).build();
|
||||
|
||||
final AbstractTransactionRequestProto abstractTransactionRequestProto = AbstractTransactionRequestProto
|
||||
.newBuilder().setAbstractMessage(abstractMessage).build();
|
||||
|
||||
final UndoLogDeleteRequestProto undoLogDeleteRequestProto = UndoLogDeleteRequestProto.newBuilder()
|
||||
.setAbstractTransactionRequest(abstractTransactionRequestProto).setSaveDays(
|
||||
undoLogDeleteRequest.getSaveDays()).setBranchType(
|
||||
BranchTypeProto.valueOf(undoLogDeleteRequest.getBranchType().name())).setResourceId(
|
||||
undoLogDeleteRequest.getResourceId()).build();
|
||||
|
||||
return undoLogDeleteRequestProto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UndoLogDeleteRequest convert2Model(UndoLogDeleteRequestProto undoLogDeleteRequestProto) {
|
||||
UndoLogDeleteRequest undoLogDeleteRequest = new UndoLogDeleteRequest();
|
||||
undoLogDeleteRequest.setSaveDays((short)undoLogDeleteRequestProto.getSaveDays());
|
||||
undoLogDeleteRequest.setResourceId(undoLogDeleteRequestProto.getResourceId());
|
||||
undoLogDeleteRequest.setBranchType(BranchType.valueOf(undoLogDeleteRequestProto.getBranchType().name()));
|
||||
|
||||
return undoLogDeleteRequest;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,322 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.manager;
|
||||
|
||||
import io.seata.serializer.protobuf.convertor.BranchCommitRequestConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.BranchCommitResponseConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.BranchRegisterRequestConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.BranchRegisterResponseConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.BranchReportRequestConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.BranchReportResponseConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.BranchRollbackRequestConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.BranchRollbackResponseConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.GlobalBeginRequestConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.GlobalBeginResponseConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.GlobalCommitRequestConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.GlobalCommitResponseConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.GlobalLockQueryRequestConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.GlobalLockQueryResponseConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.GlobalReportRequestConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.GlobalReportResponseConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.GlobalRollbackRequestConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.GlobalRollbackResponseConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.GlobalStatusRequestConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.GlobalStatusResponseConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.HeartbeatMessageConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.MergeResultMessageConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.MergedWarpMessageConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.PbConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.RegisterRMRequestConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.RegisterRMResponseConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.RegisterTMRequestConvertor;
|
||||
import io.seata.serializer.protobuf.convertor.RegisterTMResponseConvertor;
|
||||
import io.seata.serializer.protobuf.generated.GlobalReportRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalReportResponseProto;
|
||||
import io.seata.core.protocol.HeartbeatMessage;
|
||||
import io.seata.core.protocol.MergeResultMessage;
|
||||
import io.seata.core.protocol.MergedWarpMessage;
|
||||
import io.seata.core.protocol.RegisterRMRequest;
|
||||
import io.seata.core.protocol.RegisterRMResponse;
|
||||
import io.seata.core.protocol.RegisterTMRequest;
|
||||
import io.seata.core.protocol.RegisterTMResponse;
|
||||
import io.seata.serializer.protobuf.convertor.UndoLogDeleteRequestConvertor;
|
||||
import io.seata.serializer.protobuf.generated.BranchCommitRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.BranchCommitResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.BranchRegisterRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.BranchRegisterResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.BranchReportRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.BranchReportResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.BranchRollbackRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.BranchRollbackResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalBeginRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalBeginResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalCommitRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalCommitResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalLockQueryRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalLockQueryResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalRollbackRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalRollbackResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalStatusRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.GlobalStatusResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.HeartbeatMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.MergedResultMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.MergedWarpMessageProto;
|
||||
import io.seata.serializer.protobuf.generated.RegisterRMRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.RegisterRMResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.RegisterTMRequestProto;
|
||||
import io.seata.serializer.protobuf.generated.RegisterTMResponseProto;
|
||||
import io.seata.serializer.protobuf.generated.UndoLogDeleteRequestProto;
|
||||
import io.seata.core.protocol.transaction.BranchCommitRequest;
|
||||
import io.seata.core.protocol.transaction.BranchCommitResponse;
|
||||
import io.seata.core.protocol.transaction.BranchRegisterRequest;
|
||||
import io.seata.core.protocol.transaction.BranchRegisterResponse;
|
||||
import io.seata.core.protocol.transaction.BranchReportRequest;
|
||||
import io.seata.core.protocol.transaction.BranchReportResponse;
|
||||
import io.seata.core.protocol.transaction.BranchRollbackRequest;
|
||||
import io.seata.core.protocol.transaction.BranchRollbackResponse;
|
||||
import io.seata.core.protocol.transaction.GlobalBeginRequest;
|
||||
import io.seata.core.protocol.transaction.GlobalBeginResponse;
|
||||
import io.seata.core.protocol.transaction.GlobalCommitRequest;
|
||||
import io.seata.core.protocol.transaction.GlobalCommitResponse;
|
||||
import io.seata.core.protocol.transaction.GlobalLockQueryRequest;
|
||||
import io.seata.core.protocol.transaction.GlobalLockQueryResponse;
|
||||
import io.seata.core.protocol.transaction.GlobalReportRequest;
|
||||
import io.seata.core.protocol.transaction.GlobalReportResponse;
|
||||
import io.seata.core.protocol.transaction.GlobalRollbackRequest;
|
||||
import io.seata.core.protocol.transaction.GlobalRollbackResponse;
|
||||
import io.seata.core.protocol.transaction.GlobalStatusRequest;
|
||||
import io.seata.core.protocol.transaction.GlobalStatusResponse;
|
||||
import io.seata.core.protocol.transaction.UndoLogDeleteRequest;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class ProtobufConvertManager {
|
||||
|
||||
private Map<String, PbConvertor> convertorMap = new ConcurrentHashMap<>();
|
||||
|
||||
private Map<String, PbConvertor> reverseConvertorMap = new ConcurrentHashMap<>();
|
||||
|
||||
private Map<String, Class> protoClazzMap = new ConcurrentHashMap<>();
|
||||
|
||||
private static class SingletonHolder {
|
||||
private static final ProtobufConvertManager INSTANCE;
|
||||
|
||||
static {
|
||||
final ProtobufConvertManager protobufConvertManager = new ProtobufConvertManager();
|
||||
protobufConvertManager.convertorMap.put(GlobalBeginRequest.class.getName(),
|
||||
new GlobalBeginRequestConvertor());
|
||||
protobufConvertManager.convertorMap.put(BranchCommitRequest.class.getName(),
|
||||
new BranchCommitRequestConvertor());
|
||||
protobufConvertManager.convertorMap.put(BranchCommitResponse.class.getName(),
|
||||
new BranchCommitResponseConvertor());
|
||||
protobufConvertManager.convertorMap.put(BranchRegisterRequest.class.getName(),
|
||||
new BranchRegisterRequestConvertor());
|
||||
protobufConvertManager.convertorMap.put(BranchRegisterResponse.class.getName(),
|
||||
new BranchRegisterResponseConvertor());
|
||||
protobufConvertManager.convertorMap.put(BranchReportRequest.class.getName(),
|
||||
new BranchReportRequestConvertor());
|
||||
protobufConvertManager.convertorMap.put(BranchReportResponse.class.getName(),
|
||||
new BranchReportResponseConvertor());
|
||||
protobufConvertManager.convertorMap.put(BranchRollbackRequest.class.getName(),
|
||||
new BranchRollbackRequestConvertor());
|
||||
protobufConvertManager.convertorMap.put(BranchRollbackResponse.class.getName(),
|
||||
new BranchRollbackResponseConvertor());
|
||||
protobufConvertManager.convertorMap.put(GlobalBeginResponse.class.getName(),
|
||||
new GlobalBeginResponseConvertor());
|
||||
protobufConvertManager.convertorMap.put(GlobalCommitRequest.class.getName(),
|
||||
new GlobalCommitRequestConvertor());
|
||||
protobufConvertManager.convertorMap.put(GlobalCommitResponse.class.getName(),
|
||||
new GlobalCommitResponseConvertor());
|
||||
protobufConvertManager.convertorMap.put(GlobalLockQueryRequest.class.getName(),
|
||||
new GlobalLockQueryRequestConvertor());
|
||||
protobufConvertManager.convertorMap.put(GlobalLockQueryResponse.class.getName(),
|
||||
new GlobalLockQueryResponseConvertor());
|
||||
protobufConvertManager.convertorMap.put(GlobalRollbackRequest.class.getName(),
|
||||
new GlobalRollbackRequestConvertor());
|
||||
protobufConvertManager.convertorMap.put(GlobalRollbackResponse.class.getName(),
|
||||
new GlobalRollbackResponseConvertor());
|
||||
protobufConvertManager.convertorMap.put(GlobalStatusRequest.class.getName(),
|
||||
new GlobalStatusRequestConvertor());
|
||||
protobufConvertManager.convertorMap.put(GlobalStatusResponse.class.getName(),
|
||||
new GlobalStatusResponseConvertor());
|
||||
protobufConvertManager.convertorMap.put(GlobalReportRequest.class.getName(),
|
||||
new GlobalReportRequestConvertor());
|
||||
protobufConvertManager.convertorMap.put(GlobalReportResponse.class.getName(),
|
||||
new GlobalReportResponseConvertor());
|
||||
protobufConvertManager.convertorMap.put(UndoLogDeleteRequest.class.getName(),
|
||||
new UndoLogDeleteRequestConvertor());
|
||||
|
||||
protobufConvertManager.convertorMap.put(MergedWarpMessage.class.getName(),
|
||||
new MergedWarpMessageConvertor());
|
||||
protobufConvertManager.convertorMap.put(HeartbeatMessage.class.getName(), new HeartbeatMessageConvertor());
|
||||
protobufConvertManager.convertorMap.put(MergeResultMessage.class.getName(),
|
||||
new MergeResultMessageConvertor());
|
||||
protobufConvertManager.convertorMap.put(RegisterRMRequest.class.getName(),
|
||||
new RegisterRMRequestConvertor());
|
||||
protobufConvertManager.convertorMap.put(RegisterRMResponse.class.getName(),
|
||||
new RegisterRMResponseConvertor());
|
||||
protobufConvertManager.convertorMap.put(RegisterTMRequest.class.getName(),
|
||||
new RegisterTMRequestConvertor());
|
||||
protobufConvertManager.convertorMap.put(RegisterTMResponse.class.getName(),
|
||||
new RegisterTMResponseConvertor());
|
||||
|
||||
protobufConvertManager.protoClazzMap.put(GlobalBeginRequestProto.getDescriptor().getFullName(),
|
||||
GlobalBeginRequestProto.class);
|
||||
protobufConvertManager.protoClazzMap.put(BranchCommitRequestProto.getDescriptor().getFullName(),
|
||||
BranchCommitRequestProto.class);
|
||||
protobufConvertManager.protoClazzMap.put(BranchCommitResponseProto.getDescriptor().getFullName(),
|
||||
BranchCommitResponseProto.class);
|
||||
protobufConvertManager.protoClazzMap.put(BranchRegisterRequestProto.getDescriptor().getFullName(),
|
||||
BranchRegisterRequestProto.class);
|
||||
protobufConvertManager.protoClazzMap.put(BranchRegisterResponseProto.getDescriptor().getFullName(),
|
||||
BranchRegisterResponseProto.class);
|
||||
protobufConvertManager.protoClazzMap.put(BranchReportRequestProto.getDescriptor().getFullName(),
|
||||
BranchReportRequestProto.class);
|
||||
protobufConvertManager.protoClazzMap.put(BranchReportResponseProto.getDescriptor().getFullName(),
|
||||
BranchReportResponseProto.class);
|
||||
protobufConvertManager.protoClazzMap.put(BranchRollbackRequestProto.getDescriptor().getFullName(),
|
||||
BranchRollbackRequestProto.class);
|
||||
protobufConvertManager.protoClazzMap.put(BranchRollbackResponseProto.getDescriptor().getFullName(),
|
||||
BranchRollbackResponseProto.class);
|
||||
protobufConvertManager.protoClazzMap.put(GlobalBeginResponseProto.getDescriptor().getFullName(),
|
||||
GlobalBeginResponseProto.class);
|
||||
protobufConvertManager.protoClazzMap.put(GlobalCommitRequestProto.getDescriptor().getFullName(),
|
||||
GlobalCommitRequestProto.class);
|
||||
protobufConvertManager.protoClazzMap.put(GlobalCommitResponseProto.getDescriptor().getFullName(),
|
||||
GlobalCommitResponseProto.class);
|
||||
protobufConvertManager.protoClazzMap.put(GlobalLockQueryRequestProto.getDescriptor().getFullName(),
|
||||
GlobalLockQueryRequestProto.class);
|
||||
protobufConvertManager.protoClazzMap.put(GlobalLockQueryResponseProto.getDescriptor().getFullName(),
|
||||
GlobalLockQueryResponseProto.class);
|
||||
protobufConvertManager.protoClazzMap.put(GlobalRollbackRequestProto.getDescriptor().getFullName(),
|
||||
GlobalRollbackRequestProto.class);
|
||||
protobufConvertManager.protoClazzMap.put(GlobalRollbackResponseProto.getDescriptor().getFullName(),
|
||||
GlobalRollbackResponseProto.class);
|
||||
protobufConvertManager.protoClazzMap.put(GlobalStatusRequestProto.getDescriptor().getFullName(),
|
||||
GlobalStatusRequestProto.class);
|
||||
protobufConvertManager.protoClazzMap.put(GlobalStatusResponseProto.getDescriptor().getFullName(),
|
||||
GlobalStatusResponseProto.class);
|
||||
protobufConvertManager.protoClazzMap.put(GlobalReportRequestProto.getDescriptor().getFullName(),
|
||||
GlobalReportRequestProto.class);
|
||||
protobufConvertManager.protoClazzMap.put(GlobalReportResponseProto.getDescriptor().getFullName(),
|
||||
GlobalReportResponseProto.class);
|
||||
protobufConvertManager.protoClazzMap.put(UndoLogDeleteRequestProto.getDescriptor().getFullName(),
|
||||
UndoLogDeleteRequestProto.class);
|
||||
|
||||
protobufConvertManager.protoClazzMap.put(MergedWarpMessageProto.getDescriptor().getFullName(),
|
||||
MergedWarpMessageProto.class);
|
||||
protobufConvertManager.protoClazzMap.put(HeartbeatMessageProto.getDescriptor().getFullName(),
|
||||
HeartbeatMessageProto.class);
|
||||
protobufConvertManager.protoClazzMap.put(MergedResultMessageProto.getDescriptor().getFullName(),
|
||||
MergedResultMessageProto.class);
|
||||
protobufConvertManager.protoClazzMap.put(RegisterRMRequestProto.getDescriptor().getFullName(),
|
||||
RegisterRMRequestProto.class);
|
||||
protobufConvertManager.protoClazzMap.put(RegisterRMResponseProto.getDescriptor().getFullName(),
|
||||
RegisterRMResponseProto.class);
|
||||
protobufConvertManager.protoClazzMap.put(RegisterTMRequestProto.getDescriptor().getFullName(),
|
||||
RegisterTMRequestProto.class);
|
||||
protobufConvertManager.protoClazzMap.put(RegisterTMResponseProto.getDescriptor().getFullName(),
|
||||
RegisterTMResponseProto.class);
|
||||
|
||||
protobufConvertManager.reverseConvertorMap.put(GlobalBeginRequestProto.class.getName(),
|
||||
new GlobalBeginRequestConvertor());
|
||||
protobufConvertManager.reverseConvertorMap.put(BranchCommitRequestProto.class.getName(),
|
||||
new BranchCommitRequestConvertor());
|
||||
protobufConvertManager.reverseConvertorMap.put(BranchCommitResponseProto.class.getName(),
|
||||
new BranchCommitResponseConvertor());
|
||||
protobufConvertManager.reverseConvertorMap.put(BranchRegisterRequestProto.class.getName(),
|
||||
new BranchRegisterRequestConvertor());
|
||||
protobufConvertManager.reverseConvertorMap.put(BranchRegisterResponseProto.class.getName(),
|
||||
new BranchRegisterResponseConvertor());
|
||||
protobufConvertManager.reverseConvertorMap.put(BranchReportRequestProto.class.getName(),
|
||||
new BranchReportRequestConvertor());
|
||||
protobufConvertManager.reverseConvertorMap.put(BranchReportResponseProto.class.getName(),
|
||||
new BranchReportResponseConvertor());
|
||||
protobufConvertManager.reverseConvertorMap.put(BranchRollbackRequestProto.class.getName(),
|
||||
new BranchRollbackRequestConvertor());
|
||||
protobufConvertManager.reverseConvertorMap.put(BranchRollbackResponseProto.class.getName(),
|
||||
new BranchRollbackResponseConvertor());
|
||||
protobufConvertManager.reverseConvertorMap.put(GlobalBeginResponseProto.class.getName(),
|
||||
new GlobalBeginResponseConvertor());
|
||||
protobufConvertManager.reverseConvertorMap.put(GlobalCommitRequestProto.class.getName(),
|
||||
new GlobalCommitRequestConvertor());
|
||||
protobufConvertManager.reverseConvertorMap.put(GlobalCommitResponseProto.class.getName(),
|
||||
new GlobalCommitResponseConvertor());
|
||||
protobufConvertManager.reverseConvertorMap.put(GlobalLockQueryRequestProto.class.getName(),
|
||||
new GlobalLockQueryRequestConvertor());
|
||||
protobufConvertManager.reverseConvertorMap.put(GlobalLockQueryResponseProto.class.getName(),
|
||||
new GlobalLockQueryResponseConvertor());
|
||||
protobufConvertManager.reverseConvertorMap.put(GlobalRollbackRequestProto.class.getName(),
|
||||
new GlobalRollbackRequestConvertor());
|
||||
protobufConvertManager.reverseConvertorMap.put(GlobalRollbackResponseProto.class.getName(),
|
||||
new GlobalRollbackResponseConvertor());
|
||||
protobufConvertManager.reverseConvertorMap.put(GlobalStatusRequestProto.class.getName(),
|
||||
new GlobalStatusRequestConvertor());
|
||||
protobufConvertManager.reverseConvertorMap.put(GlobalStatusResponseProto.class.getName(),
|
||||
new GlobalStatusResponseConvertor());
|
||||
protobufConvertManager.reverseConvertorMap.put(GlobalReportRequestProto.class.getName(),
|
||||
new GlobalReportRequestConvertor());
|
||||
protobufConvertManager.reverseConvertorMap.put(GlobalReportResponseProto.class.getName(),
|
||||
new GlobalReportResponseConvertor());
|
||||
protobufConvertManager.reverseConvertorMap.put(UndoLogDeleteRequestProto.class.getName(),
|
||||
new UndoLogDeleteRequestConvertor());
|
||||
|
||||
protobufConvertManager.reverseConvertorMap.put(MergedWarpMessageProto.class.getName(),
|
||||
new MergedWarpMessageConvertor());
|
||||
protobufConvertManager.reverseConvertorMap.put(HeartbeatMessageProto.class.getName(),
|
||||
new HeartbeatMessageConvertor());
|
||||
protobufConvertManager.reverseConvertorMap.put(MergedResultMessageProto.class.getName(),
|
||||
new MergeResultMessageConvertor());
|
||||
protobufConvertManager.reverseConvertorMap.put(RegisterRMRequestProto.class.getName(),
|
||||
new RegisterRMRequestConvertor());
|
||||
protobufConvertManager.reverseConvertorMap.put(RegisterRMResponseProto.class.getName(),
|
||||
new RegisterRMResponseConvertor());
|
||||
protobufConvertManager.reverseConvertorMap.put(RegisterTMRequestProto.class.getName(),
|
||||
new RegisterTMRequestConvertor());
|
||||
protobufConvertManager.reverseConvertorMap.put(RegisterTMResponseProto.class.getName(),
|
||||
new RegisterTMResponseConvertor());
|
||||
|
||||
INSTANCE = protobufConvertManager;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets instance.
|
||||
*
|
||||
* @return the instance
|
||||
*/
|
||||
public static final ProtobufConvertManager getInstance() {
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
public PbConvertor fetchConvertor(String clazz) {
|
||||
return convertorMap.get(clazz);
|
||||
}
|
||||
|
||||
public PbConvertor fetchReversedConvertor(String clazz) {
|
||||
return reverseConvertorMap.get(clazz);
|
||||
}
|
||||
|
||||
public Class fetchProtoClass(String clazz) {
|
||||
return protoClazzMap.get(clazz);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
io.seata.serializer.protobuf.ProtobufSerializer
|
||||
@@ -0,0 +1,35 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractTransactionRequest.proto";
|
||||
import "branchType.proto";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "AbstractBranchEndRequest";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
message AbstractBranchEndRequestProto {
|
||||
AbstractTransactionRequestProto abstractTransactionRequest = 1;
|
||||
string xid = 2;
|
||||
/**
|
||||
* The Branch id.
|
||||
*/
|
||||
int64 branchId = 3;
|
||||
|
||||
/**
|
||||
* The Branch type.
|
||||
*/
|
||||
BranchTypeProto branchType = 4;
|
||||
|
||||
/**
|
||||
* The Resource id.
|
||||
*/
|
||||
string resourceId = 5;
|
||||
|
||||
/**
|
||||
* The Application data.
|
||||
*/
|
||||
string applicationData = 6;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractTransactionResponse.proto";
|
||||
import "branchStatus.proto";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "AbstractBranchEndResponse";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
message AbstractBranchEndResponseProto {
|
||||
|
||||
AbstractTransactionResponseProto abstractTransactionResponse =1;
|
||||
string xid = 2;
|
||||
int64 branchId = 3;
|
||||
BranchStatusProto branchStatus = 4;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractTransactionRequest.proto";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "AbstractGlobalEndRequest";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
message AbstractGlobalEndRequestProto {
|
||||
|
||||
AbstractTransactionRequestProto abstractTransactionRequest =1;
|
||||
string xid = 2;
|
||||
string extraData = 3;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractTransactionResponse.proto";
|
||||
import "globalStatus.proto";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "AbstractGlobalEndResponse";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
message AbstractGlobalEndResponseProto {
|
||||
AbstractTransactionResponseProto abstractTransactionResponse = 1;
|
||||
GlobalStatusProto globalStatus = 2;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractMessage.proto";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "AbstractIdentifyRequest";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
message AbstractIdentifyRequestProto {
|
||||
|
||||
AbstractMessageProto abstractMessage=1;
|
||||
|
||||
string version = 2;
|
||||
|
||||
string applicationId = 3;
|
||||
|
||||
string transactionServiceGroup = 4;
|
||||
|
||||
string extraData = 5;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractResultMessage.proto";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "AbstractIdentifyResponse";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
message AbstractIdentifyResponseProto {
|
||||
|
||||
AbstractResultMessageProto abstractResultMessage=1;
|
||||
string version = 2;
|
||||
string extraData = 3;
|
||||
bool identified = 4;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "messageType.proto";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "AbstractMessage";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
message AbstractMessageProto {
|
||||
MessageTypeProto messageType = 1;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "resultCode.proto";
|
||||
import "abstractMessage.proto";
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "AbstractResultMessage";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
message AbstractResultMessageProto {
|
||||
AbstractMessageProto AbstractMessage=1;
|
||||
ResultCodeProto resultCode = 2;
|
||||
string msg = 3;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractMessage.proto";
|
||||
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "AbstractTransactionRequest";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
message AbstractTransactionRequestProto {
|
||||
AbstractMessageProto abstractMessage=1;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractResultMessage.proto";
|
||||
import "transactionExceptionCode.proto";
|
||||
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "AbstractTransactionResponse";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
message AbstractTransactionResponseProto {
|
||||
AbstractResultMessageProto abstractResultMessage = 1;
|
||||
TransactionExceptionCodeProto transactionExceptionCode = 2;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractBranchEndRequest.proto";
|
||||
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "BranchCommitRequest";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
message BranchCommitRequestProto {
|
||||
AbstractBranchEndRequestProto abstractBranchEndRequest = 1;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractBranchEndResponse.proto";
|
||||
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "BranchCommitResponse";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
message BranchCommitResponseProto {
|
||||
AbstractBranchEndResponseProto abstractBranchEndResponse = 1;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "branchType.proto";
|
||||
import "abstractTransactionRequest.proto";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "BranchRegisterRequest";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
message BranchRegisterRequestProto {
|
||||
AbstractTransactionRequestProto abstractTransactionRequest =1;
|
||||
string xid = 2;
|
||||
BranchTypeProto branchType = 3;
|
||||
string resourceId = 4;
|
||||
string lockKey = 5;
|
||||
string applicationData = 6;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractTransactionResponse.proto";
|
||||
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "BranchRegisterResponse";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
message BranchRegisterResponseProto {
|
||||
AbstractTransactionResponseProto abstractTransactionResponse = 1;
|
||||
int64 branchId = 2;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "branchStatus.proto";
|
||||
import "branchType.proto";
|
||||
import "abstractTransactionRequest.proto";
|
||||
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "BranchReportRequest";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
message BranchReportRequestProto {
|
||||
|
||||
AbstractTransactionRequestProto abstractTransactionRequest =1;
|
||||
string xid = 2;
|
||||
|
||||
int64 branchId = 3;
|
||||
|
||||
string resourceId = 4;
|
||||
|
||||
BranchStatusProto status = 5;
|
||||
|
||||
string applicationData = 6;
|
||||
|
||||
BranchTypeProto branchType = 7;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractTransactionResponse.proto";
|
||||
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "BranchReportResponse";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
message BranchReportResponseProto {
|
||||
AbstractTransactionResponseProto abstractTransactionResponse = 1;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractBranchEndRequest.proto";
|
||||
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "BranchRollbackRequest";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
message BranchRollbackRequestProto {
|
||||
AbstractBranchEndRequestProto abstractBranchEndRequest = 1;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractBranchEndResponse.proto";
|
||||
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "BranchRollbackResponse";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
message BranchRollbackResponseProto {
|
||||
AbstractBranchEndResponseProto abstractBranchEndResponse = 1;
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "BranchStatus";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
enum BranchStatusProto {
|
||||
|
||||
/**
|
||||
* Unknown branch status.
|
||||
*/
|
||||
// special for Unknown
|
||||
BUnknown = 0;
|
||||
|
||||
/**
|
||||
* The Registered.
|
||||
*/
|
||||
// Registered to TC.
|
||||
Registered = 1;
|
||||
|
||||
/**
|
||||
* The Phase one done.
|
||||
*/
|
||||
// Branch logic is successfully done at phase one.
|
||||
PhaseOne_Done = 2;
|
||||
|
||||
/**
|
||||
* The Phase one failed.
|
||||
*/
|
||||
// Branch logic is failed at phase one.
|
||||
PhaseOne_Failed = 3;
|
||||
|
||||
/**
|
||||
* The Phase one timeout.
|
||||
*/
|
||||
// Branch logic is NOT reported for a timeout.
|
||||
PhaseOne_Timeout = 4;
|
||||
|
||||
/**
|
||||
* The Phase two committed.
|
||||
*/
|
||||
// Commit logic is successfully done at phase two.
|
||||
PhaseTwo_Committed = 5;
|
||||
|
||||
/**
|
||||
* The Phase two commit failed retryable.
|
||||
*/
|
||||
// Commit logic is failed but retryable.
|
||||
PhaseTwo_CommitFailed_Retryable = 6;
|
||||
|
||||
/**
|
||||
* The Phase two commit failed unretryable.
|
||||
*/
|
||||
// Commit logic is failed and NOT retryable.
|
||||
PhaseTwo_CommitFailed_Unretryable = 7;
|
||||
|
||||
/**
|
||||
* The Phase two rollbacked.
|
||||
*/
|
||||
// Rollback logic is successfully done at phase two.
|
||||
PhaseTwo_Rollbacked = 8;
|
||||
|
||||
/**
|
||||
* The Phase two rollback failed retryable.
|
||||
*/
|
||||
// Rollback logic is failed but retryable.
|
||||
PhaseTwo_RollbackFailed_Retryable = 9;
|
||||
|
||||
/**
|
||||
* The Phase two rollback failed unretryable.
|
||||
*/
|
||||
// Rollback logic is failed but NOT retryable.
|
||||
PhaseTwo_RollbackFailed_Unretryable = 10;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "BranchType";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
enum BranchTypeProto {
|
||||
|
||||
AT = 0;
|
||||
|
||||
TCC = 1;
|
||||
|
||||
SAGA = 2;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractTransactionRequest.proto";
|
||||
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "GlobalBeginRequest";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
message GlobalBeginRequestProto {
|
||||
AbstractTransactionRequestProto abstractTransactionRequest=1;
|
||||
int32 timeout = 2;
|
||||
string transactionName = 3;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractTransactionResponse.proto";
|
||||
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "GlobalBeginResponse";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
message GlobalBeginResponseProto {
|
||||
AbstractTransactionResponseProto abstractTransactionResponse =1;
|
||||
string xid = 2;
|
||||
string extraData = 3;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractGlobalEndRequest.proto";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "GlobalCommitRequest";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
message GlobalCommitRequestProto {
|
||||
AbstractGlobalEndRequestProto abstractGlobalEndRequest =1;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractGlobalEndResponse.proto";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "GlobalCommitResponse";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
message GlobalCommitResponseProto {
|
||||
AbstractGlobalEndResponseProto abstractGlobalEndResponse =1;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "branchRegisterRequest.proto";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "GlobalLockQueryRequest";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
message GlobalLockQueryRequestProto {
|
||||
BranchRegisterRequestProto branchRegisterRequest =1;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractTransactionResponse.proto";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "GlobalLockQueryResponse";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
message GlobalLockQueryResponseProto {
|
||||
AbstractTransactionResponseProto abstractTransactionResponse = 1;
|
||||
bool lockable = 2;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractGlobalEndRequest.proto";
|
||||
import "globalStatus.proto";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "GlobalReportRequest";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
message GlobalReportRequestProto {
|
||||
AbstractGlobalEndRequestProto abstractGlobalEndRequest = 1;
|
||||
GlobalStatusProto globalStatus = 2;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractGlobalEndResponse.proto";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "GlobalReportResponse";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
message GlobalReportResponseProto {
|
||||
AbstractGlobalEndResponseProto abstractGlobalEndResponse = 1;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractGlobalEndRequest.proto";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "GlobalRollbackRequest";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
message GlobalRollbackRequestProto {
|
||||
AbstractGlobalEndRequestProto abstractGlobalEndRequest = 1;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractGlobalEndResponse.proto";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "GlobalRollbackResponse";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
message GlobalRollbackResponseProto {
|
||||
AbstractGlobalEndResponseProto abstractGlobalEndResponse = 1;
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "GlobalStatus";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
enum GlobalStatusProto {
|
||||
|
||||
/**
|
||||
* Un known global status.
|
||||
*/
|
||||
// Unknown
|
||||
UnKnown = 0;
|
||||
|
||||
/**
|
||||
* The Begin.
|
||||
*/
|
||||
// PHASE 1: can accept new branch registering.
|
||||
Begin = 1;
|
||||
|
||||
/**
|
||||
* PHASE 2: Running Status: may be changed any time.
|
||||
*/
|
||||
// Committing.
|
||||
Committing = 2;
|
||||
|
||||
/**
|
||||
* The Commit retrying.
|
||||
*/
|
||||
// Retrying commit after a recoverable failure.
|
||||
CommitRetrying = 3;
|
||||
|
||||
/**
|
||||
* Rollbacking global status.
|
||||
*/
|
||||
// Rollbacking
|
||||
Rollbacking = 4;
|
||||
|
||||
/**
|
||||
* The Rollback retrying.
|
||||
*/
|
||||
// Retrying rollback after a recoverable failure.
|
||||
RollbackRetrying = 5;
|
||||
|
||||
/**
|
||||
* The Timeout rollbacking.
|
||||
*/
|
||||
// Rollbacking since timeout
|
||||
TimeoutRollbacking = 6;
|
||||
|
||||
/**
|
||||
* The Timeout rollback retrying.
|
||||
*/
|
||||
// Retrying rollback (since timeout) after a recoverable failure.
|
||||
TimeoutRollbackRetrying = 7;
|
||||
|
||||
/**
|
||||
* All branches can be async committed. The committing is NOT done yet, but it can be seen as committed for TM/RM
|
||||
* client.
|
||||
*/
|
||||
AsyncCommitting = 8;
|
||||
|
||||
/**
|
||||
* PHASE 2: Final Status: will NOT change any more.
|
||||
*/
|
||||
// Finally: global transaction is successfully committed.
|
||||
Committed = 9;
|
||||
|
||||
/**
|
||||
* The Commit failed.
|
||||
*/
|
||||
// Finally: failed to commit
|
||||
CommitFailed = 10;
|
||||
|
||||
/**
|
||||
* The Rollbacked.
|
||||
*/
|
||||
// Finally: global transaction is successfully rollbacked.
|
||||
Rollbacked = 11;
|
||||
|
||||
/**
|
||||
* The Rollback failed.
|
||||
*/
|
||||
// Finally: failed to rollback
|
||||
RollbackFailed = 12;
|
||||
|
||||
/**
|
||||
* The Timeout rollbacked.
|
||||
*/
|
||||
// Finally: global transaction is successfully rollbacked since timeout.
|
||||
TimeoutRollbacked = 13;
|
||||
|
||||
/**
|
||||
* The Timeout rollback failed.
|
||||
*/
|
||||
// Finally: failed to rollback since timeout
|
||||
TimeoutRollbackFailed = 14;
|
||||
|
||||
/**
|
||||
* The Finished.
|
||||
*/
|
||||
// Not managed in session MAP any more
|
||||
Finished = 15;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractGlobalEndRequest.proto";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "GlobalStatusRequest";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
message GlobalStatusRequestProto {
|
||||
AbstractGlobalEndRequestProto abstractGlobalEndRequest = 1;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractGlobalEndResponse.proto";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "GlobalStatusResponse";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
message GlobalStatusResponseProto {
|
||||
AbstractGlobalEndResponseProto abstractGlobalEndResponse = 1;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "HeartbeatMessage";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
message HeartbeatMessageProto {
|
||||
bool ping = 1;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractMessage.proto";
|
||||
import "google/protobuf/any.proto";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "MergedResultMessage";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
message MergedResultMessageProto {
|
||||
AbstractMessageProto abstractMessage=1;
|
||||
repeated google.protobuf.Any msgs = 2;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractMessage.proto";
|
||||
import "google/protobuf/any.proto";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "MergedWarpMessage";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
message MergedWarpMessageProto {
|
||||
AbstractMessageProto abstractMessage=1;
|
||||
repeated google.protobuf.Any msgs = 2;
|
||||
repeated int32 msgIds=3;
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "MessageType";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
enum MessageTypeProto {
|
||||
|
||||
TYPE_GLOBAL_PRESERVED = 0;
|
||||
|
||||
TYPE_GLOBAL_BEGIN = 1;
|
||||
|
||||
TYPE_GLOBAL_BEGIN_RESULT = 2;
|
||||
/**
|
||||
* The constant TYPE_GLOBAL_COMMIT.
|
||||
*/
|
||||
TYPE_GLOBAL_COMMIT = 7;
|
||||
/**
|
||||
* The constant TYPE_GLOBAL_COMMIT_RESULT.
|
||||
*/
|
||||
TYPE_GLOBAL_COMMIT_RESULT = 8;
|
||||
/**
|
||||
* The constant TYPE_GLOBAL_ROLLBACK.
|
||||
*/
|
||||
TYPE_GLOBAL_ROLLBACK = 9;
|
||||
/**
|
||||
* The constant TYPE_GLOBAL_ROLLBACK_RESULT.
|
||||
*/
|
||||
TYPE_GLOBAL_ROLLBACK_RESULT = 10;
|
||||
/**
|
||||
* The constant TYPE_GLOBAL_STATUS.
|
||||
*/
|
||||
TYPE_GLOBAL_STATUS = 15;
|
||||
/**
|
||||
* The constant TYPE_GLOBAL_STATUS_RESULT.
|
||||
*/
|
||||
TYPE_GLOBAL_STATUS_RESULT = 16;
|
||||
/**
|
||||
* The constant TYPE_GLOBAL_REPORT.
|
||||
*/
|
||||
TYPE_GLOBAL_REPORT = 17;
|
||||
/**
|
||||
* The constant TYPE_GLOBAL_REPORT_RESULT.
|
||||
*/
|
||||
TYPE_GLOBAL_REPORT_RESULT = 18;
|
||||
/**
|
||||
* The constant TYPE_GLOBAL_LOCK_QUERY.
|
||||
*/
|
||||
TYPE_GLOBAL_LOCK_QUERY = 21;
|
||||
/**
|
||||
* The constant TYPE_GLOBAL_LOCK_QUERY_RESULT.
|
||||
*/
|
||||
TYPE_GLOBAL_LOCK_QUERY_RESULT = 22;
|
||||
|
||||
/**
|
||||
* The constant TYPE_BRANCH_COMMIT.
|
||||
*/
|
||||
TYPE_BRANCH_COMMIT = 3;
|
||||
/**
|
||||
* The constant TYPE_BRANCH_COMMIT_RESULT.
|
||||
*/
|
||||
TYPE_BRANCH_COMMIT_RESULT = 4;
|
||||
/**
|
||||
* The constant TYPE_BRANCH_ROLLBACK.
|
||||
*/
|
||||
TYPE_BRANCH_ROLLBACK = 5;
|
||||
/**
|
||||
* The constant TYPE_BRANCH_ROLLBACK_RESULT.
|
||||
*/
|
||||
TYPE_BRANCH_ROLLBACK_RESULT = 6;
|
||||
/**
|
||||
* The constant TYPE_BRANCH_REGISTER.
|
||||
*/
|
||||
TYPE_BRANCH_REGISTER = 11;
|
||||
/**
|
||||
* The constant TYPE_BRANCH_REGISTER_RESULT.
|
||||
*/
|
||||
TYPE_BRANCH_REGISTER_RESULT = 12;
|
||||
/**
|
||||
* The constant TYPE_BRANCH_STATUS_REPORT.
|
||||
*/
|
||||
TYPE_BRANCH_STATUS_REPORT = 13;
|
||||
/**
|
||||
* The constant TYPE_BRANCH_STATUS_REPORT_RESULT.
|
||||
*/
|
||||
TYPE_BRANCH_STATUS_REPORT_RESULT = 14;
|
||||
|
||||
/**
|
||||
* The constant TYPE_SEATA_MERGE.
|
||||
*/
|
||||
TYPE_SEATA_MERGE = 59;
|
||||
/**
|
||||
* The constant TYPE_SEATA_MERGE_RESULT.
|
||||
*/
|
||||
TYPE_SEATA_MERGE_RESULT = 60;
|
||||
|
||||
/**
|
||||
* The constant TYPE_REG_CLT.
|
||||
*/
|
||||
TYPE_REG_CLT = 101;
|
||||
/**
|
||||
* The constant TYPE_REG_CLT_RESULT.
|
||||
*/
|
||||
TYPE_REG_CLT_RESULT = 102;
|
||||
/**
|
||||
* The constant TYPE_REG_RM.
|
||||
*/
|
||||
TYPE_REG_RM = 103;
|
||||
/**
|
||||
* The constant TYPE_REG_RM_RESULT.
|
||||
*/
|
||||
TYPE_REG_RM_RESULT = 104;
|
||||
|
||||
/**
|
||||
* The constant TYPE_UNDO_LOG_DELETE.
|
||||
*/
|
||||
TYPE_UNDO_LOG_DELETE = 111;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractIdentifyRequest.proto";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "RegisterRMRequest";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
message RegisterRMRequestProto {
|
||||
AbstractIdentifyRequestProto abstractIdentifyRequest = 1;
|
||||
string resourceIds = 2;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractIdentifyResponse.proto";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "RegisterRMResponse";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
message RegisterRMResponseProto {
|
||||
AbstractIdentifyResponseProto abstractIdentifyResponse = 1;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractIdentifyRequest.proto";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "RegisterTMRequest";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
message RegisterTMRequestProto {
|
||||
AbstractIdentifyRequestProto abstractIdentifyRequest = 1;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractIdentifyResponse.proto";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "RegisterTMResponse";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
message RegisterTMResponseProto {
|
||||
AbstractIdentifyResponseProto abstractIdentifyResponse = 1;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "ResultCode";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
enum ResultCodeProto {
|
||||
|
||||
Failed = 0;
|
||||
|
||||
Success = 1;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "TransactionExceptionCode";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
enum TransactionExceptionCodeProto {
|
||||
|
||||
/**
|
||||
* Unknown transaction exception code.
|
||||
*/
|
||||
//
|
||||
Unknown = 0;
|
||||
|
||||
/**
|
||||
* Lock key conflict transaction exception code.
|
||||
*/
|
||||
//
|
||||
LockKeyConflict = 1;
|
||||
|
||||
/**
|
||||
* Io transaction exception code.
|
||||
*/
|
||||
//
|
||||
IO = 2;
|
||||
|
||||
/**
|
||||
* Branch rollback failed retriable transaction exception code.
|
||||
*/
|
||||
//
|
||||
BranchRollbackFailed_Retriable = 3;
|
||||
|
||||
/**
|
||||
* Branch rollback failed unretriable transaction exception code.
|
||||
*/
|
||||
//
|
||||
BranchRollbackFailed_Unretriable = 4;
|
||||
|
||||
/**
|
||||
* Branch register failed transaction exception code.
|
||||
*/
|
||||
//
|
||||
BranchRegisterFailed = 5;
|
||||
|
||||
/**
|
||||
* Branch report failed transaction exception code.
|
||||
*/
|
||||
//
|
||||
BranchReportFailed = 6;
|
||||
|
||||
/**
|
||||
* Lockable check failed transaction exception code.
|
||||
*/
|
||||
//
|
||||
LockableCheckFailed = 7;
|
||||
|
||||
/**
|
||||
* Branch transaction not exist transaction exception code.
|
||||
*/
|
||||
//
|
||||
BranchTransactionNotExist = 8;
|
||||
|
||||
/**
|
||||
* Global transaction not exist transaction exception code.
|
||||
*/
|
||||
//
|
||||
GlobalTransactionNotExist = 9;
|
||||
|
||||
/**
|
||||
* Global transaction not active transaction exception code.
|
||||
*/
|
||||
//
|
||||
GlobalTransactionNotActive = 10;
|
||||
|
||||
/**
|
||||
* Global transaction status invalid transaction exception code.
|
||||
*/
|
||||
//
|
||||
GlobalTransactionStatusInvalid = 11;
|
||||
|
||||
/**
|
||||
* Failed to send branch commit request transaction exception code.
|
||||
*/
|
||||
//
|
||||
FailedToSendBranchCommitRequest = 12;
|
||||
|
||||
/**
|
||||
* Failed to send branch rollback request transaction exception code.
|
||||
*/
|
||||
//
|
||||
FailedToSendBranchRollbackRequest = 13;
|
||||
|
||||
/**
|
||||
* Failed to add branch transaction exception code.
|
||||
*/
|
||||
//
|
||||
FailedToAddBranch = 14;
|
||||
|
||||
/**
|
||||
* Failed to lock global transaction exception code.
|
||||
*/
|
||||
FailedLockGlobalTranscation = 15;
|
||||
|
||||
/**
|
||||
* FailedWriteSession
|
||||
*/
|
||||
FailedWriteSession = 16;
|
||||
|
||||
/**
|
||||
* FailedStore
|
||||
*/
|
||||
FailedStore = 17;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package io.seata.protocol.protobuf;
|
||||
|
||||
import "abstractTransactionRequest.proto";
|
||||
import "branchType.proto";
|
||||
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "UndoLogDeleteRequest";
|
||||
option java_package = "io.seata.serializer.protobuf.generated";
|
||||
|
||||
// PublishRequest is a publish request.
|
||||
message UndoLogDeleteRequestProto {
|
||||
AbstractTransactionRequestProto abstractTransactionRequest = 1;
|
||||
|
||||
/**
|
||||
* The Resource id.
|
||||
*/
|
||||
string resourceId = 2;
|
||||
|
||||
/**
|
||||
* The SaveDays data.
|
||||
*/
|
||||
int32 saveDays = 3;
|
||||
|
||||
/**
|
||||
* The Branch type.
|
||||
*/
|
||||
BranchTypeProto branchType = 4;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.BranchCommitRequestProto;
|
||||
import io.seata.core.model.BranchType;
|
||||
import io.seata.core.protocol.transaction.BranchCommitRequest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class BranchCommitRequestConvertorTest {
|
||||
|
||||
@Test
|
||||
public void convert2Proto() {
|
||||
|
||||
BranchCommitRequest branchCommitRequest = new BranchCommitRequest();
|
||||
branchCommitRequest.setBranchType(BranchType.AT);
|
||||
branchCommitRequest.setXid("xid");
|
||||
branchCommitRequest.setResourceId("resourceId");
|
||||
branchCommitRequest.setBranchId(123);
|
||||
branchCommitRequest.setApplicationData("app");
|
||||
|
||||
BranchCommitRequestConvertor branchCommitRequestConvertor = new BranchCommitRequestConvertor();
|
||||
BranchCommitRequestProto proto = branchCommitRequestConvertor.convert2Proto(
|
||||
branchCommitRequest);
|
||||
BranchCommitRequest realRequest = branchCommitRequestConvertor.convert2Model(proto);
|
||||
|
||||
assertThat(realRequest.getTypeCode()).isEqualTo(branchCommitRequest.getTypeCode());
|
||||
assertThat(realRequest.getBranchType()).isEqualTo(branchCommitRequest.getBranchType());
|
||||
assertThat(realRequest.getXid()).isEqualTo(branchCommitRequest.getXid());
|
||||
assertThat(realRequest.getResourceId()).isEqualTo(branchCommitRequest.getResourceId());
|
||||
assertThat(realRequest.getBranchId()).isEqualTo(branchCommitRequest.getBranchId());
|
||||
assertThat(realRequest.getApplicationData()).isEqualTo(branchCommitRequest.getApplicationData());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.BranchCommitResponseProto;
|
||||
import io.seata.core.exception.TransactionExceptionCode;
|
||||
import io.seata.core.model.BranchStatus;
|
||||
import io.seata.core.protocol.ResultCode;
|
||||
import io.seata.core.protocol.transaction.BranchCommitResponse;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class BranchCommitResponseConvertorTest {
|
||||
|
||||
@Test
|
||||
public void convert2Proto() {
|
||||
|
||||
BranchCommitResponse branchCommitResponse = new BranchCommitResponse();
|
||||
branchCommitResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchTransactionNotExist);
|
||||
branchCommitResponse.setResultCode(ResultCode.Success);
|
||||
branchCommitResponse.setMsg("xx");
|
||||
branchCommitResponse.setXid("xid");
|
||||
branchCommitResponse.setBranchStatus(BranchStatus.PhaseTwo_Rollbacked);
|
||||
branchCommitResponse.setBranchId(123);
|
||||
|
||||
BranchCommitResponseConvertor convertor = new BranchCommitResponseConvertor();
|
||||
BranchCommitResponseProto proto = convertor.convert2Proto(branchCommitResponse);
|
||||
BranchCommitResponse real = convertor.convert2Model(proto);
|
||||
|
||||
assertThat(real.getTypeCode()).isEqualTo(branchCommitResponse.getTypeCode());
|
||||
assertThat(real.getMsg()).isEqualTo(branchCommitResponse.getMsg());
|
||||
assertThat(real.getXid()).isEqualTo(branchCommitResponse.getXid());
|
||||
assertThat(real.getTransactionExceptionCode()).isEqualTo(branchCommitResponse.getTransactionExceptionCode());
|
||||
assertThat(real.getBranchStatus()).isEqualTo(branchCommitResponse.getBranchStatus());
|
||||
assertThat(real.getResultCode()).isEqualTo(branchCommitResponse.getResultCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.BranchRegisterRequestProto;
|
||||
import io.seata.core.model.BranchType;
|
||||
import io.seata.core.protocol.transaction.BranchRegisterRequest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class BranchRegisterRequestConvertorTest {
|
||||
|
||||
@Test
|
||||
public void convert2Proto() {
|
||||
|
||||
BranchRegisterRequest branchRegisterRequest = new BranchRegisterRequest();
|
||||
branchRegisterRequest.setApplicationData("data");
|
||||
branchRegisterRequest.setBranchType(BranchType.AT);
|
||||
branchRegisterRequest.setLockKey("localKey");
|
||||
branchRegisterRequest.setResourceId("resourceId");
|
||||
branchRegisterRequest.setXid("xid");
|
||||
|
||||
BranchRegisterRequestConvertor convertor = new BranchRegisterRequestConvertor();
|
||||
BranchRegisterRequestProto proto = convertor.convert2Proto(
|
||||
branchRegisterRequest);
|
||||
BranchRegisterRequest real = convertor.convert2Model(proto);
|
||||
|
||||
assertThat(real.getTypeCode()).isEqualTo(branchRegisterRequest.getTypeCode());
|
||||
assertThat(real.getApplicationData()).isEqualTo(branchRegisterRequest.getApplicationData());
|
||||
assertThat(real.getXid()).isEqualTo(branchRegisterRequest.getXid());
|
||||
assertThat(real.getBranchType()).isEqualTo(branchRegisterRequest.getBranchType());
|
||||
assertThat(real.getLockKey()).isEqualTo(branchRegisterRequest.getLockKey());
|
||||
assertThat(real.getResourceId()).isEqualTo(branchRegisterRequest.getResourceId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.BranchRegisterResponseProto;
|
||||
import io.seata.core.exception.TransactionExceptionCode;
|
||||
import io.seata.core.protocol.ResultCode;
|
||||
import io.seata.core.protocol.transaction.BranchRegisterResponse;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class BranchRegisterResponseConvertorTest {
|
||||
|
||||
@Test
|
||||
public void convert2Proto() {
|
||||
|
||||
BranchRegisterResponse branchRegisterResponse = new BranchRegisterResponse();
|
||||
branchRegisterResponse.setTransactionExceptionCode(TransactionExceptionCode.GlobalTransactionNotActive);
|
||||
branchRegisterResponse.setResultCode(ResultCode.Failed);
|
||||
branchRegisterResponse.setMsg("msg");
|
||||
branchRegisterResponse.setBranchId(123);
|
||||
|
||||
BranchRegisterResponseConvertor convertor = new BranchRegisterResponseConvertor();
|
||||
BranchRegisterResponseProto proto = convertor.convert2Proto(
|
||||
branchRegisterResponse);
|
||||
|
||||
BranchRegisterResponse real = convertor.convert2Model(proto);
|
||||
|
||||
assertThat(real.getTransactionExceptionCode()).isEqualTo(branchRegisterResponse.getTransactionExceptionCode());
|
||||
assertThat(real.getResultCode()).isEqualTo(branchRegisterResponse.getResultCode());
|
||||
assertThat(real.getMsg()).isEqualTo(branchRegisterResponse.getMsg());
|
||||
assertThat(real.getBranchId()).isEqualTo(branchRegisterResponse.getBranchId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.BranchReportRequestProto;
|
||||
import io.seata.core.model.BranchStatus;
|
||||
import io.seata.core.model.BranchType;
|
||||
import io.seata.core.protocol.transaction.BranchReportRequest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class BranchReportRequestConvertorTest {
|
||||
|
||||
@Test
|
||||
public void convert2Proto() {
|
||||
|
||||
BranchReportRequest branchReportRequest = new BranchReportRequest();
|
||||
|
||||
branchReportRequest.setApplicationData("data");
|
||||
branchReportRequest.setBranchId(123);
|
||||
branchReportRequest.setResourceId("resourceId");
|
||||
branchReportRequest.setXid("xid");
|
||||
branchReportRequest.setBranchType(
|
||||
BranchType.AT);
|
||||
branchReportRequest.setStatus(BranchStatus.PhaseOne_Done);
|
||||
BranchReportRequestConvertor convertor = new BranchReportRequestConvertor();
|
||||
BranchReportRequestProto proto = convertor.convert2Proto(branchReportRequest);
|
||||
BranchReportRequest real = convertor.convert2Model(proto);
|
||||
|
||||
assertThat(real.getBranchType()).isEqualTo(branchReportRequest.getBranchType());
|
||||
assertThat(real.getXid()).isEqualTo(branchReportRequest.getXid());
|
||||
assertThat(real.getResourceId()).isEqualTo(branchReportRequest.getResourceId());
|
||||
assertThat(real.getBranchId()).isEqualTo(branchReportRequest.getBranchId());
|
||||
assertThat(real.getApplicationData()).isEqualTo(branchReportRequest.getApplicationData());
|
||||
assertThat(real.getStatus()).isEqualTo(branchReportRequest.getStatus());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.BranchReportResponseProto;
|
||||
import io.seata.core.exception.TransactionExceptionCode;
|
||||
import io.seata.core.protocol.ResultCode;
|
||||
import io.seata.core.protocol.transaction.BranchReportResponse;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class BranchReportResponseConvertorTest {
|
||||
|
||||
@Test
|
||||
public void convert2Proto() {
|
||||
|
||||
BranchReportResponse branchReportResponse = new BranchReportResponse();
|
||||
branchReportResponse.setMsg("msg");
|
||||
branchReportResponse.setResultCode(ResultCode.Failed);
|
||||
branchReportResponse.setTransactionExceptionCode(TransactionExceptionCode.GlobalTransactionNotExist);
|
||||
BranchReportResponseConvertor convertor = new BranchReportResponseConvertor();
|
||||
BranchReportResponseProto proto = convertor.convert2Proto(branchReportResponse);
|
||||
BranchReportResponse real = convertor.convert2Model(proto);
|
||||
assertThat((real.getTypeCode())).isEqualTo(branchReportResponse.getTypeCode());
|
||||
assertThat((real.getMsg())).isEqualTo(branchReportResponse.getMsg());
|
||||
assertThat((real.getResultCode())).isEqualTo(branchReportResponse.getResultCode());
|
||||
assertThat((real.getTransactionExceptionCode())).isEqualTo(branchReportResponse.getTransactionExceptionCode());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.BranchRollbackRequestProto;
|
||||
import io.seata.core.model.BranchType;
|
||||
import io.seata.core.protocol.transaction.BranchRollbackRequest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class BranchRollbackRequestConvertorTest {
|
||||
|
||||
@Test
|
||||
public void convert2Proto() {
|
||||
|
||||
BranchRollbackRequest branchRegisterRequest = new BranchRollbackRequest();
|
||||
branchRegisterRequest.setApplicationData("data");
|
||||
branchRegisterRequest.setBranchType(BranchType.AT);
|
||||
branchRegisterRequest.setResourceId("resourceId");
|
||||
branchRegisterRequest.setXid("xid");
|
||||
branchRegisterRequest.setBranchId(123);
|
||||
|
||||
BranchRollbackRequestConvertor convertor = new BranchRollbackRequestConvertor();
|
||||
BranchRollbackRequestProto proto = convertor.convert2Proto(
|
||||
branchRegisterRequest);
|
||||
|
||||
BranchRollbackRequest real = convertor.convert2Model(proto);
|
||||
|
||||
assertThat((real.getTypeCode())).isEqualTo(branchRegisterRequest.getTypeCode());
|
||||
assertThat((real.getApplicationData())).isEqualTo(branchRegisterRequest.getApplicationData());
|
||||
assertThat((real.getBranchType())).isEqualTo(branchRegisterRequest.getBranchType());
|
||||
assertThat((real.getXid())).isEqualTo(branchRegisterRequest.getXid());
|
||||
assertThat((real.getResourceId())).isEqualTo(branchRegisterRequest.getResourceId());
|
||||
assertThat((real.getBranchId())).isEqualTo(branchRegisterRequest.getBranchId());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.BranchRollbackResponseProto;
|
||||
import io.seata.core.exception.TransactionExceptionCode;
|
||||
import io.seata.core.model.BranchStatus;
|
||||
import io.seata.core.protocol.ResultCode;
|
||||
import io.seata.core.protocol.transaction.BranchRollbackResponse;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class BranchRollbackResponseConvertorTest {
|
||||
|
||||
@Test
|
||||
public void convert2Proto() {
|
||||
|
||||
BranchRollbackResponse branchRollbackResponse = new BranchRollbackResponse();
|
||||
branchRollbackResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchTransactionNotExist);
|
||||
branchRollbackResponse.setResultCode(ResultCode.Success);
|
||||
branchRollbackResponse.setMsg("xx");
|
||||
branchRollbackResponse.setXid("xid");
|
||||
branchRollbackResponse.setBranchStatus(BranchStatus.PhaseTwo_Rollbacked);
|
||||
branchRollbackResponse.setBranchId(123);
|
||||
|
||||
BranchRollbackResponseConvertor convertor = new BranchRollbackResponseConvertor();
|
||||
BranchRollbackResponseProto proto = convertor.convert2Proto(
|
||||
branchRollbackResponse);
|
||||
BranchRollbackResponse real = convertor.convert2Model(proto);
|
||||
|
||||
assertThat(real.getTypeCode()).isEqualTo(branchRollbackResponse.getTypeCode());
|
||||
assertThat(real.getMsg()).isEqualTo(branchRollbackResponse.getMsg());
|
||||
assertThat(real.getXid()).isEqualTo(branchRollbackResponse.getXid());
|
||||
assertThat(real.getTransactionExceptionCode()).isEqualTo(branchRollbackResponse.getTransactionExceptionCode());
|
||||
assertThat(real.getBranchStatus()).isEqualTo(branchRollbackResponse.getBranchStatus());
|
||||
assertThat(real.getResultCode()).isEqualTo(branchRollbackResponse.getResultCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.GlobalBeginRequestProto;
|
||||
import io.seata.core.protocol.transaction.GlobalBeginRequest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class GlobalBeginRequestConvertorTest {
|
||||
|
||||
@Test
|
||||
public void convert2Proto() {
|
||||
GlobalBeginRequest globalBeginRequest = new GlobalBeginRequest();
|
||||
globalBeginRequest.setTimeout(3000);
|
||||
globalBeginRequest.setTransactionName("taa");
|
||||
|
||||
GlobalBeginRequestConvertor convertor = new GlobalBeginRequestConvertor();
|
||||
GlobalBeginRequestProto proto = convertor.convert2Proto(globalBeginRequest);
|
||||
GlobalBeginRequest real = convertor.convert2Model(proto);
|
||||
|
||||
assertThat(real.getTypeCode()).isEqualTo(globalBeginRequest.getTypeCode());
|
||||
assertThat(real.getTimeout()).isEqualTo(globalBeginRequest.getTimeout());
|
||||
assertThat(real.getTransactionName()).isEqualTo(globalBeginRequest.getTransactionName());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.GlobalBeginResponseProto;
|
||||
import io.seata.core.exception.TransactionExceptionCode;
|
||||
import io.seata.core.protocol.ResultCode;
|
||||
import io.seata.core.protocol.transaction.GlobalBeginResponse;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class GlobalBeginResponseConvertorTest {
|
||||
|
||||
@Test
|
||||
public void convert2Proto() {
|
||||
|
||||
GlobalBeginResponse globalBeginResponse = new GlobalBeginResponse();
|
||||
|
||||
globalBeginResponse.setResultCode(ResultCode.Failed);
|
||||
globalBeginResponse.setMsg("msg");
|
||||
globalBeginResponse.setExtraData("extraData");
|
||||
globalBeginResponse.setXid("xid");
|
||||
globalBeginResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchRollbackFailed_Retriable);
|
||||
|
||||
GlobalBeginResponseConvertor convertor = new GlobalBeginResponseConvertor();
|
||||
GlobalBeginResponseProto proto = convertor.convert2Proto(globalBeginResponse);
|
||||
GlobalBeginResponse real = convertor.convert2Model(proto);
|
||||
assertThat((real.getTypeCode())).isEqualTo(globalBeginResponse.getTypeCode());
|
||||
assertThat((real.getMsg())).isEqualTo(globalBeginResponse.getMsg());
|
||||
assertThat((real.getResultCode())).isEqualTo(globalBeginResponse.getResultCode());
|
||||
assertThat((real.getTransactionExceptionCode())).isEqualTo(globalBeginResponse.getTransactionExceptionCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.GlobalCommitRequestProto;
|
||||
import io.seata.core.protocol.transaction.GlobalCommitRequest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class GlobalCommitRequestConvertorTest {
|
||||
|
||||
@Test
|
||||
public void convert2Proto() {
|
||||
|
||||
GlobalCommitRequest globalCommitRequest = new GlobalCommitRequest();
|
||||
globalCommitRequest.setExtraData("extraData");
|
||||
globalCommitRequest.setXid("xid");
|
||||
|
||||
GlobalCommitRequestConvertor convertor = new GlobalCommitRequestConvertor();
|
||||
GlobalCommitRequestProto proto = convertor.convert2Proto(globalCommitRequest);
|
||||
GlobalCommitRequest real = convertor.convert2Model(proto);
|
||||
assertThat((real.getTypeCode())).isEqualTo(globalCommitRequest.getTypeCode());
|
||||
assertThat((real.getXid())).isEqualTo(globalCommitRequest.getXid());
|
||||
assertThat((real.getExtraData())).isEqualTo(globalCommitRequest.getExtraData());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.GlobalCommitResponseProto;
|
||||
import io.seata.core.exception.TransactionExceptionCode;
|
||||
import io.seata.core.model.GlobalStatus;
|
||||
import io.seata.core.protocol.ResultCode;
|
||||
import io.seata.core.protocol.transaction.GlobalCommitResponse;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class GlobalCommitResponseConvertorTest {
|
||||
|
||||
@Test
|
||||
public void convert2Proto() {
|
||||
|
||||
GlobalCommitResponse globalCommitResponse = new GlobalCommitResponse();
|
||||
globalCommitResponse.setGlobalStatus(GlobalStatus.AsyncCommitting);
|
||||
globalCommitResponse.setMsg("msg");
|
||||
globalCommitResponse.setResultCode(ResultCode.Failed);
|
||||
globalCommitResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchRegisterFailed);
|
||||
GlobalCommitResponseConvertor convertor = new GlobalCommitResponseConvertor();
|
||||
GlobalCommitResponseProto proto = convertor.convert2Proto(globalCommitResponse);
|
||||
GlobalCommitResponse real = convertor.convert2Model(proto);
|
||||
assertThat((real.getTypeCode())).isEqualTo(globalCommitResponse.getTypeCode());
|
||||
assertThat((real.getMsg())).isEqualTo(globalCommitResponse.getMsg());
|
||||
assertThat((real.getResultCode())).isEqualTo(globalCommitResponse.getResultCode());
|
||||
assertThat((real.getTransactionExceptionCode())).isEqualTo(globalCommitResponse.getTransactionExceptionCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.GlobalLockQueryRequestProto;
|
||||
import io.seata.core.model.BranchType;
|
||||
import io.seata.core.protocol.transaction.GlobalLockQueryRequest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class GlobalLockQueryRequestConvertorTest {
|
||||
|
||||
@Test
|
||||
public void convert2Proto() {
|
||||
|
||||
GlobalLockQueryRequest globalLockQueryRequest = new GlobalLockQueryRequest();
|
||||
globalLockQueryRequest.setApplicationData("data");
|
||||
globalLockQueryRequest.setBranchType(BranchType.AT);
|
||||
globalLockQueryRequest.setLockKey("localKey");
|
||||
globalLockQueryRequest.setResourceId("resourceId");
|
||||
globalLockQueryRequest.setXid("xid");
|
||||
|
||||
GlobalLockQueryRequestConvertor convertor = new GlobalLockQueryRequestConvertor();
|
||||
GlobalLockQueryRequestProto proto = convertor.convert2Proto(
|
||||
globalLockQueryRequest);
|
||||
GlobalLockQueryRequest real = convertor.convert2Model(proto);
|
||||
|
||||
assertThat(real.getTypeCode()).isEqualTo(globalLockQueryRequest.getTypeCode());
|
||||
assertThat(real.getApplicationData()).isEqualTo(globalLockQueryRequest.getApplicationData());
|
||||
assertThat(real.getXid()).isEqualTo(globalLockQueryRequest.getXid());
|
||||
assertThat(real.getBranchType()).isEqualTo(globalLockQueryRequest.getBranchType());
|
||||
assertThat(real.getLockKey()).isEqualTo(globalLockQueryRequest.getLockKey());
|
||||
assertThat(real.getResourceId()).isEqualTo(globalLockQueryRequest.getResourceId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.GlobalLockQueryResponseProto;
|
||||
import io.seata.core.exception.TransactionExceptionCode;
|
||||
import io.seata.core.protocol.ResultCode;
|
||||
import io.seata.core.protocol.transaction.GlobalLockQueryResponse;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class GlobalLockQueryResponseConvertorTest {
|
||||
|
||||
@Test
|
||||
public void convert2Proto() {
|
||||
|
||||
GlobalLockQueryResponse globalLockQueryResponse = new GlobalLockQueryResponse();
|
||||
globalLockQueryResponse.setLockable(true);
|
||||
globalLockQueryResponse.setMsg("msg");
|
||||
globalLockQueryResponse.setResultCode(ResultCode.Failed);
|
||||
globalLockQueryResponse.setTransactionExceptionCode(TransactionExceptionCode.GlobalTransactionNotActive);
|
||||
GlobalLockQueryResponseConvertor convertor = new GlobalLockQueryResponseConvertor();
|
||||
GlobalLockQueryResponseProto proto = convertor.convert2Proto(
|
||||
globalLockQueryResponse);
|
||||
GlobalLockQueryResponse real = convertor.convert2Model(proto);
|
||||
assertThat((real.getTypeCode())).isEqualTo(globalLockQueryResponse.getTypeCode());
|
||||
assertThat((real.getMsg())).isEqualTo(globalLockQueryResponse.getMsg());
|
||||
assertThat((real.getResultCode())).isEqualTo(globalLockQueryResponse.getResultCode());
|
||||
assertThat((real.getTransactionExceptionCode())).isEqualTo(
|
||||
globalLockQueryResponse.getTransactionExceptionCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.GlobalRollbackRequestProto;
|
||||
import io.seata.core.protocol.transaction.GlobalRollbackRequest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class GlobalRollbackRequestConvertorTest {
|
||||
|
||||
@Test
|
||||
public void convert2Proto() {
|
||||
|
||||
GlobalRollbackRequest globalRollbackRequest = new GlobalRollbackRequest();
|
||||
globalRollbackRequest.setExtraData("extraData");
|
||||
globalRollbackRequest.setXid("xid");
|
||||
|
||||
GlobalRollbackRequestConvertor convertor = new GlobalRollbackRequestConvertor();
|
||||
GlobalRollbackRequestProto proto = convertor.convert2Proto(
|
||||
globalRollbackRequest);
|
||||
GlobalRollbackRequest real = convertor.convert2Model(proto);
|
||||
assertThat((real.getTypeCode())).isEqualTo(globalRollbackRequest.getTypeCode());
|
||||
assertThat((real.getXid())).isEqualTo(globalRollbackRequest.getXid());
|
||||
assertThat((real.getExtraData())).isEqualTo(globalRollbackRequest.getExtraData());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.GlobalRollbackResponseProto;
|
||||
import io.seata.core.exception.TransactionExceptionCode;
|
||||
import io.seata.core.model.GlobalStatus;
|
||||
import io.seata.core.protocol.ResultCode;
|
||||
import io.seata.core.protocol.transaction.GlobalRollbackResponse;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class GlobalRollbackResponseConvertorTest {
|
||||
|
||||
@Test
|
||||
public void convert2Proto() {
|
||||
|
||||
GlobalRollbackResponse globalRollbackResponse = new GlobalRollbackResponse();
|
||||
globalRollbackResponse.setGlobalStatus(GlobalStatus.AsyncCommitting);
|
||||
globalRollbackResponse.setMsg("msg");
|
||||
globalRollbackResponse.setResultCode(ResultCode.Failed);
|
||||
globalRollbackResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchRegisterFailed);
|
||||
GlobalRollbackResponseConvertor convertor = new GlobalRollbackResponseConvertor();
|
||||
GlobalRollbackResponseProto proto = convertor.convert2Proto(
|
||||
globalRollbackResponse);
|
||||
GlobalRollbackResponse real = convertor.convert2Model(proto);
|
||||
assertThat((real.getTypeCode())).isEqualTo(globalRollbackResponse.getTypeCode());
|
||||
assertThat((real.getMsg())).isEqualTo(globalRollbackResponse.getMsg());
|
||||
assertThat((real.getResultCode())).isEqualTo(globalRollbackResponse.getResultCode());
|
||||
assertThat((real.getTransactionExceptionCode())).isEqualTo(
|
||||
globalRollbackResponse.getTransactionExceptionCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.GlobalStatusRequestProto;
|
||||
import io.seata.core.protocol.transaction.GlobalStatusRequest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class GlobalStatusRequestConvertorTest {
|
||||
|
||||
@Test
|
||||
public void convert2Proto() {
|
||||
|
||||
GlobalStatusRequest globalStatusRequest = new GlobalStatusRequest();
|
||||
globalStatusRequest.setExtraData("extraData");
|
||||
globalStatusRequest.setXid("xid");
|
||||
GlobalStatusRequestConvertor convertor = new GlobalStatusRequestConvertor();
|
||||
GlobalStatusRequestProto proto = convertor.convert2Proto(
|
||||
globalStatusRequest);
|
||||
GlobalStatusRequest real = convertor.convert2Model(proto);
|
||||
assertThat((real.getTypeCode())).isEqualTo(globalStatusRequest.getTypeCode());
|
||||
assertThat((real.getXid())).isEqualTo(globalStatusRequest.getXid());
|
||||
assertThat((real.getExtraData())).isEqualTo(globalStatusRequest.getExtraData());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.GlobalStatusResponseProto;
|
||||
import io.seata.core.exception.TransactionExceptionCode;
|
||||
import io.seata.core.model.GlobalStatus;
|
||||
import io.seata.core.protocol.ResultCode;
|
||||
import io.seata.core.protocol.transaction.GlobalStatusResponse;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class GlobalStatusResponseConvertorTest {
|
||||
|
||||
@Test
|
||||
public void convert2Proto() {
|
||||
|
||||
GlobalStatusResponse globalStatusResponse = new GlobalStatusResponse();
|
||||
globalStatusResponse.setGlobalStatus(GlobalStatus.AsyncCommitting);
|
||||
globalStatusResponse.setMsg("msg");
|
||||
globalStatusResponse.setResultCode(ResultCode.Failed);
|
||||
globalStatusResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchRegisterFailed);
|
||||
GlobalStatusResponseConvertor convertor = new GlobalStatusResponseConvertor();
|
||||
GlobalStatusResponseProto proto = convertor.convert2Proto(
|
||||
globalStatusResponse);
|
||||
GlobalStatusResponse real = convertor.convert2Model(proto);
|
||||
assertThat((real.getTypeCode())).isEqualTo(globalStatusResponse.getTypeCode());
|
||||
assertThat((real.getMsg())).isEqualTo(globalStatusResponse.getMsg());
|
||||
assertThat((real.getResultCode())).isEqualTo(globalStatusResponse.getResultCode());
|
||||
assertThat((real.getTransactionExceptionCode())).isEqualTo(
|
||||
globalStatusResponse.getTransactionExceptionCode());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.HeartbeatMessageProto;
|
||||
import io.seata.core.protocol.HeartbeatMessage;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class HeartbeatMessageConvertorTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
HeartbeatMessage heartbeatMessage = HeartbeatMessage.PING;
|
||||
HeartbeatMessageConvertor convertor = new HeartbeatMessageConvertor();
|
||||
HeartbeatMessageProto proto = convertor.convert2Proto(heartbeatMessage);
|
||||
HeartbeatMessage real = convertor.convert2Model(proto);
|
||||
assertThat(real).isEqualTo(heartbeatMessage);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.MergedWarpMessageProto;
|
||||
import io.seata.core.protocol.AbstractMessage;
|
||||
import io.seata.core.protocol.MergedWarpMessage;
|
||||
import io.seata.core.protocol.transaction.GlobalBeginRequest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class MergeMessageConvertorTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
MergedWarpMessage mergedWarpMessage = new MergedWarpMessage();
|
||||
final ArrayList<AbstractMessage> msgs = new ArrayList<>();
|
||||
final GlobalBeginRequest globalBeginRequest = buildGlobalBeginRequest();
|
||||
msgs.add(globalBeginRequest);
|
||||
mergedWarpMessage.msgs = msgs;
|
||||
|
||||
MergedWarpMessageConvertor pbConvertor = new MergedWarpMessageConvertor();
|
||||
MergedWarpMessageProto globalBeginRequestProto = pbConvertor.convert2Proto(
|
||||
mergedWarpMessage);
|
||||
|
||||
MergedWarpMessage model = pbConvertor.convert2Model(globalBeginRequestProto);
|
||||
|
||||
GlobalBeginRequest decodeModel = (GlobalBeginRequest)model.msgs.get(0);
|
||||
assertThat(decodeModel.getTransactionName()).isEqualTo(
|
||||
globalBeginRequest.getTransactionName());
|
||||
assertThat(decodeModel.getTimeout()).isEqualTo(globalBeginRequest.getTimeout());
|
||||
assertThat(
|
||||
decodeModel.getTypeCode()).isEqualTo(globalBeginRequest.getTypeCode());
|
||||
|
||||
}
|
||||
|
||||
private GlobalBeginRequest buildGlobalBeginRequest() {
|
||||
final GlobalBeginRequest globalBeginRequest = new GlobalBeginRequest();
|
||||
globalBeginRequest.setTransactionName("xx");
|
||||
globalBeginRequest.setTimeout(3000);
|
||||
return globalBeginRequest;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.serializer.protobuf.convertor;
|
||||
|
||||
import io.seata.serializer.protobuf.generated.MergedResultMessageProto;
|
||||
import io.seata.core.exception.TransactionExceptionCode;
|
||||
import io.seata.core.model.GlobalStatus;
|
||||
import io.seata.core.protocol.AbstractResultMessage;
|
||||
import io.seata.core.protocol.MergeResultMessage;
|
||||
import io.seata.core.protocol.ResultCode;
|
||||
import io.seata.core.protocol.transaction.GlobalCommitResponse;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author leizhiyuan
|
||||
*/
|
||||
public class MergeResultMessageConvertorTest {
|
||||
|
||||
@Test
|
||||
public void convert2Proto() {
|
||||
|
||||
MergeResultMessage mergeResultMessage = new MergeResultMessage();
|
||||
AbstractResultMessage[] msgs = new AbstractResultMessage[1];
|
||||
final GlobalCommitResponse globalCommitResponse = new GlobalCommitResponse();
|
||||
globalCommitResponse.setGlobalStatus(GlobalStatus.AsyncCommitting);
|
||||
globalCommitResponse.setMsg("msg");
|
||||
globalCommitResponse.setResultCode(ResultCode.Failed);
|
||||
globalCommitResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchRegisterFailed);
|
||||
msgs[0] = globalCommitResponse;
|
||||
mergeResultMessage.setMsgs(msgs);
|
||||
|
||||
MergeResultMessageConvertor convertor = new MergeResultMessageConvertor();
|
||||
MergedResultMessageProto proto = convertor.convert2Proto(mergeResultMessage);
|
||||
MergeResultMessage real = convertor.convert2Model(proto);
|
||||
|
||||
GlobalCommitResponse realObj = (GlobalCommitResponse)real.getMsgs()[0];
|
||||
|
||||
assertThat((realObj.getTypeCode())).isEqualTo(globalCommitResponse.getTypeCode());
|
||||
assertThat((realObj.getMsg())).isEqualTo(globalCommitResponse.getMsg());
|
||||
assertThat((realObj.getResultCode())).isEqualTo(globalCommitResponse.getResultCode());
|
||||
assertThat((realObj.getTransactionExceptionCode())).isEqualTo(
|
||||
globalCommitResponse.getTransactionExceptionCode());
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user