Nested transactions

CREATE, READ, UPDATE and DELETE (CRUD) operations are always executed in the context of a transaction. Transaction execution is controlled with the following four API methods.

public TXContext begin();
public void prepare() throws ConstraintViolationException;
public void commit() throws ConstraintViolationException;
public void rollback();

Please notice, that the begin() method needn't be called explicitely at a transaction boundary (commit / rollback). Thus the begin() method solely serves the purpose of starting a nested transaction. Therefore you are able to set savepoints within a running transaction.

// initialise a file-based database and obtain a session to it
EOContainerSession eocSession =
 FileEOC.createEOC(new File("feature.sdf"), 100).getSession();

// create an entity object
Person person = eocSession.insert( Person() );

// start a nested transaction		
TXContext nestedTX = eocSession.begin();

// make some change in the context of the nested transaction
person.setFirstname( "Christian" );

// commit the nested transaction
nestedTX.commit();

// rollback the main transaction
eocSession.rollback();
>> Show next feature
>> Back to the feature list