in neo4j/src/main/java/org/hibernate/ogm/datastore/neo4j/embedded/dialect/impl/EmbeddedNeo4jTupleAssociationSnapshot.java [38:111]
private static Map<String, Object> collectProperties(Relationship relationship, AssociationKey associationKey, AssociatedEntityKeyMetadata associatedEntityKeyMetadata) {
Map<String, Object> properties = new HashMap<String, Object>();
String[] rowKeyColumnNames = associationKey.getMetadata().getRowKeyColumnNames();
Node ownerNode = findOwnerNode( relationship, associationKey );
Node targetNode = findTargetNode( relationship, associationKey, ownerNode );
// Index columns
for ( int i = 0; i < rowKeyColumnNames.length; i++ ) {
if ( relationship.hasProperty( rowKeyColumnNames[i] ) ) {
properties.put( rowKeyColumnNames[i], relationship.getProperty( rowKeyColumnNames[i] ) );
}
}
// Properties stored in the target side of the association
for ( String associationColumn : associatedEntityKeyMetadata.getAssociationKeyColumns() ) {
String targetColumnName = associatedEntityKeyMetadata.getCorrespondingEntityKeyColumn( associationColumn );
if ( isPartOfEmbedded( targetColumnName ) ) {
// Embedded column
String collectionRole = associationKey.getMetadata().getCollectionRole();
if ( targetColumnName.equals( collectionRole ) ) {
// Ex: @ElementCollection List<String> examples
targetColumnName = targetColumnName.substring( targetColumnName.lastIndexOf( "." ) + 1 );
if ( targetNode.hasProperty( targetColumnName ) ) {
properties.put( associationColumn, targetNode.getProperty( targetColumnName ) );
}
}
else if ( targetNode.hasProperty( targetColumnName ) ) {
// Embedded id
properties.put( associationColumn, targetNode.getProperty( targetColumnName ) );
}
else {
// Ex: @ElementCollection List<Embedded> examples
Node embeddedNode = targetNode;
if ( targetColumnName.startsWith( collectionRole ) ) {
targetColumnName = targetColumnName.substring( collectionRole.length() + 1 );
}
String[] split = split( targetColumnName );
boolean found = true;
for ( int i = 0; i < split.length - 1; i++ ) {
Iterator<Relationship> iterator = embeddedNode.getRelationships( Direction.OUTGOING, withName( split[i] ) ).iterator();
if ( iterator.hasNext() ) {
embeddedNode = iterator.next().getEndNode();
}
else {
found = false;
break;
}
}
if ( found ) {
targetColumnName = targetColumnName.substring( targetColumnName.lastIndexOf( "." ) + 1 );
if ( embeddedNode.hasProperty( targetColumnName ) ) {
properties.put( associationColumn, embeddedNode.getProperty( targetColumnName ) );
}
}
}
}
else {
if ( targetNode.hasProperty( targetColumnName ) ) {
properties.put( associationColumn, targetNode.getProperty( targetColumnName ) );
}
}
}
// Property stored in the owner side of the association
for ( int i = 0; i < associationKey.getColumnNames().length; i++ ) {
if ( ownerNode.hasProperty( associationKey.getEntityKey().getColumnNames()[i] ) ) {
properties.put( associationKey.getColumnNames()[i], ownerNode.getProperty( associationKey.getEntityKey().getColumnNames()[i] ) );
}
}
return properties;
}