<commit_before>/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * JBoss, Home of Professional Open Source
 * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
 * as indicated by the @authors tag. All rights reserved.
 * See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This copyrighted material is made available to anyone wishing to use,
 * modify, copy, or redistribute it subject to the terms and conditions
 * of the GNU Lesser General Public License, v. 2.1.
 * This program is distributed in the hope that it will be useful, but WITHOUT A
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public License,
 * v.2.1 along with this distribution; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA  02110-1301, USA.
 */
package org.hibernate.ogm.dialect.mongodb;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.hibernate.ogm.datastore.spi.AssociationSnapshot;
import org.hibernate.ogm.datastore.spi.Tuple;
import org.hibernate.ogm.grid.RowKey;

import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

/**
 * @author <NAME> <alan at eth0.org.uk>
 */
public class MongoDBAssociationSnapshot implements AssociationSnapshot {

	private final Map<RowKey, DBObject> map;
	private final DBObject assoc;

	public MongoDBAssociationSnapshot(DBObject assoc) {
		this.assoc = assoc;
		this.map = new LinkedHashMap<RowKey, DBObject>();
		
		for ( DBObject row : getRows() ) {
			List<String> columnNames = new ArrayList<String>();
			List<Object> columnValues = new ArrayList<Object>();
			DBObject columns = (DBObject)row.get( MongoDBDialect.COLUMNS_FIELDNAME );
			
			for ( String columnKey : columns.keySet() ) {
				columnNames.add( columnKey );
				columnValues.add( columns.get( columnKey ) );
			}
			
			RowKey rowKey = new RowKey( (String)row.get( MongoDBDialect.TABLE_FIELDNAME ),
					columnNames.toArray( new String[]{} ),
					columnValues.toArray() );
			
			this.map.put( rowKey, row );
		}
	}

	@Override
	public Tuple get(RowKey column) {
		DBObject row = this.map.get( column );
		DBObject dbTuple = (DBObject)row.get( MongoDBDialect.TUPLE_FIELDNAME );
		return new Tuple( new MongoDBTupleSnapshot( dbTuple ) );
	}

	public DBObject getQueryObject() {
		DBObject query = new BasicDBObject();
		query.put( MongoDBDialect.ID_FIELDNAME, assoc.get( MongoDBDialect.ID_FIELDNAME ) );
		return query;
	}

	@Override
	public boolean containsKey(RowKey column) {
		return map.containsKey( column );
	}

	@Override
	public int size() {
		return map.size();
	}

	public Map<RowKey, DBObject> getAssembledMap() {
		return map;
	}

	@SuppressWarnings("unchecked")
	public Collection<DBObject> getRows() {
		return (Collection<DBObject>)assoc.get( MongoDBDialect.ROWS_FIELDNAME );
	}

	public DBObject getRowKeyDBObject(RowKey rowKey) {
		return map.get( rowKey );
	}

	@Override
	public Set<RowKey> getRowKeys() {
		return map.keySet();
	}

	public DBObject getDBObject() {
		return this.assoc;
	}

	@Override
	public String toString() {
		final StringBuilder sb = new StringBuilder();
		sb.append( "MongoDBAssociationSnapshot(" );
		sb.append( map.size() );
		sb.append( " RowKey entries)." );
		return sb.toString();
	}
}<commit_msg>OGM-144 Remove dead code<commit_after>/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * JBoss, Home of Professional Open Source
 * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
 * as indicated by the @authors tag. All rights reserved.
 * See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This copyrighted material is made available to anyone wishing to use,
 * modify, copy, or redistribute it subject to the terms and conditions
 * of the GNU Lesser General Public License, v. 2.1.
 * This program is distributed in the hope that it will be useful, but WITHOUT A
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public License,
 * v.2.1 along with this distribution; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA  02110-1301, USA.
 */
package org.hibernate.ogm.dialect.mongodb;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.hibernate.ogm.datastore.spi.AssociationSnapshot;
import org.hibernate.ogm.datastore.spi.Tuple;
import org.hibernate.ogm.grid.RowKey;

import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

/**
 * @author <NAME> <alan at eth0.org.uk>
 */
public class MongoDBAssociationSnapshot implements AssociationSnapshot {

	private final Map<RowKey, DBObject> map;
	private final DBObject assoc;

	public MongoDBAssociationSnapshot(DBObject assoc) {
		this.assoc = assoc;
		this.map = new LinkedHashMap<RowKey, DBObject>();
		
		for ( DBObject row : getRows() ) {
			List<String> columnNames = new ArrayList<String>();
			List<Object> columnValues = new ArrayList<Object>();
			DBObject columns = (DBObject)row.get( MongoDBDialect.COLUMNS_FIELDNAME );
			
			for ( String columnKey : columns.keySet() ) {
				columnNames.add( columnKey );
				columnValues.add( columns.get( columnKey ) );
			}
			
			RowKey rowKey = new RowKey( (String)row.get( MongoDBDialect.TABLE_FIELDNAME ),
					columnNames.toArray( new String[]{} ),
					columnValues.toArray() );
			
			this.map.put( rowKey, row );
		}
	}

	@Override
	public Tuple get(RowKey column) {
		DBObject row = this.map.get( column );
		DBObject dbTuple = (DBObject)row.get( MongoDBDialect.TUPLE_FIELDNAME );
		return new Tuple( new MongoDBTupleSnapshot( dbTuple ) );
	}

	//not for embedded
	public DBObject getQueryObject() {
		DBObject query = new BasicDBObject();
		query.put( MongoDBDialect.ID_FIELDNAME, assoc.get( MongoDBDialect.ID_FIELDNAME ) );
		return query;
	}

	@Override
	public boolean containsKey(RowKey column) {
		return map.containsKey( column );
	}

	@Override
	public int size() {
		return map.size();
	}

	@SuppressWarnings("unchecked")
	public Collection<DBObject> getRows() {
		return (Collection<DBObject>)assoc.get( MongoDBDialect.ROWS_FIELDNAME );
	}

	public DBObject getRowKeyDBObject(RowKey rowKey) {
		return map.get( rowKey );
	}

	@Override
	public Set<RowKey> getRowKeys() {
		return map.keySet();
	}

	@Override
	public String toString() {
		final StringBuilder sb = new StringBuilder();
		sb.append( "MongoDBAssociationSnapshot(" );
		sb.append( map.size() );
		sb.append( " RowKey entries)." );
		return sb.toString();
	}
}
{'fraction_non_alphanumeric': 0.10242243943901402, 'fraction_numerical': 0.006091514378807197, 'mean_word_length': 4.241276911655531, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2659447', 'n_tokens_mistral': 2359, 'n_tokens_neox': 2167, 'n_words': 669}