Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2006, Red Hat Middleware LLC, and individual contributors
   * as indicated by the @author tags.
   * See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   * This copyrighted material is made available to anyone wishing to use,
   * modify, copy, or redistribute it subject to the terms and conditions
   * of the GNU Lesser General Public License, v. 2.1.
  * This program is distributed in the hope that it will be useful, but WITHOUT A
  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
  * You should have received a copy of the GNU Lesser General Public License,
  * v.2.1 along with this distribution; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  * MA  02110-1301, USA.
  *
  * (C) 2005-2006,
  * @author JBoss Inc.
  */
 /*
  * Copyright (C) 1998, 1999, 2000, 2001,
  *
  * Arjuna Solutions Limited,
  * Newcastle upon Tyne,
  * Tyne and Wear,
  * UK.
  *
  * $Id: CadaverRecord.java 2342 2006-03-30 13:06:17Z  $
  */
 
 package com.arjuna.ats.internal.arjuna.abstractrecords;
 
 
Cadaver records are created whenever a persistent object is deleted while still in the scope of an atomic action. This ensures that if the action commits the state of the persistent objects gets properly reflected back in the object participantStore. For objects that are only recoverable such work is unnecessary. Cadaver records replace PersistenceRecords in the record list of an atomic action so they must be merged with such records to enable both commits and aborts to occur.

Author(s):
Mark Little (mark@arjuna.com)
Version:
$Id: CadaverRecord.java 2342 2006-03-30 13:06:17Z $
Since:
JTS 1.0.
 
 
 public class CadaverRecord extends PersistenceRecord
 {

    
Create a new instance, passing in the object that is being managed.

Parameters:
os the state of the object that is being removed.
participantStore the object participantStore instance used to manipulate the persistent state.
sm the object being removed.
 
 
     public CadaverRecord (OutputObjectState osParticipantStore participantStore,
 			  StateManager sm)
     {
 	super(osparticipantStoresm);
 
 	 = ((os != null) ? true : false);
 	 = null;
 
 	if (..isTraceEnabled()) {
         ..trace("CadaverRecord::CadaverRecord(" + os + ", " + sm.get_uid() + ")");
     }
     }

    
Override default AbstractRecord method. CadaverRecords are propagated regardless of the termination condition.

Returns:
true
 
 
     public boolean propagateOnAbort ()
     {
 	return true;
     }

    
The type of the record.

Returns:
RecordType.PERSISTENT
See also:
com.arjuna.ats.arjuna.coordinator.RecordType
    public int typeIs ()
    {
    }

    
The nested transaction has aborted. The record will invalidate any new state.
    public int nestedAbort ()
    {
	if (..isTraceEnabled()) {
        ..trace("CadaverRecord::nestedAbort() for " + order());
    }
	if ( != null)
	     = false;
    }
	/*
	 * No need to forget the action since this object is
	 * being deleted so it is unlikely to have modified called
	 * on it!
	 */
	//	super.forgetAction(false);
    }

    
The nested transaction is preparing. If there is any new state for the object being removed, and that state is valid, then this record will call nestedPrepare on the object being removed. If we have no new state then we cannot commit and must force an abort. Do this by failing the prepare phase.
    public int nestedPrepare ()
    {
	if (..isTraceEnabled()) {
        ..trace("CadaverRecord::nestedPrepare() for " + order());
    }
	    return super.nestedPrepare();
	else
    }

    
The nested transaction has aborted. Invalidate any new state.
    public int topLevelAbort ()
    {
	if (..isTraceEnabled()) {
        ..trace("CadaverRecord::topLevelAbort() for " + order());
    }
	 = false;
    }
	// super.forgetAction(false);
    }

    
At topLevelCommit we commit the uncommitted version already saved into object participantStore. Cannot use inherited version since that assumes object is alive instead talk directly to the object participantStore itself.
    public int topLevelCommit ()
    {
	if (..isTraceEnabled()) {
        ..trace("CadaverRecord::topLevelCommit() for " + order());
    }
	boolean res = true;
	OutputObjectState oState = super.;
	if ((oState != null) && ( == .))
	{
	    if ( == null)
	    try
	    {
		res = .commit_state(oState.stateUid(), oState.type());
	    }
	    catch (ObjectStoreException e)
	    {
		res = false;
	    }
	}
	// super.forgetAction(false);
    }

    
At topLevelPrepare write uncommitted version into object participantStore. Cannot use inherited version since that assumes object is alive instead talk directly to the object participantStore itself.
    public int topLevelPrepare ()
    {
	if (..isTraceEnabled()) {
        ..trace("CadaverRecord::topLevelPrepare() for " + order());
    }
	OutputObjectState oState = ( ? super. : );
	if (oState != null)
	{
	    if ( == .)
	    {
		if ( == null)
		try
		{
		    if (.write_uncommitted(oState.stateUid(), oState.type(), oState))
		    {
			    tlpOk = .;
		    }
		}
		catch (final ObjectStoreException e)
		{
		    e.printStackTrace();
		}
	    }
	    else
	}
	return tlpOk;
    }

    
Override AbstractRecord.print to write specific information to the specified stream.

Parameters:
strm the stream to use.
    public void print (PrintWriter strm)
    {
	strm.println("Cadaver for:");
	super.print(strm);
    }

    
The type of the class - may be used to save information in an hierarchical manner in the object participantStore.
    public String type()
    {
	return "/StateManager/AbstractRecord/RecoveryRecord/PersistenceRecord/CadaverRecord";
    }

    
Override the AbstractRecord.doSave.

Returns:
true if the object being removed is a persistent object (RecordType.PERSISTENT). false otherwise.
See also:
com.arjuna.ats.arjuna.coordinator.RecordType
    public boolean doSave ()
    {
	    return true;
	else
	    return false;
    }

    
merge takes the information from the incoming PersistenceRecord and uses it to initialise the oldState information. This is required for processing of action aborts since CadaverRecords maintain the final state of an object normally - which is required if the action commits.

Parameters:
mergewith The record to merge with.
    public void merge (AbstractRecord mergewith)
    {
	/*
	 *  Following assumes that value returns a pointer to the
	 *  old state maintained in the PersistenceRecord (as an ObjectState).
	 *  Here we create a copy of that state allowing the original
	 *  to be deleted
	 */
	 = mergewith.typeIs();
	if ( != null)
	{
	    if ()
	    {
		 = null;
	    }
	    else
	    {
	    }
	}
    }

    
Overrides AbstractRecord.shouldMerge

Parameters:
ar the record to potentially merge with.
Returns:
true if this instance and the parameter have the same id (order()) and the parameter is either persistent or recoverable. false otherwise.
See also:
com.arjuna.ats.arjuna.coordinator.RecordType
    public boolean shouldMerge (AbstractRecord ar)
    {
	return (((order().equals(ar.order())) &&
		 ((ar.typeIs() == .) ||
		  (ar.typeIs() == .)))
true : false);
    }

    
Overrides AbstractRecord.shouldReplace

Parameters:
ar the record to potentially replace this instance.
Returns:
true if this instance and the parameter have the same id (order()) and the parameter is either persistent or recoverable. false otherwise.
See also:
com.arjuna.ats.arjuna.coordinator.RecordType
    public boolean shouldReplace (AbstractRecord ar)
    {
	return (((order().equals(ar.order())) &&
		 ((ar.typeIs() == .) ||
		  (ar.typeIs() == .)))
true : false);
    }

    
Create a new instance using default values. Typically used during failure recovery.
    public CadaverRecord ()
    {
	super();
	 = false;
	 = null;
	if (..isTraceEnabled()) {
        ..trace("CadaverRecord::CadaverRecord ()");
    }
    }
    private boolean           newStateIsValid;
    private OutputObjectState oldState;
    private int               oType;
New to GrepCode? Check out our FAQ X