<commit_before>package org.hivedb.util.scenarioBuilder;

import java.util.Collection;
import java.util.Map;

import org.hivedb.HiveException;
import org.hivedb.meta.Hive;
import org.hivedb.meta.PartitionDimension;
import org.hivedb.meta.Resource;
import org.hivedb.util.GenerateHiveIndexKeys;
import org.hivedb.util.InstallHiveIndexSchema;

/**
 *
 * @author andylikuski <NAME>
 * 
 *  Given a hive URI, index URIs, and data nodes, this class contructs 
 *  partition dimensions, node groups, primary indexes, resources, and secondary index,
 *  and also creates sample object instances and inserts their ids into the index tables.
 *  The meta data is set to the hive, so that the result of constructing this class
 *  is a full hive and populated index tables. The class instance also offers a number
 *  of methods that return the meta data and instances created in order for tests to
 *  validate the persisted data.
 *  
 *  There are serveral configuration parameters listed as constants at the top of the class
 *  which are used to determine what classes are modeled and how many instances are created.
 *  You may alter these or sublcass HiveScenarioConfig to test your own classes. HiveScenario
 *  expects the classes to conform to its Identifiable interface. To test your classes subclass
 *  them and implement the Identifiable interface. The Identifiable interface allows a class
 *  to function as a primary index key and as a single secondary index key. If you want a class
 *  to only function as a primary index class you can implement PrimaryIndexIdentifiable and
 *  to only function as a resource/secondary index class implement SecondaryIndexIdentifiable.
 *  
 *  Primary Index classes must have a no argument contructor (for use by reflection)
 *  Secondary Index classes must have a 1 argument contructor (for use by reflection) whose
 *  arguement is the instance to be used as the primary index key (see SecondaryIndexidentifiable)
 */
public class HiveScenario {
	
	public static HiveScenario run(HiveScenarioConfig hiveScenarioConfig) throws HiveException {
		HiveScenario hiveScenario = new HiveScenario(hiveScenarioConfig);
		hiveScenarioConfig.getHive().sync(); //Get the data that we've inserted so we can compare HiveScenario's data to the Hive's data
		return hiveScenario;
	}

	protected HiveScenario(final HiveScenarioConfig hiveScenarioConfig) throws HiveException
	{
		final Hive hive = hiveScenarioConfig.getHive();
		fill(hiveScenarioConfig, hive);
	}
	private void fill(final HiveScenarioConfig hiveScenarioConfig, final Hive hive) throws HiveException {
		Map<PrimaryIndexIdentifiable, PartitionDimension> partitionDimensionMap = InstallHiveIndexSchema.install(hiveScenarioConfig, hive);
		this.partitionDimensionMap = partitionDimensionMap;
		populateData(hiveScenarioConfig, hive, partitionDimensionMap);
	}
	private void populateData(final HiveScenarioConfig hiveScenarioConfig, final Hive hive, Map<PrimaryIndexIdentifiable, PartitionDimension> partitionDimensionMap) {
		GenerateHiveIndexKeys generateHiveIndexKeys = new GenerateHiveIndexKeys();
		Map<PrimaryIndexIdentifiable, Collection<PrimaryIndexIdentifiable>> primaryIndexIdentifiableMap = 
			generateHiveIndexKeys.createPrimaryIndexInstances(hive, hiveScenarioConfig);
		
		Map<PrimaryIndexIdentifiable, Map<ResourceIdentifiable, Collection<ResourceIdentifiable>>> secondaryIndexInstanceMap
			= generateHiveIndexKeys.createSecondaryIndexInstances(hive, hiveScenarioConfig, primaryIndexIdentifiableMap);
	<commit_msg>Debugging threading problem on another machine, will be checking frequently<commit_after>package org.hivedb.util.scenarioBuilder;

import java.util.Collection;
import java.util.Map;

import org.hivedb.HiveException;
import org.hivedb.meta.Hive;
import org.hivedb.meta.PartitionDimension;
import org.hivedb.meta.Resource;
import org.hivedb.util.GenerateHiveIndexKeys;
import org.hivedb.util.InstallHiveIndexSchema;

/**
 *
 * @author andylikuski <NAME>
 * 
 *  Given a hive URI, index URIs, and data nodes, this class contructs 
 *  partition dimensions, node groups, primary indexes, resources, and secondary index,
 *  and also creates sample object instances and inserts their ids into the index tables.
 *  The meta data is set to the hive, so that the result of constructing this class
 *  is a full hive and populated index tables. The class instance also offers a number
 *  of methods that return the meta data and instances created in order for tests to
 *  validate the persisted data.
 *  
 *  There are serveral configuration parameters listed as constants at the top of the class
 *  which are used to determine what classes are modeled and how many instances are created.
 *  You may alter these or sublcass HiveScenarioConfig to test your own classes. HiveScenario
 *  expects the classes to conform to its Identifiable interface. To test your classes subclass
 *  them and implement the Identifiable interface. The Identifiable interface allows a class
 *  to function as a primary index key and as a single secondary index key. If you want a class
 *  to only function as a primary index class you can implement PrimaryIndexIdentifiable and
 *  to only function as a resource/secondary index class implement SecondaryIndexIdentifiable.
 *  
 *  Primary Index classes must have a no argument contructor (for use by reflection)
 *  Secondary Index classes must have a 1 argument contructor (for use by reflection) whose
 *  arguement is the instance to be used as the primary index key (see SecondaryIndexidentifiable)
 */
public class HiveScenario {
	
	public static HiveScenario run(HiveScenarioConfig hiveScenarioConfig) throws HiveException {
		HiveScenario hiveScenario = new HiveScenario(hiveScenarioConfig);
		return hiveScenario;
	}

	protected HiveScenario(final HiveScenarioConfig hiveScenarioConfig) throws HiveException
	{
		final Hive hive = hiveScenarioConfig.getHive();
		fill(hiveScenarioConfig, hive);
	}
	private void fill(final HiveScenarioConfig hiveScenarioConfig, final Hive hive) throws HiveException {
		Map<PrimaryIndexIdentifiable, PartitionDimension> partitionDimensionMap = InstallHiveIndexSchema.install(hiveScenarioConfig, hive);
		this.partitionDimensionMap = partitionDimensionMap;
		populateData(hiveScenarioConfig, hive, partitionDimensionMap);
	}
	private void populateData(final HiveScenarioConfig hiveScenarioConfig, final Hive hive, Map<PrimaryIndexIdentifiable, PartitionDimension> partitionDimensionMap) {
		GenerateHiveIndexKeys generateHiveIndexKeys = new GenerateHiveIndexKeys();
		Map<PrimaryIndexIdentifiable, Collection<PrimaryIndexIdentifiable>> primaryIndexIdentifiableMap = 
			generateHiveIndexKeys.createPrimaryIndexInstances(hive, hiveScenarioConfig);
		
		Map<PrimaryIndexIdentifiable, Map<ResourceIdentifiable, Collection<ResourceIdentifiable>>> secondaryIndexInstanceMap
			= generateHiveIndexKeys.createSecondaryIndexInstances(hive, hiveScenarioConfig, primaryIndexIdentifiableMap);
	
{'fraction_non_alphanumeric': 0.05202809230328221, 'fraction_numerical': 0.00028665615594094884, 'mean_word_length': 5.664756446991404, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '4332299', 'n_tokens_mistral': 1905, 'n_tokens_neox': 1845, 'n_words': 692}