diff --git a/src/de/tud/kom/p2psim/impl/util/db/dao/DAO.java b/src/de/tud/kom/p2psim/impl/util/db/dao/DAO.java index 7bd14fd19aafb4fa6a9bcaa0a2052122123da668..715eec2bd49fb167e1b4b257c9d9909d2f4ab848 100644 --- a/src/de/tud/kom/p2psim/impl/util/db/dao/DAO.java +++ b/src/de/tud/kom/p2psim/impl/util/db/dao/DAO.java @@ -48,6 +48,7 @@ import de.tud.kom.p2psim.impl.util.db.metric.Measurement; import de.tud.kom.p2psim.impl.util.db.metric.MeasurementPair; import de.tud.kom.p2psim.impl.util.db.metric.MeasurementPairList; import de.tud.kom.p2psim.impl.util.db.metric.MeasurementSingle; +import de.tud.kom.p2psim.impl.util.db.metric.MeasurementSpatial; import de.tud.kom.p2psim.impl.util.db.metric.MeasurementStatistic; import de.tud.kom.p2psim.impl.util.db.metric.Metric; import de.tud.kom.p2psim.impl.util.db.metric.MetricDescription; @@ -155,6 +156,7 @@ public class DAO { cfg.addAnnotatedClass(MeasurementPair.class); cfg.addAnnotatedClass(MeasurementPairList.class); cfg.addAnnotatedClass(MeasurementSingle.class); + cfg.addAnnotatedClass(MeasurementSpatial.class); cfg.addAnnotatedClass(MeasurementStatistic.class); cfg.addAnnotatedClass(Metric.class); cfg.addAnnotatedClass(MetricDescription.class); diff --git a/src/de/tud/kom/p2psim/impl/util/db/dao/metric/MeasurementDAO.java b/src/de/tud/kom/p2psim/impl/util/db/dao/metric/MeasurementDAO.java index 789584fb92a63994e8b8593d736f948c5540d5ff..7a5b24ef253b145809ae32bf1f3f2f7c831850d9 100644 --- a/src/de/tud/kom/p2psim/impl/util/db/dao/metric/MeasurementDAO.java +++ b/src/de/tud/kom/p2psim/impl/util/db/dao/metric/MeasurementDAO.java @@ -32,6 +32,7 @@ import de.tud.kom.p2psim.impl.util.db.metric.Measurement; import de.tud.kom.p2psim.impl.util.db.metric.MeasurementPair; import de.tud.kom.p2psim.impl.util.db.metric.MeasurementPairList; import de.tud.kom.p2psim.impl.util.db.metric.MeasurementSingle; +import de.tud.kom.p2psim.impl.util.db.metric.MeasurementSpatial; import de.tud.kom.p2psim.impl.util.db.metric.MeasurementStatistic; import de.tud.kom.p2psim.impl.util.db.metric.Metric; import de.tud.kom.p2psim.impl.util.db.metric.MetricDescription; @@ -101,6 +102,31 @@ public class MeasurementDAO extends DAO { hostMetric); addToPersistQueue(measurement); } + + /** + * Store a single measurement for a host, tied to a specific location. + * + * @param metricDesc + * @param hostId + * @param time + * @param value + * @param locationX + * @param locationY + */ + public static void storeSpatialMeasurement(MetricDescription metricDesc, + long hostId, long time, double value, int locationX, + int locationY) { + if (inactive) { + return; + } + + Metric metric = MetricDAO.lookupSpatialMetric(metricDesc); + HostMetric hostMetric = HostMetricDAO.lookupHostMetric(metric, hostId); + + MeasurementSpatial measurement = new MeasurementSpatial(time, value, + hostMetric, locationX, locationY); + addToPersistQueue(measurement); + } /** * Stores for a series of measurements the given values for a host. The diff --git a/src/de/tud/kom/p2psim/impl/util/db/dao/metric/MetricDAO.java b/src/de/tud/kom/p2psim/impl/util/db/dao/metric/MetricDAO.java index a0b3b0eabc78b99eb409668b89c3c5f86d79cb44..5a2496959655d0150a42a6c3c6e69e2af6035e08 100644 --- a/src/de/tud/kom/p2psim/impl/util/db/dao/metric/MetricDAO.java +++ b/src/de/tud/kom/p2psim/impl/util/db/dao/metric/MetricDAO.java @@ -27,7 +27,7 @@ public class MetricDAO extends DAO { /** * Identifier for a single metric */ - SINGLE, + SINGLE, SPATIAL, /** * Identifier for an aggregate metric */ @@ -62,6 +62,16 @@ public class MetricDAO extends DAO { public static Metric lookupSingleMetric(MetricDescription metricDesc) { return lookupMetric(metricDesc, MetricType.SINGLE); } + + /** Retrieve a {@link Metric} object for the given MetricDescription + * for spatial value metrics. + * + * If there is no matching Metric object, it is created, persisted, and cached + * automatically. + */ + public static Metric lookupSpatialMetric(MetricDescription metricDesc) { + return lookupMetric(metricDesc, MetricType.SPATIAL); + } /** Retrieve a {@link Metric} object for the given MetricDescription * for pair value metrics. diff --git a/src/de/tud/kom/p2psim/impl/util/db/metric/MeasurementSpatial.java b/src/de/tud/kom/p2psim/impl/util/db/metric/MeasurementSpatial.java new file mode 100644 index 0000000000000000000000000000000000000000..67f6df948979612618094873b73a6bb908d03103 --- /dev/null +++ b/src/de/tud/kom/p2psim/impl/util/db/metric/MeasurementSpatial.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2005-2010 KOM – Multimedia Communications Lab + * + * This file is part of PeerfactSim.KOM. + * + * PeerfactSim.KOM is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * PeerfactSim.KOM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with PeerfactSim.KOM. If not, see . + * + */ + +package de.tud.kom.p2psim.impl.util.db.metric; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Index; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +/** + * A single measurement, but with an assigned location. + * + * @author Bjoern Richerzhagen + */ +@Entity +@Table(name = "measurements_spatial", indexes = { + @Index(columnList = "time", name = "time"), + @Index(columnList = "hostMetricId", name = "hostMetricId") }) +public class MeasurementSpatial { + + /** + * A unique Id, will be set by the database + */ + @SuppressWarnings("unused") + @Id + @GeneratedValue() + private int id; + + /** + * The simulation time of this measurement + */ + @SuppressWarnings("unused") + private long time; + + /** + * The value for this measurement + */ + @SuppressWarnings("unused") + @Column(nullable = true) + private Double value; + + @Column(nullable = true, name = "[locationX]") + private Integer locationX; + + @Column(nullable = true, name = "[locationY]") + private Integer locationY; + + /** + * The mapping Object of this measurement to the {@link Metric}-Object, + * which describes this metric. + */ + @SuppressWarnings("unused") + @ManyToOne + @JoinColumn(name = "hostMetricId") + private HostMetric hostMetric; + + /** + * Creates a {@link MeasurementSingle}-Object with the given parameters. If + * value has the value infinity or NaN, then will be set this value to null. + * + * @param time + * The simulation time as date to this measurement + * @param value + * The value for this measurement + * @param statistic + * The reference to the {@link Metric}-Object, which describes + * this metric. Is used for the mapping. + */ + public MeasurementSpatial(long time, Double value, HostMetric hostMetric, Integer locationX, Integer locationY) { + super(); + this.time = time; + this.hostMetric = hostMetric; + + // check for infinity or NaN + this.value = checkForSpecialNumbers(value); + this.locationX = locationX; + this.locationY = locationY; + } + + /** + * Check for special numbers, like infinity or NaN. If the given value is + * equals this numbers then will be return null, otherwise will be returned + * the given value. + * + * @param value + * The value, which should be checked. + * @return The value or null, if it is a special number. + */ + private Double checkForSpecialNumbers(Double value) { + if (value == null) + return value; + if (value.equals(Double.NEGATIVE_INFINITY) + || value.equals(Double.POSITIVE_INFINITY) + || value.equals(Double.NaN)) { + return null; + } else { + return value; + } + } + +}