org.mmbase.bridge.implementation
Class BasicTransaction

java.lang.Object
  extended by org.mmbase.bridge.implementation.BasicCloud
      extended by org.mmbase.bridge.implementation.BasicTransaction
All Implemented Interfaces:
Serializable, Cloneable, Comparable<Cloud>, Cloud, Transaction, SizeMeasurable

public class BasicTransaction
extends BasicCloud
implements Transaction

The basic implementation for a Transaction cLoud. A Transaction cloud is a cloud which buffers all changes made to nodes - which means that changes are committed only if you commit the transaction itself. This mechanism allows you to rollback changes if something goes wrong.

Version:
$Id: BasicTransaction.java 41394 2010-03-16 09:13:37Z michiel $
Author:
Pierre van Rooden
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.mmbase.bridge.implementation.BasicCloud
BasicCloud.BasicCloudStarter
 
Field Summary
protected  BasicCloud parentCloud
           
protected  String transactionName
          The id of the transaction for use with the transaction manager.
 
Fields inherited from class org.mmbase.bridge.implementation.BasicCloud
account, count, description, locale, name, nodeManagerCache, properties, transactions, userContext
 
Fields inherited from interface org.mmbase.bridge.Cloud
PROP_IGNOREVALIDATION, PROP_REQUEST, PROP_RESPONSE, PROP_SESSIONNAME, PROP_XMLMODE
 
Constructor Summary
BasicTransaction(String name, BasicCloud cloud)
           
 
Method Summary
(package private)  int add(BasicNode node)
          Marks the given node as 'being edited'.
(package private)  void add(String currentObjectContext)
          Ignored by basic cloud.
protected  void afterCommit(BasicNode n)
          This method is called after a of a certain node.
 void cancel()
          Cancels this transaction.
 boolean commit()
          Commits this transaction.
(package private)  boolean contains(MMObjectNode node)
          Checks wether the current transaction contains the given node.
(package private)  void createAlias(BasicNode node, String aliasName)
           
 BasicTransaction createTransaction(String name, boolean overwrite)
          Creates a transaction on this cloud with a specified name.
(package private)  void deleteNewNode(int temporaryNodeId, MMObjectNode node)
           
(package private)  void deleteNode(int temporaryNodeId, MMObjectNode node)
          Ignored by basic cloud.
protected  void finalize()
          If this Transaction is scheduled to be garbage collected, the transaction is canceled and cleaned up.
(package private)  String getAccount()
          The owner to use for the temporary node manager.
 String getCloudName()
          Returns the name of the cloud this transaction uses
protected  Collection<MMObjectNode> getCoreNodes()
           
 String getId()
          Returns the unique ID used for this transaction.
 Node getNode(String nodeNumber)
          Returns the node with the specified number from this cloud.
 NodeList getNodes()
           
 Cloud getNonTransactionalCloud()
          Returns a cloud which is not a Transaction.
 Map<Object,Object> getProperties()
          Retrieves all properties previously set for this cloud.
 Object getProperty(Object key)
          Retrieves a property previously set for this cloud.
 boolean hasNode(String nodeNumber)
          Determines whether a node with the specified number is available from this cloud.
 boolean isCanceled()
          Returns whether the transaction is canceled
 boolean isCommitted()
          Returns whether the transaction is committed
(package private)  BasicNode makeNode(MMObjectNode node, String nodeNumber)
           
protected  void processCommitProcessors(Node n)
          Calls the commit processor for every field.
protected  void processDeleteProcessors(Node n)
          Calls the delete processor for every field.
protected  void setValue(BasicNode node, String fieldName, Object value)
           
 String toString()
           
(package private)  boolean verify()
           
 
Methods inherited from class org.mmbase.bridge.implementation.BasicCloud
_readObject, _writeObject, check, check, checkAlias, checkNodes, compareTo, createAggregatedQuery, createNodeList, createNodeManagerList, createNodeQuery, createQuery, createRelationList, createRelationManagerList, createTransaction, createTransaction, equals, getBasicNodeManager, getBasicNodeManager, getByteSize, getByteSize, getCloudContext, getClusterNodes, getDescription, getFunction, getFunctions, getLastStepList, getList, getList, getLocale, getName, getNode, getNodeByAlias, getNodeManager, getNodeManager, getNodeManagers, getPossibleContexts, getRelation, getRelation, getRelationManager, getRelationManager, getRelationManager, getRelationManager, getRelationManager, getRelationManagers, getRelationManagers, getRelationManagers, getResultNodeList, getSecureList, getTransaction, getUser, hasNode, hasNodeManager, hasRelation, hasRelation, hasRelationManager, hasRelationManager, hasRelationManager, hasRole, isTemporaryId, may, mayRead, mayRead, remove, setLocale, setProperty, setSecurityConstraint, setSecurityConstraint, shutdown, toBasicQuery, uniqueId, verify, verify
 
Methods inherited from class java.lang.Object
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mmbase.bridge.Cloud
createAggregatedQuery, createNodeList, createNodeManagerList, createNodeQuery, createQuery, createRelationList, createRelationManagerList, createTransaction, createTransaction, getCloudContext, getDescription, getFunction, getFunctions, getList, getList, getLocale, getName, getNode, getNodeByAlias, getNodeManager, getNodeManager, getNodeManagers, getPossibleContexts, getRelation, getRelation, getRelationManager, getRelationManager, getRelationManager, getRelationManager, getRelationManagers, getRelationManagers, getRelationManagers, getTransaction, getUser, hasNode, hasNodeManager, hasRelation, hasRelation, hasRelationManager, hasRelationManager, hasRelationManager, hasRole, may, mayRead, mayRead, setLocale, setProperty, shutdown
 

Field Detail

transactionName

protected String transactionName
The id of the transaction for use with the transaction manager. This is the name as speficied by the user, prefixed by the account name.


parentCloud

protected BasicCloud parentCloud
Constructor Detail

BasicTransaction

BasicTransaction(String name,
                 BasicCloud cloud)
Method Detail

getCoreNodes

protected final Collection<MMObjectNode> getCoreNodes()
Since:
MMBase 1.9

getAccount

String getAccount()
Description copied from class: BasicCloud
The owner to use for the temporary node manager.

Overrides:
getAccount in class BasicCloud
Returns:
the account name

getId

public String getId()
Returns the unique ID used for this transaction. The transaction name may not be unique, because different users, may have transactions with the same name.

Since:
MMBase-1.9.3

getNodes

public NodeList getNodes()
Specified by:
getNodes in interface Transaction
Since:
MMBase-1.9

createTransaction

public BasicTransaction createTransaction(String name,
                                          boolean overwrite)
                                   throws AlreadyExistsException
Description copied from interface: Cloud
Creates a transaction on this cloud with a specified name.

Specified by:
createTransaction in interface Cloud
Overrides:
createTransaction in class BasicCloud
Parameters:
name - an unique name to use for the transaction
overwrite - if true, cancels and replaces any existing transaction of this name for the current user
Returns:
a Transaction on this cloud
Throws:
AlreadyExistsException - if a transaction with the specified name allready exists and overwrite is false

verify

boolean verify()

commit

public boolean commit()
Description copied from interface: Transaction
Commits this transaction. This has no effect if the transaction itself was 'nested' in another transaction. In that case, nothing happens until the 'outer' transaction commits. This routine also removes the transaction as an 'active' transaction (it cannot be opened again).

Specified by:
commit in interface Transaction
Returns:
true if the commit succeeded, false otherwise

cancel

public void cancel()
Description copied from interface: Transaction
Cancels this transaction. If the transaction itself was 'nested' in another transaction, that 'outer' transaction is also canceled. This routine also removes the transaction (and all outer transactions) as an 'active' transaction (it cannot be opened again).

Specified by:
cancel in interface Transaction

add

int add(BasicNode node)
Description copied from class: BasicCloud
Marks the given node as 'being edited'. This means that a copy must be made which is going to contain the changes until the node (or the transaction) is committed.

Overrides:
add in class BasicCloud

add

void add(String currentObjectContext)
Description copied from class: BasicCloud
Ignored by basic cloud. See add(String).

Overrides:
add in class BasicCloud

createAlias

void createAlias(BasicNode node,
                 String aliasName)
Overrides:
createAlias in class BasicCloud

deleteNewNode

void deleteNewNode(int temporaryNodeId,
                   MMObjectNode node)
Overrides:
deleteNewNode in class BasicCloud

deleteNode

void deleteNode(int temporaryNodeId,
                MMObjectNode node)
Description copied from class: BasicCloud
Ignored by basic cloud. See delete(String).

Overrides:
deleteNode in class BasicCloud

contains

boolean contains(MMObjectNode node)
Description copied from class: BasicCloud
Checks wether the current transaction contains the given node.

Overrides:
contains in class BasicCloud

makeNode

BasicNode makeNode(MMObjectNode node,
                   String nodeNumber)
Overrides:
makeNode in class BasicCloud

finalize

protected void finalize()
If this Transaction is scheduled to be garbage collected, the transaction is canceled and cleaned up. Unless it has already been committed/canceled, ofcourse, and unless the parentcloud of a transaction is a transaction itself. In that case, the parent transaction should cancel! This means that a transaction is always cleared - if it 'times out', or is not properly removed, it will eventually be removed from the MMBase cache.

Overrides:
finalize in class Object

isCanceled

public boolean isCanceled()
Description copied from interface: Transaction
Returns whether the transaction is canceled

Specified by:
isCanceled in interface Transaction
Returns:
true when canceled

isCommitted

public boolean isCommitted()
Description copied from interface: Transaction
Returns whether the transaction is committed

Specified by:
isCommitted in interface Transaction
Returns:
true when committed

getProperty

public Object getProperty(Object key)
Description copied from interface: Cloud
Retrieves a property previously set for this cloud. If this Cloud has a 'parent' cloud (ie. this Cloud is a Transaction), then this will also mirror properties in this parent cloud.

Specified by:
getProperty in interface Cloud
Overrides:
getProperty in class BasicCloud
Parameters:
key - the key of the property
Returns:
the property value
See Also:
Cloud.setProperty(Object, Object)

getProperties

public Map<Object,Object> getProperties()
Description copied from interface: Cloud
Retrieves all properties previously set for this cloud.

Specified by:
getProperties in interface Cloud
Overrides:
getProperties in class BasicCloud
Returns:
all properties

getCloudName

public String getCloudName()
Description copied from interface: Transaction
Returns the name of the cloud this transaction uses

Specified by:
getCloudName in interface Transaction
Returns:
the name of the cloud
See Also:
Transaction.getCloudName()

toString

public String toString()
Overrides:
toString in class BasicCloud

getNonTransactionalCloud

public Cloud getNonTransactionalCloud()
Description copied from interface: Cloud
Returns a cloud which is not a Transaction.

Specified by:
getNonTransactionalCloud in interface Cloud
Overrides:
getNonTransactionalCloud in class BasicCloud
Returns:
This cloud or a parent cloud if this cloud is a Transaction

processDeleteProcessors

protected void processDeleteProcessors(Node n)
Description copied from class: BasicCloud
Calls the delete processor for every field.

Overrides:
processDeleteProcessors in class BasicCloud

processCommitProcessors

protected void processCommitProcessors(Node n)
Description copied from class: BasicCloud
Calls the commit processor for every field.

Overrides:
processCommitProcessors in class BasicCloud

setValue

protected void setValue(BasicNode node,
                        String fieldName,
                        Object value)
Overrides:
setValue in class BasicCloud

hasNode

public boolean hasNode(String nodeNumber)
Description copied from interface: Cloud
Determines whether a node with the specified number is available from this cloud. If the string passed is not a number, the string is assumed to be an alias. Note that this method does not determine whether you may actually access (read) this node, use Cloud.mayRead(int) to determine this.

Specified by:
hasNode in interface Cloud
Overrides:
hasNode in class BasicCloud
Parameters:
nodeNumber - a string containing the number or alias of the requested node
Returns:
true if the node exists

getNode

public Node getNode(String nodeNumber)
             throws NotFoundException
Description copied from interface: Cloud
Returns the node with the specified number from this cloud. If the string passed is not a number, the string is assumed to be an alias. The returned node is a new instance of Node with a reference to this instance of Cloud.

Specified by:
getNode in interface Cloud
Overrides:
getNode in class BasicCloud
Parameters:
nodeNumber - a string containing the number or alias of the requested node
Returns:
the requested node
Throws:
NotFoundException - if the specified node could not be found

afterCommit

protected void afterCommit(BasicNode n)
Description copied from class: BasicCloud
This method is called after a of a certain node. If we are not in a transaction this performing the actual commit procedure (using the temporary object manager), and calls Object.notifyAll(). This last thing makes it easy to wait for a node to really exist (finished committing)
                synchronized(ntCloud) {
                    while (! ntCloud.hasNode(node)) {
                        ntCloud.wait();
                    }
                }
     
Committing in a transaction goes a bit different, because the actual committing only happens in the , this method will be mostly empty for BasicTransaction.

Overrides:
afterCommit in class BasicCloud


MMBase 2.0-SNAPSHOT - null