Skip to content

Commit

Permalink
OGM-1474 Replace CREATE UNIQUE in Cypher queries with MERGE
Browse files Browse the repository at this point in the history
  Running CREATE UNIQUE queries will generate the following warning:

  ```
  The RULE planner is not available in the current CYPHER version,
  the query has been run by an older CYPHER version. CREATE UNIQUE is unsupported
  for current CYPHER version, the query has been execute by an older CYPHER version
  ```
  • Loading branch information
DavideD committed May 24, 2018
1 parent 5128722 commit 758d766
Showing 1 changed file with 5 additions and 5 deletions.
Expand Up @@ -104,7 +104,7 @@ private static String initFindRelationshipQuery(EntityKeyMetadata ownerEntityKey

/*
* MATCH (o:ENTITY:table1 {id: {0}}), (t:ENTITY:table2 {id: {1}})
* CREATE UNIQUE (o) -[r:role {props}]-> (t)
* MERGE (o) -[r:role {props}]-> (t)
* RETURN r
*/
private static String initCreateRelationshipQuery(EntityKeyMetadata ownerEntityKeyMetadata, AssociationKeyMetadata associationKeyMetadata) {
Expand All @@ -115,7 +115,7 @@ private static String initCreateRelationshipQuery(EntityKeyMetadata ownerEntityK
queryBuilder.append( ", " );
offset += ownerEntityKeyMetadata.getColumnNames().length;
appendEntityNode( "t", targetEntityKeyMetadata, queryBuilder, offset );
queryBuilder.append( " CREATE UNIQUE (n)" );
queryBuilder.append( " MERGE (n)" );
queryBuilder.append( " -[r" );
queryBuilder.append( ":" );
appendRelationshipType( queryBuilder, associationKeyMetadata );
Expand Down Expand Up @@ -347,7 +347,7 @@ private boolean isCollectionOfPrimitives(String collectionRole, String[] embedde
* Example 1:
*
* MATCH (owner:ENTITY:MultiAddressAccount {login: {0}})
* CREATE UNIQUE (owner) -[r:addresses {name: {1}}]-> (target:EMBEDDED:`MultiAddressAccount_addresses` {city: {2}, country: {3}})
* MERGE (owner) -[r:addresses {name: {1}}]-> (target:EMBEDDED:`MultiAddressAccount_addresses` {city: {2}, country: {3}})
* RETURN r
*
* Example 2:
Expand All @@ -360,11 +360,11 @@ private void createRelationshipforCollectionOfComponents(AssociationKey associat
int offset = associationKey.getEntityKey().getColumnNames().length;
if ( isPartOfEmbedded( collectionRole ) ) {
String[] pathToEmbedded = appendEmbeddedNodes( collectionRole, queryBuilder );
queryBuilder.append( " CREATE UNIQUE (e) -[r:" );
queryBuilder.append( " MERGE (e) -[r:" );
appendRelationshipType( queryBuilder, pathToEmbedded[pathToEmbedded.length - 1] );
}
else {
queryBuilder.append( " CREATE UNIQUE (owner) -[r:" );
queryBuilder.append( " MERGE (owner) -[r:" );
appendRelationshipType( queryBuilder, collectionRole );
}
appendProperties( queryBuilder, associationKey.getMetadata().getRowKeyIndexColumnNames(), offset );
Expand Down

0 comments on commit 758d766

Please sign in to comment.