List<String> selectableColumns = tupleTypeContext.getSelectableColumns(); for ( String column : selectableColumns ) { if ( isPartOfEmbedded( column ) ) { String embeddedPath = column.substring( 0, column.lastIndexOf( "." ) ); if ( !queries.containsKey( column ) ) { String[] columnPath = EmbeddedHelper.split( column ); StringBuilder queryBuilder = new StringBuilder( "MATCH " ); appendEntityNode( ENTITY_ALIAS, ownerEntityKeyMetadata, queryBuilder );
/** * A regular embedded is an element that it is embedded but it is not a key or a collection. * * @param keyColumnNames the column names representing the identifier of the entity * @param column the column we want to check * @return {@code true} if the column represent an attribute of a regular embedded element, {@code false} otherwise */ public static boolean isPartOfRegularEmbedded(String[] keyColumnNames, String column) { return isPartOfEmbedded( column ) && !ArrayHelper.contains( keyColumnNames, column ); }
private static String[] appendEmbeddedNodes(String path, StringBuilder queryBuilder) { String[] columns = split( path ); for ( int i = 0; i < columns.length - 1; i++ ) { queryBuilder.append( " - [:" ); appendRelationshipType( queryBuilder, columns[i] ); queryBuilder.append( "] ->" ); if ( i < columns.length - 2 ) { queryBuilder.append( " (e" ); queryBuilder.append( i ); queryBuilder.append( ":" ); queryBuilder.append( EMBEDDED ); queryBuilder.append( ") MERGE (e" ); queryBuilder.append( i ); queryBuilder.append( ")" ); } } queryBuilder.append( " (e:" ); queryBuilder.append( EMBEDDED ); queryBuilder.append( ")" ); return columns; }
private void createRelationshipForCollectionOfPrimitivesOrMap(AssociationKey associationKey, String collectionRole, String[] columnNames, StringBuilder queryBuilder) { String relationshipType = collectionRole; if ( isPartOfEmbedded( collectionRole ) ) { queryBuilder.append( " MERGE (owner) " ); String[] pathToEmbedded = appendEmbeddedNodes( collectionRole, queryBuilder ); relationshipType = pathToEmbedded[pathToEmbedded.length - 1]; queryBuilder.append( " CREATE (e) -[r:" ); } else { queryBuilder.append( " CREATE (owner) -[r:" ); } escapeIdentifier( queryBuilder, relationshipType ); queryBuilder.append( "]->(new:" ); queryBuilder.append( EMBEDDED ); queryBuilder.append( ":" ); escapeIdentifier( queryBuilder, associationKey.getTable() ); queryBuilder.append( " {" ); // THe name of the property is the same as the relationship type escapeIdentifier( queryBuilder, relationshipType ); queryBuilder.append( ": {" ); queryBuilder.append( columnNames.length ); queryBuilder.append( "}" ); queryBuilder.append( "}" ); queryBuilder.append( ")" ); queryBuilder.append( " RETURN r" ); }
private static String[] appendEmbeddedNodes(String path, StringBuilder queryBuilder) { String[] columns = split( path ); for ( int i = 0; i < columns.length - 1; i++ ) { queryBuilder.append( " - [:" ); appendRelationshipType( queryBuilder, columns[i] ); queryBuilder.append( "] ->" ); if ( i < columns.length - 2 ) { queryBuilder.append( " (e" ); queryBuilder.append( i ); queryBuilder.append( ":" ); queryBuilder.append( EMBEDDED ); queryBuilder.append( ") MERGE (e" ); queryBuilder.append( i ); queryBuilder.append( ")" ); } } queryBuilder.append( " (e:" ); queryBuilder.append( EMBEDDED ); queryBuilder.append( ")" ); return columns; }
private static Node embeddedAssociationOwner(Relationship relationship, String collectionRole) { if ( isPartOfEmbedded( collectionRole ) ) { String[] split = EmbeddedHelper.split( collectionRole ); Node ownerNode = relationship.getStartNode(); for ( int i = 1; i < split.length; i++ ) { String type = split[split.length - i - 1]; Relationship next = ownerNode.getRelationships( Direction.INCOMING, withName( type ) ).iterator().next(); ownerNode = next.getStartNode(); } return ownerNode; } else { return relationship.getStartNode(); } }
private void createRelationshipForCollectionOfPrimitivesOrMap(AssociationKey associationKey, String collectionRole, String[] columnNames, StringBuilder queryBuilder) { String relationshipType = collectionRole; if ( isPartOfEmbedded( collectionRole ) ) { queryBuilder.append( " MERGE (owner) " ); String[] pathToEmbedded = appendEmbeddedNodes( collectionRole, queryBuilder ); relationshipType = pathToEmbedded[pathToEmbedded.length - 1]; queryBuilder.append( " CREATE (e) -[r:" ); } else { queryBuilder.append( " CREATE (owner) -[r:" ); } escapeIdentifier( queryBuilder, relationshipType ); int offset = ownerEntityKeyMetadata.getColumnNames().length; appendProperties( queryBuilder, associationKey.getMetadata().getRowKeyIndexColumnNames(), offset ); queryBuilder.append( "]-> (new:" ); queryBuilder.append( EMBEDDED ); queryBuilder.append( ":" ); escapeIdentifier( queryBuilder, associationKey.getTable() ); queryBuilder.append( " {" ); // THe name of the property is the same as the relationship type escapeIdentifier( queryBuilder, relationshipType ); queryBuilder.append( ": {" ); offset += associationKey.getMetadata().getRowKeyIndexColumnNames().length; queryBuilder.append( offset ); queryBuilder.append( "}" ); queryBuilder.append( "}" ); queryBuilder.append( ")" ); queryBuilder.append( " RETURN r" ); }
private static String[] appendEmbeddedNodes(String path, StringBuilder queryBuilder) { String[] columns = split( path ); for ( int i = 0; i < columns.length - 1; i++ ) { queryBuilder.append( " - [:" ); appendRelationshipType( queryBuilder, columns[i] ); queryBuilder.append( "] ->" ); if ( i < columns.length - 2 ) { queryBuilder.append( " (e" ); queryBuilder.append( i ); queryBuilder.append( ":" ); queryBuilder.append( EMBEDDED ); queryBuilder.append( ") MERGE (e" ); queryBuilder.append( i ); queryBuilder.append( ")" ); } } queryBuilder.append( " (e:" ); queryBuilder.append( EMBEDDED ); queryBuilder.append( ")" ); return columns; }
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( "-[:" );
if ( isPartOfEmbedded( targetColumnName ) ) { fetchEmbeddedProperties( associationKey, properties, targetNode, associationColumn, targetColumnName );
private Object readEmbeddedProperty(String column) { String[] split = split( column ); Node embeddedNode = node; for ( int i = 0; i < split.length - 1; i++ ) { String relType = split[i]; Iterator<Relationship> rels = embeddedNode.getRelationships( Direction.OUTGOING, withName( relType ) ).iterator(); if ( rels.hasNext() ) { embeddedNode = rels.next().getEndNode(); } else { return null; } } return readProperty( embeddedNode, split[split.length - 1] ); }
private StringBuilder findAssociationPartialQuery(String relationshipType, AssociationKeyMetadata associationKeyMetadata) { StringBuilder queryBuilder = new StringBuilder( findAssociationPartialQuery ); if ( isPartOfEmbedded( relationshipType ) ) { String[] path = split( relationshipType ); int index = 0; for ( String embeddedRelationshipType : path ) {
private void appendSubTree(EmbeddedNodesTree tree, String currentProperty, String relationshipType, int index) { EmbeddedNodesTree subTree = tree.getChild( relationshipType ); if ( subTree == null ) { subTree = new EmbeddedNodesTree(); tree.addChild( relationshipType, subTree ); } if ( isPartOfEmbedded( currentProperty ) ) { int firstDot = currentProperty.indexOf( "." ); String relType = currentProperty.substring( 0, firstDot ); String subProperty = currentProperty.substring( firstDot + 1 ); appendSubTree( tree, subProperty, relType, index ); } else { EmbeddedNodeProperty property = new EmbeddedNodeProperty(); property.setColumn( currentProperty ); property.setParam( index ); subTree.addProperty( property ); } }
private void removeTupleOperation(EntityKey entityKey, Node node, TupleOperation operation, TupleContext tupleContext, Set<String> processedAssociationRoles) { if ( !tupleContext.getTupleTypeContext().isPartOfAssociation( operation.getColumn() ) ) { if ( isPartOfRegularEmbedded( entityKey.getColumnNames(), operation.getColumn() ) ) { // Embedded node String[] split = split( operation.getColumn() ); removePropertyForEmbedded( node, split, 0 ); } else if ( node.hasProperty( operation.getColumn() ) ) { node.removeProperty( operation.getColumn() ); } } // if the column represents a to-one association, remove the relationship else { String associationRole = tupleContext.getTupleTypeContext().getRole( operation.getColumn() ); if ( !processedAssociationRoles.contains( associationRole ) ) { Iterator<Relationship> relationships = node.getRelationships( withName( associationRole ) ).iterator(); if ( relationships.hasNext() ) { relationships.next().delete(); } } } }
if ( isPartOfEmbedded( targetColumnName ) ) { String[] split = split( targetColumnName ); boolean found = true; for ( int i = 0; i < split.length - 1; i++ ) {
private void appendSubTree(EmbeddedNodesTree tree, String currentProperty, String relationshipType, int index) { EmbeddedNodesTree subTree = tree.getChild( relationshipType ); if ( subTree == null ) { subTree = new EmbeddedNodesTree(); tree.addChild( relationshipType, subTree ); } if ( isPartOfEmbedded( currentProperty ) ) { int firstDot = currentProperty.indexOf( "." ); String relType = currentProperty.substring( 0, firstDot ); String subProperty = currentProperty.substring( firstDot + 1 ); appendSubTree( tree, subProperty, relType, index ); } else { EmbeddedNodeProperty property = new EmbeddedNodeProperty(); property.setColumn( currentProperty ); property.setParam( index ); subTree.addProperty( property ); } }
private void createRelationshipforCollectionOfComponents(AssociationKey associationKey, String collectionRole, String[] embeddedColumnNames, Object[] embeddedColumnValues, StringBuilder queryBuilder) { int offset = associationKey.getEntityKey().getColumnNames().length; EmbeddedNodesTree tree = createEmbeddedTree( collectionRole, embeddedColumnNames, embeddedColumnValues, offset ); if ( isPartOfEmbedded( collectionRole ) ) { String[] pathToEmbedded = appendEmbeddedNodes( collectionRole, queryBuilder ); queryBuilder.append( " CREATE (e) -[r:" );
private void createRelationshipforCollectionOfComponents(AssociationKey associationKey, String collectionRole, String[] embeddedColumnNames, Object[] embeddedColumnValues, StringBuilder queryBuilder) { int offset = associationKey.getEntityKey().getColumnNames().length; if ( isPartOfEmbedded( collectionRole ) ) { String[] pathToEmbedded = appendEmbeddedNodes( collectionRole, queryBuilder ); queryBuilder.append( " MERGE (e) -[r:" );