Search in sources :

Example 1 with EntityAggregateMapHolder

use of org.eclipse.persistence.testing.models.collections.map.EntityAggregateMapHolder in project eclipselink by eclipse-ee4j.

the class TestUpdateEntityAggregateMapMapping method test.

@Override
public void test() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    holders = uow.readAllObjects(EntityAggregateMapHolder.class, holderExp);
    changedHolder = (EntityAggregateMapHolder) holders.get(0);
    EntityMapKey key = new EntityMapKey();
    key.setId(1);
    changedHolder.removeEntityToAggregateMapItem(key);
    AggregateMapValue mapValue = new AggregateMapValue();
    mapValue.setValue(3);
    key = new EntityMapKey();
    key.setId(3);
    key = (EntityMapKey) uow.registerObject(key);
    changedHolder.addEntityToAggregateMapItem(key, mapValue);
    uow.commit();
    Object holderForComparison = uow.readObject(changedHolder);
    if (!compareObjects(changedHolder, holderForComparison)) {
        throw new TestErrorException("Objects do not match after write");
    }
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) AggregateMapValue(org.eclipse.persistence.testing.models.collections.map.AggregateMapValue) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) EntityAggregateMapHolder(org.eclipse.persistence.testing.models.collections.map.EntityAggregateMapHolder) EntityMapKey(org.eclipse.persistence.testing.models.collections.map.EntityMapKey)

Example 2 with EntityAggregateMapHolder

use of org.eclipse.persistence.testing.models.collections.map.EntityAggregateMapHolder in project eclipselink by eclipse-ee4j.

the class TestReadEntityAggregateMapMapping method setup.

@Override
public void setup() {
    mapping = (AggregateCollectionMapping) getSession().getProject().getDescriptor(EntityAggregateMapHolder.class).getMappingForAttributeName("entityToAggregateMap");
    oldFetchJoinValue = mapping.getJoinFetch();
    mapping.setJoinFetch(fetchJoinRelationship);
    getSession().getProject().getDescriptor(EntityAggregateMapHolder.class).reInitializeJoinedAttributes();
    UnitOfWork uow = getSession().acquireUnitOfWork();
    EntityAggregateMapHolder holder = new EntityAggregateMapHolder();
    AggregateMapValue value = new AggregateMapValue();
    value.setValue(1);
    EntityMapKey key = new EntityMapKey();
    key.setData("11");
    key.setId(1);
    holder.addEntityToAggregateMapItem(key, value);
    uow.registerObject(key);
    AggregateMapValue value2 = new AggregateMapValue();
    value2.setValue(2);
    key = new EntityMapKey();
    key.setData("22");
    key.setId(2);
    holder.addEntityToAggregateMapItem(key, value2);
    uow.registerObject(holder);
    uow.registerObject(key);
    uow.commit();
    holderExp = (new ExpressionBuilder()).get("id").equal(holder.getId());
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) AggregateMapValue(org.eclipse.persistence.testing.models.collections.map.AggregateMapValue) EntityAggregateMapHolder(org.eclipse.persistence.testing.models.collections.map.EntityAggregateMapHolder) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) EntityMapKey(org.eclipse.persistence.testing.models.collections.map.EntityMapKey)

Example 3 with EntityAggregateMapHolder

use of org.eclipse.persistence.testing.models.collections.map.EntityAggregateMapHolder in project eclipselink by eclipse-ee4j.

the class TestUpdateEntityAggregateMapMapping method verify.

@Override
public void verify() {
    getSession().getIdentityMapAccessor().initializeIdentityMaps();
    holders = getSession().readAllObjects(EntityAggregateMapHolder.class, holderExp);
    EntityAggregateMapHolder holder = (EntityAggregateMapHolder) holders.get(0);
    if (!compareObjects(holder, changedHolder)) {
        throw new TestErrorException("Objects do not match reinitialize");
    }
    EntityMapKey key = new EntityMapKey();
    key.setId(1);
    if (holder.getEntityToAggregateMap().containsKey(key)) {
        throw new TestErrorException("Item that was removed is still present in map.");
    }
    key = new EntityMapKey();
    key.setId(3);
    AggregateMapValue value = (AggregateMapValue) holder.getEntityToAggregateMap().get(key);
    if (value.getValue() != 3) {
        throw new TestErrorException("Item was not correctly added to map");
    }
    if (keyMapping.isPrivateOwned()) {
        ReadObjectQuery query = new ReadObjectQuery(EntityMapKey.class);
        ExpressionBuilder keys = new ExpressionBuilder();
        Expression keycriteria = keys.get("id").equal(1);
        query.setSelectionCriteria(keycriteria);
        key = (EntityMapKey) getSession().executeQuery(query);
        if (key != null) {
            throw new TestErrorException("PrivateOwned EntityMapKey was not deleted.");
        }
    }
}
Also used : AggregateMapValue(org.eclipse.persistence.testing.models.collections.map.AggregateMapValue) ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) Expression(org.eclipse.persistence.expressions.Expression) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) EntityAggregateMapHolder(org.eclipse.persistence.testing.models.collections.map.EntityAggregateMapHolder) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) EntityMapKey(org.eclipse.persistence.testing.models.collections.map.EntityMapKey)

Example 4 with EntityAggregateMapHolder

use of org.eclipse.persistence.testing.models.collections.map.EntityAggregateMapHolder in project eclipselink by eclipse-ee4j.

the class TestReadEntityAggregateMapMapping method verify.

@Override
public void verify() {
    if (holders == null || holders.size() != 1) {
        throw new TestErrorException("Incorrect number of MapHolders was read.");
    }
    EntityAggregateMapHolder holder = (EntityAggregateMapHolder) holders.get(0);
    if (!((IndirectMap) holder.getEntityToAggregateMap()).getValueHolder().isInstantiated() && fetchJoinRelationship > 0) {
        throw new TestErrorException("Relationship was not properly joined.");
    }
    if (holder.getEntityToAggregateMap().size() != 2) {
        throw new TestErrorException("Incorrect Number of MapEntityValues was read.");
    }
    EntityMapKey mapKey = new EntityMapKey();
    mapKey.setData("11");
    mapKey.setId(1);
    AggregateMapValue value = (AggregateMapValue) holder.getEntityToAggregateMap().get(mapKey);
    if (value.getValue() != 1) {
        throw new TestErrorException("Incorrect MapEntityValues was read.");
    }
}
Also used : AggregateMapValue(org.eclipse.persistence.testing.models.collections.map.AggregateMapValue) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) EntityAggregateMapHolder(org.eclipse.persistence.testing.models.collections.map.EntityAggregateMapHolder) EntityMapKey(org.eclipse.persistence.testing.models.collections.map.EntityMapKey)

Aggregations

AggregateMapValue (org.eclipse.persistence.testing.models.collections.map.AggregateMapValue)4 EntityAggregateMapHolder (org.eclipse.persistence.testing.models.collections.map.EntityAggregateMapHolder)4 EntityMapKey (org.eclipse.persistence.testing.models.collections.map.EntityMapKey)4 TestErrorException (org.eclipse.persistence.testing.framework.TestErrorException)3 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)2 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)2 Expression (org.eclipse.persistence.expressions.Expression)1 ReadObjectQuery (org.eclipse.persistence.queries.ReadObjectQuery)1