Skip to content

Fix build on Java 16. #3752

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

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>3.3.0-SNAPSHOT</version>
<version>3.3.0-GH-3749-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data MongoDB</name>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb-benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>3.3.0-SNAPSHOT</version>
<version>3.3.0-GH-3749-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>3.3.0-SNAPSHOT</version>
<version>3.3.0-GH-3749-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>3.3.0-SNAPSHOT</version>
<version>3.3.0-GH-3749-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.springframework.data.mapping.MappingException;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
import org.springframework.data.mongodb.core.mapping.TimeSeries;
import org.springframework.data.mongodb.test.util.MongoTestMappingContext;

/**
* Unit tests for {@link EntityOperations}.
Expand All @@ -32,7 +33,7 @@
*/
class EntityOperationsUnitTests {

EntityOperations operations = new EntityOperations(new MongoMappingContext());
EntityOperations operations = new EntityOperations(MongoTestMappingContext.newTestContext());

@Test // GH-3731
void shouldReportInvalidTimeField() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public class MongoTemplateTests {

cfg.configureMappingContext(it -> {
it.autocreateIndex(false);
it.intitalEntitySet(AuditablePerson.class);
it.initialEntitySet(AuditablePerson.class);

});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.mongodb.test.util;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
* @author Christoph Strobl
*/
public class MappingContextConfigurer {

Set<Class<?>> intitalEntitySet;
boolean autocreateIndex = false;

public void autocreateIndex(boolean autocreateIndex) {
this.autocreateIndex = autocreateIndex;
}

public void initialEntitySet(Set<Class<?>> initialEntitySet) {
this.intitalEntitySet = initialEntitySet;
}

public void initialEntitySet(Class<?>... initialEntitySet) {
this.intitalEntitySet = new HashSet<>(Arrays.asList(initialEntitySet));
}

Set<Class<?>> initialEntitySet() {
return intitalEntitySet != null ? intitalEntitySet : Collections.emptySet();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.mongodb.test.util;

import java.util.Arrays;

import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.CustomConversions;
import org.springframework.data.mongodb.core.convert.MongoCustomConversions;

/**
* @author Christoph Strobl
*/
public class MongoConverterConfigurer {

CustomConversions customConversions;

public void customConversions(CustomConversions customConversions) {
this.customConversions = customConversions;
}

public void customConverters(Converter<?, ?>... converters) {
customConversions(new MongoCustomConversions(Arrays.asList(converters)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.mongodb.test.util;

import java.util.Collections;
import java.util.function.Consumer;

import org.springframework.data.mongodb.core.convert.MongoCustomConversions;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;

/**
* @author Christoph Strobl
*/
public class MongoTestMappingContext extends MongoMappingContext {

private MappingContextConfigurer contextConfigurer;
private MongoConverterConfigurer converterConfigurer;

public static MongoTestMappingContext newTestContext() {
return new MongoTestMappingContext(conig -> {}).init();
}

public MongoTestMappingContext(MappingContextConfigurer contextConfig) {

this.contextConfigurer = contextConfig;
this.converterConfigurer = new MongoConverterConfigurer();
}

public MongoTestMappingContext(Consumer<MappingContextConfigurer> contextConfig) {

this(new MappingContextConfigurer());
contextConfig.accept(contextConfigurer);
}

public MongoTestMappingContext customConversions(MongoConverterConfigurer converterConfig) {

this.converterConfigurer = converterConfig;
return this;
}

public MongoTestMappingContext customConversions(Consumer<MongoConverterConfigurer> converterConfig) {

converterConfig.accept(converterConfigurer);
return this;
}

public MongoTestMappingContext init() {

setInitialEntitySet(contextConfigurer.initialEntitySet());
setAutoIndexCreation(contextConfigurer.autocreateIndex);
if (converterConfigurer.customConversions != null) {
setSimpleTypeHolder(converterConfigurer.customConversions.getSimpleTypeHolder());
} else {
setSimpleTypeHolder(new MongoCustomConversions(Collections.emptyList()).getSimpleTypeHolder());
}

super.afterPropertiesSet();
return this;
}

@Override
public void afterPropertiesSet() {
init();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public MongoTestTemplate(MongoClient client, String database, Class<?>... initia
cfg.configureMappingContext(it -> {

it.autocreateIndex(false);
it.intitalEntitySet(initialEntities);
it.initialEntitySet(initialEntities);
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,15 @@
package org.springframework.data.mongodb.test.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.auditing.IsNewAwareAuditingHandler;
import org.springframework.data.convert.CustomConversions;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mongodb.MongoDatabaseFactory;
import org.springframework.data.mongodb.ReactiveMongoDatabaseFactory;
Expand Down Expand Up @@ -115,16 +110,7 @@ ApplicationContext getApplicationContext() {
MongoMappingContext mappingContext() {

if (mappingContext == null) {

mappingContext = new MongoMappingContext();
mappingContext.setInitialEntitySet(mappingContextConfigurer.initialEntitySet());
mappingContext.setAutoIndexCreation(mappingContextConfigurer.autocreateIndex);
if(mongoConverterConfigurer.customConversions != null) {
mappingContext.setSimpleTypeHolder(mongoConverterConfigurer.customConversions.getSimpleTypeHolder());
} else {
mappingContext.setSimpleTypeHolder(new MongoCustomConversions(Collections.emptyList()).getSimpleTypeHolder());
}
mappingContext.afterPropertiesSet();
mappingContext = new MongoTestMappingContext(mappingContextConfigurer).customConversions(mongoConverterConfigurer).init();
}

return mappingContext;
Expand Down Expand Up @@ -222,41 +208,6 @@ public void defaultDb(String defaultDatabase) {
}
}

public static class MongoConverterConfigurer {

CustomConversions customConversions;

public void customConversions(CustomConversions customConversions) {
this.customConversions = customConversions;
}

public void customConverters(Converter<?, ?>... converters) {
customConversions(new MongoCustomConversions(Arrays.asList(converters)));
}
}

public static class MappingContextConfigurer {

Set<Class<?>> intitalEntitySet;
boolean autocreateIndex = false;

public void autocreateIndex(boolean autocreateIndex) {
this.autocreateIndex = autocreateIndex;
}

public void intitalEntitySet(Set<Class<?>> intitalEntitySet) {
this.intitalEntitySet = intitalEntitySet;
}

public void intitalEntitySet(Class<?>... initialEntitySet) {
this.intitalEntitySet = new HashSet<>(Arrays.asList(initialEntitySet));
}

Set<Class<?>> initialEntitySet() {
return intitalEntitySet != null ? intitalEntitySet : Collections.emptySet();
}
}

public static class AuditingConfigurer {

Function<MappingContext, IsNewAwareAuditingHandler> auditingHandlerFunction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public ReactiveMongoTestTemplate(MongoClient client, String database, Class<?>..
cfg.configureMappingContext(it -> {

it.autocreateIndex(false);
it.intitalEntitySet(initialEntities);
it.initialEntitySet(initialEntities);
});
});
}
Expand Down