private static Collection getRowsFromMapAssociation()

in mongodb/src/main/java/org/hibernate/ogm/datastore/mongodb/dialect/impl/MongoDBAssociationSnapshot.java [86:136]


	private static Collection<?> getRowsFromMapAssociation(AssociationKey associationKey, Document value) {
		String rowKeyIndexColumn = associationKey.getMetadata().getRowKeyIndexColumnNames()[0];
		List<Document> rows = new ArrayList<Document>();

		String[] associationKeyColumns = associationKey.getMetadata()
				.getAssociatedEntityKeyMetadata()
				.getAssociationKeyColumns();

		// Omit shared prefix of compound ids, will be handled in the row accessor
		String prefix = DocumentHelpers.getColumnSharedPrefix( associationKeyColumns );
		prefix = prefix == null ? "" : prefix + ".";

		String embeddedValueColumnPrefix = associationKey.getMetadata().getCollectionRole() + EMBEDDABLE_COLUMN_PREFIX;

		// restore the list representation
		for ( String rowKey : value.keySet() ) {
			Object mapRow = value.get( rowKey );

			// include the row key index column
			Document row = new Document();
			row.put( rowKeyIndexColumn, rowKey );

			// several value columns, copy them all
			if ( mapRow instanceof Document ) {
				for ( String column : associationKey.getMetadata().getAssociatedEntityKeyMetadata().getAssociationKeyColumns() ) {
					// The column is part of an element collection; Restore the "value" node in the hierarchy
					if ( column.startsWith( embeddedValueColumnPrefix ) ) {
						MongoHelpers.setValue(
								row,
								column.substring( associationKey.getMetadata().getCollectionRole().length() + 1 ),
								( (Document) mapRow ).get( column.substring( embeddedValueColumnPrefix.length() ) )
						);
					}
					else {
						row.put(
								column.substring( prefix.length() ),
								( (Document) mapRow ).get( column.substring( prefix.length() ) )
						);
					}
				}
			}
			// single value column
			else {
				row.put( associationKey.getMetadata().getAssociatedEntityKeyMetadata().getAssociationKeyColumns()[0], mapRow );
			}

			rows.add( row );
		}

		return rows;
	}