Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* Contains parser classes for the MongoDb namespace support.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.mongodb.config;
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* Provides MongoDB Components support for Java DSL.
*/
@org.springframework.lang.NonNullApi
@org.springframework.lang.NonNullFields
@org.jspecify.annotations.NullMarked
package org.springframework.integration.mongodb.dsl;
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

import java.util.Collection;
import java.util.Map;
import java.util.Objects;

import com.mongodb.DBObject;
import org.bson.Document;
import org.jspecify.annotations.Nullable;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
Expand All @@ -40,7 +42,6 @@
import org.springframework.expression.common.LiteralExpression;
import org.springframework.expression.spel.support.StandardTypeLocator;
import org.springframework.integration.endpoint.AbstractMessageSource;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
Expand All @@ -64,14 +65,16 @@ public abstract class AbstractMongoDbMessageSource<T> extends AbstractMessageSou

private Expression collectionNameExpression = new LiteralExpression("data");

@SuppressWarnings("NullAway.Init")
private MongoConverter mongoConverter;

private Class<?> entityClass = DBObject.class;

private boolean expectSingleResult = false;

private Expression updateExpression;
private @Nullable Expression updateExpression;

@SuppressWarnings("NullAway.Init")
private ApplicationContext applicationContext;

private volatile boolean initialized = false;
Expand Down Expand Up @@ -156,7 +159,7 @@ public boolean isExpectSingleResult() {
return this.expectSingleResult;
}

public Expression getUpdateExpression() {
public @Nullable Expression getUpdateExpression() {
return this.updateExpression;
}

Expand Down Expand Up @@ -261,7 +264,7 @@ else if (value instanceof Update castUpdate) {
}

private static Pair<String, Object> idFieldFromMap(Map<String, Object> map) {
return Pair.of(ID_FIELD, map.get(ID_FIELD));
return Pair.of(ID_FIELD, Objects.requireNonNull(map.get(ID_FIELD)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
package org.springframework.integration.mongodb.inbound;

import org.bson.Document;
import org.jspecify.annotations.Nullable;
import reactor.core.publisher.Flux;

import org.springframework.data.mongodb.core.ChangeStreamOptions;
import org.springframework.data.mongodb.core.ReactiveMongoOperations;
import org.springframework.integration.endpoint.MessageProducerSupport;
import org.springframework.integration.mongodb.support.MongoHeaders;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.util.Assert;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.Collection;
import java.util.List;

import org.jspecify.annotations.Nullable;

import org.springframework.context.ApplicationContext;
import org.springframework.data.mongodb.MongoDatabaseFactory;
import org.springframework.data.mongodb.core.MongoOperations;
Expand All @@ -31,7 +33,6 @@
import org.springframework.integration.mongodb.support.MongoHeaders;
import org.springframework.integration.support.AbstractIntegrationMessageBuilder;
import org.springframework.integration.transaction.IntegrationResourceHolder;
import org.springframework.lang.Nullable;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
Expand Down Expand Up @@ -64,6 +65,7 @@ public class MongoDbMessageSource extends AbstractMongoDbMessageSource<Object> {
@Nullable
private final MongoDatabaseFactory mongoDbFactory;

@SuppressWarnings("NullAway.Init")
private MongoOperations mongoTemplate;

/**
Expand Down Expand Up @@ -105,9 +107,7 @@ protected void onInit() {
if (this.mongoDbFactory != null) {
MongoTemplate template = new MongoTemplate(this.mongoDbFactory, getMongoConverter());
ApplicationContext applicationContext = getApplicationContext();
if (applicationContext != null) {
template.setApplicationContext(applicationContext);
}
template.setApplicationContext(applicationContext);
this.mongoTemplate = template;
}
setMongoConverter(this.mongoTemplate.getConverter());
Expand All @@ -124,7 +124,7 @@ protected void onInit() {
* query will be provided in the {@link MongoHeaders#COLLECTION_NAME} header.
*/
@Override
protected Object doReceive() {
protected @Nullable Object doReceive() {
Assert.isTrue(isInitialized(), "This class is not yet initialized. Invoke its afterPropertiesSet() method");
AbstractIntegrationMessageBuilder<Object> messageBuilder = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.integration.mongodb.inbound;

import org.jspecify.annotations.Nullable;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
Expand All @@ -30,7 +31,6 @@
import org.springframework.data.util.Pair;
import org.springframework.expression.Expression;
import org.springframework.integration.mongodb.support.MongoHeaders;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;

/**
Expand All @@ -57,6 +57,7 @@ public class ReactiveMongoDbMessageSource extends AbstractMongoDbMessageSource<P
@Nullable
private final ReactiveMongoDatabaseFactory reactiveMongoDatabaseFactory;

@SuppressWarnings("NullAway.Init")
private ReactiveMongoOperations reactiveMongoTemplate;

/**
Expand Down Expand Up @@ -101,9 +102,7 @@ protected void onInit() {
ReactiveMongoTemplate template =
new ReactiveMongoTemplate(this.reactiveMongoDatabaseFactory, getMongoConverter());
ApplicationContext applicationContext = getApplicationContext();
if (applicationContext != null) {
template.setApplicationContext(applicationContext);
}
template.setApplicationContext(applicationContext);
this.reactiveMongoTemplate = template;
}
setMongoConverter(this.reactiveMongoTemplate.getConverter());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* Provides classes related to the Mongo inbound channel adapters
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.mongodb.inbound;
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Map;

import org.bson.Document;
import org.jspecify.annotations.Nullable;

import org.springframework.data.mongodb.MongoDatabaseFactory;
import org.springframework.data.mongodb.core.FindAndModifyOptions;
Expand Down Expand Up @@ -124,7 +125,7 @@ public void put(String key, String value) {
* @see MongoTemplate#findOne(Query, Class, String)
*/
@Override
public String get(String key) {
public @Nullable String get(String key) {
Assert.hasText(key, KEY_MUST_NOT_BE_EMPTY);
Query query = new Query(Criteria.where(ID_FIELD).is(key));
query.fields().exclude(ID_FIELD);
Expand All @@ -142,7 +143,7 @@ public String get(String key) {
* @see MongoTemplate#findAndRemove(Query, Class, String)
*/
@Override
public String remove(String key) {
public @Nullable String remove(String key) {
Assert.hasText(key, KEY_MUST_NOT_BE_EMPTY);
Query query = new Query(Criteria.where(ID_FIELD).is(key));
query.fields().exclude(ID_FIELD);
Expand All @@ -167,7 +168,7 @@ public String remove(String key) {
* @see java.util.concurrent.ConcurrentMap#putIfAbsent(Object, Object)
*/
@Override
public String putIfAbsent(String key, String value) {
public @Nullable String putIfAbsent(String key, String value) {
Assert.hasText(key, KEY_MUST_NOT_BE_EMPTY);
Assert.hasText(value, "'value' must not be empty.");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* Contains mongodb metadata store related classes
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.mongodb.metadata;
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import com.mongodb.MongoException;
import com.mongodb.client.MongoCollection;
import org.bson.Document;
import org.jspecify.annotations.Nullable;

import org.springframework.dao.DataAccessException;
import org.springframework.data.mongodb.core.CollectionCallback;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

package org.springframework.integration.mongodb.outbound;

import java.util.Objects;

import org.bson.Document;
import org.jspecify.annotations.Nullable;

import org.springframework.data.mongodb.MongoDatabaseFactory;
import org.springframework.data.mongodb.core.MongoOperations;
Expand Down Expand Up @@ -46,22 +49,25 @@
*/
public class MongoDbOutboundGateway extends AbstractReplyProducingMessageHandler {

private MongoDatabaseFactory mongoDbFactory;
private @Nullable MongoDatabaseFactory mongoDbFactory;

private MongoConverter mongoConverter;
private @Nullable MongoConverter mongoConverter;

@SuppressWarnings("NullAway.Init")
private MongoOperations mongoTemplate;

@SuppressWarnings("NullAway.Init")
private EvaluationContext evaluationContext;

private Expression queryExpression;
private @Nullable Expression queryExpression;

private MessageCollectionCallback<?> collectionCallback;
private @Nullable MessageCollectionCallback<?> collectionCallback;

private boolean expectSingleResult = false;

private Class<?> entityClass = Document.class;

@SuppressWarnings("NullAway.Init")
private Expression collectionNameExpression;

public MongoDbOutboundGateway(MongoDatabaseFactory mongoDbFactory) {
Expand Down Expand Up @@ -147,20 +153,21 @@ protected void doInit() {
}

if (this.mongoTemplate == null) {
this.mongoTemplate = new MongoTemplate(this.mongoDbFactory, this.mongoConverter);
this.mongoTemplate = new MongoTemplate(Objects.requireNonNull(this.mongoDbFactory), this.mongoConverter);
}
}

@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
protected @Nullable Object handleRequestMessage(Message<?> requestMessage) {
String collectionName =
this.collectionNameExpression.getValue(this.evaluationContext, requestMessage, String.class);
Assert.notNull(collectionName, "'collectionNameExpression' cannot evaluate to null");
Object result;

if (this.collectionCallback != null) {
var collectionCallbackToUse = this.collectionCallback;
result = this.mongoTemplate.execute(collectionName,
collection -> this.collectionCallback.doInCollection(collection, requestMessage));
collection -> collectionCallbackToUse.doInCollection(collection, requestMessage));
}
else {
Query query = buildQuery(requestMessage);
Expand All @@ -178,7 +185,7 @@ protected Object handleRequestMessage(Message<?> requestMessage) {

private Query buildQuery(Message<?> requestMessage) {
Query query;

Objects.requireNonNull(this.queryExpression);
Object expressionValue =
this.queryExpression.getValue(this.evaluationContext, requestMessage, Object.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

package org.springframework.integration.mongodb.outbound;

import java.util.Objects;

import org.jspecify.annotations.Nullable;

import org.springframework.data.mongodb.MongoDatabaseFactory;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.MongoTemplate;
Expand All @@ -42,12 +46,14 @@
*/
public class MongoDbStoringMessageHandler extends AbstractMessageHandler {

private final MongoDatabaseFactory mongoDbFactory;
private final @Nullable MongoDatabaseFactory mongoDbFactory;

@SuppressWarnings("NullAway.Init")
private MongoOperations mongoTemplate;

private MongoConverter mongoConverter;
private @Nullable MongoConverter mongoConverter;

@SuppressWarnings("NullAway.Init")
private StandardEvaluationContext evaluationContext;

private Expression collectionNameExpression = new LiteralExpression("data");
Expand Down Expand Up @@ -106,7 +112,7 @@ protected void onInit() {
this.evaluationContext =
ExpressionUtils.createStandardEvaluationContext(this.getBeanFactory());
if (this.mongoTemplate == null) {
this.mongoTemplate = new MongoTemplate(this.mongoDbFactory, this.mongoConverter);
this.mongoTemplate = new MongoTemplate(Objects.requireNonNull(this.mongoDbFactory), this.mongoConverter);
}
this.initialized = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package org.springframework.integration.mongodb.outbound;

import java.util.Objects;

import org.jspecify.annotations.Nullable;
import reactor.core.publisher.Mono;

import org.springframework.data.mongodb.ReactiveMongoDatabaseFactory;
Expand All @@ -42,12 +45,14 @@
*/
public class ReactiveMongoDbStoringMessageHandler extends AbstractReactiveMessageHandler {

@SuppressWarnings("NullAway.Init")
private ReactiveMongoOperations mongoTemplate;

private ReactiveMongoDatabaseFactory mongoDbFactory;
private @Nullable ReactiveMongoDatabaseFactory mongoDbFactory;

private MongoConverter mongoConverter;
private @Nullable MongoConverter mongoConverter;

@SuppressWarnings("NullAway.Init")
private StandardEvaluationContext evaluationContext;

private Expression collectionNameExpression = new LiteralExpression("data");
Expand Down Expand Up @@ -105,6 +110,7 @@ protected void onInit() {
super.onInit();
this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory());
if (this.mongoTemplate == null) {
Objects.requireNonNull(this.mongoDbFactory);
ReactiveMongoTemplate template = new ReactiveMongoTemplate(this.mongoDbFactory, this.mongoConverter);
template.setApplicationContext(getApplicationContext());
this.mongoTemplate = template;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* Provides classes related to the Mongo outbound channel adapters
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.mongodb.outbound;
Loading