use of org.eclipse.persistence.sdo.SDOChangeSummary in project eclipselink by eclipse-ee4j.
the class JAXBValueStore method copy.
@Override
public ValueStore copy() {
AbstractSession session = ((JAXBContext) jaxbHelperContext.getJAXBContext()).getXMLContext().getSession(entity);
Object originalEntity = entity;
entity = descriptor.getInstantiationPolicy().buildNewInstance();
for (SDOProperty sdoProperty : (List<SDOProperty>) dataObject.getType().getProperties()) {
if (!sdoProperty.getType().isChangeSummaryType()) {
Mapping mapping = getJAXBMappingForProperty(sdoProperty);
CoreAttributeAccessor attributeAccessor = mapping.getAttributeAccessor();
Object attributeValue = attributeAccessor.getAttributeValueFromObject(originalEntity);
if (mapping.isCollectionMapping()) {
Object containerCopy = null;
SDOChangeSummary sdoChangeSummary = dataObject.getChangeSummary();
if (null != sdoChangeSummary) {
List list = listWrappers.get(sdoProperty);
containerCopy = sdoChangeSummary.getOriginalElements().get(list);
}
if (null == containerCopy) {
CoreContainerPolicy containerPolicy = mapping.getContainerPolicy();
containerCopy = containerPolicy.containerInstance();
if (null != attributeValue) {
Object attributeValueIterator = containerPolicy.iteratorFor(attributeValue);
while (containerPolicy.hasNext(attributeValueIterator)) {
containerPolicy.addInto(containerPolicy.nextEntry(attributeValueIterator), containerCopy, session);
}
}
}
attributeAccessor.setAttributeValueInObject(entity, containerCopy);
} else {
attributeAccessor.setAttributeValueInObject(entity, attributeValue);
}
}
}
return new JAXBValueStore(jaxbHelperContext, originalEntity, descriptor, dataObject, listWrappers);
}
use of org.eclipse.persistence.sdo.SDOChangeSummary 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"));
*/
}
use of org.eclipse.persistence.sdo.SDOChangeSummary in project eclipselink by eclipse-ee4j.
the class ChangeSummaryChildSimpleDeleteTestCases method verifyAfterLoad.
@Override
protected void verifyAfterLoad(XMLDocument document) {
super.verifyAfterLoad(document);
ChangeSummary teamCS = document.getRootObject().getChangeSummary();
assertNull(teamCS);
DataObject manager = document.getRootObject().getDataObject("manager");
assertNotNull(manager);
ChangeSummary managerCS = manager.getChangeSummary();
assertNotNull(managerCS);
assertTrue(managerCS.isLogging());
assertTrue(managerCS.isLogging());
int deletedSize = ((SDOChangeSummary) managerCS).getDeleted().size();
assertEquals(3, deletedSize);
assertTrue(managerCS.isModified(manager));
Iterator iter = ((SDOChangeSummary) managerCS).getDeleted().iterator();
while (iter.hasNext()) {
SDODataObject nextDeleted = (SDODataObject) iter.next();
assertEquals(nextDeleted.getInstanceProperties().size(), managerCS.getOldValues(nextDeleted).size());
}
assertEquals(2, managerCS.getOldValues(manager).size());
List teamOldValues = managerCS.getOldValues(manager);
// assertEquals(2, teamOldValues.size());
// assertTrue(teamOldValues.size() <= 4);
ChangeSummary.Setting idSetting = managerCS.getOldValue(manager, manager.getInstanceProperty("id"));
assertNull(idSetting);
// TODO: uncomment when Node null policy works
ChangeSummary.Setting nameSetting = managerCS.getOldValue(manager, manager.getInstanceProperty("name"));
assertNull(nameSetting);
ChangeSummary.Setting addressSetting = managerCS.getOldValue(manager, manager.getInstanceProperty("address"));
assertNotNull(addressSetting);
DataObject addressDO = (DataObject) addressSetting.getValue();
assertNotNull(addressDO);
Object streetValue = addressDO.get("street");
assertEquals("theStreet", streetValue);
DataObject originalAddress = (DataObject) ((SDOChangeSummary) managerCS).getReverseDeletedMap().get(addressDO);
DataObject oldContainer = managerCS.getOldContainer(originalAddress);
assertEquals(oldContainer, manager);
Property oldContainmentProp = managerCS.getOldContainmentProperty(originalAddress);
assertNotNull(oldContainmentProp);
assertEquals(oldContainmentProp, manager.getInstanceProperty("address"));
// TODO: yard stuff
ChangeSummary.Setting yardOldSetting = managerCS.getOldValue(originalAddress, addressDO.getInstanceProperty("yard"));
DataObject yardDO = (DataObject) yardOldSetting.getValue();
assertNotNull(yardDO);
DataObject originalYard = (DataObject) ((SDOChangeSummary) managerCS).getReverseDeletedMap().get(yardDO);
DataObject yardOldContainer = managerCS.getOldContainer(originalYard);
assertEquals(yardOldContainer, originalAddress);
assertNotNull(yardOldContainer);
Property yardOldContainmentProp = managerCS.getOldContainmentProperty(originalYard);
assertNotNull(yardOldContainmentProp);
assertEquals(yardOldContainmentProp, addressDO.getInstanceProperty("yard"));
managerCS.getOldValues(yardDO);
ChangeSummary.Setting phoneSetting = managerCS.getOldValue(manager, manager.getInstanceProperty("phone"));
assertNotNull(phoneSetting);
assertNotNull(phoneSetting.getValue());
assertTrue(phoneSetting.getValue() instanceof List);
assertEquals(4, ((List) phoneSetting.getValue()).size());
/*teamCS.endLogging();
teamCS.beginLogging();
manager.set("name","Suzanne");
manager.set("id","123");
*/
// assertTrue(teamCS.isCreated(manager));
// assertEquals(0, teamCS.getOldValues(manager).size());
}
use of org.eclipse.persistence.sdo.SDOChangeSummary in project eclipselink by eclipse-ee4j.
the class ChangeSummaryXSDwSeqTestCases method testResetOfUnsetOpenContentPropertyClearsUnsetOCPropMap.
// Exercise cs.removeUnsetOCProperty()
public void testResetOfUnsetOpenContentPropertyClearsUnsetOCPropMap() {
List preOrderList = null;
int numberOfDataObjectsInSubTree = 0;
// unset isMany=true (to fill unsetPropsMap and createdList later when we (re)set it back)
SDODataObject shipTo = (SDODataObject) rootObject.get(PROPERTY_NAME_PO_SHIPTO);
// use index 2 to avoid a swap later
SDODataObject phone2 = (SDODataObject) rootObject.get(PROPERTY_NAME_PO_SHIPTO_PHONE2);
shipTo.unset("phone[2]");
// save size of tree before CS was turned on
preOrderList = preOrderTraversalDataObjectList((SDODataObject) rootObject, false);
numberOfDataObjectsInSubTree = preOrderList.size();
int numberOfNodesInRootBeforeCSon = 14;
assertEquals(numberOfNodesInRootBeforeCSon, numberOfDataObjectsInSubTree);
// set a simple-single Open Content property
SDOProperty openRootProperty = new SDOProperty(aHelperContext);
openRootProperty.setName(OC_PROP1SimpleSingleNAME);
openRootProperty.setType(SDOConstants.SDO_STRING);
// aRootTypeOC.setOpen(true);
((SDOType) rootObject.getType()).setOpen(true);
rootObject.set(openRootProperty, OC_PROP1SimpleSingleVALUE);
// set an Open Content property and delete it
SDOProperty openRootPropertyToBeDeleted = new SDOProperty(aHelperContext);
openRootPropertyToBeDeleted.setName(OC_PROP2SimpleSingleNAME);
openRootPropertyToBeDeleted.setType(SDOConstants.SDO_STRING);
// aRootTypeOC.setOpen(true);
rootObject.set(openRootPropertyToBeDeleted, OC_PROP2SimpleSingleVALUE);
// turn on logging
cs.beginLogging();
assertTrue(cs.isLogging());
// delete an Open Content property
rootObject.unset(openRootPropertyToBeDeleted);
assertFalse(((SDOChangeSummary) cs).getUnsetOCPropertiesMap().isEmpty());
// reset it
rootObject.set(openRootPropertyToBeDeleted, OC_PROP2SimpleSingleVALUE);
assertTrue(((SDOChangeSummary) cs).getUnsetOCPropertiesMap().isEmpty());
}
use of org.eclipse.persistence.sdo.SDOChangeSummary in project eclipselink by eclipse-ee4j.
the class ChangeSummaryXSDwSeqTestCases method testRemoveByObjectItem2Price2.
public void testRemoveByObjectItem2Price2() {
DataObject item2DO = rootObject.getDataObject("items/item[2]");
DataObject item2ProductDO = item2DO.getDataObject("product");
DataObject item2ProductPrice1DO = item2ProductDO.getDataObject("price[1]");
DataObject item2ProductPrice2DO = item2ProductDO.getDataObject("price[2]");
cs.beginLogging();
int startListSize = item2ProductDO.getList("price").size();
assertEquals(2, startListSize);
item2ProductDO.getList("price").remove(item2ProductPrice2DO);
int endListSize = item2ProductDO.getList("price").size();
assertEquals(1, endListSize);
assertModified(item2ProductDO, cs);
assertUnchanged(item2ProductPrice1DO, cs);
// TODO: failure starts here
assertDetached(item2ProductPrice2DO, cs);
assertEquals(2, cs.getChangedDataObjects().size());
assertEquals(14, ((SDOChangeSummary) cs).getOldContainer().size());
assertEquals(14, ((SDOChangeSummary) cs).getOldContainmentProperty().size());
List aSettingList = cs.getOldValues(item2ProductDO);
assertTrue(aSettingList.size() > 0);
ChangeSummary.Setting containmentSetting = (ChangeSummary.Setting) aSettingList.get(0);
assertEquals("price", containmentSetting.getProperty().getName());
assertTrue(containmentSetting.getValue() instanceof List);
assertEquals(2, ((List) containmentSetting.getValue()).size());
assertEquals(true, containmentSetting.isSet());
// writeXML(rootObject);
}
Aggregations