use of org.eclipse.persistence.internal.dynamic.DynamicEntityImpl in project eclipselink by eclipse-ee4j.
the class DynamicJAXBFromSessionsXMLTestCases method compareObjects.
protected void compareObjects(Object controlObject, Object testObject) throws Exception {
if (objectsAlreadyCheckedForEquality.contains(testObject)) {
// To handle cyclic relationships, only check each pair of DynamicEntities once
return;
}
if (controlObject == null && testObject == null) {
// Nothing to check
return;
}
if (controlObject == null && testObject != null) {
fail("testObject was [" + testObject + "] but controlObject was [" + controlObject + "].");
}
if (controlObject != null && testObject == null) {
fail("testObject was [" + testObject + "] but controlObject was [" + controlObject + "].");
}
if (testObject instanceof Element && controlObject instanceof Element) {
Element testElement = (Element) testObject;
Element controlElement = (Element) controlObject;
boolean equal = true;
try {
if (testElement.getNodeType() == Node.ATTRIBUTE_NODE && controlElement.getNodeType() == Node.ATTRIBUTE_NODE) {
Attr att1 = (Attr) testElement;
Attr att2 = (Attr) controlElement;
equal = equal && att1.getNodeValue().equals(att2.getNodeValue());
} else if (testElement.getNodeType() == Node.TEXT_NODE && controlElement.getNodeType() == Node.TEXT_NODE) {
Text text1 = (Text) testElement;
Text text2 = (Text) controlElement;
equal = equal && text1.getNodeValue().equals(text2.getNodeValue());
} else if (testElement.getNodeType() == Node.ELEMENT_NODE && controlElement.getNodeType() == Node.ELEMENT_NODE) {
Element elem1 = testElement;
Element elem2 = controlElement;
equal = equal && elem1.getNodeName().equals(elem2.getNodeName());
equal = equal && (elem1.getChildNodes().getLength() == elem2.getChildNodes().getLength());
compareObjects(elem1.getFirstChild().getNodeValue(), elem2.getFirstChild().getNodeValue());
}
if (!equal) {
fail("testElement was [" + testElement + "] but controlElement was [" + controlElement + "].");
}
} catch (Exception e) {
fail("Element comparison failed: " + e.getLocalizedMessage());
}
return;
}
if (testObject instanceof List && controlObject instanceof List) {
if ((((List) testObject).size()) != (((List) controlObject).size())) {
fail("testObject had [" + ((List) testObject).size() + "] elements but controlObject had [" + ((List) controlObject).size() + "].");
}
for (int i = 0; i < ((List) controlObject).size(); i++) {
compareObjects(((List) controlObject).get(i), ((List) testObject).get(i));
}
// We've now checked all the elements so return
return;
}
if (testObject.getClass().isArray() && controlObject.getClass().isArray()) {
if (!Helper.comparePotentialArrays(testObject, controlObject)) {
fail("controlObject [" + controlObject + "] is not equal to testObject [" + testObject + "].");
}
// We've now checked all the elements so return
return;
}
if (controlObject instanceof DynamicEntityImpl && testObject instanceof DynamicEntityImpl) {
DynamicEntityImpl dynamicControl = (DynamicEntityImpl) controlObject;
DynamicEntityImpl dynamicTest = (DynamicEntityImpl) testObject;
String controlClass = dynamicControl.getType().getClassName();
String testClass = dynamicTest.getType().getClassName();
if (!controlClass.equals(testClass)) {
fail("testObject [" + testClass + "] and controlObject [" + controlClass + "] are not the same class.");
}
objectsAlreadyCheckedForEquality.add(testObject);
if (dynamicControl.getType().getNumberOfProperties() != dynamicTest.getType().getNumberOfProperties()) {
fail("testObject and controlObject did not have the same number of properties.");
}
List<String> propNames = dynamicControl.getType().getPropertiesNames();
Iterator<String> it = propNames.iterator();
while (it.hasNext()) {
String propName = it.next();
Object controlValue = dynamicControl.get(propName);
Object testValue = dynamicTest.get(propName);
compareObjects(controlValue, testValue);
}
} else {
if (!testObject.equals(controlObject)) {
fail("testObject was [" + testObject + "] but controlObject was [" + controlObject + "].");
}
}
}
use of org.eclipse.persistence.internal.dynamic.DynamicEntityImpl in project eclipselink by eclipse-ee4j.
the class StreamingOutputMarshaller method createMarshaller.
public static Marshaller createMarshaller(PersistenceContext context, MediaType mediaType) throws JAXBException {
Marshaller marshaller = context.getJAXBContext().createMarshaller();
marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, mediaType.toString());
marshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false);
marshaller.setAdapter(new LinkAdapter(context.getBaseURI().toString(), context));
marshaller.setListener(new Marshaller.Listener() {
@Override
public void beforeMarshal(Object source) {
if (source instanceof DynamicEntity) {
DynamicEntityImpl sourceImpl = (DynamicEntityImpl) source;
PropertyChangeListener listener = sourceImpl._persistence_getPropertyChangeListener();
sourceImpl._persistence_setPropertyChangeListener(null);
((DynamicEntity) source).set("self", source);
sourceImpl._persistence_setPropertyChangeListener(listener);
}
}
});
return marshaller;
}
use of org.eclipse.persistence.internal.dynamic.DynamicEntityImpl in project eclipselink by eclipse-ee4j.
the class SimpleTypes_MultiTable method verifyChangeTracking.
@Test
public void verifyChangeTracking() {
persistSimpleA();
DynamicType simpleTypeA = dynamicHelper.getType("SimpleA");
Assert.assertNotNull(simpleTypeA);
UnitOfWork uow = session.acquireUnitOfWork();
ReadObjectQuery findQuery = dynamicHelper.newReadObjectQuery("SimpleA");
findQuery.setSelectionCriteria(findQuery.getExpressionBuilder().get("id").equal(1));
DynamicEntityImpl a = (DynamicEntityImpl) uow.executeQuery(findQuery);
assertNotNull(a);
assertNotNull(a._persistence_getPropertyChangeListener());
uow.release();
session.release();
}
use of org.eclipse.persistence.internal.dynamic.DynamicEntityImpl in project eclipselink by eclipse-ee4j.
the class SimpleTypes_AggregateObject method verifyChangTracking.
@Test
public void verifyChangTracking() {
persistSimpleA();
DynamicType simpleTypeA = dynamicHelper.getType("SimpleA");
Assert.assertNotNull(simpleTypeA);
UnitOfWork uow = session.acquireUnitOfWork();
ReadObjectQuery roq = dynamicHelper.newReadObjectQuery("SimpleA");
roq.setSelectionCriteria(roq.getExpressionBuilder().get("id").equal(1));
DynamicEntityImpl sharedA = (DynamicEntityImpl) session.executeQuery(roq);
assertNotNull(sharedA);
assertNull(sharedA._persistence_getPropertyChangeListener());
DynamicEntityImpl a = (DynamicEntityImpl) uow.executeQuery(roq);
assertNotNull(a);
assertNotNull(a._persistence_getPropertyChangeListener());
DynamicEntityImpl c = a.<DynamicEntityImpl>get("c");
assertNotNull(c);
assertNotNull(c._persistence_getPropertyChangeListener());
assertTrue(c._persistence_getPropertyChangeListener() instanceof AggregateAttributeChangeListener);
uow.release();
}
use of org.eclipse.persistence.internal.dynamic.DynamicEntityImpl in project eclipselink by eclipse-ee4j.
the class SimpleTypes_MultiTable method verifyChangeTracking.
@Test
public void verifyChangeTracking() {
persistSimpleA();
DynamicType simpleTypeA = helper.getType("SimpleA");
assertNotNull(simpleTypeA);
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
DynamicEntityImpl a = (DynamicEntityImpl) em.find(simpleTypeA.getJavaClass(), 1);
assertNotNull(a);
assertNotNull(a._persistence_getPropertyChangeListener());
em.getTransaction().rollback();
em.close();
}
Aggregations