Skip to content

FMWK-467 Issue using refs with yaml file #161

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

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -183,34 +183,42 @@ public Builder withNamespace(String namespace) {
this.classConfig.setNamespace(namespace);
return this;
}

public Builder withShortName(String shortName) {
this.classConfig.setShortName(shortName);
return this;
}

public Builder withSet(String setName) {
this.classConfig.setSet(setName);
return this;
}

public Builder withTtl(int ttl) {
this.classConfig.setTtl(ttl);
return this;
}

public Builder withVersion(int version) {
this.classConfig.setVersion(version);
return this;
}

public Builder withSendKey(boolean sendKey) {
this.classConfig.setSendKey(sendKey);
return this;
}

public Builder withMapAll(boolean mapAll) {
this.classConfig.setMapAll(mapAll);
return this;
}

public Builder withDurableDelete(boolean durableDelete) {
this.classConfig.setDurableDelete(durableDelete);
return this;
}

public Builder withShortName(boolean sendKey) {
this.classConfig.setSendKey(sendKey);
return this;
Expand All @@ -221,7 +229,7 @@ public Builder withFactoryClassAndMethod(@NotNull Class<?> factoryClass, @NotNul
this.classConfig.setFactoryMethod(factoryMethod);
return this;
}

public Builder withKeyField(String fieldName) {
if (this.classConfig.getKey() == null) {
this.classConfig.setKey(new KeyConfig());
Expand All @@ -230,7 +238,7 @@ public Builder withKeyField(String fieldName) {
this.classConfig.getKey().setField(fieldName);
return this;
}

public Builder withKeyFieldAndStoreAsBin(String fieldName, boolean storeAsBin) {
if (this.classConfig.getKey() == null) {
this.classConfig.setKey(new KeyConfig());
Expand All @@ -240,7 +248,7 @@ public Builder withKeyFieldAndStoreAsBin(String fieldName, boolean storeAsBin) {
this.classConfig.getKey().setStoreAsBin(storeAsBin);
return this;
}

public Builder withKeyGetterAndSetterOf(String getterName, String setterName) {
if (this.classConfig.getKey() == null) {
this.classConfig.setKey(new KeyConfig());
Expand All @@ -250,12 +258,12 @@ public Builder withKeyGetterAndSetterOf(String getterName, String setterName) {
this.classConfig.getKey().setSetter(setterName);
return this;
}

public AeroBinConfig withFieldNamed(String fieldName) {
validateFieldExists(fieldName);
return new AeroBinConfig(this, fieldName);
}

private void mergeBinConfig(BinConfig config) {
List<BinConfig> bins = this.classConfig.getBins();
for (BinConfig thisBin : bins) {
Expand All @@ -271,46 +279,48 @@ public ClassConfig build() {
return this.classConfig;
}
}

public static class AeroBinConfig {
private final Builder builder;
private final BinConfig binConfig;

public AeroBinConfig(Builder builder, String fieldName) {
super();
this.builder = builder;
this.binConfig = new BinConfig();
this.binConfig.setField(fieldName);
}

public Builder mappingToBin(String name) {
this.binConfig.setName(name);
return this.end();
}

public Builder beingReferencedBy(AerospikeReference.ReferenceType type) {
this.binConfig.setReference(new ReferenceConfig(type, false));
this.binConfig.setReference(new ReferenceConfig(type, false, true));
return this.end();
}

public Builder beingLazilyReferencedBy(AerospikeReference.ReferenceType type) {
this.binConfig.setReference(new ReferenceConfig(type, true));
this.binConfig.setReference(new ReferenceConfig(type, true, true));
return this.end();
}

public Builder beingEmbeddedAs(AerospikeEmbed.EmbedType type) {
EmbedConfig embedConfig = new EmbedConfig();
embedConfig.setType(type);
this.binConfig.setEmbed(embedConfig);
return this.end();
}

public Builder beingEmbeddedAs(AerospikeEmbed.EmbedType type, AerospikeEmbed.EmbedType elementType) {
EmbedConfig embedConfig = new EmbedConfig();
embedConfig.setType(type);
embedConfig.setElementType(elementType);
this.binConfig.setEmbed(embedConfig);
return this.end();
}

public Builder beingEmbeddedAs(AerospikeEmbed.EmbedType type, AerospikeEmbed.EmbedType elementType, boolean saveKey) {
EmbedConfig embedConfig = new EmbedConfig();
embedConfig.setType(type);
Expand All @@ -319,6 +329,7 @@ public Builder beingEmbeddedAs(AerospikeEmbed.EmbedType type, AerospikeEmbed.Emb
this.binConfig.setEmbed(embedConfig);
return this.end();
}

/**
* Exclude the field. An excluded field doesn't need any other config, so return the parent.
* This allows for more natural syntax like:
Expand All @@ -327,17 +338,16 @@ public Builder beingEmbeddedAs(AerospikeEmbed.EmbedType type, AerospikeEmbed.Emb
* .withFieldName("ignoreMe").beingExcluded()
* .end()
* </code>
* @return
* @return Parent builder
*/
public Builder beingExcluded() {
this.binConfig.setExclude(true);
return this.end();
}

private Builder end() {
this.builder.mergeBinConfig(binConfig);
return this.builder;
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ public class ReferenceConfig {
private Boolean lazy;
private Boolean batchLoad;

public ReferenceConfig() {}
public ReferenceConfig(ReferenceType type, boolean lazy) {
public ReferenceConfig() {
}

public ReferenceConfig(ReferenceType type, boolean lazy, boolean batchLoad) {
this.type = type;
this.lazy = lazy;
this.batchLoad = batchLoad;
}

public ReferenceType getType() {
return type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,11 @@ private static TypeMapper getMapper(Class<?> clazz, AnnotatedType type, IBaseAer
} else {
// Reference
ReferenceConfig ref = binConfig.getReference();
typeMapper = new ObjectReferenceMapper(ClassCache.getInstance().loadClass(clazz, mapper), ref.getLazy(), ref.getBatchLoad(), ref.getType(), mapper);
typeMapper = new ObjectReferenceMapper(
ClassCache.getInstance().loadClass(clazz, mapper),
ref.getLazy() == null ? false : ref.getLazy(),
Copy link
Member Author

Choose a reason for hiding this comment

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

Can we assign defaults for lazy and batchLoad in ReferenceConfig class? that way if another place requires defaults it will be taken from a single point of truth

Copy link
Member Author

Choose a reason for hiding this comment

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

After consulting with Tim, we can improve it but at some point we will need a refactor of yaml/annotation config reading which will affect this place as well - I'm ok with the scope of this PR just because its only a single place of null check but later we will probably want to refactor/improve/clean some areas of the Java Object Mapper including this specific flow

ref.getBatchLoad() == null ? true : ref.getBatchLoad(),
ref.getType(), mapper);
addToMap = false;
}
} else {
Expand Down
Loading