From 18fbf8990dfee1b20d5f1c6dede44c769f7cab8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=80=E6=BA=90=E6=B5=B7=E5=93=A5?= Date: Tue, 1 Aug 2023 16:55:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=B8=B8=E6=A0=87?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=97=B6=EF=BC=8C=E9=85=8D=E7=BD=AE=20`@Colu?= =?UTF-8?q?mn(typeHandler=20=3Dxxx)`=20=E4=B8=8D=E7=94=9F=E7=94=9F?= =?UTF-8?q?=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98=20close=20#I7PNUL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/mybatis/FlexConfiguration.java | 2 +- .../java/com/mybatisflex/test/Account.java | 2 +- .../mybatisflex/test/CursorTestStarter.java | 82 +++++++++++++++++++ .../src/main/resources/data.sql | 4 +- 4 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/CursorTestStarter.java diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexConfiguration.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexConfiguration.java index 8727d865..f6a78b3c 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexConfiguration.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/FlexConfiguration.java @@ -171,7 +171,7 @@ public class FlexConfiguration extends Configuration { } //entity select else if (StringUtil.endsWithAny(ms.getId(), "selectOneById", "selectListByIds" - , "selectListByQuery")) { + , "selectListByQuery", "selectCursorByQuery")) { ms = replaceResultMap(ms, getTableInfo(ms)); } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Account.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Account.java index 6c1ec522..50a06088 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Account.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/Account.java @@ -46,7 +46,7 @@ public class Account extends BaseEntity implements Serializable, AgeAware { @NotBlank private Date birthday; - @Column(typeHandler = Fastjson2TypeHandler.class, isLarge = true) + @Column(typeHandler = Fastjson2TypeHandler.class) private Map options; @Column(isLogicDelete = true) diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/CursorTestStarter.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/CursorTestStarter.java new file mode 100644 index 00000000..852c4943 --- /dev/null +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/CursorTestStarter.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * 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 com.mybatisflex.test; + +import com.mybatisflex.core.MybatisFlexBootstrap; +import com.mybatisflex.core.audit.AuditManager; +import com.mybatisflex.core.audit.ConsoleMessageCollector; +import com.mybatisflex.core.audit.MessageCollector; +import com.mybatisflex.core.query.QueryWrapper; +import com.mybatisflex.core.row.Db; +import com.mybatisflex.core.row.RowUtil; +import org.apache.ibatis.cursor.Cursor; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; + +import javax.sql.DataSource; +import java.util.List; + +import static com.mybatisflex.test.table.AccountTableDef.ACCOUNT; +import static com.mybatisflex.test.table.ArticleTableDef.ARTICLE; + +public class CursorTestStarter { + + public static void main(String[] args) { + DataSource dataSource = new EmbeddedDatabaseBuilder() + .setType(EmbeddedDatabaseType.H2) + .addScript("schema.sql") + .addScript("data.sql") + .build(); + + MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance() + .setDataSource(dataSource) + .addMapper(AccountMapper.class) + .addMapper(MyAccountMapper.class) + .start(); + + //开启审计功能 + AuditManager.setAuditEnable(true); + + //设置 SQL 审计收集器 + MessageCollector collector = new ConsoleMessageCollector(); + AuditManager.setMessageCollector(collector); + + + AccountMapper accountMapper = bootstrap.getMapper(AccountMapper.class); + + List accounts = accountMapper.selectAll(); + System.out.println(accounts); + + QueryWrapper asWrapper = QueryWrapper.create() + .select(ARTICLE.ALL_COLUMNS, ACCOUNT.ALL_COLUMNS) + .from(ARTICLE) + .leftJoin(ACCOUNT).on(ARTICLE.ACCOUNT_ID.eq(ACCOUNT.ID)) + .where(ARTICLE.ID.ge(0).or(ACCOUNT.ID.ge(0))); + + RowUtil.printPretty(Db.selectListByQuery(asWrapper)); + + Db.tx(() -> { + Cursor accountCursor = accountMapper.selectCursorByQuery(asWrapper); + for (Account account : accountCursor) { + System.out.println(account); + } + return true; + }); + + + } + +} diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/resources/data.sql b/mybatis-flex-test/mybatis-flex-native-test/src/main/resources/data.sql index 6734810a..2a4051d2 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/resources/data.sql +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/resources/data.sql @@ -1,6 +1,6 @@ INSERT INTO tb_account -VALUES (1, '张三', 18, 0,'2020-01-11', null,0), - (2, '王麻子叔叔', 19, 1, '2021-03-21', null,0); +VALUES (1, '张三', 18, 0,'2020-01-11', '{"key":"value1"}',0), + (2, '王麻子叔叔', 19, 1, '2021-03-21', '{"key":"value2"}',0); INSERT INTO tb_article