private static Object getAssociationRow(Tuple row, AssociationKey associationKey) { String[] rowKeyColumnsToPersist = associationKey.getMetadata().getColumnsWithoutKeyColumns( row.getColumnNames() ); // return value itself if there is only a single column to store if ( rowKeyColumnsToPersist.length == 1 ) { return row.get( rowKeyColumnsToPersist[0] ); } // otherwise a Document with the row contents else { // if the columns are only made of the embedded id columns, remove the embedded id property prefix // collectionrole: [ { id: { id1: "foo", id2: "bar" } } ] becomes collectionrole: [ { id1: "foo", id2: "bar" } ] String prefix = getColumnSharedPrefixOfAssociatedEntityLink( associationKey ); Document rowObject = new Document(); for ( String column : rowKeyColumnsToPersist ) { Object value = row.get( column ); if ( value != null ) { // remove the prefix if present String columnName = column.startsWith( prefix ) ? column.substring( prefix.length() ) : column; MongoHelpers.setValue( rowObject, columnName, value ); } } return rowObject; } }
private static Object getAssociationRow(Tuple row, AssociationKey associationKey) { String[] rowKeyColumnsToPersist = associationKey.getMetadata().getColumnsWithoutKeyColumns( row.getColumnNames() ); // return value itself if there is only a single column to store if ( rowKeyColumnsToPersist.length == 1 ) { return row.get( rowKeyColumnsToPersist[0] ); } // otherwise a Document with the row contents else { // if the columns are only made of the embedded id columns, remove the embedded id property prefix // collectionrole: [ { id: { id1: "foo", id2: "bar" } } ] becomes collectionrole: [ { id1: "foo", id2: "bar" } ] String prefix = getColumnSharedPrefixOfAssociatedEntityLink( associationKey ); Document rowObject = new Document(); for ( String column : rowKeyColumnsToPersist ) { Object value = row.get( column ); if ( value != null ) { // remove the prefix if present String columnName = column.startsWith( prefix ) ? column.substring( prefix.length() ) : column; MongoHelpers.setValue( rowObject, columnName, value ); } } return rowObject; } }
private Object getAssociationRow(Tuple row, AssociationKey associationKey) { String[] columnsToPersist = associationKey.getMetadata() .getColumnsWithoutKeyColumns( row.getColumnNames() ); // return value itself if there is only a single column to store if ( columnsToPersist.length == 1 ) { return row.get( columnsToPersist[0] ); } EntityDocument rowObject = new EntityDocument(); String prefix = getColumnSharedPrefixOfAssociatedEntityLink( associationKey ); for ( String column : columnsToPersist ) { Object value = row.get( column ); if ( value != null ) { String columnName = column.startsWith( prefix ) ? column.substring( prefix.length() ) : column; rowObject.set( columnName, value ); } } return rowObject.getPropertiesAsHierarchy(); }
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 ); } }