Skip to content

Commit b85b534

Browse files
committed
Polishing.
Add missing Override annotations.
1 parent 9907016 commit b85b534

File tree

2 files changed

+22
-37
lines changed

2 files changed

+22
-37
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsTemplate.java

+12
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,14 @@ public GridFsTemplate(MongoDatabaseFactory dbFactory, MongoConverter converter,
8787
this.bucket = bucket;
8888
}
8989

90+
@Override
9091
public ObjectId store(InputStream content, @Nullable String filename, @Nullable String contentType,
9192
@Nullable Object metadata) {
9293
return store(content, filename, contentType, toDocument(metadata));
9394
}
9495

96+
@Override
97+
@SuppressWarnings("unchecked")
9598
public <T> T store(GridFsObject<T, InputStream> upload) {
9699

97100
GridFSUploadOptions uploadOptions = computeUploadOptionsFor(upload.getOptions().getContentType(),
@@ -110,6 +113,7 @@ public <T> T store(GridFsObject<T, InputStream> upload) {
110113
return upload.getFileId();
111114
}
112115

116+
@Override
113117
public GridFSFindIterable find(Query query) {
114118

115119
Assert.notNull(query, "Query must not be null");
@@ -130,35 +134,41 @@ public GridFSFindIterable find(Query query) {
130134
return iterable;
131135
}
132136

137+
@Override
133138
public GridFSFile findOne(Query query) {
134139
return find(query).first();
135140
}
136141

142+
@Override
137143
public void delete(Query query) {
138144

139145
for (GridFSFile gridFSFile : find(query)) {
140146
getGridFs().delete(gridFSFile.getId());
141147
}
142148
}
143149

150+
@Override
144151
public ClassLoader getClassLoader() {
145152
return dbFactory.getClass().getClassLoader();
146153
}
147154

155+
@Override
148156
public GridFsResource getResource(String location) {
149157

150158
return Optional.ofNullable(findOne(query(whereFilename().is(location)))) //
151159
.map(this::getResource) //
152160
.orElseGet(() -> GridFsResource.absent(location));
153161
}
154162

163+
@Override
155164
public GridFsResource getResource(GridFSFile file) {
156165

157166
Assert.notNull(file, "GridFSFile must not be null");
158167

159168
return new GridFsResource(file, getGridFs().openDownloadStream(file.getId()));
160169
}
161170

171+
@Override
162172
public GridFsResource[] getResources(String locationPattern) {
163173

164174
if (!StringUtils.hasText(locationPattern)) {
@@ -184,6 +194,8 @@ public GridFsResource[] getResources(String locationPattern) {
184194

185195
private GridFSBucket getGridFs() {
186196

197+
Assert.notNull(dbFactory, "MongoDatabaseFactory must not be null");
198+
187199
MongoDatabase db = dbFactory.getMongoDatabase();
188200
return bucket == null ? GridFSBuckets.create(db) : GridFSBuckets.create(db, bucket);
189201
}

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/ReactiveGridFsTemplate.java

+10-37
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public ReactiveGridFsTemplate(ReactiveMongoDatabaseFactory dbFactory, MongoConve
8282
*
8383
* @param dbFactory must not be {@literal null}.
8484
* @param converter must not be {@literal null}.
85-
* @param bucket
85+
* @param bucket can be {@literal null}.
8686
*/
8787
public ReactiveGridFsTemplate(ReactiveMongoDatabaseFactory dbFactory, MongoConverter converter,
8888
@Nullable String bucket) {
@@ -96,7 +96,7 @@ public ReactiveGridFsTemplate(ReactiveMongoDatabaseFactory dbFactory, MongoConve
9696
* @param dataBufferFactory must not be {@literal null}.
9797
* @param dbFactory must not be {@literal null}.
9898
* @param converter must not be {@literal null}.
99-
* @param bucket
99+
* @param bucket can be {@literal null}.
100100
*/
101101
public ReactiveGridFsTemplate(DataBufferFactory dataBufferFactory, ReactiveMongoDatabaseFactory dbFactory,
102102
MongoConverter converter, @Nullable String bucket) {
@@ -117,6 +117,8 @@ public Mono<ObjectId> store(Publisher<DataBuffer> content, @Nullable String file
117117
return store(content, filename, contentType, toDocument(metadata));
118118
}
119119

120+
@Override
121+
@SuppressWarnings("unchecked")
120122
public <T> Mono<T> store(GridFsObject<T, Publisher<DataBuffer>> upload) {
121123

122124
GridFSUploadOptions uploadOptions = computeUploadOptionsFor(upload.getOptions().getContentType(),
@@ -274,6 +276,7 @@ public FindCallback(Query query, Document queryObject, Document sortObject) {
274276
this.sortObject = sortObject;
275277
}
276278

279+
@Override
277280
public GridFSFindPublisher doInBucket(GridFSBucket bucket) {
278281

279282
GridFSFindPublisher findPublisher = bucket.find(queryObject).sort(sortObject);
@@ -311,55 +314,25 @@ public GridFSFindPublisher doInBucket(GridFSBucket bucket) {
311314
}
312315
}
313316

314-
private static class UploadCallback implements ReactiveBucketCallback<Void> {
315-
316-
private final BsonValue fileId;
317-
private final String filename;
318-
private final Publisher<ByteBuffer> source;
319-
private final GridFSUploadOptions uploadOptions;
320-
321-
public UploadCallback(BsonValue fileId, String filename, Publisher<ByteBuffer> source,
322-
GridFSUploadOptions uploadOptions) {
323-
324-
this.fileId = fileId;
325-
this.filename = filename;
326-
this.source = source;
327-
this.uploadOptions = uploadOptions;
328-
}
317+
private record UploadCallback(BsonValue fileId, String filename, Publisher<ByteBuffer> source,
318+
GridFSUploadOptions uploadOptions) implements ReactiveBucketCallback<Void> {
329319

330320
@Override
331321
public GridFSUploadPublisher<Void> doInBucket(GridFSBucket bucket) {
332322
return bucket.uploadFromPublisher(fileId, filename, source, uploadOptions);
333323
}
334324
}
335325

336-
private static class AutoIdCreatingUploadCallback implements ReactiveBucketCallback<ObjectId> {
337-
338-
private final String filename;
339-
private final Publisher<ByteBuffer> source;
340-
private final GridFSUploadOptions uploadOptions;
341-
342-
public AutoIdCreatingUploadCallback(String filename, Publisher<ByteBuffer> source,
343-
GridFSUploadOptions uploadOptions) {
344-
345-
this.filename = filename;
346-
this.source = source;
347-
this.uploadOptions = uploadOptions;
348-
}
326+
private record AutoIdCreatingUploadCallback(String filename, Publisher<ByteBuffer> source,
327+
GridFSUploadOptions uploadOptions) implements ReactiveBucketCallback<ObjectId> {
349328

350329
@Override
351330
public GridFSUploadPublisher<ObjectId> doInBucket(GridFSBucket bucket) {
352331
return bucket.uploadFromPublisher(filename, source, uploadOptions);
353332
}
354333
}
355334

356-
private static class DeleteCallback implements ReactiveBucketCallback<Void> {
357-
358-
private final BsonValue id;
359-
360-
public DeleteCallback(BsonValue id) {
361-
this.id = id;
362-
}
335+
private record DeleteCallback(BsonValue id) implements ReactiveBucketCallback<Void> {
363336

364337
@Override
365338
public Publisher<Void> doInBucket(GridFSBucket bucket) {

0 commit comments

Comments
 (0)