From b85b53443b572914436165aa97f5be117f266389 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Fri, 26 May 2023 14:47:02 +0200 Subject: [PATCH] Polishing. Add missing Override annotations. --- .../data/mongodb/gridfs/GridFsTemplate.java | 12 +++++ .../gridfs/ReactiveGridFsTemplate.java | 47 ++++--------------- 2 files changed, 22 insertions(+), 37 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsTemplate.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsTemplate.java index ebc72fb6b..d5cd80f2f 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsTemplate.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsTemplate.java @@ -87,11 +87,14 @@ public class GridFsTemplate extends GridFsOperationsSupport implements GridFsOpe this.bucket = bucket; } + @Override public ObjectId store(InputStream content, @Nullable String filename, @Nullable String contentType, @Nullable Object metadata) { return store(content, filename, contentType, toDocument(metadata)); } + @Override + @SuppressWarnings("unchecked") public T store(GridFsObject upload) { GridFSUploadOptions uploadOptions = computeUploadOptionsFor(upload.getOptions().getContentType(), @@ -110,6 +113,7 @@ public class GridFsTemplate extends GridFsOperationsSupport implements GridFsOpe return upload.getFileId(); } + @Override public GridFSFindIterable find(Query query) { Assert.notNull(query, "Query must not be null"); @@ -130,10 +134,12 @@ public class GridFsTemplate extends GridFsOperationsSupport implements GridFsOpe return iterable; } + @Override public GridFSFile findOne(Query query) { return find(query).first(); } + @Override public void delete(Query query) { for (GridFSFile gridFSFile : find(query)) { @@ -141,10 +147,12 @@ public class GridFsTemplate extends GridFsOperationsSupport implements GridFsOpe } } + @Override public ClassLoader getClassLoader() { return dbFactory.getClass().getClassLoader(); } + @Override public GridFsResource getResource(String location) { return Optional.ofNullable(findOne(query(whereFilename().is(location)))) // @@ -152,6 +160,7 @@ public class GridFsTemplate extends GridFsOperationsSupport implements GridFsOpe .orElseGet(() -> GridFsResource.absent(location)); } + @Override public GridFsResource getResource(GridFSFile file) { Assert.notNull(file, "GridFSFile must not be null"); @@ -159,6 +168,7 @@ public class GridFsTemplate extends GridFsOperationsSupport implements GridFsOpe return new GridFsResource(file, getGridFs().openDownloadStream(file.getId())); } + @Override public GridFsResource[] getResources(String locationPattern) { if (!StringUtils.hasText(locationPattern)) { @@ -184,6 +194,8 @@ public class GridFsTemplate extends GridFsOperationsSupport implements GridFsOpe private GridFSBucket getGridFs() { + Assert.notNull(dbFactory, "MongoDatabaseFactory must not be null"); + MongoDatabase db = dbFactory.getMongoDatabase(); return bucket == null ? GridFSBuckets.create(db) : GridFSBuckets.create(db, bucket); } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/ReactiveGridFsTemplate.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/ReactiveGridFsTemplate.java index c71a1d471..b763bee18 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/ReactiveGridFsTemplate.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/ReactiveGridFsTemplate.java @@ -82,7 +82,7 @@ public class ReactiveGridFsTemplate extends GridFsOperationsSupport implements R * * @param dbFactory must not be {@literal null}. * @param converter must not be {@literal null}. - * @param bucket + * @param bucket can be {@literal null}. */ public ReactiveGridFsTemplate(ReactiveMongoDatabaseFactory dbFactory, MongoConverter converter, @Nullable String bucket) { @@ -96,7 +96,7 @@ public class ReactiveGridFsTemplate extends GridFsOperationsSupport implements R * @param dataBufferFactory must not be {@literal null}. * @param dbFactory must not be {@literal null}. * @param converter must not be {@literal null}. - * @param bucket + * @param bucket can be {@literal null}. */ public ReactiveGridFsTemplate(DataBufferFactory dataBufferFactory, ReactiveMongoDatabaseFactory dbFactory, MongoConverter converter, @Nullable String bucket) { @@ -117,6 +117,8 @@ public class ReactiveGridFsTemplate extends GridFsOperationsSupport implements R return store(content, filename, contentType, toDocument(metadata)); } + @Override + @SuppressWarnings("unchecked") public Mono store(GridFsObject> upload) { GridFSUploadOptions uploadOptions = computeUploadOptionsFor(upload.getOptions().getContentType(), @@ -274,6 +276,7 @@ public class ReactiveGridFsTemplate extends GridFsOperationsSupport implements R this.sortObject = sortObject; } + @Override public GridFSFindPublisher doInBucket(GridFSBucket bucket) { GridFSFindPublisher findPublisher = bucket.find(queryObject).sort(sortObject); @@ -311,21 +314,8 @@ public class ReactiveGridFsTemplate extends GridFsOperationsSupport implements R } } - private static class UploadCallback implements ReactiveBucketCallback { - - private final BsonValue fileId; - private final String filename; - private final Publisher source; - private final GridFSUploadOptions uploadOptions; - - public UploadCallback(BsonValue fileId, String filename, Publisher source, - GridFSUploadOptions uploadOptions) { - - this.fileId = fileId; - this.filename = filename; - this.source = source; - this.uploadOptions = uploadOptions; - } + private record UploadCallback(BsonValue fileId, String filename, Publisher source, + GridFSUploadOptions uploadOptions) implements ReactiveBucketCallback { @Override public GridFSUploadPublisher doInBucket(GridFSBucket bucket) { @@ -333,19 +323,8 @@ public class ReactiveGridFsTemplate extends GridFsOperationsSupport implements R } } - private static class AutoIdCreatingUploadCallback implements ReactiveBucketCallback { - - private final String filename; - private final Publisher source; - private final GridFSUploadOptions uploadOptions; - - public AutoIdCreatingUploadCallback(String filename, Publisher source, - GridFSUploadOptions uploadOptions) { - - this.filename = filename; - this.source = source; - this.uploadOptions = uploadOptions; - } + private record AutoIdCreatingUploadCallback(String filename, Publisher source, + GridFSUploadOptions uploadOptions) implements ReactiveBucketCallback { @Override public GridFSUploadPublisher doInBucket(GridFSBucket bucket) { @@ -353,13 +332,7 @@ public class ReactiveGridFsTemplate extends GridFsOperationsSupport implements R } } - private static class DeleteCallback implements ReactiveBucketCallback { - - private final BsonValue id; - - public DeleteCallback(BsonValue id) { - this.id = id; - } + private record DeleteCallback(BsonValue id) implements ReactiveBucketCallback { @Override public Publisher doInBucket(GridFSBucket bucket) {