Skip to content

Commit d0cc75d

Browse files
committed
code format
1 parent 6e5067c commit d0cc75d

File tree

25 files changed

+104
-119
lines changed

25 files changed

+104
-119
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55
<packaging>pom</packaging>

springboot-example/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55
<parent>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ public MultiResponse<DemoEntity> findAll(PageRequest pageRequest) {
4040
}
4141

4242

43-
4443
@GetMapping("/test-list")
45-
public List<IdKey> test1() throws SQLException{
44+
public List<IdKey> test1() throws SQLException {
4645
return idKeyDao.findAll();
4746
}
4847

springboot-starter-data-fast/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<parent>
66
<artifactId>springboot-parent</artifactId>

springboot-starter-id-generator/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<parent>
66
<artifactId>springboot-parent</artifactId>

springboot-starter-id-generator/src/main/java/com/codingapi/springboot/generator/AutoConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public GeneratorProperties generatorProperties() {
1818

1919
@Bean(initMethod = "init")
2020
@ConditionalOnMissingBean
21-
public IdKeyDao idKeyDao(GeneratorProperties generatorProperties){
22-
IdKeyDao keyDao = new IdKeyDao(generatorProperties.getJdbcUrl());
21+
public IdKeyDao idKeyDao(GeneratorProperties generatorProperties) {
22+
IdKeyDao keyDao = new IdKeyDao(generatorProperties.getJdbcUrl());
2323
GeneratorContext.getInstance().init(keyDao);
2424
return keyDao;
2525
}

springboot-starter-id-generator/src/main/java/com/codingapi/springboot/generator/GeneratorContext.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
public class GeneratorContext {
66

7+
private static GeneratorContext instance;
8+
private IdGenerateContext idGenerateContext;
9+
710
private GeneratorContext() {
811
}
912

10-
private static GeneratorContext instance;
11-
1213
public static GeneratorContext getInstance() {
1314
if (instance == null) {
1415
synchronized (GeneratorContext.class) {
@@ -20,13 +21,11 @@ public static GeneratorContext getInstance() {
2021
return instance;
2122
}
2223

23-
private IdGenerateContext idGenerateContext;
24-
2524
long generateId(Class<?> clazz) {
2625
return idGenerateContext.generateId(clazz);
2726
}
2827

29-
void init(IdKeyDao idKeyDao){
28+
void init(IdKeyDao idKeyDao) {
3029
idGenerateContext = new IdGenerateContext(idKeyDao);
3130
}
3231

springboot-starter-id-generator/src/main/java/com/codingapi/springboot/generator/IdGenerateContext.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ public IdGenerateContext(IdKeyDao keyDao) {
1111
this.keyDao = keyDao;
1212
}
1313

14-
public synchronized long generateId(Class<?> clazz) {
15-
IdKey idKey = keyDao.getByKey(clazz.getName());
16-
if(idKey==null){
14+
public synchronized long generateId(Class<?> clazz) {
15+
IdKey idKey = keyDao.getByKey(clazz.getName());
16+
if (idKey == null) {
1717
idKey = new IdKey(clazz.getName());
1818
keyDao.save(idKey);
19-
}else{
19+
} else {
2020
keyDao.updateMaxId(idKey);
2121
}
2222
return idKey.getId();

springboot-starter-id-generator/src/main/java/com/codingapi/springboot/generator/dao/DbHelper.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,43 +12,18 @@ public class DbHelper<T> {
1212
private final QueryRunner queryRunner;
1313

1414

15-
interface IExecute {
16-
default void execute(Connection connection, QueryRunner queryRunner) throws SQLException {
17-
}
18-
}
19-
20-
interface IUpdateAndQuery<T> {
21-
default T updateAndQuery(Connection connection, QueryRunner queryRunner) throws SQLException {
22-
return null;
23-
}
24-
}
25-
26-
interface IUpdate {
27-
default int update(Connection connection, QueryRunner queryRunner) throws SQLException {
28-
return 0;
29-
}
30-
}
31-
32-
interface IQuery<T> {
33-
default T query(Connection connection, QueryRunner queryRunner) throws SQLException {
34-
return null;
35-
}
36-
}
37-
3815
public DbHelper(String jdbcUrl) {
3916
this.dataSource = new JdbcDataSource();
4017
this.queryRunner = new QueryRunner();
4118
this.dataSource.setURL(jdbcUrl);
4219
}
4320

44-
4521
public void execute(IExecute execute) throws SQLException {
4622
Connection connection = dataSource.getConnection();
4723
execute.execute(connection, queryRunner);
4824
connection.close();
4925
}
5026

51-
5227
public T updateAndQuery(IUpdateAndQuery<T> execute) throws SQLException {
5328
Connection connection = dataSource.getConnection();
5429
connection.setAutoCommit(false);
@@ -74,4 +49,29 @@ public T query(IQuery<T> execute) throws SQLException {
7449
return res;
7550
}
7651

52+
53+
interface IExecute {
54+
default void execute(Connection connection, QueryRunner queryRunner) throws SQLException {
55+
}
56+
}
57+
58+
59+
interface IUpdateAndQuery<T> {
60+
default T updateAndQuery(Connection connection, QueryRunner queryRunner) throws SQLException {
61+
return null;
62+
}
63+
}
64+
65+
interface IUpdate {
66+
default int update(Connection connection, QueryRunner queryRunner) throws SQLException {
67+
return 0;
68+
}
69+
}
70+
71+
interface IQuery<T> {
72+
default T query(Connection connection, QueryRunner queryRunner) throws SQLException {
73+
return null;
74+
}
75+
}
76+
7777
}

springboot-starter-id-generator/src/main/java/com/codingapi/springboot/generator/dao/IdKeyDao.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,17 @@ public int update(Connection connection, QueryRunner queryRunner) throws SQLExce
4848
}
4949

5050

51-
5251
@SneakyThrows
5352
public IdKey getByKey(String key) {
5453
return dbHelper.query(new DbHelper.IQuery<List<IdKey>>() {
5554
@Override
5655
public List<IdKey> query(Connection connection, QueryRunner queryRunner) throws SQLException {
57-
return queryRunner.query(connection, "SELECT * FROM ID_GENERATOR WHERE TAG = ?", handler,key);
56+
return queryRunner.query(connection, "SELECT * FROM ID_GENERATOR WHERE TAG = ?", handler, key);
5857
}
5958
}).stream().findFirst().orElse(null);
6059
}
6160

6261

63-
6462
@SneakyThrows
6563
public IdKey updateMaxId(IdKey generator) {
6664
return dbHelper.updateAndQuery(new DbHelper.IUpdateAndQuery<List<IdKey>>() {

0 commit comments

Comments
 (0)