From 04ada5b8112ee7fd699b8e4bd8f7b60ea5315ae2 Mon Sep 17 00:00:00 2001 From: aoshiguchen <1052045476@qq.com> Date: Tue, 28 Jun 2022 20:48:39 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E7=94=9F=E6=88=90bean=E5=AE=9E?= =?UTF-8?q?=E4=BE=8B=E4=BC=98=E5=8C=96=EF=BC=8C=E5=BD=93bean=E6=89=80?= =?UTF-8?q?=E5=B1=9E=E7=B1=BB=E6=98=AF=E4=B8=80=E4=B8=AA=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E8=87=AA=E5=8A=A8=E7=94=A8aop=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E4=BB=A3=E7=90=86=E5=AE=9E=E4=BE=8B=202=E3=80=81aop?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=8B=A6=E6=88=AA=E5=99=A8=E5=AE=9E=E4=BE=8B?= =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=8C=E5=BD=93=E6=8B=A6=E6=88=AA=E5=99=A8?= =?UTF-8?q?=E5=9C=A8bean=E5=AE=B9=E5=99=A8=E4=B8=AD=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E5=AE=9E=E4=BE=8B=E6=97=B6=EF=BC=8C=E7=9B=B4=E6=8E=A5=E5=A4=8D?= =?UTF-8?q?=E7=94=A8bean=E5=AE=B9=E5=99=A8=E4=B8=AD=E7=9A=84=E5=AE=9E?= =?UTF-8?q?=E4=BE=8B=203=E3=80=81=E6=96=B0=E5=A2=9ESqlMapper=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E3=80=81=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81=E3=80=82?= =?UTF-8?q?=E4=BD=BF=E5=BE=97JdbcTemplate=E7=9A=84=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E6=9B=B4=E5=8A=A0=E4=BC=98=E9=9B=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aop/interceptor/InterceptorFactory.java | 6 +- .../fun/asgc/neutrino/core/context/Bean.java | 3 + .../neutrino/core/db/annotation/Delete.java | 38 ++++++++++++ .../neutrino/core/db/annotation/Insert.java | 38 ++++++++++++ .../core/db/annotation/ResultType.java | 37 +++++++++++ .../neutrino/core/db/annotation/Select.java | 34 ++++++---- .../neutrino/core/db/annotation/Update.java | 38 ++++++++++++ .../neutrino/core/db/mapper/SqlMapper.java | 4 ++ .../core/db/mapper/SqlMapperInterceptor.java | 62 +++++++++++++++++++ .../core/db/mapper/Configuration.java | 48 ++++++++++++++ .../neutrino/core/db/mapper/Launcher.java | 37 +++++++++++ .../asgc/neutrino/core/db/mapper/Test1.java | 37 +++++++++++ .../asgc/neutrino/core/db/mapper/User.java | 48 ++++++++++++++ .../neutrino/core/db/mapper/UserMapper.java | 37 +++++++++++ .../src/test/resources/application.yml | 2 + 15 files changed, 455 insertions(+), 14 deletions(-) create mode 100644 neutrino-core/src/main/java/fun/asgc/neutrino/core/db/annotation/Delete.java create mode 100644 neutrino-core/src/main/java/fun/asgc/neutrino/core/db/annotation/Insert.java create mode 100644 neutrino-core/src/main/java/fun/asgc/neutrino/core/db/annotation/ResultType.java create mode 100644 neutrino-core/src/main/java/fun/asgc/neutrino/core/db/annotation/Update.java create mode 100644 neutrino-core/src/main/java/fun/asgc/neutrino/core/db/mapper/SqlMapperInterceptor.java create mode 100644 neutrino-core/src/test/java/fun/asgc/neutrino/core/db/mapper/Configuration.java create mode 100644 neutrino-core/src/test/java/fun/asgc/neutrino/core/db/mapper/Launcher.java create mode 100644 neutrino-core/src/test/java/fun/asgc/neutrino/core/db/mapper/Test1.java create mode 100644 neutrino-core/src/test/java/fun/asgc/neutrino/core/db/mapper/User.java create mode 100644 neutrino-core/src/test/java/fun/asgc/neutrino/core/db/mapper/UserMapper.java create mode 100644 neutrino-core/src/test/resources/application.yml diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/interceptor/InterceptorFactory.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/interceptor/InterceptorFactory.java index 8c3a5126..f31780f4 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/interceptor/InterceptorFactory.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/interceptor/InterceptorFactory.java @@ -48,7 +48,11 @@ public class InterceptorFactory { clazz, () -> { try { - interceptorCache.set(clazz, clazz.newInstance()); + if (BeanManager.getBean(clazz) != null) { + interceptorCache.set(clazz, BeanManager.getBean(clazz)); + } else { + interceptorCache.set(clazz, clazz.newInstance()); + } } catch (InstantiationException|IllegalAccessException e) { throw new RuntimeException(e); } diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/context/Bean.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/context/Bean.java index c3c24324..0ffcb62d 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/context/Bean.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/context/Bean.java @@ -23,6 +23,7 @@ package fun.asgc.neutrino.core.context; import fun.asgc.neutrino.core.annotation.*; +import fun.asgc.neutrino.core.aop.Aop; import fun.asgc.neutrino.core.container.LifeCycle; import fun.asgc.neutrino.core.container.BeanContainer; import fun.asgc.neutrino.core.util.*; @@ -118,6 +119,8 @@ public class Bean implements LifeCycle { Configuration configuration = clazz.getAnnotation(Configuration.class); if (null != configuration) { instance = ConfigUtil.getYmlConfig(clazz); + } else if (ClassUtil.isInterface(clazz)) { + instance = Aop.get(clazz); } else { // 由编码规避没有无参构造器的问题 instance = clazz.newInstance(); diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/annotation/Delete.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/annotation/Delete.java new file mode 100644 index 00000000..d3eed038 --- /dev/null +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/annotation/Delete.java @@ -0,0 +1,38 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.db.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * + * @author: aoshiguchen + * @date: 2022/6/28 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface Delete { + String value(); +} diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/annotation/Insert.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/annotation/Insert.java new file mode 100644 index 00000000..3ba3101c --- /dev/null +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/annotation/Insert.java @@ -0,0 +1,38 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.db.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * + * @author: aoshiguchen + * @date: 2022/6/28 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface Insert { + String value(); +} diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/annotation/ResultType.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/annotation/ResultType.java new file mode 100644 index 00000000..a49c775b --- /dev/null +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/annotation/ResultType.java @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.db.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author: aoshiguchen + * @date: 2022/6/28 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface ResultType { + Class> value(); +} diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/annotation/Select.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/annotation/Select.java index f294e8d4..bda96130 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/annotation/Select.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/annotation/Select.java @@ -1,14 +1,23 @@ /** - * Copyright (C) 2018-2022 Zeyi information technology (Shanghai) Co., Ltd. - *
- * All right reserved. - *
- * This software is the confidential and proprietary - * information of Zeyi Company of China. - * ("Confidential Information"). You shall not disclose - * such Confidential Information and shall use it only - * in accordance with the terms of the contract agreement - * you entered into with Zeyi inc. + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. */ package fun.asgc.neutrino.core.db.annotation; @@ -19,12 +28,11 @@ import java.lang.annotation.Target; /** * - * @author: wen.y + * @author: aoshiguchen * @date: 2022/6/28 */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Select { - String sql(); - Class> resultType(); + String value(); } diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/annotation/Update.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/annotation/Update.java new file mode 100644 index 00000000..86648c79 --- /dev/null +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/annotation/Update.java @@ -0,0 +1,38 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.db.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * + * @author: aoshiguchen + * @date: 2022/6/28 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface Update { + String value(); +} diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/mapper/SqlMapper.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/mapper/SqlMapper.java index 69322c7b..1285feca 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/mapper/SqlMapper.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/mapper/SqlMapper.java @@ -21,10 +21,14 @@ */ package fun.asgc.neutrino.core.db.mapper; +import fun.asgc.neutrino.core.aop.Intercept; +import fun.asgc.neutrino.core.aop.interceptor.InnerGlobalInterceptor; + /** * @author: aoshiguchen * @date: 2022/6/28 */ +@Intercept(value = SqlMapperInterceptor.class, exclude = InnerGlobalInterceptor.class) public interface SqlMapper { } diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/mapper/SqlMapperInterceptor.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/mapper/SqlMapperInterceptor.java new file mode 100644 index 00000000..0167cfd7 --- /dev/null +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/mapper/SqlMapperInterceptor.java @@ -0,0 +1,62 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.db.mapper; + +import fun.asgc.neutrino.core.annotation.Autowired; +import fun.asgc.neutrino.core.annotation.Component; +import fun.asgc.neutrino.core.aop.Invocation; +import fun.asgc.neutrino.core.aop.interceptor.Interceptor; +import fun.asgc.neutrino.core.db.annotation.Select; +import fun.asgc.neutrino.core.db.template.JdbcTemplate; +import fun.asgc.neutrino.core.util.Assert; +import fun.asgc.neutrino.core.util.StringUtil; + +import java.util.Collection; + +/** + * sqlmapper拦截器 + * @author: aoshiguchen + * @date: 2022/6/28 + */ +@Component +public class SqlMapperInterceptor implements Interceptor { + + @Autowired + private JdbcTemplate jdbcTemplate; + + @Override + public void intercept(Invocation inv) { + Assert.notNull(jdbcTemplate, "JdbcTemplate未注入,调用失败!"); + if (inv.getTargetMethod().isAnnotationPresent(Select.class)) { + Select select = inv.getTargetMethod().getAnnotation(Select.class); + String sql = select.value(); + if (StringUtil.isEmpty(sql)) { + throw new RuntimeException("sql不能为空!"); + } + Class> returnType = inv.getReturnType(); + if (!Collection.class.isAssignableFrom(returnType)) { + Object res = jdbcTemplate.query(returnType, sql, inv.getArgs()); + inv.setReturnValue(res); + } + } + } +} diff --git a/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/mapper/Configuration.java b/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/mapper/Configuration.java new file mode 100644 index 00000000..3919119c --- /dev/null +++ b/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/mapper/Configuration.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.db.mapper; + +import com.alibaba.druid.pool.DruidDataSource; +import fun.asgc.neutrino.core.annotation.Bean; +import fun.asgc.neutrino.core.annotation.Component; +import fun.asgc.neutrino.core.annotation.Order; +import fun.asgc.neutrino.core.db.template.JdbcTemplate; + +/** + * + * @author: aoshiguchen + * @date: 2022/6/28 + */ +@Order(0) +@Component +public class Configuration { + + @Bean + public JdbcTemplate jdbcTemplate() { + DruidDataSource dataSource = new DruidDataSource(); + dataSource.setUrl("jdbc:mysql://localhost:3306/test1?useUnicode=true&characterEncoding=utf8"); + dataSource.setUsername("root"); + dataSource.setPassword("YWasgc@10520"); + return new JdbcTemplate(dataSource); + } + +} diff --git a/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/mapper/Launcher.java b/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/mapper/Launcher.java new file mode 100644 index 00000000..586a5eac --- /dev/null +++ b/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/mapper/Launcher.java @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.db.mapper; + +import fun.asgc.neutrino.core.annotation.*; +import fun.asgc.neutrino.core.launcher.NeutrinoLauncher; + +/** + * + * @author: aoshiguchen + * @date: 2022/6/28 + */ +@NeutrinoApplication +public class Launcher { + public static void main(String[] args) { + NeutrinoLauncher.runSync(Launcher.class, args); + } +} diff --git a/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/mapper/Test1.java b/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/mapper/Test1.java new file mode 100644 index 00000000..9886cb33 --- /dev/null +++ b/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/mapper/Test1.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2018-2022 Zeyi information technology (Shanghai) Co., Ltd. + *
+ * All right reserved. + *
+ * This software is the confidential and proprietary + * information of Zeyi Company of China. + * ("Confidential Information"). You shall not disclose + * such Confidential Information and shall use it only + * in accordance with the terms of the contract agreement + * you entered into with Zeyi inc. + */ +package fun.asgc.neutrino.core.db.mapper; + +import com.alibaba.fastjson.JSONObject; +import fun.asgc.neutrino.core.annotation.Autowired; +import fun.asgc.neutrino.core.annotation.Component; +import fun.asgc.neutrino.core.runner.ApplicationRunner; +import lombok.extern.slf4j.Slf4j; + +/** + * + * @author: aoshiguchen + * @date: 2022/6/28 + */ +@Slf4j +@Component +public class Test1 implements ApplicationRunner { + @Autowired + private UserMapper userMapper; + + @Override + public void run(String[] args) { + User user = userMapper.findOneById(1L); + log.info("查询结果:{}", JSONObject.toJSONString(user)); + } +} diff --git a/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/mapper/User.java b/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/mapper/User.java new file mode 100644 index 00000000..e2bcb39d --- /dev/null +++ b/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/mapper/User.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.db.mapper; + +import fun.asgc.neutrino.core.db.annotation.Id; +import fun.asgc.neutrino.core.db.annotation.Table; +import lombok.Data; +import lombok.ToString; + +import java.util.Date; + +/** + * + * @author: aoshiguchen + * @date: 2022/6/28 + */ +@ToString +@Data +@Table("user") +public class User { + @Id + private Long id; + private String name; + private Integer age; + private String email; + private String sex; + private Date createTime; + private Date updateTime; +} diff --git a/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/mapper/UserMapper.java b/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/mapper/UserMapper.java new file mode 100644 index 00000000..e651dccb --- /dev/null +++ b/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/mapper/UserMapper.java @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.db.mapper; + +import fun.asgc.neutrino.core.annotation.Component; +import fun.asgc.neutrino.core.db.annotation.Select; + +/** + * + * @author: aoshiguchen + * @date: 2022/6/28 + */ +@Component +public interface UserMapper extends SqlMapper { + + @Select("select * from user where id = ?") + User findOneById(Long id); +} diff --git a/neutrino-core/src/test/resources/application.yml b/neutrino-core/src/test/resources/application.yml new file mode 100644 index 00000000..b8898cc2 --- /dev/null +++ b/neutrino-core/src/test/resources/application.yml @@ -0,0 +1,2 @@ +application: + name: neutrino-core-test