<commit_before>package org.eclipse.epsilon.emc.mongodb;

import java.util.Collection;
import java.util.Collections;
import java.util.UUID;

import org.eclipse.epsilon.common.util.StringProperties;
import org.eclipse.epsilon.eol.exceptions.models.EolModelElementTypeNotFoundException;
import org.eclipse.epsilon.eol.exceptions.models.EolModelLoadingException;
import org.eclipse.epsilon.eol.exceptions.models.EolNotInstantiableModelElementTypeException;
import org.eclipse.epsilon.eol.execute.introspection.IPropertyGetter;
import org.eclipse.epsilon.eol.execute.introspection.IPropertySetter;
import org.eclipse.epsilon.eol.execute.operations.contributors.IOperationContributorProvider;
import org.eclipse.epsilon.eol.execute.operations.contributors.OperationContributor;
import org.eclipse.epsilon.eol.models.IRelativePathResolver;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBObject;
import com.mongodb.Mongo;

public class MongoModel extends DefaultModel implements IOperationContributorProvider {
	
	public static final String PROPERTY_DB = "DB";
	public static final String DBOBJECT_ID = "_id";
	public static final String COLLECTION_ID = "_collectionName";
	
	protected DB db;
	protected String databaseName;
	protected MongoPropertyGetter propertyGetter = new MongoPropertyGetter();
	protected MongoPropertySetter propertySetter = new MongoPropertySetter(this);
	
	public MongoModel() {}
	
	public MongoModel(DB db) {
		this.db = db;
	}
	
	@Override
	public Object createInstance(String type)
			throws EolModelElementTypeNotFoundException,
			EolNotInstantiableModelElementTypeException {
		
		DBObject dbObject = new BasicDBObject();
		if (type.startsWith("d_")) {
			dbObject.put(COLLECTION_ID, type.substring(2));
			db.getCollection(type.substring(2)).save(dbObject);
		}
		else {
			dbObject.put(DBOBJECT_ID, UUID.randomUUID().toString());
		}
		return dbObject;
		
	}
	
	@Override
	public IPropertyGetter getPropertyGetter() {
		return propertyGetter;
	}

	@Override
	public IPropertySetter getPropertySetter() {
		return propertySetter;
	}
	
	@Override
	public Collection<?> getAllOfKind(String type)
			throws EolModelElementTypeNotFoundException {
		return getAllOfType(type);
	}

	@Override
	public Collection<?> getAllOfType(String type)
			throws EolModelElementTypeNotFoundException {
		if (type.startsWith("d_"))
			return new MongoCollection(db.getCollection(type.substring(2)));
		else return Collections.emptyList();
	}

	@Override
	public boolean hasType(String type) {
		return type.startsWith("d_") || type.startsWith("e_");
	}
	
	@Override
	public boolean isInstantiable(String type) {
		return hasType(type);
	}

	@Override
	public void load(StringProperties properties, IRelativePathResolver resolver)
			throws EolModelLoadingException {
		super.load(properties, resolver);
		this.databaseName = properties.getProperty(MongoModel.PROPERTY_DB);
		try {
			this.db = new Mongo().getDB(databaseName);
		}
		catch (Exception ex) {
			throw new EolModelLoadingException(ex, this);
		}
	}
	
	
	public void reset() {
		try {
			this.db.dropDatabase();
			this.db = new Mongo().getDB(databaseName);
		}
		catch (Exception ex) {
			throw new RuntimeException(ex);
		}
	}
	
	@Override
	public boolean owns(Object o) {
		return o instanceof DBObject;
	}

	public DB getDb() {
		return db;
	}
	
	public void setDb(DB db) {
		this.db = db;
	}

	@Override
	public OperationContributor getOperationContributor() {
		return new OperationContributor() {
			
			@Override
			public boolean contributesTo(Object target) {
				return target instanceof DBObject;
			}
			
			public void save() {
				DBObject dbObject = (DBObject) target;
				db.getCollection(dbObject.get(COLLECTION_ID) + "").save(dbObject);
			}
						
		};
	}
	
}
<commit_msg>Modified type naming scheme<commit_after>package org.eclipse.epsilon.emc.mongodb;

import java.util.Collection;
import java.util.Collections;
import java.util.UUID;

import org.eclipse.epsilon.common.util.StringProperties;
import org.eclipse.epsilon.eol.exceptions.models.EolModelElementTypeNotFoundException;
import org.eclipse.epsilon.eol.exceptions.models.EolModelLoadingException;
import org.eclipse.epsilon.eol.exceptions.models.EolNotInstantiableModelElementTypeException;
import org.eclipse.epsilon.eol.execute.introspection.IPropertyGetter;
import org.eclipse.epsilon.eol.execute.introspection.IPropertySetter;
import org.eclipse.epsilon.eol.execute.operations.contributors.IOperationContributorProvider;
import org.eclipse.epsilon.eol.execute.operations.contributors.OperationContributor;
import org.eclipse.epsilon.eol.models.IRelativePathResolver;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBObject;
import com.mongodb.Mongo;

public class MongoModel extends DefaultModel implements IOperationContributorProvider {
	
	public static final String PROPERTY_DB = "DB";
	public static final String DBOBJECT_ID = "_id";
	public static final String COLLECTION_ID = "_collectionName";
	
	protected DB db;
	protected String databaseName;
	protected MongoPropertyGetter propertyGetter = new MongoPropertyGetter();
	protected MongoPropertySetter propertySetter = new MongoPropertySetter(this);
	
	public MongoModel() {}
	
	public MongoModel(DB db) {
		this.db = db;
	}
	
	@Override
	public Object createInstance(String type)
			throws EolModelElementTypeNotFoundException,
			EolNotInstantiableModelElementTypeException {
		
		DBObject dbObject = new BasicDBObject();
		dbObject.put(DBOBJECT_ID, UUID.randomUUID().toString());
		dbObject.put(COLLECTION_ID, type);
		/*
		if (type.startsWith("d_")) {
			dbObject.put(COLLECTION_ID, type.substring(2));
			db.getCollection(type.substring(2)).save(dbObject);
		}
		else {
			dbObject.put(DBOBJECT_ID, UUID.randomUUID().toString());
		}*/
		return dbObject;
		
	}
	
	@Override
	public IPropertyGetter getPropertyGetter() {
		return propertyGetter;
	}

	@Override
	public IPropertySetter getPropertySetter() {
		return propertySetter;
	}
	
	@Override
	public Collection<?> getAllOfKind(String type)
			throws EolModelElementTypeNotFoundException {
		return getAllOfType(type);
	}

	@Override
	public Collection<?> getAllOfType(String type)
			throws EolModelElementTypeNotFoundException {
		return new MongoCollection(db.getCollection(type));
	}

	@Override
	public boolean hasType(String type) {
		return true;
	}
	
	@Override
	public boolean isInstantiable(String type) {
		return hasType(type);
	}

	@Override
	public void load(StringProperties properties, IRelativePathResolver resolver)
			throws EolModelLoadingException {
		super.load(properties, resolver);
		this.databaseName = properties.getProperty(MongoModel.PROPERTY_DB);
		try {
			this.db = new Mongo().getDB(databaseName);
		}
		catch (Exception ex) {
			throw new EolModelLoadingException(ex, this);
		}
	}
	
	
	public void reset() {
		try {
			this.db.dropDatabase();
			this.db = new Mongo().getDB(databaseName);
		}
		catch (Exception ex) {
			throw new RuntimeException(ex);
		}
	}
	
	@Override
	public boolean owns(Object o) {
		return o instanceof DBObject;
	}

	public DB getDb() {
		return db;
	}
	
	public void setDb(DB db) {
		this.db = db;
	}

	@Override
	public OperationContributor getOperationContributor() {
		return new OperationContributor() {
			
			@Override
			public boolean contributesTo(Object target) {
				return target instanceof DBObject;
			}
			
			public void save() {
				DBObject dbObject = (DBObject) target;
				db.getCollection(dbObject.get(COLLECTION_ID) + "").save(dbObject);
			}
			
		};
	}
	
}

{'fraction_non_alphanumeric': 0.09746434231378764, 'fraction_numerical': 0.0006603275224511358, 'mean_word_length': 4.977111286503551, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5015914', 'n_tokens_mistral': 2567, 'n_tokens_neox': 2290, 'n_words': 477}