public void insert(Map<AggregationKey, AggregationValue> map, GraphGranularityType graphGranularityType) { long start = System.currentTimeMillis(); log.info("Storing {} reporting...", graphGranularityType.name()); String insertSQL = getTableByGraphType(graphGranularityType); try (Connection connection = ds.getConnection(); PreparedStatement ps = connection.prepareStatement(insertSQL)) { for (Map.Entry<AggregationKey, AggregationValue> entry : map.entrySet()) { prepareReportingInsert(ps, entry, graphGranularityType); ps.addBatch(); } ps.executeBatch(); connection.commit(); } catch (Exception e) { log.error("Error inserting reporting data in DB.", e); } log.info("Storing {} reporting finished. Time {}. Records saved {}", graphGranularityType.name(), System.currentTimeMillis() - start, map.size()); }
public static void prepareReportingInsert(PreparedStatement ps, String email, int dashId, int deviceId, short pin, PinType pinType, long ts, double value) throws SQLException { ps.setString(1, email); ps.setInt(2, dashId); ps.setInt(3, deviceId); ps.setShort(4, pin); ps.setInt(5, pinType.ordinal()); ps.setTimestamp(6, new Timestamp(ts), DateTimeUtils.UTC_CALENDAR); ps.setDouble(7, value); }