Skip to content

Commit b3648bc

Browse files
authored
Merge pull request #5 from zhongxunking/develop
1.3.0.RELEASE
2 parents d521a16 + ba48786 commit b3648bc

125 files changed

Lines changed: 2919 additions & 2978 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 12 additions & 411 deletions
Large diffs are not rendered by default.

common/pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.bekit</groupId>
88
<artifactId>bekit</artifactId>
9-
<version>1.2.5.RELEASE</version>
9+
<version>1.3.0.RELEASE</version>
1010
</parent>
1111

1212
<artifactId>common</artifactId>
@@ -21,6 +21,12 @@
2121
<groupId>org.slf4j</groupId>
2222
<artifactId>slf4j-api</artifactId>
2323
</dependency>
24+
<dependency>
25+
<groupId>org.springframework.boot</groupId>
26+
<artifactId>spring-boot-autoconfigure</artifactId>
27+
<scope>provided</scope>
28+
<optional>true</optional>
29+
</dependency>
2430
<dependency>
2531
<groupId>org.springframework</groupId>
2632
<artifactId>spring-tx</artifactId>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* 作者:钟勋 (e-mail:zhongxunking@163.com)
3+
*/
4+
5+
/*
6+
* 修订记录:
7+
* @author 钟勋 2019-12-02 20:37 创建
8+
*/
9+
package org.bekit.common.boot;
10+
11+
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
12+
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
13+
import org.springframework.context.annotation.Configuration;
14+
import org.springframework.context.annotation.Import;
15+
16+
/**
17+
* 公共自动配置
18+
*/
19+
@Configuration
20+
@AutoConfigureAfter(TransactionAutoConfiguration.class)
21+
@Import(CommonConfiguration.class)
22+
public class CommonAutoConfiguration {
23+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* 作者:钟勋 (e-mail:zhongxunking@163.com)
3+
*/
4+
5+
/*
6+
* 修订记录:
7+
* @author 钟勋 2019-12-02 20:37 创建
8+
*/
9+
package org.bekit.common.boot;
10+
11+
import org.bekit.common.transaction.TransactionManager;
12+
import org.bekit.common.transaction.support.EmptyTransactionManager;
13+
import org.bekit.common.transaction.support.SpringTransactionManager;
14+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
15+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
16+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
17+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
18+
import org.springframework.context.annotation.Configuration;
19+
import org.springframework.context.annotation.Import;
20+
import org.springframework.transaction.PlatformTransactionManager;
21+
22+
/**
23+
* 公共配置
24+
*/
25+
@Configuration
26+
public class CommonConfiguration {
27+
/**
28+
* 事务配置
29+
*/
30+
@Configuration
31+
@ConditionalOnMissingBean(TransactionManager.class)
32+
public static class TransactionManagerConfiguration {
33+
/**
34+
* PlatformTransactionManager存在
35+
*/
36+
@Configuration
37+
@ConditionalOnClass(PlatformTransactionManager.class)
38+
public static class PlatformTransactionManagerClassExists {
39+
/**
40+
* Spring事务管理器配置
41+
*/
42+
@Configuration
43+
@ConditionalOnBean(PlatformTransactionManager.class)
44+
@Import(SpringTransactionManager.class)
45+
public static class SpringTransactionManagerConfiguration {
46+
}
47+
48+
/**
49+
* 空事务管理器配置
50+
*/
51+
@Configuration
52+
@ConditionalOnMissingBean(PlatformTransactionManager.class)
53+
@Import(EmptyTransactionManager.class)
54+
public static class EmptyTransactionManagerConfiguration {
55+
}
56+
}
57+
58+
/**
59+
* PlatformTransactionManager不存在
60+
*/
61+
@Configuration
62+
@ConditionalOnMissingClass("org.springframework.transaction.PlatformTransactionManager")
63+
@Import(EmptyTransactionManager.class)
64+
public static class PlatformTransactionManagerClassNotExists {
65+
}
66+
}
67+
}

common/src/main/java/org/bekit/common/method/MethodExecutor.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,49 @@
88
*/
99
package org.bekit.common.method;
1010

11+
import lombok.AllArgsConstructor;
12+
import lombok.Getter;
13+
1114
import java.lang.reflect.InvocationTargetException;
1215
import java.lang.reflect.Method;
1316

1417
/**
1518
* 方法执行器
1619
*/
20+
@AllArgsConstructor
21+
@Getter
1722
public abstract class MethodExecutor {
18-
// 目标方法
19-
private final Method targetMethod;
20-
21-
public MethodExecutor(Method targetMethod) {
22-
this.targetMethod = targetMethod;
23-
}
23+
// 方法
24+
private final Method method;
2425

2526
/**
2627
* 执行方法
2728
*
2829
* @param obj 被执行的对象
2930
* @param args 需传入目标方法的参数
30-
* @return 目标方法返回的结果
31+
* @return 方法返回的结果
3132
* @throws Throwable 执行过程中发生任何异常都会往外抛
3233
*/
3334
protected Object execute(Object obj, Object[] args) throws Throwable {
3435
try {
35-
return targetMethod.invoke(obj, args);
36+
return method.invoke(obj, args);
3637
} catch (InvocationTargetException e) {
3738
// 抛出原始异常
3839
throw e.getTargetException();
3940
}
4041
}
4142

4243
/**
43-
* 获取目标方法入参类型
44+
* 获取方法入参类型
4445
*/
45-
public Class[] getParameterTypes() {
46-
return targetMethod.getParameterTypes();
46+
public Class<?>[] getParameterTypes() {
47+
return method.getParameterTypes();
4748
}
4849

4950
/**
50-
* 获取目标方法返回类型
51+
* 获取方法返回类型
5152
*/
52-
public Class getReturnType() {
53-
return targetMethod.getReturnType();
53+
public Class<?> getReturnType() {
54+
return method.getReturnType();
5455
}
5556
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* 作者:钟勋 (e-mail:zhongxunking@163.com)
3+
*/
4+
5+
/*
6+
* 修订记录:
7+
* @author 钟勋 2016-12-19 01:26 创建
8+
*/
9+
package org.bekit.common.registrar;
10+
11+
import lombok.AllArgsConstructor;
12+
13+
import java.util.Collections;
14+
import java.util.Map;
15+
import java.util.Set;
16+
import java.util.concurrent.ConcurrentHashMap;
17+
import java.util.function.Function;
18+
19+
/**
20+
* 抽象注册器
21+
*/
22+
@AllArgsConstructor
23+
public abstract class AbstractRegistrar<N, E> {
24+
// 元素集
25+
private final Map<N, E> elementMap = new ConcurrentHashMap<>();
26+
// 名称提取器
27+
private final Function<E, N> nameExtractor;
28+
29+
/**
30+
* 注册元素
31+
*
32+
* @param element 被注册的元素
33+
* @return 被替换的元素
34+
*/
35+
public E register(E element) {
36+
return elementMap.put(nameExtractor.apply(element), element);
37+
}
38+
39+
/**
40+
* 获取所有元素的名称
41+
*
42+
* @return 所有所有元素的名称
43+
*/
44+
public Set<N> getNames() {
45+
return Collections.unmodifiableSet(elementMap.keySet());
46+
}
47+
48+
/**
49+
* 获取元素
50+
*
51+
* @param name 元素名称
52+
* @return 元素
53+
*/
54+
public E get(N name) {
55+
return elementMap.get(name);
56+
}
57+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* 作者:钟勋 (e-mail:zhongxunking@163.com)
3+
*/
4+
5+
/*
6+
* 修订记录:
7+
* @author 钟勋 2019-12-24 22:23 创建
8+
*/
9+
package org.bekit.common.scanner;
10+
11+
import lombok.AllArgsConstructor;
12+
import org.springframework.context.ApplicationListener;
13+
import org.springframework.context.event.ContextRefreshedEvent;
14+
15+
import java.lang.annotation.Annotation;
16+
17+
/**
18+
* 抽象扫描器
19+
*/
20+
@AllArgsConstructor
21+
public abstract class AbstractScanner implements ApplicationListener<ContextRefreshedEvent> {
22+
// 需扫描的注解类型
23+
private final Class<? extends Annotation> annotationType;
24+
25+
@Override
26+
public void onApplicationEvent(ContextRefreshedEvent event) {
27+
// 扫描
28+
String[] beanNames = event.getApplicationContext().getBeanNamesForAnnotation(annotationType);
29+
for (String beanName : beanNames) {
30+
onScan(event.getApplicationContext().getBean(beanName));
31+
}
32+
}
33+
34+
/**
35+
* 扫描模版方法
36+
*
37+
* @param obj 扫描到的对象
38+
*/
39+
protected abstract void onScan(Object obj);
40+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* 作者:钟勋 (e-mail:zhongxunking@163.com)
3+
*/
4+
5+
/*
6+
* 修订记录:
7+
* @author 钟勋 2019-12-01 22:02 创建
8+
*/
9+
package org.bekit.common.transaction;
10+
11+
/**
12+
* 事务管理器
13+
*/
14+
public interface TransactionManager {
15+
/**
16+
* 获取事务
17+
*
18+
* @param type 事务类型
19+
* @return 事务状态(非null)
20+
*/
21+
Object getTransaction(TransactionType type);
22+
23+
/**
24+
* 提交
25+
*
26+
* @param status 事务状态
27+
*/
28+
void commit(Object status);
29+
30+
/**
31+
* 回滚
32+
*
33+
* @param status 事务状态
34+
*/
35+
void rollback(Object status);
36+
37+
/**
38+
* 事务类型
39+
*/
40+
enum TransactionType {
41+
// 融合事务(如果已存在事务,则使用已存在事务;否则创建新事务)
42+
REQUIRED,
43+
// 新事务(不管是否已存在事务,都创建新事务)
44+
REQUIRES_NEW,
45+
// 无事务(如果已存在事务,则挂起已存在事务;否则不做处理)
46+
NOT_SUPPORTED
47+
}
48+
}

0 commit comments

Comments
 (0)