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: PersistenceRecord.java 2342 2006-03-30 13:06:17Z  $
  */
 
 package com.arjuna.ats.internal.arjuna.abstractrecords;
 
 
A PersistenceRecord is created whenever a persistent object is created/read/modified within the scope of a transaction. It is responsible for ensuring that state changes are committed or rolled back on behalf of the object depending upon the outcome of the transaction.

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

This constructor is used to create a new instance of PersistenceRecord.
 
 
 	public PersistenceRecord (OutputObjectState osParticipantStore participantStoreStateManager sm)
 	{
 		super(ossm);
 
 		if (..isTraceEnabled()) {
             ..trace("PersistenceRecord::PersistenceRecord("
                     + os + ", " + sm.get_uid() + ")");
         }
 
 		 = false;
 		this. = participantStore;
 		 = null;
 	}

Redefintions of abstract functions inherited from RecoveryRecord.
 
 
 	public int typeIs ()
 	{
 	}

topLevelAbort may have to remove the persistent state that was written into the object store during the processing of topLevelPrepare. It then does the standard abort processing.
 
 
 	public int topLevelAbort ()
 	{
 	    if (..isTraceEnabled()) {
 	        ..trace("PersistenceRecord::topLevelAbort() for "
	                + order());
	    }
	    Uid uid = null;
	    String type = null;
	    if (// state written by StateManager instance
	    {
	        uid = order();
	        type = getTypeOfObject();
	    }
	    else
	    {
	        if ( == null// hasn't been prepared, so no state
	        {
	            return nestedAbort();
	        }
	        else
	        {
	            uid = .stateUid();
	            type = .type();
	        }
	    }
	    try
	    {
	        if (!.remove_uncommitted(uidtype)) {
	            return .;
	        }
	    }
	    catch (ObjectStoreException e) {
	        return .;
	    }
	    return nestedAbort();
	}

commit the state saved during the prepare phase.
	public int topLevelCommit ()
	{
		if (..isTraceEnabled()) {
            ..trace("PersistenceRecord::topLevelCommit() : About to commit state, "+
                    "uid = "+order()+", ObjType = "+getTypeOfObject());
        }
		if (..isTraceEnabled())
		{
			if ( != null) {
                ..trace(", store = "
                        +  + "(" + .getClass().getCanonicalName() + ")");
            }
			else {
                ..trace("");
            }
		}
		boolean result = false;
		if ( != null)
		{
			try
			{
				{
					if (!result) {
                        ..warn_PersistenceRecord_2(order());
                    }
				}
				else
				{
					if ( != null)
					{
					}
					else {
                        ..warn_PersistenceRecord_3();
                    }
				}
			}
			catch (ObjectStoreException e) {
                ..warn_PersistenceRecord_4(e);
                result = false;
            }
		}
		else {
        }
		if (!result) {
        }
		super.forgetAction(true);
		return ((result) ? .
	}

topLevelPrepare attempts to save the object. It will either do this in the action intention list or directly in the object store by using the 'deactivate' function of the object depending upon the size of the state. To ensure that objects are correctly hidden while they are in an uncommitted state if we use the abbreviated protocol then we write an EMPTY object state as the shadow state - THIS MUST NOT BE COMMITTED. Instead we write_committed the one saved in the intention list. If the store cannot cope with being given an empty state we revert to the old protocol.
	public int topLevelPrepare ()
	{
		if (..isTraceEnabled()) {
            ..trace("PersistenceRecord::topLevelPrepare() for "
                    + order());
        }
		StateManager sm = super.;
		if ((sm != null) && ( != null))
		{
		    /*
		     * Get ready to create our state to be saved. At this stage we're not
		     * sure if the state will go into its own log or be written into the
		     * transaction log for improved performance.
		     */
		    
			{
			    /*
			     * We assume that crash recovery will always run before
			     * the object can be reactivated!
			     */
				{
							Uid.nullUid(), null);
					/*
					 * Write an empty shadow state to the store to indicate one
					 * exists, and to prevent bogus activation in the case where
					 * crash recovery hasn't run yet.
					 */
					try
					{
						    result = .;
						else
						{
						    result = .;
						}
					}
					catch (ObjectStoreException e) {
                        ..warn_PersistenceRecord_21(e);
                    }
					dummy = null;
				}
				else
				{
				    /*
				     * Don't write anything as our state will go into the log.
				     */
				    
				}
			}
			else
			{
			    {
			         = true;
			        result = .;
			    }
			    else 
			    {
			         = null;
			        
			    }
			}
		}
		else {
        }
		return result;
	}

topLevelCleanup must leave the persistent state that was written in the object store during the processing of topLevelPrepare intact. Crash recovery will take care of its resolution
	public int topLevelCleanup ()
	{
		if (..isTraceEnabled()) {
            ..trace("PersistenceRecord::topLevelCleanup() for "
                    + order());
        }
	}

Returns:
true
	public boolean doSave ()
	{
		return true;
	}
    public boolean restore_state (InputObjectState osint ot)
	{
		if (..isTraceEnabled()) {
            ..trace("PersistenceRecord::restore_state() for "
                    + order());
        }
		boolean res = false;
		 = null;
        try
        {
             = os.unpackBoolean();
            // topLevelState = null;
            if (!)
            {
                 = new OutputObjectState(os);
                res = .valid();
            }
            else
                res = true;
            res = (res && super.restore_state(osot));
            // Note: we don't persist the targetParticipantStore, instead assuming the
            // default one present at recovery time will be equivalent. Changing the
            // objectstore config when records exist in the tx store is therefore a Bad Thing.
             = getStore();
            return res;
        }
        catch (final Exception e) {
        }
		return res;
	}
	public boolean save_state (OutputObjectState osint ot)
	{
		if (..isTraceEnabled()) {
            ..trace("PersistenceRecord::save_state() for "
                    + order());
        }
		boolean res = true;
		if ( != null)
		{
            // Note: we don't persist the targetParticipantStore, instead assuming the
            // default one present at recovery time will be equivalent. Changing the
            // objectstore config when records exist in the tx store is therefore a Bad Thing.
            try
            {
                os.packBoolean();
                /*
                         * If we haven't written a shadow state, then pack the state
                         * into the transaction log. There MUST be a state at this
                         * point.
                         */
                if (!)
                {
                    res = ( != null);
                    if (res)
                        .packInto(os);
                    else {
                        ..warn_PersistenceRecord_14();
                    }
                }
            }
            catch (IOException e) {
                res = false;
                ..warn_PersistenceRecord_15();
            }
		}
		else {
            try {
                os.packString(null);
            }
            catch (IOException e) {
                res = false;
            }
        }
		return res && super.save_state(osot);
	}
	public void print (PrintWriter strm)
	{
		super.print(strm); /* bypass RecoveryRecord */
		strm.println("PersistenceRecord with state:\n" + super.);
	}
	public String type ()
	{
		return "/StateManager/AbstractRecord/RecoveryRecord/PersistenceRecord";
	}

Creates a 'blank' persistence record. This is used during crash recovery when recreating the prepared list of a server atomic action.
	{
		super();
		if (..isTraceEnabled()) {
            ..trace("PersistenceRecord::PersistenceRecord() - crash recovery constructor");
        }
		 = false;
		 = null;
	}

Cadaver records force write shadows. This operation supresses to abbreviated commit This should never return false
	protected boolean shadowForced ()
	{
		if ( == null)
		{
			 = true;
			return true;
		}
		/* I've already done the abbreviated protocol so its too late */
		return false;
	}
	// this value should really come from the object store implementation!
	public static final int MAX_OBJECT_SIZE = 4096; // block size
	protected boolean shadowMade;
	protected static boolean classicPrepare = false;
	private static boolean writeOptimisation = false;
	static
	{
         = arjPropertyManager.getCoordinatorEnvironmentBean().isClassicPrepare();
         = arjPropertyManager.getCoordinatorEnvironmentBean().isWriteOptimisation();
	}
New to GrepCode? Check out our FAQ X