Skip to content

Commit 5cb7fe4

Browse files
committed
refactor: 优化
1 parent ff9d4f7 commit 5cb7fe4

File tree

6 files changed

+51
-19
lines changed

6 files changed

+51
-19
lines changed

hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/Authentication.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package org.hswebframework.web.authorization;
1919

20-
import org.hswebframework.web.authorization.annotation.Logical;
2120
import org.springframework.util.StringUtils;
2221
import reactor.core.publisher.Mono;
2322

hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/simple/SimpleAuthentication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import lombok.Setter;
2222
import org.hswebframework.web.authorization.*;
2323

24+
import java.io.Serial;
2425
import java.io.Serializable;
2526
import java.util.*;
2627
import java.util.function.BiPredicate;
@@ -32,6 +33,7 @@
3233
@Setter
3334
public class SimpleAuthentication implements Authentication {
3435

36+
@Serial
3537
private static final long serialVersionUID = -2898863220255336528L;
3638

3739
private User user;

hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/configuration/AutoDDLProcessor.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.hswebframework.ezorm.rdb.operator.builder.fragments.ddl.CreateTableSqlBuilder;
1212
import org.hswebframework.web.api.crud.entity.EntityFactory;
1313
import org.hswebframework.web.crud.annotation.DDL;
14-
import org.hswebframework.web.crud.entity.factory.MapperEntityFactory;
1514
import org.hswebframework.web.crud.events.EntityDDLEvent;
1615
import org.hswebframework.web.event.GenericsPayloadApplicationEvent;
1716
import org.springframework.beans.factory.InitializingBean;
@@ -26,7 +25,6 @@
2625
import java.util.HashSet;
2726
import java.util.List;
2827
import java.util.Set;
29-
import java.util.stream.Collectors;
3028

3129
@Getter
3230
@Setter
@@ -86,9 +84,9 @@ public void afterPropertiesSet() {
8684
.autoLoad(false)
8785
.commit()
8886
.reactive()
89-
.subscribeOn(Schedulers.boundedElastic()),
90-
8,8)
91-
.doOnError((err) -> log.error(err.getMessage(), err))
87+
.subscribeOn(Schedulers.boundedElastic())
88+
.doOnError((err) -> log.error("execute ddl {} failed", meta.getName(), err)),
89+
8, 8)
9290
.then()
9391
.block(Duration.ofMinutes(5));
9492
} else {
@@ -121,7 +119,7 @@ public void afterPropertiesSet() {
121119
SqlRequest request = schema.findFeatureNow(CreateTableSqlBuilder.ID).build(metadata);
122120
log.info("DDL SQL for {} \n{}", entity, request.toNativeSql());
123121
schema.addTable(metadata);
124-
}else {
122+
} else {
125123
table.merge(metadata);
126124
}
127125

hsweb-core/src/main/java/org/hswebframework/web/bean/ClassDescription.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22

33
import lombok.Getter;
44
import org.hswebframework.web.dict.EnumDict;
5+
import org.springframework.util.ReflectionUtils;
56

67
import java.lang.reflect.Field;
7-
import java.util.Arrays;
8-
import java.util.Collection;
9-
import java.util.Map;
10-
import java.util.Set;
11-
import java.util.stream.Collectors;
8+
import java.util.*;
129

1310
@Getter
1411
public class ClassDescription {
@@ -26,20 +23,24 @@ public class ClassDescription {
2623

2724
public ClassDescription(Class<?> type) {
2825
this.type = type;
26+
2927
collectionType = Collection.class.isAssignableFrom(type);
3028
enumDict = EnumDict.class.isAssignableFrom(type);
3129
arrayType = type.isArray();
3230
enumType = type.isEnum();
33-
fieldSize = type.getDeclaredFields().length;
31+
3432
number = Number.class.isAssignableFrom(type);
3533
if (enumType) {
3634
enums = type.getEnumConstants();
3735
} else {
3836
enums = null;
3937
}
40-
fields = Arrays
41-
.stream(type.getDeclaredFields())
42-
.collect(Collectors.toMap(Field::getName, f -> f, (a, b) -> b));
38+
Map<String, Field> f = new HashMap<>();
39+
ReflectionUtils.doWithFields(type, field -> {
40+
f.put(field.getName(), field);
41+
});
42+
fields = Collections.unmodifiableMap(f);
43+
fieldSize = fields.size();
4344
}
4445

4546
}

hsweb-core/src/main/java/org/hswebframework/web/proxy/Proxy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class Proxy<I> extends URLClassLoader {
3131
@Getter
3232
private final String classFullName;
3333

34-
private final Set<ClassLoader> loaders = new HashSet<>();
34+
private final Set<ClassLoader> loaders = new LinkedHashSet<>();
3535
private Class<I> targetClass;
3636

3737
@SneakyThrows

hsweb-core/src/test/java/org/hswebframework/web/bean/FastBeanCopierTest.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public void testExtendableToExtendable() {
3838
Assert.assertEquals(source.getExtension("color"), e.getExtension("color"));
3939

4040
}
41+
4142
@Test
4243
public void testToExtendable() {
4344
Source source = new Source();
@@ -67,13 +68,14 @@ public void testFromExtendable() {
6768
Source source = new Source();
6869
ExtendableEntity e = FastBeanCopier.copy(source, new ExtendableEntity());
6970
e.setName("test");
70-
e.setExtension("age",123);
71+
e.setExtension("age", 123);
7172
FastBeanCopier.copy(e, source);
7273
Assert.assertEquals(e.getName(), source.getName());
7374
Assert.assertEquals(e.getExtension("age"), source.getAge());
7475

7576

7677
}
78+
7779
@Test
7880
public void testMapToExtendable() {
7981
Source source = new Source();
@@ -219,7 +221,7 @@ protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundE
219221
return clazz;
220222
}
221223
} catch (Throwable ignore) {
222-
// ignore.printStackTrace();
224+
//ignore.printStackTrace();
223225
}
224226
return super.loadClass(name, resolve);
225227
}
@@ -305,4 +307,34 @@ public interface ProxyTest {
305307
void setName(String name);
306308
}
307309

310+
@Test
311+
public void testExtendsExtendable() {
312+
ExtendableExtends ext = new ExtendableExtends();
313+
ext.setId("test");
314+
ext.setName("hehe");
315+
ext.setExtension("ext1", "haha");
316+
Map<String, Object> map = FastBeanCopier.copy(ext, new HashMap<>());
317+
Assert.assertNotNull(map.get("id"));
318+
Assert.assertNotNull(map.get("name"));
319+
Assert.assertNotNull(map.get("ext1"));
320+
321+
ExtendableExtends ext2 = FastBeanCopier.copy(map, new ExtendableExtends());
322+
Assert.assertEquals(ext.getId(),ext2.getId());
323+
Assert.assertEquals(ext.getName(),ext2.getName());
324+
Assert.assertEquals(ext.getExtensions(),ext2.getExtensions());
325+
326+
327+
}
328+
329+
@Getter
330+
@Setter
331+
public static class ExtendableSuper extends DefaultExtendable {
332+
private String id;
333+
}
334+
335+
@Getter
336+
@Setter
337+
public static class ExtendableExtends extends ExtendableSuper {
338+
private String name;
339+
}
308340
}

0 commit comments

Comments
 (0)