Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to Isolate Transactions Across Tiers in Postgres / JDBC
    primarykey
    data
    text
    <p>I'm working on a Java project that incorporates a <strong>PostgresSQL 9.0</strong> database tier, using <strong>JDBC</strong>. SQL is wrapped in functions, executed in <strong>Java</strong> like stored procedures using JDBC.</p> <p>The database requires a <em>header-detail</em> scheme, with detail records requiring the foreign-key ID to the header. Thus, the header row is written first, then a couple thousand detail records. <em>I need to prevent the user from accessing the header until the details have completed writing.</em></p> <p>You may suggest wrapping the entire transaction so that the header record cannot be committed until the detail records have completed writing. However, you can see below that I've isolated the transactions to calls in Java: write header, then loop thru details (while writing detail rows). Due the the sheer size of the data, it is not feasible to pass the detailed data to the function to perform one transaction.</p> <p><strong>My question is: how do I wrap the transaction at the JDBC level, so that the header is not committed until the detail records have finished writing?</strong></p> <p>The best solution metaphor would be SQL Server's named transaction's, where the transaction could be started in the data-access layer code (outside other transactions), and completed in a later DB call.</p> <p>The following (simplified) code executes without error, but doesn't resolve the isolation problem:</p> <pre><code>DatabaseManager mgr = DatabaseManager.getInstance(); Connection conn = mgr.getConnection(); CallableStatement proc = null; conn.setAutoCommit(false); proc = conn.prepareCall("BEGIN TRANSACTION"); proc.execute(); //Write header details writeHeader(....); for(Fault fault : faultList) { writeFault(fault, buno, rsmTime, dnld, faultType, verbose); } proc = conn.prepareCall("COMMIT TRANSACTION"); proc.execute(); </code></pre> <p>Your brilliant answer will be much appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload