}
public SpeedDistributionRecord updateFromClosestDistribution(SpeedDistributionRecord query) throws Exception
{
SpeedDistributionRecord match = null;
try {
Connection connection = getConnection();
Statement s = connection.createStatement();
String tagId = query.getTagId();
String dayType = query.getDayType();
String hourBin = query.getHourBin(); // make sure to send into SP as int
double totalFlow = query.getTotalFlow();
String sql = "SELECT * FROM " +
"TAMT_updateFromClosestDistribution('"+tagId+"','"+dayType+"', "+hourBin+", " +
totalFlow+", "+CLOSEST_DISTRIBUTION_PERCENT_THRESHOLD+") " +
"AS foo(tagid text, daytype text, hourbin int, " +
"isobserved boolean, totaflow double precision, " +
"diff double precision)";
//logger.debug("SQL for TAMT_updateFromClosestDistribution: " + sql);
/*
* The TAMT_getClosestDistribution function always
* returns the closest row by daytype+threshold
* or closest row without daytype+threshold. So this
* should always be exactly one row (no more, no less).
*/
ResultSet r = s.executeQuery(sql);
while(r.next())
{
match = new SpeedDistributionRecord();
match.setTagId(r.getString(1));
match.setDayType(r.getString(2));
match.setHourBin(r.getString(3));
match.setObserved(r.getBoolean(4));
match.setTotalFlow(r.getDouble(5));
}
} catch (SQLException e) {
logger.error(e.getMessage());
throw new Exception("There was an error executing the SQL: "