Skip to content

Commit 94d8960

Browse files
schauderodrotbohm
authored andcommitted
DATAJDBC-99 - Polishing.
Events now use the id as source. The id is encapsulated in a value object to support null ids in BeforeInsert events. Entity references in events are now Optionals. Dropped redundant Event suffix from events. Added "@SInCE 2.0" to classes. Replaced constructors and getters with Lombok annotations. Simplified pom.xml. Extracted interface JdbcPersistentEntity and JdbcPersistentProperty. Integration tests use the Spring Test framework. Fixed test for entities with primitive id type. Original pull request: #5.
1 parent 25fa2d4 commit 94d8960

39 files changed

+924
-584
lines changed

lombok.config

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lombok.nonNull.exceptionType = IllegalArgumentException
2+
lombok.log.fieldName = LOG

pom.xml

-55
Original file line numberDiff line numberDiff line change
@@ -128,61 +128,6 @@
128128
<groupId>org.apache.maven.plugins</groupId>
129129
<artifactId>maven-surefire-plugin</artifactId>
130130
<version>2.12</version>
131-
<dependencies>
132-
<dependency>
133-
<groupId>org.springframework</groupId>
134-
<artifactId>spring-instrument</artifactId>
135-
<version>${spring}</version>
136-
<scope>runtime</scope>
137-
</dependency>
138-
<dependency>
139-
<groupId>org.hsqldb</groupId>
140-
<artifactId>hsqldb</artifactId>
141-
<version>${hsqldb1}</version>
142-
<scope>runtime</scope>
143-
</dependency>
144-
</dependencies>
145-
<executions>
146-
<execution>
147-
<id>default-test</id>
148-
<configuration>
149-
<excludes>
150-
<exclude>**/*</exclude>
151-
</excludes>
152-
</configuration>
153-
</execution>
154-
<execution>
155-
<id>unit-tests</id>
156-
<goals>
157-
<goal>test</goal>
158-
</goals>
159-
<phase>test</phase>
160-
<configuration>
161-
<includes>
162-
<include>**/*UnitTests.java</include>
163-
</includes>
164-
</configuration>
165-
</execution>
166-
<execution>
167-
<id>integration-tests</id>
168-
<goals>
169-
<goal>test</goal>
170-
</goals>
171-
<phase>test</phase>
172-
<configuration>
173-
<includes>
174-
<include>**/*IntegrationTests.java</include>
175-
<include>**/*Tests.java</include>
176-
</includes>
177-
<excludes>
178-
<exclude>**/*UnitTests.java</exclude>
179-
\ </excludes>
180-
<argLine>
181-
-javaagent:${settings.localRepository}/org/jacoco/org.jacoco.agent/${jacoco}/org.jacoco.agent-${jacoco}-runtime.jar=destfile=${jacoco.destfile}
182-
</argLine>
183-
</configuration>
184-
</execution>
185-
</executions>
186131
</plugin>
187132
<plugin>
188133
<groupId>org.apache.maven.plugins</groupId>

src/main/java/org/springframework/data/jdbc/mapping/context/JdbcMappingContext.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import java.beans.PropertyDescriptor;
1919
import java.lang.reflect.Field;
20+
21+
import org.springframework.data.jdbc.mapping.model.BasicJdbcPersistentProperty;
2022
import org.springframework.data.jdbc.mapping.model.JdbcPersistentEntity;
2123
import org.springframework.data.jdbc.mapping.model.JdbcPersistentProperty;
2224
import org.springframework.data.mapping.context.AbstractMappingContext;
@@ -25,17 +27,22 @@
2527

2628
/**
2729
* @author Jens Schauder
30+
* @since 2.0
2831
*/
2932
public class JdbcMappingContext extends AbstractMappingContext<JdbcPersistentEntity<?>, JdbcPersistentProperty> {
3033

31-
3234
@Override
3335
protected <T> JdbcPersistentEntity createPersistentEntity(TypeInformation<T> typeInformation) {
3436
return new JdbcPersistentEntity(typeInformation);
3537
}
3638

3739
@Override
38-
protected JdbcPersistentProperty createPersistentProperty(Field field, PropertyDescriptor descriptor, JdbcPersistentEntity owner, SimpleTypeHolder simpleTypeHolder) {
39-
return new JdbcPersistentProperty(field, descriptor, owner, simpleTypeHolder);
40+
protected JdbcPersistentProperty createPersistentProperty( //
41+
Field field, //
42+
PropertyDescriptor descriptor, //
43+
JdbcPersistentEntity owner, //
44+
SimpleTypeHolder simpleTypeHolder //
45+
) {
46+
return new BasicJdbcPersistentProperty(field, descriptor, owner, simpleTypeHolder);
4047
}
4148
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.jdbc.mapping.event;
17+
18+
import org.springframework.data.jdbc.mapping.event.Identifier.Specified;
19+
20+
/**
21+
* Gets published after instantiation and setting of all the properties of an entity. This allows to do some postprocessing of entities.
22+
*
23+
* @author Jens Schauder
24+
* @since 2.0
25+
*/
26+
public class AfterCreation extends JdbcEventWithIdAndEntity {
27+
28+
/**
29+
* @param id of the entity
30+
* @param entity the newly instantiated entity.
31+
*/
32+
public AfterCreation(Specified id, Object entity) {
33+
super(id, entity);
34+
}
35+
}

src/main/java/org/springframework/data/jdbc/mapping/event/AfterCreationEvent.java

-36
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.jdbc.mapping.event;
17+
18+
import java.util.Optional;
19+
20+
import org.springframework.data.jdbc.mapping.event.Identifier.Specified;
21+
22+
/**
23+
* Gets published after deletion of an entity. It will have a {@link Specified} identifier.
24+
*
25+
* If the entity is empty or not depends on the delete method used.
26+
*
27+
* @author Jens Schauder
28+
* @since 2.0
29+
*/
30+
public class AfterDelete extends JdbcEventWithId{
31+
32+
/**
33+
* @param id of the entity.
34+
* @param instance the deleted entity if it is available.
35+
*/
36+
public AfterDelete(Specified id, Optional<Object> instance) {
37+
super(id, instance);
38+
}
39+
}

src/main/java/org/springframework/data/jdbc/mapping/event/AfterDeleteEvent.java

-36
This file was deleted.

src/main/java/org/springframework/data/jdbc/mapping/event/AfterInsertEvent.java src/main/java/org/springframework/data/jdbc/mapping/event/AfterInsert.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@
1515
*/
1616
package org.springframework.data.jdbc.mapping.event;
1717

18-
import java.util.function.Function;
18+
import org.springframework.data.jdbc.mapping.event.Identifier.Specified;
1919

2020
/**
21-
* gets published after an entity got inserted into the database.
21+
* Gets published after an entity got inserted into the database.
2222
*
2323
* @author Jens Schauder
24+
* @since 2.0
2425
*/
25-
public class AfterInsertEvent extends AfterSaveEvent {
26+
public class AfterInsert extends AfterSave {
2627

2728
/**
29+
* @param id identifier of the entity triggering the event.
2830
* @param instance the newly inserted entity.
29-
* @param idProvider a function providing the id, for the instance.
30-
* @param <T> type of the entity and the argument of the {@code idProvider}
3131
*/
32-
public <T> AfterInsertEvent(T instance, Function<T, Object> idProvider) {
33-
super(instance, idProvider);
32+
public AfterInsert(Specified id, Object instance) {
33+
super(id, instance);
3434
}
3535
}

src/main/java/org/springframework/data/jdbc/mapping/event/AfterSaveEvent.java src/main/java/org/springframework/data/jdbc/mapping/event/AfterSave.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,23 @@
1515
*/
1616
package org.springframework.data.jdbc.mapping.event;
1717

18-
import java.util.function.Function;
18+
import java.util.Optional;
19+
20+
import org.springframework.data.jdbc.mapping.event.Identifier.Specified;
1921

2022
/**
21-
* subclasses of this get published after a new instance or a changed instance was saved in the database
23+
* Subclasses of this get published after a new instance or a changed instance was saved in the database.
24+
*
2225
* @author Jens Schauder
26+
* @since 2.0
2327
*/
24-
public class AfterSaveEvent extends JdbcEvent{
28+
public class AfterSave extends JdbcEventWithIdAndEntity {
2529

2630
/**
31+
* @param id identifier of
2732
* @param instance the newly saved entity.
28-
* @param idProvider a function providing the id, for the instance.
29-
* @param <T> type of the entity and the argument of the {@code idProvider}
3033
*/
31-
<T> AfterSaveEvent(T instance, Function<T, Object> idProvider) {
32-
super(instance, idProvider);
34+
AfterSave(Specified id, Object instance) {
35+
super(id, instance);
3336
}
3437
}

src/main/java/org/springframework/data/jdbc/mapping/event/AfterUpdateEvent.java src/main/java/org/springframework/data/jdbc/mapping/event/AfterUpdate.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@
1515
*/
1616
package org.springframework.data.jdbc.mapping.event;
1717

18-
import java.util.function.Function;
18+
import org.springframework.data.jdbc.mapping.event.Identifier.Specified;
1919

2020
/**
21-
* gets published after an entity was updated in the database.
21+
* Gets published after an entity was updated in the database.
2222
*
2323
* @author Jens Schauder
24+
* @since 2.0
2425
*/
25-
public class AfterUpdateEvent extends AfterSaveEvent {
26+
public class AfterUpdate extends AfterSave {
2627

2728
/**
29+
* @param id of the entity
2830
* @param instance the updated entity.
29-
* @param idProvider a function providing the id, for the instance.
30-
* @param <T> type of the entity and the argument of the {@code idProvider}
3131
*/
32-
public <T> AfterUpdateEvent(T instance, Function<T, Object> idProvider) {
33-
super(instance, idProvider);
32+
public AfterUpdate(Specified id, Object instance) {
33+
super(id, instance);
3434
}
3535
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.jdbc.mapping.event;
17+
18+
import java.util.Optional;
19+
20+
import org.springframework.data.jdbc.mapping.event.Identifier.Specified;
21+
22+
/**
23+
* Gets published when an entity is about to get deleted.
24+
*
25+
* @author Jens Schauder
26+
* @since 2.0
27+
*/
28+
public class BeforeDelete extends JdbcEventWithId {
29+
30+
/**
31+
* @param id the id of the entity
32+
* @param entity the entity about to get deleted. Might be empty.
33+
*/
34+
public <T> BeforeDelete(Specified id, Optional<Object> entity) {
35+
super(id, entity);
36+
}
37+
}

0 commit comments

Comments
 (0)