Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.mapdb;


Transaction factory

Author(s):
Jan Kotek
 
 public class TxMaker {

    
marker for deleted record
    protected static final Object DELETED = new Object();
    private final boolean txSnapshotsEnabled;
    private final boolean strictDBGet;

    
parent engine under which modifications are stored
    protected Engine engine;
    public TxMaker(Engine engine) {
        this(engine,false,false);
    }
    public TxMaker(Engine engineboolean strictDBGetboolean txSnapshotsEnabled) {
        if(engine==nullthrow new IllegalArgumentException();
        if(!engine.canSnapshot())
            throw new IllegalArgumentException("Snapshot must be enabled for TxMaker");
        if(engine.isReadOnly())
            throw new IllegalArgumentException("TxMaker can not be used with read-only Engine");
        this. = engine;
        this. = strictDBGet;
        this. = txSnapshotsEnabled;
    }
    
    public DB makeTx(){
        Engine snapshot = .snapshot();
        if()
            snapshot = new TxEngine(snapshot,false);
        return new DB(snapshot,);
    }
    public void close() {
        .close();
         = null;
    }

    
Executes given block withing single transaction. If block throws TxRollbackException execution is repeated until it does not fail.

Parameters:
txBlock
    public void execute(TxBlock txBlock) {
        for(;;){
            DB tx = makeTx();
            try{
                txBlock.tx(tx);
                if(!tx.isClosed())
                    tx.commit();
                return;
            }catch(TxRollbackException e){
                //failed, so try again
                if(!tx.isClosed()) tx.close();
            }
        }
    }

    
Executes given block withing single transaction. If block throws TxRollbackException execution is repeated until it does not fail. This method returns result returned by txBlock.

Parameters:
txBlock
    public <A> A execute(Fun.Function1<A, DBtxBlock) {
        for(;;){
            DB tx = makeTx();
            try{
                A a = txBlock.run(tx);
                if(!tx.isClosed())
                    tx.commit();
                return a;
            }catch(TxRollbackException e){
                //failed, so try again
                if(!tx.isClosed()) tx.close();
            }
        }
    }
New to GrepCode? Check out our FAQ X