Skip to content

Commit

Permalink
测试同时执行ORM操作和JDBC语句不会导致事务异常
Browse files Browse the repository at this point in the history
  • Loading branch information
entropy-cloud committed Jul 6, 2024
1 parent 8483479 commit cfca427
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_chgType,GROUP_ID,NAME,PARENT_ID,OWNER_ID,DEL_FLAG,VERSION,CREATED_BY,CREATE_TIME,UPDATED_BY,UPDATE_TIME,REMARK
A,@var:NopAuthGroup@groupId,test,,,0,0,autotest-ref,*,autotest-ref,*,
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

import io.nop.api.core.annotations.autotest.EnableSnapshot;
import io.nop.api.core.annotations.autotest.NopTestConfig;
import io.nop.api.core.beans.ApiRequest;
import io.nop.api.core.beans.ApiResponse;
import io.nop.api.core.beans.graphql.GraphQLRequestBean;
import io.nop.api.core.beans.graphql.GraphQLResponseBean;
import io.nop.auth.dao.entity.NopAuthRole;
Expand Down Expand Up @@ -43,5 +41,13 @@ public void testRollback() {
assertTrue(daoProvider.daoFor(NopAuthRole.class).getEntityById("test123") == null);
}


@EnableSnapshot
@Test
public void testTransaction() {
GraphQLRequestBean request = new GraphQLRequestBean();
request.setQuery("mutation { DemoAuth__testTransaction }");
IGraphQLExecutionContext context = graphQLEngine.newGraphQLContext(request);
GraphQLResponseBean response = graphQLEngine.executeGraphQL(context);
assertTrue(!response.hasError());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
import io.nop.api.core.annotations.biz.BizQuery;
import io.nop.api.core.annotations.biz.RequestBean;
import io.nop.api.core.annotations.ioc.InjectValue;
import io.nop.auth.dao.entity.NopAuthGroup;
import io.nop.auth.dao.entity.NopAuthRole;
import io.nop.commons.util.StringHelper;
import io.nop.core.lang.sql.SQL;
import io.nop.dao.api.IDaoProvider;
import io.nop.dao.api.IEntityDao;
import io.nop.dao.jdbc.IJdbcTemplate;
import jakarta.inject.Inject;

import java.util.Arrays;
Expand All @@ -25,6 +29,9 @@ public class DemoAuthBizModel {
@Inject
IDaoProvider daoProvider;

@Inject
IJdbcTemplate jdbcTemplate;

@InjectValue("${test.prefix}.data")
String testField;

Expand All @@ -35,7 +42,7 @@ public void setTestValue(String value) {
this.testValue = value;
}

public String getTestValue(){
public String getTestValue() {
return testValue;
}

Expand All @@ -55,4 +62,15 @@ public String testFlushError() {
public String hello(@RequestBean DemoRequest request) {
return "userId:" + request.getUserId();
}

@BizMutation
public void testTransaction() {
IEntityDao<NopAuthGroup> dao = daoProvider.daoFor(NopAuthGroup.class);
NopAuthGroup group = new NopAuthGroup();
group.setName("test");
dao.saveEntity(group);

SQL sql = new SQL("update nop_auth_group set parent_id = null where 1=0");
jdbcTemplate.executeUpdate(sql);
}
}

0 comments on commit cfca427

Please sign in to comment.