[ https://issues.apache.org/jira/browse/JENA-1458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16311997#comment-16311997 ]
ASF GitHub Bot commented on JENA-1458: -------------------------------------- Github user afs commented on a diff in the pull request: https://github.com/apache/jena/pull/336#discussion_r159750664 --- Diff: jena-arq/src/main/java/org/apache/jena/sparql/core/mem/DatasetGraphInMemory.java --- @@ -146,25 +162,84 @@ private void _begin(ReadWrite readWrite) { } /** Called transaction start code at most once per transaction. */ - private void startTransaction(ReadWrite mode) { - transactionLock.enterCriticalSection(mode.equals(READ)); // get the dataset write lock, if needed. - transactionType(mode); + private void startTransaction(TxnType txnType, ReadWrite mode) { + transactionLock.enterCriticalSection(mode.equals(ReadWrite.READ)); // get the dataset write lock, if needed. + transactionType.set(txnType); + transactionMode(mode); isInTransaction(true); } /** Called transaction ending code at most once per transaction. */ private void finishTransaction() { isInTransaction.remove(); transactionType.remove(); + transactionMode.remove(); version.remove(); transactionLock.leaveCriticalSection(); } + @Override + public boolean promote() { + if (!isInTransaction()) + throw new JenaTransactionException("Tried to promote outside a transaction!"); + if ( transactionMode().equals(ReadWrite.WRITE) ) + return true; + + boolean readCommitted; + // Initial state + switch(transactionType.get()) { + case WRITE : + return true; + case READ : + throw new JenaTransactionException("Tried to promote READ transaction"); + case READ_COMMITTED_PROMOTE : + readCommitted = true; + case READ_PROMOTE : + readCommitted = false; + // Maybe! + break; + default: + throw new NullPointerException(); + } + + try { + _promote(readCommitted); + return true; + } catch (JenaTransactionException ex) { + return false ; + } + } + + private void _promote(boolean readCommited) { + //System.err.printf("Promote: version=%d generation=%d\n", version.get() , generation.get()) ; + + // Outside lock. + if ( ! readCommited && version.get() != generation.get() ) { --- End diff -- I'll take that as an "approved" :-) and merge it. This PR is big so we can keep reviewing after the merge if people want to make further comments. > Transaction promotion > --------------------- > > Key: JENA-1458 > URL: https://issues.apache.org/jira/browse/JENA-1458 > Project: Apache Jena > Issue Type: Improvement > Affects Versions: Jena 3.6.0 > Reporter: Andy Seaborne > Assignee: Andy Seaborne > > Expose the transaction promotion capabilities of TIM, TDB, and TDB2. -- This message was sent by Atlassian JIRA (v6.4.14#64029)