Skip to content

Commit 6ab6050

Browse files
christophstroblodrotbohm
authored andcommitted
DATAJPA-1064 - Integrate Data Commons Java 8 upgrade branch.
Make sure things compile again and do the same as they have done before by checking and fixing unit and integration tests.
1 parent a04d9b8 commit 6ab6050

File tree

54 files changed

+342
-249
lines changed

Some content is hidden

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

54 files changed

+342
-249
lines changed

src/main/java/org/springframework/data/jpa/domain/AbstractAuditable.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2011 the original author or authors.
2+
* Copyright 2008-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,26 +16,29 @@
1616
package org.springframework.data.jpa.domain;
1717

1818
import java.io.Serializable;
19+
import java.time.LocalDateTime;
20+
import java.time.ZoneId;
1921
import java.util.Date;
22+
import java.util.Optional;
2023

2124
import javax.persistence.ManyToOne;
2225
import javax.persistence.MappedSuperclass;
2326
import javax.persistence.Temporal;
2427
import javax.persistence.TemporalType;
2528

26-
import org.joda.time.DateTime;
2729
import org.springframework.data.domain.Auditable;
2830

2931
/**
3032
* Abstract base class for auditable entities. Stores the audition values in persistent fields.
3133
*
3234
* @author Oliver Gierke
35+
* @author Christoph Strobl
3336
* @param <U> the auditing type. Typically some kind of user.
3437
* @param <PK> the type of the auditing type's idenifier
3538
*/
3639
@MappedSuperclass
3740
public abstract class AbstractAuditable<U, PK extends Serializable> extends AbstractPersistable<PK> implements
38-
Auditable<U, PK> {
41+
Auditable<U, PK, LocalDateTime> {
3942

4043
private static final long serialVersionUID = 141481953116476081L;
4144

@@ -56,9 +59,9 @@ public abstract class AbstractAuditable<U, PK extends Serializable> extends Abst
5659
*
5760
* @see org.springframework.data.domain.Auditable#getCreatedBy()
5861
*/
59-
public U getCreatedBy() {
62+
public Optional<U> getCreatedBy() {
6063

61-
return createdBy;
64+
return Optional.ofNullable(createdBy);
6265
}
6366

6467
/*
@@ -67,19 +70,20 @@ public U getCreatedBy() {
6770
* @see
6871
* org.springframework.data.domain.Auditable#setCreatedBy(java.lang.Object)
6972
*/
70-
public void setCreatedBy(final U createdBy) {
73+
public void setCreatedBy(final Optional<? extends U> createdBy) {
7174

72-
this.createdBy = createdBy;
75+
this.createdBy = createdBy.orElse(null);
7376
}
7477

7578
/*
7679
* (non-Javadoc)
7780
*
7881
* @see org.springframework.data.domain.Auditable#getCreatedDate()
7982
*/
80-
public DateTime getCreatedDate() {
83+
@Override
84+
public Optional<LocalDateTime> getCreatedDate() {
8185

82-
return null == createdDate ? null : new DateTime(createdDate);
86+
return null == createdDate ? Optional.empty() : Optional.of(LocalDateTime.ofInstant(createdDate.toInstant(), ZoneId.systemDefault()));
8387
}
8488

8589
/*
@@ -89,19 +93,19 @@ public DateTime getCreatedDate() {
8993
* org.springframework.data.domain.Auditable#setCreatedDate(org.joda.time
9094
* .DateTime)
9195
*/
92-
public void setCreatedDate(final DateTime createdDate) {
96+
public void setCreatedDate(Optional<? extends LocalDateTime> createdDate) {
9397

94-
this.createdDate = null == createdDate ? null : createdDate.toDate();
98+
this.createdDate = createdDate.map(d -> Date.from(d.atZone(ZoneId.systemDefault()).toInstant())).orElse(null);
9599
}
96100

97101
/*
98102
* (non-Javadoc)
99103
*
100104
* @see org.springframework.data.domain.Auditable#getLastModifiedBy()
101105
*/
102-
public U getLastModifiedBy() {
106+
public Optional<U> getLastModifiedBy() {
103107

104-
return lastModifiedBy;
108+
return Optional.ofNullable(lastModifiedBy);
105109
}
106110

107111
/*
@@ -111,19 +115,19 @@ public U getLastModifiedBy() {
111115
* org.springframework.data.domain.Auditable#setLastModifiedBy(java.lang
112116
* .Object)
113117
*/
114-
public void setLastModifiedBy(final U lastModifiedBy) {
118+
public void setLastModifiedBy(final Optional<? extends U> lastModifiedBy) {
115119

116-
this.lastModifiedBy = lastModifiedBy;
120+
this.lastModifiedBy = lastModifiedBy.orElse(null);
117121
}
118122

119123
/*
120124
* (non-Javadoc)
121125
*
122126
* @see org.springframework.data.domain.Auditable#getLastModifiedDate()
123127
*/
124-
public DateTime getLastModifiedDate() {
128+
public Optional<LocalDateTime> getLastModifiedDate() {
125129

126-
return null == lastModifiedDate ? null : new DateTime(lastModifiedDate);
130+
return null == lastModifiedDate ? Optional.empty() : Optional.of(LocalDateTime.ofInstant(lastModifiedDate.toInstant(), ZoneId.systemDefault()));
127131
}
128132

129133
/*
@@ -133,8 +137,8 @@ public DateTime getLastModifiedDate() {
133137
* org.springframework.data.domain.Auditable#setLastModifiedDate(org.joda
134138
* .time.DateTime)
135139
*/
136-
public void setLastModifiedDate(final DateTime lastModifiedDate) {
140+
public void setLastModifiedDate(Optional<? extends LocalDateTime> lastModifiedDate) {
137141

138-
this.lastModifiedDate = null == lastModifiedDate ? null : lastModifiedDate.toDate();
142+
this.lastModifiedDate = lastModifiedDate.map(d -> Date.from(d.atZone(ZoneId.systemDefault()).toInstant())).orElse(null);
139143
}
140144
}

src/main/java/org/springframework/data/jpa/domain/support/AuditingEntityListener.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2012 the original author or authors.
2+
* Copyright 2008-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,8 @@
1818
import javax.persistence.PrePersist;
1919
import javax.persistence.PreUpdate;
2020

21+
import java.util.Optional;
22+
2123
import org.springframework.beans.factory.ObjectFactory;
2224
import org.springframework.beans.factory.annotation.Configurable;
2325
import org.springframework.data.auditing.AuditingHandler;
@@ -54,6 +56,7 @@
5456
*
5557
* @author Oliver Gierke
5658
* @author Thomas Darimont
59+
* @author Christoph Strobl
5760
*/
5861
@Configurable
5962
public class AuditingEntityListener {
@@ -80,7 +83,7 @@ public void setAuditingHandler(ObjectFactory<AuditingHandler> auditingHandler) {
8083
@PrePersist
8184
public void touchForCreate(Object target) {
8285
if (handler != null) {
83-
handler.getObject().markCreated(target);
86+
handler.getObject().markCreated(Optional.ofNullable(target));
8487
}
8588
}
8689

@@ -93,7 +96,7 @@ public void touchForCreate(Object target) {
9396
@PreUpdate
9497
public void touchForUpdate(Object target) {
9598
if (handler != null) {
96-
handler.getObject().markModified(target);
99+
handler.getObject().markModified(Optional.ofNullable(target));
97100
}
98101
}
99102
}

src/main/java/org/springframework/data/jpa/mapping/JpaMetamodelMappingContext.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@
2525
import org.springframework.data.jpa.provider.PersistenceProvider;
2626
import org.springframework.data.mapping.context.AbstractMappingContext;
2727
import org.springframework.data.mapping.context.MappingContext;
28+
import org.springframework.data.mapping.model.Property;
2829
import org.springframework.data.mapping.model.SimpleTypeHolder;
2930
import org.springframework.data.util.TypeInformation;
3031
import org.springframework.util.Assert;
@@ -33,6 +34,7 @@
3334
* {@link MappingContext} implementation based on a Jpa {@link Metamodel}.
3435
*
3536
* @author Oliver Gierke
37+
* @author Christoph Strobl
3638
* @since 1.3
3739
*/
3840
public class JpaMetamodelMappingContext
@@ -69,11 +71,11 @@ protected <T> JpaPersistentEntityImpl<?> createPersistentEntity(TypeInformation<
6971
* @see org.springframework.data.mapping.context.AbstractMappingContext#createPersistentProperty(java.lang.reflect.Field, java.beans.PropertyDescriptor, org.springframework.data.mapping.model.MutablePersistentEntity, org.springframework.data.mapping.model.SimpleTypeHolder)
7072
*/
7173
@Override
72-
protected JpaPersistentProperty createPersistentProperty(Field field, PropertyDescriptor descriptor,
74+
protected JpaPersistentProperty createPersistentProperty(Property property,
7375
JpaPersistentEntityImpl<?> owner, SimpleTypeHolder simpleTypeHolder) {
7476

7577
Metamodel metamodel = getMetamodelFor(owner.getType());
76-
return new JpaPersistentPropertyImpl(metamodel, field, descriptor, owner, simpleTypeHolder);
78+
return new JpaPersistentPropertyImpl(metamodel, property, owner, simpleTypeHolder);
7779
}
7880

7981
/*

src/main/java/org/springframework/data/jpa/mapping/JpaPersistentEntityImpl.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616
package org.springframework.data.jpa.mapping;
1717

1818
import java.util.Comparator;
19+
import java.util.Optional;
1920

2021
import org.springframework.data.annotation.Version;
2122
import org.springframework.data.jpa.provider.ProxyIdAccessor;
@@ -30,6 +31,7 @@
3031
*
3132
* @author Oliver Gierke
3233
* @author Greg Turnquist
34+
* @author Christoph Strobl
3335
* @since 1.3
3436
*/
3537
class JpaPersistentEntityImpl<T> extends BasicPersistentEntity<T, JpaPersistentProperty>
@@ -49,7 +51,7 @@ class JpaPersistentEntityImpl<T> extends BasicPersistentEntity<T, JpaPersistentP
4951
*/
5052
public JpaPersistentEntityImpl(TypeInformation<T> information, ProxyIdAccessor proxyIdAccessor) {
5153

52-
super(information, null);
54+
super(information, Optional.empty());
5355

5456
Assert.notNull(proxyIdAccessor, "ProxyIdAccessor must not be null!");
5557
this.proxyIdAccessor = proxyIdAccessor;
@@ -82,13 +84,13 @@ public void verify() {
8284

8385
super.verify();
8486

85-
JpaPersistentProperty versionProperty = getVersionProperty();
87+
Optional<JpaPersistentProperty> versionProperty = getVersionProperty();
8688

87-
if (versionProperty == null) {
89+
if (!versionProperty.isPresent()) {
8890
return;
8991
}
9092

91-
if (versionProperty.isAnnotationPresent(Version.class)) {
93+
if (versionProperty.get().isAnnotationPresent(Version.class)) {
9294
throw new IllegalArgumentException(String.format(INVALID_VERSION_ANNOTATION, versionProperty));
9395
}
9496
}
@@ -129,8 +131,8 @@ public JpaProxyAwareIdentifierAccessor(JpaPersistentEntity<?> entity, Object bea
129131
* @see org.springframework.data.mapping.IdentifierAccessor#getIdentifier()
130132
*/
131133
@Override
132-
public Object getIdentifier() {
133-
return proxyIdAccessor.shouldUseAccessorFor(bean) ? proxyIdAccessor.getIdentifierFrom(bean)
134+
public Optional<Object> getIdentifier() {
135+
return proxyIdAccessor.shouldUseAccessorFor(bean) ? Optional.ofNullable(proxyIdAccessor.getIdentifierFrom(bean))
134136
: super.getIdentifier();
135137
}
136138
}

src/main/java/org/springframework/data/jpa/mapping/JpaPersistentPropertyImpl.java

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
2121
import java.util.Collection;
2222
import java.util.Collections;
2323
import java.util.HashSet;
24+
import java.util.Optional;
2425
import java.util.Set;
2526

2627
import javax.persistence.Access;
@@ -45,6 +46,7 @@
4546
import org.springframework.data.mapping.Association;
4647
import org.springframework.data.mapping.PersistentEntity;
4748
import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty;
49+
import org.springframework.data.mapping.model.Property;
4850
import org.springframework.data.mapping.model.SimpleTypeHolder;
4951
import org.springframework.data.util.ClassTypeInformation;
5052
import org.springframework.data.util.TypeInformation;
@@ -55,6 +57,7 @@
5557
*
5658
* @author Oliver Gierke
5759
* @author Greg Turnquist
60+
* @author Christoph Strobl
5861
* @since 1.3
5962
*/
6063
class JpaPersistentPropertyImpl extends AnnotationBasedPersistentProperty<JpaPersistentProperty>
@@ -97,15 +100,14 @@ class JpaPersistentPropertyImpl extends AnnotationBasedPersistentProperty<JpaPer
97100
* Creates a new {@link JpaPersistentPropertyImpl}
98101
*
99102
* @param metamodel must not be {@literal null}.
100-
* @param field must not be {@literal null}.
101-
* @param propertyDescriptor can be {@literal null}.
103+
* @param property must not be {@literal null}.
102104
* @param owner must not be {@literal null}.
103105
* @param simpleTypeHolder must not be {@literal null}.
104106
*/
105-
public JpaPersistentPropertyImpl(Metamodel metamodel, Field field, PropertyDescriptor propertyDescriptor,
107+
public JpaPersistentPropertyImpl(Metamodel metamodel, Property property,
106108
PersistentEntity<?, JpaPersistentProperty> owner, SimpleTypeHolder simpleTypeHolder) {
107109

108-
super(field, propertyDescriptor, owner, simpleTypeHolder);
110+
super(property, owner, simpleTypeHolder);
109111

110112
Assert.notNull(metamodel, "Metamodel must not be null!");
111113

@@ -234,27 +236,27 @@ public boolean isWritable() {
234236
*/
235237
private Boolean detectPropertyAccess() {
236238

237-
org.springframework.data.annotation.AccessType accessType = findAnnotation(
239+
Optional<org.springframework.data.annotation.AccessType> accessType = findAnnotation(
238240
org.springframework.data.annotation.AccessType.class);
239241

240-
if (accessType != null) {
241-
return Type.PROPERTY.equals(accessType.value());
242+
if (accessType.isPresent()) {
243+
return Type.PROPERTY.equals(accessType.get().value());
242244
}
243245

244-
Access access = findAnnotation(Access.class);
246+
Optional<Access> access = findAnnotation(Access.class);
245247

246-
if (access != null) {
247-
return AccessType.PROPERTY.equals(access.value());
248+
if (access.isPresent()) {
249+
return AccessType.PROPERTY.equals(access.get().value());
248250
}
249251

250252
accessType = findPropertyOrOwnerAnnotation(org.springframework.data.annotation.AccessType.class);
251253

252-
if (accessType != null) {
253-
return Type.PROPERTY.equals(accessType.value());
254+
if (accessType.isPresent()) {
255+
return Type.PROPERTY.equals(accessType.get().value());
254256
}
255257

256258
access = findPropertyOrOwnerAnnotation(Access.class);
257-
return access == null ? null : AccessType.PROPERTY.equals(access.value());
259+
return access.map(t -> AccessType.PROPERTY.equals(t.value())).orElse(null);
258260
}
259261

260262
/**
@@ -266,11 +268,14 @@ private TypeInformation<?> detectAssociationTargetType() {
266268

267269
for (Class<? extends Annotation> associationAnnotation : ASSOCIATION_ANNOTATIONS) {
268270

269-
Annotation annotation = findAnnotation(associationAnnotation);
270-
Object targetEntity = AnnotationUtils.getValue(annotation, "targetEntity");
271+
Optional<? extends Annotation> annotation = findAnnotation(associationAnnotation);
272+
if(annotation.isPresent()) {
271273

272-
if (targetEntity != null && !void.class.equals(targetEntity)) {
273-
return ClassTypeInformation.from((Class<?>) targetEntity);
274+
Object targetEntity = AnnotationUtils.getValue(annotation.get(), "targetEntity");
275+
276+
if (targetEntity != null && !void.class.equals(targetEntity)) {
277+
return ClassTypeInformation.from((Class<?>) targetEntity);
278+
}
274279
}
275280
}
276281

@@ -287,9 +292,9 @@ private final boolean detectUpdatability() {
287292

288293
for (Class<? extends Annotation> annotationType : UPDATEABLE_ANNOTATIONS) {
289294

290-
Annotation annotation = findAnnotation(annotationType);
295+
Optional<? extends Annotation> annotation = findAnnotation(annotationType);
291296

292-
if (annotation != null && AnnotationUtils.getValue(annotation, "updatable").equals(Boolean.FALSE)) {
297+
if (annotation.isPresent() && AnnotationUtils.getValue(annotation.get(), "updatable").equals(Boolean.FALSE)) {
293298
return false;
294299
}
295300
}

0 commit comments

Comments
 (0)