DeviationDAOCachedMergingMySQL extends AbstractTableCreatingDroppingDAOImpl implements DeviationDAO { public synchronized int insertDeviations(final List<Deviation> deviations) { File tempFile = null; BufferedWriter writer; try { tempFile = File.createTempFile("insert_temp_deviations", ".tmp"); writer = new BufferedWriter(new FileWriter(tempFile)); for (Deviation deviation : deviations) writeDeviation(writer, deviation); writer.close(); return QUERY_INSERT_TEMP_DEVIATIONS.update(tempFile.getAbsolutePath()); } catch (IOException e) { throw new RuntimeException(e); } finally { if (tempFile != null) { if (!tempFile.delete() && logger.isWarnEnabled()) logger.warn("couldn't delete temp file: " + tempFile.getAbsolutePath()); } } } DeviationDAOCachedMergingMySQL(DataSource dataSource, SqlScriptService sqlScriptService); void starting(); void endUpdate(); void finished(final int tenantId, final int itemTypeId); synchronized Deviation getDeviation(final int tenantId, final int item1Id, final int item1TypeId,
                                               final int item2Id, int item2TypeId); List<Deviation> getDeviationsOrdered(final int tenantId, final int itemTypeId, final int itemId,
                                                final Long minCountConstraint,
                                                final Integer maxNumberOfDeviationsConstraint); @Nonnull Set<TenantItem> getItemIds(final int tenantId, final TIntSet itemTypeIds); synchronized int insertDeviation(final Deviation deviation); synchronized int insertDeviations(final List<Deviation> deviations); @Override String getDefaultTableName(); @Override String getTableCreatingSQLScriptName(); @Override void dropTable(); static final int[] NO_TYPES; }
@Test public void insertDeviations_canInsert2kDeviations() { final int TO_INSERT = 2000; List<Deviation> deviations = new ArrayList<Deviation>(TO_INSERT); for (int i = 0; i < TO_INSERT; i++) deviations.add(new Deviation(null, i, 1, i + 1, 1, i + 2, i * 1.5, i * 10)); int noRows = cachedMergingMySqlDeviationDAO.insertDeviations(deviations); assertThat(noRows, is(TO_INSERT)); }