title: What is a good approach for safe concurrent updates in a relational database?
body: <p>I'm writing a Java app to update a relational database (currently H2). I have a process which does the following:</p>
  
  <ol>
  <li>Query an external system for certain data items </li>
  <li>Check whether or not those items have already been imported into our system by
  checking an import log table. If not: </li>
  <li>Import the new data items into various tables. </li>
  <li>Write a new record into the import log
  table.</li>
  </ol>
  
  <p>This process might be run concurrently in different threads. I'd like to avoid the problem where two threads might both check the import log, find nothing there, and then both attempt to insert the data items.</p>
  
  <p>What might be a good approach? I've been considering:</p>
  
  <ol>
  <li>Using SERIALIZABLE transaction isolation.</li>
  <li>Relying on a unique index constraint in the import log to error and rollback one of the transactions.</li>
  <li>Confining the process to a single thread in the Java app.</li>
  </ol>
  
  <p>None of the above seem very appealing, for various reasons -- is there another approach that might work better?</p>