Skip to content

Added configuration in code#147

Merged
tim-aero merged 4 commits intoaerospike:mainfrom
tim-aero:configuration-through-code
Jul 7, 2023
Merged

Added configuration in code#147
tim-aero merged 4 commits intoaerospike:mainfrom
tim-aero:configuration-through-code

Conversation

@tim-aero
Copy link
Contributor

@tim-aero tim-aero commented Jul 4, 2023

  • Builder pattern used to build configuration
  • Refactored the AeroMapper and ReactiveAeroMapper to extracts the builders into a common class whilse preserving the same interface
  • Added setters onto several configuration classes
  • Added unit tests for the configuration in code
  • Minor other tweaks

- Builder pattern used to build configuration
- Refactored the AeroMapper and ReactiveAeroMapper to extracts the
builders into a common class whilse preserving the same interface
- Added setters onto several configuration classes
- Added unit tests for the configuration in code
- Minor other tweaks
@tim-aero tim-aero requested review from reugn and roimenashe July 4, 2023 01:07
Comment on lines 162 to 163


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Comment on lines 33 to 34


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

}

enum PolicyType {
public static enum PolicyType {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for explicit static modifier

* @return this object
*/
public AbstractBuilder<T> addConverter(Object converter) {
GenericTypeMapper mapper = new GenericTypeMapper(converter);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename the local variable to not hide the class field

Comment on lines 177 to 179
if (!ConfigurationUtils.validateFieldOnClass(this.clazz, fieldName)) {
throw new AerospikeException(String.format("Field %s does not exist on class %s or its superclasses", fieldName, this.clazz));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be extracted to a validation method and reused (used twice in the class)

}

public AeroPolicyMapper<T> withReadPolicy(Policy policy) {
return new AeroPolicyMapper<T>(this, PolicyType.READ, policy);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diamond operator AeroPolicyMapper<>(...) can be used in return statements


@Test
public void testWithConfiguration() {
AeroMapper mapper = new AeroMapper.Builder(client)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current builder architecture using intermediate states is complicated. Please consider something like:

ClassConfiguration classConfigB = ClassConfiguration.Builder(B.class)
        .withFieldNamed("c")
        .beingEmbeddedAs(AerospikeEmbed.EmbedType.MAP)
        .build();
new AeroMapper.Builder(client)
        .withClassConfiguration(classConfigB)
        .build();

}

@Test
public void testWithInvalidConfiguarion() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public void testWithInvalidConfiguarion() {
public void testWithInvalidConfiguration() {

.withFieldNamed("c").beingEmbeddedAs(AerospikeEmbed.EmbedType.MAP)
.end()
.build();
Assertions.fail("Excpected invalid configuration to throw an error");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Assertions.fail("Excpected invalid configuration to throw an error");
Assertions.fail("Expected invalid configuration to throw an error");

tim-aero added 3 commits July 5, 2023 10:21
Refactored the ClassConfig builder to be a separate builder for a
cleaner experience
@tim-aero tim-aero requested a review from reugn July 5, 2023 20:43
@tim-aero tim-aero merged commit b8b852d into aerospike:main Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants