mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 17:18:24 +08:00
test: add MainSqlTest.java
This commit is contained in:
parent
44aa1986c3
commit
d9673c5f1a
@ -18,6 +18,8 @@ package com.mybatisflex.core.query;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.table.TableInfo;
|
||||
import com.mybatisflex.core.table.TableInfoFactory;
|
||||
import com.mybatisflex.core.util.SqlUtil;
|
||||
|
||||
import java.util.List;
|
||||
@ -137,4 +139,10 @@ public class QueryChain<T> extends QueryWrapperAdapter<QueryChain<T>> {
|
||||
return baseMapper.paginateWithRelationsAs(page, this, asType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSQL() {
|
||||
TableInfo tableInfo = TableInfoFactory.ofMapperClass(baseMapper.getClass());
|
||||
CPI.setFromIfNecessary(this, tableInfo.getSchema(), tableInfo.getTableName());
|
||||
return super.toSQL();
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,10 +17,14 @@
|
||||
package com.mybatisflex.core.update;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.mybatisflex.core.dialect.DialectFactory;
|
||||
import com.mybatisflex.core.exception.FlexExceptions;
|
||||
import com.mybatisflex.core.mybatis.Mappers;
|
||||
import com.mybatisflex.core.query.CPI;
|
||||
import com.mybatisflex.core.query.QueryColumn;
|
||||
import com.mybatisflex.core.query.QueryWrapperAdapter;
|
||||
import com.mybatisflex.core.table.TableInfo;
|
||||
import com.mybatisflex.core.table.TableInfoFactory;
|
||||
import com.mybatisflex.core.util.ClassUtil;
|
||||
import com.mybatisflex.core.util.LambdaGetter;
|
||||
import com.mybatisflex.core.util.SqlUtil;
|
||||
@ -124,4 +128,13 @@ public class UpdateChain<T> extends QueryWrapperAdapter<UpdateChain<T>> {
|
||||
return SqlUtil.toBool(baseMapper.updateByQuery(entity, this));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toSQL() {
|
||||
TableInfo tableInfo = TableInfoFactory.ofMapperClass(baseMapper.getClass());
|
||||
CPI.setFromIfNecessary(this, tableInfo.getSchema(), tableInfo.getTableName());
|
||||
String sql = DialectFactory.getDialect().forUpdateEntityByQuery(tableInfo,entity,true,this);
|
||||
return SqlUtil.replaceSqlParams(sql, CPI.getValueArray(this));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -16,8 +16,6 @@
|
||||
|
||||
package com.mybatisflex.coretest;
|
||||
|
||||
import com.mybatisflex.core.exception.FlexExceptions;
|
||||
import com.mybatisflex.core.exception.locale.LocalizedFormats;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
@ -28,7 +26,7 @@ public class LocaleFormatTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
throw FlexExceptions.wrap(LocalizedFormats.OBJECT_NULL, "primaryValues");
|
||||
// throw FlexExceptions.wrap(LocalizedFormats.OBJECT_NULL, "primaryValues");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,48 @@
|
||||
package com.mybatisflex.test;
|
||||
|
||||
import com.mybatisflex.core.FlexGlobalConfig;
|
||||
import com.mybatisflex.core.mybatis.FlexConfiguration;
|
||||
import com.mybatisflex.core.update.UpdateChain;
|
||||
import com.mybatisflex.mapper.ArticleMapper;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.apache.ibatis.mapping.Environment;
|
||||
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
|
||||
|
||||
public class MainSqlTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Environment environment = new Environment("test", new JdbcTransactionFactory(), new HikariDataSource());
|
||||
|
||||
FlexConfiguration configuration = new FlexConfiguration(environment);
|
||||
FlexGlobalConfig globalConfig = FlexGlobalConfig.getDefaultConfig();
|
||||
globalConfig.setConfiguration(configuration);
|
||||
FlexGlobalConfig.setConfig("test", globalConfig, true);
|
||||
|
||||
configuration.addMapper(ArticleMapper.class);
|
||||
|
||||
|
||||
// ArticleMapper mapper = (ArticleMapper) Proxy.newProxyInstance(MainSqlTest.class.getClassLoader(),
|
||||
// new Class[]{ArticleMapper.class}, new InvocationHandler() {
|
||||
// @Override
|
||||
// public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
// return null;
|
||||
// }
|
||||
// });
|
||||
//
|
||||
//
|
||||
// String sql1 = QueryChain.of(mapper)
|
||||
// .where(Article::getId).eq(100)
|
||||
// .toSQL();
|
||||
//
|
||||
// System.out.println(sql1);
|
||||
|
||||
|
||||
String sql2 = UpdateChain.of(Article.class)
|
||||
.set("xxxx", "xxxx")
|
||||
.where(Article::getId).ge(100)
|
||||
.toSQL();
|
||||
|
||||
System.out.println(sql2);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user