From 55d7120c8c33126e47b699b7a76294801bc68939 Mon Sep 17 00:00:00 2001
From: kamosama <837080904@qq.com>
Date: Wed, 9 Aug 2023 20:48:07 +0800
Subject: [PATCH 1/2] =?UTF-8?q?test=EF=BC=9A=E5=A2=9E=E5=8A=A0kotlin?=
=?UTF-8?q?=E5=8D=95=E7=8B=AC=E7=9A=84=E6=B5=8B=E8=AF=95=E6=A8=A1=E5=9D=97?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
mybatis-flex-kotlin/pom.xml | 56 ++------
.../com/mybatisflex/kotlin/db/DbConfig.kt | 0
.../com/mybatisflex/kotlin/entry/Entry.kt | 0
.../kotlin/extensions/db/DbExtensions.kt | 0
.../extensions/entry/EntryExtensions.kt | 0
.../extensions/mapper/MaaperExtensions.kt | 0
.../kotlin/extensions/sql/SqlExtensions.kt | 0
.../kotlin/scope/BootstrapScope.kt | 0
.../mybatisflex/kotlin/scope/QueryScope.kt | 0
.../mybatisflex/kotlintest/ExtensionTest.kt | 111 ---------------
.../src/test/resources/schema.sql | 15 --
.../.gitignore | 38 +++++
.../mybatis-flex-spring-kotlin-test/pom.xml | 133 ++++++++++++++++++
.../kotlin/com/mybatisflex/test/AppConfig.kt | 65 +++++++++
.../mybatisflex/test/mapper/AccountMapper.kt | 41 ++++++
.../com/mybatisflex/test/model}/Account.kt | 8 +-
.../test/model/AccountOnSetListener.kt | 27 ++++
.../src/main/resources/data-kt.sql | 1 +
.../main}/resources/mybatis-flex.properties | 2 +-
.../src/main/resources/schema.sql | 7 +
.../com/mybatisflex/test/KotlinSpringTest.kt | 41 ++++++
.../kotlin/com/mybatisflex/test/KotlinTest.kt | 103 ++++++++++++++
mybatis-flex-test/pom.xml | 1 +
23 files changed, 470 insertions(+), 179 deletions(-)
rename mybatis-flex-kotlin/src/main/{java => kotlin}/com/mybatisflex/kotlin/db/DbConfig.kt (100%)
rename mybatis-flex-kotlin/src/main/{java => kotlin}/com/mybatisflex/kotlin/entry/Entry.kt (100%)
rename mybatis-flex-kotlin/src/main/{java => kotlin}/com/mybatisflex/kotlin/extensions/db/DbExtensions.kt (100%)
rename mybatis-flex-kotlin/src/main/{java => kotlin}/com/mybatisflex/kotlin/extensions/entry/EntryExtensions.kt (100%)
rename mybatis-flex-kotlin/src/main/{java => kotlin}/com/mybatisflex/kotlin/extensions/mapper/MaaperExtensions.kt (100%)
rename mybatis-flex-kotlin/src/main/{java => kotlin}/com/mybatisflex/kotlin/extensions/sql/SqlExtensions.kt (100%)
rename mybatis-flex-kotlin/src/main/{java => kotlin}/com/mybatisflex/kotlin/scope/BootstrapScope.kt (100%)
rename mybatis-flex-kotlin/src/main/{java => kotlin}/com/mybatisflex/kotlin/scope/QueryScope.kt (100%)
delete mode 100755 mybatis-flex-kotlin/src/test/java/com/mybatisflex/kotlintest/ExtensionTest.kt
delete mode 100755 mybatis-flex-kotlin/src/test/resources/schema.sql
create mode 100755 mybatis-flex-test/mybatis-flex-spring-kotlin-test/.gitignore
create mode 100755 mybatis-flex-test/mybatis-flex-spring-kotlin-test/pom.xml
create mode 100755 mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/main/kotlin/com/mybatisflex/test/AppConfig.kt
create mode 100755 mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/main/kotlin/com/mybatisflex/test/mapper/AccountMapper.kt
rename {mybatis-flex-kotlin/src/test/java/com/mybatisflex/kotlintest/entry => mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/main/kotlin/com/mybatisflex/test/model}/Account.kt (89%)
create mode 100755 mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/main/kotlin/com/mybatisflex/test/model/AccountOnSetListener.kt
rename mybatis-flex-kotlin/src/test/resources/data.sql => mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/main/resources/data-kt.sql (99%)
rename {mybatis-flex-kotlin/src/test => mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/main}/resources/mybatis-flex.properties (72%)
create mode 100755 mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/main/resources/schema.sql
create mode 100755 mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/test/kotlin/com/mybatisflex/test/KotlinSpringTest.kt
create mode 100644 mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/test/kotlin/com/mybatisflex/test/KotlinTest.kt
diff --git a/mybatis-flex-kotlin/pom.xml b/mybatis-flex-kotlin/pom.xml
index ec43b3be..ddfac86d 100755
--- a/mybatis-flex-kotlin/pom.xml
+++ b/mybatis-flex-kotlin/pom.xml
@@ -6,7 +6,7 @@
- * 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.kotlintest
-
-import com.mybatisflex.core.BaseMapper
-import com.mybatisflex.core.FlexConsts
-import com.mybatisflex.core.audit.AuditManager
-import com.mybatisflex.core.audit.ConsoleMessageCollector
-import com.mybatisflex.kotlin.entry.Entry
-import com.mybatisflex.kotlin.extensions.db.*
-import com.mybatisflex.kotlin.extensions.entry.*
-import com.mybatisflex.kotlin.extensions.mapper.queryList
-import com.mybatisflex.kotlin.extensions.sql.*
-import com.mybatisflex.kotlin.scope.buildBootstrap
-import com.mybatisflex.kotlintest.entry.Account
-import com.mybatisflex.kotlintest.entry.table.AccountTableDef.ACCOUNT
-import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder
-
-import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType
-import javax.sql.DataSource
-import kotlin.streams.toList
-
-
-fun main() {
- val dataSource: DataSource = EmbeddedDatabaseBuilder()
- .setType(EmbeddedDatabaseType.H2)
- .addScript("schema.sql")
- .addScript("data.sql")
- .build()
-
- AuditManager.setAuditEnable(true)
- AuditManager.setMessageCollector(ConsoleMessageCollector())
-
- buildBootstrap {
- + AccountMapper::class.java
- dataSources {
-// dataSource(FlexConsts.NAME,dataSource)
- FlexConsts.NAME of dataSource
-// "dataSource1" of dataSource
-// "dataSource2" of dataSource
- }
-// + dataSource
- }.start()
-
- filter
+ * 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.mybatis.FlexConfiguration
+import com.mybatisflex.spring.FlexSqlSessionFactoryBean
+import org.apache.ibatis.logging.stdout.StdOutImpl
+import org.apache.ibatis.session.SqlSessionFactory
+import org.mybatis.spring.SqlSessionFactoryBean
+import org.mybatis.spring.annotation.MapperScan
+import org.springframework.context.annotation.Bean
+import org.springframework.context.annotation.Configuration
+import org.springframework.context.event.ContextStartedEvent
+import org.springframework.context.event.EventListener
+import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder
+import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType
+import javax.sql.DataSource
+
+@Configuration
+@MapperScan("com.mybatisflex.test.mapper")
+open class AppConfig {
+
+
+ @Bean
+ open fun dataSource(): DataSource? {
+ return EmbeddedDatabaseBuilder()
+ .setType(EmbeddedDatabaseType.H2)
+ .addScript("schema.sql")
+ .addScript("data-kt.sql")
+ .build()
+ }
+
+ @Bean
+ open fun sqlSessionFactory(dataSource: DataSource): SqlSessionFactory? {
+ val factoryBean: SqlSessionFactoryBean = FlexSqlSessionFactoryBean()
+ factoryBean.setDataSource(dataSource)
+ val configuration = FlexConfiguration()
+ configuration.logImpl = StdOutImpl::class.java
+ factoryBean.setConfiguration(configuration)
+ return factoryBean.getObject()
+ }
+
+ @EventListener(classes = [ContextStartedEvent::class])
+ open fun handleContextStartedEvent() {
+ println("handleContextStartedEvent listener invoked!")
+ }
+
+
+
+}
+
+
diff --git a/mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/main/kotlin/com/mybatisflex/test/mapper/AccountMapper.kt b/mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/main/kotlin/com/mybatisflex/test/mapper/AccountMapper.kt
new file mode 100755
index 00000000..da9f80d4
--- /dev/null
+++ b/mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/main/kotlin/com/mybatisflex/test/mapper/AccountMapper.kt
@@ -0,0 +1,41 @@
+/*
+ * 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.mapper
+
+import com.mybatisflex.core.BaseMapper
+import com.mybatisflex.kotlin.extensions.mapper.queryList
+import com.mybatisflex.kotlin.extensions.sql.*
+import com.mybatisflex.test.model.Account
+import com.mybatisflex.test.model.table.AccountTableDef.ACCOUNT
+
+
+@JvmDefaultWithCompatibility
+interface AccountMapper : BaseMapper
+ * 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.model
+
+import com.mybatisflex.annotation.SetListener
+
+
+class AccountOnSetListener : SetListener {
+ override fun onSet(entity: Any, property: String, value: Any): Any {
+ println(">>>>>>> property: $property value:$value")
+ return value
+ }
+}
+
diff --git a/mybatis-flex-kotlin/src/test/resources/data.sql b/mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/main/resources/data-kt.sql
similarity index 99%
rename from mybatis-flex-kotlin/src/test/resources/data.sql
rename to mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/main/resources/data-kt.sql
index 228b8319..2ee98fe5 100755
--- a/mybatis-flex-kotlin/src/test/resources/data.sql
+++ b/mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/main/resources/data-kt.sql
@@ -1,4 +1,5 @@
INSERT INTO tb_account
VALUES (1, 'Michael Yang', 18, '2020-01-11');
+
INSERT INTO tb_account
VALUES (2, 'Michael Zhanng', 20, '2020-01-11');
diff --git a/mybatis-flex-kotlin/src/test/resources/mybatis-flex.properties b/mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/main/resources/mybatis-flex.properties
similarity index 72%
rename from mybatis-flex-kotlin/src/test/resources/mybatis-flex.properties
rename to mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/main/resources/mybatis-flex.properties
index b25cdd95..929568bf 100755
--- a/mybatis-flex-kotlin/src/test/resources/mybatis-flex.properties
+++ b/mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/main/resources/mybatis-flex.properties
@@ -1,4 +1,4 @@
processor.mappersGenerateEnable=false
-processor.tablesNameStyle=upCase
+processor.tablesNameStyle=lowerCase
processor.tablesDefSuffix=Def
processor.allInTables=true
diff --git a/mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/main/resources/schema.sql b/mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/main/resources/schema.sql
new file mode 100755
index 00000000..f75d140c
--- /dev/null
+++ b/mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/main/resources/schema.sql
@@ -0,0 +1,7 @@
+CREATE TABLE IF NOT EXISTS `tb_account`
+(
+ `id` INTEGER ,
+ `u_name` VARCHAR(100) NOT NULL,
+ `age` INTEGER,
+ `birthday` DATETIME
+);
diff --git a/mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/test/kotlin/com/mybatisflex/test/KotlinSpringTest.kt b/mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/test/kotlin/com/mybatisflex/test/KotlinSpringTest.kt
new file mode 100755
index 00000000..1ba41622
--- /dev/null
+++ b/mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/test/kotlin/com/mybatisflex/test/KotlinSpringTest.kt
@@ -0,0 +1,41 @@
+/*
+ * 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.test.mapper.AccountMapper
+import org.assertj.core.api.WithAssertions
+import org.junit.runner.RunWith
+
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.test.context.ContextConfiguration
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner
+import kotlin.test.Test
+
+
+@RunWith(SpringJUnit4ClassRunner::class)
+@ContextConfiguration(classes = [AppConfig::class])
+class KotlinSpringTest : WithAssertions {
+ @Autowired
+ lateinit var accountMapper: AccountMapper
+
+ @Test
+ fun testSelectByQuery() {
+ val accounts = accountMapper.findByAge(18,2)
+ accounts.forEach(::println)
+ }
+
+
+}
diff --git a/mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/test/kotlin/com/mybatisflex/test/KotlinTest.kt b/mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/test/kotlin/com/mybatisflex/test/KotlinTest.kt
new file mode 100644
index 00000000..68bf7f2a
--- /dev/null
+++ b/mybatis-flex-test/mybatis-flex-spring-kotlin-test/src/test/kotlin/com/mybatisflex/test/KotlinTest.kt
@@ -0,0 +1,103 @@
+/*
+ * 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.FlexConsts
+import com.mybatisflex.core.audit.AuditManager
+import com.mybatisflex.core.audit.ConsoleMessageCollector
+import com.mybatisflex.kotlin.entry.Entry
+import com.mybatisflex.kotlin.extensions.db.filter
+import com.mybatisflex.kotlin.extensions.db.mapper
+import com.mybatisflex.kotlin.extensions.db.query
+import com.mybatisflex.kotlin.extensions.entry.*
+import com.mybatisflex.kotlin.extensions.sql.*
+import com.mybatisflex.kotlin.scope.buildBootstrap
+import com.mybatisflex.test.mapper.AccountMapper
+import com.mybatisflex.test.model.Account
+import com.mybatisflex.test.model.table.AccountTableDef.ACCOUNT
+import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder
+import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType
+import javax.sql.DataSource
+import kotlin.streams.toList
+import kotlin.test.Test
+
+
+class KotlinTest {
+ @Test
+ fun testDb() {
+ val dataSource: DataSource = EmbeddedDatabaseBuilder()
+ .setType(EmbeddedDatabaseType.H2)
+ .addScript("schema.sql")
+ .addScript("data-kt.sql")
+ .build()
+
+ AuditManager.setAuditEnable(true)
+ AuditManager.setMessageCollector(ConsoleMessageCollector())
+
+ buildBootstrap {
+ +AccountMapper::class.java
+ dataSources {
+// dataSource(FlexConsts.NAME,dataSource)
+ FlexConsts.NAME of dataSource
+// "dataSource1" of dataSource
+// "dataSource2" of dataSource
+ }
+// + dataSource
+ }.start()
+//
+ ACCOUNT.query