org.akubraproject.txn
Class AbstractTransactionalConnection

java.lang.Object
  extended by org.akubraproject.impl.AbstractBlobStoreConnection
      extended by org.akubraproject.txn.AbstractTransactionalConnection
All Implemented Interfaces:
Synchronization, org.akubraproject.BlobStoreConnection
Direct Known Subclasses:
SQLTransactionalConnection

public abstract class AbstractTransactionalConnection
extends org.akubraproject.impl.AbstractBlobStoreConnection
implements Synchronization

A basic superclass for transactional store connections. This implements the common blob-handling parts of a transactional connection, leaving subclasses to implement the transactional management of the id-mappings.

Subclasses must implement getRealId, remNameEntry, addNameEntry, listBlobIds, and override close; in addition they may want to override beforeCompletion and/or afterCompletion for pre- and post-commit/rollback processing.

The subclass is expected to implement id mapping, mapping upper-level blob-id's to underlying blob-id's; these mappings are managed via the remNameEntry and addNameEntry method, and getRealId is used to query the mapping.

Author:
Ronald Tschalär

Nested Class Summary
protected  class AbstractTransactionalConnection.TxnBlob
          A transactional blob implementation.
 
Field Summary
protected  Map<URI,org.akubraproject.Blob> blobCache
          a cache of blobs
protected  org.akubraproject.BlobStoreConnection bStoreCon
          the underlying blob-store that actually stores the blobs
protected  List<URI> delBlobs
          the list of underlying id's of deleted blobs
protected  boolean isCompleted
          Whether or not the current transaction has been completed yet
protected  List<URI> newBlobs
          the list of underlying id's of added blobs
protected  Transaction tx
          the transaction this connection belongs to
 
Fields inherited from class org.akubraproject.impl.AbstractBlobStoreConnection
closed, owner, streamManager
 
Constructor Summary
protected AbstractTransactionalConnection(org.akubraproject.BlobStore owner, org.akubraproject.BlobStore bStore, Transaction tx, Map<String,String> hints)
          Create a new transactional connection.
 
Method Summary
protected  void addBlob(URI ourId, URI storeId)
          Add a blob to the underlying store.
protected abstract  void addNameEntry(URI ourId, URI storeId)
          Add an id mapping.
 void afterCompletion(int status)
          Invoked after the transaction has completed, i.e.
 void beforeCompletion()
          Invoked before the transaction is completed, i.e.
 org.akubraproject.Blob getBlob(URI blobId, Map<String,String> hints)
           
protected abstract  URI getRealId(URI blobId)
          Look up the underlying store's blob-id for the given upper-level blob-id.
protected  void remBlob(URI ourId, URI storeId)
          Remove a blob from the underlying store.
protected abstract  void remNameEntry(URI ourId, URI storeId)
          Remove an id mapping.
 void sync()
           
protected  void validateId(URI blobId)
          Check whether we can store this id.
 
Methods inherited from class org.akubraproject.impl.AbstractBlobStoreConnection
close, ensureOpen, getBlob, getBlobStore, isClosed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.akubraproject.BlobStoreConnection
listBlobIds
 

Field Detail

bStoreCon

protected final org.akubraproject.BlobStoreConnection bStoreCon
the underlying blob-store that actually stores the blobs


tx

protected final Transaction tx
the transaction this connection belongs to


isCompleted

protected boolean isCompleted
Whether or not the current transaction has been completed yet


newBlobs

protected final List<URI> newBlobs
the list of underlying id's of added blobs


delBlobs

protected final List<URI> delBlobs
the list of underlying id's of deleted blobs


blobCache

protected final Map<URI,org.akubraproject.Blob> blobCache
a cache of blobs

Constructor Detail

AbstractTransactionalConnection

protected AbstractTransactionalConnection(org.akubraproject.BlobStore owner,
                                          org.akubraproject.BlobStore bStore,
                                          Transaction tx,
                                          Map<String,String> hints)
                                   throws IOException
Create a new transactional connection.

Parameters:
owner - the blob-store we belong to
bStore - the underlying blob-store to use
tx - the transaction we belong to
hints - A set of hints for the openConnection on the wrapped store
Throws:
IOException - if an error occurs initializing this connection
Method Detail

getBlob

public org.akubraproject.Blob getBlob(URI blobId,
                                      Map<String,String> hints)
                               throws IOException
Specified by:
getBlob in interface org.akubraproject.BlobStoreConnection
Throws:
IOException

sync

public void sync()
          throws IOException
Specified by:
sync in interface org.akubraproject.BlobStoreConnection
Throws:
IOException

validateId

protected void validateId(URI blobId)
                   throws org.akubraproject.UnsupportedIdException
Check whether we can store this id.

Parameters:
blobId - the upper level blob-id
Throws:
org.akubraproject.UnsupportedIdException - if the id cannot be stored

getRealId

protected abstract URI getRealId(URI blobId)
                          throws IOException
Look up the underlying store's blob-id for the given upper-level blob-id.

Parameters:
blobId - the upper level blob-id
Returns:
the underlying blob-id that blobId maps to, or null if no such mapping exists (i.e. blobId is not a known upper-level blob-id)
Throws:
IOException - if an error occurred looking up the id

remNameEntry

protected abstract void remNameEntry(URI ourId,
                                     URI storeId)
                              throws IOException
Remove an id mapping.

Parameters:
ourId - the upper-level blob-id
storeId - the underlying store's blob-id
Throws:
IOException - if an error occurred removing the mapping or the mapping does not exist

addNameEntry

protected abstract void addNameEntry(URI ourId,
                                     URI storeId)
                              throws IOException
Add an id mapping.

Parameters:
ourId - the upper-level blob-id to map
storeId - the underlying store's blob-id to map ourId to
Throws:
IOException - if an error occurred adding the mapping or the mapping already exists

remBlob

protected void remBlob(URI ourId,
                       URI storeId)
                throws IOException
Remove a blob from the underlying store. This implementation just updates the newBlobs and delBlobs lists; actual blob deletion is deferred till commit.

Parameters:
ourId - the upper-level blob-id
storeId - the underlying store's blob-id
Throws:
IOException - if an error occurred removing the blob or the blob does not exist

addBlob

protected void addBlob(URI ourId,
                       URI storeId)
                throws IOException
Add a blob to the underlying store. This implementation just updates the newBlobs list; actual blob writing is done via the blob itself..

Parameters:
ourId - the upper-level blob-id
storeId - the underlying store's blob-id
Throws:
IOException - if an error occurred removing the blob or the blob does not exist

beforeCompletion

public void beforeCompletion()
Invoked before the transaction is completed, i.e. before a rollback or commit is started. Whether or not this is called on a rollback may vary.

Specified by:
beforeCompletion in interface Synchronization
See Also:
Synchronization.beforeCompletion()

afterCompletion

public void afterCompletion(int status)
Invoked after the transaction has completed, i.e. after a rollback or commit has finished. This is always callled.

Subclasses that override this must make sure to invoke super.afterCompletion so that the cleanup code in this implementation is run. This implementation cleans up deleted or added blobs (depending on the outcome of the transaction).

Specified by:
afterCompletion in interface Synchronization
See Also:
Synchronization.afterCompletion(int)


Copyright © 2009-2012 DuraSpace. All Rights Reserved.