use of org.springframework.jdbc.core.StatementCallback in project cobar by alibaba.
the class CobarAdapter method getCurrentTimeMillis.
@Override
public Pair<Long, Long> getCurrentTimeMillis() {
return (Pair<Long, Long>) getJdbcTemplate().execute(new StatementCallback() {
@Override
public Object doInStatement(Statement stmt) throws SQLException, DataAccessException {
ResultSet rs = null;
try {
long time1 = System.currentTimeMillis();
rs = stmt.executeQuery("show @@status.time");
long time2 = System.currentTimeMillis();
if (rs.next()) {
return new Pair<Long, Long>(time1 + (time2 - time1) / 2, rs.getLong(1));
} else {
throw new IncorrectResultSizeDataAccessException(1, 0);
}
} finally {
if (rs != null) {
rs.close();
}
}
}
});
}
Aggregations