Search in sources :

Example 1 with AggregateMapValue

use of org.eclipse.persistence.testing.models.collections.map.AggregateMapValue 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 AggregateMapValue

use of org.eclipse.persistence.testing.models.collections.map.AggregateMapValue 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 AggregateMapValue

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

the class TestUpdateDirectAggregateMapMapping method verify.

@Override
public void verify() {
    getSession().getIdentityMapAccessor().initializeIdentityMaps();
    Object initialHolder = holders.get(0);
    holders = getSession().readAllObjects(DirectAggregateMapHolder.class, holderExp);
    DirectAggregateMapHolder holder = (DirectAggregateMapHolder) holders.get(0);
    if (!compareObjects(holder, changedHolder)) {
        throw new TestErrorException("Objects do not match reinitialize");
    }
    if (holder.getDirectToAggregateMap().containsKey(1)) {
        throw new TestErrorException("Item that was removed is still present in map.");
    }
    AggregateMapValue value = (AggregateMapValue) holder.getDirectToAggregateMap().get(3);
    if (value.getValue() != 3) {
        throw new TestErrorException("Item was not correctly added to map");
    }
}
Also used : AggregateMapValue(org.eclipse.persistence.testing.models.collections.map.AggregateMapValue) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) DirectAggregateMapHolder(org.eclipse.persistence.testing.models.collections.map.DirectAggregateMapHolder)

Example 4 with AggregateMapValue

use of org.eclipse.persistence.testing.models.collections.map.AggregateMapValue 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 5 with AggregateMapValue

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

the class TestUpdateDirectAggregateMapMapping method test.

@Override
public void test() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    holders = uow.readAllObjects(DirectAggregateMapHolder.class, holderExp);
    changedHolder = (DirectAggregateMapHolder) holders.get(0);
    changedHolder.removeDirectToAggregateMapItem(1);
    AggregateMapValue mapValue = new AggregateMapValue();
    mapValue.setValue(3);
    changedHolder.addDirectToAggregateMapItem(3, 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) DirectAggregateMapHolder(org.eclipse.persistence.testing.models.collections.map.DirectAggregateMapHolder)

Aggregations

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