Skip to content

Commit

Permalink
Make Cypher Neo4j 5 compatible.
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-simons authored and meistermeier committed Jul 5, 2022
1 parent 9527d87 commit 054d06c
Show file tree
Hide file tree
Showing 34 changed files with 352 additions and 601 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ build/
.gradle/
devenv.local
.vscode/
build.log
2 changes: 2 additions & 0 deletions api/src/main/java/org/neo4j/ogm/config/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,9 @@ public Builder verifyConnection(Boolean verifyConnection) {
*
* @param autoIndex auto index config
* @return the changed builder
* @deprecated The usage of this tool is deprecated. Please use a proper migration tooling, like neo4j-migrations or liquibase with the Neo4j plugin. The build-in auto index manager only supports Neo4j 4.4 and higher.
*/
@Deprecated
public Builder autoIndex(String autoIndex) {
this.autoIndex = autoIndex;
return this;
Expand Down
303 changes: 132 additions & 171 deletions core/src/main/java/org/neo4j/ogm/autoindex/AutoIndex.java

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions core/src/main/java/org/neo4j/ogm/autoindex/AutoIndexManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@
* @author Eric Spiegelberg
* @author Michael J. Simons
* @author Gerrit Meier
* @deprecated The usage of this tool is deprecated. Please use a proper migration tooling, like neo4j-migrations or liquibase with the Neo4j plugin.
*/
@Deprecated
public class AutoIndexManager {

/**
Expand Down Expand Up @@ -186,17 +188,17 @@ private List<AutoIndex> loadIndexesFromDB() {
List<AutoIndex> dbIndexes = new ArrayList<>();

session.doInTransaction(() -> {
Result query = session.query("CALL db.constraints()", emptyMap());
Result query = session.query("SHOW CONSTRAINTS YIELD *", emptyMap());
for (Map<String, Object> queryResult : query.queryResults()) {
Optional<AutoIndex> dbIndex = AutoIndex.parseConstraint(queryResult, databaseInfo.version);
Optional<AutoIndex> dbIndex = AutoIndex.parseConstraint(queryResult);
dbIndex.ifPresent(dbIndexes::add);
}
}, READ_ONLY);

session.doInTransaction(() -> {
Result query = session.query("CALL db.indexes()", emptyMap());
Result query = session.query("SHOW INDEXES YIELD *", emptyMap());
for (Map<String, Object> queryResult : query.queryResults()) {
Optional<AutoIndex> dbIndex = AutoIndex.parseIndex(queryResult, databaseInfo.version);
Optional<AutoIndex> dbIndex = AutoIndex.parseIndex(queryResult);
dbIndex.ifPresent(dbIndexes::add);
}
}, READ_ONLY);
Expand Down Expand Up @@ -279,8 +281,8 @@ private static Set<AutoIndex> initialiseAutoIndex(MetaData metaData) {
properties.add(p);
}
});
AutoIndex autoIndex = new AutoIndex(type, owningType,
properties.toArray(new String[properties.size()]));
AutoIndex autoIndex = new AutoIndex(classInfo.getUnderlyingClass(), type, owningType,
properties.toArray(new String[0]), null);
LOGGER.debug("Adding composite index [description={}]", autoIndex);
indexMetadata.add(autoIndex);
}
Expand All @@ -300,7 +302,7 @@ private static Set<AutoIndex> initialiseAutoIndex(MetaData metaData) {
continue;
}

final AutoIndex autoIndex = new AutoIndex(type, owningType, new String[] { fieldInfo.property() });
final AutoIndex autoIndex = new AutoIndex(classInfo.getUnderlyingClass(), type, owningType, new String[] { fieldInfo.property() }, null);
LOGGER.debug("Adding Index [description={}]", autoIndex);
indexMetadata.add(autoIndex);
}
Expand All @@ -311,8 +313,8 @@ private static Set<AutoIndex> initialiseAutoIndex(MetaData metaData) {
IndexType type = classInfo.isRelationshipEntity() ?
IndexType.REL_PROP_EXISTENCE_CONSTRAINT : IndexType.NODE_PROP_EXISTENCE_CONSTRAINT;

AutoIndex autoIndex = new AutoIndex(type, owningType,
new String[] { requiredField.property() });
AutoIndex autoIndex = new AutoIndex(classInfo.getUnderlyingClass(), type, owningType,
new String[] { requiredField.property() }, null);

LOGGER.debug("Adding required constraint [description={}]", autoIndex);
indexMetadata.add(autoIndex);
Expand Down
8 changes: 7 additions & 1 deletion core/src/main/java/org/neo4j/ogm/autoindex/IndexType.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.neo4j.ogm.autoindex;

import java.util.EnumSet;

/**
* @author Frantisek Hartman
*/
Expand Down Expand Up @@ -51,6 +53,10 @@ enum IndexType {
/**
* Relationship property existence constraint
*/
REL_PROP_EXISTENCE_CONSTRAINT,
REL_PROP_EXISTENCE_CONSTRAINT;

boolean isConstraint() {
return EnumSet.of(UNIQUE_CONSTRAINT, NODE_KEY_CONSTRAINT, NODE_PROP_EXISTENCE_CONSTRAINT,
REL_PROP_EXISTENCE_CONSTRAINT).contains(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public String expression(String nodeIdentifier, String filteredProperty,
String latitude = nodeIdentifier + LATITUDE_PROPERTY_SUFFIX;
String longitude = nodeIdentifier + LONGITUDE_PROPERTY_SUFFIX;
return String
.format("distance(point({latitude: %s, longitude: %s}),point({latitude: $lat, longitude: $lon})) " +
.format("point.distance(point({latitude: %s, longitude: %s}),point({latitude: $lat, longitude: $lon})) " +
"%s $distance ", latitude, longitude, operator.getValue());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public String expression(String nodeIdentifier, String filteredProperty,
String comparisonOperator = operator.getValue();

return String.format(
"distance($%s,%s) %s $%s ",
"point.distance($%s,%s) %s $%s ",
OGM_POINT_PARAMETER, pointPropertyOfEntity, comparisonOperator, DISTANCE_VALUE_PARAMETER);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public String expression(String nodeIdentifier, String filteredProperty,
if (operator == IS_NULL) {
return String.format("%s.`%s` IS NULL ", nodeIdentifier, filteredProperty);
} else if (operator == EXISTS) {
return String.format("EXISTS(%s.`%s`) ", nodeIdentifier, filteredProperty);
return String.format("%s.`%s` IS NOT NULL ", nodeIdentifier, filteredProperty);
} else if (operator == IS_TRUE) {
return String.format("%s.`%s` = true ", nodeIdentifier, filteredProperty);
} else {
Expand Down
7 changes: 4 additions & 3 deletions core/src/main/java/org/neo4j/ogm/session/SessionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static java.util.Objects.*;
import static org.neo4j.ogm.config.AutoIndexMode.*;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CopyOnWriteArrayList;
Expand Down Expand Up @@ -164,7 +165,7 @@ public void register(EventListener eventListener) {
}

/**
* Removes the the specified listener from <code>this SessionFactory</code>.
* Removes the specified listener from <code>this SessionFactory</code>.
* Only Session instances created after this call are affected.
*
* @param eventListener The event listener to deregister.
Expand Down Expand Up @@ -264,10 +265,10 @@ private static Driver newConfiguredDriverInstance(Configuration configuration) {
String driverClassName = configuration.getDriverClassName();
try {
final Class<?> driverClass = Class.forName(driverClassName);
final Driver driver = (Driver) driverClass.newInstance();
final Driver driver = (Driver) driverClass.getConstructor().newInstance();
driver.configure(configuration);
return driver;
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
throw new ConfigurationException("Could not load driver class " + driverClassName, e);
}
}
Expand Down
173 changes: 0 additions & 173 deletions core/src/test/java/org/neo4j/ogm/autoindex/AutoIndexTest.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class TestContainersTestBase {

private static final boolean isEnterpriseEdition;

private static final String DEFAULT_IMAGE = "neo4j:4.3.7";
private static final String DEFAULT_IMAGE = "neo4j:4.4.6";

private static final String SYS_PROPERTY_ACCEPT_AND_USE_COMMERCIAL_EDITION = "NEO4J_OGM_NEO4J_ACCEPT_AND_USE_COMMERCIAL_EDITION";

Expand Down
Loading

0 comments on commit 054d06c

Please sign in to comment.