!261 refactor: 移动 SeataMode 类到 starter 模块。

Merge pull request !261 from 王帅/main
This commit is contained in:
Michael Yang 2023-08-09 05:10:56 +00:00 committed by Gitee
commit 4005fc8c9e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 39 additions and 31 deletions

View File

@ -44,11 +44,20 @@ public abstract class QueryModel<T extends QueryModel<T>> {
protected QueryWrapper queryWrapper() {
if (queryWrapper == null) {
queryWrapper = QueryWrapper.create();
TableInfo tableInfo = TableInfoFactory.ofEntityClass(getClass());
QueryTable queryTable = new QueryTable();
queryTable.setSchema(tableInfo.getSchema());
queryTable.setName(tableInfo.getTableName());
queryWrapper = QueryWrapper.create().from(queryTable);
}
return queryWrapper;
}
public T as(String alias) {
queryWrapper().as(alias);
return (T) this;
}
public T select() {
return (T) this;
}

View File

@ -19,7 +19,6 @@ import com.mybatisflex.core.datasource.DataSourceBuilder;
import com.mybatisflex.core.datasource.DataSourceDecipher;
import com.mybatisflex.core.datasource.DataSourceManager;
import com.mybatisflex.core.datasource.FlexDataSource;
import com.mybatisflex.spring.SeataMode;
import com.mybatisflex.spring.boot.MybatisFlexProperties.SeataConfig;
import com.mybatisflex.spring.datasource.DataSourceAdvice;
import io.seata.rm.datasource.DataSourceProxy;
@ -87,7 +86,7 @@ public class MultiDataSourceAutoConfiguration {
DataSourceManager.decryptDataSource(dataSource);
if (seataConfig != null && seataConfig.isEnable()) {
if (seataConfig.getSeataMode() == SeataMode.XA) {
if (seataConfig.getSeataMode() == MybatisFlexProperties.SeataMode.XA) {
dataSource = new DataSourceProxyXA(dataSource);
} else {
dataSource = new DataSourceProxy(dataSource);

View File

@ -17,7 +17,6 @@ package com.mybatisflex.spring.boot;
import com.mybatisflex.core.FlexConsts;
import com.mybatisflex.core.FlexGlobalConfig;
import com.mybatisflex.spring.SeataMode;
import org.apache.ibatis.io.VFS;
import org.apache.ibatis.logging.Log;
import org.apache.ibatis.mapping.ResultSetType;
@ -42,6 +41,7 @@ import java.util.stream.Stream;
/**
* Mybatis-Flex 的配置属性
* 参考https://github.com/mybatis/spring-boot-starter/blob/master/mybatis-spring-boot-autoconfigure/src/main/java/org/mybatis/spring/boot/autoconfigure/MybatisProperties.java
*
* @author Eddú Meléndez
* @author Kazuki Shimizu
* @author micahel
@ -909,7 +909,7 @@ public class MybatisFlexProperties {
*
* @author life
*/
public static class SeataConfig{
public static class SeataConfig {
/**
* 是否开启
@ -936,6 +936,18 @@ public class MybatisFlexProperties {
public void setSeataMode(SeataMode seataMode) {
this.seataMode = seataMode;
}
}
/**
* @author life
*/
public enum SeataMode {
XA,
AT
}
}

View File

@ -1,26 +0,0 @@
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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 com.mybatisflex.spring;
/**
* @author life
*/
public enum SeataMode {
XA,
AT
}

View File

@ -156,4 +156,18 @@ class ActiveRecordTest {
.forEach(System.out::println);
}
@Test
void testToSql() {
String sql = User.create()
.as("u")
.select(USER.ALL_COLUMNS, ROLE.ALL_COLUMNS)
.leftJoin(USER_ROLE).as("ur").on(USER_ROLE.USER_ID.eq(USER.USER_ID))
.leftJoin(ROLE).as("r").on(USER_ROLE.ROLE_ID.eq(ROLE.ROLE_ID))
.where(USER.USER_ID.eq(2))
.toQueryWrapper()
.toSQL();
System.out.println(sql);
}
}