Skip to content

Commit

Permalink
Add logging interfaces and use them to handle log messages in #243
Browse files Browse the repository at this point in the history
  • Loading branch information
rlodge committed Feb 29, 2024
1 parent e205bcd commit 8e15975
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 18 deletions.
7 changes: 6 additions & 1 deletion pom.xml
Expand Up @@ -31,7 +31,7 @@
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>4.8.1</version>
<version>4.11.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand All @@ -41,6 +41,11 @@
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
Expand Down
52 changes: 37 additions & 15 deletions src/main/java/org/mongojack/JacksonMongoCollection.java
Expand Up @@ -26,22 +26,9 @@
import com.mongodb.ReadConcern;
import com.mongodb.ReadPreference;
import com.mongodb.WriteConcern;
import com.mongodb.client.ClientSession;
import com.mongodb.client.DistinctIterable;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MapReduceIterable;
import com.mongodb.client.MongoClient;
import com.mongodb.client.*;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.DeleteManyModel;
import com.mongodb.client.model.DeleteOneModel;
import com.mongodb.client.model.DropCollectionOptions;
import com.mongodb.client.model.Filters;
import com.mongodb.client.model.ReplaceOneModel;
import com.mongodb.client.model.ReplaceOptions;
import com.mongodb.client.model.UpdateManyModel;
import com.mongodb.client.model.UpdateOneModel;
import com.mongodb.client.model.WriteModel;
import com.mongodb.client.model.*;
import com.mongodb.client.result.DeleteResult;
import com.mongodb.client.result.UpdateResult;
import org.bson.BsonDocument;
Expand Down Expand Up @@ -668,6 +655,41 @@ public void drop(final ClientSession clientSession, final DropCollectionOptions
mongoCollection.drop(clientSession, dropCollectionOptions);
}

@Override
public String createSearchIndex(String indexName, Bson definition) {
return mongoCollection.createSearchIndex(indexName, definition);
}

@Override
public String createSearchIndex(Bson definition) {
return mongoCollection.createSearchIndex(definition);
}

@Override
public List<String> createSearchIndexes(List<SearchIndexModel> searchIndexModels) {
return mongoCollection.createSearchIndexes(searchIndexModels);
}

@Override
public void updateSearchIndex(String indexName, Bson definition) {
mongoCollection.updateSearchIndex(indexName, definition);
}

@Override
public void dropSearchIndex(String indexName) {
mongoCollection.dropSearchIndex(indexName);
}

@Override
public ListSearchIndexesIterable<Document> listSearchIndexes() {
return mongoCollection.listSearchIndexes();
}

@Override
public <TResult1> ListSearchIndexesIterable<TResult1> listSearchIndexes(Class<TResult1> tResult1Class) {
return mongoCollection.listSearchIndexes(tResult1Class);
}

private void initializeIfNecessary(Object maybeInitializable) {
if (maybeInitializable instanceof InitializationRequiredForTransformation) {
((InitializationRequiredForTransformation) maybeInitializable).initialize(objectMapper, type, jacksonCodecRegistry);
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/org/mongojack/internal/stream/JacksonCodec.java
Expand Up @@ -28,6 +28,8 @@
import org.bson.types.ObjectId;
import org.mongojack.JacksonCodecRegistry;
import org.mongojack.internal.AnnotationHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -37,6 +39,8 @@
@SuppressWarnings("WeakerAccess")
public class JacksonCodec<T> implements Codec<T>, CollectibleCodec<T>, OverridableUuidRepresentationCodec<T> {

private final static Logger logger = LoggerFactory.getLogger(JacksonCodec.class);

private final JacksonEncoder<T> encoder;
private final JacksonDecoder<T> decoder;
private final ObjectMapper objectMapper;
Expand Down Expand Up @@ -106,7 +110,7 @@ private Supplier<BsonValue> getIdReader(final T t) {
try {
return constructIdValue(beanPropertyDefinition.getAccessor().getValue(t), maybeBpd);
} catch (Exception e) {
e.printStackTrace();
logger.warn("Suppressed error attempting to get reader for object id in " + t.getClass(), e);
return BsonNull.VALUE;
}
}).orElseGet(() -> () -> BsonNull.VALUE);
Expand All @@ -123,7 +127,7 @@ private Consumer<BsonObjectId> getIdWriter(final T t) {
);
}
} catch (Exception e) {
e.printStackTrace();
logger.warn("Suppressed error attempting to get writer for object id in " + t.getClass(), e);
}
}).orElseGet(() -> (bsonObjectId) -> {
});
Expand Down

0 comments on commit 8e15975

Please sign in to comment.