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();
DynamicTypeImpl simpleTypeA = (DynamicTypeImpl) 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());
DynamicEntityImpl c = a.<DynamicEntityImpl>get("c");
assertNotNull(c);
assertNotNull(c._persistence_getPropertyChangeListener());
assertTrue(c._persistence_getPropertyChangeListener() instanceof AggregateAttributeChangeListener);
em.getTransaction().rollback();
em.close();
}
use of org.eclipse.persistence.internal.dynamic.DynamicEntityImpl in project eclipselink by eclipse-ee4j.
the class DynamicTestCases method compareDynamicObjects.
private void compareDynamicObjects(Object controlObject, Object testObject) throws Exception {
if (objectsAlreadyCheckedForEquality.contains(testObject)) {
// To handle cyclic relationships, only check each object once.
return;
}
if (!(controlObject instanceof DynamicEntityImpl)) {
fail("controlObject [" + controlObject + "] was not an instance of DynamicEntityImpl.");
}
if (!(testObject instanceof DynamicEntityImpl)) {
fail("testObject [" + testObject + "] was not an instance of DynamicEntityImpl.");
}
DynamicEntityImpl dynamicControl = (DynamicEntityImpl) controlObject;
DynamicEntityImpl dynamicTest = (DynamicEntityImpl) testObject;
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 = getValue(dynamicControl, propName);
Object testValue = getValue(dynamicTest, propName);
if ((testValue instanceof DynamicEntityImpl) && (controlValue instanceof DynamicEntityImpl)) {
compareDynamicObjects(controlValue, testValue);
} else if ((testValue instanceof List) && (controlValue instanceof List)) {
if ((((List) testValue).size()) != (((List) controlValue).size())) {
fail(dynamicControl.getType().getName() + " " + propName + ": testValue was " + testValue + " but controlValue was " + controlValue);
}
for (int i = 0; i < ((List) controlValue).size(); i++) {
compareDynamicObjects(((List) controlValue).get(i), ((List) testValue).get(i));
}
} else {
if (testValue == null && controlValue == null) {
continue;
}
if (testValue == null && controlValue != null) {
fail(dynamicControl.getType().getName() + " " + propName + ": testValue was " + testValue + " but controlValue was " + controlValue);
}
if (testValue != null && controlValue == null) {
fail(dynamicTest.getType().getName() + " " + propName + ": testValue was " + testValue + " but controlValue was " + controlValue);
}
if (!testValue.equals(controlValue)) {
fail(propName + ": testValue was " + testValue + " but controlValue was " + controlValue);
}
}
}
}
use of org.eclipse.persistence.internal.dynamic.DynamicEntityImpl in project eclipselink by eclipse-ee4j.
the class IdHelper method buildObjectShell.
/**
* build a shell of an object based on a primary key. The object shell will be an instance of the object with
* only primary key populated
*/
public static Object buildObjectShell(PersistenceContext context, String entityType, Object id) {
ClassDescriptor descriptor = context.getDescriptor(entityType);
List<DatabaseMapping> pkMappings = descriptor.getObjectBuilder().getPrimaryKeyMappings();
Object entity = null;
if (descriptor.hasCMPPolicy()) {
CMP3Policy policy = (CMP3Policy) descriptor.getCMPPolicy();
entity = policy.createBeanUsingKey(id, (AbstractSession) context.getServerSession());
} else if (DynamicEntity.class.isAssignableFrom(descriptor.getJavaClass())) {
DynamicEntityImpl dynamicEntity = (DynamicEntityImpl) context.newEntity(entityType);
// represents the value of that mapping
if (pkMappings.size() == 1) {
dynamicEntity.set(pkMappings.get(0).getAttributeName(), id);
} else {
// If there are more that one PK, we assume an array as produced
// by buildId() above with the keys
// based on a sorted order of PK fields
List<SortableKey> pkIndices = new ArrayList<>();
int index = 0;
for (DatabaseMapping mapping : pkMappings) {
pkIndices.add(new SortableKey(mapping, index));
index++;
}
Collections.sort(pkIndices);
Object[] keyElements = (Object[]) id;
for (SortableKey key : pkIndices) {
dynamicEntity.set(key.getMapping().getAttributeName(), keyElements[key.getIndex()]);
}
}
entity = dynamicEntity;
} else {
throw new RuntimeException("Could not create shell for entity.");
}
if (entity instanceof PersistenceEntity) {
((PersistenceEntity) entity)._persistence_setId(id);
}
if (entity instanceof FetchGroupTracker) {
((FetchGroupTracker) entity)._persistence_setSession(JpaHelper.getDatabaseSession(context.getEmf()));
}
return entity;
}
Aggregations