Search in sources :

Example 96 with SDOSequence

use of org.eclipse.persistence.sdo.SDOSequence in project eclipselink by eclipse-ee4j.

the class SDOSequenceTestCS method testMoveSameIndexOutOfBoundsLow.

public void testMoveSameIndexOutOfBoundsLow() {
    defineAndLoadRoot(false, false);
    DataObject po = (DataObject) root.get(PO_SEQUENCE_PATH);
    assertNotNull(po);
    assertTrue(po.getType().isSequenced());
    SDOSequence aSequence = (SDOSequence) po.getSequence();
    // move 2 sequenced objects
    Property beforeMoveProp1 = aSequence.getProperty(1);
    assertNotNull(beforeMoveProp1);
    aSequence.move(-1, -1);
    Property afterMoveProp1 = aSequence.getProperty(1);
    // verify the move did not take place
    assertTrue(beforeMoveProp1 == afterMoveProp1);
}
Also used : SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) Property(commonj.sdo.Property) SDOSequence(org.eclipse.persistence.sdo.SDOSequence)

Example 97 with SDOSequence

use of org.eclipse.persistence.sdo.SDOSequence in project eclipselink by eclipse-ee4j.

the class SDOSequenceTest method testSequenceReturnFrom_SDODataObject_getSequence.

/*
    private SDOSequence getSequence() {
        // get sequence po
        SDODataObject po = (SDODataObject)root.get(PO_SEQUENCE_PATH);
        assertNotNull(po);
        assertTrue(po.getType().isSequenced());
        SDOSequence aSequence = (SDOSequence)po.getSequence();

        // create our own setting until Helpers are ready
        aSequence = new SDOSequence(po);
        for(Iterator i = po.getInstanceProperties().iterator(); i.hasNext();) {
            Property aProperty = (Property)i.next();
            aSequence.add(aProperty, po.get(aProperty));
        }
        assertNotNull(aSequence);
        assertEquals(5, aSequence.size());
        return aSequence;
    }
*/
/**
 * SDOSequence specific unit tests
 */
/**
 * Returns the <code>Sequence</code> for this DataObject.
 * When getType().isSequencedType() == true,
 * the Sequence of a DataObject corresponds to the
 * XML elements representing the values of its Properties.
 * Updates through DataObject and the Lists or Sequences returned
 * from DataObject operate on the same data.
 * When getType().isSequencedType() == false, null is returned.
 */
public void testSequenceReturnFrom_SDODataObject_getSequence() {
    getRootViaDefineViaDataObjectandLoadViaDataFactory();
    // get sequence po
    SDODataObject po = (SDODataObject) root.get(PO_SEQUENCE_PATH);
    assertNotNull(po);
    assertTrue(po.getType().isSequenced());
    SDOSequence aSequence = po.getSequence();
    assertNotNull(aSequence);
// assertEquals(4, aSequence.size());
}
Also used : SDOSequence(org.eclipse.persistence.sdo.SDOSequence) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 98 with SDOSequence

use of org.eclipse.persistence.sdo.SDOSequence in project eclipselink by eclipse-ee4j.

the class SDOCopyHelper method copyShallow.

/**
 * Create a shallow copy of the DataObject dataObject:
 *   Creates a new DataObject copiedDataObject with the same values
 *     as the source dataObject for each property where
 *       property.getType().isDataType() is true.
 *   The value of such a Property property in copiedDataObject is:
 *       dataObject.get(property) for single-valued Properties
 *       (copiedDataObject.get(property) equals() dataObject.get(property)), or
 *       a List where each member is equal to the member at the
 *       same index in dataObject for multi-valued Properties
 *        copiedDataObject.getList(property).get(i) equals() dataObject.getList(property).get(i)
 *   The copied Object is unset for each Property where
 *       property.getType().isDataType() is false
 *       since they are not copied.
 *   Read-only properties are copied.
 *   A copied object shares metadata with the source object
 *     sourceDO.getType() == copiedDO.getType()
 *   If a ChangeSummary is part of the source DataObject
 *     the copy has a new, empty ChangeSummary.
 *     Logging state is the same as the source ChangeSummary.
 *
 * @param dataObject to be copied
 * @return copy of dataObject
 */
@Override
public DataObject copyShallow(DataObject dataObject) {
    if (null == dataObject) {
        return null;
    }
    SDODataObject copy = (SDODataObject) getHelperContext().getDataFactory().create(dataObject.getType().getURI(), dataObject.getType().getName());
    List ocListOriginal = ((SDODataObject) dataObject)._getOpenContentProperties();
    for (Iterator anOCIterator = ocListOriginal.iterator(); anOCIterator.hasNext(); ) {
        copy.addOpenContentProperty((Property) anOCIterator.next());
    }
    List ocAttrsListOriginal = ((SDODataObject) dataObject)._getOpenContentPropertiesAttributes();
    for (Iterator anOCAttrIterator = ocAttrsListOriginal.iterator(); anOCAttrIterator.hasNext(); ) {
        copy.addOpenContentProperty((Property) anOCAttrIterator.next());
    }
    // start iterating all copy's properties
    List allProperties = copy.getInstanceProperties();
    Iterator iterProperties = allProperties.iterator();
    while (iterProperties.hasNext()) {
        SDOProperty eachProperty = (SDOProperty) iterProperties.next();
        if (dataObject.isSet(eachProperty)) {
            Object o = getValue((SDODataObject) dataObject, eachProperty, null);
            if (eachProperty.getType().isDataType()) {
                if (!eachProperty.getType().isChangeSummaryType()) {
                    // we defer sequence updates at this point
                    // make copy if current property is datatype
                    copy.setInternal(eachProperty, o, false);
                }
            }
        }
    }
    if (dataObject.getType().isSequenced()) {
        List<Setting> settings = ((SDOSequence) dataObject.getSequence()).getSettings();
        for (int index = 0, size = dataObject.getSequence().size(); index < size; index++) {
            Setting nextSetting = settings.get(index);
            Property prop = dataObject.getSequence().getProperty(index);
            if (prop == null || prop.getType().isDataType()) {
                Setting copySetting = nextSetting.copy(copy);
                copy.getSequence().getSettings().add(copySetting);
                copy.getSequence().addValueToSettings(copySetting);
            }
        }
    }
    if ((copy != null) && (copy.getChangeSummary() != null) && (copy.getType().getChangeSummaryProperty() != null)) {
        if (((SDODataObject) dataObject).getChangeSummary().isLogging()) {
            copy.getChangeSummary().setLogging(true);
        }
    }
    return copy;
}
Also used : Setting(org.eclipse.persistence.oxm.sequenced.Setting) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) Property(commonj.sdo.Property) SDOSequence(org.eclipse.persistence.sdo.SDOSequence) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 99 with SDOSequence

use of org.eclipse.persistence.sdo.SDOSequence in project eclipselink by eclipse-ee4j.

the class ChangeSummaryGetOldSequenceTestCases method testGetOldSequenceDeletedItem.

public void testGetOldSequenceDeletedItem() {
    cs.beginLogging();
    DataObject lineItem1 = (DataObject) itemsObject.getList("item").get(0);
    DataObject lineItem2 = (DataObject) itemsObject.getList("item").get(1);
    Sequence currentSeq = itemsObject.getSequence();
    assertEquals(2, currentSeq.size());
    cs.beginLogging();
    lineItem1.delete();
    assertEquals(1, currentSeq.size());
    Sequence oldSeq = cs.getOldSequence(itemsObject);
    assertNotNull(oldSeq);
    assertEquals(2, ((SDOSequence) oldSeq).getSettings().size());
    DataObject oldLineItem1 = (DataObject) oldSeq.getValue(0);
    assertEquals("Lawnmower", oldLineItem1.get("productName"));
    DataObject oldLineItem2 = (DataObject) oldSeq.getValue(1);
    assertEquals("Baby Monitor", oldLineItem2.get("productName"));
    // should be a deep copy not the same object
    assertNotSame(lineItem1, oldLineItem1);
    assertNotSame(lineItem2, oldLineItem2);
    assertFalse(lineItem1.equals(oldLineItem1));
    assertFalse(lineItem2.equals(oldLineItem2));
}
Also used : DataObject(commonj.sdo.DataObject) Sequence(commonj.sdo.Sequence) SDOSequence(org.eclipse.persistence.sdo.SDOSequence) SDOSequence(org.eclipse.persistence.sdo.SDOSequence)

Example 100 with SDOSequence

use of org.eclipse.persistence.sdo.SDOSequence in project eclipselink by eclipse-ee4j.

the class ChangeSummaryGetOldSequenceTestCases method testGetOldSequenceDeletedAddress.

public void testGetOldSequenceDeletedAddress() {
    cs.beginLogging();
    Sequence currentSeq = address1Object.getSequence();
    assertEquals(4, currentSeq.size());
    address1Object.delete();
    assertEquals(0, currentSeq.size());
    Sequence oldSeq = cs.getOldSequence(address1Object);
    assertNotNull(oldSeq);
    assertEquals(4, ((SDOSequence) oldSeq).getSettings().size());
}
Also used : Sequence(commonj.sdo.Sequence) SDOSequence(org.eclipse.persistence.sdo.SDOSequence) SDOSequence(org.eclipse.persistence.sdo.SDOSequence)

Aggregations

SDOSequence (org.eclipse.persistence.sdo.SDOSequence)211 SDODataObject (org.eclipse.persistence.sdo.SDODataObject)178 DataObject (commonj.sdo.DataObject)176 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)93 Property (commonj.sdo.Property)75 ListWrapper (org.eclipse.persistence.sdo.helper.ListWrapper)73 ArrayList (java.util.ArrayList)46 SDOException (org.eclipse.persistence.exceptions.SDOException)37 Sequence (commonj.sdo.Sequence)15 List (java.util.List)10 SDOChangeSummary (org.eclipse.persistence.sdo.SDOChangeSummary)8 Iterator (java.util.Iterator)7 ChangeSummary (commonj.sdo.ChangeSummary)6 SDOType (org.eclipse.persistence.sdo.SDOType)4 Map (java.util.Map)2 TypeHelper (commonj.sdo.helper.TypeHelper)1 HashMap (java.util.HashMap)1 XMLConversionManager (org.eclipse.persistence.internal.oxm.XMLConversionManager)1 XMLRoot (org.eclipse.persistence.oxm.XMLRoot)1 XMLUnmarshaller (org.eclipse.persistence.oxm.XMLUnmarshaller)1