Skip to content

Port to jdk17 and spring 3.0.0 #1279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 30 additions & 44 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-couchbase</artifactId>
<version>4.3.0-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>

<name>Spring Data Couchbase</name>
<description>Spring Data integration for Couchbase</description>
Expand All @@ -14,14 +15,17 @@
<parent>
<groupId>org.springframework.data.build</groupId>
<artifactId>spring-data-parent</artifactId>
<version>2.6.0-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
</parent>

<properties>
<couchbase>3.2.1</couchbase>
<couchbase.osgi>3.2.1</couchbase.osgi>
<springdata.commons>2.6.0-SNAPSHOT</springdata.commons>
<couchbase>3.2.3</couchbase>
<couchbase.osgi>3.2.3</couchbase.osgi>
<springdata.commons>3.0.0-SNAPSHOT</springdata.commons>
<java-module-name>spring.data.couchbase</java-module-name>
<jodatime>2.10.13</jodatime>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've dropped support for Jodatime in Spring Data Commons. Unless there's a strong reason to keep Joda, we suggest switching to JSR-310 types.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have this as optional - if the user provides the jodatime then we will support it. I believe the JSR-310 types are handled by https://github.com/spring-projects/spring-data-couchbase/blob/5.0.x/src/main/java/org/springframework/data/couchbase/core/convert/CouchbaseJsr310Converters.java

<jakarta.validation>3.0.1</jakarta.validation>
<hibernate.validator>7.0.1.Final</hibernate.validator>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -64,6 +68,13 @@
<version>${couchbase}</version>
</dependency>

<!-- CDI -->
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<version>3.0.0</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
Expand All @@ -72,9 +83,9 @@
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.3.6.Final</version>
<version>7.0.1.Final</version>
<scope>test</scope>
</dependency>

Expand Down Expand Up @@ -112,24 +123,25 @@

<!-- JSR 303 Validation -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>${validation}</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>3.0.0</version>
<scope>test</scope>
<groupId>jakarta.el</groupId>
<artifactId>jakarta.el-api</artifactId>
<version>4.0.0</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>3.0.0</version>
<scope>test</scope>
<artifactId>jakarta.el</artifactId>
<version>4.0.2</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>

<!-- CDI -->
Expand All @@ -148,21 +160,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>${cdi}</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>${javax-annotation-api}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-se</artifactId>
Expand Down Expand Up @@ -279,17 +276,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Automatic-Module-Name>${java-module-name}</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

package org.springframework.data.couchbase.core;

import java.lang.reflect.InaccessibleObjectException;
import java.util.Map;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
Expand All @@ -40,6 +44,7 @@
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.model.ConvertingPropertyAccessor;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;

/**
* Internal encode/decode support for CouchbaseTemplate.
Expand Down Expand Up @@ -84,7 +89,18 @@ public CouchbaseDocument encodeEntity(final Object entityToEncode) {
public <T> T decodeEntity(String id, String source, long cas, Class<T> entityClass) {
final CouchbaseDocument converted = new CouchbaseDocument(id);
converted.setId(id);
CouchbasePersistentEntity<?> persistentEntity = mappingContext.getRequiredPersistentEntity(entityClass);
CouchbasePersistentEntity persistentEntity = couldBePersistentEntity(entityClass);

if (persistentEntity == null) { // method could return a Long, Boolean, String etc.
// QueryExecutionConverters.unwrapWrapperTypes will recursively unwrap until there is nothing left
// to unwrap. This results in List<String[]> being unwrapped past String[] to String, so this may also be a
// Collection (or Array) of entityClass. We have no way of knowing - so just assume it is what we are told.
// if this is a Collection or array, only the first element will be returned.
Set<Map.Entry<String, Object>> set = ((CouchbaseDocument) translationService.decode(source, converted))
.getContent().entrySet();
return (T) set.iterator().next().getValue();
}

if (cas != 0 && persistentEntity.getVersionProperty() != null) {
converted.put(persistentEntity.getVersionProperty().getName(), cas);
}
Expand All @@ -98,6 +114,17 @@ public <T> T decodeEntity(String id, String source, long cas, Class<T> entityCla
N1qlJoinResolver.handleProperties(persistentEntity, accessor, template.reactive(), id);
return accessor.getBean();
}
CouchbasePersistentEntity couldBePersistentEntity(Class<?> entityClass) {
if (ClassUtils.isPrimitiveOrWrapper(entityClass) || entityClass == String.class) {
return null;
}
try {
return mappingContext.getPersistentEntity(entityClass);
} catch (InaccessibleObjectException t) {

}
return null;
}

@Override
public Object applyUpdatedCas(final Object entity, CouchbaseDocument converted, final long cas) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

import reactor.core.publisher.Mono;

import java.lang.reflect.InaccessibleObjectException;
import java.util.Map;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
Expand All @@ -42,6 +46,7 @@
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.model.ConvertingPropertyAccessor;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;

/**
* Internal encode/decode support for {@link ReactiveCouchbaseTemplate}.
Expand Down Expand Up @@ -84,7 +89,19 @@ public <T> Mono<T> decodeEntity(String id, String source, long cas, Class<T> ent
return Mono.fromSupplier(() -> {
final CouchbaseDocument converted = new CouchbaseDocument(id);
converted.setId(id);
CouchbasePersistentEntity<?> persistentEntity = mappingContext.getRequiredPersistentEntity(entityClass);

CouchbasePersistentEntity persistentEntity = couldBePersistentEntity(entityClass);

if (persistentEntity == null) { // method could return a Long, Boolean, String etc.
// QueryExecutionConverters.unwrapWrapperTypes will recursively unwrap until there is nothing left
// to unwrap. This results in List<String[]> being unwrapped past String[] to String, so this may also be a
// Collection (or Array) of entityClass. We have no way of knowing - so just assume it is what we are told.
// if this is a Collection or array, only the first element will be returned.
Set<Map.Entry<String, Object>> set = ((CouchbaseDocument) translationService.decode(source, converted))
.getContent().entrySet();
return (T) set.iterator().next().getValue();
}

if (cas != 0 && persistentEntity.getVersionProperty() != null) {
converted.put(persistentEntity.getVersionProperty().getName(), cas);
}
Expand All @@ -100,6 +117,18 @@ public <T> Mono<T> decodeEntity(String id, String source, long cas, Class<T> ent
});
}

CouchbasePersistentEntity couldBePersistentEntity(Class<?> entityClass) {
if (ClassUtils.isPrimitiveOrWrapper(entityClass) || entityClass == String.class) {
return null;
}
try {
return mappingContext.getPersistentEntity(entityClass);
} catch (InaccessibleObjectException t) {

}
return null;
}

@Override
public Mono<Object> applyUpdatedCas(final Object entity, CouchbaseDocument converted, final long cas) {
return Mono.fromSupplier(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.data.convert.CustomConversions;
import org.springframework.data.convert.EntityInstantiators;
import org.springframework.data.mapping.model.EntityInstantiators;

/**
* An abstract {@link CouchbaseConverter} that provides the basics for the {@link MappingCouchbaseConverter}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.time.LocalTime;
import java.time.Period;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
Expand Down Expand Up @@ -71,6 +72,9 @@ private CouchbaseJsr310Converters() {
converters.add(StringToDurationConverter.INSTANCE);
converters.add(PeriodToStringConverter.INSTANCE);
converters.add(StringToPeriodConverter.INSTANCE);
converters.add(ZonedDateTimeToLongConverter.INSTANCE);
converters.add(NumberToZonedDateTimeConverter.INSTANCE);

return converters;
}

Expand Down Expand Up @@ -99,6 +103,31 @@ public Long convert(LocalDateTime source) {
}
}

@ReadingConverter
public enum NumberToZonedDateTimeConverter implements Converter<Number, ZonedDateTime> {

INSTANCE;

@Override
public ZonedDateTime convert(Number source) {
return source == null ? null
: ZonedDateTime.ofInstant(DateConverters.SerializedObjectToDateConverter.INSTANCE.convert(source).toInstant(),
systemDefault());
}
}

@WritingConverter
public enum ZonedDateTimeToLongConverter implements Converter<ZonedDateTime, Long> {

INSTANCE;

@Override
public Long convert(ZonedDateTime source) {
return source == null ? null
: DateConverters.DateToLongConverter.INSTANCE.convert(Date.from(source.toInstant()));
}
}

@ReadingConverter
public enum NumberToLocalDateConverter implements Converter<Number, LocalDate> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.data.annotation.Transient;
import org.springframework.data.convert.CustomConversions;
import org.springframework.data.convert.EntityInstantiator;
import org.springframework.data.couchbase.core.mapping.CouchbaseDocument;
import org.springframework.data.couchbase.core.mapping.CouchbaseList;
import org.springframework.data.couchbase.core.mapping.CouchbaseMappingContext;
Expand All @@ -60,6 +59,7 @@
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.model.ConvertingPropertyAccessor;
import org.springframework.data.mapping.model.DefaultSpELExpressionEvaluator;
import org.springframework.data.mapping.model.EntityInstantiator;
import org.springframework.data.mapping.model.ParameterValueProvider;
import org.springframework.data.mapping.model.PersistentEntityParameterValueProvider;
import org.springframework.data.mapping.model.PropertyValueProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

import java.util.Set;

import javax.validation.ConstraintViolationException;
import javax.validation.Validator;

import jakarta.validation.ConstraintViolationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.couchbase.core.mapping.CouchbaseDocument;
import org.springframework.util.Assert;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;

/**
* javax.validation dependant entities validator. When it is registered as Spring component its automatically invoked
Expand All @@ -38,14 +38,14 @@ public class ValidatingCouchbaseEventListener extends AbstractCouchbaseEventList

private static final Logger LOG = LoggerFactory.getLogger(ValidatingCouchbaseEventListener.class);

private final Validator validator;
private final LocalValidatorFactoryBean validator;

/**
* Creates a new {@link ValidatingCouchbaseEventListener} using the given {@link Validator}.
*
* @param validator must not be {@literal null}.
*/
public ValidatingCouchbaseEventListener(Validator validator) {
public ValidatingCouchbaseEventListener(LocalValidatorFactoryBean validator) {
Assert.notNull(validator, "Validator must not be null!");
this.validator = validator;
}
Expand Down
Loading