package rsv.process.model.record;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.apache.log4j.Logger;

import rsv.process.model.MetricDataModel;
import rsv.process.model.RSVDatabase;
import rsv.process.model.OIMModel;

public class MetricData {
	private static final Logger logger = Logger.getLogger(MetricData.class);	
	
	//core parameters
	protected int metricdata_id;
	protected int metric_id;
	protected int resource_id;
	protected int timestamp;
	protected int status_id;
	protected int detail_id;
	
	private String note = "";
	
	public MetricData(ResultSet rs) {
		try {
			metricdata_id = rs.getInt("id");
			metric_id = rs.getInt("metric_id");
			resource_id = rs.getInt("resource_id");
			status_id = rs.getInt("metric_status_id");
			timestamp = rs.getInt("timestamp");
			detail_id = rs.getInt("detail_id");
		} catch (SQLException e) {
			logger.error("Failed to inialize MetricData record from given resultset", e);
		}
	}
	
	protected MetricData() {
		//should only be used by DummyMetricData, etc..
	}
	
	public int getID() { return metricdata_id; }
	public int getStatusID() { return status_id; }
	public int getResourceID() { return resource_id; }	
	public int getMetricID() { return metric_id; }
	public int getTimestamp() { return timestamp; }	
	public int getDetailID() { return detail_id; }	
	
	public String fetchDetail() throws SQLException {
		MetricDataModel mdm = new MetricDataModel();
		return mdm.getDetail(getDetailID());
	}

	public int getFreshFor() throws SQLException {
		OIMModel oim = new OIMModel();
		return oim.lookupFreshFor(metric_id);
	}
	
	public void addNote(String _note) {
		note += _note;
	}
}

@@ -1638,22 +1638,27 @@
 l();%0D%0A%09%09
-return
+Integer i =
  oim.loo
@@ -1678,24 +1678,162 @@
 etric_id);%0D%0A
+%09%09if(i == null) %7B%0D%0A%09%09%09logger.error(%22Metric ID: %22 +metric_id + %22 has no fresh for value (letting it null-pointer-ed)%22);%0D%0A%09%09%7D%0D%0A%09%09return i;%0D%0A
 %09%7D%0D%0A%09%0D%0A%09publ

Check on null fresh for