Search in sources :

Example 1 with AggregateEntity1MMapHolder

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

the class TestUpdateAggregateEntity1MMapMapping method test.

@Override
public void test() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    holders = uow.readAllObjects(AggregateEntity1MMapHolder.class, holderExp);
    changedHolder = (AggregateEntity1MMapHolder) holders.get(0);
    AggregateMapKey key = new AggregateMapKey();
    key.setKey(11);
    changedHolder.removeAggregateToEntityMapItem(key);
    AEOTMMapValue mapValue = new AEOTMMapValue();
    mapValue.setId(3);
    mapValue = (AEOTMMapValue) uow.registerObject(mapValue);
    key = new AggregateMapKey();
    key.setKey(33);
    mapValue.getHolder().setValue(changedHolder);
    changedHolder.addAggregateToEntityMapItem(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) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) AggregateEntity1MMapHolder(org.eclipse.persistence.testing.models.collections.map.AggregateEntity1MMapHolder) AggregateMapKey(org.eclipse.persistence.testing.models.collections.map.AggregateMapKey) AEOTMMapValue(org.eclipse.persistence.testing.models.collections.map.AEOTMMapValue)

Example 2 with AggregateEntity1MMapHolder

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

the class TestUpdateAggregateEntity1MMapMapping method verify.

@Override
public void verify() {
    getSession().getIdentityMapAccessor().initializeIdentityMaps();
    holders = getSession().readAllObjects(AggregateEntity1MMapHolder.class, holderExp);
    AggregateEntity1MMapHolder holder = (AggregateEntity1MMapHolder) holders.get(0);
    if (!compareObjects(holder, changedHolder)) {
        throw new TestErrorException("Objects do not match reinitialize");
    }
    AggregateMapKey key = new AggregateMapKey();
    key.setKey(11);
    if (holder.getAggregateToEntityMap().containsKey(key)) {
        throw new TestErrorException("Item that was removed is still present in map.");
    }
    key = new AggregateMapKey();
    key.setKey(33);
    AEOTMMapValue value = (AEOTMMapValue) holder.getAggregateToEntityMap().get(key);
    if (value.getId() != 3) {
        throw new TestErrorException("Item was not correctly added to map");
    }
    if (mapping.isPrivateOwned()) {
        ReadObjectQuery query = new ReadObjectQuery(AEOTMMapValue.class);
        ExpressionBuilder values = new ExpressionBuilder();
        Expression criteria = values.get("id").equal(1);
        query.setSelectionCriteria(criteria);
        value = (AEOTMMapValue) getSession().executeQuery(query);
        if (value != null) {
            throw new TestErrorException("PrivateOwned DEOTMMapValue was not deleted.");
        }
    }
}
Also used : ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) Expression(org.eclipse.persistence.expressions.Expression) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) AggregateEntity1MMapHolder(org.eclipse.persistence.testing.models.collections.map.AggregateEntity1MMapHolder) AggregateMapKey(org.eclipse.persistence.testing.models.collections.map.AggregateMapKey) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) AEOTMMapValue(org.eclipse.persistence.testing.models.collections.map.AEOTMMapValue)

Example 3 with AggregateEntity1MMapHolder

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

the class TestReadAggregateEntity1MMapMapping method reset.

@Override
public void reset() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    Iterator i = holders.iterator();
    while (i.hasNext()) {
        AggregateEntity1MMapHolder holder = (AggregateEntity1MMapHolder) i.next();
        Iterator j = holder.getAggregateToEntityMap().keySet().iterator();
        while (j.hasNext()) {
            uow.deleteObject(holder.getAggregateToEntityMap().get(j.next()));
        }
    }
    uow.deleteAllObjects(holders);
    uow.commit();
    if (!verifyDelete(holders.get(0))) {
        throw new TestErrorException("Delete was unsuccessful.");
    }
    mapping.setJoinFetch(oldFetchJoinValue);
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) Iterator(java.util.Iterator) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) AggregateEntity1MMapHolder(org.eclipse.persistence.testing.models.collections.map.AggregateEntity1MMapHolder)

Example 4 with AggregateEntity1MMapHolder

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

the class TestReadAggregateEntity1MMapMapping method verify.

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

Example 5 with AggregateEntity1MMapHolder

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

the class TestReadAggregateEntity1MMapMapping method setup.

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

Aggregations

AggregateEntity1MMapHolder (org.eclipse.persistence.testing.models.collections.map.AggregateEntity1MMapHolder)6 TestErrorException (org.eclipse.persistence.testing.framework.TestErrorException)4 AEOTMMapValue (org.eclipse.persistence.testing.models.collections.map.AEOTMMapValue)4 AggregateMapKey (org.eclipse.persistence.testing.models.collections.map.AggregateMapKey)4 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)3 Iterator (java.util.Iterator)2 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)2 Enumeration (java.util.Enumeration)1 Vector (java.util.Vector)1 Expression (org.eclipse.persistence.expressions.Expression)1 ReadObjectQuery (org.eclipse.persistence.queries.ReadObjectQuery)1