Skip to content

Commit 29dcb14

Browse files
committed
add id generator & remove leaf
1 parent 7e92e6d commit 29dcb14

File tree

41 files changed

+162
-1408
lines changed

Some content is hidden

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

41 files changed

+162
-1408
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,28 @@
1212
## maven install
1313

1414
```
15+
<!-- Springboot领域驱动框架 -->
1516
<dependency>
1617
<groupId>com.codingapi.springboot</groupId>
1718
<artifactId>springboot-starter</artifactId>
1819
<version>${last.version}</version>
1920
</dependency>
2021
22+
<!-- 快速数据呈现框架 -->
2123
<dependency>
2224
<groupId>com.codingapi.springboot</groupId>
23-
<artifactId>springboot-starter-leaf</artifactId>
25+
<artifactId>springboot-starter-data-fast</artifactId>
2426
<version>${last.version}</version>
2527
</dependency>
2628
29+
<!-- Id自增策略框架 -->
30+
<dependency>
31+
<groupId>com.codingapi.springboot</groupId>
32+
<artifactId>springboot-starter-id-generator</artifactId>
33+
<version>${last.version}</version>
34+
</dependency>
35+
36+
<!-- security&jwt权限框架 -->
2737
<dependency>
2838
<groupId>com.codingapi.springboot</groupId>
2939
<artifactId>springboot-starter-security-jwt</artifactId>

pom.xml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,6 @@
137137
<version>${codingapi.framework.version}</version>
138138
</dependency>
139139

140-
<dependency>
141-
<groupId>com.codingapi.springboot</groupId>
142-
<artifactId>springboot-starter-leaf</artifactId>
143-
<version>${codingapi.framework.version}</version>
144-
</dependency>
145-
146140
<dependency>
147141
<groupId>com.codingapi.springboot</groupId>
148142
<artifactId>springboot-starter-id-generator</artifactId>
@@ -222,7 +216,6 @@
222216
<module>springboot-starter</module>
223217
<module>springboot-example</module>
224218
<module>springboot-starter-security-jwt</module>
225-
<module>springboot-starter-leaf</module>
226219
<module>springboot-starter-data-fast</module>
227220
<module>springboot-starter-id-generator</module>
228221
</modules>
@@ -236,7 +229,6 @@
236229
<module>springboot-starter</module>
237230
<module>springboot-example</module>
238231
<module>springboot-starter-security-jwt</module>
239-
<module>springboot-starter-leaf</module>
240232
<module>springboot-starter-data-fast</module>
241233
<module>springboot-starter-id-generator</module>
242234
</modules>
@@ -284,7 +276,6 @@
284276
<modules>
285277
<module>springboot-starter</module>
286278
<module>springboot-starter-security-jwt</module>
287-
<module>springboot-starter-leaf</module>
288279
<module>springboot-starter-data-fast</module>
289280
<module>springboot-starter-id-generator</module>
290281
</modules>

springboot-example/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@
3636
<artifactId>springboot-starter-security-jwt</artifactId>
3737
</dependency>
3838

39-
<dependency>
40-
<groupId>com.codingapi.springboot</groupId>
41-
<artifactId>springboot-starter-leaf</artifactId>
42-
</dependency>
43-
4439
<dependency>
4540
<groupId>com.codingapi.springboot</groupId>
4641
<artifactId>springboot-starter-data-fast</artifactId>

springboot-example/src/main/java/com/codingapi/springboot/example/ExampleApplication.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.codingapi.springboot.example;
22

3-
import com.codingapi.springboot.leaf.EnableLeaf;
43
import org.springframework.boot.SpringApplication;
54
import org.springframework.boot.autoconfigure.SpringBootApplication;
65
import org.springframework.context.annotation.Bean;
@@ -10,7 +9,6 @@
109
import java.util.Locale;
1110

1211
@SpringBootApplication
13-
@EnableLeaf
1412
public class ExampleApplication {
1513

1614
public static void main(String[] args) {

springboot-example/src/main/java/com/codingapi/springboot/example/domain/entity/Demo.java

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

33
import com.codingapi.springboot.example.domain.event.DemoNameChangeEvent;
44
import com.codingapi.springboot.framework.event.EventPusher;
5-
import com.codingapi.springboot.leaf.LeafIdGenerate;
5+
import com.codingapi.springboot.generator.IdGenerate;
66
import lombok.Getter;
77

88
/**
99
* @author lorne
1010
* @since 1.0.0
1111
*/
12-
public class Demo implements LeafIdGenerate {
12+
public class Demo implements IdGenerate {
1313

1414
@Getter
1515
private Integer id;

springboot-example/src/main/java/com/codingapi/springboot/example/ui/controller/OpenController.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
import com.codingapi.springboot.framework.dto.request.PageRequest;
77
import com.codingapi.springboot.framework.dto.response.MultiResponse;
88
import com.codingapi.springboot.framework.dto.response.Response;
9-
import com.codingapi.springboot.generator.dao.IdGeneratorDao;
10-
import com.codingapi.springboot.generator.domain.IdGenerator;
9+
import com.codingapi.springboot.generator.dao.IdKeyDao;
10+
import com.codingapi.springboot.generator.domain.IdKey;
1111
import lombok.AllArgsConstructor;
1212
import org.springframework.web.bind.annotation.GetMapping;
1313
import org.springframework.web.bind.annotation.RequestMapping;
1414
import org.springframework.web.bind.annotation.RequestParam;
1515
import org.springframework.web.bind.annotation.RestController;
1616

1717
import java.sql.SQLException;
18-
import java.util.Date;
1918
import java.util.List;
2019

2120
@RestController
@@ -27,7 +26,7 @@ public class OpenController {
2726

2827
private final DemoEntityRepository demoEntityRepository;
2928

30-
private final IdGeneratorDao idGeneratorDao;
29+
private final IdKeyDao idKeyDao;
3130

3231
@GetMapping("/save")
3332
public Response save(@RequestParam("name") String name) {
@@ -43,17 +42,14 @@ public MultiResponse<DemoEntity> findAll(PageRequest pageRequest) {
4342

4443

4544
@GetMapping("/test-list")
46-
public List<IdGenerator> test1() throws SQLException{
47-
return idGeneratorDao.findAll();
45+
public List<IdKey> test1() throws SQLException{
46+
return idKeyDao.findAll();
4847
}
4948

5049
@GetMapping("/test-save")
5150
public Response test2() throws SQLException {
52-
IdGenerator generator = new IdGenerator();
53-
generator.setKey("xxxx");
54-
generator.setId(1L);
55-
generator.setUpdateTime(new Date());
56-
idGeneratorDao.save(generator);
51+
IdKey generator = new IdKey("xxx");
52+
idKeyDao.save(generator);
5753
return Response.buildSuccess();
5854
}
5955

springboot-example/src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ spring.datasource.url=jdbc:h2:file:./demo.db
44
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
55
spring.jpa.hibernate.ddl-auto=create-drop
66
spring.jpa.show-sql=true
7-
codingapi.leaf.jdbc-url=jdbc:h2:mem:leaf;DB_CLOSE_DELAY=-1
7+
codingapi.id.generator.jdbc-url=jdbc:h2:mem:generator;DB_CLOSE_DELAY=-1
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.codingapi.springboot.generator;
22

3-
import com.codingapi.springboot.generator.dao.IdGeneratorDao;
3+
import com.codingapi.springboot.generator.dao.IdKeyDao;
44
import com.codingapi.springboot.generator.properties.GeneratorProperties;
55
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
66
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -11,16 +11,17 @@
1111
public class AutoConfiguration {
1212

1313
@Bean
14-
@ConfigurationProperties(prefix = "codingapi.generator")
14+
@ConfigurationProperties(prefix = "codingapi.id.generator")
1515
public GeneratorProperties generatorProperties() {
1616
return new GeneratorProperties();
1717
}
1818

1919
@Bean(initMethod = "init")
2020
@ConditionalOnMissingBean
21-
public IdGeneratorDao idGeneratorDao(GeneratorProperties generatorProperties){
22-
return new IdGeneratorDao(generatorProperties.getJdbcUrl());
21+
public IdKeyDao idKeyDao(GeneratorProperties generatorProperties){
22+
IdKeyDao keyDao = new IdKeyDao(generatorProperties.getJdbcUrl());
23+
GeneratorContext.getInstance().init(keyDao);
24+
return keyDao;
2325
}
2426

25-
2627
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
11
package com.codingapi.springboot.generator;
22

3+
import com.codingapi.springboot.generator.dao.IdKeyDao;
4+
35
public class GeneratorContext {
46

7+
private GeneratorContext() {
8+
}
9+
10+
private static GeneratorContext instance;
11+
12+
public static GeneratorContext getInstance() {
13+
if (instance == null) {
14+
synchronized (GeneratorContext.class) {
15+
if (instance == null) {
16+
instance = new GeneratorContext();
17+
}
18+
}
19+
}
20+
return instance;
21+
}
22+
23+
private IdGenerateContext idGenerateContext;
24+
25+
long generateId(Class<?> clazz) {
26+
return idGenerateContext.generateId(clazz);
27+
}
28+
29+
void init(IdKeyDao idKeyDao){
30+
idGenerateContext = new IdGenerateContext(idKeyDao);
31+
}
532

633
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.codingapi.springboot.generator;
2+
3+
public interface IdGenerate {
4+
5+
default long generateLongId() {
6+
return GeneratorContext.getInstance().generateId(getClass());
7+
}
8+
9+
default int generateIntId() {
10+
return (int) GeneratorContext.getInstance().generateId(getClass());
11+
}
12+
13+
default String generateStringId() {
14+
return String.valueOf(GeneratorContext.getInstance().generateId(getClass()));
15+
}
16+
17+
}

0 commit comments

Comments
 (0)