Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OGM-692 [Neo4j] Fix queries on embedded properties
- Loading branch information
Showing
6 changed files
with
318 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...src/main/java/org/hibernate/ogm/datastore/neo4j/query/parsing/impl/EmbeddedAliasTree.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Hibernate OGM, Domain model persistence for NoSQL datastores | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.ogm.datastore.neo4j.query.parsing.impl; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* Tree structure that can be used to store alias of embedded components in Neo4j. | ||
* <p> | ||
* For example, a path to two properties like: | ||
* <ol> | ||
* <li>n.first.anotherEmbedded</li> | ||
* <li>n.second.anotherEmbedded</li> | ||
* </ol> | ||
* Might be represented with the following structure: | ||
* <pre> | ||
* n (alias = n)|- first (alias = n_0) -- anotherEmbedded (alias = n_0_0) | ||
* | | ||
* -- second (alias = n_1) -- anotherEmbedded (alias = n_0_1) | ||
* </pre> | ||
* | ||
* @author Davide D'Alto | ||
*/ | ||
public class EmbeddedAliasTree { | ||
|
||
private final String name; | ||
private final String alias; | ||
private final List<EmbeddedAliasTree> children; | ||
|
||
/** | ||
* Creates a tree node. | ||
* | ||
* @param alias the alias used for the embedded | ||
* @param name the name of the property representing the emebedded | ||
*/ | ||
public EmbeddedAliasTree(String alias, String name) { | ||
this.name = name; | ||
this.alias = alias; | ||
this.children = new ArrayList<EmbeddedAliasTree>(); | ||
} | ||
|
||
public EmbeddedAliasTree findChild(String name) { | ||
for ( EmbeddedAliasTree child : children ) { | ||
if ( child.getName().equals( name ) ) { | ||
return child; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void addChild(EmbeddedAliasTree embeddedNode) { | ||
children.add( embeddedNode ); | ||
} | ||
|
||
public String getAlias() { | ||
return alias; | ||
} | ||
|
||
public List<EmbeddedAliasTree> getChildren() { | ||
return Collections.unmodifiableList( children ); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder builder = new StringBuilder(); | ||
builder.append( "[name=" ); | ||
builder.append( name ); | ||
builder.append( ", alias=" ); | ||
builder.append( alias ); | ||
builder.append( "]" ); | ||
return builder.toString(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.