private boolean hasRowIndex(AssociationKey associationKey) { return associationKey.getMetadata().getRowKeyIndexColumnNames().length > 0; }
/** * @param associationMetadata * @return index column name for indexed embedded collections or null for collections without index */ private String findIndexColumnName(AssociationKeyMetadata associationMetadata) { String indexColumnName = null; if ( associationMetadata.getAssociationType() == AssociationType.SET || associationMetadata.getAssociationType() == AssociationType.BAG ) { // String cols[] = associationMetadata.getColumnsWithoutKeyColumns( // Arrays.asList( associationMetadata.getRowKeyColumnNames() ) // ); } else { if ( associationMetadata.getRowKeyIndexColumnNames().length > 1 ) { throw new UnsupportedOperationException( "Multiple index columns not implemented yet" ); } indexColumnName = associationMetadata.getRowKeyIndexColumnNames()[0]; } return indexColumnName; }
private Object[] relationshipProperties(AssociationKey associationKey, AssociationOperation action) { Object[] relationshipProperties = new Object[associationKey.getMetadata().getRowKeyIndexColumnNames().length]; String[] indexColumns = associationKey.getMetadata().getRowKeyIndexColumnNames(); for ( int i = 0; i < indexColumns.length; i++ ) { relationshipProperties[i] = action.getValue().get( indexColumns[i] ); } return relationshipProperties; }
private Object[] relationshipProperties(AssociationKey associationKey, Tuple associationRow) { String[] indexColumns = associationKey.getMetadata().getRowKeyIndexColumnNames(); Object[] properties = new Object[indexColumns.length]; for ( int i = 0; i < indexColumns.length; i++ ) { String propertyName = indexColumns[i]; properties[i] = associationRow.get( propertyName ); } return properties; }
private Object[] relationshipProperties(AssociationKey associationKey, AssociationOperation action) { Object[] relationshipProperties = new Object[associationKey.getMetadata().getRowKeyIndexColumnNames().length]; String[] indexColumns = associationKey.getMetadata().getRowKeyIndexColumnNames(); for ( int i = 0; i < indexColumns.length; i++ ) { relationshipProperties[i] = action.getValue().get( indexColumns[i] ); } return relationshipProperties; }
private Object[] relationshipProperties(AssociationKey associationKey, Tuple associationRow) { String[] indexColumns = associationKey.getMetadata().getRowKeyIndexColumnNames(); Object[] properties = new Object[indexColumns.length]; for ( int i = 0; i < indexColumns.length; i++ ) { String propertyName = indexColumns[i]; properties[i] = associationRow.get( propertyName ); } return properties; }
private static String initFindRelationshipQuery(EntityKeyMetadata ownerEntityKeyMetadata, AssociationKeyMetadata associationKeyMetadata) { int offset = 0; StringBuilder queryBuilder = new StringBuilder( "MATCH " ); queryBuilder.append( "(n:" ); queryBuilder.append( ENTITY ); queryBuilder.append( ":" ); appendLabel( ownerEntityKeyMetadata, queryBuilder ); appendProperties( ownerEntityKeyMetadata, queryBuilder ); queryBuilder.append( ") - " ); queryBuilder.append( "[r" ); queryBuilder.append( ":" ); appendRelationshipType( queryBuilder, associationKeyMetadata ); offset = ownerEntityKeyMetadata.getColumnNames().length; if ( associationKeyMetadata.getRowKeyIndexColumnNames().length > 0 ) { appendProperties( queryBuilder, associationKeyMetadata.getRowKeyIndexColumnNames(), offset ); queryBuilder.append( "] - (t" ); } else { queryBuilder.append( "] - (t" ); appendProperties( queryBuilder, associationKeyMetadata.getAssociatedEntityKeyMetadata().getEntityKeyMetadata().getColumnNames(), offset ); } queryBuilder.append( ")" ); queryBuilder.append( " RETURN r" ); return queryBuilder.toString(); }
private static String initCreateRelationshipQuery(EntityKeyMetadata ownerEntityKeyMetadata, AssociationKeyMetadata associationKeyMetadata) { EntityKeyMetadata targetEntityKeyMetadata = associationKeyMetadata.getAssociatedEntityKeyMetadata().getEntityKeyMetadata(); int offset = 0; StringBuilder queryBuilder = new StringBuilder( "MATCH " ); appendEntityNode( "n", ownerEntityKeyMetadata, queryBuilder ); queryBuilder.append( ", " ); offset += ownerEntityKeyMetadata.getColumnNames().length; appendEntityNode( "t", targetEntityKeyMetadata, queryBuilder, offset ); queryBuilder.append( " MERGE (n)" ); queryBuilder.append( " -[r" ); queryBuilder.append( ":" ); appendRelationshipType( queryBuilder, associationKeyMetadata ); offset = ownerEntityKeyMetadata.getColumnNames().length; if ( associationKeyMetadata.getRowKeyIndexColumnNames().length > 0 ) { offset += targetEntityKeyMetadata.getColumnNames().length; appendProperties( queryBuilder, associationKeyMetadata.getRowKeyIndexColumnNames(), offset ); } queryBuilder.append( "]-> (t)" ); queryBuilder.append( " RETURN r" ); return queryBuilder.toString(); }
/** * The only properties added to a relationship are the columns representing the index of the association. */ private void applyProperties(AssociationKey associationKey, Tuple associationRow, Relationship relationship) { String[] indexColumns = associationKey.getMetadata().getRowKeyIndexColumnNames(); for ( int i = 0; i < indexColumns.length; i++ ) { String propertyName = indexColumns[i]; Object propertyValue = associationRow.get( propertyName ); relationship.setProperty( propertyName, propertyValue ); } }
protected Object[] relationshipValues(AssociationKey associationKey, RowKey rowKey) { Object[] relationshipValues; if ( associationKey.getMetadata().getRowKeyIndexColumnNames().length > 0 ) { int length = associationKey.getMetadata().getRowKeyIndexColumnNames().length; relationshipValues = new Object[length]; String[] indexColumnNames = associationKey.getMetadata().getRowKeyIndexColumnNames(); for ( int i = 0; i < indexColumnNames.length; i++ ) { for ( int j = 0; j < rowKey.getColumnNames().length; j++ ) { if ( indexColumnNames[i].equals( rowKey.getColumnNames()[j] ) ) { relationshipValues[i] = rowKey.getColumnValues()[j]; } } } return relationshipValues; } else { return getEntityKey( associationKey, rowKey ).getColumnValues(); } }
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" ); }
appendRelationshipType( queryBuilder, associationKeyMetadata ); int offset = ownerEntityKeyMetadata.getColumnNames().length; boolean hasIndexColumns = associationKeyMetadata.getRowKeyIndexColumnNames().length > 0; if ( hasIndexColumns ) { appendProperties( queryBuilder, associationKeyMetadata.getRowKeyIndexColumnNames(), offset );
/** * Whether the rows of the given association should be stored in a hash using the single row key column as key or * not. */ public static boolean organizeAssociationMapByRowKey( org.hibernate.ogm.model.spi.Association association, AssociationKey key, AssociationContext associationContext) { if ( association.isEmpty() ) { return false; } if ( key.getMetadata().getRowKeyIndexColumnNames().length != 1 ) { return false; } Object valueOfFirstRow = association.get( association.getKeys().iterator().next() ) .get( key.getMetadata().getRowKeyIndexColumnNames()[0] ); if ( !( valueOfFirstRow instanceof String ) ) { return false; } // The list style may be explicitly enforced for compatibility reasons return getMapStorage( associationContext ) == MapStorageType.BY_KEY; }
associationContext.getAssociationTypeContext() ) && organizeByRowKey ) { String rowKeyColumn = organizeByRowKey ? associationKey.getMetadata().getRowKeyIndexColumnNames()[0] : null; Map<String, Object> rows = new HashMap<>();
@Override protected Object[] relationshipValues(AssociationKey associationKey, RowKey rowKey) { Object[] relationshipValues; if ( associationKey.getMetadata().getRowKeyIndexColumnNames().length > 0 ) { int length = associationKey.getMetadata().getRowKeyIndexColumnNames().length; relationshipValues = new Object[length]; String[] indexColumnNames = associationKey.getMetadata().getRowKeyIndexColumnNames(); for ( int i = 0; i < indexColumnNames.length; i++ ) { for ( int j = 0; j < rowKey.getColumnNames().length; j++ ) { if ( indexColumnNames[i].equals( rowKey.getColumnNames()[j] ) ) { relationshipValues[i] = rowKey.getColumnValues()[j]; } } } } else { relationshipValues = getEntityKey( associationKey, rowKey ).getColumnValues(); } Object[] queryValues = ArrayHelper.concat( associationKey.getEntityKey().getColumnValues(), relationshipValues ); return queryValues; }
String rowKeyColumn = organizeByRowKey ? key.getMetadata().getRowKeyIndexColumnNames()[0] : null; Document rows = new Document();
String rowKeyColumn = organizeByRowKey ? key.getMetadata().getRowKeyIndexColumnNames()[0] : null; Document rows = new Document();
String rowKeyIndexColumn = associationKey.getMetadata().getRowKeyIndexColumnNames()[0]; List<Document> rows = new ArrayList<Document>();
String rowKeyIndexColumn = associationKey.getMetadata().getRowKeyIndexColumnNames()[0]; List<Document> rows = new ArrayList<Document>();
private void putAssociationOperation(Association association, AssociationKey associationKey, AssociationOperation action, AssociationContext associationContext) { AssociatedEntityKeyMetadata associatedEntityKeyMetadata = associationContext.getAssociationTypeContext().getAssociatedEntityKeyMetadata(); Relationship relationship = getAssociationQueries( associationKey.getMetadata() ).findRelationship( dataBase, associationKey, action.getKey() ); if ( relationship != null ) { for ( String relationshipProperty : associationKey.getMetadata().getRowKeyIndexColumnNames() ) { relationship.setProperty( relationshipProperty, action.getValue().get( relationshipProperty ) ); } for ( String column : associationKey.getMetadata().getColumnsWithoutKeyColumns( action.getValue().getColumnNames() ) ) { if ( !isRowKeyColumn( associationKey.getMetadata(), column ) ) { relationship.getEndNode().setProperty( column, action.getValue().get( column ) ); } } GraphLogger.log( "Updated relationship: %1$s", relationship ); } else { relationship = createRelationship( associationKey, action.getValue(), associatedEntityKeyMetadata, associationContext ); GraphLogger.log( "Created relationship: %1$s", relationship ); } }