use of org.eclipse.persistence.testing.models.collections.map.EntityEntityU1MMapHolder in project eclipselink by eclipse-ee4j.
the class TestReadEntityEntityU1MMapMapping method setup.
@Override
public void setup() {
mapping = (UnidirectionalOneToManyMapping) getSession().getProject().getDescriptor(EntityEntityU1MMapHolder.class).getMappingForAttributeName("entityToEntityMap");
oldFetchJoinValue = mapping.getJoinFetch();
mapping.setJoinFetch(fetchJoinRelationship);
getSession().getProject().getDescriptor(EntityEntityU1MMapHolder.class).reInitializeJoinedAttributes();
UnitOfWork uow = getSession().acquireUnitOfWork();
EntityEntityU1MMapHolder holder = new EntityEntityU1MMapHolder();
EntityMapValue value = new EntityMapValue();
value.setId(1);
EntityMapKey key = new EntityMapKey();
key.setId(11);
key.setData("data1");
holder.addEntityToEntityMapItem(key, value);
uow.registerObject(key);
EntityMapValue value2 = new EntityMapValue();
value2.setId(2);
key = new EntityMapKey();
key.setId(22);
holder.addEntityToEntityMapItem(key, value2);
uow.registerObject(holder);
uow.registerObject(key);
uow.registerObject(value);
uow.registerObject(value2);
uow.commit();
holderExp = (new ExpressionBuilder()).get("id").equal(holder.getId());
getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
}
use of org.eclipse.persistence.testing.models.collections.map.EntityEntityU1MMapHolder in project eclipselink by eclipse-ee4j.
the class TestReadEntityEntityU1MMapMapping method verify.
@Override
public void verify() {
if (holders == null || holders.size() != 1) {
throw new TestErrorException("Incorrect number of MapHolders was read.");
}
EntityEntityU1MMapHolder holder = (EntityEntityU1MMapHolder) holders.get(0);
if (!((IndirectMap) holder.getEntityToEntityMap()).getValueHolder().isInstantiated() && fetchJoinRelationship > 0) {
throw new TestErrorException("Relationship was not properly joined.");
}
if (holder.getEntityToEntityMap().size() != 2) {
throw new TestErrorException("Incorrect Number of MapEntityValues was read.");
}
EntityMapKey mapKey = new EntityMapKey();
mapKey.setId(11);
EntityMapValue value = (EntityMapValue) holder.getEntityToEntityMap().get(mapKey);
if (value.getId() != 1) {
throw new TestErrorException("Incorrect MapEntityValues was read.");
}
mapKey = (EntityMapKey) getSession().readObject(mapKey);
if (!mapKey.getData().equals("data1")) {
throw new TestErrorException("EntityMapKey had wrong data");
}
}
use of org.eclipse.persistence.testing.models.collections.map.EntityEntityU1MMapHolder in project eclipselink by eclipse-ee4j.
the class TestReadEntityEntityU1MMapMapping method reset.
@Override
public void reset() {
UnitOfWork uow = getSession().acquireUnitOfWork();
Iterator i = holders.iterator();
while (i.hasNext()) {
EntityEntityU1MMapHolder holder = (EntityEntityU1MMapHolder) i.next();
Iterator j = holder.getEntityToEntityMap().keySet().iterator();
while (j.hasNext()) {
Object key = j.next();
uow.deleteObject(holder.getEntityToEntityMap().get(key));
uow.deleteObject(key);
}
}
uow.deleteAllObjects(holders);
uow.commit();
if (!verifyDelete(holders.get(0))) {
throw new TestErrorException("Delete was unsuccessful.");
}
mapping.setJoinFetch(oldFetchJoinValue);
}
use of org.eclipse.persistence.testing.models.collections.map.EntityEntityU1MMapHolder in project eclipselink by eclipse-ee4j.
the class TestUpdateEntityEntityU1MMapMapping method test.
@Override
public void test() {
UnitOfWork uow = getSession().acquireUnitOfWork();
holders = uow.readAllObjects(EntityEntityU1MMapHolder.class, holderExp);
changedHolder = (EntityEntityU1MMapHolder) holders.get(0);
EntityMapKey key = new EntityMapKey();
key.setId(11);
changedHolder.removeEntityToEntityMapItem(key);
EntityMapValue mapValue = new EntityMapValue();
mapValue.setId(3);
mapValue = (EntityMapValue) uow.registerObject(mapValue);
key = new EntityMapKey();
key.setId(33);
key = (EntityMapKey) uow.registerObject(key);
changedHolder.addEntityToEntityMapItem(key, mapValue);
uow.commit();
Object holderForComparison = uow.readObject(changedHolder);
if (!compareObjects(changedHolder, holderForComparison)) {
throw new TestErrorException("Objects do not match after write");
}
}
use of org.eclipse.persistence.testing.models.collections.map.EntityEntityU1MMapHolder in project eclipselink by eclipse-ee4j.
the class TestUpdateEntityEntityU1MMapMapping method verify.
@Override
public void verify() {
getSession().getIdentityMapAccessor().initializeIdentityMaps();
holders = getSession().readAllObjects(EntityEntityU1MMapHolder.class, holderExp);
EntityEntityU1MMapHolder holder = (EntityEntityU1MMapHolder) holders.get(0);
if (!compareObjects(holder, changedHolder)) {
throw new TestErrorException("Objects do not match reinitialize");
}
EntityMapKey key = new EntityMapKey();
key.setId(11);
if (holder.getEntityToEntityMap().containsKey(key)) {
throw new TestErrorException("Item that was removed is still present in map.");
}
key = new EntityMapKey();
key.setId(33);
EntityMapValue value = (EntityMapValue) holder.getEntityToEntityMap().get(key);
if (value.getId() != 3) {
throw new TestErrorException("Item was not correctly added to map");
}
if (mapping.isPrivateOwned()) {
ReadObjectQuery query = new ReadObjectQuery(EntityMapValue.class);
ExpressionBuilder values = new ExpressionBuilder();
Expression criteria = values.get("id").equal(1);
query.setSelectionCriteria(criteria);
value = (EntityMapValue) getSession().executeQuery(query);
if (value != null) {
throw new TestErrorException("PrivateOwned EntityMapValue was not deleted.");
}
query = new ReadObjectQuery(EntityMapKey.class);
ExpressionBuilder keys = new ExpressionBuilder();
Expression keycriteria = keys.get("id").equal(11);
query.setSelectionCriteria(keycriteria);
key = (EntityMapKey) getSession().executeQuery(query);
if (key != null) {
throw new TestErrorException("PrivateOwned EntityMapKey was not deleted.");
}
}
}
Aggregations