Skip to content

Commit 23b1f44

Browse files
committed
fix schema
1 parent 28d4531 commit 23b1f44

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

springboot-starter-persistence/src/main/java/com/codingapi/springboot/persistence/property/SchemaProperty.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public SchemaProperty(Class<?> domainClazz) {
2626

2727

2828
public List<BeanProperty> getProperties(boolean hasId) {
29-
if(hasId){
29+
if (hasId) {
3030
return properties;
31-
}else{
31+
} else {
3232
return properties.stream()
3333
.filter(beanProperty -> !beanProperty.getName().equals("id"))
3434
.collect(Collectors.toList());
@@ -46,4 +46,13 @@ public boolean hasIdValue(Object domain) {
4646
public void setIdValue(Object domain, Number key) {
4747
idBeanProperty.setIdValue(domain, key);
4848
}
49+
50+
public boolean hasIdProperty() {
51+
for (BeanProperty property : properties) {
52+
if (property.getName().equals("id")) {
53+
return true;
54+
}
55+
}
56+
return false;
57+
}
4958
}

springboot-starter-persistence/src/main/java/com/codingapi/springboot/persistence/register/DomainClassRegister.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ private DomainClassRegister() {
1616
this.classes = new ArrayList<>();
1717
}
1818

19-
public void register(Class<?> domainClass) {
19+
public DomainClassRegister register(Class<?> domainClass) {
2020
this.classes.add(domainClass);
21+
return this;
22+
}
23+
24+
public void register(Class<?>... domainClasses) {
25+
this.classes.addAll(List.of(domainClasses));
2126
}
2227

2328
public boolean supports(Class<?> domainClass) {

springboot-starter-persistence/src/main/java/com/codingapi/springboot/persistence/schema/Schema.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@ public Schema(Class<?> domainClass) {
1717
log.info("Schema init:{}", domainClass);
1818
this.domainClass = domainClass;
1919
this.schemaProperty = new SchemaProperty(domainClass);
20+
this.check();
2021
}
2122

23+
public void check() {
24+
if (!this.schemaProperty.hasIdProperty()) {
25+
throw new RuntimeException("schema id property not found");
26+
}
27+
}
2228

2329
public abstract BuildSchema buildSchema();
2430

springboot-starter-persistence/src/test/java/com/example/demo/register/DomainRegister.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.example.demo.register;
22

3-
import com.example.demo.domain.Demo;
43
import com.codingapi.springboot.persistence.register.DomainClassRegister;
4+
import com.example.demo.domain.Demo;
55
import org.springframework.beans.factory.InitializingBean;
66
import org.springframework.stereotype.Component;
77

0 commit comments

Comments
 (0)