1 | package de.uka.ipd.sdq.sensorframework.entities.impl; |
2 | |
3 | import java.util.ArrayList; |
4 | |
5 | import de.uka.ipd.sdq.sensorframework.entities.Measurement; |
6 | import de.uka.ipd.sdq.sensorframework.entities.Sensor; |
7 | import de.uka.ipd.sdq.sensorframework.entities.SensorAndMeasurements; |
8 | import de.uka.ipd.sdq.sensorframework.entities.StateMeasurement; |
9 | import de.uka.ipd.sdq.sensorframework.entities.TimeSpanMeasurement; |
10 | import de.uka.ipd.sdq.sensorframework.entities.dao.IDAOFactory; |
11 | |
12 | @javax.persistence.Entity |
13 | public class ExperimentRunImpl extends de.uka.ipd.sdq.sensorframework.entities.base.AbstractExperimentRun { |
14 | |
15 | public ExperimentRunImpl(IDAOFactory myFactory) { |
16 | super(myFactory); |
17 | } |
18 | |
19 | @Override |
20 | public SensorAndMeasurements getMeasurementsOfSensor(Sensor sensor) { |
21 | // TODO: Fix this conceptually!!! |
22 | // EntityManager em = ExperimentDAO.singleton().getEntityManagerFactory().createEntityManager(); |
23 | // Query q = em.createQuery("SELECT m FROM Measurement m WHERE FK_SENSOR = "+sensor.getSensorID()); |
24 | // Collection <Measurement> result = q.getResultList(); |
25 | // em.close(); |
26 | ArrayList<Measurement> result = new ArrayList<Measurement>(); |
27 | for (Measurement m: this.getMeasurements()) { |
28 | if (m instanceof TimeSpanMeasurement) { |
29 | TimeSpanMeasurement tsm = (TimeSpanMeasurement) m; |
30 | if (tsm.getSensor() == sensor) |
31 | result.add(m); |
32 | } |
33 | if (m instanceof StateMeasurement) { |
34 | StateMeasurement tsm = (StateMeasurement) m; |
35 | if (tsm.getSensor() == sensor) |
36 | result.add(m); |
37 | } |
38 | } |
39 | return new SensorAndMeasurements(sensor,result); |
40 | } |
41 | } |