1 | package de.uka.ipd.sdq.sensorframework.dao.memory; |
2 | |
3 | import java.util.Collection; |
4 | import java.util.Collections; |
5 | import java.util.HashMap; |
6 | |
7 | import de.uka.ipd.sdq.sensorframework.entities.ExperimentRun; |
8 | import de.uka.ipd.sdq.sensorframework.entities.Measurement; |
9 | import de.uka.ipd.sdq.sensorframework.entities.dao.IDAOFactory; |
10 | import de.uka.ipd.sdq.sensorframework.entities.dao.IExperimentRunDAO; |
11 | import de.uka.ipd.sdq.sensorframework.entities.impl.ExperimentRunImpl; |
12 | import de.uka.ipd.sdq.sensorframework.entities.impl.ScalabilityExperimentRunImpl; |
13 | |
14 | /** |
15 | * TODO |
16 | * |
17 | */ |
18 | public class MemoryExperimentRunDAO implements IExperimentRunDAO { |
19 | |
20 | private long nextID = 0; |
21 | private IDAOFactory myFactory; |
22 | private HashMap<Long,ExperimentRun> index = new HashMap<Long, ExperimentRun>(); |
23 | |
24 | public MemoryExperimentRunDAO(IDAOFactory memoryDAOFactory) { |
25 | this.myFactory = memoryDAOFactory; |
26 | } |
27 | |
28 | public synchronized ExperimentRun addExperimentRun(String p_experimentdatetime) { |
29 | ExperimentRun result = new ExperimentRunImpl(this.myFactory); |
30 | result.setExperimentRunID(nextID++); |
31 | result.setExperimentDateTime(p_experimentdatetime); |
32 | |
33 | index.put(result.getExperimentRunID(),result); |
34 | return result; |
35 | } |
36 | |
37 | public synchronized ExperimentRun addScalabilityExperimentRun(String p_experimentdatetime) { |
38 | ExperimentRun result = new ScalabilityExperimentRunImpl(this.myFactory); |
39 | result.setExperimentRunID(nextID++); |
40 | result.setExperimentDateTime(p_experimentdatetime); |
41 | |
42 | index.put(result.getExperimentRunID(),result); |
43 | return result; |
44 | } |
45 | |
46 | public synchronized ExperimentRun get(long id) { |
47 | return index.get(id); |
48 | } |
49 | |
50 | public synchronized Collection<ExperimentRun> getExperimentRuns() { |
51 | return Collections.unmodifiableCollection(index.values()); |
52 | } |
53 | |
54 | public void store(ExperimentRun er) { |
55 | } |
56 | |
57 | public synchronized void removeExperimentRun(ExperimentRun experimentRun, |
58 | boolean doCascade) { |
59 | if (experimentRun == null) { |
60 | return; |
61 | } |
62 | |
63 | if ( doCascade == true ) { |
64 | //remove all measurements |
65 | for (Measurement measurement:experimentRun.getMeasurements()) { |
66 | myFactory.createMeasurementDAO().removeMeasurement(measurement, true); |
67 | } |
68 | } |
69 | index.remove(experimentRun.getExperimentRunID()); |
70 | } |
71 | |
72 | public void storeAll() { |
73 | // Nothing to do here |
74 | } |
75 | |
76 | |
77 | } |