Skip to content

Commit

Permalink
Unrelated polishing.
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-simons committed Apr 21, 2020
1 parent 4fdda0b commit 2cf37f0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 25 deletions.
19 changes: 6 additions & 13 deletions core/src/main/java/org/neo4j/ogm/autoindex/AutoIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Arrays;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -348,24 +349,16 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}

AutoIndex autoIndex = (AutoIndex) o;

// Probably incorrect - comparing Object[] arrays with Arrays.equals
if (!Arrays.equals(properties, autoIndex.properties)) {
return false;
}
if (!owningType.equals(autoIndex.owningType)) {
return false;
}
return type == autoIndex.type;
return Arrays.equals(properties, autoIndex.properties) &&
owningType.equals(autoIndex.owningType) &&
type == autoIndex.type;
}

@Override
public int hashCode() {
int result = Arrays.hashCode(properties);
result = 31 * result + owningType.hashCode();
result = 31 * result + type.hashCode();
int result = Objects.hash(owningType, type);
result = 31 * result + Arrays.hashCode(properties);
return result;
}

Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/org/neo4j/ogm/context/EntityGraphMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private void deleteObsoleteRelationships() {
ClassInfo classInfo = metaData.classInfo(entity);
if (classInfo.hasVersionField()) {
FieldInfo field = classInfo.getVersionField();
builder.setVersionProperty(field.propertyName(), (Long) field.read(entity));
builder.setVersionProperty(field.property(), (Long) field.read(entity));
}
}

Expand Down Expand Up @@ -576,7 +576,7 @@ private RelationshipBuilder getRelationshipBuilder(Compiler cypherBuilder, Objec

ClassInfo classInfo = metaData.classInfo(entity);
if (classInfo.primaryIndexField() != null) {
relationshipBuilder.setPrimaryIdName(classInfo.primaryIndexField().propertyName());
relationshipBuilder.setPrimaryIdName(classInfo.primaryIndexField().property());
}
}
return relationshipBuilder;
Expand Down Expand Up @@ -721,22 +721,22 @@ private <T> void updateFieldsOnBuilder(Object entity, PropertyContainerBuilder<T
} else if (fieldInfo.isVersionField()) {
updateVersionField(entity, builder, fieldInfo);
} else {
builder.addProperty(fieldInfo.propertyName(), fieldInfo.readProperty(entity));
builder.addProperty(fieldInfo.property(), fieldInfo.readProperty(entity));
}
}
}

private <T> void updateVersionField(Object entity, PropertyContainerBuilder<T> builder, FieldInfo fieldInfo) {
Long version = (Long) fieldInfo.readProperty(entity);
builder.setVersionProperty(fieldInfo.propertyName(), version);
builder.setVersionProperty(fieldInfo.property(), version);

if (version == null) {
version = 0L;
} else {
version = version + 1;
}
fieldInfo.writeDirect(entity, version);
builder.addProperty(fieldInfo.propertyName(), version);
builder.addProperty(fieldInfo.property(), version);
}

private Object getStartEntity(ClassInfo relEntityClassInfo, Object relationshipEntity) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/neo4j/ogm/metadata/ClassInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ Class<?> getTypeParameterDescriptorForRelationship(String relationshipType, Dire
* @return If this class contains any fields/properties annotated with @Index.
*/
public boolean containsIndexes() {
return !getIndexFields().isEmpty() || !getCompositeIndexes().isEmpty();
return !(getIndexFields().isEmpty() && getCompositeIndexes().isEmpty());
}

/**
Expand Down
4 changes: 0 additions & 4 deletions core/src/main/java/org/neo4j/ogm/metadata/FieldInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,6 @@ public String relationshipType() {
return relationship();
}

public String propertyName() {
return property();
}

public boolean isComposite() {
return hasCompositeConverter();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public void shouldPreferAnnotatedFieldToGetterWhenReadingFromAnObject() {
.isEqualTo(domainObject.propertyWithDifferentAnnotatedGetter);

for (FieldInfo reader : readers) {
if (reader.propertyName().equals("differentAnnotationOnGetter")) {
if (reader.property().equals("differentAnnotationOnGetter")) {
assertThat(reader instanceof FieldInfo).isTrue();
}
}
Expand All @@ -215,7 +215,7 @@ public void shouldPreferMethodBasedAccessToFieldAccessWhenReadingFromObjectsWith
ClassInfo classInfo = this.domainInfo.getClass(DummyDomainObject.class.getName());

DummyDomainObject domainObject = new DummyDomainObject();
domainObject.nonAnnotatedTestProperty = new Double(30.16);
domainObject.nonAnnotatedTestProperty = 30.16;

FieldInfo objectAccess = classInfo.getFieldInfo("nonAnnotatedTestProperty");
assertThat(objectAccess).as("The resultant object accessor shouldn't be null").isNotNull();
Expand Down

0 comments on commit 2cf37f0

Please sign in to comment.