Skip to content
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

Merge 5.0 breaking changes into the main line of development #1268

Merged
merged 28 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9722162
Bump to 5.0.0-SNAPSHOT
jyemin Sep 14, 2023
9cb26b5
Remove Stream-related types from API
jyemin Sep 12, 2023
b1c89fb
Simplify StreamFactoryFactory implementations
jyemin Sep 15, 2023
94c321f
Remove deprecated ServerAddress methods (#1224)
jyemin Oct 21, 2023
e975980
Migrate bson tests from JUnit 4 to 5 (#1229)
jyemin Oct 24, 2023
86452b8
Remove deprecation of DBCursor#explain
jyemin Oct 25, 2023
775d40c
Remove dead code in ReplyHeader (#1231)
jyemin Nov 6, 2023
f75aaf6
Fix Groovy test
jyemin Nov 6, 2023
b783489
Fix ClusterFixture creation of NettyStreamFactoryFactory
jyemin Nov 6, 2023
58c8171
Remove Stream#shouldSupportAdditionalTimeout method (#1227)
jyemin Nov 6, 2023
f845b65
Remove deprecated methods in read preference classes
jyemin Oct 26, 2023
db1866a
Remove deprecated connection string option
jyemin Oct 26, 2023
a0ccaf7
Remove deprecated DBCollection methods
jyemin Oct 26, 2023
d83b259
Remove deprecated index-related methods
jyemin Nov 6, 2023
faba36c
Remove deprecated mapReduce options
jyemin Nov 6, 2023
78727c8
Remove getCluster method (#1245)
jyemin Nov 7, 2023
20bad8b
Remove deprecated constructors and factory methods
jyemin Nov 7, 2023
c5dd111
Remove deprecated oplogReplay-related methods (#1252)
jyemin Nov 9, 2023
0b26c04
Suppress deprecation warning
jyemin Nov 9, 2023
eed7815
Re-enable deprecation warnings
jyemin Nov 9, 2023
ac603f3
Make NettyStreamFactoryFactory implement AutoCloseable (#1244)
jyemin Nov 14, 2023
bea8ecf
Remove deprecated record annotations (#1249)
jyemin Nov 14, 2023
8c82359
Remove deprecated Parameterizable interface (#1248)
jyemin Nov 15, 2023
3298efd
Remove deprecated connection pool-event related classes/methods
jyemin Oct 26, 2023
f03a713
Remove deprecated event adapters
jyemin Oct 26, 2023
4726012
Removed deprecated MapCodec
jyemin Oct 26, 2023
1a84aaa
Rename MapCodecV2 to MapCodec
jyemin Oct 26, 2023
7b3312a
Make deprecated IterableCodec package-private
jyemin Oct 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 20 additions & 24 deletions bson-record-codec/src/main/org/bson/codecs/record/RecordCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@
import org.bson.codecs.RepresentationConfigurable;
import org.bson.codecs.configuration.CodecConfigurationException;
import org.bson.codecs.configuration.CodecRegistry;
import org.bson.codecs.record.annotations.BsonId;
import org.bson.codecs.record.annotations.BsonProperty;
import org.bson.codecs.record.annotations.BsonRepresentation;
import org.bson.codecs.pojo.annotations.BsonCreator;
import org.bson.codecs.pojo.annotations.BsonDiscriminator;
import org.bson.codecs.pojo.annotations.BsonExtraElements;
import org.bson.codecs.pojo.annotations.BsonId;
import org.bson.codecs.pojo.annotations.BsonIgnore;
import org.bson.codecs.pojo.annotations.BsonProperty;
import org.bson.codecs.pojo.annotations.BsonRepresentation;
import org.bson.diagnostics.Logger;
import org.bson.diagnostics.Loggers;

Expand Down Expand Up @@ -87,7 +91,6 @@ Object getValue(final Record record) throws InvocationTargetException, IllegalAc
return component.getAccessor().invoke(record);
}

@SuppressWarnings("deprecation")
private static Codec<?> computeCodec(final List<Type> typeParameters, final RecordComponent component,
final CodecRegistry codecRegistry) {
var rawType = toWrapper(resolveComponentType(typeParameters, component));
Expand All @@ -97,11 +100,9 @@ private static Codec<?> computeCodec(final List<Type> typeParameters, final Reco
: codecRegistry.get(rawType);
BsonType bsonRepresentationType = null;

if (component.isAnnotationPresent(BsonRepresentation.class)) {
bsonRepresentationType = component.getAnnotation(BsonRepresentation.class).value();
} else if (isAnnotationPresentOnField(component, org.bson.codecs.pojo.annotations.BsonRepresentation.class)) {
if (isAnnotationPresentOnField(component, BsonRepresentation.class)) {
bsonRepresentationType = getAnnotationOnField(component,
org.bson.codecs.pojo.annotations.BsonRepresentation.class).value();
BsonRepresentation.class).value();
}
if (bsonRepresentationType != null) {
if (codec instanceof RepresentationConfigurable<?> representationConfigurable) {
Expand Down Expand Up @@ -145,16 +146,11 @@ private static int getIndexOfTypeParameter(final String typeParameterName, final
recordClass.getName(), typeParameterName));
}

@SuppressWarnings("deprecation")
private static String computeFieldName(final RecordComponent component) {
if (component.isAnnotationPresent(BsonId.class)) {
if (isAnnotationPresentOnField(component, BsonId.class)) {
return "_id";
} else if (isAnnotationPresentOnField(component, org.bson.codecs.pojo.annotations.BsonId.class)) {
return "_id";
} else if (component.isAnnotationPresent(BsonProperty.class)) {
return component.getAnnotation(BsonProperty.class).value();
} else if (isAnnotationPresentOnField(component, org.bson.codecs.pojo.annotations.BsonProperty.class)) {
return getAnnotationOnField(component, org.bson.codecs.pojo.annotations.BsonProperty.class).value();
} else if (isAnnotationPresentOnField(component, BsonProperty.class)) {
return getAnnotationOnField(component, BsonProperty.class).value();
}
return component.getName();
}
Expand Down Expand Up @@ -182,14 +178,14 @@ private static <T extends Annotation> T getAnnotationOnField(final RecordCompone
}

private static void validateAnnotations(final RecordComponent component, final int index) {
validateAnnotationNotPresentOnType(component.getDeclaringRecord(), org.bson.codecs.pojo.annotations.BsonDiscriminator.class);
validateAnnotationNotPresentOnConstructor(component.getDeclaringRecord(), org.bson.codecs.pojo.annotations.BsonCreator.class);
validateAnnotationNotPresentOnMethod(component.getDeclaringRecord(), org.bson.codecs.pojo.annotations.BsonCreator.class);
validateAnnotationNotPresentOnFieldOrAccessor(component, org.bson.codecs.pojo.annotations.BsonIgnore.class);
validateAnnotationNotPresentOnFieldOrAccessor(component, org.bson.codecs.pojo.annotations.BsonExtraElements.class);
validateAnnotationOnlyOnField(component, index, org.bson.codecs.pojo.annotations.BsonId.class);
validateAnnotationOnlyOnField(component, index, org.bson.codecs.pojo.annotations.BsonProperty.class);
validateAnnotationOnlyOnField(component, index, org.bson.codecs.pojo.annotations.BsonRepresentation.class);
validateAnnotationNotPresentOnType(component.getDeclaringRecord(), BsonDiscriminator.class);
validateAnnotationNotPresentOnConstructor(component.getDeclaringRecord(), BsonCreator.class);
validateAnnotationNotPresentOnMethod(component.getDeclaringRecord(), BsonCreator.class);
validateAnnotationNotPresentOnFieldOrAccessor(component, BsonIgnore.class);
validateAnnotationNotPresentOnFieldOrAccessor(component, BsonExtraElements.class);
validateAnnotationOnlyOnField(component, index, BsonId.class);
validateAnnotationOnlyOnField(component, index, BsonProperty.class);
validateAnnotationOnlyOnField(component, index, BsonRepresentation.class);
}

private static <T extends Annotation> void validateAnnotationNotPresentOnType(final Class<?> clazz,
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.bson.codecs.configuration.CodecRegistry;
import org.bson.codecs.record.samples.TestRecordEmbedded;
import org.bson.codecs.record.samples.TestRecordParameterized;
import org.bson.codecs.record.samples.TestRecordWithDeprecatedAnnotations;
import org.bson.codecs.record.samples.TestRecordWithIllegalBsonCreatorOnConstructor;
import org.bson.codecs.record.samples.TestRecordWithIllegalBsonCreatorOnMethod;
import org.bson.codecs.record.samples.TestRecordWithIllegalBsonDiscriminatorOnRecord;
Expand Down Expand Up @@ -69,34 +68,6 @@

public class RecordCodecTest {

@Test
public void testRecordWithDeprecatedAnnotations() {
var codec = createRecordCodec(TestRecordWithDeprecatedAnnotations.class, Bson.DEFAULT_CODEC_REGISTRY);
var identifier = new ObjectId();
var testRecord = new TestRecordWithDeprecatedAnnotations("Lucas", 14, List.of("soccer", "basketball"), identifier.toHexString());

var document = new BsonDocument();
var writer = new BsonDocumentWriter(document);

// when
codec.encode(writer, testRecord, EncoderContext.builder().build());

// then
assertEquals(
new BsonDocument("_id", new BsonObjectId(identifier))
.append("name", new BsonString("Lucas"))
.append("hobbies", new BsonArray(List.of(new BsonString("soccer"), new BsonString("basketball"))))
.append("a", new BsonInt32(14)),
document);
assertEquals("_id", document.getFirstKey());

// when
var decoded = codec.decode(new BsonDocumentReader(document), DecoderContext.builder().build());

// then
assertEquals(testRecord, decoded);
}

@Test
public void testRecordWithPojoAnnotations() {
var codec = createRecordCodec(TestRecordWithPojoAnnotations.class, Bson.DEFAULT_CODEC_REGISTRY);
Expand Down Expand Up @@ -305,9 +276,9 @@ public void testRecordWithNestedParameterizedRecordWithDifferentlyOrderedTypePar

@Test
public void testRecordWithNulls() {
var codec = createRecordCodec(TestRecordWithDeprecatedAnnotations.class, Bson.DEFAULT_CODEC_REGISTRY);
var codec = createRecordCodec(TestRecordWithPojoAnnotations.class, Bson.DEFAULT_CODEC_REGISTRY);
var identifier = new ObjectId();
var testRecord = new TestRecordWithDeprecatedAnnotations(null, 14, null, identifier.toHexString());
var testRecord = new TestRecordWithPojoAnnotations(null, 14, null, identifier.toHexString());

var document = new BsonDocument();
var writer = new BsonDocumentWriter(document);
Expand Down Expand Up @@ -359,9 +330,9 @@ public void testExceptionsWithStoredNullsOnPrimitiveField() {

@Test
public void testRecordWithExtraData() {
var codec = createRecordCodec(TestRecordWithDeprecatedAnnotations.class, Bson.DEFAULT_CODEC_REGISTRY);
var codec = createRecordCodec(TestRecordWithPojoAnnotations.class, Bson.DEFAULT_CODEC_REGISTRY);
var identifier = new ObjectId();
var testRecord = new TestRecordWithDeprecatedAnnotations("Felix", 13, List.of("rugby", "badminton"), identifier.toHexString());
var testRecord = new TestRecordWithPojoAnnotations("Felix", 13, List.of("rugby", "badminton"), identifier.toHexString());

var document = new BsonDocument("_id", new BsonObjectId(identifier))
.append("nationality", new BsonString("British"))
Expand Down

This file was deleted.

25 changes: 2 additions & 23 deletions bson/src/main/org/bson/codecs/IterableCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,16 @@

/**
* Encodes and decodes {@code Iterable} objects.
*
* @since 3.3
* @deprecated Prefer {@link CollectionCodecProvider}
*/
@Deprecated
@SuppressWarnings("rawtypes")
public class IterableCodec implements Codec<Iterable>, OverridableUuidRepresentationCodec<Iterable> {
class IterableCodec implements Codec<Iterable>, OverridableUuidRepresentationCodec<Iterable> {

private final CodecRegistry registry;
private final BsonTypeCodecMap bsonTypeCodecMap;
private final Transformer valueTransformer;
private final UuidRepresentation uuidRepresentation;

/**
* Construct a new instance with the given {@code CodecRegistry} and {@code BsonTypeClassMap}.
*
* @param registry the non-null codec registry
* @param bsonTypeClassMap the non-null BsonTypeClassMap
*/
public IterableCodec(final CodecRegistry registry, final BsonTypeClassMap bsonTypeClassMap) {
this(registry, bsonTypeClassMap, null);
}

/**
* Construct a new instance with the given {@code CodecRegistry} and {@code BsonTypeClassMap}.
*
* @param registry the non-null codec registry
* @param bsonTypeClassMap the non-null BsonTypeClassMap
* @param valueTransformer the value Transformer
*/
public IterableCodec(final CodecRegistry registry, final BsonTypeClassMap bsonTypeClassMap, final Transformer valueTransformer) {
IterableCodec(final CodecRegistry registry, final BsonTypeClassMap bsonTypeClassMap, final Transformer valueTransformer) {
this(registry, new BsonTypeCodecMap(notNull("bsonTypeClassMap", bsonTypeClassMap), registry), valueTransformer,
UuidRepresentation.UNSPECIFIED);
}
Expand Down