Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
Reformat code, revise nullability declarations.

See #4709
Original pull request: #4721
  • Loading branch information
mp911de committed Jun 11, 2024
1 parent 4ca008d commit bbef940
Showing 1 changed file with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected DBRef asReference(@Nullable Object constant) {
return asReference(constant, null);
}

protected DBRef asReference(Object constant, Path<?> path) {
protected DBRef asReference(Object constant, @Nullable Path<?> path) {
return converter.toDBRef(constant, getPropertyForPotentialDbRef(path));
}

Expand All @@ -135,7 +135,7 @@ protected String asDBKey(@Nullable Operation<?> expr, int index) {

MongoPersistentProperty property = getPropertyFor(path);

return property.isIdProperty() ? key.replaceAll("." + ID_KEY + "$", "") : key;
return property != null && property.isIdProperty() ? key.replaceAll("." + ID_KEY + "$", "") : key;
}

@Override
Expand All @@ -144,20 +144,26 @@ protected boolean isId(Path<?> arg) {
return propertyFor == null ? super.isId(arg) : propertyFor.isIdProperty();
}

@Override
@Nullable
protected Object convert(@Nullable Path<?> path, @Nullable Constant<?> constant) {

if (constant == null) {
return null;
}

if (!isReference(path)) {

MongoPersistentProperty property = getPropertyFor(path);
if(property == null) {
if (property == null) {
return super.convert(path, constant);
}

if(property.isIdProperty()) {
if (property.isIdProperty()) {
return mapper.convertId(constant.getConstant(), property.getFieldType());
}

if(property.hasExplicitWriteTarget()) {
if (property.hasExplicitWriteTarget()) {
return converter.convertToMongoType(constant.getConstant(), TypeInformation.of(property.getFieldType()));
}

Expand All @@ -166,17 +172,19 @@ protected Object convert(@Nullable Path<?> path, @Nullable Constant<?> constant)

MongoPersistentProperty property = getPropertyFor(path);

if (property.isDocumentReference()) {
return converter.toDocumentPointer(constant.getConstant(), property).getPointer();
}
if (property != null) {
if (property.isDocumentReference()) {
return converter.toDocumentPointer(constant.getConstant(), property).getPointer();
}

if (property.isIdProperty()) {
if (property.isIdProperty()) {

MongoPersistentProperty propertyForPotentialDbRef = getPropertyForPotentialDbRef(path);
if (propertyForPotentialDbRef != null && propertyForPotentialDbRef.isDocumentReference()) {
return converter.toDocumentPointer(constant.getConstant(), propertyForPotentialDbRef).getPointer();
MongoPersistentProperty propertyForPotentialDbRef = getPropertyForPotentialDbRef(path);
if (propertyForPotentialDbRef != null && propertyForPotentialDbRef.isDocumentReference()) {
return converter.toDocumentPointer(constant.getConstant(), propertyForPotentialDbRef).getPointer();
}
return asReference(constant.getConstant(), path.getMetadata().getParent());
}
return asReference(constant.getConstant(), path.getMetadata().getParent());
}

return asReference(constant.getConstant(), path);
Expand All @@ -203,7 +211,8 @@ private MongoPersistentProperty getPropertyFor(Path<?> path) {
* @param path
* @return
*/
private MongoPersistentProperty getPropertyForPotentialDbRef(Path<?> path) {
@Nullable
private MongoPersistentProperty getPropertyForPotentialDbRef(@Nullable Path<?> path) {

if (path == null) {
return null;
Expand Down

0 comments on commit bbef940

Please sign in to comment.