|
| 1 | +package com.oltpbenchmark.benchmarks.dataloader; |
| 2 | + |
| 3 | +import com.oltpbenchmark.WorkloadConfiguration; |
| 4 | +import com.oltpbenchmark.api.BenchmarkModule; |
| 5 | +import com.oltpbenchmark.api.Loader; |
| 6 | +import com.oltpbenchmark.api.Worker; |
| 7 | +import com.oltpbenchmark.benchmarks.featurebench.FeatureBenchLoader; |
| 8 | +import org.apache.commons.configuration2.HierarchicalConfiguration; |
| 9 | +import org.apache.commons.configuration2.tree.ImmutableNode; |
| 10 | + |
| 11 | +import java.io.FileInputStream; |
| 12 | +import java.io.FileNotFoundException; |
| 13 | +import java.io.IOException; |
| 14 | +import java.io.InputStream; |
| 15 | +import java.util.*; |
| 16 | + |
| 17 | +public class DataGenerator extends BenchmarkModule { |
| 18 | + /** |
| 19 | + * Constructor! |
| 20 | + * |
| 21 | + * @param workConf |
| 22 | + */ |
| 23 | + public DataGenerator(WorkloadConfiguration workConf) { |
| 24 | + super(workConf); |
| 25 | + } |
| 26 | + |
| 27 | + @Override |
| 28 | + protected List<Worker<? extends BenchmarkModule>> makeWorkersImpl() throws IOException { |
| 29 | + return null; |
| 30 | + } |
| 31 | + |
| 32 | + @Override |
| 33 | + protected Loader<DataGenerator> makeLoaderImpl() { |
| 34 | + // load properties file |
| 35 | + |
| 36 | + return new DataGeneratorLoader(this, getProperties("datatype-mapping.properties"), |
| 37 | + getProperties("pk-mapping.properties"), getFkProperties()); |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + protected Package getProcedurePackageImpl() { |
| 42 | + return null; |
| 43 | + } |
| 44 | + |
| 45 | + public Map<String, PropertyMapping> getProperties(String propertiesType) { |
| 46 | + Properties properties = new Properties(); |
| 47 | + Map<String, PropertyMapping> propertyMap = new LinkedHashMap<>(); |
| 48 | + final String path = "/benchmarks/" + getBenchmarkName() + "/" + propertiesType; |
| 49 | + |
| 50 | + try (InputStream input = this.getClass().getResourceAsStream(path)) { |
| 51 | + properties.load(input); |
| 52 | + for (String key : properties.stringPropertyNames()) { |
| 53 | + String value = properties.getProperty(key); |
| 54 | + String[] parts = value.split(":"); |
| 55 | + String className = parts[0]; |
| 56 | + int numParams = Integer.parseInt(parts[1]); |
| 57 | + List<Object> params = new ArrayList<>(); |
| 58 | + if (numParams > 0) { |
| 59 | + params.addAll(Arrays.asList(parts[2].split(","))); |
| 60 | + } |
| 61 | + |
| 62 | + PropertyMapping property = new PropertyMapping(className, numParams, params); |
| 63 | + propertyMap.put(key, property); |
| 64 | + } |
| 65 | + } catch (IOException e) { |
| 66 | + throw new RuntimeException(e); |
| 67 | + } |
| 68 | + return propertyMap; |
| 69 | + } |
| 70 | + |
| 71 | + public Map<String, FkPropertyMapping> getFkProperties() { |
| 72 | + Properties properties = new Properties(); |
| 73 | + Map<String, FkPropertyMapping> propertyMap = new LinkedHashMap<>(); |
| 74 | + final String path = "/benchmarks/" + getBenchmarkName() + "/fk-mapping.properties"; |
| 75 | + |
| 76 | + try (InputStream input = this.getClass().getResourceAsStream(path)) { |
| 77 | + properties.load(input); |
| 78 | + for (String key : properties.stringPropertyNames()) { |
| 79 | + String value = properties.getProperty(key); |
| 80 | + String[] parts = value.split(":"); |
| 81 | + String className = parts[0]; |
| 82 | + String dataType = parts[1]; |
| 83 | + |
| 84 | + FkPropertyMapping property = new FkPropertyMapping(className, dataType); |
| 85 | + propertyMap.put(key, property); |
| 86 | + } |
| 87 | + } catch (IOException e) { |
| 88 | + throw new RuntimeException(e); |
| 89 | + } |
| 90 | + return propertyMap; |
| 91 | + } |
| 92 | +} |
0 commit comments