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()); }