diff --git a/changelog-temp.md b/changelog-temp.md index f6adafb3e..8f3113f71 100644 --- a/changelog-temp.md +++ b/changelog-temp.md @@ -1,5 +1,5 @@ -- opt: 优化代码生成器支持可视化配置生产能力 -- opt: 解构扩展包不再强制依赖 spring 开发框架 +- opt: 优化代码生成器支持可视化配置生成能力 +- opt: 解耦扩展包不再强制依赖 spring 开发框架 - feat: 重构 service 模块抽象为 CrudRepository 不再建议使用 IService 避免业务层数据混乱 - feat: 新增 solon 启动插件支持 diff --git a/mybatis-plus-solon-plugin/build.gradle b/mybatis-plus-solon-plugin/build.gradle deleted file mode 100644 index f4546ead0..000000000 --- a/mybatis-plus-solon-plugin/build.gradle +++ /dev/null @@ -1,17 +0,0 @@ -apply plugin: 'kotlin' - -compileKotlin{ - kotlinOptions.jvmTarget = "1.8" -} - -dependencies { - api project(":mybatis-plus-extension") - api "org.noear:mybatis-solon-plugin:3.0.1" - api "org.noear:solon-aot:3.0.1" - testImplementation "org.noear:solon-test:3.0.1" - testImplementation "io.github.classgraph:classgraph:4.8.176" - testImplementation "com.zaxxer:HikariCP:4.0.3" - testImplementation "${lib.h2}" - testImplementation "${lib.mysql}" - testImplementation "${lib.'logback-classic'}" -} diff --git a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/core/override/SolonMybatisMapperProxy.java b/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/core/override/SolonMybatisMapperProxy.java deleted file mode 100644 index a635ab02b..000000000 --- a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/core/override/SolonMybatisMapperProxy.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.baomidou.mybatisplus.core.override; - -import org.apache.ibatis.session.SqlSession; -import org.apache.ibatis.session.SqlSessionFactory; - -import java.lang.reflect.Method; - -public class SolonMybatisMapperProxy extends MybatisMapperProxy { - - private final SqlSessionFactory factory; - private final Class mapperInterface; - private final SqlSession sqlSession; - - public SolonMybatisMapperProxy(SqlSessionFactory sqlSessionFactory, SqlSession sqlSession, Class mapperInterface) { - super(null, mapperInterface, null); - this.factory = sqlSessionFactory; - this.sqlSession = sqlSession; - this.mapperInterface = mapperInterface; - } - - @Override - public SqlSession getSqlSession() { - return sqlSession; - } - - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - try (SqlSession session = factory.openSession(true)) { - Object mapper = session.getMapper(mapperInterface); - return method.invoke(mapper, args); - } - } -} diff --git a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/activerecord/Model.java b/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/activerecord/Model.java deleted file mode 100644 index 667cab8f8..000000000 --- a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/activerecord/Model.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2011-2024, baomidou (jobob@qq.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.baomidou.mybatisplus.extension.activerecord; - -import com.baomidou.mybatisplus.extension.toolkit.SqlRunner; - -/** - * ActiveRecord 模式 CRUD - *

- * 必须存在对应的原始mapper并继承baseMapper并且可以使用的前提下 - * 才能使用此 AR 模式 !!! - *

- * - * @param - * @author hubin - * @since 2016-11-06 - */ -public abstract class Model> extends AbstractModel { - - /** - * 执行 SQL - */ - public SqlRunner sql() { - return new SqlRunner(this.entityClass); - } -} diff --git a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/compatible/SolonCompatibleSet.java b/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/compatible/SolonCompatibleSet.java deleted file mode 100644 index 1e4fb7d52..000000000 --- a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/compatible/SolonCompatibleSet.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2011-2024, baomidou (jobob@qq.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.baomidou.mybatisplus.extension.compatible; - -import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils; -import org.apache.ibatis.logging.Log; -import org.apache.ibatis.reflection.ExceptionUtil; -import org.apache.ibatis.session.ExecutorType; -import org.apache.ibatis.session.SqlSession; -import org.apache.ibatis.session.SqlSessionFactory; -import org.noear.solon.core.util.GenericUtil; -import org.noear.solon.core.util.ResourceUtil; -import org.noear.solon.data.tran.TranUtils; - -import java.io.InputStream; -import java.util.function.Consumer; - -/** - * spring 兼容方法集接口实现类 - */ -public class SolonCompatibleSet implements CompatibleSet { - - @Override - public SqlSession getSqlSession(SqlSessionFactory sessionFactory) { - return sessionFactory.openSession(); - } - - @Override - public void closeSqlSession(SqlSession sqlSession, SqlSessionFactory sqlSessionFactory) { - if (sqlSession != null) { - sqlSession.close(); - } - } - - @Override - public boolean executeBatch(SqlSessionFactory sqlSessionFactory, Log log, Consumer consumer) { - boolean transaction = TranUtils.inTrans(); - SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); - if (!transaction) { - log.warn("SqlSession [" + sqlSession + "] Transaction not enabled"); - } - try { - consumer.accept(sqlSession); - //非事务情况下,强制commit。 - sqlSession.commit(!transaction); - return true; - } catch (RuntimeException t) { - throw t; - } catch (Throwable t) { - sqlSession.rollback(); - Throwable unwrapped = ExceptionUtil.unwrapThrowable(t); - if (unwrapped instanceof RuntimeException) { - throw (RuntimeException) unwrapped; - } else { - throw ExceptionUtils.mpe(unwrapped); - } - } finally { - sqlSession.close(); - } - } - - @Override - public InputStream getInputStream(String path) throws Exception { - return ResourceUtil.findResource(path).openStream(); - } - -} diff --git a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/ddl/SimpleDdl.java b/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/ddl/SimpleDdl.java deleted file mode 100644 index 52ea76279..000000000 --- a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/ddl/SimpleDdl.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2011-2024, baomidou (jobob@qq.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.baomidou.mybatisplus.extension.ddl; - -import org.noear.solon.annotation.Inject; - -import javax.sql.DataSource; -import java.util.List; -import java.util.function.Consumer; - -/** - * 非多数据源 DDL 实现 - * - * @author hubin - * @since 2021-09-23 - */ -public class SimpleDdl implements IDdl { - - @Inject - private DataSource dataSource; - - @Override - public void runScript(Consumer consumer) { - consumer.accept(dataSource); - } - - @Override - public List getSqlFiles() { - return null; - } - -} diff --git a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/repository/CrudRepository.java b/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/repository/CrudRepository.java deleted file mode 100644 index 7e4e46b28..000000000 --- a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/repository/CrudRepository.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2011-2024, baomidou (jobob@qq.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.baomidou.mybatisplus.extension.repository; - -import com.baomidou.mybatisplus.core.enums.SqlMethod; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.core.metadata.TableInfo; -import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; -import com.baomidou.mybatisplus.core.toolkit.Assert; -import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; -import com.baomidou.mybatisplus.core.toolkit.Constants; -import com.baomidou.mybatisplus.core.toolkit.StringUtils; -import com.baomidou.mybatisplus.extension.toolkit.SqlHelper; -import org.apache.ibatis.binding.MapperMethod; -import org.noear.solon.annotation.Inject; -import org.noear.solon.data.annotation.Tran; - -import java.util.Collection; - -/** - * IService 实现类( 泛型:M 是 mapper 对象,T 是实体 ) - * - * @author hubin - * @since 2018-06-23 - */ -public abstract class CrudRepository, T> extends AbstractRepository { - - @Inject - protected M baseMapper; - - @Override - public M getBaseMapper() { - Assert.notNull(this.baseMapper, "baseMapper can not be null"); - return this.baseMapper; - } - - /** - * 批量插入 - * - * @param entityList ignore - * @param batchSize ignore - * @return ignore - */ - @Tran - @Override - public boolean saveBatch(Collection entityList, int batchSize) { - String sqlStatement = getSqlStatement(SqlMethod.INSERT_ONE); - return executeBatch(entityList, batchSize, (sqlSession, entity) -> sqlSession.insert(sqlStatement, entity)); - } - - /** - * 获取mapperStatementId - * - * @param sqlMethod 方法名 - * @return 命名id - * @since 3.4.0 - */ - protected String getSqlStatement(SqlMethod sqlMethod) { - return SqlHelper.getSqlStatement(this.getMapperClass(), sqlMethod); - } - - @Tran - @Override - public boolean saveOrUpdateBatch(Collection entityList, int batchSize) { - TableInfo tableInfo = TableInfoHelper.getTableInfo(this.getEntityClass()); - Assert.notNull(tableInfo, "error: can not execute. because can not find cache of TableInfo for entity!"); - String keyProperty = tableInfo.getKeyProperty(); - Assert.notEmpty(keyProperty, "error: can not execute. because can not find column for id from entity!"); - return SqlHelper.saveOrUpdateBatch(getSqlSessionFactory(), this.getMapperClass(), this.log, entityList, batchSize, (sqlSession, entity) -> { - Object idVal = tableInfo.getPropertyValue(entity, keyProperty); - return StringUtils.checkValNull(idVal) - || CollectionUtils.isEmpty(sqlSession.selectList(getSqlStatement(SqlMethod.SELECT_BY_ID), entity)); - }, (sqlSession, entity) -> { - MapperMethod.ParamMap param = new MapperMethod.ParamMap<>(); - param.put(Constants.ENTITY, entity); - sqlSession.update(getSqlStatement(SqlMethod.UPDATE_BY_ID), param); - }); - } - - @Tran - @Override - public boolean updateBatchById(Collection entityList, int batchSize) { - String sqlStatement = getSqlStatement(SqlMethod.UPDATE_BY_ID); - return executeBatch(entityList, batchSize, (sqlSession, entity) -> { - MapperMethod.ParamMap param = new MapperMethod.ParamMap<>(); - param.put(Constants.ENTITY, entity); - sqlSession.update(sqlStatement, param); - }); - } -} diff --git a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/service/IService.java b/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/service/IService.java deleted file mode 100644 index 352a5b892..000000000 --- a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/service/IService.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2011-2024, baomidou (jobob@qq.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.baomidou.mybatisplus.extension.service; - -import com.baomidou.mybatisplus.extension.repository.IRepository; -import org.noear.solon.data.annotation.Tran; - -import java.util.Collection; - -/** - * 顶级 Service - * - * @author hubin - * @since 2018-06-23 - */ -public interface IService extends IRepository { - - /** - * 插入(批量) - * - * @param entityList 实体对象集合 - */ - @Tran - default boolean saveBatch(Collection entityList) { - return saveBatch(entityList, DEFAULT_BATCH_SIZE); - } - - /** - * 批量修改插入 - * - * @param entityList 实体对象集合 - */ - @Tran - default boolean saveOrUpdateBatch(Collection entityList) { - return saveOrUpdateBatch(entityList, DEFAULT_BATCH_SIZE); - } - - /** - * 批量删除(jdbc批量提交) - * - * @param list 主键ID或实体列表(主键ID类型必须与实体类型字段保持一致) - * @return 删除结果 - * @since 3.5.0 - */ - @Tran - default boolean removeBatchByIds(Collection list) { - return removeByIds(list); - } - - /** - * 根据ID 批量更新 - * - * @param entityList 实体对象集合 - */ - @Tran - default boolean updateBatchById(Collection entityList) { - return updateBatchById(entityList, DEFAULT_BATCH_SIZE); - } -} diff --git a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/service/impl/ServiceImpl.java b/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/service/impl/ServiceImpl.java deleted file mode 100644 index 6b3333964..000000000 --- a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/service/impl/ServiceImpl.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2011-2024, baomidou (jobob@qq.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.baomidou.mybatisplus.extension.service.impl; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.extension.repository.CrudRepository; -import com.baomidou.mybatisplus.extension.service.IService; - -/** - * IService 实现类( 泛型:M 是 mapper 对象,T 是实体 ) - * - * @author hubin - * @since 2018-06-23 - */ -public class ServiceImpl, T> extends CrudRepository implements IService { - -} diff --git a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/service/impl/package-info.java b/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/service/impl/package-info.java deleted file mode 100644 index 8e6be58a8..000000000 --- a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/service/impl/package-info.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2011-2024, baomidou (jobob@qq.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. - */ -/** - * 通用 service 实现 - * - * @author hubin - * @since 2018-06-08 - */ -package com.baomidou.mybatisplus.extension.service.impl; diff --git a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/service/package-info.java b/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/service/package-info.java deleted file mode 100644 index 92566b86c..000000000 --- a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/service/package-info.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2011-2024, baomidou (jobob@qq.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. - */ -/** - * 通用 Service 接口 - * - * @author hubin - * @since 2018-06-08 - */ -package com.baomidou.mybatisplus.extension.service; diff --git a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/toolkit/SqlRunner.java b/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/toolkit/SqlRunner.java deleted file mode 100644 index 45f1ab23e..000000000 --- a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/extension/toolkit/SqlRunner.java +++ /dev/null @@ -1,244 +0,0 @@ -/* - * Copyright (c) 2011-2024, baomidou (jobob@qq.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.baomidou.mybatisplus.extension.toolkit; - -import com.baomidou.mybatisplus.core.assist.ISqlRunner; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; -import com.baomidou.mybatisplus.core.toolkit.GlobalConfigUtils; -import com.baomidou.mybatisplus.core.toolkit.StringUtils; -import org.apache.ibatis.logging.Log; -import org.apache.ibatis.logging.LogFactory; -import org.apache.ibatis.session.SqlSession; -import org.apache.ibatis.session.SqlSessionFactory; -import org.noear.solon.data.annotation.Tran; - -import java.util.List; -import java.util.Map; -import java.util.Optional; - -/** - * SqlRunner 执行 SQL - * - * @author Caratacus - * @since 2016-12-11 - */ -public class SqlRunner implements ISqlRunner { - - // 单例Query - public static final SqlRunner DEFAULT = new SqlRunner(); - private final Log log = LogFactory.getLog(SqlRunner.class); - private Class clazz; - - public SqlRunner() { - } - - public SqlRunner(Class clazz) { - this.clazz = clazz; - } - - /** - * 获取默认的SqlQuery(适用于单库) - * - * @return ignore - */ - public static SqlRunner db() { - return DEFAULT; - } - - /** - * 根据当前class对象获取SqlQuery(适用于多库) - * - * @param clazz ignore - * @return ignore - */ - public static SqlRunner db(Class clazz) { - return new SqlRunner(clazz); - } - - @Tran - @Override - public boolean insert(String sql, Object... args) { - SqlSession sqlSession = sqlSession(); - try { - return SqlHelper.retBool(sqlSession.insert(INSERT, sqlMap(sql, args))); - } finally { - closeSqlSession(sqlSession); - } - } - - @Tran - @Override - public boolean delete(String sql, Object... args) { - SqlSession sqlSession = sqlSession(); - try { - return SqlHelper.retBool(sqlSession.delete(DELETE, sqlMap(sql, args))); - } finally { - closeSqlSession(sqlSession); - } - } - - /** - * 获取sqlMap参数 - * - * @param sql 指定参数的格式: {0}, {1} - * @param args 仅支持String - * @return ignore - */ - private Map sqlMap(String sql, Object... args) { - Map sqlMap = CollectionUtils.newHashMapWithExpectedSize(1); - sqlMap.put(SQL, StringUtils.sqlArgsFill(sql, args)); - return sqlMap; - } - - /** - * 获取sqlMap参数 - * - * @param sql 指定参数的格式: {0}, {1} - * @param page 分页模型 - * @param args 仅支持String - * @return ignore - */ - private Map sqlMap(String sql, IPage page, Object... args) { - Map sqlMap = CollectionUtils.newHashMapWithExpectedSize(2); - sqlMap.put(PAGE, page); - sqlMap.put(SQL, StringUtils.sqlArgsFill(sql, args)); - return sqlMap; - } - - @Tran - @Override - public boolean update(String sql, Object... args) { - SqlSession sqlSession = sqlSession(); - try { - return SqlHelper.retBool(sqlSession.update(UPDATE, sqlMap(sql, args))); - } finally { - closeSqlSession(sqlSession); - } - } - - /** - * 根据sql查询Map结果集 - *

SqlRunner.db().selectList("select * from tbl_user where name={0}", "Caratacus")

- * - * @param sql sql语句,可添加参数,格式:{0},{1} - * @param args 只接受String格式 - * @return ignore - */ - @Override - public List> selectList(String sql, Object... args) { - SqlSession sqlSession = sqlSession(); - try { - return sqlSession.selectList(SELECT_LIST, sqlMap(sql, args)); - } finally { - closeSqlSession(sqlSession); - } - } - - /** - * 根据sql查询一个字段值的结果集 - *

注意:该方法只会返回一个字段的值, 如果需要多字段,请参考{@code selectList()}

- * - * @param sql sql语句,可添加参数,格式:{0},{1} - * @param args 只接受String格式 - * @return ignore - */ - @Override - public List selectObjs(String sql, Object... args) { - SqlSession sqlSession = sqlSession(); - try { - return sqlSession.selectList(SELECT_OBJS, sqlMap(sql, args)); - } finally { - closeSqlSession(sqlSession); - } - } - - /** - * 根据sql查询一个字段值的一条结果 - *

注意:该方法只会返回一个字段的值, 如果需要多字段,请参考{@code selectOne()}

- * - * @param sql sql语句,可添加参数,格式:{0},{1} - * @param args 只接受String格式 - * @return ignore - */ - @Override - public Object selectObj(String sql, Object... args) { - return SqlHelper.getObject(log, selectObjs(sql, args)); - } - - @Override - public long selectCount(String sql, Object... args) { - SqlSession sqlSession = sqlSession(); - try { - return SqlHelper.retCount(sqlSession.selectOne(COUNT, sqlMap(sql, args))); - } finally { - closeSqlSession(sqlSession); - } - } - - @Override - public Map selectOne(String sql, Object... args) { - return SqlHelper.getObject(log, selectList(sql, args)); - } - - @Override - public >> E selectPage(E page, String sql, Object... args) { - if (null == page) { - return null; - } - SqlSession sqlSession = sqlSession(); - try { - page.setRecords(sqlSession.selectList(SELECT_LIST, sqlMap(sql, page, args))); - } finally { - closeSqlSession(sqlSession); - } - return page; - } - - /** - * 获取Session 默认自动提交 - */ - private SqlSession sqlSession() { - return getSqlSessionFactory().openSession(); - } - - /** - * 释放sqlSession - * - * @param sqlSession session - */ - private void closeSqlSession(SqlSession sqlSession) { - if (sqlSession != null) { - sqlSession.close(); - } - } - - /** - * 获取SqlSessionFactory - */ - private SqlSessionFactory getSqlSessionFactory() { - return Optional.ofNullable(clazz).map(GlobalConfigUtils::currentSessionFactory).orElse(SqlHelper.FACTORY); - } - - /** - * @deprecated 3.5.3.2 - */ - @Deprecated - public void close() { - - } - -} diff --git a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/solon/integration/MybatisAdapterFactoryPlus.java b/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/solon/integration/MybatisAdapterFactoryPlus.java deleted file mode 100644 index 9bdd251bd..000000000 --- a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/solon/integration/MybatisAdapterFactoryPlus.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.baomidou.mybatisplus.solon.integration; - -import org.apache.ibatis.solon.MybatisAdapter; -import org.apache.ibatis.solon.MybatisAdapterFactory; -import org.noear.solon.core.BeanWrap; -import org.noear.solon.core.Props; - -/** - * 适配器工厂 for mybatis-plus - * - * @author noear, iYarnFog - * @since 1.5 - */ -public class MybatisAdapterFactoryPlus implements MybatisAdapterFactory { - @Override - public MybatisAdapter create(BeanWrap dsWrap) { - return new MybatisAdapterPlus(dsWrap); - } - - @Override - public MybatisAdapter create(BeanWrap dsWrap, Props dsProps) { - return new MybatisAdapterPlus(dsWrap, dsProps); - } -} diff --git a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/solon/integration/MybatisAdapterPlus.java b/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/solon/integration/MybatisAdapterPlus.java deleted file mode 100644 index 7bf9bde8f..000000000 --- a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/solon/integration/MybatisAdapterPlus.java +++ /dev/null @@ -1,146 +0,0 @@ -package com.baomidou.mybatisplus.solon.integration; - -import com.baomidou.mybatisplus.core.MybatisConfiguration; -import com.baomidou.mybatisplus.core.MybatisSqlSessionFactoryBuilder; -import com.baomidou.mybatisplus.core.config.GlobalConfig; -import com.baomidou.mybatisplus.core.override.SolonMybatisMapperProxy; -import com.baomidou.mybatisplus.core.toolkit.GlobalConfigUtils; -import org.apache.ibatis.mapping.Environment; -import org.apache.ibatis.session.SqlSession; -import org.apache.ibatis.session.SqlSessionFactory; -import org.apache.ibatis.solon.integration.MybatisAdapterDefault; -import org.noear.solon.Utils; -import org.noear.solon.core.BeanWrap; -import org.noear.solon.core.Props; -import org.noear.solon.core.VarHolder; - -import java.lang.reflect.Proxy; -import java.util.HashMap; -import java.util.Map; - -/** - * 适配器 for mybatis-plus - *

- * 1.提供 mapperScan 能力 - * 2.生成 factory 的能力 - * - * @author noear, iYarnFog - * @since 1.5 - */ -public class MybatisAdapterPlus extends MybatisAdapterDefault { - - MybatisSqlSessionFactoryBuilder factoryBuilderPlus; - GlobalConfig globalConfig; - SqlSession sqlSession; - Map, Object> mapperCached = new HashMap<>(); - - /** - * 构建Sql工厂适配器,使用默认的 typeAliases 和 mappers 配置 - */ - protected MybatisAdapterPlus(BeanWrap dsWrap) { - super(dsWrap); - - this.factoryBuilderPlus = new MybatisSqlSessionFactoryBuilder(); - - dsWrap.context().getBeanAsync(MybatisSqlSessionFactoryBuilder.class, bean -> { - factoryBuilderPlus = bean; - }); - } - - /** - * 构建Sql工厂适配器,使用属性配置 - */ - protected MybatisAdapterPlus(BeanWrap dsWrap, Props dsProps) { - super(dsWrap, dsProps); - - this.factoryBuilderPlus = new MybatisSqlSessionFactoryBuilder(); - - dsWrap.context().getBeanAsync(MybatisSqlSessionFactoryBuilder.class, bean -> { - factoryBuilderPlus = bean; - }); - } - - /** - * 初始化配置 - */ - @Override - protected void initConfiguration(Environment environment) { - //for configuration section - config = new MybatisConfiguration(environment); - - Props cfgProps = dsProps.getProp("configuration"); - if (cfgProps.size() > 0) { - Utils.injectProperties(config, cfgProps); - } - - - //for globalConfig section - globalConfig = new GlobalConfig().setDbConfig(new GlobalConfig.DbConfig()); - - Props globalProps = dsProps.getProp("globalConfig"); - if (globalProps.size() > 0) { - //尝试配置注入 - Utils.injectProperties(globalConfig, globalProps); - } - - GlobalConfigUtils.setGlobalConfig(config, globalConfig); - } - - /** - * 获取会话工厂 - */ - @Override - public SqlSessionFactory getFactory() { - if (factory == null) { - factory = factoryBuilderPlus.build(getConfiguration()); - } - - return factory; - } - - public SqlSession getSession() { - if (sqlSession == null) { - sqlSession = new SolonSqlSession(getFactory()); - } - return sqlSession; - } - - @Override - public T getMapper(Class mapperClz) { - Object mapper = mapperCached.get(mapperClz); - - if (mapper == null) { - synchronized (mapperClz) { - mapper = mapperCached.get(mapperClz); - if (mapper == null) { - SolonMybatisMapperProxy tMybatisMapperProxy = new SolonMybatisMapperProxy<>(getFactory(), getSession(), mapperClz); - mapper = Proxy.newProxyInstance( - mapperClz.getClassLoader(), - new Class[]{mapperClz}, - tMybatisMapperProxy); - mapperCached.put(mapperClz, mapper); - } - } - } - - return (T) mapper; - } - - /** - * 获取全局配置 - */ - public GlobalConfig getGlobalConfig() { - return globalConfig; - } - - @Override - public void injectTo(VarHolder varH) { - super.injectTo(varH); - - //@Db("db1") SqlSessionFactory factory; - if (GlobalConfig.class.isAssignableFrom(varH.getType())) { - varH.setValue(this.getGlobalConfig()); - return; - } - } -} diff --git a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/solon/integration/SolonSqlSession.java b/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/solon/integration/SolonSqlSession.java deleted file mode 100644 index 451d0d917..000000000 --- a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/solon/integration/SolonSqlSession.java +++ /dev/null @@ -1,209 +0,0 @@ -package com.baomidou.mybatisplus.solon.integration; - -import org.apache.ibatis.cursor.Cursor; -import org.apache.ibatis.executor.BatchResult; -import org.apache.ibatis.reflection.ExceptionUtil; -import org.apache.ibatis.session.Configuration; -import org.apache.ibatis.session.ResultHandler; -import org.apache.ibatis.session.RowBounds; -import org.apache.ibatis.session.SqlSession; -import org.apache.ibatis.session.SqlSessionFactory; -import org.noear.solon.data.tran.TranUtils; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.sql.Connection; -import java.util.List; -import java.util.Map; - -public class SolonSqlSession implements SqlSession { - - private final SqlSessionFactory sqlSessionFactory; - private final SqlSession sqlSessionProxy; - - public SolonSqlSession(SqlSessionFactory sqlSessionFactory) { - this.sqlSessionFactory = sqlSessionFactory; - this.sqlSessionProxy = (SqlSession) Proxy.newProxyInstance(SqlSessionFactory.class.getClassLoader(), new Class[]{SqlSession.class}, new SqlSessionInterceptor()); - } - - public SqlSessionFactory getSqlSessionFactory() { - return this.sqlSessionFactory; - } - - public SqlSession getSqlSessionProxy() { - return this.sqlSessionProxy; - } - - @Override - public T selectOne(String statement) { - return this.sqlSessionProxy.selectOne(statement); - } - - @Override - public T selectOne(String statement, Object parameter) { - return this.sqlSessionProxy.selectOne(statement, parameter); - } - - @Override - public Map selectMap(String statement, String mapKey) { - return this.sqlSessionProxy.selectMap(statement, mapKey); - } - - @Override - public Map selectMap(String statement, Object parameter, String mapKey) { - return this.sqlSessionProxy.selectMap(statement, parameter, mapKey); - } - - @Override - public Map selectMap(String statement, Object parameter, String mapKey, RowBounds rowBounds) { - return this.sqlSessionProxy.selectMap(statement, parameter, mapKey, rowBounds); - } - - @Override - public Cursor selectCursor(String statement) { - return this.sqlSessionProxy.selectCursor(statement); - } - - @Override - public Cursor selectCursor(String statement, Object parameter) { - return this.sqlSessionProxy.selectCursor(statement, parameter); - } - - @Override - public Cursor selectCursor(String statement, Object parameter, RowBounds rowBounds) { - return this.sqlSessionProxy.selectCursor(statement, parameter, rowBounds); - } - - @Override - public List selectList(String statement) { - return this.sqlSessionProxy.selectList(statement); - } - - @Override - public List selectList(String statement, Object parameter) { - return this.sqlSessionProxy.selectList(statement, parameter); - } - - @Override - public List selectList(String statement, Object parameter, RowBounds rowBounds) { - return this.sqlSessionProxy.selectList(statement, parameter, rowBounds); - } - - @Override - public void select(String statement, ResultHandler handler) { - this.sqlSessionProxy.select(statement, handler); - } - - @Override - public void select(String statement, Object parameter, ResultHandler handler) { - this.sqlSessionProxy.select(statement, parameter, handler); - } - - @Override - public void select(String statement, Object parameter, RowBounds rowBounds, ResultHandler handler) { - this.sqlSessionProxy.select(statement, parameter, rowBounds, handler); - } - - @Override - public int insert(String statement) { - return this.sqlSessionProxy.insert(statement); - } - - @Override - public int insert(String statement, Object parameter) { - return this.sqlSessionProxy.insert(statement, parameter); - } - - @Override - public int update(String statement) { - return this.sqlSessionProxy.update(statement); - } - - @Override - public int update(String statement, Object parameter) { - return this.sqlSessionProxy.update(statement, parameter); - } - - @Override - public int delete(String statement) { - return this.sqlSessionProxy.delete(statement); - } - - @Override - public int delete(String statement, Object parameter) { - return this.sqlSessionProxy.delete(statement, parameter); - } - - @Override - public T getMapper(Class type) { - return this.getConfiguration().getMapper(type, this); - } - - @Override - public void commit() { - throw new UnsupportedOperationException("Manual commit is not allowed over a Solon managed SqlSession"); - } - - @Override - public void commit(boolean force) { - throw new UnsupportedOperationException("Manual commit is not allowed over a Solon managed SqlSession"); - } - - @Override - public void rollback() { - throw new UnsupportedOperationException("Manual rollback is not allowed over a Solon managed SqlSession"); - } - - @Override - public void rollback(boolean force) { - throw new UnsupportedOperationException("Manual rollback is not allowed over a Solon managed SqlSession"); - } - - @Override - public void close() { - throw new UnsupportedOperationException("Manual close is not allowed over a Solon managed SqlSession"); - } - - @Override - public void clearCache() { - this.sqlSessionProxy.clearCache(); - } - - @Override - public Configuration getConfiguration() { - return this.sqlSessionFactory.getConfiguration(); - } - - @Override - public Connection getConnection() { - return this.sqlSessionProxy.getConnection(); - } - - @Override - public List flushStatements() { - return this.sqlSessionProxy.flushStatements(); - } - - private class SqlSessionInterceptor implements InvocationHandler { - private SqlSessionInterceptor() { - } - - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - Object unwrapped; - try (SqlSession sqlSession = sqlSessionFactory.openSession(true)) { - Object result = method.invoke(sqlSession, args); - sqlSession.commit(!TranUtils.inTrans()); - unwrapped = result; - } catch (Throwable var11) { - unwrapped = ExceptionUtil.unwrapThrowable(var11); - if (unwrapped instanceof RuntimeException) { - throw (RuntimeException) unwrapped; - } - throw (Throwable) unwrapped; - } - return unwrapped; - } - } -} \ No newline at end of file diff --git a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/solon/integration/XPluginImpl.java b/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/solon/integration/XPluginImpl.java deleted file mode 100644 index 4ea409e80..000000000 --- a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/solon/integration/XPluginImpl.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.baomidou.mybatisplus.solon.integration; - -import com.baomidou.mybatisplus.core.toolkit.reflect.GenericTypeUtils; -import com.baomidou.mybatisplus.extension.compatible.CompatibleHelper; -import com.baomidou.mybatisplus.extension.compatible.SolonCompatibleSet; -import com.baomidou.mybatisplus.solon.integration.aot.MybatisPlusRuntimeNativeRegistrar; -import org.noear.solon.aot.RuntimeNativeRegistrar; -import org.noear.solon.core.AppContext; -import org.noear.solon.core.runtime.NativeDetector; -import org.noear.solon.core.util.ClassUtil; -import org.noear.solon.core.util.GenericUtil; -import org.apache.ibatis.solon.integration.MybatisAdapterManager; -import org.noear.solon.core.Plugin; - -/** - * @author noear - * @since 1.5 - */ -public class XPluginImpl implements Plugin { - - @Override - public void start(AppContext context) { - // - // 此插件的 solon.plugin.priority 会大于 mybatis-solon-plugin 的值 - // - MybatisAdapterManager.setAdapterFactory(new MybatisAdapterFactoryPlus()); - - // 注入兼容配置 - CompatibleHelper.setCompatibleSet(new SolonCompatibleSet()); - - // 提供反射处理类 - GenericTypeUtils.setGenericTypeResolver((GenericUtil::resolveTypeArguments)); - - // aot - if (NativeDetector.isAotRuntime() && ClassUtil.hasClass(() -> RuntimeNativeRegistrar.class)) { - context.wrapAndPut(MybatisPlusRuntimeNativeRegistrar.class); - } - } -} diff --git a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/solon/integration/aot/MybatisPlusRuntimeNativeRegistrar.java b/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/solon/integration/aot/MybatisPlusRuntimeNativeRegistrar.java deleted file mode 100644 index c1b040e08..000000000 --- a/mybatis-plus-solon-plugin/src/main/java/com/baomidou/mybatisplus/solon/integration/aot/MybatisPlusRuntimeNativeRegistrar.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.baomidou.mybatisplus.solon.integration.aot; - -import com.baomidou.mybatisplus.core.MybatisConfiguration; -import com.baomidou.mybatisplus.core.MybatisXMLLanguageDriver; -import com.baomidou.mybatisplus.core.conditions.AbstractLambdaWrapper; -import com.baomidou.mybatisplus.core.conditions.AbstractWrapper; -import com.baomidou.mybatisplus.core.conditions.ISqlSegment; -import com.baomidou.mybatisplus.core.conditions.Wrapper; -import com.baomidou.mybatisplus.core.conditions.interfaces.Compare; -import com.baomidou.mybatisplus.core.conditions.interfaces.Func; -import com.baomidou.mybatisplus.core.conditions.interfaces.Join; -import com.baomidou.mybatisplus.core.conditions.interfaces.Nested; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.conditions.query.Query; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.core.toolkit.support.SFunction; -import org.noear.solon.aot.RuntimeNativeMetadata; -import org.noear.solon.aot.RuntimeNativeRegistrar; -import org.noear.solon.aot.hint.ExecutableMode; -import org.noear.solon.aot.hint.MemberCategory; -import org.noear.solon.core.AppContext; - -import java.lang.invoke.SerializedLambda; - -/** - * mybatis-plus aot 注册 native 元数据 - * - * @author songyinyin - * @since 2.3 - */ -public class MybatisPlusRuntimeNativeRegistrar implements RuntimeNativeRegistrar { - - @Override - public void register(AppContext context, RuntimeNativeMetadata metadata) { - metadata.registerDefaultConstructor(MybatisXMLLanguageDriver.class); - metadata.registerReflection(MybatisConfiguration.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS); - metadata.registerAllDeclaredMethod(MybatisConfiguration.class, ExecutableMode.INVOKE); - - metadata.registerReflection(AbstractLambdaWrapper.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS); - - metadata.registerJdkProxy(AbstractWrapper.DoSomething.class); - metadata.registerReflection(AbstractWrapper.DoSomething.class); - metadata.registerReflection(AbstractWrapper.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS); - metadata.registerAllDeclaredMethod(AbstractWrapper.class, ExecutableMode.INVOKE); - - metadata.registerReflection(ISqlSegment.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS); - metadata.registerReflection(Wrapper.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS); - - metadata.registerAllDeclaredMethod(Wrapper.class, ExecutableMode.INVOKE); - - metadata.registerReflection(Compare.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS); - metadata.registerReflection(Func.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS); - metadata.registerReflection(Join.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS); - metadata.registerReflection(Nested.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS); - - metadata.registerReflection(LambdaQueryWrapper.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INTROSPECT_PUBLIC_METHODS, - MemberCategory.INTROSPECT_PUBLIC_METHODS, MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS); - metadata.registerAllDeclaredMethod(LambdaQueryWrapper.class, ExecutableMode.INVOKE); - - metadata.registerReflection(Query.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS); - - metadata.registerAllDeclaredMethod(BaseMapper.class, ExecutableMode.INVOKE); - - metadata.registerSerialization(SerializedLambda.class); - metadata.registerSerialization(SFunction.class); - } - -} diff --git a/mybatis-plus-solon-plugin/src/main/resources/META-INF/solon/mybatis-plus-solon-plugin.properties b/mybatis-plus-solon-plugin/src/main/resources/META-INF/solon/mybatis-plus-solon-plugin.properties deleted file mode 100644 index 660b0bb3e..000000000 --- a/mybatis-plus-solon-plugin/src/main/resources/META-INF/solon/mybatis-plus-solon-plugin.properties +++ /dev/null @@ -1,2 +0,0 @@ -solon.plugin=com.baomidou.mybatisplus.solon.integration.XPluginImpl -solon.plugin.priority=30 \ No newline at end of file diff --git a/mybatis-plus-solon-plugin/src/test/java/demo/Config.java b/mybatis-plus-solon-plugin/src/test/java/demo/Config.java deleted file mode 100644 index c3ed33dbd..000000000 --- a/mybatis-plus-solon-plugin/src/test/java/demo/Config.java +++ /dev/null @@ -1,34 +0,0 @@ -package demo; - -import com.baomidou.mybatisplus.core.MybatisConfiguration; -import com.baomidou.mybatisplus.core.MybatisSqlSessionFactoryBuilder; -import com.baomidou.mybatisplus.core.config.GlobalConfig; -import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; -import demo.dso.MetaObjectHandlerImpl; -import demo.dso.MybatisSqlSessionFactoryBuilderImpl; -import org.apache.ibatis.solon.annotation.Db; -import org.noear.solon.Solon; -import org.noear.solon.annotation.Bean; -import org.noear.solon.annotation.Configuration; -import org.noear.solon.annotation.Inject; - -import javax.sql.DataSource; - -@Configuration -public class Config { - @Bean - public void db1_cfg(@Db("db1") MybatisConfiguration cfg, - @Db("db1") GlobalConfig globalConfig) { - //增加 mybatis-plus 的自带分页插件 - MybatisPlusInterceptor plusInterceptor = new MybatisPlusInterceptor(); - plusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); - - cfg.addInterceptor(plusInterceptor); - } - -// @Bean -// public MybatisSqlSessionFactoryBuilder factoryBuilderNew(){ -// return new MybatisSqlSessionFactoryBuilderImpl(); -// } -} - diff --git a/mybatis-plus-solon-plugin/src/test/java/demo/DemoApp.java b/mybatis-plus-solon-plugin/src/test/java/demo/DemoApp.java deleted file mode 100644 index 3ce885e1f..000000000 --- a/mybatis-plus-solon-plugin/src/test/java/demo/DemoApp.java +++ /dev/null @@ -1,22 +0,0 @@ -package demo; - -import com.baomidou.mybatisplus.core.toolkit.Assert; -import demo.dso.service.UserService; -import demo.model.User; -import org.noear.solon.Solon; - -import java.util.List; - -/** - * @author noear 2021/7/12 created - */ -public class DemoApp { - public static void main(String[] args) { - Solon.start(DemoApp.class, args); - - //test - UserService userService = Solon.context().getBean(UserService.class); - - Assert.notNull(userService.getUserList(), "查询结果异常"); - } -} diff --git a/mybatis-plus-solon-plugin/src/test/java/demo/controller/IndexController.java b/mybatis-plus-solon-plugin/src/test/java/demo/controller/IndexController.java deleted file mode 100644 index d33137183..000000000 --- a/mybatis-plus-solon-plugin/src/test/java/demo/controller/IndexController.java +++ /dev/null @@ -1,21 +0,0 @@ -package demo.controller; - -import demo.dso.service.UserService; -import demo.model.User; -import org.noear.solon.annotation.Controller; -import org.noear.solon.annotation.Inject; -import org.noear.solon.annotation.Mapping; - -import java.util.List; - -@Controller -public class IndexController { - - @Inject - UserService userService; - - @Mapping("/") - public List index() { - return userService.getUserList(); - } -} diff --git a/mybatis-plus-solon-plugin/src/test/java/demo/dso/MetaObjectHandlerImpl.java b/mybatis-plus-solon-plugin/src/test/java/demo/dso/MetaObjectHandlerImpl.java deleted file mode 100644 index 3e7bc842f..000000000 --- a/mybatis-plus-solon-plugin/src/test/java/demo/dso/MetaObjectHandlerImpl.java +++ /dev/null @@ -1,19 +0,0 @@ -package demo.dso; - -import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; -import org.apache.ibatis.reflection.MetaObject; - -/** - * @author noear 2022/4/17 created - */ -public class MetaObjectHandlerImpl implements MetaObjectHandler { - @Override - public void insertFill(MetaObject metaObject) { - - } - - @Override - public void updateFill(MetaObject metaObject) { - - } -} diff --git a/mybatis-plus-solon-plugin/src/test/java/demo/dso/MybatisSqlSessionFactoryBuilderImpl.java b/mybatis-plus-solon-plugin/src/test/java/demo/dso/MybatisSqlSessionFactoryBuilderImpl.java deleted file mode 100644 index 184fc9a7d..000000000 --- a/mybatis-plus-solon-plugin/src/test/java/demo/dso/MybatisSqlSessionFactoryBuilderImpl.java +++ /dev/null @@ -1,9 +0,0 @@ -package demo.dso; - -import com.baomidou.mybatisplus.core.MybatisSqlSessionFactoryBuilder; - -/** - * @author noear 2021/10/20 created - */ -public class MybatisSqlSessionFactoryBuilderImpl extends MybatisSqlSessionFactoryBuilder { -} diff --git a/mybatis-plus-solon-plugin/src/test/java/demo/dso/mapper/UserMapper.java b/mybatis-plus-solon-plugin/src/test/java/demo/dso/mapper/UserMapper.java deleted file mode 100644 index 8986e2a94..000000000 --- a/mybatis-plus-solon-plugin/src/test/java/demo/dso/mapper/UserMapper.java +++ /dev/null @@ -1,10 +0,0 @@ -package demo.dso.mapper; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import demo.model.User; - -/** - * @author 颖 - */ -public interface UserMapper extends BaseMapper { -} \ No newline at end of file diff --git a/mybatis-plus-solon-plugin/src/test/java/demo/dso/service/UserService.java b/mybatis-plus-solon-plugin/src/test/java/demo/dso/service/UserService.java deleted file mode 100644 index 5724e23a9..000000000 --- a/mybatis-plus-solon-plugin/src/test/java/demo/dso/service/UserService.java +++ /dev/null @@ -1,24 +0,0 @@ -package demo.dso.service; - -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import demo.dso.mapper.UserMapper; -import demo.model.User; -import org.noear.solon.annotation.Component; -import org.noear.solon.annotation.Inject; - -import java.util.List; - -/** - * @author noear 2021/9/9 created - */ -@Component -public class UserService { - @Inject - UserMapper userMapper; - - public List getUserList() { - assert userMapper != null; - - return userMapper.selectList(new QueryWrapper<>()); - } -} diff --git a/mybatis-plus-solon-plugin/src/test/java/demo/model/User.java b/mybatis-plus-solon-plugin/src/test/java/demo/model/User.java deleted file mode 100644 index faff025da..000000000 --- a/mybatis-plus-solon-plugin/src/test/java/demo/model/User.java +++ /dev/null @@ -1,31 +0,0 @@ -package demo.model; - -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; - -/** - * @author iYarnFog - */ -@TableName(value = "users") -public class User { - @TableId(type = IdType.AUTO) - private Long id; - private String uuid; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getUuid() { - return uuid; - } - - public void setUuid(String uuid) { - this.uuid = uuid; - } -} diff --git a/mybatis-plus-solon-plugin/src/test/java/features/IGenericTypeResolverImplTest.java b/mybatis-plus-solon-plugin/src/test/java/features/IGenericTypeResolverImplTest.java deleted file mode 100644 index a2307e904..000000000 --- a/mybatis-plus-solon-plugin/src/test/java/features/IGenericTypeResolverImplTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package features; - - -import com.baomidou.mybatisplus.core.mapper.Mapper; -import demo.dso.mapper.UserMapper; -import org.junit.jupiter.api.Test; -import org.noear.solon.core.util.GenericUtil; - -import java.util.Arrays; -import java.util.Map; - -public class IGenericTypeResolverImplTest { - - - @Test - public void resolveTypeArguments() { - System.out.println(Arrays.toString(GenericUtil.resolveTypeArguments(DemoImpl.class, Map.class))); - System.out.println(Arrays.toString(GenericUtil.resolveTypeArguments(DemoImpl.class, Demo.class))); - - System.out.println(Arrays.toString(GenericUtil.resolveTypeArguments(UserMapper.class, Mapper.class))); - } - - private interface Demo {} - private abstract static class DemoImpl implements Map, IGenericTypeResolverImplTest.Demo { - - } -} \ No newline at end of file diff --git a/mybatis-plus-solon-plugin/src/test/resources/app.yml b/mybatis-plus-solon-plugin/src/test/resources/app.yml deleted file mode 100644 index 6d738e2fe..000000000 --- a/mybatis-plus-solon-plugin/src/test/resources/app.yml +++ /dev/null @@ -1,24 +0,0 @@ -server: - port: 6040 - -# 配置数据源 -solon.dataSources: - db1!: - class: "com.zaxxer.hikari.HikariDataSource" - jdbcUrl: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf8&autoReconnect=true&rewriteBatchedStatements=true - driverClassName: com.mysql.cj.jdbc.Driver - username: root - password: 1234 - -mybatis: - db1: - mappers: - - "demo.dso.mapper.*" - configuration: - cacheEnabled: false - mapUnderscoreToCamelCase: true - globalConfig: - banner: false - metaObjectHandler: "demo.dso.MetaObjectHandlerImpl" - dbConfig: - logicDeleteField: "deleted" diff --git a/settings.gradle b/settings.gradle index 93217ae1a..56ca7a6de 100644 --- a/settings.gradle +++ b/settings.gradle @@ -22,7 +22,6 @@ include 'mybatis-plus-extension' include 'mybatis-plus-generator' include 'mybatis-plus-bom' include 'mybatis-plus-spring' -include 'mybatis-plus-solon-plugin' include 'spring-boot-starter' include ':spring-boot-starter:mybatis-plus-boot-starter' include ':spring-boot-starter:mybatis-plus-boot-starter-test'