/** Loads a CSV file into a table */ public void loadCSV(String table, File input, boolean clearTable, char separator) throws IOException, SQLException { if (clearTable) executeUpdate("DELETE FROM " + table); ResultSet r = query(limit("SELECT * FROM " + table, 1)); int[] types = new int[r.getMetaData().getColumnCount()]; for (int i = 0; i < types.length; i++) types[i] = r.getMetaData().getColumnType(i + 1); close(r); Inserter bulki = newInserter(table, types); boolean start = true; for (List<String> values : new CSVLines(input)) { if (start) { if (values.size() != types.length) { throw new SQLException( "File " + input.getName() + " has " + values.size() + " columns, but table " + table + " has " + types.length); } start = false; continue; } if (values.size() != types.length) { Announce.warning( "Line cannot be read from file", input.getName(), "into table", table, ":\n", values); continue; } bulki.insert((Object[]) values.toArray()); } bulki.close(); }
@Test @JUnitTemporaryDatabase public void testConcurrentInsert() throws InterruptedException { Inserter one = new Inserter(m_upsertService, m_populator.getNode1().getId(), 1001, "ifName1"); Inserter two = new Inserter(m_upsertService, m_populator.getNode1().getId(), 1001, "ifName2"); one.start(); two.start(); one.join(); two.join(); assertNull("Exception on upsert two " + two.getThrowable(), two.getThrowable()); assertNull("Exception on upsert one " + one.getThrowable(), one.getThrowable()); }