Search in sources :

Example 1 with DisposeRecord

use of com.arjuna.ats.internal.arjuna.abstractrecords.DisposeRecord in project narayana by jbosstm.

the class StateManager method destroy.

/**
 * Destroy the object (e.g., remove its state from the persistent store.)
 * Calls to destroy for volatile objects (ones not maintained within the
 * volatile object store) are ignored, and FALSE is returned.
 *
 * @return <code>true</code> on success, <code>false</code> otherwise.
 */
public synchronized boolean destroy() {
    if (tsLogger.logger.isTraceEnabled()) {
        tsLogger.logger.trace("StateManager::destroy for object-id " + objectUid);
    }
    boolean result = false;
    if (participantStore != null) {
        BasicAction action = BasicAction.Current();
        if (// add will fail if the status is wrong!
        action != null) {
            DisposeRecord dr = new DisposeRecord(participantStore, this);
            if (action.add(dr) != AddOutcome.AR_ADDED) {
                dr = null;
                tsLogger.i18NLogger.warn_StateManager_6(action.get_uid());
            } else
                result = true;
        } else {
            try {
                result = participantStore.remove_committed(get_uid(), type());
                if (result)
                    destroyed();
            } catch (Exception e) {
                tsLogger.i18NLogger.warn_StateManager_7(e);
                result = false;
            }
        }
    } else {
        /*
             * Not a persistent object!
             */
        tsLogger.i18NLogger.warn_StateManager_8();
    }
    return result;
}
Also used : BasicAction(com.arjuna.ats.arjuna.coordinator.BasicAction) DisposeRecord(com.arjuna.ats.internal.arjuna.abstractrecords.DisposeRecord) IOException(java.io.IOException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException)

Example 2 with DisposeRecord

use of com.arjuna.ats.internal.arjuna.abstractrecords.DisposeRecord in project narayana by jbosstm.

the class RecordListUnitTest method test.

@Test
public void test() throws Exception {
    RecordList rl = new RecordList();
    DisposeRecord dr = new DisposeRecord();
    rl.insert(dr);
    assertEquals(rl.getFront(), dr);
    rl.insert(dr);
    assertEquals(rl.getRear(), dr);
    RecordList copy = new RecordList(rl);
    ActivationRecord ar = new ActivationRecord();
    rl.insert(ar);
    rl.print(new PrintWriter(new ByteArrayOutputStream()));
    assertTrue(rl.toString() != null);
    assertEquals(rl.getNext(dr), null);
    assertTrue(rl.peekFront() != null);
    assertTrue(rl.peekRear() != null);
    assertEquals(rl.peekNext(dr), null);
    assertTrue(rl.remove(dr));
}
Also used : RecordList(com.arjuna.ats.arjuna.coordinator.RecordList) ActivationRecord(com.arjuna.ats.internal.arjuna.abstractrecords.ActivationRecord) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DisposeRecord(com.arjuna.ats.internal.arjuna.abstractrecords.DisposeRecord) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 3 with DisposeRecord

use of com.arjuna.ats.internal.arjuna.abstractrecords.DisposeRecord in project narayana by jbosstm.

the class CadaverRecordUnitTest method test.

@Test
public void test() {
    ParticipantStore store = StoreManager.setupStore(null, StateType.OS_UNSHARED);
    CadaverRecord cr = new CadaverRecord(new OutputObjectState(), store, new ExtendedObject());
    assertTrue(cr.propagateOnAbort());
    assertTrue(cr.propagateOnCommit());
    assertEquals(cr.typeIs(), RecordType.PERSISTENCE);
    assertTrue(cr.type() != null);
    assertEquals(cr.doSave(), false);
    cr.merge(new PersistenceRecord(new OutputObjectState(), store, new ExtendedObject()));
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.nestedAbort(), TwoPhaseOutcome.FINISH_OK);
    cr = new CadaverRecord(new OutputObjectState(), store, new ExtendedObject());
    cr.merge(new PersistenceRecord(new OutputObjectState(), store, new ExtendedObject()));
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.nestedCommit(), TwoPhaseOutcome.FINISH_OK);
    cr = new CadaverRecord(new OutputObjectState(new Uid(), "foobar"), store, new ExtendedObject());
    cr.merge(new PersistenceRecord(new OutputObjectState(new Uid(), "foobar"), store, new ExtendedObject()));
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(cr.topLevelAbort(), TwoPhaseOutcome.FINISH_OK);
    cr = new CadaverRecord(new OutputObjectState(new Uid(), "foobar"), store, new ExtendedObject());
    cr.merge(new PersistenceRecord(new OutputObjectState(new Uid(), "foobar"), store, new ExtendedObject()));
    cr.merge(new PersistenceRecord(new OutputObjectState(new Uid(), "foobar"), store, new ExtendedObject()));
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(cr.topLevelCommit(), TwoPhaseOutcome.FINISH_OK);
    cr = new CadaverRecord();
    cr.print(new PrintWriter(new ByteArrayOutputStream()));
    assertFalse(cr.shouldMerge(new DisposeRecord()));
    assertFalse(cr.shouldReplace(new DisposeRecord()));
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) ExtendedObject(com.hp.mwtests.ts.arjuna.resources.ExtendedObject) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) PersistenceRecord(com.arjuna.ats.internal.arjuna.abstractrecords.PersistenceRecord) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ParticipantStore(com.arjuna.ats.arjuna.objectstore.ParticipantStore) DisposeRecord(com.arjuna.ats.internal.arjuna.abstractrecords.DisposeRecord) CadaverRecord(com.arjuna.ats.internal.arjuna.abstractrecords.CadaverRecord) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 4 with DisposeRecord

use of com.arjuna.ats.internal.arjuna.abstractrecords.DisposeRecord in project narayana by jbosstm.

the class DisposeRecordUnitTest method test.

@Test
public void test() {
    ParticipantStore store = StoreManager.setupStore(null, StateType.OS_UNSHARED);
    DisposeRecord cr = new DisposeRecord(store, new ExtendedObject());
    assertFalse(cr.propagateOnAbort());
    assertTrue(cr.propagateOnCommit());
    assertEquals(cr.typeIs(), RecordType.DISPOSE);
    assertTrue(cr.type() != null);
    assertEquals(cr.doSave(), true);
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(cr.nestedAbort(), TwoPhaseOutcome.FINISH_OK);
    cr = new DisposeRecord(store, new ExtendedObject());
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(cr.nestedCommit(), TwoPhaseOutcome.FINISH_OK);
    cr = new DisposeRecord(store, new ExtendedObject());
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(cr.topLevelAbort(), TwoPhaseOutcome.FINISH_OK);
    cr = new DisposeRecord(store, new ExtendedObject());
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(cr.topLevelCommit(), TwoPhaseOutcome.FINISH_OK);
    cr = new DisposeRecord();
    assertFalse(cr.shouldAdd(new PersistenceRecord()));
    assertFalse(cr.shouldAlter(new PersistenceRecord()));
    assertFalse(cr.shouldMerge(new PersistenceRecord()));
    assertFalse(cr.shouldReplace(new PersistenceRecord()));
    assertFalse(cr.save_state(new OutputObjectState(), ObjectType.ANDPERSISTENT));
    assertFalse(cr.restore_state(new InputObjectState(), ObjectType.ANDPERSISTENT));
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) ExtendedObject(com.hp.mwtests.ts.arjuna.resources.ExtendedObject) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) PersistenceRecord(com.arjuna.ats.internal.arjuna.abstractrecords.PersistenceRecord) ParticipantStore(com.arjuna.ats.arjuna.objectstore.ParticipantStore) DisposeRecord(com.arjuna.ats.internal.arjuna.abstractrecords.DisposeRecord) Test(org.junit.Test)

Aggregations

DisposeRecord (com.arjuna.ats.internal.arjuna.abstractrecords.DisposeRecord)4 Test (org.junit.Test)3 ParticipantStore (com.arjuna.ats.arjuna.objectstore.ParticipantStore)2 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)2 PersistenceRecord (com.arjuna.ats.internal.arjuna.abstractrecords.PersistenceRecord)2 ExtendedObject (com.hp.mwtests.ts.arjuna.resources.ExtendedObject)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintWriter (java.io.PrintWriter)2 Uid (com.arjuna.ats.arjuna.common.Uid)1 BasicAction (com.arjuna.ats.arjuna.coordinator.BasicAction)1 RecordList (com.arjuna.ats.arjuna.coordinator.RecordList)1 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)1 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)1 ActivationRecord (com.arjuna.ats.internal.arjuna.abstractrecords.ActivationRecord)1 CadaverRecord (com.arjuna.ats.internal.arjuna.abstractrecords.CadaverRecord)1 IOException (java.io.IOException)1