Search in sources :

Example 1 with Sequence

use of commonj.sdo.Sequence in project eclipselink by eclipse-ee4j.

the class SDODataObject method undoChanges.

/**
 * INTERNAL:
 * This function reverses any operations that were performed on this object since change tracking
 * was turned on.  The object is returned to the state when logging was first started.<br>
 * @param isCSRoot
 * @param cs
 * @param origContainer
 * @param origContainmentPropName
 */
public // 
void undoChanges(// 
boolean isCSRoot, // 
ChangeSummary cs, SDODataObject origContainer, String origContainmentPropName) {
    // dont do anything if the changeSummary is null
    if (null == cs) {
        return;
    }
    // base step: swap valueStores at the current node
    if (((SDOChangeSummary) cs).isDirty(this)) {
        // reset only if changes were done
        if (!isCSRoot) {
            // reset changeSummary
            if (null == changeSummary) {
                // we are not recursively setting cs - so don't use the set function as child nodes will be replaced later
                changeSummary = (SDOChangeSummary) cs;
            }
            // reset container
            if (null == container) {
                _setContainer(origContainer);
            }
            // reset containmentProperty name
            if (null == containmentPropertyName) {
                _setContainmentPropertyName(origContainmentPropName);
            }
        }
        // swap valueStores
        _setCurrentValueStore((ValueStore) ((SDOChangeSummary) cs).getOriginalValueStores().get(this));
        // return original to null (no changes)
        ((SDOChangeSummary) cs).getOriginalValueStores().remove(this);
    }
    // swap sequences (may be UC2(DataObject and sequence change) or UC4 (sequence change only)
    if (getType().isSequenced()) {
        // perform sequence.isDirty check independent of a dataObject.isDirty check
        if (((SDOChangeSummary) cs).isDirty(sequence)) {
            Sequence currentSequence = sequence;
            SDOSequence originalSequence = (SDOSequence) ((SDOChangeSummary) cs).getOriginalSequences().get(this);
            // both sequences are either null or set
            if ((null == originalSequence) && (null != currentSequence)) {
                throw SDOException.oldSequenceNotFound();
            } else {
                sequence = originalSequence;
            }
            // reset the cache map
            ((SDOChangeSummary) cs).getOldSequences().remove(this);
            // rest the primary map
            ((SDOChangeSummary) cs).getOriginalSequences().remove(this);
        }
    }
    // restore any open content properties to the 3 data structures on SDODataObject, and remove from cs.unsetOCPropsMap
    // see openContentPropertiesMap<String,Property>, openContentProperties(List<Property>). instanceProperties (List<Property>)
    List oldUnsetOCList = ((SDOChangeSummary) cs).getUnsetOCProperties(this);
    for (int i = 0, size = oldUnsetOCList.size(); i < size; i++) {
        // it is essential that the oc property is removed from the cs or we will get an unsupported op during resetChanges()
        // the property will be added only when logging=true, we reference the first item in the list as it reduces in size
        addOpenContentProperty((Property) oldUnsetOCList.get(0));
    }
    // recursive step: swap valueStores on every contained subtree
    for (Iterator iterProperties = getInstanceProperties().iterator(); iterProperties.hasNext(); ) {
        SDOProperty property = (SDOProperty) iterProperties.next();
        if (!property.getType().isChangeSummaryType()) {
            Object value = get(property);
            if ((null == value) && (null != getChangeSummary())) {
            // no changes for null properties
            } else {
                if (property.isMany()) {
                    // assumption that we never have a null ListWrapper should still avoid a possible NPE
                    if (null != value) {
                        ((ListWrapper) value).undoChanges(getChangeSummary());
                        if (!property.getType().isDataType()) {
                            for (Iterator iterMany = ((List) value).iterator(); iterMany.hasNext(); ) {
                                Object valueMany = iterMany.next();
                                if (null != valueMany) {
                                    // handle micro-corner case ListWrapper is null
                                    ((SDODataObject) valueMany).undoChanges(false, changeSummary, this, property.getName());
                                }
                            }
                        }
                    }
                } else {
                    if (!property.getType().isDataType() && (null != value)) {
                        ((SDODataObject) value).undoChanges(false, changeSummary, this, property.getName());
                    }
                }
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) ListWrapper(org.eclipse.persistence.sdo.helper.ListWrapper) ArrayList(java.util.ArrayList) List(java.util.List) DataObject(commonj.sdo.DataObject) SequencedObject(org.eclipse.persistence.oxm.sequenced.SequencedObject) Sequence(commonj.sdo.Sequence)

Example 2 with Sequence

use of commonj.sdo.Sequence in project eclipselink by eclipse-ee4j.

the class XPathEngine method set.

/**
 * Set a property's value.
 *
 * @param lastProperty      the property to queries.
 * @param lastDataObject    the DataObject, owner of the queried property
 * @param numInLastProperty the index number in the value list of the above property
 * @param value             the value to be set as the target property's value
 * @param convertValue     boolean used for set if we should convert the value
 */
private void set(Property lastProperty, DataObject lastDataObject, int numInLastProperty, Object value, boolean convertValue) {
    if (numInLastProperty == -1) {
        if (lastDataObject != null) {
            if (convertValue) {
                DataHelper dataHelper = ((SDODataObject) lastDataObject).getType().getHelperContext().getDataHelper();
                value = dataHelper.convert(lastProperty, value);
            }
            lastDataObject.set(lastProperty, value);
        } else {
            throw new IllegalArgumentException("lastDataObject is null");
        }
    } else {
        // case like set("a/b.1", List) will cause a list be added into a existed list
        List objects = lastDataObject.getList(lastProperty);
        if (convertValue) {
            DataHelper dataHelper = ((SDODataObject) lastDataObject).getType().getHelperContext().getDataHelper();
            value = dataHelper.convert(lastProperty.getType(), value);
        }
        Sequence seq = lastDataObject.getSequence();
        if (seq != null) {
            seq.setValue(numInLastProperty, value);
        } else {
            objects.set(numInLastProperty, value);
        }
    }
}
Also used : List(java.util.List) DataHelper(commonj.sdo.helper.DataHelper) Sequence(commonj.sdo.Sequence) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 3 with Sequence

use of commonj.sdo.Sequence in project eclipselink by eclipse-ee4j.

the class SDOTestCase method assertSequencesCopiedAndSwappedAfterFirstModifyOperation.

protected void assertSequencesCopiedAndSwappedAfterFirstModifyOperation(DataObject aRootObject, Sequence aCurrentSequenceAfterLoggingFirstOnParam) {
    // verify logging is on
    assertTrue(aRootObject.getChangeSummary().isLogging());
    assertNotNull(aCurrentSequenceAfterLoggingFirstOnParam);
    Sequence anOriginalSequenceAfterOperation = (Sequence) ((SDOChangeSummary) aRootObject.getChangeSummary()).getOriginalSequences().get(aRootObject);
    Sequence aCurrentSequenceAfterOperation = ((SDODataObject) aRootObject).getSequence();
    assertNotNull(anOriginalSequenceAfterOperation);
    assertNotNull(aCurrentSequenceAfterOperation);
    assertTrue(anOriginalSequenceAfterOperation == aCurrentSequenceAfterLoggingFirstOnParam);
}
Also used : SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary) SDOSequence(org.eclipse.persistence.sdo.SDOSequence) Sequence(commonj.sdo.Sequence) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 4 with Sequence

use of commonj.sdo.Sequence in project eclipselink by eclipse-ee4j.

the class ChangeSummaryDeleteOpenContentTestCases method verifyAfterLoad.

@Override
protected void verifyAfterLoad(XMLDocument document) {
    super.verifyAfterLoad(document);
    ChangeSummary teamCS = document.getRootObject().getChangeSummary();
    assertNotNull(teamCS);
    DataObject manager = document.getRootObject().getDataObject("manager");
    assertNotNull(manager);
    ChangeSummary managerCS = manager.getChangeSummary();
    assertEquals(teamCS, managerCS);
    assertTrue(teamCS.isLogging());
    assertTrue(teamCS.isLogging());
    List yards = manager.getList("theYard");
    assertTrue(yards.isEmpty());
    assertEquals(1, ((SDOChangeSummary) managerCS).getModified().size());
    assertEquals(4, ((SDOChangeSummary) managerCS).getDeleted().size());
    DataObject deletedYard = (DataObject) ((SDOChangeSummary) managerCS).getDeleted().get(0);
    // TODO: what should be deletedYard.get"width" vs. get oldSetting "width
    assertEquals("theSqFootage", deletedYard.get("squarefootage"));
    assertEquals("thelength", deletedYard.get("length"));
    assertEquals("theWidth", deletedYard.get("width"));
    // theYardDefined
    DataObject deletedYardDefined = (DataObject) ((SDOChangeSummary) managerCS).getDeleted().get(1);
    ChangeSummary.Setting setting = managerCS.getOldValue(deletedYardDefined, deletedYardDefined.getInstanceProperty("squarefootage"));
    assertNotNull(setting);
    assertEquals("theSqFootageDefined", setting.getValue());
    setting = managerCS.getOldValue(deletedYardDefined, deletedYardDefined.getInstanceProperty("length"));
    assertNotNull(setting);
    assertEquals("thelengthDefined", setting.getValue());
    setting = managerCS.getOldValue(deletedYardDefined, deletedYardDefined.getInstanceProperty("width"));
    assertNotNull(setting);
    assertEquals("theWidthDefined", setting.getValue());
    // theYardUndefined
    DataObject deletedYardUndefined = (DataObject) ((SDOChangeSummary) managerCS).getDeleted().get(2);
    setting = managerCS.getOldValue(deletedYardUndefined, deletedYardUndefined.getInstanceProperty("squarefootage"));
    assertNotNull(setting);
    assertEquals(1, ((List) setting.getValue()).size());
    assertEquals("theSqFootageUndefined", ((List) setting.getValue()).get(0));
    setting = managerCS.getOldValue(deletedYardUndefined, deletedYardUndefined.getInstanceProperty("length"));
    assertNotNull(setting);
    assertEquals(1, ((List) setting.getValue()).size());
    assertEquals("thelengthUndefined", ((List) setting.getValue()).get(0));
    setting = managerCS.getOldValue(deletedYardUndefined, deletedYardUndefined.getInstanceProperty("width"));
    assertNotNull(setting);
    assertEquals(1, ((List) setting.getValue()).size());
    assertEquals("theWidthUndefined", ((List) setting.getValue()).get(0));
    // 
    // address
    DataObject address = (DataObject) ((SDOChangeSummary) managerCS).getDeleted().get(3);
    setting = managerCS.getOldValue(address, address.getInstanceProperty("street"));
    assertNotNull(setting);
    assertEquals("theStreet", setting.getValue());
    assertTrue(setting.isSet());
    ChangeSummary.Setting oldNameSetting = managerCS.getOldValue(manager, manager.getInstanceProperty("name"));
    List oldValues = managerCS.getOldValues(manager);
    Sequence oldSequence = managerCS.getOldSequence(manager);
    assertEquals(4, oldValues.size());
    assertEquals(5, oldSequence.size());
    assertEquals("Jane Doe", oldSequence.getValue(0));
    assertEquals("name", oldSequence.getProperty(0).getName());
    DataObject yardValue = (DataObject) oldSequence.getValue(1);
    assertNotNull(yardValue);
    assertEquals("Yard", yardValue.getType().getName());
    assertEquals("theYard", oldSequence.getProperty(1).getName());
    DataObject yardDefinedValue = (DataObject) oldSequence.getValue(2);
    assertEquals("Yard", yardDefinedValue.getType().getName());
    assertNotNull(yardDefinedValue);
    // assertEquals("theYardDefined" ,oldSequence.getProperty(2).getName());
    SDODataObject yardUnDefinedValue = (SDODataObject) oldSequence.getValue(3);
    assertNotNull(yardUnDefinedValue);
    assertTrue(yardUnDefinedValue.getType().isOpenSequencedType());
    assertEquals("theYardUndefined", oldSequence.getProperty(3).getName());
    DataObject addressValue = (DataObject) oldSequence.getValue(4);
    assertEquals("Address", addressValue.getType().getName());
    assertEquals("address", oldSequence.getProperty(4).getName());
// olsequence is size 2 with name + address
// DataObject yard = manager.getDataObject("theYard");
/* List yards = manager.getList("theYard");
        assertEquals(1, yards.size());
        DataObject yard = (DataObject)yards.get(0);
        assertNotNull(yard);
        assertEquals("theSqFootage", yard.get("squarefootage"));
        assertEquals("thelength", yard.get("length"));
        assertEquals("theWidth", yard.get("width"));
        */
}
Also used : DataObject(commonj.sdo.DataObject) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary) List(java.util.List) Sequence(commonj.sdo.Sequence) SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary) ChangeSummary(commonj.sdo.ChangeSummary) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 5 with Sequence

use of commonj.sdo.Sequence in project eclipselink by eclipse-ee4j.

the class SDOSequenceTestXSD method testEqualDeepTrueAfterIsSequencedSetToFalseAfterDefineViaNonSpecMethod.

/*
//  variant test cases that should cause equality failure
    testSequenceOnCopyHasDifferentOrder
    testSequenceOnCopyIsEmpty
    testSequenceOnCopyIsLarger
    testSequenceOnCopyIsSmaller
    testSequenceOnCopyHasDifferentPropertyAtIndex
    testSequenceOnCopyHasDifferentValueAtIndex
    testSequenceOnOriginalHasDifferentOrder
    testSequenceOnOriginalIsEmpty
    testSequenceOnOriginalIsLarger
    testSequenceOnOriginalIsSmaller
    testSequenceOnOriginalHasDifferentPropertyAtIndex
    testSequenceOnOriginalHasDifferentValueAtIndex
*/
public void testEqualDeepTrueAfterIsSequencedSetToFalseAfterDefineViaNonSpecMethod() {
    defineAndLoadRoot(false, false);
    Sequence aSequence = getSequence(root, PO_SEQUENCE_PATH, PO_SEQUENCE_SIZE);
    DataObject po = (DataObject) root.get(PO_SEQUENCE_PATH);
    // copy po
    DataObject rootCopy = copyHelper.copy(root);
    // check sequence was copied
    Sequence aSequenceCopy = getSequence(rootCopy, PO_SEQUENCE_PATH, PO_SEQUENCE_SIZE);
    assertNotNull(aSequenceCopy);
    // compareSequences((SDOSequence)aSequence, (SDOSequence)aSequenceCopy, PO_SEQUENCE_SIZE, true);
    // test equalityHelper
    DataObject poCopy = (DataObject) rootCopy.get(PO_SEQUENCE_PATH);
    boolean bEqual = equalityHelper.equal(po, poCopy);
    assertTrue(bEqual);
    // modify copy sequence state - non public method - both po and poCopy will have their state changed because they share an SDOType
    assertTrue(po.getType().isSequenced());
    assertTrue(poCopy.getType().isSequenced());
    // WARNING: Users should not be doing this - however it is supported
    ((SDOType) poCopy.getType()).setSequenced(false);
    assertFalse(po.getType().isSequenced());
    assertFalse(poCopy.getType().isSequenced());
    bEqual = equalityHelper.equal(po, poCopy);
    // sequences will not be compared
    assertTrue(bEqual);
}
Also used : SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) SDOType(org.eclipse.persistence.sdo.SDOType) Sequence(commonj.sdo.Sequence) SDOSequence(org.eclipse.persistence.sdo.SDOSequence)

Aggregations

Sequence (commonj.sdo.Sequence)32 SDOSequence (org.eclipse.persistence.sdo.SDOSequence)29 DataObject (commonj.sdo.DataObject)18 SDODataObject (org.eclipse.persistence.sdo.SDODataObject)12 List (java.util.List)10 ArrayList (java.util.ArrayList)8 ChangeSummary (commonj.sdo.ChangeSummary)7 SDOChangeSummary (org.eclipse.persistence.sdo.SDOChangeSummary)6 SDOType (org.eclipse.persistence.sdo.SDOType)4 Property (commonj.sdo.Property)3 DataHelper (commonj.sdo.helper.DataHelper)1 TypeHelper (commonj.sdo.helper.TypeHelper)1 Iterator (java.util.Iterator)1 SDOException (org.eclipse.persistence.exceptions.SDOException)1 XMLConversionManager (org.eclipse.persistence.internal.oxm.XMLConversionManager)1 XMLRoot (org.eclipse.persistence.oxm.XMLRoot)1 XMLUnmarshaller (org.eclipse.persistence.oxm.XMLUnmarshaller)1 SequencedObject (org.eclipse.persistence.oxm.sequenced.SequencedObject)1 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)1 ListWrapper (org.eclipse.persistence.sdo.helper.ListWrapper)1