Skip to content

Commit

Permalink
Null Pointer Exception using refs with the YAML file
Browse files Browse the repository at this point in the history
  • Loading branch information
roimenashe committed Jun 18, 2024
1 parent b21833f commit 2b34490
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 20 deletions.
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 withKeyGetterAndSetterOf(String getterName, String setterName) {
if (this.classConfig.getKey() == null) {
this.classConfig.setKey(new KeyConfig());
Expand All @@ -240,12 +248,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 @@ -261,46 +269,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 @@ -309,6 +319,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 @@ -317,17 +328,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(),
ref.getBatchLoad() == null ? true : ref.getBatchLoad(),
ref.getType(), mapper);
addToMap = false;
}
} else {
Expand Down

0 comments on commit 2b34490

Please sign in to comment.