!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;
import org.noear.solon.core.BeanWrap;
import org.noear.solon.core.Props;
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-flex
* MyBatis-Flex 适配器工厂
*
* @author noear
* @since 2.2
*/
public class MybatisAdapterFactoryFlex implements MybatisAdapterFactory {
@Override
public MybatisAdapter create(BeanWrap dsWrap) {
return new MybatisAdapterFlex(dsWrap);
@ -21,4 +38,5 @@ public class MybatisAdapterFactoryFlex implements MybatisAdapterFactory {
public MybatisAdapter create(BeanWrap dsWrap, Props 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;
import com.mybatisflex.core.FlexGlobalConfig;
@ -17,15 +33,19 @@ import org.noear.solon.core.event.EventBus;
import javax.sql.DataSource;
/**
* 适配器 for mybatis-flex
* MyBatis-Flex 适配器
*
* @author noear
* @since 2.2
*/
public class MybatisAdapterFlex extends MybatisAdapterDefault {
FlexSqlSessionFactoryBuilder factoryBuilderPlus;
FlexGlobalConfig globalConfig;
RowMapperInvoker rowMapperInvoker;
protected MybatisAdapterFlex(BeanWrap dsWrap) {
super(dsWrap);
@ -107,25 +127,23 @@ public class MybatisAdapterFlex extends MybatisAdapterDefault {
return factory;
}
RowMapperInvoker rowMapperInvoker;
@Override
public void injectTo(VarHolder varH) {
super.injectTo(varH);
//@Db("db1") FlexGlobalConfig globalConfig;
// @Db("db1") FlexGlobalConfig globalConfig
if (FlexGlobalConfig.class.isAssignableFrom(varH.getType())) {
varH.setValue(this.getGlobalConfig());
return;
}
//@Db("db1") RowMapperInvoker rowMapper;
// @Db("db1") RowMapperInvoker rowMapper
if (RowMapperInvoker.class.equals(varH.getType())) {
if (rowMapperInvoker == null) {
rowMapperInvoker = new RowMapperInvoker(getFactory());
}
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;
import org.apache.ibatis.solon.integration.MybatisAdapterManager;
@ -5,15 +21,16 @@ import org.noear.solon.core.AopContext;
import org.noear.solon.core.Plugin;
/**
* 配置 MyBatis-Flex 插件
*
* @author noear
* @since 2.2
*/
public class XPluginImpl implements Plugin {
@Override
public void start(AopContext context) throws Throwable {
//
public void start(AopContext context) {
// 此插件的 solon.plugin.priority 会大于 mybatis-solon-plugin 的值
//
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).
* <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.
/*
* 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.service.impl;
@ -19,6 +19,12 @@ import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.service.IService;
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> {
@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.util.Iterator;
/**
* <p>判断是否有 MyBatis-Flex 的多数据源配置
*
* <p>如果配置文件中有 MyBatis-Flex 的多数据源配置就加载 MyBatis-Flex 多数据源自动配置类
*/
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Conditional(ConditionalOnMybatisFlexDatasource.OnMybatisFlexDataSourceCondition.class)

View File

@ -1,28 +1,33 @@
/**
* 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.
/*
* 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.boot;
import com.mybatisflex.core.mybatis.FlexConfiguration;
/**
* FlexConfiguration 做自定义的配置支持 {@link FlexConfiguration}
* {@link FlexConfiguration} 做自定义的配置支持
*/
@FunctionalInterface
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).
* <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.
/*
* 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.boot;
@ -26,16 +26,27 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.TransactionManagementConfigurer;
/**
* MyBatis-Flex 事务自动配置
*/
@ConditionalOnClass(Db.class)
@Configuration(proxyBeanMethods = false)
@AutoConfigureAfter({MybatisFlexAutoConfiguration.class})
@AutoConfigureBefore({TransactionAutoConfiguration.class})
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();
@Override
@Bean
@Override
public PlatformTransactionManager annotationDrivenTransactionManager() {
return flexTransactionManager;
}

View File

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

View File

@ -1,17 +1,17 @@
/**
* 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.
/*
* 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.boot;
@ -30,117 +30,117 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* 脚本语言驱动的自动配置平常一般项目用不到只为了同步 mybatis 自带的 MybatisLanguageDriverAutoConfiguration
* 脚本语言驱动的自动配置平常一般项目用不到只为了同步 MyBatis 自带的 MybatisLanguageDriverAutoConfiguration
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(LanguageDriver.class)
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(proxyBeanMethods = false)
@ConditionalOnClass(FreeMarkerLanguageDriver.class)
@ConditionalOnMissingClass("org.mybatis.scripting.freemarker.FreeMarkerLanguageDriverConfig")
public static class LegacyFreeMarkerConfiguration {
@Bean
@ConditionalOnMissingBean
FreeMarkerLanguageDriver 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);
/**
* Configuration class for mybatis-freemarker 1.1.x or under.
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(FreeMarkerLanguageDriver.class)
@ConditionalOnMissingClass("org.mybatis.scripting.freemarker.FreeMarkerLanguageDriverConfig")
public static class LegacyFreeMarkerConfiguration {
@Bean
@ConditionalOnMissingBean
FreeMarkerLanguageDriver freeMarkerLanguageDriver() {
return new FreeMarkerLanguageDriver();
}
}
@Bean
@ConditionalOnMissingBean
@ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".freemarker")
public FreeMarkerLanguageDriverConfig freeMarkerLanguageDriverConfig() {
return FreeMarkerLanguageDriverConfig.newInstance();
}
}
/**
* 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);
}
/**
* Configuration class for mybatis-velocity 2.0 or under.
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(org.mybatis.scripting.velocity.Driver.class)
@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
@ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".freemarker")
public FreeMarkerLanguageDriverConfig freeMarkerLanguageDriverConfig() {
return FreeMarkerLanguageDriverConfig.newInstance();
}
}
@Bean
@ConditionalOnMissingBean
@ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".velocity")
public VelocityLanguageDriverConfig velocityLanguageDriverConfig() {
return VelocityLanguageDriverConfig.newInstance();
}
}
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(ThymeleafLanguageDriver.class)
public static class ThymeleafConfiguration {
@Bean
@ConditionalOnMissingBean
ThymeleafLanguageDriver thymeleafLanguageDriver(ThymeleafLanguageDriverConfig config) {
return new ThymeleafLanguageDriver(config);
/**
* Configuration class for mybatis-velocity 2.0 or under.
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(org.mybatis.scripting.velocity.Driver.class)
@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();
}
}
@Bean
@ConditionalOnMissingBean
@ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".thymeleaf")
public ThymeleafLanguageDriverConfig thymeleafLanguageDriverConfig() {
return ThymeleafLanguageDriverConfig.newInstance();
/**
* 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
@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.
@SuppressWarnings("unused")
private static class MetadataThymeleafLanguageDriverConfig extends ThymeleafLanguageDriverConfig {
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(ThymeleafLanguageDriver.class)
public static class ThymeleafConfiguration {
@Bean
@ConditionalOnMissingBean
ThymeleafLanguageDriver thymeleafLanguageDriver(ThymeleafLanguageDriverConfig config) {
return new ThymeleafLanguageDriver(config);
}
@ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".thymeleaf.dialect")
@Override
public DialectConfig getDialect() {
return super.getDialect();
}
@Bean
@ConditionalOnMissingBean
@ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".thymeleaf")
public ThymeleafLanguageDriverConfig thymeleafLanguageDriverConfig() {
return ThymeleafLanguageDriverConfig.newInstance();
}
@ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".thymeleaf.template-file")
@Override
public TemplateFileConfig getTemplateFile() {
return super.getTemplateFile();
}
// This class provides to avoid the https://github.com/spring-projects/spring-boot/issues/21626 as workaround.
@SuppressWarnings("unused")
private static class MetadataThymeleafLanguageDriverConfig extends ThymeleafLanguageDriverConfig {
@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).
* <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.
/*
* 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.boot;
@ -31,59 +31,58 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Mybatis VFS 支持
* MyBatis VFS 支持
*/
public class SpringBootVFS extends VFS {
private static Charset urlDecodingCharset;
private final ResourcePatternResolver resourceResolver;
private static Charset urlDecodingCharset;
static {
setUrlDecodingCharset(Charset.defaultCharset());
}
public SpringBootVFS() {
this.resourceResolver = new PathMatchingResourcePatternResolver(getClass().getClassLoader());
}
@Override
public boolean isValid() {
return true;
}
@Override
protected List<String> list(URL url, String path) throws IOException {
String urlString = URLDecoder.decode(url.toString(), urlDecodingCharset.name());
String baseUrlString = urlString.endsWith("/") ? urlString : urlString.concat("/");
Resource[] resources = resourceResolver.getResources(baseUrlString + "**/*.class");
return Stream.of(resources).map(resource -> preserveSubpackageName(baseUrlString, resource, path))
.collect(Collectors.toList());
}
/**
* Set the charset for decoding an encoded URL string.
* <p>
* Default is system default charset.
* </p>
*
* @param charset
* the charset for decoding an encoded URL string
*
* @since 2.3.0
*/
public static void setUrlDecodingCharset(Charset charset) {
urlDecodingCharset = charset;
}
private static String preserveSubpackageName(final String baseUrlString, final Resource resource,
final String rootPath) {
try {
return rootPath + (rootPath.endsWith("/") ? "" : "/") + Normalizer
.normalize(URLDecoder.decode(resource.getURL().toString(), urlDecodingCharset.name()), Normalizer.Form.NFC)
.substring(baseUrlString.length());
} catch (IOException e) {
throw new UncheckedIOException(e);
static {
setUrlDecodingCharset(Charset.defaultCharset());
}
private final ResourcePatternResolver resourceResolver;
public SpringBootVFS() {
this.resourceResolver = new PathMatchingResourcePatternResolver(getClass().getClassLoader());
}
/**
* Set the charset for decoding an encoded URL string.
* <p>
* Default is system default charset.
* </p>
*
* @param charset the charset for decoding an encoded URL string
* @since 2.3.0
*/
public static void setUrlDecodingCharset(Charset charset) {
urlDecodingCharset = charset;
}
private static String preserveSubpackageName(final String baseUrlString, final Resource resource,
final String rootPath) {
try {
return rootPath + (rootPath.endsWith("/") ? "" : "/") + Normalizer
.normalize(URLDecoder.decode(resource.getURL().toString(), urlDecodingCharset.name()), Normalizer.Form.NFC)
.substring(baseUrlString.length());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
@Override
public boolean isValid() {
return true;
}
@Override
protected List<String> list(URL url, String path) throws IOException {
String urlString = URLDecoder.decode(url.toString(), urlDecodingCharset.name());
String baseUrlString = urlString.endsWith("/") ? urlString : urlString.concat("/");
Resource[] resources = resourceResolver.getResources(baseUrlString + "**/*.class");
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).
* <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.
/*
* 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.boot;
import org.mybatis.spring.SqlSessionFactoryBean;
/**
* FlexSqlSessionFactoryBean 做自定义的配置支持
* FlexSqlSessionFactoryBean 做自定义的配置支持
*
* @see com.mybatisflex.spring.FlexSqlSessionFactoryBean
*/
@FunctionalInterface
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).
* <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.
/*
* 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.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).
* <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.
/*
* 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;
@ -73,9 +73,11 @@ import static org.springframework.util.StringUtils.hasLength;
import static org.springframework.util.StringUtils.tokenizeToStringArray;
/**
* spring 在定义 SqlSessionFactoryBean 的时候需要替换为 FlexSqlSessionFactoryBean
* 源于 {@link SqlSessionFactoryBean}主要是用于构建 {@link com.mybatisflex.core.mybatis.FlexConfiguration }而不是使用原生的 Configuration
* 此代码主要是用于修改 {@link FlexSqlSessionFactoryBean#buildSqlSessionFactory()} 部分
* <p>Spring 在定义 SqlSessionFactoryBean 的时候需要替换为 FlexSqlSessionFactoryBean
*
* <p>源于 {@link SqlSessionFactoryBean}主要是用于构建 {@link com.mybatisflex.core.mybatis.FlexConfiguration }而不是使用原生的 {@link Configuration}
*
* <p>此代码主要是用于修改 {@link FlexSqlSessionFactoryBean#buildSqlSessionFactory()} 部分
*/
public class FlexSqlSessionFactoryBean extends SqlSessionFactoryBean
implements FactoryBean<SqlSessionFactory>, InitializingBean, ApplicationListener<ApplicationEvent> {

View File

@ -1,17 +1,17 @@
/**
* 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.
/*
* 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;
@ -23,6 +23,9 @@ import org.springframework.transaction.TransactionException;
import org.springframework.transaction.support.AbstractPlatformTransactionManager;
import org.springframework.transaction.support.DefaultTransactionStatus;
/**
* MyBatis-Flex 事务支持
*/
public class FlexTransactionManager extends AbstractPlatformTransactionManager {
@Override

View File

@ -36,6 +36,11 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public class DataSourceInterceptor implements MethodInterceptor {
/**
* 缓存方法对应的数据源
*/
private final Map<Object, String> dsCache = new ConcurrentHashMap<>();
@Override
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) {
Object cacheKey = new MethodClassKey(method, targetClass);
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;