in neo4j/src/main/java/org/hibernate/ogm/datastore/neo4j/dialect/impl/BaseNeo4jEntityQueries.java [189:232]
private Map<String, String> initRemoveEmbeddedPropertyQuery(EntityKeyMetadata entityKeyMetadata, TupleTypeContext tupleTypeContext) {
if ( tupleTypeContext == null ) {
return Collections.emptyMap();
}
Map<String, String> removeColumn = new HashMap<>();
for ( String column : tupleTypeContext.getSelectableColumns() ) {
if ( EmbeddedHelper.isPartOfEmbedded( column ) ) {
if ( !removeColumn.containsKey( column ) ) {
StringBuilder queryBuilder = new StringBuilder();
queryBuilder.append( "MATCH " );
appendEntityNode( "n", entityKeyMetadata, queryBuilder );
String[] path = EmbeddedHelper.split( column );
for ( int i = 0; i < path.length - 1; i++ ) {
queryBuilder.append( "-[:" );
appendRelationshipType( queryBuilder, path[i] );
queryBuilder.append( "]->" );
if ( i == path.length - 2 ) {
queryBuilder.append( "(e:EMBEDDED) " );
}
else {
queryBuilder.append( "(:EMBEDDED) " );
}
}
queryBuilder.append( "REMOVE e." );
escapeIdentifier( queryBuilder, path[path.length - 1] );
queryBuilder.append( " WITH e " );
queryBuilder.append( "MATCH (e)<-[erel]-(a) " );
queryBuilder.append( "WHERE length(keys(e))=0 AND NOT ((e)-->()) " );
queryBuilder.append( "DELETE e, erel " );
queryBuilder.append( "WITH a " );
queryBuilder.append( "OPTIONAL MATCH path=(a)<-[r*]-(b:EMBEDDED), (b)<-[brel]-(), (x) " );
queryBuilder.append( "WHERE a:EMBEDDED AND length(keys(a))=0 AND NOT((a)<-[*]-(:EMBEDDED)-->()) AND NOT ((a)<-[*]-(x)<-[*]-(b)) AND length(keys(b))>0 " );
queryBuilder.append( "FOREACH (r in relationships(path) | DELETE r) " );
queryBuilder.append( "FOREACH (n in nodes(path) | DELETE n) " );
queryBuilder.append( "WITH a " );
queryBuilder.append( "MATCH (a)<-[arel]-() " );
queryBuilder.append( "WHERE length(keys(a))=0 AND a:EMBEDDED " );
queryBuilder.append( "DELETE arel, a " );
removeColumn.put( column, queryBuilder.toString() );
}
}
}
return Collections.unmodifiableMap( removeColumn );
}