!97 optimize javadoc and code format

Merge pull request !97 from 王帅/main
This commit is contained in:
Michael Yang 2023-06-28 03:09:56 +00:00 committed by Gitee
commit dd45e14639
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
20 changed files with 492 additions and 297 deletions

View File

@ -1,17 +1,34 @@
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.solon.integration; package com.mybatisflex.solon.integration;
import org.noear.solon.core.BeanWrap;
import org.noear.solon.core.Props;
import org.apache.ibatis.solon.MybatisAdapter; import org.apache.ibatis.solon.MybatisAdapter;
import org.apache.ibatis.solon.MybatisAdapterFactory; import org.apache.ibatis.solon.MybatisAdapterFactory;
import org.noear.solon.core.BeanWrap;
import org.noear.solon.core.Props;
/** /**
* 适配器工厂 for mybatis-flex * MyBatis-Flex 适配器工厂
* *
* @author noear * @author noear
* @since 2.2 * @since 2.2
*/ */
public class MybatisAdapterFactoryFlex implements MybatisAdapterFactory { public class MybatisAdapterFactoryFlex implements MybatisAdapterFactory {
@Override @Override
public MybatisAdapter create(BeanWrap dsWrap) { public MybatisAdapter create(BeanWrap dsWrap) {
return new MybatisAdapterFlex(dsWrap); return new MybatisAdapterFlex(dsWrap);
@ -21,4 +38,5 @@ public class MybatisAdapterFactoryFlex implements MybatisAdapterFactory {
public MybatisAdapter create(BeanWrap dsWrap, Props dsProps) { public MybatisAdapter create(BeanWrap dsWrap, Props dsProps) {
return new MybatisAdapterFlex(dsWrap, dsProps); return new MybatisAdapterFlex(dsWrap, dsProps);
} }
} }

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.solon.integration; package com.mybatisflex.solon.integration;
import com.mybatisflex.core.FlexGlobalConfig; import com.mybatisflex.core.FlexGlobalConfig;
@ -17,15 +33,19 @@ import org.noear.solon.core.event.EventBus;
import javax.sql.DataSource; import javax.sql.DataSource;
/** /**
* 适配器 for mybatis-flex * MyBatis-Flex 适配器
* *
* @author noear * @author noear
* @since 2.2 * @since 2.2
*/ */
public class MybatisAdapterFlex extends MybatisAdapterDefault { public class MybatisAdapterFlex extends MybatisAdapterDefault {
FlexSqlSessionFactoryBuilder factoryBuilderPlus; FlexSqlSessionFactoryBuilder factoryBuilderPlus;
FlexGlobalConfig globalConfig; FlexGlobalConfig globalConfig;
RowMapperInvoker rowMapperInvoker;
protected MybatisAdapterFlex(BeanWrap dsWrap) { protected MybatisAdapterFlex(BeanWrap dsWrap) {
super(dsWrap); super(dsWrap);
@ -107,25 +127,23 @@ public class MybatisAdapterFlex extends MybatisAdapterDefault {
return factory; return factory;
} }
RowMapperInvoker rowMapperInvoker;
@Override @Override
public void injectTo(VarHolder varH) { public void injectTo(VarHolder varH) {
super.injectTo(varH); super.injectTo(varH);
//@Db("db1") FlexGlobalConfig globalConfig; // @Db("db1") FlexGlobalConfig globalConfig
if (FlexGlobalConfig.class.isAssignableFrom(varH.getType())) { if (FlexGlobalConfig.class.isAssignableFrom(varH.getType())) {
varH.setValue(this.getGlobalConfig()); varH.setValue(this.getGlobalConfig());
return; return;
} }
//@Db("db1") RowMapperInvoker rowMapper; // @Db("db1") RowMapperInvoker rowMapper
if (RowMapperInvoker.class.equals(varH.getType())) { if (RowMapperInvoker.class.equals(varH.getType())) {
if (rowMapperInvoker == null) { if (rowMapperInvoker == null) {
rowMapperInvoker = new RowMapperInvoker(getFactory()); rowMapperInvoker = new RowMapperInvoker(getFactory());
} }
varH.setValue(rowMapperInvoker); varH.setValue(rowMapperInvoker);
return;
} }
} }
} }

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.solon.integration; package com.mybatisflex.solon.integration;
import org.apache.ibatis.solon.integration.MybatisAdapterManager; import org.apache.ibatis.solon.integration.MybatisAdapterManager;
@ -5,15 +21,16 @@ import org.noear.solon.core.AopContext;
import org.noear.solon.core.Plugin; import org.noear.solon.core.Plugin;
/** /**
* 配置 MyBatis-Flex 插件
*
* @author noear * @author noear
* @since 2.2 * @since 2.2
*/ */
public class XPluginImpl implements Plugin { public class XPluginImpl implements Plugin {
@Override @Override
public void start(AopContext context) throws Throwable { public void start(AopContext context) {
//
// 此插件的 solon.plugin.priority 会大于 mybatis-solon-plugin 的值 // 此插件的 solon.plugin.priority 会大于 mybatis-solon-plugin 的值
//
MybatisAdapterManager.setAdapterFactory(new MybatisAdapterFactoryFlex()); MybatisAdapterManager.setAdapterFactory(new MybatisAdapterFactoryFlex());
} }

View File

@ -0,0 +1,20 @@
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.
*/
/**
* MyBatis-Flex Solon 支持
*/
package com.mybatisflex.solon.integration;

View File

@ -1,17 +1,17 @@
/** /*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p> * <p>
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* <p> * <p>
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* <p> * <p>
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.mybatisflex.solon.service.impl; package com.mybatisflex.solon.service.impl;
@ -19,6 +19,12 @@ import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.service.IService; import com.mybatisflex.core.service.IService;
import org.noear.solon.annotation.Inject; import org.noear.solon.annotation.Inject;
/**
* 默认 {@link IService} 实现类
*
* @param <M> Mapper 类型
* @param <T> Entity 类型
*/
public class ServiceImpl<M extends BaseMapper<T>, T> implements IService<T> { public class ServiceImpl<M extends BaseMapper<T>, T> implements IService<T> {
@Inject @Inject

View File

@ -0,0 +1,20 @@
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.
*/
/**
* IService 实现
*/
package com.mybatisflex.solon.service.impl;

View File

@ -30,7 +30,11 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import java.util.Iterator; import java.util.Iterator;
/**
* <p>判断是否有 MyBatis-Flex 的多数据源配置
*
* <p>如果配置文件中有 MyBatis-Flex 的多数据源配置就加载 MyBatis-Flex 多数据源自动配置类
*/
@Target({ElementType.TYPE, ElementType.METHOD}) @Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Conditional(ConditionalOnMybatisFlexDatasource.OnMybatisFlexDataSourceCondition.class) @Conditional(ConditionalOnMybatisFlexDatasource.OnMybatisFlexDataSourceCondition.class)

View File

@ -1,28 +1,33 @@
/** /*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p> * <p>
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* <p> * <p>
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* <p> * <p>
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.mybatisflex.spring.boot; package com.mybatisflex.spring.boot;
import com.mybatisflex.core.mybatis.FlexConfiguration; import com.mybatisflex.core.mybatis.FlexConfiguration;
/** /**
* FlexConfiguration 做自定义的配置支持 {@link FlexConfiguration} * {@link FlexConfiguration} 做自定义的配置支持
*/ */
@FunctionalInterface @FunctionalInterface
public interface ConfigurationCustomizer { public interface ConfigurationCustomizer {
void customize(FlexConfiguration configuration); /**
* 自定义配置 {@link FlexConfiguration}
*
* @param configuration MyBatis Flex Configuration
*/
void customize(FlexConfiguration configuration);
} }

View File

@ -1,17 +1,17 @@
/** /*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p> * <p>
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* <p> * <p>
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* <p> * <p>
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.mybatisflex.spring.boot; package com.mybatisflex.spring.boot;
@ -26,16 +26,27 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.TransactionManagementConfigurer; import org.springframework.transaction.annotation.TransactionManagementConfigurer;
/**
* MyBatis-Flex 事务自动配置
*/
@ConditionalOnClass(Db.class) @ConditionalOnClass(Db.class)
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@AutoConfigureAfter({MybatisFlexAutoConfiguration.class}) @AutoConfigureAfter({MybatisFlexAutoConfiguration.class})
@AutoConfigureBefore({TransactionAutoConfiguration.class}) @AutoConfigureBefore({TransactionAutoConfiguration.class})
public class FlexTransactionAutoConfiguration implements TransactionManagementConfigurer { public class FlexTransactionAutoConfiguration implements TransactionManagementConfigurer {
/**
* 这里使用 final 修饰属性是因为<br>
* <p>
* 1调用 {@link #annotationDrivenTransactionManager} 方法会返回 TransactionManager 对象<br>
* 2{@code @Bean} 注入又会返回 TransactionManager 对象<br>
* <p>
* 需要保证两个对象的一致性
*/
private final FlexTransactionManager flexTransactionManager = new FlexTransactionManager(); private final FlexTransactionManager flexTransactionManager = new FlexTransactionManager();
@Override
@Bean @Bean
@Override
public PlatformTransactionManager annotationDrivenTransactionManager() { public PlatformTransactionManager annotationDrivenTransactionManager() {
return flexTransactionManager; return flexTransactionManager;
} }

View File

@ -34,7 +34,7 @@ import java.util.Map;
/** /**
* 多数据源的配置支持 * MyBatis-Flex 多数据源的配置支持
*/ */
@ConditionalOnMybatisFlexDatasource() @ConditionalOnMybatisFlexDatasource()
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@ -50,7 +50,6 @@ public class MultiDataSourceAutoConfiguration {
dataSourceProperties = properties.getDatasource(); dataSourceProperties = properties.getDatasource();
} }
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public DataSource dataSource() { public DataSource dataSource() {
@ -71,6 +70,9 @@ public class MultiDataSourceAutoConfiguration {
return flexDataSource; return flexDataSource;
} }
/**
* {@link com.mybatisflex.annotation.UseDataSource} 注解切换数据源切面
*/
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public DataSourceAdvice dataSourceAdvice() { public DataSourceAdvice dataSourceAdvice() {

View File

@ -1,17 +1,17 @@
/** /*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p> * <p>
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* <p> * <p>
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* <p> * <p>
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.mybatisflex.spring.boot; package com.mybatisflex.spring.boot;
@ -30,117 +30,117 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
/** /**
* 脚本语言驱动的自动配置平常一般项目用不到只为了同步 mybatis 自带的 MybatisLanguageDriverAutoConfiguration * 脚本语言驱动的自动配置平常一般项目用不到只为了同步 MyBatis 自带的 MybatisLanguageDriverAutoConfiguration
*/ */
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@ConditionalOnClass(LanguageDriver.class) @ConditionalOnClass(LanguageDriver.class)
public class MybatisLanguageDriverAutoConfiguration { public class MybatisLanguageDriverAutoConfiguration {
private static final String CONFIGURATION_PROPERTY_PREFIX = "mybatis-flex.scripting-language-driver"; private static final String CONFIGURATION_PROPERTY_PREFIX = "mybatis-flex.scripting-language-driver";
/** /**
* Configuration class for mybatis-freemarker 1.1.x or under. * Configuration class for mybatis-freemarker 1.1.x or under.
*/ */
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@ConditionalOnClass(FreeMarkerLanguageDriver.class) @ConditionalOnClass(FreeMarkerLanguageDriver.class)
@ConditionalOnMissingClass("org.mybatis.scripting.freemarker.FreeMarkerLanguageDriverConfig") @ConditionalOnMissingClass("org.mybatis.scripting.freemarker.FreeMarkerLanguageDriverConfig")
public static class LegacyFreeMarkerConfiguration { public static class LegacyFreeMarkerConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
FreeMarkerLanguageDriver freeMarkerLanguageDriver() { FreeMarkerLanguageDriver freeMarkerLanguageDriver() {
return new FreeMarkerLanguageDriver(); return new FreeMarkerLanguageDriver();
} }
}
/**
* Configuration class for mybatis-freemarker 1.2.x or above.
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ FreeMarkerLanguageDriver.class, FreeMarkerLanguageDriverConfig.class })
public static class FreeMarkerConfiguration {
@Bean
@ConditionalOnMissingBean
FreeMarkerLanguageDriver freeMarkerLanguageDriver(FreeMarkerLanguageDriverConfig config) {
return new FreeMarkerLanguageDriver(config);
} }
@Bean /**
@ConditionalOnMissingBean * Configuration class for mybatis-freemarker 1.2.x or above.
@ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".freemarker") */
public FreeMarkerLanguageDriverConfig freeMarkerLanguageDriverConfig() { @Configuration(proxyBeanMethods = false)
return FreeMarkerLanguageDriverConfig.newInstance(); @ConditionalOnClass({FreeMarkerLanguageDriver.class, FreeMarkerLanguageDriverConfig.class})
} public static class FreeMarkerConfiguration {
} @Bean
@ConditionalOnMissingBean
FreeMarkerLanguageDriver freeMarkerLanguageDriver(FreeMarkerLanguageDriverConfig config) {
return new FreeMarkerLanguageDriver(config);
}
/** @Bean
* Configuration class for mybatis-velocity 2.0 or under. @ConditionalOnMissingBean
*/ @ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".freemarker")
@Configuration(proxyBeanMethods = false) public FreeMarkerLanguageDriverConfig freeMarkerLanguageDriverConfig() {
@ConditionalOnClass(org.mybatis.scripting.velocity.Driver.class) return FreeMarkerLanguageDriverConfig.newInstance();
@ConditionalOnMissingClass("org.mybatis.scripting.velocity.VelocityLanguageDriverConfig") }
@SuppressWarnings("deprecation")
public static class LegacyVelocityConfiguration {
@Bean
@ConditionalOnMissingBean
org.mybatis.scripting.velocity.Driver velocityLanguageDriver() {
return new org.mybatis.scripting.velocity.Driver();
}
}
/**
* Configuration class for mybatis-velocity 2.1.x or above.
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ VelocityLanguageDriver.class, VelocityLanguageDriverConfig.class })
public static class VelocityConfiguration {
@Bean
@ConditionalOnMissingBean
VelocityLanguageDriver velocityLanguageDriver(VelocityLanguageDriverConfig config) {
return new VelocityLanguageDriver(config);
} }
@Bean /**
@ConditionalOnMissingBean * Configuration class for mybatis-velocity 2.0 or under.
@ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".velocity") */
public VelocityLanguageDriverConfig velocityLanguageDriverConfig() { @Configuration(proxyBeanMethods = false)
return VelocityLanguageDriverConfig.newInstance(); @ConditionalOnClass(org.mybatis.scripting.velocity.Driver.class)
} @ConditionalOnMissingClass("org.mybatis.scripting.velocity.VelocityLanguageDriverConfig")
} @SuppressWarnings("deprecation")
public static class LegacyVelocityConfiguration {
@Configuration(proxyBeanMethods = false) @Bean
@ConditionalOnClass(ThymeleafLanguageDriver.class) @ConditionalOnMissingBean
public static class ThymeleafConfiguration { org.mybatis.scripting.velocity.Driver velocityLanguageDriver() {
@Bean return new org.mybatis.scripting.velocity.Driver();
@ConditionalOnMissingBean }
ThymeleafLanguageDriver thymeleafLanguageDriver(ThymeleafLanguageDriverConfig config) {
return new ThymeleafLanguageDriver(config);
} }
@Bean /**
@ConditionalOnMissingBean * Configuration class for mybatis-velocity 2.1.x or above.
@ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".thymeleaf") */
public ThymeleafLanguageDriverConfig thymeleafLanguageDriverConfig() { @Configuration(proxyBeanMethods = false)
return ThymeleafLanguageDriverConfig.newInstance(); @ConditionalOnClass({VelocityLanguageDriver.class, VelocityLanguageDriverConfig.class})
public static class VelocityConfiguration {
@Bean
@ConditionalOnMissingBean
VelocityLanguageDriver velocityLanguageDriver(VelocityLanguageDriverConfig config) {
return new VelocityLanguageDriver(config);
}
@Bean
@ConditionalOnMissingBean
@ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".velocity")
public VelocityLanguageDriverConfig velocityLanguageDriverConfig() {
return VelocityLanguageDriverConfig.newInstance();
}
} }
// This class provides to avoid the https://github.com/spring-projects/spring-boot/issues/21626 as workaround. @Configuration(proxyBeanMethods = false)
@SuppressWarnings("unused") @ConditionalOnClass(ThymeleafLanguageDriver.class)
private static class MetadataThymeleafLanguageDriverConfig extends ThymeleafLanguageDriverConfig { public static class ThymeleafConfiguration {
@Bean
@ConditionalOnMissingBean
ThymeleafLanguageDriver thymeleafLanguageDriver(ThymeleafLanguageDriverConfig config) {
return new ThymeleafLanguageDriver(config);
}
@ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".thymeleaf.dialect") @Bean
@Override @ConditionalOnMissingBean
public DialectConfig getDialect() { @ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".thymeleaf")
return super.getDialect(); public ThymeleafLanguageDriverConfig thymeleafLanguageDriverConfig() {
} return ThymeleafLanguageDriverConfig.newInstance();
}
@ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".thymeleaf.template-file") // This class provides to avoid the https://github.com/spring-projects/spring-boot/issues/21626 as workaround.
@Override @SuppressWarnings("unused")
public TemplateFileConfig getTemplateFile() { private static class MetadataThymeleafLanguageDriverConfig extends ThymeleafLanguageDriverConfig {
return super.getTemplateFile();
} @ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".thymeleaf.dialect")
@Override
public DialectConfig getDialect() {
return super.getDialect();
}
@ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".thymeleaf.template-file")
@Override
public TemplateFileConfig getTemplateFile() {
return super.getTemplateFile();
}
}
} }
}
} }

View File

@ -1,17 +1,17 @@
/** /*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p> * <p>
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* <p> * <p>
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* <p> * <p>
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.mybatisflex.spring.boot; package com.mybatisflex.spring.boot;
@ -31,59 +31,58 @@ import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
/** /**
* Mybatis VFS 支持 * MyBatis VFS 支持
*/ */
public class SpringBootVFS extends VFS { public class SpringBootVFS extends VFS {
private static Charset urlDecodingCharset; private static Charset urlDecodingCharset;
private final ResourcePatternResolver resourceResolver;
static { static {
setUrlDecodingCharset(Charset.defaultCharset()); setUrlDecodingCharset(Charset.defaultCharset());
} }
public SpringBootVFS() { private final ResourcePatternResolver resourceResolver;
this.resourceResolver = new PathMatchingResourcePatternResolver(getClass().getClassLoader());
} public SpringBootVFS() {
this.resourceResolver = new PathMatchingResourcePatternResolver(getClass().getClassLoader());
@Override }
public boolean isValid() {
return true; /**
} * Set the charset for decoding an encoded URL string.
* <p>
@Override * Default is system default charset.
protected List<String> list(URL url, String path) throws IOException { * </p>
String urlString = URLDecoder.decode(url.toString(), urlDecodingCharset.name()); *
String baseUrlString = urlString.endsWith("/") ? urlString : urlString.concat("/"); * @param charset the charset for decoding an encoded URL string
Resource[] resources = resourceResolver.getResources(baseUrlString + "**/*.class"); * @since 2.3.0
return Stream.of(resources).map(resource -> preserveSubpackageName(baseUrlString, resource, path)) */
.collect(Collectors.toList()); public static void setUrlDecodingCharset(Charset charset) {
} urlDecodingCharset = charset;
}
/**
* Set the charset for decoding an encoded URL string. private static String preserveSubpackageName(final String baseUrlString, final Resource resource,
* <p> final String rootPath) {
* Default is system default charset. try {
* </p> return rootPath + (rootPath.endsWith("/") ? "" : "/") + Normalizer
* .normalize(URLDecoder.decode(resource.getURL().toString(), urlDecodingCharset.name()), Normalizer.Form.NFC)
* @param charset .substring(baseUrlString.length());
* the charset for decoding an encoded URL string } catch (IOException e) {
* throw new UncheckedIOException(e);
* @since 2.3.0 }
*/ }
public static void setUrlDecodingCharset(Charset charset) {
urlDecodingCharset = charset; @Override
} public boolean isValid() {
return true;
private static String preserveSubpackageName(final String baseUrlString, final Resource resource, }
final String rootPath) {
try { @Override
return rootPath + (rootPath.endsWith("/") ? "" : "/") + Normalizer protected List<String> list(URL url, String path) throws IOException {
.normalize(URLDecoder.decode(resource.getURL().toString(), urlDecodingCharset.name()), Normalizer.Form.NFC) String urlString = URLDecoder.decode(url.toString(), urlDecodingCharset.name());
.substring(baseUrlString.length()); String baseUrlString = urlString.endsWith("/") ? urlString : urlString.concat("/");
} catch (IOException e) { Resource[] resources = resourceResolver.getResources(baseUrlString + "**/*.class");
throw new UncheckedIOException(e); return Stream.of(resources).map(resource -> preserveSubpackageName(baseUrlString, resource, path))
.collect(Collectors.toList());
} }
}
} }

View File

@ -1,29 +1,35 @@
/** /*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p> * <p>
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* <p> * <p>
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* <p> * <p>
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.mybatisflex.spring.boot; package com.mybatisflex.spring.boot;
import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.SqlSessionFactoryBean;
/** /**
* FlexSqlSessionFactoryBean 做自定义的配置支持 * FlexSqlSessionFactoryBean 做自定义的配置支持
*
* @see com.mybatisflex.spring.FlexSqlSessionFactoryBean * @see com.mybatisflex.spring.FlexSqlSessionFactoryBean
*/ */
@FunctionalInterface @FunctionalInterface
public interface SqlSessionFactoryBeanCustomizer { public interface SqlSessionFactoryBeanCustomizer {
void customize(SqlSessionFactoryBean factoryBean); /**
* 自定义 {@link SqlSessionFactoryBean}
*
* @param factoryBean FlexSqlSessionFactoryBean
*/
void customize(SqlSessionFactoryBean factoryBean);
} }

View File

@ -1,16 +1,20 @@
/** /*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p> * <p>
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* <p> * <p>
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* <p> * <p>
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.mybatisflex.spring.boot;
/**
* MyBatis-Flex Spring Boot 支持
*/
package com.mybatisflex.spring.boot;

View File

@ -1,17 +1,17 @@
/** /*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p> * <p>
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* <p> * <p>
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* <p> * <p>
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.mybatisflex.spring; package com.mybatisflex.spring;
@ -73,9 +73,11 @@ import static org.springframework.util.StringUtils.hasLength;
import static org.springframework.util.StringUtils.tokenizeToStringArray; import static org.springframework.util.StringUtils.tokenizeToStringArray;
/** /**
* spring 在定义 SqlSessionFactoryBean 的时候需要替换为 FlexSqlSessionFactoryBean * <p>Spring 在定义 SqlSessionFactoryBean 的时候需要替换为 FlexSqlSessionFactoryBean
* 源于 {@link SqlSessionFactoryBean}主要是用于构建 {@link com.mybatisflex.core.mybatis.FlexConfiguration }而不是使用原生的 Configuration *
* 此代码主要是用于修改 {@link FlexSqlSessionFactoryBean#buildSqlSessionFactory()} 部分 * <p>源于 {@link SqlSessionFactoryBean}主要是用于构建 {@link com.mybatisflex.core.mybatis.FlexConfiguration }而不是使用原生的 {@link Configuration}
*
* <p>此代码主要是用于修改 {@link FlexSqlSessionFactoryBean#buildSqlSessionFactory()} 部分
*/ */
public class FlexSqlSessionFactoryBean extends SqlSessionFactoryBean public class FlexSqlSessionFactoryBean extends SqlSessionFactoryBean
implements FactoryBean<SqlSessionFactory>, InitializingBean, ApplicationListener<ApplicationEvent> { implements FactoryBean<SqlSessionFactory>, InitializingBean, ApplicationListener<ApplicationEvent> {

View File

@ -1,17 +1,17 @@
/** /*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p> * <p>
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* <p> * <p>
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* <p> * <p>
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.mybatisflex.spring; package com.mybatisflex.spring;
@ -23,6 +23,9 @@ import org.springframework.transaction.TransactionException;
import org.springframework.transaction.support.AbstractPlatformTransactionManager; import org.springframework.transaction.support.AbstractPlatformTransactionManager;
import org.springframework.transaction.support.DefaultTransactionStatus; import org.springframework.transaction.support.DefaultTransactionStatus;
/**
* MyBatis-Flex 事务支持
*/
public class FlexTransactionManager extends AbstractPlatformTransactionManager { public class FlexTransactionManager extends AbstractPlatformTransactionManager {
@Override @Override

View File

@ -36,6 +36,11 @@ import java.util.concurrent.ConcurrentHashMap;
*/ */
public class DataSourceInterceptor implements MethodInterceptor { public class DataSourceInterceptor implements MethodInterceptor {
/**
* 缓存方法对应的数据源
*/
private final Map<Object, String> dsCache = new ConcurrentHashMap<>();
@Override @Override
public Object invoke(MethodInvocation invocation) throws Throwable { public Object invoke(MethodInvocation invocation) throws Throwable {
@ -57,11 +62,6 @@ public class DataSourceInterceptor implements MethodInterceptor {
} }
} }
/**
* 缓存方法对应的数据源
*/
private final Map<Object, String> dsCache = new ConcurrentHashMap<>();
private String findDataSourceKey(Method method, Class<?> targetClass) { private String findDataSourceKey(Method method, Class<?> targetClass) {
Object cacheKey = new MethodClassKey(method, targetClass); Object cacheKey = new MethodClassKey(method, targetClass);
String dsKey = this.dsCache.get(cacheKey); String dsKey = this.dsCache.get(cacheKey);

View File

@ -0,0 +1,20 @@
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.spring.datasource;

View File

@ -0,0 +1,20 @@
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.
*/
/**
* MyBatis-Flex Spring 支持
*/
package com.mybatisflex.spring;

View File

@ -0,0 +1,20 @@
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.
*/
/**
* IService 实现
*/
package com.mybatisflex.spring.service.impl;